+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>
* libmisc/root_flag.c: Drop privileges before changing root. The
static bool is_shadow = false;
-static bool pw_opened = false;
static bool spw_opened = false;
static bool pw_locked = false;
/*
* Make certain we have the right number of arguments
*/
- if ((argc < optind) || (argc > (optind + 2))) {
+ if (argc > (optind + 2)) {
usage (E_USAGE);
}
}
fail_exit (E_CANTOPEN);
}
- pw_opened = true;
if (is_shadow && !use_tcb) {
if (spw_open (read_only ? O_RDONLY : O_RDWR) == 0) {
fprintf (stderr, _("%s: cannot open %s\n"),
* changes to the files.
*/
if (changed) {
- if (pw_opened && pw_close () == 0) {
+ if (pw_close () == 0) {
fprintf (stderr,
_("%s: failure while writing changes to %s\n"),
Prog, pw_dbname ());
}
fail_exit (E_CANTUPDATE);
}
- pw_opened = false;
- if (is_shadow && spw_opened && (spw_close () == 0)) {
+ if (spw_opened && (spw_close () == 0)) {
fprintf (stderr,
_("%s: failure while writing changes to %s\n"),
Prog, spw_dbname ());
/* The passwd entry has a shadow counterpart.
* 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"),
pwd->pw_name, spw_dbname (), pw_dbname ());
*errors += 1;
/*
* Warn if last password change in the future. --marekm
*/
- if ( !quiet
- && (spw->sp_lstchg > (long) time ((time_t *) 0) / SCALE)) {
- printf (_("user %s: last password change in the future\n"),
- spw->sp_namp);
- *errors += 1;
+ if (!quiet) {
+ time_t t = time ((time_t *) 0);
+ if ( (t != 0)
+ && (spw->sp_lstchg > (long) t / SCALE)) {
+ printf (_("user %s: last password change in the future\n"),
+ spw->sp_namp);
+ *errors += 1;
+ }
}
}
}