Use setpassent() and setgroupent() on systems that support it to

keep the passwd and group database open.  Sudo does a lot of passwd
and group lookups so it can be beneficial to just leave the file
open.
This commit is contained in:
Todd C. Miller
2018-02-20 13:22:59 -07:00
parent 4f9296928c
commit faa5baac9b
4 changed files with 35 additions and 0 deletions

View File

@@ -508,6 +508,19 @@ get_user_info(struct user_details *ud)
int fd;
debug_decl(get_user_info, SUDO_DEBUG_UTIL)
/*
* On BSD systems you can set a hint to keep the password and
* group databases open instead of having to open and close
* them all the time. Since sudo does a lot of password and
* group lookups, keeping the file open can speed things up.
*/
#ifdef HAVE_SETPASSENT
setpassent(1);
#endif /* HAVE_SETPASSENT */
#ifdef HAVE_SETGROUPENT
setgroupent(1);
#endif /* HAVE_SETGROUPENT */
memset(ud, 0, sizeof(*ud));
/* XXX - bound check number of entries */