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.
This commit is contained in:
@@ -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 ();
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -547,6 +547,7 @@ void update_primary_groups (gid_t ogid, gid_t ngid)
|
||||
}
|
||||
}
|
||||
}
|
||||
endpwent ();
|
||||
}
|
||||
|
||||
/*
|
||||
|
@@ -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++)
|
||||
|
@@ -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)
|
||||
|
@@ -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 */
|
||||
|
@@ -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);
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user