mirror of
https://github.com/sudo-project/sudo.git
synced 2025-09-01 06:45:10 +00:00
Set close on exec flag in private versions of setpwent() and setgrent().
This commit is contained in:
@@ -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
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
@@ -43,6 +43,7 @@
|
|||||||
# include <strings.h>
|
# include <strings.h>
|
||||||
# endif
|
# endif
|
||||||
#endif /* HAVE_STRING_H */
|
#endif /* HAVE_STRING_H */
|
||||||
|
#include <fcntl.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
#include <grp.h>
|
#include <grp.h>
|
||||||
@@ -89,10 +90,13 @@ setpwfile(const char *file)
|
|||||||
void
|
void
|
||||||
setpwent(void)
|
setpwent(void)
|
||||||
{
|
{
|
||||||
if (pwf == NULL)
|
if (pwf == NULL) {
|
||||||
pwf = fopen(pwfile, "r");
|
pwf = fopen(pwfile, "r");
|
||||||
else
|
if (pwf != NULL)
|
||||||
|
fcntl(fileno(pwf), F_SETFD, FD_CLOEXEC);
|
||||||
|
} else {
|
||||||
rewind(pwf);
|
rewind(pwf);
|
||||||
|
}
|
||||||
pw_stayopen = 1;
|
pw_stayopen = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -154,10 +158,13 @@ getpwnam(const char *name)
|
|||||||
{
|
{
|
||||||
struct passwd *pw;
|
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);
|
rewind(pwf);
|
||||||
else if ((pwf = fopen(pwfile, "r")) == NULL)
|
}
|
||||||
return(NULL);
|
|
||||||
while ((pw = getpwent()) != NULL) {
|
while ((pw = getpwent()) != NULL) {
|
||||||
if (strcmp(pw->pw_name, name) == 0)
|
if (strcmp(pw->pw_name, name) == 0)
|
||||||
break;
|
break;
|
||||||
@@ -174,10 +181,13 @@ getpwuid(uid_t uid)
|
|||||||
{
|
{
|
||||||
struct passwd *pw;
|
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);
|
rewind(pwf);
|
||||||
else if ((pwf = fopen(pwfile, "r")) == NULL)
|
}
|
||||||
return(NULL);
|
|
||||||
while ((pw = getpwent()) != NULL) {
|
while ((pw = getpwent()) != NULL) {
|
||||||
if (pw->pw_uid == uid)
|
if (pw->pw_uid == uid)
|
||||||
break;
|
break;
|
||||||
@@ -200,10 +210,13 @@ setgrfile(const char *file)
|
|||||||
void
|
void
|
||||||
setgrent(void)
|
setgrent(void)
|
||||||
{
|
{
|
||||||
if (grf == NULL)
|
if (grf == NULL) {
|
||||||
grf = fopen(grfile, "r");
|
grf = fopen(grfile, "r");
|
||||||
else
|
if (grf != NULL)
|
||||||
|
fcntl(fileno(grf), F_SETFD, FD_CLOEXEC);
|
||||||
|
} else {
|
||||||
rewind(grf);
|
rewind(grf);
|
||||||
|
}
|
||||||
gr_stayopen = 1;
|
gr_stayopen = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -263,10 +276,13 @@ getgrnam(const char *name)
|
|||||||
{
|
{
|
||||||
struct group *gr;
|
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);
|
rewind(grf);
|
||||||
else if ((grf = fopen(grfile, "r")) == NULL)
|
}
|
||||||
return(NULL);
|
|
||||||
while ((gr = getgrent()) != NULL) {
|
while ((gr = getgrent()) != NULL) {
|
||||||
if (strcmp(gr->gr_name, name) == 0)
|
if (strcmp(gr->gr_name, name) == 0)
|
||||||
break;
|
break;
|
||||||
@@ -283,10 +299,13 @@ getgrgid(gid_t gid)
|
|||||||
{
|
{
|
||||||
struct group *gr;
|
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);
|
rewind(grf);
|
||||||
else if ((grf = fopen(grfile, "r")) == NULL)
|
}
|
||||||
return(NULL);
|
|
||||||
while ((gr = getgrent()) != NULL) {
|
while ((gr = getgrent()) != NULL) {
|
||||||
if (gr->gr_gid == gid)
|
if (gr->gr_gid == gid)
|
||||||
break;
|
break;
|
||||||
|
Reference in New Issue
Block a user