diff options
author | Karel Zak | 2016-10-14 15:28:00 +0200 |
---|---|---|
committer | Karel Zak | 2017-09-18 11:48:56 +0200 |
commit | 9303158534111b1451dac4ee2f2e2daf60ee2f68 (patch) | |
tree | 212de5955cbdb54208535125aa851150c11a1030 /login-utils | |
parent | su: cleanup setenv related code (diff) | |
download | kernel-qcow2-util-linux-9303158534111b1451dac4ee2f2e2daf60ee2f68.tar.gz kernel-qcow2-util-linux-9303158534111b1451dac4ee2f2e2daf60ee2f68.tar.xz kernel-qcow2-util-linux-9303158534111b1451dac4ee2f2e2daf60ee2f68.zip |
su: cleanup setuid/gid related code
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'login-utils')
-rw-r--r-- | login-utils/su-common.c | 29 |
1 files changed, 12 insertions, 17 deletions
diff --git a/login-utils/su-common.c b/login-utils/su-common.c index 59360e4af..ec1869e0f 100644 --- a/login-utils/su-common.c +++ b/login-utils/su-common.c @@ -469,35 +469,30 @@ static void modify_environment(struct su_context *su, const char *shell) supam_export_environment(su); } -/* Become the user and group(s) specified by PW. */ - -static void -init_groups(struct su_context *su, gid_t * groups, size_t num_groups) +static void init_groups(struct su_context *su, gid_t *groups, size_t ngroups) { - int retval; + int rc; errno = 0; - - if (num_groups) - retval = setgroups(num_groups, groups); + if (ngroups) + rc = setgroups(ngroups, groups); else - retval = initgroups(su->pwd->pw_name, su->pwd->pw_gid); + rc = initgroups(su->pwd->pw_name, su->pwd->pw_gid); - if (retval == -1) { + if (rc == -1) { supam_cleanup(su, PAM_ABORT); err(EXIT_FAILURE, _("cannot set groups")); } endgrent(); - retval = pam_setcred(su->pamh, PAM_ESTABLISH_CRED); - if (is_pam_failure(retval)) - errx(EXIT_FAILURE, "%s", pam_strerror(su->pamh, retval)); - else - su->pam_has_cred = 1; + rc = pam_setcred(su->pamh, PAM_ESTABLISH_CRED); + if (is_pam_failure(rc)) + errx(EXIT_FAILURE, _("failed to user credentials: %s"), + pam_strerror(su->pamh, rc)); + su->pam_has_cred = 1; } -static void -change_identity (const struct passwd * const pw) +static void change_identity(const struct passwd *pw) { if (setgid(pw->pw_gid)) err(EXIT_FAILURE, _("cannot set group id")); |