2
0
mirror of https://github.com/sudo-project/sudo.git synced 2025-08-31 06:15:37 +00:00

Set close on exec flag in private versions of setpwent() and setgrent().

This commit is contained in:
Todd C. Miller
2010-05-21 14:51:05 -04:00
parent 16c2769ed9
commit d3d8364d4e

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2005,2008 Todd C. Miller <Todd.Miller@courtesan.com>
* Copyright (c) 2005, 2008, 2010 Todd C. Miller <Todd.Miller@courtesan.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -43,6 +43,7 @@
# include <strings.h>
# endif
#endif /* HAVE_STRING_H */
#include <fcntl.h>
#include <limits.h>
#include <pwd.h>
#include <grp.h>
@@ -89,10 +90,13 @@ setpwfile(const char *file)
void
setpwent(void)
{
if (pwf == NULL)
if (pwf == NULL) {
pwf = fopen(pwfile, "r");
else
if (pwf != NULL)
fcntl(fileno(pwf), F_SETFD, FD_CLOEXEC);
} else {
rewind(pwf);
}
pw_stayopen = 1;
}
@@ -154,10 +158,13 @@ getpwnam(const char *name)
{
struct passwd *pw;
if (pwf != NULL)
if (pwf == NULL) {
if ((pwf = fopen(pwfile, "r")) == NULL)
return(NULL);
fcntl(fileno(pwf), F_SETFD, FD_CLOEXEC);
} else {
rewind(pwf);
else if ((pwf = fopen(pwfile, "r")) == NULL)
return(NULL);
}
while ((pw = getpwent()) != NULL) {
if (strcmp(pw->pw_name, name) == 0)
break;
@@ -174,10 +181,13 @@ getpwuid(uid_t uid)
{
struct passwd *pw;
if (pwf != NULL)
if (pwf == NULL) {
if ((pwf = fopen(pwfile, "r")) == NULL)
return(NULL);
fcntl(fileno(pwf), F_SETFD, FD_CLOEXEC);
} else {
rewind(pwf);
else if ((pwf = fopen(pwfile, "r")) == NULL)
return(NULL);
}
while ((pw = getpwent()) != NULL) {
if (pw->pw_uid == uid)
break;
@@ -200,10 +210,13 @@ setgrfile(const char *file)
void
setgrent(void)
{
if (grf == NULL)
if (grf == NULL) {
grf = fopen(grfile, "r");
else
if (grf != NULL)
fcntl(fileno(grf), F_SETFD, FD_CLOEXEC);
} else {
rewind(grf);
}
gr_stayopen = 1;
}
@@ -263,10 +276,13 @@ getgrnam(const char *name)
{
struct group *gr;
if (grf != NULL)
if (grf == NULL) {
if ((grf = fopen(grfile, "r")) == NULL)
return(NULL);
fcntl(fileno(grf), F_SETFD, FD_CLOEXEC);
} else {
rewind(grf);
else if ((grf = fopen(grfile, "r")) == NULL)
return(NULL);
}
while ((gr = getgrent()) != NULL) {
if (strcmp(gr->gr_name, name) == 0)
break;
@@ -283,10 +299,13 @@ getgrgid(gid_t gid)
{
struct group *gr;
if (grf != NULL)
if (grf == NULL) {
if ((grf = fopen(grfile, "r")) == NULL)
return(NULL);
fcntl(fileno(grf), F_SETFD, FD_CLOEXEC);
} else {
rewind(grf);
else if ((grf = fopen(grfile, "r")) == NULL)
return(NULL);
}
while ((gr = getgrent()) != NULL) {
if (gr->gr_gid == gid)
break;