提交 3135a696 编写于 作者: X xionglei6

fix: 修改属性设置错误

Signed-off-by: Nxionglei6 <xionglei6@huawei.com>
上级 9ad8dc2d
......@@ -27,7 +27,7 @@
#define BSH_KEY_CTRLC 0x03 // ctr + c
#define BSH_KEY_ESC 0x1B // ecs
#define BSH_COMMAND_MAX_LENGTH 5 * 1024
#define BSH_COMMAND_MAX_LENGTH (5 * 1024)
#define BSH_PARAMETER_MAX_NUMBER 10
#define BSH_CMD_NAME_END 48
#define BSH_CMD_MAX_KEY 5
......
......@@ -11,23 +11,23 @@
# See the License for the specific language governing permissions and
# limitations under the License.
build_version root:root:0777
hw_sc.build.os.enable root:root:0777
hw_sc.build.os.apiversion root:root:0777
hw_sc.build.os.version root:root:0777
hw_sc.build.os.releasetype root:root:0777
build_version = root:root:0777
hw_sc.build.os.enable = root:root:0777
hw_sc.build.os.apiversion = root:root:0777
hw_sc.build.os.version = root:root:0777
hw_sc.build.os.releasetype = root:root:0777
const.actionable_compatible_property.enabled root:root:0777
const.postinstall.fstab.prefix root:root:0777
const.secure root:root:0777
security.perf_harden root:root:0777
const.allow.mock.location root:root:0777
const.debuggable root:root:0777
persist.sys.usb.config root:root:0777
const.actionable_compatible_property.enabled = root:root:0777
const.postinstall.fstab.prefix = root:root:0777
const.secure = root:root:0777
security.perf_harden = root:root:0777
const.allow.mock.location = root:root:0777
const.debuggable = root:root:0777
persist.sys.usb.config = root:root:0777
# default forbit other user to start service
ohos.servicectrl. system:root:0770
test.permission. root:root:0770
test.permission.read. root:root:0774
test.permission.write. root:root:0772
test.permission.watcher. root:root:0771
\ No newline at end of file
ohos.servicectrl. = system:servicectrl:0775
test.permission. = root:root:0770
test.permission.read. = root:root:0774
test.permission.write. = root:root:0772
test.permission.watcher. = root:root:0771
\ No newline at end of file
......@@ -27,7 +27,7 @@ extern "C" {
// 配置
#define LOOP_EVENT_USE_EPOLL 1
#define LOOP_DEFAULT_BUFFER 1024
#define LOOP_DEFAULT_BUFFER (1024 * 5)
#define LOOP_MAX_BUFFER (1024 * 64)
#define LOOP_MAX_CLIENT 1024
......
......@@ -25,10 +25,9 @@
#define OCT_BASE 8
static ParamSecurityLabel g_localSecurityLabel = {};
static void GetUserIdByName(FILE *fp, uid_t *uid, const char *name, uint32_t nameLen)
static void GetUserIdByName(uid_t *uid, const char *name, uint32_t nameLen)
{
*uid = -1;
(void)fp;
struct passwd *data = NULL;
while ((data = getpwent()) != NULL) {
if ((data->pw_name != NULL) && (strlen(data->pw_name) == nameLen) &&
......@@ -40,10 +39,9 @@ static void GetUserIdByName(FILE *fp, uid_t *uid, const char *name, uint32_t nam
endpwent();
}
static void GetGroupIdByName(FILE *fp, gid_t *gid, const char *name, uint32_t nameLen)
static void GetGroupIdByName(gid_t *gid, const char *name, uint32_t nameLen)
{
*gid = -1;
(void)fp;
struct group *data = NULL;
while ((data = getgrent()) != NULL) {
if ((data->gr_name != NULL) && (strlen(data->gr_name) == nameLen) &&
......@@ -56,7 +54,7 @@ static void GetGroupIdByName(FILE *fp, gid_t *gid, const char *name, uint32_t na
}
// user:group:r|w
static int GetParamDacData(FILE *fpForGroup, FILE *fpForUser, ParamDacData *dacData, const char *value)
static int GetParamDacData(ParamDacData *dacData, const char *value)
{
if (dacData == NULL) {
return -1;
......@@ -69,8 +67,8 @@ static int GetParamDacData(FILE *fpForGroup, FILE *fpForUser, ParamDacData *dacD
if (mode == NULL) {
return -1;
}
GetUserIdByName(fpForUser, &dacData->uid, value, groupName - value);
GetGroupIdByName(fpForGroup, &dacData->gid, groupName + 1, mode - groupName - 1);
GetUserIdByName(&dacData->uid, value, groupName - value);
GetGroupIdByName(&dacData->gid, groupName + 1, mode - groupName - 1);
dacData->mode = strtol(mode + 1, NULL, OCT_BASE);
return 0;
}
......@@ -116,45 +114,49 @@ static int DecodeSecurityLabel(ParamSecurityLabel **srcLabel, const char *buffer
return 0;
}
typedef struct {
SecurityLabelFunc label;
void *context;
} LoadContext;
static int LoadOneParam_ (const uint32_t *context, const char *name, const char *value)
{
LoadContext *loadContext = (LoadContext *)context;
ParamAuditData auditData = {0};
auditData.name = name;
#ifdef STARTUP_INIT_TEST
auditData.label = value;
#endif
int ret = GetParamDacData(&auditData.dacData, value);
PARAM_CHECK(ret == 0, return -1, "Failed to get param info %d %s", ret, name);
ret = loadContext->label(&auditData, loadContext->context);
PARAM_CHECK(ret == 0, return -1, "Failed to write param info %d \"%s\"", ret, name);
return 0;
}
static int LoadParamLabels(const char *fileName, SecurityLabelFunc label, void *context)
{
LoadContext loadContext = {
label, context
};
uint32_t infoCount = 0;
ParamAuditData auditData = {0};
FILE *fpForGroup = fopen(GROUP_FILE_PATH, "r");
FILE *fpForUser = fopen(USER_FILE_PATH, "r");
FILE *fp = fopen(fileName, "r");
char *buff = (char *)calloc(1, PARAM_BUFFER_SIZE);
SubStringInfo *info = calloc(1, sizeof(SubStringInfo) * (SUBSTR_INFO_DAC + 1));
while (fp != NULL && fpForGroup != NULL && fpForUser != NULL &&
info != NULL && buff != NULL && fgets(buff, PARAM_BUFFER_SIZE, fp) != NULL) {
buff[PARAM_BUFFER_SIZE - 1] = '\0';
int subStrNumber = GetSubStringInfo(buff, strlen(buff), ' ', info, SUBSTR_INFO_DAC + 1);
if (subStrNumber <= SUBSTR_INFO_DAC) {
const uint32_t buffSize = PARAM_NAME_LEN_MAX + PARAM_CONST_VALUE_LEN_MAX + 10; // 10 size
char *buff = (char *)calloc(1, buffSize);
while (fp != NULL && buff != NULL && fgets(buff, buffSize, fp) != NULL) {
buff[buffSize - 1] = '\0';
int ret = SpliteString(buff, NULL, 0, LoadOneParam_, (uint32_t *)&loadContext);
if (ret != 0) {
PARAM_LOGE("Failed to splite string %s fileName %s", buff, fileName);
continue;
}
auditData.name = info[SUBSTR_INFO_NAME].value;
#ifdef STARTUP_INIT_TEST
auditData.label = info[SUBSTR_INFO_NAME].value;
#endif
int ret = GetParamDacData(fpForGroup, fpForUser, &auditData.dacData, info[SUBSTR_INFO_DAC].value);
PARAM_CHECK(ret == 0, continue, "Failed to get param info %d %s", ret, buff);
ret = label(&auditData, context);
PARAM_CHECK(ret == 0, continue, "Failed to write param info %d %s", ret, buff);
infoCount++;
}
PARAM_LOGI("Load parameter label total %u success %s", infoCount, fileName);
if (fp != NULL) {
(void)fclose(fp);
}
if (info != NULL) {
free(info);
}
if (fpForGroup != NULL) {
(void)fclose(fpForGroup);
}
if (fpForUser != NULL) {
(void)fclose(fpForUser);
}
if (buff != NULL) {
free(buff);
}
......
......@@ -131,6 +131,16 @@ int SpliteString(char *line, const char *exclude[], uint32_t count,
value++;
}
// Skip spaces
char *tmp = name;
while ((tmp < value) && (*tmp != '\0')) {
if (isspace(*tmp)) {
(*tmp) = '\0';
break;
}
tmp++;
}
// empty name, just ignore this line
if (*value == '\0') {
return 0;
......
......@@ -123,7 +123,7 @@ PARAM_STATIC int AddSecurityLabel(const ParamAuditData *auditData, void *context
PARAM_CHECK(context != NULL, return -1, "Invalid context");
ParamWorkSpace *workSpace = (ParamWorkSpace *)context;
int ret = CheckParamName(auditData->name, 1);
PARAM_CHECK(ret == 0, return ret, "Illegal param name %s", auditData->name);
PARAM_CHECK(ret == 0, return ret, "Illegal param name \"%s\"", auditData->name);
ParamTrieNode *node = FindTrieNode(&workSpace->paramSpace, auditData->name, strlen(auditData->name), NULL);
if (node == NULL) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册