]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
su: cleanup setuid/gid related code
authorKarel Zak <kzak@redhat.com>
Fri, 14 Oct 2016 13:28:00 +0000 (15:28 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 18 Sep 2017 09:48:56 +0000 (11:48 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
login-utils/su-common.c

index 59360e4af772a09dd2d21f6ae6414d114a377a26..ec1869e0f6293021ee031b496992f2dfd89bbc12 100644 (file)
@@ -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"));