* src/pwconv.c: Use a bool when possible instead of int integers.

* src/pwconv.c: Add brackets and parenthesis.
	* src/pwconv.c: Ignore return value of setlocale(),
	bindtextdomain(), and textdomain().
	* src/pwconv.c: Avoid implicit conversion of pointers / integers /
	chars to booleans.
This commit is contained in:
nekral-guest 2008-06-09 19:43:22 +00:00
parent 2a267ca05f
commit 24a7015f64
2 changed files with 37 additions and 23 deletions

View File

@ -1,3 +1,12 @@
2008-06-09 Nicolas François <nicolas.francois@centraliens.net>
* src/pwconv.c: Use a bool when possible instead of int integers.
* src/pwconv.c: Add brackets and parenthesis.
* src/pwconv.c: Ignore return value of setlocale(),
bindtextdomain(), and textdomain().
* src/pwconv.c: Avoid implicit conversion of pointers / integers /
chars to booleans.
2008-06-09 Nicolas François <nicolas.francois@centraliens.net> 2008-06-09 Nicolas François <nicolas.francois@centraliens.net>
* NEWS, src/newusers.c: Implement the -r, --system option. * NEWS, src/newusers.c: Implement the -r, --system option.

View File

@ -83,18 +83,20 @@
/* /*
* Global variables * Global variables
*/ */
static int static bool shadow_locked = false;
shadow_locked = 0, passwd_locked = 0; static bool passwd_locked = false;
/* local function prototypes */ /* local function prototypes */
static void fail_exit (int); static void fail_exit (int);
static void fail_exit (int status) static void fail_exit (int status)
{ {
if (shadow_locked) if (shadow_locked) {
spw_unlock (); spw_unlock ();
if (passwd_locked) }
if (passwd_locked) {
pw_unlock (); pw_unlock ();
}
exit (status); exit (status);
} }
@ -106,26 +108,26 @@ int main (int argc, char **argv)
struct spwd spent; struct spwd spent;
char *Prog = argv[0]; char *Prog = argv[0];
setlocale (LC_ALL, ""); (void) setlocale (LC_ALL, "");
bindtextdomain (PACKAGE, LOCALEDIR); (void) bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE); (void) textdomain (PACKAGE);
if (!pw_lock ()) { if (pw_lock () == 0) {
fprintf (stderr, _("%s: can't lock passwd file\n"), Prog); fprintf (stderr, _("%s: can't lock passwd file\n"), Prog);
fail_exit (E_PWDBUSY); fail_exit (E_PWDBUSY);
} }
passwd_locked++; passwd_locked = true;
if (!pw_open (O_RDWR)) { if (pw_open (O_RDWR) == 0) {
fprintf (stderr, _("%s: can't open passwd file\n"), Prog); fprintf (stderr, _("%s: can't open passwd file\n"), Prog);
fail_exit (E_MISSING); fail_exit (E_MISSING);
} }
if (!spw_lock ()) { if (spw_lock () == 0) {
fprintf (stderr, _("%s: can't lock shadow file\n"), Prog); fprintf (stderr, _("%s: can't lock shadow file\n"), Prog);
fail_exit (E_PWDBUSY); fail_exit (E_PWDBUSY);
} }
shadow_locked++; shadow_locked = true;
if (!spw_open (O_CREAT | O_RDWR)) { if (spw_open (O_CREAT | O_RDWR) == 0) {
fprintf (stderr, _("%s: can't open shadow file\n"), Prog); fprintf (stderr, _("%s: can't open shadow file\n"), Prog);
fail_exit (E_FAILURE); fail_exit (E_FAILURE);
} }
@ -134,11 +136,12 @@ int main (int argc, char **argv)
* Remove /etc/shadow entries for users not in /etc/passwd. * Remove /etc/shadow entries for users not in /etc/passwd.
*/ */
spw_rewind (); spw_rewind ();
while ((sp = spw_next ())) { while ((sp = spw_next ()) != NULL) {
if (pw_locate (sp->sp_namp)) if (pw_locate (sp->sp_namp) != NULL) {
continue; continue;
}
if (!spw_remove (sp->sp_namp)) { if (spw_remove (sp->sp_namp) == 0) {
/* /*
* This shouldn't happen (the entry exists) but... * This shouldn't happen (the entry exists) but...
*/ */
@ -155,12 +158,13 @@ int main (int argc, char **argv)
* missing shadow entries. * missing shadow entries.
*/ */
pw_rewind (); pw_rewind ();
while ((pw = pw_next ())) { while ((pw = pw_next ()) != NULL) {
sp = spw_locate (pw->pw_name); sp = spw_locate (pw->pw_name);
if (sp) { if (NULL != sp) {
/* do we need to update this entry? */ /* do we need to update this entry? */
if (strcmp (pw->pw_passwd, SHADOW_PASSWD_STRING) == 0) if (strcmp (pw->pw_passwd, SHADOW_PASSWD_STRING) == 0) {
continue; continue;
}
/* update existing shadow entry */ /* update existing shadow entry */
spent = *sp; spent = *sp;
} else { } else {
@ -176,7 +180,7 @@ int main (int argc, char **argv)
} }
spent.sp_pwdp = pw->pw_passwd; spent.sp_pwdp = pw->pw_passwd;
spent.sp_lstchg = time ((time_t *) 0) / (24L * 3600L); spent.sp_lstchg = time ((time_t *) 0) / (24L * 3600L);
if (!spw_update (&spent)) { if (spw_update (&spent) == 0) {
fprintf (stderr, fprintf (stderr,
_ _
("%s: can't update shadow entry for %s\n"), ("%s: can't update shadow entry for %s\n"),
@ -187,7 +191,7 @@ int main (int argc, char **argv)
/* remove password from /etc/passwd */ /* remove password from /etc/passwd */
pwent = *pw; pwent = *pw;
pwent.pw_passwd = SHADOW_PASSWD_STRING; /* XXX warning: const */ pwent.pw_passwd = SHADOW_PASSWD_STRING; /* XXX warning: const */
if (!pw_update (&pwent)) { if (pw_update (&pwent) == 0) {
fprintf (stderr, fprintf (stderr,
_ _
("%s: can't update passwd entry for %s\n"), ("%s: can't update passwd entry for %s\n"),
@ -196,11 +200,11 @@ int main (int argc, char **argv)
} }
} }
if (!spw_close ()) { if (spw_close () == 0) {
fprintf (stderr, _("%s: can't update shadow file\n"), Prog); fprintf (stderr, _("%s: can't update shadow file\n"), Prog);
fail_exit (E_FAILURE); fail_exit (E_FAILURE);
} }
if (!pw_close ()) { if (pw_close () == 0) {
fprintf (stderr, _("%s: can't update passwd file\n"), Prog); fprintf (stderr, _("%s: can't update passwd file\n"), Prog);
fail_exit (E_FAILURE); fail_exit (E_FAILURE);
} }
@ -212,3 +216,4 @@ int main (int argc, char **argv)
exit (E_SUCCESS); exit (E_SUCCESS);
} }