/*
* Make certain we have the right number of arguments
*/
- if (optind != argc && optind + 1 != argc && optind + 2 != argc)
+ if ((argc < optind) || (argc > (optind + 2))) {
usage ();
+ }
/*
* If there are two left over filenames, use those as the password
spw_name (spw_file);
is_shadow = 1;
use_system_spw_file = 0;
- } else if (optind == argc)
+ } else if (optind == argc) {
is_shadow = spw_file_present ();
+ }
}
/*
if (!pw_lock ()) {
fprintf (stderr, _("%s: cannot lock file %s\n"),
Prog, pwd_file);
- if (use_system_pw_file)
+ if (use_system_pw_file) {
SYSLOG ((LOG_WARN, "cannot lock %s", pwd_file));
+ }
closelog ();
exit (E_CANTLOCK);
}
if (is_shadow && !spw_lock ()) {
fprintf (stderr, _("%s: cannot lock file %s\n"),
Prog, spw_file);
- if (use_system_spw_file)
+ if (use_system_spw_file) {
SYSLOG ((LOG_WARN, "cannot lock %s", spw_file));
+ }
closelog ();
exit (E_CANTLOCK);
}
if (!pw_open (read_only ? O_RDONLY : O_RDWR)) {
fprintf (stderr, _("%s: cannot open file %s\n"),
Prog, pwd_file);
- if (use_system_pw_file)
+ if (use_system_pw_file) {
SYSLOG ((LOG_WARN, "cannot open %s", pwd_file));
+ }
closelog ();
exit (E_CANTOPEN);
}
if (is_shadow && !spw_open (read_only ? O_RDONLY : O_RDWR)) {
fprintf (stderr, _("%s: cannot open file %s\n"),
Prog, spw_file);
- if (use_system_spw_file)
+ if (use_system_spw_file) {
SYSLOG ((LOG_WARN, "cannot open %s", spw_file));
+ }
closelog ();
exit (E_CANTOPEN);
}
/*
* Don't be anti-social - unlock the files when you're done.
*/
- if (is_shadow)
+ if (is_shadow) {
spw_unlock ();
+ }
(void) pw_unlock ();
}
* If this is a NIS line, skip it. You can't "know" what NIS
* is going to do without directly asking NIS ...
*/
- if (pfe->line[0] == '+' || pfe->line[0] == '-')
+ if (pfe->line[0] == '+' || pfe->line[0] == '-') {
continue;
+ }
/*
* Start with the entries that are completely corrupt. They
/*
* prompt the user to delete the entry or not
*/
- if (!yes_or_no (read_only))
+ if (!yes_or_no (read_only)) {
continue;
+ }
/*
* All password file deletions wind up here. This
/*
* Don't check this entry
*/
- if (tpfe == pfe)
+ if (tpfe == pfe) {
continue;
+ }
/*
* Don't check invalid entries.
*/
- if (!ent)
+ if (!ent) {
continue;
+ }
- if (strcmp (pwd->pw_name, ent->pw_name) != 0)
+ if (strcmp (pwd->pw_name, ent->pw_name) != 0) {
continue;
+ }
/*
* Tell the user this entry is a duplicate of
/*
* prompt the user to delete the entry or not
*/
- if (yes_or_no (read_only))
+ if (yes_or_no (read_only)) {
goto delete_pw;
+ }
}
/*
* Do not treat lines which were missing in shadow
* and were added earlier.
*/
- if (spe->line == NULL)
+ if (spe->line == NULL) {
continue;
+ }
/*
* If this is a NIS line, skip it. You can't "know" what NIS
* is going to do without directly asking NIS ...
*/
- if (spe->line[0] == '+' || spe->line[0] == '-')
+ if (spe->line[0] == '+' || spe->line[0] == '-') {
continue;
+ }
/*
* Start with the entries that are completely corrupt. They
/*
* prompt the user to delete the entry or not
*/
- if (!yes_or_no (read_only))
+ if (!yes_or_no (read_only)) {
continue;
+ }
/*
* All shadow file deletions wind up here. This code
/*
* Don't check this entry
*/
- if (tspe == spe)
+ if (tspe == spe) {
continue;
+ }
/*
* Don't check invalid entries.
*/
- if (!ent)
+ if (!ent) {
continue;
+ }
- if (strcmp (spw->sp_namp, ent->sp_namp) != 0)
+ if (strcmp (spw->sp_namp, ent->sp_namp) != 0) {
continue;
+ }
/*
* Tell the user this entry is a duplicate of
/*
* prompt the user to delete the entry or not
*/
- if (yes_or_no (read_only))
+ if (yes_or_no (read_only)) {
goto delete_spw;
+ }
}
/*
/*
* prompt the user to delete the entry or not
*/
- if (yes_or_no (read_only))
+ if (yes_or_no (read_only)) {
goto delete_spw;
+ }
}
/*
if (sort_mode) {
pw_sort ();
- if (is_shadow)
+ if (is_shadow) {
spw_sort ();
+ }
changed = 1;
} else {
check_pw_file (&errors, &changed);
/*
* Tell the user what we did and exit.
*/
- if (errors)
+ if (errors) {
printf (changed ?
_("%s: the files have been updated\n") :
_("%s: no changes\n"), Prog);
+ }
closelog ();
exit (errors ? E_BADENTRY : E_OKAY);