Additional PAM cleanup:

* 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).
This commit is contained in:
nekral-guest 2008-09-06 23:46:44 +00:00
parent 49f0d8b680
commit bab84a13ff
14 changed files with 80 additions and 46 deletions

View File

@ -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.

View 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);
}

View 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);
}

View 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);
}

View 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);
}

View 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);
}

View 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);
}

View 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) {

View 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);
}

View 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) {

View 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);
}

View 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) {

View 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) {

View 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) {