From 052e9105f7a6dcc371b2c9d3656e714d8b2746c1 Mon Sep 17 00:00:00 2001 From: nekral-guest Date: Tue, 23 Mar 2010 11:26:34 +0000 Subject: [PATCH] * src/newgrp.c: Limit the scope of variable pid. * src/login_nopam.c: Limit the scope of variables end, lineno, i, str_len. * src/logoutd.c: Limit the scope of variable c. * src/vipw.c: Re-indent. * src/vipw.c: Close the file after the creation of the backup. * src/useradd.c (set_default): Close input file on failure. * src/useradd.c: Limit the scope of variables spool, file, fd, gr, gid, mode. * src/passwd.c: Limit the scope of variables last and ok. * src/chage.c: Fix typo (non breaking space). * src/login.c: Limit the scope of variables erasechar killchar, c, failed. * src/groups.c: Limit the scope of variable ngroups, pri_grp, i. * src/id.c: Limit the scope of variable i. --- ChangeLog | 18 ++++++++++++++++++ src/chage.c | 2 +- src/groups.c | 7 +++---- src/id.c | 2 +- src/login.c | 10 +++++----- src/login_nopam.c | 8 ++++---- src/logoutd.c | 2 +- src/newgrp.c | 3 ++- src/passwd.c | 3 ++- src/useradd.c | 13 +++++++------ src/vipw.c | 3 ++- 11 files changed, 46 insertions(+), 25 deletions(-) diff --git a/ChangeLog b/ChangeLog index 90f2e592..7db41c6b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,21 @@ +2010-03-23 Nicolas François + + * src/newgrp.c: Limit the scope of variable pid. + * src/login_nopam.c: Limit the scope of variables end, lineno, i, + str_len. + * src/logoutd.c: Limit the scope of variable c. + * src/vipw.c: Re-indent. + * src/vipw.c: Close the file after the creation of the backup. + * src/useradd.c (set_default): Close input file on failure. + * src/useradd.c: Limit the scope of variables spool, file, fd, gr, + gid, mode. + * src/passwd.c: Limit the scope of variables last and ok. + * src/chage.c: Fix typo (non breaking space). + * src/login.c: Limit the scope of variables erasechar killchar, c, + failed. + * src/groups.c: Limit the scope of variable ngroups, pri_grp, i. + * src/id.c: Limit the scope of variable i. + 2010-03-22 Nicolas François * lib/utent.c (getutline): Remove getutline(). This function is diff --git a/src/chage.c b/src/chage.c index c986cb8e..55afb998 100644 --- a/src/chage.c +++ b/src/chage.c @@ -270,7 +270,7 @@ static void print_date (time_t date) } if (NULL != cp) { (void) printf ("%6.6s, %4.4s\n", cp + 4, cp + 20); - } else { + } else { (void) printf ("time_t: %lu\n", date); } #endif diff --git a/src/groups.c b/src/groups.c index d260a354..3c5ae980 100644 --- a/src/groups.c +++ b/src/groups.c @@ -108,10 +108,7 @@ int main (int argc, char **argv) { #ifdef HAVE_GETGROUPS long sys_ngroups; - int ngroups; GETGROUPS_T *groups; - int pri_grp; /* TODO: should be GETGROUPS_T */ - int i; #else char *logname; char *getlogin (); @@ -138,12 +135,14 @@ int main (int argc, char **argv) */ #ifdef HAVE_GETGROUPS + int i; + int pri_grp; /* TODO: should be GETGROUPS_T */ /* * This system supports concurrent group sets, so I can ask * the system to tell me which groups are currently set for * this process. */ - ngroups = getgroups (sys_ngroups, groups); + int ngroups = getgroups (sys_ngroups, groups); if (ngroups < 0) { perror ("getgroups"); exit (EXIT_FAILURE); diff --git a/src/id.c b/src/id.c index f0c10d6a..4462ae09 100644 --- a/src/id.c +++ b/src/id.c @@ -64,7 +64,6 @@ static void usage (void) { uid_t ruid, euid; gid_t rgid, egid; - int i; long sys_ngroups; /* @@ -168,6 +167,7 @@ static void usage (void) * The group numbers will be printed followed by their names. */ if (aflg && (ngroups = getgroups (sys_ngroups, groups)) != -1) { + int i; /* * Start off the group message. It will be of the format diff --git a/src/login.c b/src/login.c index 44ef8f8e..8c4d9101 100644 --- a/src/login.c +++ b/src/login.c @@ -167,10 +167,10 @@ static void usage (void) static void setup_tty (void) { TERMIO termio; - int erasechar; - int killchar; if (GTTY (0, &termio) == 0) { /* get terminal characteristics */ + int erasechar; + int killchar; /* * Add your favorite terminal modes here ... @@ -242,7 +242,6 @@ static void check_nologin (bool login_to_root) fname = getdef_str ("NOLOGINS_FILE"); if ((NULL != fname) && (access (fname, F_OK) == 0)) { FILE *nlfp; - int c; /* * Cat the file if it can be opened, otherwise just @@ -250,6 +249,7 @@ static void check_nologin (bool login_to_root) */ nlfp = fopen (fname, "r"); if (NULL != nlfp) { + int c; while ((c = getc (nlfp)) != EOF) { if (c == '\n') { (void) putchar ('\r'); @@ -527,7 +527,6 @@ int main (int argc, char **argv) #endif unsigned int delay; unsigned int retries; - bool failed; bool subroot = false; #ifndef USE_PAM bool is_console; @@ -773,7 +772,7 @@ int main (int argc, char **argv) */ failcount = 0; while (true) { - failed = false; + bool failed = false; failcount++; #ifdef HAS_PAM_FAIL_DELAY @@ -903,6 +902,7 @@ int main (int argc, char **argv) #else /* ! USE_PAM */ while (true) { /* repeatedly get login/password pairs */ + bool failed; /* user_passwd is always a pointer to this constant string * or a passwd or shadow password that will be memzero by * pw_free / spw_free. diff --git a/src/login_nopam.c b/src/login_nopam.c index d66087c5..68a37755 100644 --- a/src/login_nopam.c +++ b/src/login_nopam.c @@ -81,8 +81,6 @@ int login_access (const char *user, const char *from) char *users; /* becomes list of login names */ char *froms; /* becomes list of terminals or hosts */ bool match = false; - int end; - int lineno = 0; /* for diagnostics */ /* * Process the table one line at a time and stop at the first match. @@ -93,8 +91,10 @@ int login_access (const char *user, const char *from) */ fp = fopen (TABLE, "r"); if (NULL != fp) { + int lineno = 0; /* for diagnostics */ while ( !match && (fgets (line, (int) sizeof (line), fp) == line)) { + int end; lineno++; end = (int) strlen (line) - 1; if (line[end] != '\n') { @@ -211,7 +211,6 @@ static bool user_match (const char *tok, const char *string) #ifdef PRIMARY_GROUP_MATCH struct passwd *userinf; #endif - int i; char *at; /* @@ -232,6 +231,7 @@ static bool user_match (const char *tok, const char *string) return true; /* local, no need for xgetgrnam */ } else if ((group = getgrnam (tok)) != NULL) { /* try group membership */ + int i; for (i = 0; NULL != group->gr_mem[i]; i++) { if (strcasecmp (string, group->gr_mem[i]) == 0) { return true; @@ -280,7 +280,6 @@ static const char *resolve_hostname (const char *string) static bool from_match (const char *tok, const char *string) { size_t tok_len; - size_t str_len; /* * If a token has the magic value "ALL" the match always succeeds. Return @@ -298,6 +297,7 @@ static bool from_match (const char *tok, const char *string) if (string_match (tok, string)) { /* ALL or exact match */ return true; } else if (tok[0] == '.') { /* domain: match last fields */ + size_t str_len; str_len = strlen (string); tok_len = strlen (tok); if ( (str_len > tok_len) diff --git a/src/logoutd.c b/src/logoutd.c index e89e55c9..45484923 100644 --- a/src/logoutd.c +++ b/src/logoutd.c @@ -95,7 +95,6 @@ static void send_mesg_to_tty (int tty_fd) { TERMIO oldt, newt; FILE *mesg_file, *tty_file; - int c; bool is_tty; tty_file = fdopen (tty_fd, "w"); @@ -114,6 +113,7 @@ static void send_mesg_to_tty (int tty_fd) mesg_file = fopen (HUP_MESG_FILE, "r"); if (NULL != mesg_file) { + int c; while ((c = getc (mesg_file)) != EOF) { if (c == '\n') { putc ('\r', tty_file); diff --git a/src/newgrp.c b/src/newgrp.c index 3a03a65c..167b10bf 100644 --- a/src/newgrp.c +++ b/src/newgrp.c @@ -282,7 +282,7 @@ static void syslog_sg (const char *name, const char *group) * receives SIGCHLD from the terminating subshell. -- JWP */ { - pid_t child, pid; + pid_t child; /* Ignore these signals. The signal handlers will later be * restored to the default handlers. */ @@ -316,6 +316,7 @@ static void syslog_sg (const char *name, const char *group) int cst = 0; gid_t gid = getgid(); struct group *grp = getgrgid (gid); + pid_t pid; do { errno = 0; diff --git a/src/passwd.c b/src/passwd.c index 8e65b674..ea51acd3 100644 --- a/src/passwd.c +++ b/src/passwd.c @@ -360,7 +360,7 @@ static int new_password (const struct passwd *pw) */ static void check_password (const struct passwd *pw, const struct spwd *sp) { - time_t now, last, ok; + time_t now; int exp_status; exp_status = isexpired (pw, sp); @@ -404,6 +404,7 @@ static void check_password (const struct passwd *pw, const struct spwd *sp) * Passwords may only be changed after sp_min time is up. */ if (sp->sp_lstchg > 0) { + time_t last, ok; last = sp->sp_lstchg * SCALE; ok = last + (sp->sp_min > 0 ? sp->sp_min * SCALE : 0); diff --git a/src/useradd.c b/src/useradd.c index b7f56711..a1deac57 100644 --- a/src/useradd.c +++ b/src/useradd.c @@ -485,6 +485,7 @@ static int set_defaults (void) fprintf (stderr, _("%s: line too long in %s: %s..."), Prog, def_file, buf); + (void) fclose (ifp); return -1; } } @@ -1804,13 +1805,13 @@ static void create_home (void) */ static void create_mail (void) { - char *spool, *file; - int fd; - struct group *gr; - gid_t gid; - mode_t mode; - if (strcasecmp (create_mail_spool, "yes") == 0) { + char *spool, *file; + int fd; + struct group *gr; + gid_t gid; + mode_t mode; + spool = getdef_str ("MAIL_DIR"); if (NULL == spool) { spool = "/var/mail"; diff --git a/src/vipw.c b/src/vipw.c index 199b2627..81c4b7c7 100644 --- a/src/vipw.c +++ b/src/vipw.c @@ -298,7 +298,7 @@ vipwedit (const char *file, int (*file_lock) (void), int (*file_unlock) (void)) "%s %s", editor, fileedit); if (system (buf) != 0) { fprintf (stderr, "%s: %s: %s\n", progname, editor, - strerror (errno)); + strerror (errno)); exit (1); } else { exit (0); @@ -369,6 +369,7 @@ vipwedit (const char *file, int (*file_lock) (void), int (*file_unlock) (void)) free (to_rename); vipwexit (_("failed to create backup file"), errno, 1); } + (void) fclose (f); } else { #endif /* WITH_TCB */ to_rename = fileedit;