]> granicus.if.org Git - shadow/commitdiff
Ensure that getpwent() is used in setpwent(), getpwent(),
authornekral-guest <nekral-guest@5a98b0ae-9ef6-0310-add3-de5d479b70d7>
Wed, 16 Apr 2008 21:52:46 +0000 (21:52 +0000)
committernekral-guest <nekral-guest@5a98b0ae-9ef6-0310-add3-de5d479b70d7>
Wed, 16 Apr 2008 21:52:46 +0000 (21:52 +0000)
endpwend() sequences (ditto for getgrent(), getspent(), and
getsgent()). The only real (minor) issue was in login, which kept
the passwd file open.
* libmisc/entry.c: Remove unneeded setspent() and endspent() (only
  getspnam is called in the middle).
* libmisc/find_new_ids.c: Make sure to close the password and
  group files with endpwent() and endgrent().
* libmisc/pwdcheck.c: Remove unneeded endspent() (only getspnam()
  is called before).
* src/lastlog.c, src/passwd.c, src/groupmod.c, src/faillog.c,
  src/groups.c: Make sure to close
  the password file with endpwent().
* src/login.c: Remove unneeded setpwent() (only xgetpwnam is
  called before).
* src/login.c, src/newgrp.c: Fix typos in comments.

ChangeLog
libmisc/entry.c
libmisc/find_new_ids.c
libmisc/pwdcheck.c
src/faillog.c
src/groupmod.c
src/groups.c
src/lastlog.c
src/login.c
src/newgrp.c
src/passwd.c

index dc3630a9ae6e292cc6df120d952ad1ee65e2fcff..ac6fef85d32792b1b8e4850baa8b1fb20d849ea7 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,22 @@
+2008-04-16  Nicolas François  <nicolas.francois@centraliens.net>
+
+       Ensure that getpwent() is used in setpwent(), getpwent(),
+       endpwend() sequences (ditto for getgrent(), getspent(), and
+       getsgent()). The only real (minor) issue was in login, which kept
+       the passwd file open.
+       * libmisc/entry.c: Remove unneeded setspent() and endspent() (only
+       getspnam is called in the middle).
+       * libmisc/find_new_ids.c: Make sure to close the password and
+       group files with endpwent() and endgrent().
+       * libmisc/pwdcheck.c: Remove unneeded endspent() (only getspnam()
+       is called before).
+       * src/lastlog.c, src/passwd.c, src/groupmod.c, src/faillog.c,
+       src/groups.c: Make sure to close
+       the password file with endpwent().
+       * src/login.c: Remove unneeded setpwent() (only xgetpwnam is
+       called before).
+       * src/login.c, src/newgrp.c: Fix typos in comments.
+
 2008-04-16  Nicolas François  <nicolas.francois@centraliens.net>
 
        * NEWS, configure.in: Fix the detection of the audit, pam, and
index 5b95eba1b8a90837f282bac967323229ead92e39..3316c8d5046dde16a2eba7defaea1026e3d6000e 100644 (file)
@@ -54,14 +54,11 @@ void pw_entry (const char *name, struct passwd *pwent)
                pwent->pw_dir = xstrdup (passwd->pw_dir);
                pwent->pw_shell = xstrdup (passwd->pw_shell);
 #if !defined(AUTOSHADOW)
-               setspent ();
                /* local, no need for xgetspnam */
                if ((spwd = getspnam (name))) {
                        pwent->pw_passwd = xstrdup (spwd->sp_pwdp);
-                       endspent ();
                        return;
                }
-               endspent ();
 #endif
                pwent->pw_passwd = xstrdup (passwd->pw_passwd);
        }
index 66dc6e80c0e6bb02eff8e6ed1a0310eaded773d0..90e4ceef3afad7350a1e99a577ad46e182c3f496 100644 (file)
@@ -65,6 +65,7 @@ int find_new_uid (int sys_user, uid_t *uid, uid_t const *preferred_uid)
                        user_id = pwd->pw_uid + 1;
                }
        }
+       endpwent ();
 
        /*
         * If a user with UID equal to UID_MAX exists, the above algorithm
@@ -146,6 +147,7 @@ int find_new_gid (int sys_group, gid_t *gid, gid_t const *preferred_gid)
                        group_id = grp->gr_gid + 1;
                }
        }
+       endgrent ();
 
        /*
         * If a group with GID equal to GID_MAX exists, the above algorithm
index 1750ebf38ad6c0b2daa37b3cc83a32598ec2e0f3..ce0a4f2c69676986cc1620214c527dfae6d643d8 100644 (file)
@@ -46,7 +46,6 @@ void passwd_check (const char *user, const char *passwd, const char *progname)
 
        if ((sp = getspnam (user))) /* !USE_PAM, no need for xgetspnam */
                passwd = sp->sp_pwdp;
-       endspent ();
        if (pw_auth (passwd, user, PW_LOGIN, (char *) 0) != 0) {
                SYSLOG ((LOG_WARN, WRONGPWD2, user));
                sleep (1);
index 024e044db8e2f44c144cb00bb4e0d807092bc6f2..36c38ff051ed8113da1f9352c1c9df3662356852 100644 (file)
@@ -170,6 +170,7 @@ static void reset (void)
                while ( (pwent = getpwent ()) != NULL ) {
                        reset_one (pwent->pw_uid);
                }
+               endpwent ();
        }
 }
 
@@ -246,8 +247,10 @@ static void setmax (int max)
                setmax_one (user, max);
        } else {
                setpwent ();
-               while ((pwent = getpwent ()))
+               while ( (pwent = getpwent ()) != NULL ) {
                        setmax_one (pwent->pw_uid, max);
+               }
+               endpwent ();
        }
 }
 
@@ -288,8 +291,10 @@ static void set_locktime (long locktime)
                set_locktime_one (user, locktime);
        } else {
                setpwent ();
-               while ((pwent = getpwent ()))
+               while ( (pwent = getpwent ()) != NULL ) {
                        set_locktime_one (pwent->pw_uid, locktime);
+               }
+               endpwent ();
        }
 }
 
index 274c3adb7cfec0446da24dcfe50261f3eff64e02..1a3f55b311365709add5209e3d837595ce5601e6 100644 (file)
@@ -547,6 +547,7 @@ void update_primary_groups (gid_t ogid, gid_t ngid)
                        }
                }
        }
+       endpwent ();
 }
 
 /*
index 53fdfb7dbca606dc8b54dae675efd5abff96aae9..9f89a7057925df96ae4bef5727115f24b002530e 100644 (file)
@@ -57,13 +57,12 @@ static void print_groups (const char *member)
        struct passwd *pwd;
        int flag = 0;
 
-       setgrent ();
-
        /* local, no need for xgetpwnam */
        if ((pwd = getpwnam (member)) == 0) {
                fprintf (stderr, _("%s: unknown user %s\n"), Prog, member);
                exit (1);
        }
+       setgrent ();
        while ((grp = getgrent ())) {
                if (is_on_list (grp->gr_mem, member)) {
                        if (groups++)
@@ -74,6 +73,7 @@ static void print_groups (const char *member)
                                flag = 1;
                }
        }
+       endgrent ();
        /* local, no need for xgetgrgid */
        if (!flag && (grp = getgrgid (pwd->pw_gid))) {
                if (groups++)
index 445a1cc73dd2beac613bb9a88c01f8a24f4f4abb..7b70bae6c085b09760bfdbcc0478400e595c9008 100644 (file)
@@ -128,7 +128,7 @@ static void print (void)
        uid_t user;
 
        setpwent ();
-       while ((pwent = getpwent ())) {
+       while ( (pwent = getpwent ()) != NULL ) {
                user = pwent->pw_uid;
                if (uflg &&
                    ((umin != -1 && user < (uid_t)umin) ||
@@ -149,6 +149,7 @@ static void print (void)
 
                print_one (pwent);
        }
+       endpwent ();
 }
 
 int main (int argc, char **argv)
index aa9e55603e0cbce35f84d1209ea091dfa6c0abf3..79f3eedd63f64a0ccfd76710469557d0d90128ab 100644 (file)
@@ -738,7 +738,6 @@ int main (int argc, char **argv)
                 */
                retcode =
                    pam_get_item (pamh, PAM_USER, (const void **)ptr_pam_user);
-               setpwent ();
                pwd = xgetpwnam (pam_user);
                if (!pwd) {
                        SYSLOG ((LOG_ERR, "xgetpwnam(%s) failed",
@@ -962,7 +961,7 @@ int main (int argc, char **argv)
        if (pwent.pw_shell[0] == '*') { /* subsystem root */
                pwent.pw_shell++;       /* skip the '*' */
                subsystem (&pwent);     /* figure out what to execute */
-               subroot++;      /* say i was here again */
+               subroot++;      /* say I was here again */
                endpwent ();    /* close all of the file which were */
                endgrent ();    /* open in the original rooted file */
                endspent ();    /* system. they will be re-opened */
index bf94d8bdeed5d97de85412e0dd1cb7f4aaa4db5f..3f07a4ed19c704cb6f102506ba50a23d6610b101 100644 (file)
@@ -695,7 +695,7 @@ int main (int argc, char **argv)
                prog = "/bin/sh";
 
        /*
-        * Now i try to find the basename of the login shell. This will
+        * Now I try to find the basename of the login shell. This will
         * become argv[0] of the spawned command.
         */
        cp = Basename ((char *) prog);
index e85b2fe2f45ab6d2b0aac25b9315de2a17120f71..42df517b303bee8ad30b9e33a3a57ddd6aaa2986 100644 (file)
@@ -848,8 +848,10 @@ int main (int argc, char **argv)
                        exit (E_NOPERM);
                }
                setpwent ();
-               while ((pw = getpwent ()))
+               while ( (pw = getpwent ()) != NULL ) {
                        print_status (pw);
+               }
+               endpwent ();
                exit (E_SUCCESS);
        }
 #if 0