]> granicus.if.org Git - shadow/commitdiff
* lib/utent.c (getutline): Remove getutline(). This function is
authornekral-guest <nekral-guest@5a98b0ae-9ef6-0310-add3-de5d479b70d7>
Tue, 23 Mar 2010 08:56:52 +0000 (08:56 +0000)
committernekral-guest <nekral-guest@5a98b0ae-9ef6-0310-add3-de5d479b70d7>
Tue, 23 Mar 2010 08:56:52 +0000 (08:56 +0000)
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
lib/groupmem.c
lib/shadow.c
lib/utent.c
libmisc/copydir.c
libmisc/find_new_gid.c
libmisc/find_new_uid.c
libmisc/limits.c
libmisc/loginprompt.c

index 660fc56cd6317e43a4cfa9c73515aec2cac4ae32..90f2e5925dbbb02ace75e569ac1112e03be82631 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2010-03-22  Nicolas François  <nicolas.francois@centraliens.net>
+
+       * 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  <nicolas.francois@centraliens.net>
 
        * libmisc/find_new_gid.c, libmisc/find_new_uid.c: Detect some
@@ -7,6 +21,8 @@
 2010-03-20  Nicolas François  <nicolas.francois@centraliens.net>
 
        * 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  <nicolas.francois@centraliens.net>
 
index 3add3c807bfebd518094806393e4df9187dcee10..25bdacfaaa93cb28e098e29bef6835320653d2d2 100644 (file)
 
 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]);
                }
index 1afcb13ed8c9219ed3eb8ef74f50b6e1a3c8202d..05cb0e4a9b0f0770a47abba4004275509be31e71 100644 (file)
 #include "defines.h"
 #include <stdio.h>
 #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);
index 94c25bf650aabd7f67e80e5e68811d14740b776d..45af2607d4eb031afc8e291df921da1a51b1e77e 100644 (file)
@@ -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
index 3c824a39d832efbd2583d179e623693ad445e7a7..7ce60690b36aa5b21f70a69f73ddf4afbfe629e3 100644 (file)
@@ -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;
                }
        }
index 1c08b9b40a3305dc41b123ed4b55ba1be29e39cc..8c54639cd6dfc43ae0dfe24f7128ebacd7e9563c 100644 (file)
@@ -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
index 139fe5f821eca8c9d1781bb71d33f70315d8ab18..7b330c28520181c159b96f5130eab33d9a51c4f5 100644 (file)
@@ -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
index ff6ac24f151d882dbaa3cf9a820a0360d3b0d483..cece004f9ad5785c403c51966d52ddc2103e1b2d 100644 (file)
@@ -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);
index 3ca893887d4f784573eae4dac488c135916a58f7..9373e610af29da0cfa2d4a1c8e1241fa518fdc5e 100644 (file)
@@ -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,");