Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Startup Init Lite
提交
1439d57f
S
Startup Init Lite
项目概览
OpenHarmony
/
Startup Init Lite
1 年多 前同步成功
通知
3
Star
37
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
Startup Init Lite
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
1439d57f
编写于
6月 10, 2021
作者:
X
xionglei6
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add groupID Signed-off-by
Signed-off-by: xionglei6 <xlei1030> Change-Id: I2a2bea02e0b0b3fb66f46f0cc1741f17c3a915fa
上级
95efba61
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
49 addition
and
6 deletion
+49
-6
services/include/init_service.h
services/include/init_service.h
+2
-1
services/src/init_read_cfg.c
services/src/init_read_cfg.c
+46
-3
services/src/init_service.c
services/src/init_service.c
+1
-2
未找到文件。
services/include/init_service.h
浏览文件 @
1439d57f
...
...
@@ -43,7 +43,8 @@ extern "C" {
typedef
struct
{
uid_t
uID
;
gid_t
gID
;
gid_t
*
gIDs
;
unsigned
int
gidsCnt
;
unsigned
int
*
caps
;
unsigned
int
capsCnt
;
}
Perms
;
...
...
services/src/init_read_cfg.c
浏览文件 @
1439d57f
...
...
@@ -135,7 +135,12 @@ static void ReleaseServiceMem(Service* curServ)
free
(
curServ
->
servPerm
.
caps
);
curServ
->
servPerm
.
caps
=
NULL
;
}
if
(
curServ
->
servPerm
.
gIDs
!=
NULL
)
{
free
(
curServ
->
servPerm
.
gIDs
);
curServ
->
servPerm
.
gIDs
=
NULL
;
}
curServ
->
servPerm
.
capsCnt
=
0
;
curServ
->
servPerm
.
gidsCnt
=
0
;
}
static
int
GetServiceName
(
const
cJSON
*
curArrItem
,
Service
*
curServ
)
...
...
@@ -220,8 +225,6 @@ static int GetServiceNumber(const cJSON* curArrItem, Service* curServ, const cha
if
(
strncmp
(
targetField
,
UID_STR_IN_CFG
,
strlen
(
UID_STR_IN_CFG
))
==
0
)
{
curServ
->
servPerm
.
uID
=
value
;
}
else
if
(
strncmp
(
targetField
,
GID_STR_IN_CFG
,
strlen
(
GID_STR_IN_CFG
))
==
0
)
{
curServ
->
servPerm
.
gID
=
value
;
}
else
if
(
strncmp
(
targetField
,
ONCE_STR_IN_CFG
,
strlen
(
ONCE_STR_IN_CFG
))
==
0
)
{
if
(
value
!=
0
)
{
curServ
->
attribute
|=
SERVICE_ATTR_ONCE
;
...
...
@@ -279,6 +282,46 @@ static int GetServiceCaps(const cJSON* curArrItem, Service* curServ)
return
SERVICE_SUCCESS
;
}
static
int
GetServiceGids
(
const
cJSON
*
curArrItem
,
Service
*
curServ
)
{
curServ
->
servPerm
.
gidsCnt
=
0
;
curServ
->
servPerm
.
gIDs
=
NULL
;
int
gidsCnt
;
cJSON
*
filedJ
=
cJSON_GetObjectItem
(
curArrItem
,
"gid"
);
if
(
cJSON_IsArray
(
filedJ
))
{
gidsCnt
=
cJSON_GetArraySize
(
filedJ
);
if
(
gidsCnt
<=
0
)
{
// gids array does not exist, means do not need any group
return
SERVICE_SUCCESS
;
}
curServ
->
servPerm
.
gIDs
=
(
unsigned
int
*
)
malloc
(
sizeof
(
unsigned
int
)
*
gidsCnt
);
if
(
curServ
->
servPerm
.
gIDs
==
NULL
)
{
return
SERVICE_FAILURE
;
}
for
(
int
i
=
0
;
i
<
gidsCnt
;
++
i
)
{
cJSON
*
gidJ
=
cJSON_GetArrayItem
(
filedJ
,
i
);
if
(
!
cJSON_IsNumber
(
gidJ
)
||
cJSON_GetNumberValue
(
gidJ
)
<
0
)
{
// resources will be released by function: ReleaseServiceMem
return
SERVICE_FAILURE
;
}
curServ
->
servPerm
.
gIDs
[
i
]
=
(
unsigned
int
)
cJSON_GetNumberValue
(
gidJ
);
}
}
else
{
int
value
=
(
int
)
cJSON_GetNumberValue
(
filedJ
);
if
(
value
<
0
)
{
return
SERVICE_FAILURE
;
}
gidsCnt
=
1
;
curServ
->
servPerm
.
gIDs
=
(
unsigned
int
*
)
malloc
(
sizeof
(
unsigned
int
));
if
(
curServ
->
servPerm
.
gIDs
==
NULL
)
{
return
SERVICE_FAILURE
;
}
curServ
->
servPerm
.
gIDs
[
0
]
=
(
unsigned
int
)
value
;
}
curServ
->
servPerm
.
gidsCnt
=
gidsCnt
;
return
SERVICE_SUCCESS
;
}
static
void
ParseAllServices
(
const
cJSON
*
fileRoot
)
{
int
servArrSize
=
0
;
...
...
@@ -311,7 +354,7 @@ static void ParseAllServices(const cJSON* fileRoot)
if
(
GetServiceName
(
curItem
,
&
retServices
[
i
])
!=
SERVICE_SUCCESS
||
GetServicePathAndArgs
(
curItem
,
&
retServices
[
i
])
!=
SERVICE_SUCCESS
||
GetServiceNumber
(
curItem
,
&
retServices
[
i
],
UID_STR_IN_CFG
)
!=
SERVICE_SUCCESS
||
GetService
Number
(
curItem
,
&
retServices
[
i
],
GID_STR_IN_CFG
)
!=
SERVICE_SUCCESS
||
GetService
Gids
(
curItem
,
&
retServices
[
i
]
)
!=
SERVICE_SUCCESS
||
GetServiceNumber
(
curItem
,
&
retServices
[
i
],
ONCE_STR_IN_CFG
)
!=
SERVICE_SUCCESS
||
GetServiceNumber
(
curItem
,
&
retServices
[
i
],
IMPORTANT_STR_IN_CFG
)
!=
SERVICE_SUCCESS
||
GetServiceCaps
(
curItem
,
&
retServices
[
i
])
!=
SERVICE_SUCCESS
)
{
...
...
services/src/init_service.c
浏览文件 @
1439d57f
...
...
@@ -48,8 +48,7 @@ static int SetPerms(const Service *service)
if
(
KeepCapability
()
!=
0
)
{
return
SERVICE_FAILURE
;
}
if
(
setgid
(
service
->
servPerm
.
gID
)
!=
0
)
{
if
(
setgroups
(
service
->
servPerm
.
gidsCnt
,
service
->
servPerm
.
gIDs
)
!=
0
)
{
return
SERVICE_FAILURE
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录