Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Startup Init Lite
提交
a402070f
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看板
未验证
提交
a402070f
编写于
12月 07, 2022
作者:
O
openharmony_ci
提交者:
Gitee
12月 07, 2022
浏览文件
操作
浏览文件
下载
差异文件
!1604 添加通过usename和groupname获取uid和gid的命令
Merge pull request !1604 from Mupceet/master_cc_add_dac_cmd
上级
ed0c7fd9
31647559
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
56 addition
and
0 deletion
+56
-0
services/begetctl/BUILD.gn
services/begetctl/BUILD.gn
+1
-0
services/begetctl/begetctl_cmd.c
services/begetctl/begetctl_cmd.c
+55
-0
未找到文件。
services/begetctl/BUILD.gn
浏览文件 @
a402070f
...
...
@@ -61,6 +61,7 @@ if (defined(ohos_lite)) {
ohos_executable("begetctl") {
sources = [
"begetctl_cmd.c",
"bootchart_cmd.c",
"dump_service.c",
"init_cmd_reboot.c",
...
...
services/begetctl/begetctl_cmd.c
浏览文件 @
a402070f
...
...
@@ -15,6 +15,9 @@
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <grp.h>
#include <pwd.h>
#include <dirent.h>
#include "begetctl.h"
#include "init_utils.h"
...
...
@@ -86,12 +89,64 @@ static int32_t GetInitLogLevelFromParam(BShellHandle shell, int argc, char **arg
return
0
;
}
static
int32_t
GetUidByName
(
BShellHandle
shell
,
int
argc
,
char
**
argv
)
{
if
(
argc
!=
2
)
{
// 2 is dac get uid parameter number
char
*
helpArgs
[]
=
{
"dac"
,
NULL
};
BShellCmdHelp
(
shell
,
1
,
helpArgs
);
return
0
;
}
struct
passwd
*
data
=
getpwnam
(
argv
[
1
]);
if
(
data
==
NULL
)
{
printf
(
"getpwnam uid failed
\n
"
);
}
else
{
printf
(
"getpwnam uid %s : %d
\n
"
,
argv
[
1
],
data
->
pw_uid
);
}
data
=
NULL
;
while
((
data
=
getpwent
())
!=
NULL
)
{
if
((
data
->
pw_name
!=
NULL
)
&&
(
strcmp
(
data
->
pw_name
,
argv
[
1
])
==
0
))
{
printf
(
"getpwent uid %s : %d
\n
"
,
argv
[
1
],
data
->
pw_uid
);
break
;
}
}
endpwent
();
return
0
;
}
static
int32_t
GetGidByName
(
BShellHandle
shell
,
int
argc
,
char
**
argv
)
{
if
(
argc
!=
2
)
{
// 2 is dac get gid parameter number
char
*
helpArgs
[]
=
{
"dac"
,
NULL
};
BShellCmdHelp
(
shell
,
1
,
helpArgs
);
return
0
;
}
struct
group
*
data
=
getgrnam
(
argv
[
1
]);
if
(
data
==
NULL
)
{
printf
(
"getgrnam gid failed
\n
"
);
}
else
{
printf
(
"getgrnam gid %s : %d
\n
"
,
argv
[
1
],
data
->
gr_gid
);
}
data
=
NULL
;
while
((
data
=
getgrent
())
!=
NULL
)
{
if
((
data
->
gr_name
!=
NULL
)
&&
(
strcmp
(
data
->
gr_name
,
argv
[
1
])
==
0
))
{
printf
(
"getgrent gid %s : %d
\n
"
,
argv
[
1
],
data
->
gr_gid
);
break
;
}
}
endgrent
();
return
0
;
}
MODULE_CONSTRUCTOR
(
void
)
{
const
CmdInfo
infos
[]
=
{
{
"set"
,
SetInitLogLevelFromParam
,
"set init log level 0:debug, 1:info, 2:warning, 3:err, 4:fatal"
,
"set log level"
,
"set log level"
},
{
"get"
,
GetInitLogLevelFromParam
,
"get init log level"
,
"get log level"
,
"get log level"
},
{
"dac"
,
GetGidByName
,
"get dac gid by group name"
,
"dac gid groupname"
,
"dac gid"
},
{
"dac"
,
GetUidByName
,
"get dac uid by user name"
,
"dac uid username"
,
"dac uid"
},
};
for
(
size_t
i
=
0
;
i
<
sizeof
(
infos
)
/
sizeof
(
infos
[
0
]);
i
++
)
{
BShellEnvRegisterCmd
(
GetShellHandle
(),
&
infos
[
i
]);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录