From: Mike Yuan Date: Sun, 8 Oct 2023 05:44:37 +0000 (+0800) Subject: core/execute: modernize get_fixed_{user,group} X-Git-Tag: v255-rc1~287^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1c9433559a40982785011aa187e2b34420a67e7e;p=thirdparty%2Fsystemd.git core/execute: modernize get_fixed_{user,group} No functional change, preparation for later commit. --- diff --git a/src/core/execute.c b/src/core/execute.c index dc7f17f0981..04f6bcd703e 100644 --- a/src/core/execute.c +++ b/src/core/execute.c @@ -989,44 +989,45 @@ restore_stdio: return r; } -static int get_fixed_user(const ExecContext *c, const char **user, - uid_t *uid, gid_t *gid, - const char **home, const char **shell) { - int r; - const char *name; +static int get_fixed_user( + const char *username, + const char **ret_user, + uid_t *ret_uid, + gid_t *ret_gid, + const char **ret_home, + const char **ret_shell) { - assert(c); + int r; - if (!c->user) - return 0; + assert(username); + assert(ret_user); /* Note that we don't set $HOME or $SHELL if they are not particularly enlightening anyway * (i.e. are "/" or "/bin/nologin"). */ - name = c->user; - r = get_user_creds(&name, uid, gid, home, shell, USER_CREDS_CLEAN); + r = get_user_creds(&username, ret_uid, ret_gid, ret_home, ret_shell, USER_CREDS_CLEAN); if (r < 0) return r; - *user = name; + *ret_user = username; return 0; } -static int get_fixed_group(const ExecContext *c, const char **group, gid_t *gid) { - int r; - const char *name; +static int get_fixed_group( + const char *groupname, + const char **ret_group, + gid_t *ret_gid) { - assert(c); + int r; - if (!c->group) - return 0; + assert(groupname); + assert(ret_group); - name = c->group; - r = get_group_creds(&name, gid, 0); + r = get_group_creds(&groupname, ret_gid, /* flags = */ 0); if (r < 0) return r; - *group = name; + *ret_group = groupname; return 0; } @@ -4153,16 +4154,20 @@ static int exec_child( username = runtime->dynamic_creds->user->name; } else { - r = get_fixed_user(context, &username, &uid, &gid, &home, &shell); - if (r < 0) { - *exit_status = EXIT_USER; - return log_unit_error_errno(unit, r, "Failed to determine user credentials: %m"); + if (context->user) { + r = get_fixed_user(context->user, &username, &uid, &gid, &home, &shell); + if (r < 0) { + *exit_status = EXIT_USER; + return log_unit_error_errno(unit, r, "Failed to determine user credentials: %m"); + } } - r = get_fixed_group(context, &groupname, &gid); - if (r < 0) { - *exit_status = EXIT_GROUP; - return log_unit_error_errno(unit, r, "Failed to determine group credentials: %m"); + if (context->group) { + r = get_fixed_group(context->group, &groupname, &gid); + if (r < 0) { + *exit_status = EXIT_GROUP; + return log_unit_error_errno(unit, r, "Failed to determine group credentials: %m"); + } } }