static void process_flags (int argc, char **argv);
static void open_files (void);
static void close_files (int changed);
+static void check_pw_file (int *errors, int *changed);
+static void check_spw_file (int *errors, int *changed);
/*
* usage - print syntax message and exit
}
/*
- * pwck - verify password file integrity
+ * check_pw_file - check the content of the passwd file
*/
-int main (int argc, char **argv)
+static void check_pw_file (int *errors, int *changed)
{
- int errors = 0;
- int changed = 0;
struct commonio_entry *pfe, *tpfe;
struct passwd *pwd;
-
- struct commonio_entry *spe, *tspe;
struct spwd *spw;
- /*
- * Get my name so that I can use it to report errors.
- */
- Prog = Basename (argv[0]);
-
- setlocale (LC_ALL, "");
- bindtextdomain (PACKAGE, LOCALEDIR);
- textdomain (PACKAGE);
-
- OPENLOG ("pwck");
-
- /* Parse the command line arguments */
- process_flags (argc, argv);
-
- open_files ();
-
- if (sort_mode) {
- pw_sort ();
- if (is_shadow)
- spw_sort ();
- changed = 1;
- goto write_and_bye;
- }
-
/*
* Loop through the entire password file.
*/
*/
printf (_("invalid password file entry\n"));
printf (_("delete line '%s'? "), pfe->line);
- errors++;
+ *errors += 1;
/*
* prompt the user to delete the entry or not
delete_pw:
SYSLOG ((LOG_INFO, "delete passwd line `%s'",
pfe->line));
- changed++;
+ *changed = 1;
__pw_del_entry (pfe);
continue;
*/
printf (_("duplicate password entry\n"));
printf (_("delete line '%s'? "), pfe->line);
- errors++;
+ *errors += 1;
/*
* prompt the user to delete the entry or not
*/
if (!check_user_name (pwd->pw_name)) {
printf (_("invalid user name '%s'\n"), pwd->pw_name);
- errors++;
+ *errors += 1;
}
/*
printf (_("user %s: no group %u\n"),
pwd->pw_name, pwd->pw_gid);
- errors++;
+ *errors += 1;
}
/*
printf (_
("user %s: directory %s does not exist\n"),
pwd->pw_name, pwd->pw_dir);
- errors++;
+ *errors += 1;
}
/*
*/
printf (_("user %s: program %s does not exist\n"),
pwd->pw_name, pwd->pw_shell);
- errors++;
+ *errors += 1;
}
/*
spw_file);
printf (_("add user '%s' in %s? "),
pwd->pw_name, spw_file);
- errors++;
+ *errors += 1;
if (yes_or_no (read_only)) {
struct spwd sp;
struct passwd pw;
sp.sp_flag = -1;
sp.sp_lstchg =
time ((time_t *) 0) / (24L * 3600L);
- changed++;
+ *changed = 1;
if (!spw_update (&sp)) {
fprintf (stderr,
}
}
}
+}
- if (!is_shadow)
- goto shadow_done;
+/*
+ * check_spw_file - check the content of the shadowed password file (shadow)
+ */
+static void check_spw_file (int *errors, int *changed)
+{
+ struct commonio_entry *spe, *tspe;
+ struct spwd *spw;
/*
* Loop through the entire shadow password file.
*/
printf (_("invalid shadow password file entry\n"));
printf (_("delete line '%s'? "), spe->line);
- errors++;
+ *errors += 1;
/*
* prompt the user to delete the entry or not
delete_spw:
SYSLOG ((LOG_INFO, "delete shadow line `%s'",
spe->line));
- changed++;
+ *changed = 1;
__spw_del_entry (spe);
continue;
*/
printf (_("duplicate shadow password entry\n"));
printf (_("delete line '%s'? "), spe->line);
- errors++;
+ *errors += 1;
/*
* prompt the user to delete the entry or not
printf (_("no matching password file entry in %s\n"),
pwd_file);
printf (_("delete line '%s'? "), spe->line);
- errors++;
+ *errors += 1;
/*
* prompt the user to delete the entry or not
printf (_
("user %s: last password change in the future\n"),
spw->sp_namp);
- errors++;
+ *errors += 1;
}
}
+}
+
+/*
+ * pwck - verify password file integrity
+ */
+int main (int argc, char **argv)
+{
+ int errors = 0;
+ int changed = 0;
+
+ /*
+ * Get my name so that I can use it to report errors.
+ */
+ Prog = Basename (argv[0]);
+
+ setlocale (LC_ALL, "");
+ bindtextdomain (PACKAGE, LOCALEDIR);
+ textdomain (PACKAGE);
+
+ OPENLOG ("pwck");
+
+ /* Parse the command line arguments */
+ process_flags (argc, argv);
+
+ open_files ();
+
+ if (sort_mode) {
+ pw_sort ();
+ if (is_shadow)
+ spw_sort ();
+ changed = 1;
+ goto write_and_bye;
+ }
+
+ check_pw_file (&errors, &changed);
+
+ if (!is_shadow)
+ goto shadow_done;
+
+ check_spw_file (&errors, &changed);
shadow_done: