Add workaround for the lack of the environ pointer on Mac OS X

in dlopen()ed modules.  Use of environ in the sudoers plugin should
ultimately be removed but this will do for the moment.
This commit is contained in:
Todd C. Miller
2010-04-14 06:38:32 -04:00
parent 2b7f0ca955
commit fb87c040cc
4 changed files with 110 additions and 0 deletions

View File

@@ -43,6 +43,9 @@
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif /* HAVE_UNISTD_H */
#ifdef HAVE__NSGETENVIRON
#include <crt_externs.h>
#endif
#include <ctype.h>
#include <errno.h>
#include <pwd.h>
@@ -101,7 +104,12 @@ struct environment {
static void sudo_setenv(const char *, const char *, int);
static void sudo_putenv(char *, int, int);
/* XXX - should not need to muck with environ, use envp from env_init */
#ifdef HAVE__NSGETENVIRON
char **environ; /* global environment */
#else
extern char **environ; /* global environment */
#endif
/*
* Copy of the sudo-managed environment.
@@ -218,6 +226,10 @@ env_init(char * const envp[])
size_t len;
int rval = -1;
#ifdef HAVE__NSGETENVIRON
environ = _NSGetEnviron();
#endif
for (ep = envp; *ep != NULL; ep++)
continue;
len = (size_t)(ep - envp);