-
Notifications
You must be signed in to change notification settings - Fork 24
Open
Description
(Note: This is a copy of a Google-internal issue written by Stan Shebs, who's now retired; unfortunately I don't have additional context.)
Calling getpwnam() inside of a getpwent() loop causes it to run forever, if nss_cache is in use:
while ((pw = getpwent()) != NULL)
{
pw2 = getpwnam("anyname");
}
The problem is that getpwnam closes /etc/passwd.cache, so getpwent() then has to open and start reading from the
beginning again. The nss_files module has a bit of special code to prevent this, nss_cache will need something like it.
The attached file takes an argument, so you can see "bad files" work, and "bad cache" hang:
#include <pwd.h>
#include <stdlib.h>
int
main(int argc, char **argv)
{
char *serviceline = "cache";
struct passwd *pw, *pw2;
if (argc > 1)
serviceline = argv[1];
__nss_configure_lookup("passwd", serviceline);
setpwent();
while ((pw = getpwent()) != NULL)
{
pw2 = getpwnam("anyname");
}
}
Metadata
Metadata
Assignees
Labels
No labels