fix: day error

Signed-off-by: Mupceet <laiguizhong@huawei.com>
This commit is contained in:
Mupceet 2022-05-05 13:47:12 +08:00
parent dee73b9f05
commit a5f9e492b6
9 changed files with 26 additions and 28 deletions

View File

@ -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 = ""

View File

@ -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") {

View File

@ -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"
],

View File

@ -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();

View File

@ -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

View File

@ -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);

View File

@ -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);

View File

@ -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;
}

View File

@ -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[] = {