* 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.
This commit is contained in:
nekral-guest 2010-03-23 11:26:34 +00:00
parent 4375be4642
commit 052e9105f7
11 changed files with 46 additions and 25 deletions

View File

@ -1,3 +1,21 @@
2010-03-23 Nicolas François <nicolas.francois@centraliens.net>
* 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 <nicolas.francois@centraliens.net> 2010-03-22 Nicolas François <nicolas.francois@centraliens.net>
* lib/utent.c (getutline): Remove getutline(). This function is * lib/utent.c (getutline): Remove getutline(). This function is

View File

@ -270,7 +270,7 @@ static void print_date (time_t date)
} }
if (NULL != cp) { if (NULL != cp) {
(void) printf ("%6.6s, %4.4s\n", cp + 4, cp + 20); (void) printf ("%6.6s, %4.4s\n", cp + 4, cp + 20);
} else { } else {
(void) printf ("time_t: %lu\n", date); (void) printf ("time_t: %lu\n", date);
} }
#endif #endif

View File

@ -108,10 +108,7 @@ int main (int argc, char **argv)
{ {
#ifdef HAVE_GETGROUPS #ifdef HAVE_GETGROUPS
long sys_ngroups; long sys_ngroups;
int ngroups;
GETGROUPS_T *groups; GETGROUPS_T *groups;
int pri_grp; /* TODO: should be GETGROUPS_T */
int i;
#else #else
char *logname; char *logname;
char *getlogin (); char *getlogin ();
@ -138,12 +135,14 @@ int main (int argc, char **argv)
*/ */
#ifdef HAVE_GETGROUPS #ifdef HAVE_GETGROUPS
int i;
int pri_grp; /* TODO: should be GETGROUPS_T */
/* /*
* This system supports concurrent group sets, so I can ask * This system supports concurrent group sets, so I can ask
* the system to tell me which groups are currently set for * the system to tell me which groups are currently set for
* this process. * this process.
*/ */
ngroups = getgroups (sys_ngroups, groups); int ngroups = getgroups (sys_ngroups, groups);
if (ngroups < 0) { if (ngroups < 0) {
perror ("getgroups"); perror ("getgroups");
exit (EXIT_FAILURE); exit (EXIT_FAILURE);

View File

@ -64,7 +64,6 @@ static void usage (void)
{ {
uid_t ruid, euid; uid_t ruid, euid;
gid_t rgid, egid; gid_t rgid, egid;
int i;
long sys_ngroups; long sys_ngroups;
/* /*
@ -168,6 +167,7 @@ static void usage (void)
* The group numbers will be printed followed by their names. * The group numbers will be printed followed by their names.
*/ */
if (aflg && (ngroups = getgroups (sys_ngroups, groups)) != -1) { if (aflg && (ngroups = getgroups (sys_ngroups, groups)) != -1) {
int i;
/* /*
* Start off the group message. It will be of the format * Start off the group message. It will be of the format

View File

@ -167,10 +167,10 @@ static void usage (void)
static void setup_tty (void) static void setup_tty (void)
{ {
TERMIO termio; TERMIO termio;
int erasechar;
int killchar;
if (GTTY (0, &termio) == 0) { /* get terminal characteristics */ if (GTTY (0, &termio) == 0) { /* get terminal characteristics */
int erasechar;
int killchar;
/* /*
* Add your favorite terminal modes here ... * Add your favorite terminal modes here ...
@ -242,7 +242,6 @@ static void check_nologin (bool login_to_root)
fname = getdef_str ("NOLOGINS_FILE"); fname = getdef_str ("NOLOGINS_FILE");
if ((NULL != fname) && (access (fname, F_OK) == 0)) { if ((NULL != fname) && (access (fname, F_OK) == 0)) {
FILE *nlfp; FILE *nlfp;
int c;
/* /*
* Cat the file if it can be opened, otherwise just * 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"); nlfp = fopen (fname, "r");
if (NULL != nlfp) { if (NULL != nlfp) {
int c;
while ((c = getc (nlfp)) != EOF) { while ((c = getc (nlfp)) != EOF) {
if (c == '\n') { if (c == '\n') {
(void) putchar ('\r'); (void) putchar ('\r');
@ -527,7 +527,6 @@ int main (int argc, char **argv)
#endif #endif
unsigned int delay; unsigned int delay;
unsigned int retries; unsigned int retries;
bool failed;
bool subroot = false; bool subroot = false;
#ifndef USE_PAM #ifndef USE_PAM
bool is_console; bool is_console;
@ -773,7 +772,7 @@ int main (int argc, char **argv)
*/ */
failcount = 0; failcount = 0;
while (true) { while (true) {
failed = false; bool failed = false;
failcount++; failcount++;
#ifdef HAS_PAM_FAIL_DELAY #ifdef HAS_PAM_FAIL_DELAY
@ -903,6 +902,7 @@ int main (int argc, char **argv)
#else /* ! USE_PAM */ #else /* ! USE_PAM */
while (true) { /* repeatedly get login/password pairs */ while (true) { /* repeatedly get login/password pairs */
bool failed;
/* user_passwd is always a pointer to this constant string /* user_passwd is always a pointer to this constant string
* or a passwd or shadow password that will be memzero by * or a passwd or shadow password that will be memzero by
* pw_free / spw_free. * pw_free / spw_free.

View File

@ -81,8 +81,6 @@ int login_access (const char *user, const char *from)
char *users; /* becomes list of login names */ char *users; /* becomes list of login names */
char *froms; /* becomes list of terminals or hosts */ char *froms; /* becomes list of terminals or hosts */
bool match = false; bool match = false;
int end;
int lineno = 0; /* for diagnostics */
/* /*
* Process the table one line at a time and stop at the first match. * 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"); fp = fopen (TABLE, "r");
if (NULL != fp) { if (NULL != fp) {
int lineno = 0; /* for diagnostics */
while ( !match while ( !match
&& (fgets (line, (int) sizeof (line), fp) == line)) { && (fgets (line, (int) sizeof (line), fp) == line)) {
int end;
lineno++; lineno++;
end = (int) strlen (line) - 1; end = (int) strlen (line) - 1;
if (line[end] != '\n') { if (line[end] != '\n') {
@ -211,7 +211,6 @@ static bool user_match (const char *tok, const char *string)
#ifdef PRIMARY_GROUP_MATCH #ifdef PRIMARY_GROUP_MATCH
struct passwd *userinf; struct passwd *userinf;
#endif #endif
int i;
char *at; char *at;
/* /*
@ -232,6 +231,7 @@ static bool user_match (const char *tok, const char *string)
return true; return true;
/* local, no need for xgetgrnam */ /* local, no need for xgetgrnam */
} else if ((group = getgrnam (tok)) != NULL) { /* try group membership */ } else if ((group = getgrnam (tok)) != NULL) { /* try group membership */
int i;
for (i = 0; NULL != group->gr_mem[i]; i++) { for (i = 0; NULL != group->gr_mem[i]; i++) {
if (strcasecmp (string, group->gr_mem[i]) == 0) { if (strcasecmp (string, group->gr_mem[i]) == 0) {
return true; return true;
@ -280,7 +280,6 @@ static const char *resolve_hostname (const char *string)
static bool from_match (const char *tok, const char *string) static bool from_match (const char *tok, const char *string)
{ {
size_t tok_len; size_t tok_len;
size_t str_len;
/* /*
* If a token has the magic value "ALL" the match always succeeds. Return * 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 */ if (string_match (tok, string)) { /* ALL or exact match */
return true; return true;
} else if (tok[0] == '.') { /* domain: match last fields */ } else if (tok[0] == '.') { /* domain: match last fields */
size_t str_len;
str_len = strlen (string); str_len = strlen (string);
tok_len = strlen (tok); tok_len = strlen (tok);
if ( (str_len > tok_len) if ( (str_len > tok_len)

View File

@ -95,7 +95,6 @@ static void send_mesg_to_tty (int tty_fd)
{ {
TERMIO oldt, newt; TERMIO oldt, newt;
FILE *mesg_file, *tty_file; FILE *mesg_file, *tty_file;
int c;
bool is_tty; bool is_tty;
tty_file = fdopen (tty_fd, "w"); 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"); mesg_file = fopen (HUP_MESG_FILE, "r");
if (NULL != mesg_file) { if (NULL != mesg_file) {
int c;
while ((c = getc (mesg_file)) != EOF) { while ((c = getc (mesg_file)) != EOF) {
if (c == '\n') { if (c == '\n') {
putc ('\r', tty_file); putc ('\r', tty_file);

View File

@ -282,7 +282,7 @@ static void syslog_sg (const char *name, const char *group)
* receives SIGCHLD from the terminating subshell. -- JWP * receives SIGCHLD from the terminating subshell. -- JWP
*/ */
{ {
pid_t child, pid; pid_t child;
/* Ignore these signals. The signal handlers will later be /* Ignore these signals. The signal handlers will later be
* restored to the default handlers. */ * restored to the default handlers. */
@ -316,6 +316,7 @@ static void syslog_sg (const char *name, const char *group)
int cst = 0; int cst = 0;
gid_t gid = getgid(); gid_t gid = getgid();
struct group *grp = getgrgid (gid); struct group *grp = getgrgid (gid);
pid_t pid;
do { do {
errno = 0; errno = 0;

View File

@ -360,7 +360,7 @@ static int new_password (const struct passwd *pw)
*/ */
static void check_password (const struct passwd *pw, const struct spwd *sp) static void check_password (const struct passwd *pw, const struct spwd *sp)
{ {
time_t now, last, ok; time_t now;
int exp_status; int exp_status;
exp_status = isexpired (pw, sp); 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. * Passwords may only be changed after sp_min time is up.
*/ */
if (sp->sp_lstchg > 0) { if (sp->sp_lstchg > 0) {
time_t last, ok;
last = sp->sp_lstchg * SCALE; last = sp->sp_lstchg * SCALE;
ok = last + (sp->sp_min > 0 ? sp->sp_min * SCALE : 0); ok = last + (sp->sp_min > 0 ? sp->sp_min * SCALE : 0);

View File

@ -485,6 +485,7 @@ static int set_defaults (void)
fprintf (stderr, fprintf (stderr,
_("%s: line too long in %s: %s..."), _("%s: line too long in %s: %s..."),
Prog, def_file, buf); Prog, def_file, buf);
(void) fclose (ifp);
return -1; return -1;
} }
} }
@ -1804,13 +1805,13 @@ static void create_home (void)
*/ */
static void create_mail (void) static void create_mail (void)
{ {
if (strcasecmp (create_mail_spool, "yes") == 0) {
char *spool, *file; char *spool, *file;
int fd; int fd;
struct group *gr; struct group *gr;
gid_t gid; gid_t gid;
mode_t mode; mode_t mode;
if (strcasecmp (create_mail_spool, "yes") == 0) {
spool = getdef_str ("MAIL_DIR"); spool = getdef_str ("MAIL_DIR");
if (NULL == spool) { if (NULL == spool) {
spool = "/var/mail"; spool = "/var/mail";

View File

@ -369,6 +369,7 @@ vipwedit (const char *file, int (*file_lock) (void), int (*file_unlock) (void))
free (to_rename); free (to_rename);
vipwexit (_("failed to create backup file"), errno, 1); vipwexit (_("failed to create backup file"), errno, 1);
} }
(void) fclose (f);
} else { } else {
#endif /* WITH_TCB */ #endif /* WITH_TCB */
to_rename = fileedit; to_rename = fileedit;