From a5f9e492b6d8f5cef08b9426c52397ddbf2ed92c Mon Sep 17 00:00:00 2001 From: Mupceet Date: Thu, 5 May 2022 13:47:12 +0800 Subject: [PATCH] fix: day error Signed-off-by: Mupceet --- begetd.gni | 1 + services/begetctl/BUILD.gn | 7 ++++++- services/init/lite/bundle.json | 2 +- services/init/lite/init.c | 2 ++ services/param/adapter/param_selinux.c | 18 +++--------------- services/param/include/param_manager.h | 2 +- services/param/include/param_security.h | 2 +- services/param/manager/param_manager.c | 15 +++++++++------ test/unittest/param/param_stub.cpp | 5 ++--- 9 files changed, 26 insertions(+), 28 deletions(-) diff --git a/begetd.gni b/begetd.gni index 1ba3bc962..49b3ccd42 100755 --- a/begetd.gni +++ b/begetd.gni @@ -15,6 +15,7 @@ declare_args() { param_feature_watcher = true param_feature_deviceinfo = false param_test = true + param_begetctl_liteos_support = false enable_ohos_startup_init_lite_use_thirdparty_mbedtls = true enable_ohos_startup_init_lite_use_posix_file_api = false config_ohos_startup_init_lite_data_path = "" diff --git a/services/begetctl/BUILD.gn b/services/begetctl/BUILD.gn index b731be8d3..426c12546 100644 --- a/services/begetctl/BUILD.gn +++ b/services/begetctl/BUILD.gn @@ -10,6 +10,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +import("//base/startup/init_lite/begetd.gni") if (defined(ohos_lite)) { executable("begetctl") { @@ -44,8 +45,12 @@ if (defined(ohos_lite)) { "//third_party/bounds_checking_function:libsec_static", ] } + group("begetctl_cmd") { + if (param_begetctl_liteos_support) { + deps = [ ":begetctl" ] + } + } } else { - import("//base/startup/init_lite/begetd.gni") import("//build/ohos.gni") ohos_executable("begetctl") { diff --git a/services/init/lite/bundle.json b/services/init/lite/bundle.json index 56bbaf99a..01875f1e8 100644 --- a/services/init/lite/bundle.json +++ b/services/init/lite/bundle.json @@ -31,7 +31,7 @@ "sub_component": [ "//base/startup/init_lite/interfaces/innerkits:libbegetutil", "//base/startup/init_lite/services:init_lite", - "//base/startup/init_lite/services/begetctl:begetctl", + "//base/startup/init_lite/services/begetctl:begetctl_cmd", "//base/startup/init_lite/watchdog:watchdog", "//base/startup/init_lite/ueventd:ueventd" ], diff --git a/services/init/lite/init.c b/services/init/lite/init.c index b21df2a55..e3dbb0d4c 100644 --- a/services/init/lite/init.c +++ b/services/init/lite/init.c @@ -53,6 +53,7 @@ void SystemPrepare(void) void SystemConfig(void) { InitServiceSpace(); +#ifdef LITEOS_SUPPORT_PARAM InitParamService(); // parse parameters LoadDefaultParams("/system/etc/param/ohos_const", LOAD_PARAM_NORMAL); @@ -60,6 +61,7 @@ void SystemConfig(void) LoadDefaultParams("/system/etc/param", LOAD_PARAM_ONLY_ADD); LoadPersistParams(); +#endif // read config ReadConfig(); diff --git a/services/param/adapter/param_selinux.c b/services/param/adapter/param_selinux.c index fbe110908..b89d15989 100644 --- a/services/param/adapter/param_selinux.c +++ b/services/param/adapter/param_selinux.c @@ -54,7 +54,7 @@ static int InitLocalSecurityLabel(ParamSecurityLabel *security, int isInit) PARAM_CHECK(g_selinuxSpace.getParamList != NULL, return -1, "Failed to dlsym getParamList %s", dlerror()); } if (g_selinuxSpace.getParamLabel == NULL) { - g_selinuxSpace.getParamLabel = (int (*)(const char *, char **))dlsym(handle, "GetParamLabel"); + g_selinuxSpace.getParamLabel = (const char * (*)(const char *))dlsym(handle, "GetParamLabel"); PARAM_CHECK(g_selinuxSpace.getParamLabel != NULL, return -1, "Failed to dlsym getParamLabel %s", dlerror()); } if (g_selinuxSpace.readParamCheck == NULL) { @@ -151,26 +151,14 @@ int RegisterSecuritySelinuxOps(ParamSecurityOps *ops, int isInit) return ret; } -const char *GetSelinuxContent(const char *name, char *buffer, uint32_t size) +const char *GetSelinuxContent(const char *name) { PARAM_CHECK(g_selinuxSpace.getParamLabel != NULL, return NULL, "Invalid getParamLabel"); PARAM_CHECK(g_selinuxSpace.setSelinuxLogCallback != NULL, return NULL, "Invalid setSelinuxLogCallback"); // log g_selinuxSpace.setSelinuxLogCallback(); - char *label = NULL; - int ret = g_selinuxSpace.getParamLabel(name, &label); - if (ret == 0 && label != NULL) { - if (strcpy_s(buffer, size, label) == 0) { - free(label); - PARAM_LOGV("GetSelinuxContent name %s label %s", name, buffer); - return buffer; - } - free(label); - } - PARAM_LOGE("Failed to get content for name %s ret %d", name, ret); - strcpy_s(buffer, size, WORKSPACE_NAME_DEF_SELINUX); - return buffer; + return g_selinuxSpace.getParamLabel(name); } #if defined STARTUP_INIT_TEST || defined LOCAL_TEST diff --git a/services/param/include/param_manager.h b/services/param/include/param_manager.h index 868929e30..b4832ca43 100644 --- a/services/param/include/param_manager.h +++ b/services/param/include/param_manager.h @@ -110,7 +110,7 @@ typedef struct { char *prefix; } ParamTraversalContext; -const char *GetSelinuxContent(const char *name, char *buffer, uint32_t size); +const char *GetSelinuxContent(const char *name); int LoadParamFromCmdLine(void); void LoadSelinuxLabel(void); diff --git a/services/param/include/param_security.h b/services/param/include/param_security.h index a518a3fa9..bcc633fdf 100644 --- a/services/param/include/param_security.h +++ b/services/param/include/param_security.h @@ -108,7 +108,7 @@ typedef struct SelinuxSpace_ { void *selinuxHandle; void (*setSelinuxLogCallback)(); int (*setParamCheck)(const char *paraName, struct ucred *uc); - int (*getParamLabel)(const char *paraName, char **context); + const char *(*getParamLabel)(const char *paraName); int (*readParamCheck)(const char *paraName); ParamContextsList *(*getParamList)(); void (*destroyParamList)(ParamContextsList **list); diff --git a/services/param/manager/param_manager.c b/services/param/manager/param_manager.c index 33c9ecef9..eb79d090c 100644 --- a/services/param/manager/param_manager.c +++ b/services/param/manager/param_manager.c @@ -543,9 +543,9 @@ int CheckParamPermission(const ParamSecurityLabel *srcLabel, const char *name, u } #ifdef PARAM_SUPPORT_SELINUX if (ret == DAC_RESULT_PERMISSION && mode != DAC_WRITE) { // open workspace for client read - char content[SELINUX_CONTENT_LEN] = {0}; - if (GetSelinuxContent(name, content, sizeof(content)) != NULL) { - AddWorkSpace(content, 1, PARAM_WORKSPACE_DEF); + const char *label = GetSelinuxContent(name); + if (label != NULL) { + AddWorkSpace(label, 1, PARAM_WORKSPACE_DEF); } else { ret = DAC_RESULT_FORBIDED; } @@ -678,9 +678,8 @@ WorkSpace *GetWorkSpace(const char *name) #ifndef PARAM_SUPPORT_SELINUX tmpName = WORKSPACE_NAME_NORMAL; #else - char content[SELINUX_CONTENT_LEN] = {0}; if (strcmp(name, WORKSPACE_NAME_DAC) != 0) { - tmpName = (char *)GetSelinuxContent(name, content, sizeof(content)); + tmpName = (char *)GetSelinuxContent(name); } #endif WorkSpace *space = NULL; @@ -833,7 +832,11 @@ int GetParamSecurityAuditData(const char *name, int type, ParamAuditData *auditD auditData->dacData.gid = node->gid; auditData->dacData.mode = node->mode; #ifdef PARAM_SUPPORT_SELINUX - GetSelinuxContent(name, auditData->label, sizeof(auditData->label)); + const char *tmpName = GetSelinuxContent(name); + if (tmpName != NULL) { + int ret = strcpy_s(auditData->label, sizeof(auditData->label), tmpName); + PARAM_CHECK(ret == 0, return 0, "Failed to copy label for %s", name); + } #endif return 0; } diff --git a/test/unittest/param/param_stub.cpp b/test/unittest/param/param_stub.cpp index 203785966..41a2c611d 100755 --- a/test/unittest/param/param_stub.cpp +++ b/test/unittest/param/param_stub.cpp @@ -70,7 +70,7 @@ static int TestSetParamCheck(const char *paraName, struct ucred *uc) return g_testPermissionResult; } -static int TestGetParamLabel(const char *paraName, char **context) +static const char *TestGetParamLabel(const char *paraName) { BEGET_LOGI("TestGetParamLabel %s", paraName); for (size_t i = 0; i < ARRAY_LENGTH(selinuxLabels); i++) { @@ -81,8 +81,7 @@ static int TestGetParamLabel(const char *paraName, char **context) } int code = TestGenHashCode(paraName); code = code % (ARRAY_LENGTH(selinuxLabels)); - *context = strdup(selinuxLabels[code][1]); - return 0; + return selinuxLabels[code][1]; } static const char *forbitReadParamName[] = {