From 4375be46429f0c36f20d0b87335800a4632c1eae Mon Sep 17 00:00:00 2001 From: nekral-guest Date: Tue, 23 Mar 2010 08:56:52 +0000 Subject: [PATCH] * lib/utent.c (getutline): Remove getutline(). This function is no more used. * lib/groupmem.c: Limit the scope of variable i. * lib/shadow.c: Avoid implicit conversion of pointers and integers to booleans. * lib/shadow.c: Added brackets. * libmisc/limits.c: Limit the scope of variable tmpmask. * libmisc/copydir.c: Close opened file on failure. * libmisc/loginprompt.c: Limit the scope of variable envc. * libmisc/find_new_uid.c, libmisc/find_new_gid.c: Limit the scope of variable id. --- ChangeLog | 16 +++++++++ lib/groupmem.c | 2 +- lib/shadow.c | 74 +++++++++++++++++++++++++++--------------- lib/utent.c | 19 ----------- libmisc/copydir.c | 1 + libmisc/find_new_gid.c | 3 +- libmisc/find_new_uid.c | 3 +- libmisc/limits.c | 2 +- libmisc/loginprompt.c | 2 +- 9 files changed, 71 insertions(+), 51 deletions(-) diff --git a/ChangeLog b/ChangeLog index 660fc56c..90f2e592 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2010-03-22 Nicolas François + + * lib/utent.c (getutline): Remove getutline(). This function is + no more used. + * lib/groupmem.c: Limit the scope of variable i. + * lib/shadow.c: Avoid implicit conversion of pointers and integers + to booleans. + * lib/shadow.c: Added brackets. + * libmisc/limits.c: Limit the scope of variable tmpmask. + * libmisc/copydir.c: Close opened file on failure. + * libmisc/loginprompt.c: Limit the scope of variable envc. + * libmisc/find_new_uid.c, libmisc/find_new_gid.c: Limit the scope + of variable id. + 2010-03-21 Nicolas François * libmisc/find_new_gid.c, libmisc/find_new_uid.c: Detect some @@ -7,6 +21,8 @@ 2010-03-20 Nicolas François * NEWS, configure.in: Next version will be 4.1.5. + * po/shadow.pot, man/po/shadow-man-pages.pot: Regenerated. + * po/*.po, man/po/*.po: Updated PO files. 2010-03-20 Nicolas François diff --git a/lib/groupmem.c b/lib/groupmem.c index 3add3c80..25bdacfa 100644 --- a/lib/groupmem.c +++ b/lib/groupmem.c @@ -90,13 +90,13 @@ void gr_free (/*@out@*/ /*@only@*/struct group *grent) { - size_t i; free (grent->gr_name); if (NULL != grent->gr_passwd) { memzero (grent->gr_passwd, strlen (grent->gr_passwd)); free (grent->gr_passwd); } if (NULL != grent->gr_mem) { + size_t i; for (i = 0; NULL != grent->gr_mem[i]; i++) { free (grent->gr_mem[i]); } diff --git a/lib/shadow.c b/lib/shadow.c index 1afcb13e..05cb0e4a 100644 --- a/lib/shadow.c +++ b/lib/shadow.c @@ -42,10 +42,10 @@ #include "defines.h" #include #ifdef USE_NIS -static int nis_used; -static int nis_ignore; +static bool nis_used; +static bool nis_ignore; static enum { native, start, middle, native2 } nis_state; -static int nis_bound; +static bool nis_bound; static char *nis_domain; static char *nis_key; static int nis_keylen; @@ -66,12 +66,12 @@ static FILE *shadow; * __setspNIS - turn on or off NIS searches */ -void __setspNIS (int flag) +void __setspNIS (bool flag) { nis_ignore = !flag; if (nis_ignore) { - nis_used = 0; + nis_used = false; } } @@ -81,10 +81,11 @@ void __setspNIS (int flag) static int bind_nis (void) { - if (yp_get_default_domain (&nis_domain)) + if (yp_get_default_domain (&nis_domain)) { return -1; + } - nis_bound = 1; + nis_bound = true; return 0; } #endif @@ -95,10 +96,11 @@ static int bind_nis (void) void setspent (void) { - if (shadow) + if (NULL != shadow) { rewind (shadow); - else + }else { shadow = fopen (SHADOW_FILE, "r"); + } #ifdef USE_NIS nis_state = native; @@ -111,8 +113,9 @@ void setspent (void) void endspent (void) { - if (shadow) + if (NULL != shadow) { (void) fclose (shadow); + } shadow = (FILE *) 0; } @@ -172,8 +175,9 @@ static struct spwd *my_sgetspent (const char *string) spwd.sp_namp = fields[0]; #ifdef USE_NIS - if (IS_NISCHAR (fields[0][0])) - nis_used = 1; + if (IS_NISCHAR (fields[0][0])) { + nis_used = true; + } #endif spwd.sp_pwdp = fields[1]; @@ -211,7 +215,9 @@ static struct spwd *my_sgetspent (const char *string) spwd.sp_min = -1; } else #endif + { return 0; + } } else if (spwd.sp_min < 0) { return 0; } @@ -263,7 +269,9 @@ static struct spwd *my_sgetspent (const char *string) spwd.sp_warn = -1; } else #endif + { return 0; + } } else if (spwd.sp_warn < 0) { return 0; } @@ -283,7 +291,9 @@ static struct spwd *my_sgetspent (const char *string) spwd.sp_inact = -1; } else #endif + { return 0; + } } else if (spwd.sp_inact < 0) { return 0; } @@ -303,7 +313,9 @@ static struct spwd *my_sgetspent (const char *string) spwd.sp_expire = -1; } else #endif + { return 0; + } } else if (spwd.sp_expire < 0) { return 0; } @@ -324,7 +336,9 @@ static struct spwd *my_sgetspent (const char *string) spwd.sp_flag = SHADOW_SP_FLAG_UNSET; } else #endif + { return 0; + } } else if (spwd.sp_flag < 0) { return 0; } @@ -377,8 +391,9 @@ struct spwd *getspent (void) struct spwd *val; char buf[BUFSIZ]; #endif - if (!shadow) + if (NULL == shadow) { setspent (); + } #ifdef USE_NIS again: @@ -432,7 +447,7 @@ struct spwd *getspent (void) return 0; } else { - if (nis_bound == 0) { + if (!nis_bound) { if (bind_nis ()) { nis_state = native2; goto again; @@ -440,15 +455,15 @@ struct spwd *getspent (void) } if (nis_state == start) { if (yp_first (nis_domain, "shadow.bynam", &nis_key, - &nis_keylen, &nis_val, &nis_vallen)) { + &nis_keylen, &nis_val, &nis_vallen)) { nis_state = native2; goto again; } nis_state = middle; } else if (nis_state == middle) { if (yp_next (nis_domain, "shadow.bynam", nis_key, - nis_keylen, &nis_key, &nis_keylen, - &nis_val, &nis_vallen)) { + nis_keylen, &nis_key, &nis_keylen, + &nis_val, &nis_vallen)) { nis_state = native2; goto again; } @@ -471,7 +486,7 @@ struct spwd *getspnam (const char *name) #ifdef USE_NIS char buf[BUFSIZ]; static char save_name[16]; - int nis_disabled = 0; + bool nis_disabled = false; #endif setspent (); @@ -481,18 +496,20 @@ struct spwd *getspnam (const char *name) * Search the shadow.byname map for this user. */ - if (!nis_ignore && !nis_bound) + if (!nis_ignore && !nis_bound) { bind_nis (); + } if (!nis_ignore && nis_bound) { char *cp; if (yp_match (nis_domain, "shadow.byname", name, - strlen (name), &nis_val, &nis_vallen) == 0) { + strlen (name), &nis_val, &nis_vallen) == 0) { cp = strchr (nis_val, '\n'); - if (NULL != cp) + if (NULL != cp) { *cp = '\0'; + } nis_state = middle; sp = my_sgetspent (nis_val); @@ -503,8 +520,9 @@ struct spwd *getspnam (const char *name) } endspent (); return sp; - } else + } else { nis_state = native2; + } } #endif #ifdef USE_NIS @@ -516,17 +534,19 @@ struct spwd *getspnam (const char *name) */ if (nis_used) { - nis_ignore++; - nis_disabled++; + nis_ignore = true; + nis_disabled = true; } #endif while ((sp = getspent ()) != (struct spwd *) 0) { - if (strcmp (name, sp->sp_namp) == 0) + if (strcmp (name, sp->sp_namp) == 0) { break; + } } #ifdef USE_NIS - if (nis_disabled) - nis_ignore--; + if (nis_disabled) { + nis_ignore = false; + } #endif endspent (); return (sp); diff --git a/lib/utent.c b/lib/utent.c index 94c25bf6..45af2607 100644 --- a/lib/utent.c +++ b/lib/utent.c @@ -88,25 +88,6 @@ struct utmp *getutent (void) return &utmp_buf; } - -/* - * getutline - get the utmp entry matching ut_line - */ - -struct utmp *getutline (const struct utmp *utent) -{ - struct utmp save; - struct utmp *new; - - save = *utent; - while (new = getutent ()) - if (strncmp (new->ut_line, save.ut_line, sizeof new->ut_line)) - continue; - else - return new; - - return (struct utmp *) 0; -} #else extern int errno; /* warning: ANSI C forbids an empty source file */ #endif diff --git a/libmisc/copydir.c b/libmisc/copydir.c index 3c824a39..7ce60690 100644 --- a/libmisc/copydir.c +++ b/libmisc/copydir.c @@ -635,6 +635,7 @@ static int copy_file (const char *src, const char *dst, while ((cnt = read (ifd, buf, sizeof buf)) > 0) { if (write (ofd, buf, (size_t)cnt) != cnt) { + (void) close (ifd); return -1; } } diff --git a/libmisc/find_new_gid.c b/libmisc/find_new_gid.c index 1c08b9b4..8c54639c 100644 --- a/libmisc/find_new_gid.c +++ b/libmisc/find_new_gid.c @@ -52,7 +52,7 @@ int find_new_gid (bool sys_group, /*@null@*/gid_t const *preferred_gid) { const struct group *grp; - gid_t gid_min, gid_max, group_id, id; + gid_t gid_min, gid_max, group_id; bool *used_gids; assert (gid != NULL); @@ -100,6 +100,7 @@ int find_new_gid (bool sys_group, * some groups were created but the changes were not committed yet. */ if (sys_group) { + gid_t id; /* setgrent / getgrent / endgrent can be very slow with * LDAP configurations (and many accounts). * Since there is a limited amount of IDs to be tested diff --git a/libmisc/find_new_uid.c b/libmisc/find_new_uid.c index 139fe5f8..7b330c28 100644 --- a/libmisc/find_new_uid.c +++ b/libmisc/find_new_uid.c @@ -52,7 +52,7 @@ int find_new_uid (bool sys_user, /*@null@*/uid_t const *preferred_uid) { const struct passwd *pwd; - uid_t uid_min, uid_max, user_id, id; + uid_t uid_min, uid_max, user_id; bool *used_uids; assert (uid != NULL); @@ -100,6 +100,7 @@ int find_new_uid (bool sys_user, * some users were created but the changes were not committed yet. */ if (sys_user) { + uid_t id; /* setpwent / getpwent / endpwent can be very slow with * LDAP configurations (and many accounts). * Since there is a limited amount of IDs to be tested diff --git a/libmisc/limits.c b/libmisc/limits.c index ff6ac24f..cece004f 100644 --- a/libmisc/limits.c +++ b/libmisc/limits.c @@ -507,7 +507,6 @@ static int setup_user_limits (const char *uname) static void setup_usergroups (const struct passwd *info) { const struct group *grp; - mode_t tmpmask; /* * if not root, and UID == GID, and username is the same as primary @@ -519,6 +518,7 @@ static void setup_usergroups (const struct passwd *info) grp = getgrgid (info->pw_gid); if ( (NULL != grp) && (strcmp (info->pw_name, grp->gr_name) == 0)) { + mode_t tmpmask; tmpmask = umask (0777); tmpmask = (tmpmask & ~070) | ((tmpmask >> 3) & 070); (void) umask (tmpmask); diff --git a/libmisc/loginprompt.c b/libmisc/loginprompt.c index 3ca89388..9373e610 100644 --- a/libmisc/loginprompt.c +++ b/libmisc/loginprompt.c @@ -60,7 +60,6 @@ void login_prompt (const char *prompt, char *name, int namesize) #define MAX_ENV 32 char *envp[MAX_ENV]; - int envc; char *cp; int i; FILE *fp; @@ -148,6 +147,7 @@ void login_prompt (const char *prompt, char *name, int namesize) if ('\0' != *cp) { /* process new variables */ char *nvar; int count = 1; + int envc; for (envc = 0; envc < MAX_ENV; envc++) { nvar = strtok ((0 != envc) ? (char *) 0 : cp, " \t,");