Avoid implicit brackets.
This commit is contained in:
parent
7080370042
commit
92d8cbb26c
@ -1,3 +1,7 @@
|
|||||||
|
2008-01-01 Nicolas François <nicolas.francois@centraliens.net>
|
||||||
|
|
||||||
|
* src/pwck.c: Avoid implicit brackets.
|
||||||
|
|
||||||
2008-01-01 Nicolas François <nicolas.francois@centraliens.net>
|
2008-01-01 Nicolas François <nicolas.francois@centraliens.net>
|
||||||
|
|
||||||
* src/grpck.c: Avoid implicit brackets.
|
* src/grpck.c: Avoid implicit brackets.
|
||||||
|
69
src/pwck.c
69
src/pwck.c
@ -132,8 +132,9 @@ static void process_flags (int argc, char **argv)
|
|||||||
/*
|
/*
|
||||||
* Make certain we have the right number of arguments
|
* 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 ();
|
usage ();
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If there are two left over filenames, use those as the password
|
* If there are two left over filenames, use those as the password
|
||||||
@ -149,9 +150,10 @@ static void process_flags (int argc, char **argv)
|
|||||||
spw_name (spw_file);
|
spw_name (spw_file);
|
||||||
is_shadow = 1;
|
is_shadow = 1;
|
||||||
use_system_spw_file = 0;
|
use_system_spw_file = 0;
|
||||||
} else if (optind == argc)
|
} else if (optind == argc) {
|
||||||
is_shadow = spw_file_present ();
|
is_shadow = spw_file_present ();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* open_files - open the shadow database
|
* open_files - open the shadow database
|
||||||
@ -168,16 +170,18 @@ static void open_files (void)
|
|||||||
if (!pw_lock ()) {
|
if (!pw_lock ()) {
|
||||||
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) {
|
||||||
SYSLOG ((LOG_WARN, "cannot lock %s", pwd_file));
|
SYSLOG ((LOG_WARN, "cannot lock %s", pwd_file));
|
||||||
|
}
|
||||||
closelog ();
|
closelog ();
|
||||||
exit (E_CANTLOCK);
|
exit (E_CANTLOCK);
|
||||||
}
|
}
|
||||||
if (is_shadow && !spw_lock ()) {
|
if (is_shadow && !spw_lock ()) {
|
||||||
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) {
|
||||||
SYSLOG ((LOG_WARN, "cannot lock %s", spw_file));
|
SYSLOG ((LOG_WARN, "cannot lock %s", spw_file));
|
||||||
|
}
|
||||||
closelog ();
|
closelog ();
|
||||||
exit (E_CANTLOCK);
|
exit (E_CANTLOCK);
|
||||||
}
|
}
|
||||||
@ -190,16 +194,18 @@ static void open_files (void)
|
|||||||
if (!pw_open (read_only ? O_RDONLY : O_RDWR)) {
|
if (!pw_open (read_only ? O_RDONLY : O_RDWR)) {
|
||||||
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) {
|
||||||
SYSLOG ((LOG_WARN, "cannot open %s", pwd_file));
|
SYSLOG ((LOG_WARN, "cannot open %s", pwd_file));
|
||||||
|
}
|
||||||
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)) {
|
||||||
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) {
|
||||||
SYSLOG ((LOG_WARN, "cannot open %s", spw_file));
|
SYSLOG ((LOG_WARN, "cannot open %s", spw_file));
|
||||||
|
}
|
||||||
closelog ();
|
closelog ();
|
||||||
exit (E_CANTOPEN);
|
exit (E_CANTOPEN);
|
||||||
}
|
}
|
||||||
@ -238,8 +244,9 @@ static void close_files (int changed)
|
|||||||
/*
|
/*
|
||||||
* Don't be anti-social - unlock the files when you're done.
|
* Don't be anti-social - unlock the files when you're done.
|
||||||
*/
|
*/
|
||||||
if (is_shadow)
|
if (is_shadow) {
|
||||||
spw_unlock ();
|
spw_unlock ();
|
||||||
|
}
|
||||||
(void) pw_unlock ();
|
(void) pw_unlock ();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -260,8 +267,9 @@ static void check_pw_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 (pfe->line[0] == '+' || pfe->line[0] == '-')
|
if (pfe->line[0] == '+' || pfe->line[0] == '-') {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Start with the entries that are completely corrupt. They
|
* Start with the entries that are completely corrupt. They
|
||||||
@ -280,8 +288,9 @@ static void check_pw_file (int *errors, int *changed)
|
|||||||
/*
|
/*
|
||||||
* prompt the user to delete the entry or not
|
* prompt the user to delete the entry or not
|
||||||
*/
|
*/
|
||||||
if (!yes_or_no (read_only))
|
if (!yes_or_no (read_only)) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* All password file deletions wind up here. This
|
* All password file deletions wind up here. This
|
||||||
@ -312,17 +321,20 @@ static void check_pw_file (int *errors, int *changed)
|
|||||||
/*
|
/*
|
||||||
* Don't check this entry
|
* Don't check this entry
|
||||||
*/
|
*/
|
||||||
if (tpfe == pfe)
|
if (tpfe == pfe) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Don't check invalid entries.
|
* Don't check invalid entries.
|
||||||
*/
|
*/
|
||||||
if (!ent)
|
if (!ent) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (strcmp (pwd->pw_name, ent->pw_name) != 0)
|
if (strcmp (pwd->pw_name, ent->pw_name) != 0) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Tell the user this entry is a duplicate of
|
* Tell the user this entry is a duplicate of
|
||||||
@ -335,9 +347,10 @@ static void check_pw_file (int *errors, int *changed)
|
|||||||
/*
|
/*
|
||||||
* prompt the user to delete the entry or not
|
* prompt the user to delete the entry or not
|
||||||
*/
|
*/
|
||||||
if (yes_or_no (read_only))
|
if (yes_or_no (read_only)) {
|
||||||
goto delete_pw;
|
goto delete_pw;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Check for invalid usernames. --marekm
|
* Check for invalid usernames. --marekm
|
||||||
@ -456,15 +469,17 @@ static void check_spw_file (int *errors, int *changed)
|
|||||||
* 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.
|
||||||
*/
|
*/
|
||||||
if (spe->line == NULL)
|
if (spe->line == NULL) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 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;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Start with the entries that are completely corrupt. They
|
* Start with the entries that are completely corrupt. They
|
||||||
@ -483,8 +498,9 @@ static void check_spw_file (int *errors, int *changed)
|
|||||||
/*
|
/*
|
||||||
* prompt the user to delete the entry or not
|
* prompt the user to delete the entry or not
|
||||||
*/
|
*/
|
||||||
if (!yes_or_no (read_only))
|
if (!yes_or_no (read_only)) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* All shadow file deletions wind up here. This code
|
* All shadow file deletions wind up here. This code
|
||||||
@ -515,17 +531,20 @@ static void check_spw_file (int *errors, int *changed)
|
|||||||
/*
|
/*
|
||||||
* Don't check this entry
|
* Don't check this entry
|
||||||
*/
|
*/
|
||||||
if (tspe == spe)
|
if (tspe == spe) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Don't check invalid entries.
|
* Don't check invalid entries.
|
||||||
*/
|
*/
|
||||||
if (!ent)
|
if (!ent) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (strcmp (spw->sp_namp, ent->sp_namp) != 0)
|
if (strcmp (spw->sp_namp, ent->sp_namp) != 0) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Tell the user this entry is a duplicate of
|
* Tell the user this entry is a duplicate of
|
||||||
@ -538,9 +557,10 @@ static void check_spw_file (int *errors, int *changed)
|
|||||||
/*
|
/*
|
||||||
* prompt the user to delete the entry or not
|
* prompt the user to delete the entry or not
|
||||||
*/
|
*/
|
||||||
if (yes_or_no (read_only))
|
if (yes_or_no (read_only)) {
|
||||||
goto delete_spw;
|
goto delete_spw;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Make sure this entry exists in the /etc/passwd
|
* Make sure this entry exists in the /etc/passwd
|
||||||
@ -559,9 +579,10 @@ static void check_spw_file (int *errors, int *changed)
|
|||||||
/*
|
/*
|
||||||
* prompt the user to delete the entry or not
|
* prompt the user to delete the entry or not
|
||||||
*/
|
*/
|
||||||
if (yes_or_no (read_only))
|
if (yes_or_no (read_only)) {
|
||||||
goto delete_spw;
|
goto delete_spw;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Warn if last password change in the future. --marekm
|
* Warn if last password change in the future. --marekm
|
||||||
@ -600,8 +621,9 @@ int main (int argc, char **argv)
|
|||||||
|
|
||||||
if (sort_mode) {
|
if (sort_mode) {
|
||||||
pw_sort ();
|
pw_sort ();
|
||||||
if (is_shadow)
|
if (is_shadow) {
|
||||||
spw_sort ();
|
spw_sort ();
|
||||||
|
}
|
||||||
changed = 1;
|
changed = 1;
|
||||||
} else {
|
} else {
|
||||||
check_pw_file (&errors, &changed);
|
check_pw_file (&errors, &changed);
|
||||||
@ -618,10 +640,11 @@ 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) {
|
||||||
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);
|
||||||
|
}
|
||||||
|
|
||||||
closelog ();
|
closelog ();
|
||||||
exit (errors ? E_BADENTRY : E_OKAY);
|
exit (errors ? E_BADENTRY : E_OKAY);
|
||||||
|
Loading…
Reference in New Issue
Block a user