[Pkg-shadow-commits] r1602 - in upstream/trunk: . src
nekral-guest at alioth.debian.org
nekral-guest at alioth.debian.org
Tue Jan 1 15:49:33 UTC 2008
Author: nekral-guest
Date: 2008-01-01 15:49:33 +0000 (Tue, 01 Jan 2008)
New Revision: 1602
Modified:
upstream/trunk/ChangeLog
upstream/trunk/src/pwck.c
Log:
Split also check_pw_file() and check_spw_file() out of main().
Modified: upstream/trunk/ChangeLog
===================================================================
--- upstream/trunk/ChangeLog 2008-01-01 15:29:47 UTC (rev 1601)
+++ upstream/trunk/ChangeLog 2008-01-01 15:49:33 UTC (rev 1602)
@@ -1,8 +1,9 @@
2008-01-01 Nicolas François <nicolas.francois at centraliens.net>
- * src/pwck.c: Split process_flags(), open_files(), and
- close_files() out of main(). New global variables is_shadow,
- sort_mode, use_system_pw_file, and use_system_spw_file.
+ * src/pwck.c: Split process_flags(), open_files(), close_files()
+ check_pw_file(), and check_spw_file() out of main(). New global
+ variables is_shadow, sort_mode, use_system_pw_file, and
+ use_system_spw_file.
2008-01-01 Nicolas François <nicolas.francois at centraliens.net>
Modified: upstream/trunk/src/pwck.c
===================================================================
--- upstream/trunk/src/pwck.c 2008-01-01 15:29:47 UTC (rev 1601)
+++ upstream/trunk/src/pwck.c 2008-01-01 15:49:33 UTC (rev 1602)
@@ -82,6 +82,8 @@
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
@@ -240,43 +242,15 @@
}
/*
- * 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.
*/
for (pfe = __pw_get_head (); pfe; pfe = pfe->next) {
@@ -299,7 +273,7 @@
*/
printf (_("invalid password file entry\n"));
printf (_("delete line '%s'? "), pfe->line);
- errors++;
+ *errors += 1;
/*
* prompt the user to delete the entry or not
@@ -316,7 +290,7 @@
delete_pw:
SYSLOG ((LOG_INFO, "delete passwd line `%s'",
pfe->line));
- changed++;
+ *changed = 1;
__pw_del_entry (pfe);
continue;
@@ -354,7 +328,7 @@
*/
printf (_("duplicate password entry\n"));
printf (_("delete line '%s'? "), pfe->line);
- errors++;
+ *errors += 1;
/*
* prompt the user to delete the entry or not
@@ -368,7 +342,7 @@
*/
if (!check_user_name (pwd->pw_name)) {
printf (_("invalid user name '%s'\n"), pwd->pw_name);
- errors++;
+ *errors += 1;
}
/*
@@ -383,7 +357,7 @@
printf (_("user %s: no group %u\n"),
pwd->pw_name, pwd->pw_gid);
- errors++;
+ *errors += 1;
}
/*
@@ -396,7 +370,7 @@
printf (_
("user %s: directory %s does not exist\n"),
pwd->pw_name, pwd->pw_dir);
- errors++;
+ *errors += 1;
}
/*
@@ -410,7 +384,7 @@
*/
printf (_("user %s: program %s does not exist\n"),
pwd->pw_name, pwd->pw_shell);
- errors++;
+ *errors += 1;
}
/*
@@ -425,7 +399,7 @@
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;
@@ -443,7 +417,7 @@
sp.sp_flag = -1;
sp.sp_lstchg =
time ((time_t *) 0) / (24L * 3600L);
- changed++;
+ *changed = 1;
if (!spw_update (&sp)) {
fprintf (stderr,
@@ -466,9 +440,15 @@
}
}
}
+}
- 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.
@@ -500,7 +480,7 @@
*/
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
@@ -517,7 +497,7 @@
delete_spw:
SYSLOG ((LOG_INFO, "delete shadow line `%s'",
spe->line));
- changed++;
+ *changed = 1;
__spw_del_entry (spe);
continue;
@@ -555,7 +535,7 @@
*/
printf (_("duplicate shadow password entry\n"));
printf (_("delete line '%s'? "), spe->line);
- errors++;
+ *errors += 1;
/*
* prompt the user to delete the entry or not
@@ -576,7 +556,7 @@
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
@@ -592,10 +572,50 @@
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:
write_and_bye:
More information about the Pkg-shadow-commits
mailing list