Merge branch 'master' of gitee.com:openharmony/startup_appspawn into sandbox-new

Signed-off-by: 钟柠 <zhongning5@huawei.com>
This commit is contained in:
钟柠 2024-04-25 02:56:07 +00:00 committed by zhongning5
commit c1a5977406
7 changed files with 67 additions and 15 deletions

View File

@ -805,6 +805,17 @@
"sandbox-flags": [ "bind", "rec" ]
}
]
}],
"ohos.permission.ACCESS_LOCAL_BACKUP":[{
"sandbox-switch": "ON",
"gids": [1023],
"mount-paths": [{
"src-path": "/data/hwbackup",
"sandbox-path": "/data/hwbackup",
"sandbox-flags": [ "bind", "rec" ],
"check-action-status": "false"
}
]
}]
}]
}

View File

@ -43,9 +43,9 @@ typedef struct TagPermissionNode {
#endif
#ifdef APPSPAWN_CLIENT
#define PERMISSION_NAME(node) (node) == NULL ? NULL : (node)->name;
#define PERMISSION_NAME(node) (node) == NULL ? NULL : (node)->name
#else
#define PERMISSION_NAME(node) (node) == NULL ? NULL : (node)->section.name;
#define PERMISSION_NAME(node) (node) == NULL ? NULL : (node)->section.name
#endif
#ifdef __cplusplus

View File

@ -53,9 +53,46 @@ int HnpProcessRunCheck(const char *runPath)
return 0;
}
static void HnpRelPath(const char *fromPath, const char *toPath, char *relPath)
{
char *from = strdup(fromPath);
char *to = strdup(toPath);
int count = 0;
int numDirs = 0;
while ((*from) && (*to) && (*from == *to)) {
from++;
to++;
count++;
}
char *p = from;
while (*p) {
if (*p == DIR_SPLIT_SYMBOL) {
numDirs++;
}
p++;
}
for (int i = 0; i < numDirs; i++) {
strcat(relPath, "../");
}
strcat(relPath, to);
for (int i = 0; i < count; i++) {
from--;
to--;
}
free(from);
free(to);
return;
}
int HnpSymlink(const char *srcFile, const char *dstFile)
{
int ret;
char relpath[MAX_FILE_PATH_LEN];
/* 将源二进制文件权限设置为750 */
ret = chmod(srcFile, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH);
@ -68,7 +105,8 @@ int HnpSymlink(const char *srcFile, const char *dstFile)
unlink(dstFile);
}
ret = symlink(srcFile, dstFile);
HnpRelPath(dstFile, srcFile, relpath);
ret = symlink(relpath, dstFile);
if (ret < 0) {
HNP_LOGE("hnp install generate soft link unsuccess, src:%s, dst:%s, errno:%d", srcFile, dstFile, errno);
return HNP_ERRNO_GENERATE_SOFT_LINK_FAILED;

View File

@ -103,7 +103,7 @@ static int HnpGenerateSoftLinkAll(const char *installPath, const char *dstPath)
DIR *dir;
struct dirent *entry;
ret = sprintf_s(srcPath, MAX_FILE_PATH_LEN, "%s/bin/", installPath);
ret = sprintf_s(srcPath, MAX_FILE_PATH_LEN, "%s/bin", installPath);
if (ret < 0) {
HNP_LOGE("sprintf install bin path unsuccess.");
return HNP_ERRNO_BASE_SPRINTF_FAILED;
@ -157,7 +157,7 @@ static int HnpGenerateSoftLink(const char *installPath, const char *hnpBasePath,
int ret = 0;
char binPath[MAX_FILE_PATH_LEN];
ret = sprintf_s(binPath, MAX_FILE_PATH_LEN, "%s/bin/", hnpBasePath);
ret = sprintf_s(binPath, MAX_FILE_PATH_LEN, "%s/bin", hnpBasePath);
if (ret < 0) {
HNP_LOGE("sprintf install bin path unsuccess.");
return HNP_ERRNO_BASE_SPRINTF_FAILED;

View File

@ -134,7 +134,7 @@ int GetParameter(const char *key, const char *def, char *value, uint32_t len)
const char *tmp = def;
if ((count % 3) == 0) { // 3 test
return -1;
} else if ((count % 3) == 1) { //
} else if ((count % 3) == 1) { // 3 test
tmp = "a";
} else {
tmp = "5";

View File

@ -656,7 +656,7 @@ HWTEST(AppSpawnClientTest, App_Client_Msg_012, TestSize.Level0)
ret = 0;
for (size_t i = 0; i < max; i++) {
if (!CheckAppPermissionFlagSet(property, (uint32_t)i)) {
APPSPAWN_LOGE("Invalid permission not set %{public}d %{public}s",
APPSPAWN_LOGE("Invalid permission not set %{public}zu %{public}s",
i, GetPermissionByIndex(clientHandle, i));
ret = APPSPAWN_ARG_INVALID;
break;

View File

@ -161,20 +161,23 @@ HWTEST(AppSpawnInterfaceTest, App_Spawn_Interface_Msg_Create_001, TestSize.Level
name1.data(), name2.data(), name3.data(), nullptr, ""};
AppSpawnReqMsgHandle reqHandle = nullptr;
AppSpawnReqMsgHandle *inputHandle[] = {&reqHandle, nullptr};
for (size_t i = 0; i < ARRAY_LENGTH(msgType); i++) {
for (size_t j = 0; j < ARRAY_LENGTH(processName); j++) {
for (size_t k = 0; k < ARRAY_LENGTH(inputHandle); k++) {
int ret = AppSpawnReqMsgCreate(msgType[i], processName[j], inputHandle[k]);
printf("App_Spawn_Interface_Msg_Create_001 %zu %zu %zu \n", i, j, k);
EXPECT_EQ(((i != 4) && (j < 3) && (k == 0) && ret == 0) || (ret != 0), 1); // 4 3 valid index
if (ret == 0) {
AppSpawnReqMsgFree(reqHandle);
}
int ret = AppSpawnReqMsgCreate(msgType[i], processName[j], &reqHandle);
printf("App_Spawn_Interface_Msg_Create_001 %zu %zu \n", i, j);
EXPECT_EQ(((i != 4) && (j < 3) && ret == 0) || (ret != 0), 1); // 4 3 valid index
if (ret == 0) {
AppSpawnReqMsgFree(reqHandle);
}
}
}
for (size_t i = 0; i < ARRAY_LENGTH(msgType); i++) {
for (size_t j = 0; j < ARRAY_LENGTH(processName); j++) {
int ret = AppSpawnReqMsgCreate(msgType[i], processName[j], nullptr);
EXPECT_EQ(ret != 0, 1);
}
}
}
/**