Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Startup Init Lite
提交
854f42c6
S
Startup Init Lite
项目概览
OpenHarmony
/
Startup Init Lite
接近 2 年 前同步成功
通知
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看板
未验证
提交
854f42c6
编写于
12月 19, 2022
作者:
O
openharmony_ci
提交者:
Gitee
12月 19, 2022
浏览文件
操作
浏览文件
下载
差异文件
!1630 系统优化:param shell 添加用户和组
Merge pull request !1630 from cheng_jinsong/init-shell
上级
a9e802b6
a2226a0f
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
52 addition
and
16 deletion
+52
-16
services/begetctl/param_cmd.c
services/begetctl/param_cmd.c
+52
-16
未找到文件。
services/begetctl/param_cmd.c
浏览文件 @
854f42c6
...
...
@@ -380,32 +380,54 @@ static int32_t BShellParamCmdPwd(BShellHandle shell, int32_t argc, char *argv[])
return
0
;
}
void
GetUserInfo
(
uid_t
*
uid
,
gid_t
*
gid
,
char
**
parameter
,
int32_t
argc
,
char
*
argv
[])
{
int32_t
i
=
0
;
*
parameter
=
NULL
;
while
(
i
<
argc
)
{
if
(
strcmp
(
argv
[
i
],
"-p"
)
==
0
&&
((
i
+
1
)
<
argc
))
{
*
parameter
=
argv
[
i
+
1
];
++
i
;
}
else
if
(
strcmp
(
argv
[
i
],
"-u"
)
==
0
&&
((
i
+
1
)
<
argc
))
{
*
uid
=
DecodeUid
(
argv
[
i
+
1
]);
*
uid
=
(
*
uid
==
-
1
)
?
0
:
*
uid
;
++
i
;
}
else
if
(
strcmp
(
argv
[
i
],
"-g"
)
==
0
&&
((
i
+
1
)
<
argc
))
{
*
gid
=
DecodeGid
(
argv
[
i
+
1
]);
*
gid
=
(
*
gid
==
-
1
)
?
0
:
*
gid
;
++
i
;
}
++
i
;
}
}
static
int32_t
BShellParamCmdShell
(
BShellHandle
shell
,
int32_t
argc
,
char
*
argv
[])
{
#ifndef STARTUP_INIT_TEST
BSH_CHECK
(
shell
!=
NULL
,
return
BSH_INVALID_PARAM
,
"Invalid shell env"
);
BSH_LOGV
(
"BShellParamCmdShell %d %s"
,
argc
,
argv
[
1
]);
int
ret
=
0
;
if
(
argc
>
1
)
{
ret
=
SystemCheckParamExist
(
argv
[
1
]);
if
(
ret
!=
0
)
{
BShellEnvOutput
(
shell
,
"Error: parameter
\'
%s
\'
not found
\r\n
"
,
argv
[
1
]);
return
-
1
;
}
}
if
(
tcgetattr
(
0
,
&
g_terminalState
))
{
return
BSH_SYSTEM_ERR
;
}
g_isSetTerminal
=
1
;
uid_t
uid
=
0
;
gid_t
gid
=
0
;
char
*
parameter
=
NULL
;
GetUserInfo
(
&
uid
,
&
gid
,
&
parameter
,
argc
,
argv
);
BSH_LOGV
(
"BShellParamCmdShell %s %d %d argc %d"
,
parameter
,
uid
,
gid
,
argc
);
if
(
parameter
!=
NULL
)
{
ret
=
SystemCheckParamExist
(
parameter
);
if
(
ret
!=
0
)
{
BShellEnvOutput
(
shell
,
"Error: parameter
\'
%s
\'
not found
\r\n
"
,
parameter
);
return
-
1
;
}
}
pid_t
pid
=
fork
();
if
(
pid
==
0
)
{
setuid
(
2000
);
// 2000 shell group
setgid
(
2000
);
// 2000 shell group
#ifdef PARAM_SUPPORT_SELINUX
setcon
(
"u:r:normal_hap_domain:s0"
);
#endif
if
(
argc
>=
2
)
{
// 2 min argc
char
*
args
[]
=
{
SHELL_NAME
,
argv
[
1
],
NULL
};
setuid
(
uid
);
setgid
(
gid
);
if
(
parameter
!=
NULL
)
{
// 2 min argc
char
*
args
[]
=
{
SHELL_NAME
,
parameter
,
NULL
};
ret
=
execv
(
CMD_PATH
,
args
);
}
else
{
char
*
args
[]
=
{
SHELL_NAME
,
NULL
};
...
...
@@ -453,7 +475,8 @@ static int32_t BShellParamCmdRegForIndepent(BShellHandle shell)
{
"param"
,
BShellParamCmdSet
,
"set system parameter"
,
"param set name value"
,
"param set"
},
{
"param"
,
BShellParamCmdWait
,
"wait system parameter"
,
"param wait name [value] [timeout]"
,
"param wait"
},
{
"param"
,
BShellParamCmdDump
,
"dump system parameter"
,
"param dump [verbose]"
,
"param dump"
},
{
"param"
,
BShellParamCmdShell
,
"shell system parameter"
,
"param shell [name]"
,
"param shell"
},
{
"param"
,
BShellParamCmdShell
,
"shell system parameter"
,
"param shell [-p] [name] [-u] [username] [-g] [groupname]"
,
"param shell"
},
};
for
(
size_t
i
=
sizeof
(
infos
)
/
sizeof
(
infos
[
0
]);
i
>
0
;
i
--
)
{
BShellEnvRegisterCmd
(
shell
,
&
infos
[
i
-
1
]);
...
...
@@ -461,8 +484,21 @@ static int32_t BShellParamCmdRegForIndepent(BShellHandle shell)
return
0
;
}
static
void
UpdateInitLogLevel
(
void
)
{
char
level
[
2
]
=
{
0
};
// 2 max length
uint32_t
length
=
sizeof
(
level
);
int
ret
=
SystemGetParameter
(
INIT_DEBUG_LEVEL
,
level
,
&
length
);
if
(
ret
==
0
)
{
errno
=
0
;
InitLogLevel
value
=
(
InitLogLevel
)
strtoul
(
level
,
NULL
,
DECIMAL_BASE
);
SetInitLogLevel
((
errno
!=
0
)
?
INIT_WARN
:
value
);
}
}
int32_t
BShellParamCmdRegister
(
BShellHandle
shell
,
int
execMode
)
{
UpdateInitLogLevel
();
if
(
execMode
)
{
BShellParamCmdRegForShell
(
shell
);
}
else
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录