!202 修复数据目录other组有执行权限

Merge pull request !202 from shilei91/OpenHarmony-3.2-Beta3
This commit is contained in:
openharmony_ci
2022-09-26 06:48:51 +00:00
committed by Gitee
12 changed files with 61 additions and 34 deletions
@@ -172,7 +172,7 @@ static uint8_t DeserializeInnerBundleName(IOwner owner, IpcIo *reply)
info->resultCode = ERR_APPEXECFWK_DESERIALIZATION_FAILED;
return ERR_APPEXECFWK_DESERIALIZATION_FAILED;
}
if (length < 0 || length > MAX_BUNDLE_NAME) {
if (length > MAX_BUNDLE_NAME) {
info->resultCode = ERR_APPEXECFWK_DESERIALIZATION_FAILED;
return ERR_APPEXECFWK_DESERIALIZATION_FAILED;
}
@@ -29,6 +29,7 @@ const char PATH_SEPARATOR = '/';
class BundleFileUtils : public NoCopyable {
public:
static bool MkRecursiveDir(const char *dir, bool isReadOthers);
static bool MkOwnerDir(const char *dir);
static bool IsExistDir(const char *path);
static bool IsExistFile(const char *file);
static bool RemoveFile(const char *path);
@@ -200,7 +200,7 @@ int32_t BundleDaemon::CreateDataDirectoryInvoke(IpcIo *req)
ReadInt32(req, &gid);
bool isChown;
ReadBool(req, &isChown);
PRINTI("BundleDaemonClient", "uid is %{public}d, isChown is %{public}d", uid, isChown);
return BundleDaemon::GetInstance().handler_.CreateDataDirectory(dataPath, uid, gid, isChown);
}
@@ -140,12 +140,12 @@ int32_t BundleDaemonHandler::CreateDataDirectory(const char *dataPath, int32_t u
}
if (!BundleFileUtils::IsExistDir(dataDir.c_str())) {
if (!BundleFileUtils::MkRecursiveDir(dataDir.c_str(), false)) {
if (!BundleFileUtils::MkOwnerDir(dataDir.c_str())) {
PRINTE("BundleDaemonHandler", "create dataPath fail");
return EC_NODIR;
}
}
PRINTI("BundleDaemonClient", "uid is %{public}d, isChown is %{public}d", uid, isChown);
if (isChown && !BundleFileUtils::ChownFile(dataDir.c_str(), uid, gid)) {
PRINTE("BundleDaemonHandler", "chown file fail");
return EC_NOFILE;
@@ -78,6 +78,32 @@ bool BundleFileUtils::MkRecursiveDir(const char *dir, bool isReadOthers)
return true;
}
bool BundleFileUtils::MkOwnerDir(const char *dir)
{
if (dir == nullptr) {
return false;
}
if (IsExistDir(dir)) {
return true;
}
size_t len = strlen(dir);
if (len == 0 || len > PATH_MAX) {
return false;
}
// Create directories level by level
char rootDir[PATH_MAX] = { '\0' };
for (size_t i = 0; i < len; ++i) {
rootDir[i] = dir[i];
if ((rootDir[i] == PATH_SEPARATOR || i == (len - 1)) && !IsExistDir(rootDir)) {
mode_t mode = S_IRWXU | S_IRWXG;
if (mkdir(rootDir, mode) < 0) {
return false;
}
}
}
return true;
}
bool BundleFileUtils::RemoveFile(const char *path)
{
if (IsExistFile(path)) {
@@ -283,7 +283,7 @@ int32_t BundleDaemonClient::CreateDataDirectory(const char *dataPath, int32_t ui
WriteInt32(&request, uid);
WriteInt32(&request, gid);
WriteBool(&request, isChown);
PRINTI("BundleDaemonClient", "uid is %{public}d, isChown is %{public}d", uid, isChown);
Lock<Mutex> lock(mutex_);
#ifdef __LINUX__
return WaitResultSync(bdsClient_->Invoke(bdsClient_, CREATE_DATA_DIRECTORY, &request, this, Notify));
@@ -330,13 +330,10 @@ bool BundleInstaller::MatchPermissions(const std::vector<std::string> & restrict
int32_t size = realRestrictedPermissions.size();
for (int32_t i = 0; i < size; i++) {
bool isMatched = false;
for (const auto & restrictedPermission : restrictedPermissions) {
if (realRestrictedPermissions[i] == restrictedPermission) {
isMatched = true;
break;
}
}
bool isMatched = std::any_of(restrictedPermissions.begin(), restrictedPermissions.end(),
[realRestrictedPermissions, i](const auto & restrictedPermission)->bool {
return realRestrictedPermissions[i] == restrictedPermission;
});
if (!isMatched) {
HILOG_WARN(HILOG_MODULE_APP, "provisionPermissions is not match the bundle reqPermissions!");
return false;
@@ -672,10 +672,9 @@ static int32_t GenerateInnerUid(std::map<int, std::string> &innerMap, const std:
}
int32_t ret = 0;
for (int32_t i = 0; i < innerMap.rbegin()->first; ++i) {
if (innerMap.find(i) == innerMap.end()) {
innerMap.emplace(i, bundleName);
ret = i + baseUid;
return ret;
auto res = innerMap.emplace(i, bundleName);
if (res.second) {
return i + baseUid;
}
}
@@ -122,13 +122,6 @@ BOOL BundleMsFeature::OnFeatureMessage(Feature *feature, Request *request)
return TRUE;
}
static void InnerFreeDataBuff(void *ptr)
{
if (ptr != nullptr) {
cJSON_free(ptr);
}
}
uint8_t BundleMsFeature::HasSystemCapability(const uint8_t funcId, IpcIo *req, IpcIo *reply)
{
if ((req == nullptr) || (reply == nullptr)) {
@@ -109,7 +109,7 @@ char *GtBundleExtractor::ExtractHapProfile(int32_t fp, uint32_t totalFileSize)
}
int32_t fileNameLen = strlen(fileName);
if (pathLen == 0 && (fileName != nullptr && strcmp(fileName, PROFILE_NAME) == 0)) {
if (pathLen == 0 && (strcmp(fileName, PROFILE_NAME) == 0)) {
UI_Free(fileName);
fileName = nullptr;
fileData = reinterpret_cast<char *>(AdapterMalloc(fileSize * sizeof(char)));
@@ -154,7 +154,7 @@ bool GtBundleExtractor::ExtractResourceFile(const char *path, int32_t fp, uint32
}
int32_t fileNameLen = strlen(fileName);
if ((strlen(relativeFilePath) == 0 && (fileName != nullptr && strcmp(fileName, PROFILE_NAME) == 0)) ||
if ((strlen(relativeFilePath) == 0 && (strcmp(fileName, PROFILE_NAME) == 0)) ||
!BundleUtil::StartWith(relativeFilePath, ASSET_JS_PATH)) {
if (!GtExtractorUtil::HasWrittenFile(path, relativeFilePath, fileName, fp, fileSize)) {
UI_Free(fileName);
@@ -109,8 +109,7 @@ uint8_t GtBundleInstaller::VerifySignature(const char *path, SignatureInfo &sign
VerifyResult verifyResult;
// verify signature
(void) APPVERI_SetDebugMode(true);
int32_t ret = (bundleStyle == THIRD_APP_FLAG) ? APPVERI_AppVerify(path, &verifyResult) :
APPVERI_AppVerify(path, &verifyResult);
int32_t ret = APPVERI_AppVerify(path, &verifyResult);
HILOG_INFO(HILOG_MODULE_AAFWK, "[BMS] APPVERI_AppVerify is %d", ret);
uint8_t errorCode = SwitchErrorCode(ret);
if (errorCode != ERR_OK) {
@@ -523,9 +522,6 @@ uint8_t GtBundleInstaller::UpdateBundleInfo(uint8_t bundleStyle, uint32_t labelI
if (bundleStyle == SYSTEM_APP_FLAG) {
bundleInfo->isSystemApp = true;
GtManagerService::GetInstance().AddBundleInfo(bundleInfo);
} else if (bundleStyle == THIRD_SYSTEM_APP_FLAG) {
bundleInfo->isSystemApp = false;
GtManagerService::GetInstance().AddBundleInfo(bundleInfo);
} else {
bundleInfo->isSystemApp = false;
GtManagerService::GetInstance().AddBundleInfo(bundleInfo);
@@ -317,6 +317,9 @@ void GtManagerService::InstallAllSystemBundle(InstallerCallback installerCallbac
AppInfoList *currentNode = nullptr;
AppInfoList *nextNode = nullptr;
LOS_DL_LIST_FOR_EACH_ENTRY_SAFE(currentNode, nextNode, &list->appDoubleList, AppInfoList, appDoubleList) {
if (currentNode == nullptr) {
return;
}
if ((strcmp(((AppInfoList *)currentNode)->filePath, ".") == 0) ||
(strcmp(((AppInfoList *)currentNode)->filePath, "..") == 0)) {
continue;
@@ -411,10 +414,12 @@ void GtManagerService::RemoveSystemAppPathList(List<ToBeInstalledApp *> *systemP
for (auto node = systemPathList->Begin(); node != systemPathList->End(); node = node->next_) {
ToBeInstalledApp *toBeInstalledApp = node->value_;
AdapterFree(toBeInstalledApp->installedPath);
AdapterFree(toBeInstalledApp->path);
AdapterFree(toBeInstalledApp->appId);
UI_Free(toBeInstalledApp);
if (toBeInstalledApp != nullptr) {
AdapterFree(toBeInstalledApp->installedPath);
AdapterFree(toBeInstalledApp->path);
AdapterFree(toBeInstalledApp->appId);
UI_Free(toBeInstalledApp);
}
}
}
@@ -433,6 +438,9 @@ void GtManagerService::ScanSystemApp(const cJSON *uninstallRecord, List<ToBeInst
AppInfoList *nextNode = nullptr;
LOS_DL_LIST_FOR_EACH_ENTRY_SAFE(currentNode, nextNode, &list->appDoubleList, AppInfoList, appDoubleList) {
if (currentNode == nullptr) {
return;
}
if ((strcmp(((AppInfoList *)currentNode)->filePath, ".") == 0) ||
(strcmp(((AppInfoList *)currentNode)->filePath, "..") == 0)) {
continue;
@@ -696,6 +704,9 @@ void GtManagerService::RemoveBundleResList(const char *bundleName)
for (auto node = bundleResList_->Begin(); node != bundleResList_->End(); node = node->next_) {
BundleRes *res = node->value_;
if (res == nullptr) {
return;
}
if (res->bundleName != nullptr && strcmp(bundleName, res->bundleName) == 0) {
AdapterFree(res->abilityRes);
AdapterFree(res);
@@ -997,6 +1008,9 @@ void GtManagerService::APP_QueryAppInfo(const char *appDir, AppInfoList *list)
return;
}
char *fileName = reinterpret_cast<char *>(AdapterMalloc(MAX_NAME_LEN + 1));
if (fileName == nullptr) {
return;
}
while ((ent = readdir(dir)) != nullptr) {
if (memset_s(fileName, MAX_NAME_LEN + 1, 0, MAX_NAME_LEN + 1) != EOK) {
break;
@@ -1029,6 +1043,7 @@ void GtManagerService::APP_QueryAppInfo(const char *appDir, AppInfoList *list)
APP_InsertAppInfo(appPath, (AppInfoList *)&list->appDoubleList);
AdapterFree(appPath);
}
closedir(dir);
AdapterFree(fileName);
}