[Pkg-shadow-commits] r1540 - in upstream/trunk: . src
nekral-guest at alioth.debian.org
nekral-guest at alioth.debian.org
Fri Dec 28 22:18:55 UTC 2007
Author: nekral-guest
Date: 2007-12-28 22:18:55 +0000 (Fri, 28 Dec 2007)
New Revision: 1540
Modified:
upstream/trunk/ChangeLog
upstream/trunk/src/chpasswd.c
Log:
Other new functions: open_files(), close_files().
This force flushing the password database after the password file is unlocked.
Modified: upstream/trunk/ChangeLog
===================================================================
--- upstream/trunk/ChangeLog 2007-12-28 22:05:51 UTC (rev 1539)
+++ upstream/trunk/ChangeLog 2007-12-28 22:18:55 UTC (rev 1540)
@@ -4,6 +4,9 @@
pam API was already checked. No need to validate it again.
* src/chpasswd.c: New functions: process_flags(), check_flags(),
check_perms(). Split out of main().
+ * src/chpasswd.c: Other new functions: open_files(), close_files().
+ This force flushing the password database after the password file is
+ unlocked.
2007-12-28 Nicolas François <nicolas.francois at centraliens.net>
Modified: upstream/trunk/src/chpasswd.c
===================================================================
--- upstream/trunk/src/chpasswd.c 2007-12-28 22:05:51 UTC (rev 1539)
+++ upstream/trunk/src/chpasswd.c 2007-12-28 22:18:55 UTC (rev 1540)
@@ -64,6 +64,8 @@
static void process_flags (int argc, char **argv);
static void check_flags (void);
static void check_perms (void);
+static void open_files (void);
+static void close_files (void);
/*
* usage - display usage message and exit
@@ -243,36 +245,14 @@
#endif /* USE_PAM */
}
-int main (int argc, char **argv)
+/*
+ * open_files - lock and open the password databases
+ */
+static void open_files (void)
{
- char buf[BUFSIZ];
- char *name;
- char *newpwd;
- char *cp;
-
- const struct spwd *sp;
- struct spwd newsp;
-
- const struct passwd *pw;
- struct passwd newpw;
- int errors = 0;
- int line = 0;
- long now = time ((long *) 0) / (24L * 3600L);
- int ok;
-
- Prog = Basename (argv[0]);
-
- setlocale (LC_ALL, "");
- bindtextdomain (PACKAGE, LOCALEDIR);
- textdomain (PACKAGE);
-
- process_flags (argc, argv);
-
- check_perms ();
-
/*
- * Lock the password file and open it for reading. This will bring
- * all of the entries into memory where they may be updated.
+ * Lock the password file and open it for reading and writing. This
+ * will bring all of the entries into memory where they may be updated.
*/
if (!pw_lock ()) {
fprintf (stderr, _("%s: can't lock password file\n"), Prog);
@@ -284,7 +264,7 @@
exit (1);
}
- is_shadow_pwd = spw_file_present ();
+ /* Do the same for the shadowed database, if it exist */
if (is_shadow_pwd) {
if (!spw_lock ()) {
fprintf (stderr, _("%s: can't lock shadow file\n"),
@@ -300,7 +280,62 @@
exit (1);
}
}
+}
+/*
+ * close_files - close and unlock the password databases
+ */
+static void close_files (void)
+{
+ if (is_shadow_pwd) {
+ if (!spw_close ()) {
+ fprintf (stderr,
+ _("%s: error updating shadow file\n"), Prog);
+ pw_unlock ();
+ exit (1);
+ }
+ spw_unlock ();
+ }
+
+ if (!pw_close ()) {
+ fprintf (stderr, _("%s: error updating password file\n"), Prog);
+ exit (1);
+ }
+ pw_unlock ();
+
+}
+
+int main (int argc, char **argv)
+{
+ char buf[BUFSIZ];
+ char *name;
+ char *newpwd;
+ char *cp;
+
+ const struct spwd *sp;
+ struct spwd newsp;
+
+ const struct passwd *pw;
+ struct passwd newpw;
+ int errors = 0;
+ int line = 0;
+ long now = time ((long *) 0) / (24L * 3600L);
+ int ok;
+
+ Prog = Basename (argv[0]);
+
+ setlocale (LC_ALL, "");
+ bindtextdomain (PACKAGE, LOCALEDIR);
+ textdomain (PACKAGE);
+
+ process_flags (argc, argv);
+
+ check_perms ();
+
+ is_shadow_pwd = spw_file_present ();
+
+ open_files ();
+
/*
* Read each line, separating the user name from the password. The
* password entry for each user will be looked up in the appropriate
@@ -421,24 +456,11 @@
pw_unlock ();
exit (1);
}
- if (is_shadow_pwd) {
- if (!spw_close ()) {
- fprintf (stderr,
- _("%s: error updating shadow file\n"), Prog);
- pw_unlock ();
- exit (1);
- }
- spw_unlock ();
- }
- if (!pw_close ()) {
- fprintf (stderr, _("%s: error updating password file\n"), Prog);
- exit (1);
- }
+ close_files ();
+
nscd_flush_cache ("passwd");
- pw_unlock ();
-
#ifdef USE_PAM
pam_end (pamh, PAM_SUCCESS);
#endif /* USE_PAM */
More information about the Pkg-shadow-commits
mailing list