Avoid implicit brackets.

This commit is contained in:
nekral-guest 2007-12-27 21:28:50 +00:00
parent c919701466
commit a77eb6b49d
2 changed files with 27 additions and 14 deletions

View File

@ -11,6 +11,7 @@
function. function.
* src/gpasswd.c: New functions: check_perms(), get_group(), * src/gpasswd.c: New functions: check_perms(), get_group(),
change_passwd(), check_flags(). Split out of main() to simplify main(). change_passwd(), check_flags(). Split out of main() to simplify main().
* src/gpasswd.c: Avoid implicit brackets.
2007-12-27 Nicolas François <nicolas.francois@centraliens.net> 2007-12-27 Nicolas François <nicolas.francois@centraliens.net>

View File

@ -132,10 +132,11 @@ static RETSIGTYPE catch_signals (int killed)
{ {
static TERMIO sgtty; static TERMIO sgtty;
if (killed) if (killed) {
STTY (0, &sgtty); STTY (0, &sgtty);
else } else {
GTTY (0, &sgtty); GTTY (0, &sgtty);
}
if (killed) { if (killed) {
putchar ('\n'); putchar ('\n');
@ -165,8 +166,9 @@ static int check_list (const char *users)
len = strlen (start); len = strlen (start);
} }
if (len > sizeof (username) - 1) if (len > sizeof (username) - 1) {
len = sizeof (username) - 1; len = sizeof (username) - 1;
}
strncpy (username, start, len); strncpy (username, start, len);
username[len] = '\0'; username[len] = '\0';
@ -176,7 +178,7 @@ static int check_list (const char *users)
if (!getpwnam (username)) { /* local, no need for xgetpwnam */ if (!getpwnam (username)) { /* local, no need for xgetpwnam */
fprintf (stderr, _("%s: unknown user %s\n"), fprintf (stderr, _("%s: unknown user %s\n"),
Prog, username); Prog, username);
errors++; errors++;
} }
} }
@ -231,8 +233,9 @@ static void process_flags (int argc, char **argv)
exit (2); exit (2);
} }
admins = optarg; admins = optarg;
if (check_list (admins)) if (check_list (admins)) {
exit (1); exit (1);
}
Aflg++; Aflg++;
break; break;
#endif #endif
@ -252,8 +255,9 @@ static void process_flags (int argc, char **argv)
failure (); failure ();
} }
members = optarg; members = optarg;
if (check_list (members)) if (check_list (members)) {
exit (1); exit (1);
}
Mflg++; Mflg++;
break; break;
case 'r': /* remove group password */ case 'r': /* remove group password */
@ -281,8 +285,9 @@ static void check_flags (int argc, int opt_index)
/* /*
* Make sure exclusive flags are exclusive * Make sure exclusive flags are exclusive
*/ */
if (aflg + dflg + rflg + Rflg + (Aflg || Mflg) > 1) if (aflg + dflg + rflg + Rflg + (Aflg || Mflg) > 1) {
usage (); usage ();
}
/* /*
* Make sure one (and only one) group was provided * Make sure one (and only one) group was provided
@ -307,7 +312,7 @@ static void open_files (void)
"locking /etc/group", group, -1, 0); "locking /etc/group", group, -1, 0);
#endif #endif
exit (1); exit (1);
} }
#ifdef SHADOWGRP #ifdef SHADOWGRP
if (is_shadowgrp && (sgr_lock () == 0)) { if (is_shadowgrp && (sgr_lock () == 0)) {
fprintf (stderr, _("%s: can't get shadow lock\n"), Prog); fprintf (stderr, _("%s: can't get shadow lock\n"), Prog);
@ -565,7 +570,9 @@ static void get_group (struct group *gr)
sg->sg_adm[1] = 0; sg->sg_adm[1] = 0;
} else } else
#endif #endif
{
sg->sg_adm[0] = 0; sg->sg_adm[0] = 0;
}
} }
if (!sgr_close ()) { if (!sgr_close ()) {
@ -607,13 +614,15 @@ static void change_passwd (struct group *gr)
printf (_("Changing the password for group %s\n"), group); printf (_("Changing the password for group %s\n"), group);
for (retries = 0; retries < RETRIES; retries++) { for (retries = 0; retries < RETRIES; retries++) {
if (!(cp = getpass (_("New Password: ")))) if (!(cp = getpass (_("New Password: ")))) {
exit (1); exit (1);
}
STRFCPY (pass, cp); STRFCPY (pass, cp);
strzero (cp); strzero (cp);
if (!(cp = getpass (_("Re-enter new password: ")))) if (!(cp = getpass (_("Re-enter new password: ")))) {
exit (1); exit (1);
}
if (strcmp (pass, cp) == 0) { if (strcmp (pass, cp) == 0) {
strzero (cp); strzero (cp);
@ -640,11 +649,13 @@ static void change_passwd (struct group *gr)
cp = pw_encrypt (pass, crypt_make_salt (NULL, NULL)); cp = pw_encrypt (pass, crypt_make_salt (NULL, NULL));
memzero (pass, sizeof pass); memzero (pass, sizeof pass);
#ifdef SHADOWGRP #ifdef SHADOWGRP
if (is_shadowgrp) if (is_shadowgrp) {
sg->sg_passwd = cp; sg->sg_passwd = cp;
else } else
#endif #endif
{
gr->gr_passwd = cp; gr->gr_passwd = cp;
}
#ifdef WITH_AUDIT #ifdef WITH_AUDIT
audit_logger (AUDIT_USER_CHAUTHTOK, Prog, audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
"changing password", group, -1, 1); "changing password", group, -1, 1);
@ -840,8 +851,9 @@ int main (int argc, char **argv)
SYSLOG ((LOG_INFO, "set administrators of %s to %s", SYSLOG ((LOG_INFO, "set administrators of %s to %s",
group, admins)); group, admins));
sgent.sg_adm = comma_to_list (admins); sgent.sg_adm = comma_to_list (admins);
if (!Mflg) if (!Mflg) {
goto output; goto output;
}
} }
#endif #endif