]> granicus.if.org Git - shadow/commitdiff
Additional PAM cleanup:
authornekral-guest <nekral-guest@5a98b0ae-9ef6-0310-add3-de5d479b70d7>
Sat, 6 Sep 2008 23:46:44 +0000 (23:46 +0000)
committernekral-guest <nekral-guest@5a98b0ae-9ef6-0310-add3-de5d479b70d7>
Sat, 6 Sep 2008 23:46:44 +0000 (23:46 +0000)
* src/userdel.c, src/newusers.c, src/chpasswd.c, src/chfn.c,
src/groupmems.c, src/usermod.c, src/groupdel.c, src/chgpasswd.c,
src/useradd.c, src/groupmod.c, src/groupadd.c, src/chage.c,
src/chsh.c: If the username cannot be determined, report it as
such (not a PAM authentication failure).

14 files changed:
ChangeLog
src/chage.c
src/chfn.c
src/chgpasswd.c
src/chpasswd.c
src/chsh.c
src/groupadd.c
src/groupdel.c
src/groupmems.c
src/groupmod.c
src/newusers.c
src/useradd.c
src/userdel.c
src/usermod.c

index f0b77dd3e28eec4c2dee83882dc2e8febe0529a4..7a5099f1bc23c0e13981e231bf42b4376d9a81a5 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -56,7 +56,8 @@
        src/useradd.c, src/groupmod.c, src/groupadd.c, src/chage.c,
        src/chsh.c: Simplify the PAM error handling. Do not keep the pamh
        handle, but terminate the PAM transaction as soon as possible if
-       there are no PAM session opened.
+       there are no PAM session opened. If the username cannot be
+       determined, report it as such (not a PAM authentication failure).
        * src/useradd.c, src/userdel.c, src/usermod.c: It is no more
        needed to initialize retval to PAM_SUCCESS.
 
index 680b57d98435b343095ef4be028814a3c5d0171e..e7dad8b90f96371e6d1ec2d15c467507ceba432e 100644 (file)
@@ -509,11 +509,14 @@ static void check_perms (void)
 #ifdef USE_PAM
        pampw = getpwuid (getuid ()); /* local, no need for xgetpwuid */
        if (NULL == pampw) {
-               retval = PAM_USER_UNKNOWN;
-       } else {
-               retval = pam_start ("chage", pampw->pw_name, &conv, &pamh);
+               fprintf (stderr,
+                        _("%s: Cannot determine your user name.\n"),
+                        Prog);
+               exit (E_NOPERM);
        }
 
+       retval = pam_start ("chage", pampw->pw_name, &conv, &pamh);
+
        if (PAM_SUCCESS == retval) {
                retval = pam_authenticate (pamh, 0);
        }
index 0137a9cf9b9b1d5e1b6f87180c12b9b8dcbcb7f9..c73ef8c5fdafe261c8a9697a499e59c33ecf14a8 100644 (file)
@@ -377,11 +377,14 @@ static void check_perms (const struct passwd *pw)
 #else                          /* !USE_PAM */
        pampw = getpwuid (getuid ()); /* local, no need for xgetpwuid */
        if (NULL == pampw) {
-               retval = PAM_USER_UNKNOWN;
-       } else {
-               retval = pam_start ("chfn", pampw->pw_name, &conv, &pamh);
+               fprintf (stderr,
+                        _("%s: Cannot determine your user name.\n"),
+                        Prog);
+               exit (E_NOPERM);
        }
 
+       retval = pam_start ("chfn", pampw->pw_name, &conv, &pamh);
+
        if (PAM_SUCCESS == retval) {
                retval = pam_authenticate (pamh, 0);
        }
index 011c009fe5e0fd74e8df23b6929c22484ca27273..d1ffe3923944181cda30d065aab6607373123c4c 100644 (file)
@@ -256,11 +256,14 @@ static void check_perms (void)
 
        pampw = getpwuid (getuid ()); /* local, no need for xgetpwuid */
        if (NULL == pampw) {
-               retval = PAM_USER_UNKNOWN;
-       } else {
-               retval = pam_start ("chgpasswd", pampw->pw_name, &conv, &pamh);
+               fprintf (stderr,
+                        _("%s: Cannot determine your user name.\n"),
+                        Prog);
+               exit (1);
        }
 
+       retval = pam_start ("chgpasswd", pampw->pw_name, &conv, &pamh);
+
        if (PAM_SUCCESS == retval) {
                retval = pam_authenticate (pamh, 0);
        }
index 014a25ae47f0ecb3a8c27e7ca730e82610876697..9a6267558c6250fb1efa0bec3627f67ca4554524 100644 (file)
@@ -250,11 +250,14 @@ static void check_perms (void)
 
        pampw = getpwuid (getuid ()); /* local, no need for xgetpwuid */
        if (NULL == pampw) {
-               retval = PAM_USER_UNKNOWN;
-       } else {
-               retval = pam_start ("chpasswd", pampw->pw_name, &conv, &pamh);
+               fprintf (stderr,
+                        _("%s: Cannot determine your user name.\n"),
+                        Prog);
+               exit (1);
        }
 
+       retval = pam_start ("chpasswd", pampw->pw_name, &conv, &pamh);
+
        if (PAM_SUCCESS == retval) {
                retval = pam_authenticate (pamh, 0);
        }
index 269b7a150a3cb714e12d68a1dc0e308751b24da5..a33be57b3ab63ee0a9216992aea109dc2f192587 100644 (file)
@@ -306,11 +306,14 @@ static void check_perms (const struct passwd *pw)
 #else                          /* !USE_PAM */
        pampw = getpwuid (getuid ()); /* local, no need for xgetpwuid */
        if (NULL == pampw) {
-               retval = PAM_USER_UNKNOWN;
-       } else {
-               retval = pam_start ("chsh", pampw->pw_name, &conv, &pamh);
+               fprintf (stderr,
+                        _("%s: Cannot determine your user name.\n"),
+                        Prog);
+               exit (E_NOPERM);
        }
 
+       retval = pam_start ("chsh", pampw->pw_name, &conv, &pamh);
+
        if (PAM_SUCCESS == retval) {
                retval = pam_authenticate (pamh, 0);
        }
index c7c7c28c70906fc6e2d856f6946ad8cdd5d0331f..6cc07a4953ed14c364e40eb4c45e4e6804428344 100644 (file)
@@ -575,11 +575,14 @@ static void check_perms (void)
 
        pampw = getpwuid (getuid ()); /* local, no need for xgetpwuid */
        if (NULL == pampw) {
-               retval = PAM_USER_UNKNOWN;
-       } else {
-               retval = pam_start ("groupadd", pampw->pw_name, &conv, &pamh);
+               fprintf (stderr,
+                        _("%s: Cannot determine your user name.\n"),
+                        Prog);
+               exit (1);
        }
 
+       retval = pam_start ("groupadd", pampw->pw_name, &conv, &pamh);
+
        if (PAM_SUCCESS == retval) {
                retval = pam_authenticate (pamh, 0);
        }
index c1245e1ad1e938d3301532320e7a90ebd8242d78..1968b953e9986825fa90f7c153787207c9910d37 100644 (file)
@@ -346,11 +346,13 @@ int main (int argc, char **argv)
                struct passwd *pampw;
                pampw = getpwuid (getuid ()); /* local, no need for xgetpwuid */
                if (pampw == NULL) {
-                       retval = PAM_USER_UNKNOWN;
-               } else {
-                       retval = pam_start ("groupdel", pampw->pw_name,
-                                           &conv, &pamh);
+                       fprintf (stderr,
+                                _("%s: Cannot determine your user name.\n"),
+                                Prog);
+                       exit (1);
                }
+
+               retval = pam_start ("groupdel", pampw->pw_name, &conv, &pamh);
        }
 
        if (PAM_SUCCESS == retval) {
index bdad3ac86a33a68569d056c492fbc86f107afe8d..8c1ff669ee508f96578c4a02fc390159c80547c4 100644 (file)
@@ -445,12 +445,14 @@ static void check_perms (void)
 
                pampw = getpwuid (getuid ()); /* local, no need for xgetpwuid */
                if (NULL == pampw) {
-                       retval = PAM_USER_UNKNOWN;
-               } else {
-                       retval = pam_start ("groupmems", pampw->pw_name,
-                                           &conv, &pamh);
+                       fprintf (stderr,
+                                _("%s: Cannot determine your user name.\n"),
+                                Prog);
+                       fail_exit (1);
                }
 
+               retval = pam_start ("groupmems", pampw->pw_name, &conv, &pamh);
+
                if (PAM_SUCCESS == retval) {
                        retval = pam_authenticate (pamh, 0);
                }
index 13362b15a94b26280cadc220cc2a6d90b06815c2..d4a277cc021e4c9519913ce40ed50ecec620b539 100644 (file)
@@ -711,11 +711,13 @@ int main (int argc, char **argv)
                struct passwd *pampw;
                pampw = getpwuid (getuid ()); /* local, no need for xgetpwuid */
                if (NULL == pamh) {
-                       retval = PAM_USER_UNKNOWN;
-               } else {
-                       retval = pam_start ("groupmod", pampw->pw_name,
-                                           &conv, &pamh);
+                       fprintf (stderr,
+                                _("%s: Cannot determine your user name.\n"),
+                                Prog);
+                       fail_exit (1);
                }
+
+               retval = pam_start ("groupmod", pampw->pw_name, &conv, &pamh);
        }
 
        if (PAM_SUCCESS == retval) {
index 1eefb7e243a454680c2398fa81d75ad51d91a7f0..209a4b4e093b2ceb13a3e82131a46c8885a0235b 100644 (file)
@@ -571,11 +571,14 @@ static void check_perms (void)
 
        pampw = getpwuid (getuid ()); /* local, no need for xgetpwuid */
        if (NULL == pampw) {
-               retval = PAM_USER_UNKNOWN;
-       } else {
-               retval = pam_start ("newusers", pampw->pw_name, &conv, &pamh);
+               fprintf (stderr,
+                        _("%s: Cannot determine your user name.\n"),
+                        Prog);
+               fail_exit (1);
        }
 
+       retval = pam_start ("newusers", pampw->pw_name, &conv, &pamh);
+
        if (PAM_SUCCESS == retval) {
                retval = pam_authenticate (pamh, 0);
        }
index dba04f0ccd001a69e9985fa48767b264bfaab604..af234d87fc2e830f8322d0e5f3eb72b26a408602 100644 (file)
@@ -1795,11 +1795,13 @@ int main (int argc, char **argv)
                struct passwd *pampw;
                pampw = getpwuid (getuid ()); /* local, no need for xgetpwuid */
                if (pampw == NULL) {
-                       retval = PAM_USER_UNKNOWN;
-               } else {
-                       retval = pam_start ("useradd", pampw->pw_name,
-                                           &conv, &pamh);
+                       fprintf (stderr,
+                                _("%s: Cannot determine your user name.\n"),
+                                Prog);
+                       fail_exit (1);
                }
+
+               retval = pam_start ("useradd", pampw->pw_name, &conv, &pamh);
        }
 
        if (PAM_SUCCESS == retval) {
index 6559785b70bf75e64bc3ec411843d6151a02d200..b59d58a624d387c62beb6669e3efa63ceceac062 100644 (file)
@@ -840,11 +840,13 @@ int main (int argc, char **argv)
                struct passwd *pampw;
                pampw = getpwuid (getuid ()); /* local, no need for xgetpwuid */
                if (pampw == NULL) {
-                       retval = PAM_USER_UNKNOWN;
-               } else {
-                       retval = pam_start ("userdel", pampw->pw_name,
-                                           &conv, &pamh);
+                       fprintf (stderr,
+                                _("%s: Cannot determine your user name.\n"),
+                                Prog);
+                       exit (E_PW_UPDATE);
                }
+
+               retval = pam_start ("userdel", pampw->pw_name, &conv, &pamh);
        }
 
        if (PAM_SUCCESS == retval) {
index 709e2984d6061dd6919eabeb6dfdb4629fca59c9..d5bb3ba435e34dc457aa06881e217869bac31d2e 100644 (file)
@@ -1661,11 +1661,13 @@ int main (int argc, char **argv)
                struct passwd *pampw;
                pampw = getpwuid (getuid ()); /* local, no need for xgetpwuid */
                if (pampw == NULL) {
-                       retval = PAM_USER_UNKNOWN;
-               } else {
-                       retval = pam_start ("usermod", pampw->pw_name,
-                                           &conv, &pamh);
+                       fprintf (stderr,
+                                _("%s: Cannot determine your user name.\n"),
+                                Prog);
+                       exit (1);
                }
+
+               retval = pam_start ("usermod", pampw->pw_name, &conv, &pamh);
        }
 
        if (PAM_SUCCESS == retval) {