run: default run0 to root explicitly
When neither --user=, --area= nor --empower is given, run0 already behaves as if root was requested, but only implicitly. That can be misleading downstream. Set arg_exec_user to "root" up front in parse_argv_sudo_mode(), so the intent is visible and the rest of the code can rely on it. Fixes #40468 Signed-off-by: Shihao Ren <renshihao.rsh@bytedance.com>
This commit is contained in:
committed by
Lennart Poettering
parent
977dc1784b
commit
4fb350a46a
+9
-3
@@ -968,14 +968,20 @@ static int parse_argv_sudo_mode(int argc, char *argv[]) {
|
||||
arg_working_directory = mfree(arg_working_directory);
|
||||
}
|
||||
|
||||
if (!arg_exec_user && (arg_area || arg_empower)) {
|
||||
if (!arg_exec_user) {
|
||||
/* If the user specifies --area= but not --user= then consider this an area switch request,
|
||||
* and default to logging into our own account.
|
||||
*
|
||||
* If the user specifies --empower but not --user= then consider this a request to empower
|
||||
* the current user. */
|
||||
* the current user.
|
||||
*
|
||||
* If neither --user=, --area= nor --empower is specified, default to switching to root
|
||||
* explicitly. */
|
||||
|
||||
arg_exec_user = getusername_malloc();
|
||||
if (arg_area || arg_empower)
|
||||
arg_exec_user = getusername_malloc();
|
||||
else
|
||||
arg_exec_user = strdup("root");
|
||||
if (!arg_exec_user)
|
||||
return log_oom();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user