From: Todd C. Miller Date: Sat, 17 Apr 2010 17:26:03 +0000 (-0400) Subject: Remove remaining references to the environ pointer. X-Git-Tag: SUDO_1_8_0~716 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0df204052f449d2b82a1888ad9cefc3916fce047;p=sudo Remove remaining references to the environ pointer. --- diff --git a/plugins/sudoers/env.c b/plugins/sudoers/env.c index 4856ace5f..88ecb11d5 100644 --- a/plugins/sudoers/env.c +++ b/plugins/sudoers/env.c @@ -234,6 +234,12 @@ env_init(char * const envp[]) return rval; } +char ** +env_get(void) +{ + return env.envp; +} + /* * Similar to setenv(3) but operates on sudo's private copy of the environment * (not environ) and it always overwrites. The dupcheck param determines @@ -263,7 +269,6 @@ sudo_setenv(var, val, dupcheck) /* * Version of setenv(3) that uses our own environ pointer. - * Will sync with environ as needed. */ int setenv(var, val, overwrite) @@ -312,7 +317,6 @@ setenv(var, val, overwrite) /* * Version of unsetenv(3) that uses our own environ pointer. - * Will sync with environ as needed. */ #ifdef UNSETENV_VOID void @@ -356,7 +360,6 @@ unsetenv(var) /* * Version of putenv(3) that uses our own environ pointer. - * Will sync with environ as needed. */ int #ifdef PUTENV_CONST diff --git a/plugins/sudoers/sudoers.c b/plugins/sudoers/sudoers.c index 551181a4d..5bb593e5e 100644 --- a/plugins/sudoers/sudoers.c +++ b/plugins/sudoers/sudoers.c @@ -123,14 +123,9 @@ static struct passwd *get_authpw(void); static int deserialize_info(char * const settings[], char * const user_info[]); extern int sudo_edit(int, char **, char **); -extern int rebuild_env(int, int); -extern int env_init(char * const envp[]); void validate_env_vars(struct list_member *); void insert_env_vars(struct list_member *); -/* XXX */ -char *fmt_string(const char *, const char *); - /* * Globals */ @@ -161,14 +156,10 @@ static struct sudo_nss_list *snl; static int NewArgc; static char **NewArgv; -/* XXX */ -extern char **environ; - /* error.c */ extern sigjmp_buf error_jmp; static int sudo_mode; -static char * const * user_env; static int sudoers_policy_open(unsigned int version, sudo_conv_t conversation, @@ -261,8 +252,8 @@ sudoers_policy_open(unsigned int version, sudo_conv_t conversation, /* Set login class if applicable. */ set_loginclass(sudo_user.pw); - /* XXX */ - user_env = envp; /* stash for later */ + /* Initialize environment functions (including replacements). */ + env_init(envp); return TRUE; } @@ -270,6 +261,7 @@ sudoers_policy_open(unsigned int version, sudo_conv_t conversation, static void sudoers_policy_close(int exit_status, int error_code) { + /* We do not currently log the exit status. */ if (error_code) warningx("unable to execute %s: %s", safe_cmnd, strerror(error_code)); } @@ -280,7 +272,6 @@ sudoers_policy_main(int argc, char * const argv[], char *env_add[], { static char *command_info[32]; /* XXX */ struct sudo_nss *nss; - char **old_environ = environ; int cmnd_status = -1, validated, pwflag = 0; int info_len = 0; int rval = FALSE; @@ -310,9 +301,6 @@ sudoers_policy_main(int argc, char * const argv[], char *env_add[], if (ISSET(sudo_mode, MODE_LOGIN_SHELL)) NewArgv[0] = runas_pw->pw_shell; - /* Set environ to contents of user_env. */ - env_init(user_env); - #ifdef USING_NONUNIX_GROUPS sudo_nonunix_groupcheck_init(); /* initialise nonunix groups impl */ #endif /* USING_NONUNIX_GROUPS */ @@ -576,13 +564,11 @@ sudoers_policy_main(int argc, char * const argv[], char *env_add[], *command_infop = command_info; *argv_out = NewArgv; - *user_env_out = environ; /* actually our local copy */ + *user_env_out = env_get(); /* our private copy */ rval = TRUE; done: - environ = old_environ; - return rval; } diff --git a/plugins/sudoers/sudoers.h b/plugins/sudoers/sudoers.h index 77b121a38..05463a356 100644 --- a/plugins/sudoers/sudoers.h +++ b/plugins/sudoers/sudoers.h @@ -306,6 +306,14 @@ void sudoers_io_close(int exit_status, int error); int sudoers_io_version(int verbose); int sudoers_io_log_output(const char *buf, unsigned int len); +/* env.c */ +char **env_get(void); +int env_init(char * const envp[]); +void rebuild_env(int, int); + +/* fmt_string.c */ +char *fmt_string(const char *, const char *); + /* Only provide extern declarations outside of sudo.c. */ #ifndef _SUDO_MAIN extern struct sudo_user sudo_user;