]> granicus.if.org Git - sudo/commitdiff
Remove remaining references to the environ pointer.
authorTodd C. Miller <Todd.Miller@courtesan.com>
Sat, 17 Apr 2010 17:26:03 +0000 (13:26 -0400)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Sat, 17 Apr 2010 17:26:03 +0000 (13:26 -0400)
plugins/sudoers/env.c
plugins/sudoers/sudoers.c
plugins/sudoers/sudoers.h

index 4856ace5f02bab97b91e8b9fa9c44986201578df..88ecb11d5a01840d0da83252a2b259ad47ce07b9 100644 (file)
@@ -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
index 551181a4d4a4fe6943ace9b9c4554d205ce372ad..5bb593e5e8d3a7700bda27da1128600e1b5229ff 100644 (file)
@@ -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;
 }
 
index 77b121a38e25b451d8393276fb3fd643addbe34e..05463a35635a82b82422c71bec57e124bf6d95f8 100644 (file)
@@ -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;