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:
@@ -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);
|
||||
}
|
||||
|
@@ -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
|
||||
|
@@ -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);
|
||||
|
Reference in New Issue
Block a user