* src/pwck.c: Removed pw_opened.

* src/pwck.c: optind cannot be greater than argc.
	* src/pwck.c: If spw_opened, then is_shadow is implicitly set.
	* src/pwck.c: Do not report passwd entry without x password and a
	shadow entry in --quiet mode (no interaction with the caller)
	* src/pwck.c: Do not check if the last password change is in the
	future if the time is set to 0.
This commit is contained in:
nekral-guest 2011-11-13 16:24:39 +00:00
parent 3c608e56f6
commit f64c88d629
2 changed files with 24 additions and 12 deletions

View File

@ -1,3 +1,13 @@
2011-11-11 Nicolas François <nicolas.francois@centraliens.net>
* src/pwck.c: Removed pw_opened.
* src/pwck.c: optind cannot be greater than argc.
* src/pwck.c: If spw_opened, then is_shadow is implicitly set.
* src/pwck.c: Do not report passwd entry without x password and a
shadow entry in --quiet mode (no interaction with the caller)
* src/pwck.c: Do not check if the last password change is in the
future if the time is set to 0.
2011-11-11 Nicolas François <nicolas.francois@centraliens.net> 2011-11-11 Nicolas François <nicolas.francois@centraliens.net>
* libmisc/root_flag.c: Drop privileges before changing root. The * libmisc/root_flag.c: Drop privileges before changing root. The

View File

@ -75,7 +75,6 @@ static bool use_system_spw_file = true;
static bool is_shadow = false; static bool is_shadow = false;
static bool pw_opened = false;
static bool spw_opened = false; static bool spw_opened = false;
static bool pw_locked = false; static bool pw_locked = false;
@ -214,7 +213,7 @@ static void process_flags (int argc, char **argv)
/* /*
* Make certain we have the right number of arguments * Make certain we have the right number of arguments
*/ */
if ((argc < optind) || (argc > (optind + 2))) { if (argc > (optind + 2)) {
usage (E_USAGE); usage (E_USAGE);
} }
@ -290,7 +289,6 @@ static void open_files (void)
} }
fail_exit (E_CANTOPEN); fail_exit (E_CANTOPEN);
} }
pw_opened = true;
if (is_shadow && !use_tcb) { if (is_shadow && !use_tcb) {
if (spw_open (read_only ? O_RDONLY : O_RDWR) == 0) { if (spw_open (read_only ? O_RDONLY : O_RDWR) == 0) {
fprintf (stderr, _("%s: cannot open %s\n"), fprintf (stderr, _("%s: cannot open %s\n"),
@ -319,7 +317,7 @@ static void close_files (bool changed)
* changes to the files. * changes to the files.
*/ */
if (changed) { if (changed) {
if (pw_opened && pw_close () == 0) { if (pw_close () == 0) {
fprintf (stderr, fprintf (stderr,
_("%s: failure while writing changes to %s\n"), _("%s: failure while writing changes to %s\n"),
Prog, pw_dbname ()); Prog, pw_dbname ());
@ -330,8 +328,7 @@ static void close_files (bool changed)
} }
fail_exit (E_CANTUPDATE); fail_exit (E_CANTUPDATE);
} }
pw_opened = false; if (spw_opened && (spw_close () == 0)) {
if (is_shadow && spw_opened && (spw_close () == 0)) {
fprintf (stderr, fprintf (stderr,
_("%s: failure while writing changes to %s\n"), _("%s: failure while writing changes to %s\n"),
Prog, spw_dbname ()); Prog, spw_dbname ());
@ -640,7 +637,9 @@ static void check_pw_file (int *errors, bool *changed)
/* The passwd entry has a shadow counterpart. /* The passwd entry has a shadow counterpart.
* Make sure no passwords are in passwd. * Make sure no passwords are in passwd.
*/ */
if (strcmp (pwd->pw_passwd, SHADOW_PASSWD_STRING) != 0) { if ( !quiet
&& (strcmp (pwd->pw_passwd,
SHADOW_PASSWD_STRING) != 0)) {
printf (_("user %s has an entry in %s, but its password field in %s is not set to 'x'\n"), printf (_("user %s has an entry in %s, but its password field in %s is not set to 'x'\n"),
pwd->pw_name, spw_dbname (), pw_dbname ()); pwd->pw_name, spw_dbname (), pw_dbname ());
*errors += 1; *errors += 1;
@ -813,11 +812,14 @@ static void check_spw_file (int *errors, bool *changed)
/* /*
* Warn if last password change in the future. --marekm * Warn if last password change in the future. --marekm
*/ */
if ( !quiet if (!quiet) {
&& (spw->sp_lstchg > (long) time ((time_t *) 0) / SCALE)) { time_t t = time ((time_t *) 0);
printf (_("user %s: last password change in the future\n"), if ( (t != 0)
spw->sp_namp); && (spw->sp_lstchg > (long) t / SCALE)) {
*errors += 1; printf (_("user %s: last password change in the future\n"),
spw->sp_namp);
*errors += 1;
}
} }
} }
} }