Avoid implicit conversions to booleans.

This commit is contained in:
nekral-guest 2008-01-01 18:27:40 +00:00
parent 92d8cbb26c
commit 4c2f65d7d0
2 changed files with 29 additions and 26 deletions

View File

@ -1,6 +1,7 @@
2008-01-01 Nicolas François <nicolas.francois@centraliens.net> 2008-01-01 Nicolas François <nicolas.francois@centraliens.net>
* src/pwck.c: Avoid implicit brackets. * src/pwck.c: Avoid implicit brackets.
* src/pwck.c: Avoid implicit conversions to booleans.
2008-01-01 Nicolas François <nicolas.francois@centraliens.net> 2008-01-01 Nicolas François <nicolas.francois@centraliens.net>

View File

@ -145,7 +145,7 @@ static void process_flags (int argc, char **argv)
pw_name (pwd_file); pw_name (pwd_file);
use_system_pw_file = 0; use_system_pw_file = 0;
} }
if (optind + 2 == argc) { if ((optind + 2) == argc) {
spw_file = argv[optind + 1]; spw_file = argv[optind + 1];
spw_name (spw_file); spw_name (spw_file);
is_shadow = 1; is_shadow = 1;
@ -167,7 +167,7 @@ static void open_files (void)
* Lock the files if we aren't in "read-only" mode * Lock the files if we aren't in "read-only" mode
*/ */
if (!read_only) { if (!read_only) {
if (!pw_lock ()) { if (pw_lock () == 0) {
fprintf (stderr, _("%s: cannot lock file %s\n"), fprintf (stderr, _("%s: cannot lock file %s\n"),
Prog, pwd_file); Prog, pwd_file);
if (use_system_pw_file) { if (use_system_pw_file) {
@ -176,7 +176,7 @@ static void open_files (void)
closelog (); closelog ();
exit (E_CANTLOCK); exit (E_CANTLOCK);
} }
if (is_shadow && !spw_lock ()) { if (is_shadow && (spw_lock () == 0)) {
fprintf (stderr, _("%s: cannot lock file %s\n"), fprintf (stderr, _("%s: cannot lock file %s\n"),
Prog, spw_file); Prog, spw_file);
if (use_system_spw_file) { if (use_system_spw_file) {
@ -191,7 +191,7 @@ static void open_files (void)
* Open the files. Use O_RDONLY if we are in read_only mode, O_RDWR * Open the files. Use O_RDONLY if we are in read_only mode, O_RDWR
* otherwise. * otherwise.
*/ */
if (!pw_open (read_only ? O_RDONLY : O_RDWR)) { if (pw_open (read_only ? O_RDONLY : O_RDWR) == 0) {
fprintf (stderr, _("%s: cannot open file %s\n"), fprintf (stderr, _("%s: cannot open file %s\n"),
Prog, pwd_file); Prog, pwd_file);
if (use_system_pw_file) { if (use_system_pw_file) {
@ -200,7 +200,7 @@ static void open_files (void)
closelog (); closelog ();
exit (E_CANTOPEN); exit (E_CANTOPEN);
} }
if (is_shadow && !spw_open (read_only ? O_RDONLY : O_RDWR)) { if (is_shadow && (spw_open (read_only ? O_RDONLY : O_RDWR) == 0)) {
fprintf (stderr, _("%s: cannot open file %s\n"), fprintf (stderr, _("%s: cannot open file %s\n"),
Prog, spw_file); Prog, spw_file);
if (use_system_spw_file) { if (use_system_spw_file) {
@ -225,14 +225,14 @@ static void close_files (int changed)
* changes to the files. * changes to the files.
*/ */
if (changed) { if (changed) {
if (!pw_close ()) { if (pw_close () == 0) {
fprintf (stderr, _("%s: cannot update file %s\n"), fprintf (stderr, _("%s: cannot update file %s\n"),
Prog, pwd_file); Prog, pwd_file);
SYSLOG ((LOG_WARN, "cannot update %s", pwd_file)); SYSLOG ((LOG_WARN, "cannot update %s", pwd_file));
closelog (); closelog ();
exit (E_CANTUPDATE); exit (E_CANTUPDATE);
} }
if (is_shadow && !spw_close ()) { if (is_shadow && (spw_close () == 0)) {
fprintf (stderr, _("%s: cannot update file %s\n"), fprintf (stderr, _("%s: cannot update file %s\n"),
Prog, spw_file); Prog, spw_file);
SYSLOG ((LOG_WARN, "cannot update %s", spw_file)); SYSLOG ((LOG_WARN, "cannot update %s", spw_file));
@ -262,12 +262,12 @@ static void check_pw_file (int *errors, int *changed)
/* /*
* Loop through the entire password file. * Loop through the entire password file.
*/ */
for (pfe = __pw_get_head (); pfe; pfe = pfe->next) { for (pfe = __pw_get_head (); NULL != pfe; pfe = pfe->next) {
/* /*
* If this is a NIS line, skip it. You can't "know" what NIS * If this is a NIS line, skip it. You can't "know" what NIS
* is going to do without directly asking NIS ... * is going to do without directly asking NIS ...
*/ */
if (pfe->line[0] == '+' || pfe->line[0] == '-') { if ((pfe->line[0] == '+') || (pfe->line[0] == '-')) {
continue; continue;
} }
@ -276,7 +276,7 @@ static void check_pw_file (int *errors, int *changed)
* have no (struct passwd) entry because they couldn't be * have no (struct passwd) entry because they couldn't be
* parsed properly. * parsed properly.
*/ */
if (!pfe->eptr) { if (NULL == pfe->eptr) {
/* /*
* Tell the user this entire line is bogus and ask * Tell the user this entire line is bogus and ask
* them to delete it. * them to delete it.
@ -315,7 +315,7 @@ static void check_pw_file (int *errors, int *changed)
/* /*
* Make sure this entry has a unique name. * Make sure this entry has a unique name.
*/ */
for (tpfe = __pw_get_head (); tpfe; tpfe = tpfe->next) { for (tpfe = __pw_get_head (); NULL != tpfe; tpfe = tpfe->next) {
const struct passwd *ent = tpfe->eptr; const struct passwd *ent = tpfe->eptr;
/* /*
@ -328,7 +328,7 @@ static void check_pw_file (int *errors, int *changed)
/* /*
* Don't check invalid entries. * Don't check invalid entries.
*/ */
if (!ent) { if (NULL == ent) {
continue; continue;
} }
@ -364,7 +364,7 @@ static void check_pw_file (int *errors, int *changed)
* Make sure the primary group exists * Make sure the primary group exists
*/ */
/* local, no need for xgetgrgid */ /* local, no need for xgetgrgid */
if (!quiet && !getgrgid (pwd->pw_gid)) { if (!quiet && (NULL == getgrgid (pwd->pw_gid))) {
/* /*
* No primary group, just give a warning * No primary group, just give a warning
@ -378,7 +378,7 @@ static void check_pw_file (int *errors, int *changed)
/* /*
* Make sure the home directory exists * Make sure the home directory exists
*/ */
if (!quiet && access (pwd->pw_dir, F_OK)) { if (!quiet && (access (pwd->pw_dir, F_OK) != 0)) {
/* /*
* Home directory doesn't exist, give a warning * Home directory doesn't exist, give a warning
*/ */
@ -390,8 +390,9 @@ static void check_pw_file (int *errors, int *changed)
/* /*
* Make sure the login shell is executable * Make sure the login shell is executable
*/ */
if (!quiet && pwd->pw_shell[0] if ( !quiet
&& access (pwd->pw_shell, F_OK)) { && ('\0' != pwd->pw_shell[0])
&& (access (pwd->pw_shell, F_OK) != 0)) {
/* /*
* Login shell doesn't exist, give a warning * Login shell doesn't exist, give a warning
@ -432,7 +433,7 @@ static void check_pw_file (int *errors, int *changed)
time ((time_t *) 0) / (24L * 3600L); time ((time_t *) 0) / (24L * 3600L);
*changed = 1; *changed = 1;
if (!spw_update (&sp)) { if (spw_update (&sp) == 0) {
fprintf (stderr, fprintf (stderr,
_("%s: can't update shadow entry for %s\n"), _("%s: can't update shadow entry for %s\n"),
Prog, sp.sp_namp); Prog, sp.sp_namp);
@ -441,7 +442,7 @@ static void check_pw_file (int *errors, int *changed)
/* remove password from /etc/passwd */ /* remove password from /etc/passwd */
pw = *pwd; pw = *pwd;
pw.pw_passwd = SHADOW_PASSWD_STRING; /* XXX warning: const */ pw.pw_passwd = SHADOW_PASSWD_STRING; /* XXX warning: const */
if (!pw_update (&pw)) { if (pw_update (&pw) == 0) {
fprintf (stderr, fprintf (stderr,
_("%s: can't update passwd entry for %s\n"), _("%s: can't update passwd entry for %s\n"),
Prog, pw.pw_name); Prog, pw.pw_name);
@ -464,7 +465,7 @@ static void check_spw_file (int *errors, int *changed)
/* /*
* Loop through the entire shadow password file. * Loop through the entire shadow password file.
*/ */
for (spe = __spw_get_head (); spe; spe = spe->next) { for (spe = __spw_get_head (); NULL != spe; spe = spe->next) {
/* /*
* Do not treat lines which were missing in shadow * Do not treat lines which were missing in shadow
* and were added earlier. * and were added earlier.
@ -477,7 +478,7 @@ static void check_spw_file (int *errors, int *changed)
* If this is a NIS line, skip it. You can't "know" what NIS * If this is a NIS line, skip it. You can't "know" what NIS
* is going to do without directly asking NIS ... * is going to do without directly asking NIS ...
*/ */
if (spe->line[0] == '+' || spe->line[0] == '-') { if ((spe->line[0] == '+') || (spe->line[0] == '-')) {
continue; continue;
} }
@ -486,7 +487,7 @@ static void check_spw_file (int *errors, int *changed)
* have no (struct spwd) entry because they couldn't be * have no (struct spwd) entry because they couldn't be
* parsed properly. * parsed properly.
*/ */
if (!spe->eptr) { if (NULL == spe->eptr) {
/* /*
* Tell the user this entire line is bogus and ask * Tell the user this entire line is bogus and ask
* them to delete it. * them to delete it.
@ -525,7 +526,7 @@ static void check_spw_file (int *errors, int *changed)
/* /*
* Make sure this entry has a unique name. * Make sure this entry has a unique name.
*/ */
for (tspe = __spw_get_head (); tspe; tspe = tspe->next) { for (tspe = __spw_get_head (); NULL != tspe; tspe = tspe->next) {
const struct spwd *ent = tspe->eptr; const struct spwd *ent = tspe->eptr;
/* /*
@ -538,7 +539,7 @@ static void check_spw_file (int *errors, int *changed)
/* /*
* Don't check invalid entries. * Don't check invalid entries.
*/ */
if (!ent) { if (NULL == ent) {
continue; continue;
} }
@ -566,7 +567,7 @@ static void check_spw_file (int *errors, int *changed)
* Make sure this entry exists in the /etc/passwd * Make sure this entry exists in the /etc/passwd
* file. * file.
*/ */
if (!pw_locate (spw->sp_namp)) { if (pw_locate (spw->sp_namp) == NULL) {
/* /*
* Tell the user this entry has no matching * Tell the user this entry has no matching
* /etc/passwd entry and ask them to delete it. * /etc/passwd entry and ask them to delete it.
@ -587,7 +588,8 @@ static void check_spw_file (int *errors, int *changed)
/* /*
* Warn if last password change in the future. --marekm * Warn if last password change in the future. --marekm
*/ */
if (!quiet && spw->sp_lstchg > time ((time_t *) 0) / SCALE) { if (!quiet
&& (spw->sp_lstchg > time ((time_t *) 0) / SCALE)) {
printf (_("user %s: last password change in the future\n"), printf (_("user %s: last password change in the future\n"),
spw->sp_namp); spw->sp_namp);
*errors += 1; *errors += 1;
@ -640,7 +642,7 @@ int main (int argc, char **argv)
/* /*
* Tell the user what we did and exit. * Tell the user what we did and exit.
*/ */
if (errors) { if (errors != 0) {
printf (changed ? printf (changed ?
_("%s: the files have been updated\n") : _("%s: the files have been updated\n") :
_("%s: no changes\n"), Prog); _("%s: no changes\n"), Prog);