* src/chage.c: Remove cleanup(). pw_lock is never called. Replace

cleanup(2) by spw_unlock and remove the calls to cleanup(1).
* src/chage.c: Remove variable pwrw. It is always set to 0. The
  password database is always read only.
This commit is contained in:
nekral-guest 2007-11-17 20:09:54 +00:00
parent cbb2911b7f
commit 24cfb1c158
2 changed files with 17 additions and 33 deletions

View File

@ -1,3 +1,10 @@
2007-11-17 Nicolas François <nicolas.francois@centraliens.net>
* src/chage.c: Remove cleanup(). pw_lock is never called. Replace
cleanup(2) by spw_unlock and remove the calls to cleanup(1).
* src/chage.c: Remove variable pwrw. It is always set to 0. The
password database is always read only.
2007-11-17 Nicolas François <nicolas.francois@centraliens.net> 2007-11-17 Nicolas François <nicolas.francois@centraliens.net>
Fixes from Openwall patch shadow-4.0.4.1-alt-man.diff: Fixes from Openwall patch shadow-4.0.4.1-alt-man.diff:

View File

@ -83,7 +83,6 @@ static void date_to_str (char *, size_t, time_t);
static int new_fields (void); static int new_fields (void);
static void print_date (time_t); static void print_date (time_t);
static void list_fields (void); static void list_fields (void);
static void cleanup (int);
/* /*
* isnum - determine whether or not a string is a number * isnum - determine whether or not a string is a number
@ -297,24 +296,6 @@ static void list_fields (void)
warndays); warndays);
} }
/*
* cleanup - unlock any locked password files
*/
static void cleanup (int state)
{
switch (state) {
case 2:
if (locks)
spw_unlock ();
case 1:
if (locks)
pw_unlock ();
case 0:
break;
}
}
/* /*
* chage - change a user's password aging information * chage - change a user's password aging information
* *
@ -341,7 +322,7 @@ int main (int argc, char **argv)
const struct spwd *sp; const struct spwd *sp;
struct spwd spwd; struct spwd spwd;
uid_t ruid; uid_t ruid;
int amroot, pwrw; int amroot;
const struct passwd *pw; const struct passwd *pw;
struct passwd pwent; struct passwd pwent;
char name[BUFSIZ]; char name[BUFSIZ];
@ -511,10 +492,8 @@ int main (int argc, char **argv)
* file entries into memory. Then we get a pointer to the password * file entries into memory. Then we get a pointer to the password
* file entry for the requested user. * file entry for the requested user.
*/ */
pwrw = 0; if (!pw_open (O_RDONLY)) {
if (!pw_open (pwrw ? O_RDWR : O_RDONLY)) {
fprintf (stderr, _("%s: can't open password file\n"), Prog); fprintf (stderr, _("%s: can't open password file\n"), Prog);
cleanup (1);
SYSLOG ((LOG_ERR, "failed opening %s", PASSWD_FILE)); SYSLOG ((LOG_ERR, "failed opening %s", PASSWD_FILE));
closelog (); closelog ();
exit (E_NOPERM); exit (E_NOPERM);
@ -522,7 +501,6 @@ int main (int argc, char **argv)
if (!(pw = pw_locate (argv[optind]))) { if (!(pw = pw_locate (argv[optind]))) {
fprintf (stderr, _("%s: unknown user %s\n"), Prog, fprintf (stderr, _("%s: unknown user %s\n"), Prog,
argv[optind]); argv[optind]);
cleanup (1);
closelog (); closelog ();
exit (E_NOPERM); exit (E_NOPERM);
} }
@ -548,7 +526,6 @@ int main (int argc, char **argv)
if (locks && !spw_lock ()) { if (locks && !spw_lock ()) {
fprintf (stderr, fprintf (stderr,
_("%s: can't lock shadow password file\n"), Prog); _("%s: can't lock shadow password file\n"), Prog);
cleanup (1);
SYSLOG ((LOG_ERR, "failed locking %s", SHADOW_FILE)); SYSLOG ((LOG_ERR, "failed locking %s", SHADOW_FILE));
closelog (); closelog ();
#ifdef WITH_AUDIT #ifdef WITH_AUDIT
@ -560,7 +537,7 @@ int main (int argc, char **argv)
if (!spw_open (locks ? O_RDWR : O_RDONLY)) { if (!spw_open (locks ? O_RDWR : O_RDONLY)) {
fprintf (stderr, fprintf (stderr,
_("%s: can't open shadow password file\n"), Prog); _("%s: can't open shadow password file\n"), Prog);
cleanup (2); spw_unlock ();
SYSLOG ((LOG_ERR, "failed opening %s", SHADOW_FILE)); SYSLOG ((LOG_ERR, "failed opening %s", SHADOW_FILE));
closelog (); closelog ();
#ifdef WITH_AUDIT #ifdef WITH_AUDIT
@ -666,7 +643,7 @@ int main (int argc, char **argv)
pw->pw_name, pw->pw_uid, 1); pw->pw_name, pw->pw_uid, 1);
#endif #endif
list_fields (); list_fields ();
cleanup (2); spw_unlock ();
closelog (); closelog ();
exit (E_SUCCESS); exit (E_SUCCESS);
} }
@ -680,7 +657,7 @@ int main (int argc, char **argv)
if (!new_fields ()) { if (!new_fields ()) {
fprintf (stderr, _("%s: error changing fields\n"), fprintf (stderr, _("%s: error changing fields\n"),
Prog); Prog);
cleanup (2); spw_unlock ();
closelog (); closelog ();
#ifdef WITH_AUDIT #ifdef WITH_AUDIT
audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "change age", audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "change age",
@ -712,7 +689,7 @@ int main (int argc, char **argv)
if (!pw_update (&pwent)) { if (!pw_update (&pwent)) {
fprintf (stderr, fprintf (stderr,
_("%s: can't update password file\n"), Prog); _("%s: can't update password file\n"), Prog);
cleanup (2); spw_unlock ();
SYSLOG ((LOG_ERR, "failed updating %s", PASSWD_FILE)); SYSLOG ((LOG_ERR, "failed updating %s", PASSWD_FILE));
closelog (); closelog ();
#ifdef WITH_AUDIT #ifdef WITH_AUDIT
@ -738,7 +715,7 @@ int main (int argc, char **argv)
if (!spw_update (&spwd)) { if (!spw_update (&spwd)) {
fprintf (stderr, fprintf (stderr,
_("%s: can't update shadow password file\n"), Prog); _("%s: can't update shadow password file\n"), Prog);
cleanup (2); spw_unlock ();
SYSLOG ((LOG_ERR, "failed updating %s", SHADOW_FILE)); SYSLOG ((LOG_ERR, "failed updating %s", SHADOW_FILE));
closelog (); closelog ();
#ifdef WITH_AUDIT #ifdef WITH_AUDIT
@ -755,7 +732,7 @@ int main (int argc, char **argv)
if (!spw_close ()) { if (!spw_close ()) {
fprintf (stderr, fprintf (stderr,
_("%s: can't rewrite shadow password file\n"), Prog); _("%s: can't rewrite shadow password file\n"), Prog);
cleanup (2); spw_unlock ();
SYSLOG ((LOG_ERR, "failed rewriting %s", SHADOW_FILE)); SYSLOG ((LOG_ERR, "failed rewriting %s", SHADOW_FILE));
closelog (); closelog ();
#ifdef WITH_AUDIT #ifdef WITH_AUDIT
@ -771,7 +748,7 @@ int main (int argc, char **argv)
*/ */
if (!pw_close ()) { if (!pw_close ()) {
fprintf (stderr, _("%s: can't rewrite password file\n"), Prog); fprintf (stderr, _("%s: can't rewrite password file\n"), Prog);
cleanup (2); spw_unlock ();
SYSLOG ((LOG_ERR, "failed rewriting %s", PASSWD_FILE)); SYSLOG ((LOG_ERR, "failed rewriting %s", PASSWD_FILE));
closelog (); closelog ();
#ifdef WITH_AUDIT #ifdef WITH_AUDIT
@ -780,7 +757,7 @@ int main (int argc, char **argv)
#endif #endif
exit (E_NOPERM); exit (E_NOPERM);
} }
cleanup (2); spw_unlock ();
SYSLOG ((LOG_INFO, "changed password expiry for %s", name)); SYSLOG ((LOG_INFO, "changed password expiry for %s", name));
#ifdef USE_PAM #ifdef USE_PAM