mirror of
https://gitee.com/openharmony/startup_init
synced 2025-02-17 10:28:00 +00:00
commit
b811269633
@ -18,6 +18,7 @@
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
@ -49,6 +50,7 @@ typedef struct {
|
||||
#define BOOT_CMD_LINE STARTUP_INIT_UT_PATH"/proc/cmdline"
|
||||
|
||||
uid_t DecodeUid(const char *name);
|
||||
gid_t DecodeGid(const char *name);
|
||||
char *ReadFileToBuf(const char *configFile);
|
||||
int GetProcCmdlineValue(const char *name, const char *buffer, char *value, int length);
|
||||
char *ReadFileData(const char *fileName);
|
||||
|
@ -291,7 +291,7 @@ static int SetOwner(const char *file, const char *ownerStr, const char *groupStr
|
||||
|
||||
uid_t owner = DecodeUid(ownerStr);
|
||||
INIT_ERROR_CHECK(owner != (uid_t)-1, return -1, "SetOwner invalid uid :%s.", ownerStr);
|
||||
gid_t group = DecodeUid(groupStr);
|
||||
gid_t group = DecodeGid(groupStr);
|
||||
INIT_ERROR_CHECK(group != (gid_t)-1, return -1, "SetOwner invalid gid :%s.", groupStr);
|
||||
return (chown(file, owner, group) != 0) ? -1 : 0;
|
||||
}
|
||||
|
@ -494,7 +494,7 @@ static int AddServiceSocket(cJSON *json, Service *service)
|
||||
stringValue = GetStringValue(json, "gid", &strLen);
|
||||
INIT_ERROR_CHECK((stringValue != NULL) && (strLen > 0), free(sockopt); sockopt = NULL; return SERVICE_FAILURE,
|
||||
"Failed to get string for gid");
|
||||
sockopt->gid = DecodeUid(stringValue);
|
||||
sockopt->gid = DecodeGid(stringValue);
|
||||
INIT_ERROR_CHECK((sockopt->uid != (uid_t)-1) && (sockopt->gid != (uid_t)-1),
|
||||
free(sockopt); sockopt = NULL; return SERVICE_FAILURE, "Invalid uid or gid");
|
||||
ret = ParseSocketOption(json, sockopt);
|
||||
@ -566,7 +566,7 @@ static int AddServiceFile(cJSON *json, Service *service)
|
||||
}
|
||||
fileOpt->perm = strtoul(opt[SERVICE_FILE_PERM], 0, OCTAL_BASE);
|
||||
fileOpt->uid = DecodeUid(opt[SERVICE_FILE_UID]);
|
||||
fileOpt->gid = DecodeUid(opt[SERVICE_FILE_GID]);
|
||||
fileOpt->gid = DecodeGid(opt[SERVICE_FILE_GID]);
|
||||
if (fileOpt->uid == (uid_t)-1 || fileOpt->gid == (gid_t)-1) {
|
||||
free(fileOpt);
|
||||
fileOpt = NULL;
|
||||
|
@ -48,7 +48,7 @@ float ConvertMicrosecondToSecond(int x)
|
||||
return ((x / THOUSAND_UNIT_INT) / THOUSAND_UNIT_FLOAT);
|
||||
}
|
||||
|
||||
uid_t DecodeUid(const char *name)
|
||||
static uid_t DecodeId(const char *name, bool isUid)
|
||||
{
|
||||
#ifndef __LITEOS_M__
|
||||
INIT_CHECK_RETURN_VALUE(name != NULL, -1);
|
||||
@ -70,13 +70,23 @@ uid_t DecodeUid(const char *name)
|
||||
if (userInf == NULL) {
|
||||
return -1;
|
||||
}
|
||||
return userInf->pw_uid;
|
||||
return isUid ? userInf->pw_uid : userInf->pw_gid;
|
||||
}
|
||||
#else
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
uid_t DecodeUid(const char *name)
|
||||
{
|
||||
return DecodeId(name, true);
|
||||
}
|
||||
|
||||
gid_t DecodeGid(const char *name)
|
||||
{
|
||||
return DecodeId(name, false);
|
||||
}
|
||||
|
||||
char *ReadFileToBuf(const char *configFile)
|
||||
{
|
||||
char *buffer = NULL;
|
||||
|
@ -102,7 +102,7 @@ static int ParseDeviceConfig(char *p)
|
||||
INIT_ERROR_CHECK(errno == 0, config->mode = DEVMODE,
|
||||
"Invalid mode in config file for device node %s. use default mode", config->name);
|
||||
config->uid = (uid_t)DecodeUid(items[DEVICE_CONFIG_UID_NUM]);
|
||||
config->gid = (gid_t)DecodeUid(items[DEVICE_CONFIG_GID_NUM]);
|
||||
config->gid = (gid_t)DecodeGid(items[DEVICE_CONFIG_GID_NUM]);
|
||||
if (count == expectedCount) {
|
||||
config->parameter = strdup(items[DEVICE_CONFIG_PARAM_NUM]); // device parameter
|
||||
} else {
|
||||
@ -142,7 +142,7 @@ static int ParseSysfsConfig(char *p)
|
||||
INIT_ERROR_CHECK(errno == 0, config->mode = DEVMODE,
|
||||
"Invalid mode in config file for sys path %s. use default mode", config->sysPath);
|
||||
config->uid = (uid_t)DecodeUid(items[SYS_CONFIG_UID_NUM]);
|
||||
config->gid = (gid_t)DecodeUid(items[SYS_CONFIG_GID_NUM]);
|
||||
config->gid = (gid_t)DecodeGid(items[SYS_CONFIG_GID_NUM]);
|
||||
ListAddTail(&g_sysDevices, &config->list);
|
||||
FreeStringVector(items, count);
|
||||
return 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user