From 74894ebf628d811966aff48ee072cbd810e99ee3 Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Sun, 13 Feb 2005 05:33:59 +0000 Subject: [PATCH] Move setting of user_path, user_shell, user_prompt and prev_user into init_vars() since user_shell at least is needed there. --- env.c | 16 ---------------- sudo.c | 32 +++++++++++++++++++++++++------- 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/env.c b/env.c index 1a0c0b50e..2256643af 100644 --- a/env.c +++ b/env.c @@ -153,7 +153,6 @@ static const char *initial_keepenv_table[] = { /* * Remove potentially dangerous variables from the environment * and returns a vector of what was pruned out. - * Sets user_path, user_prompt and prev_user as side effects. */ char ** clean_env(envp) @@ -161,7 +160,6 @@ clean_env(envp) { char **ep, **end; struct environment pruned_env; - extern char *prev_user; /* Find the end of the environment. */ for (end = envp; *end; end++) @@ -173,20 +171,6 @@ clean_env(envp) */ memset(&pruned_env, 0, sizeof(pruned_env)); for (ep = envp; *ep; ) { - switch (**ep) { - case 'P': - if (strncmp("PATH=", *ep, 5) == 0) - user_path = *ep + 5; - break; - case 'S': - if (strncmp("SHELL=", *ep, 6) == 0) - user_shell = *ep + 6; - else if (!user_prompt && strncmp("SUDO_PROMPT=", *ep, 12) == 0) - user_prompt = *ep + 12; - else if (strncmp("SUDO_USER=", *ep, 10) == 0) - prev_user = *ep + 10; - break; - } if (var_ok(*ep)) { ep++; } else { diff --git a/sudo.c b/sudo.c index 80ff17ee4..6d47a7b79 100644 --- a/sudo.c +++ b/sudo.c @@ -99,7 +99,7 @@ __unused static const char rcsid[] = "$Sudo$"; /* * Prototypes */ -static void init_vars __P((int)); +static void init_vars __P((int, char **)); static int set_cmnd __P((int)); static int parse_args __P((int, char **)); static void initial_setup __P((void)); @@ -254,7 +254,7 @@ main(argc, argv) if (user_cmnd == NULL && NewArgc == 0) usage(1); - init_vars(sudo_mode); /* XXX - move this? */ + init_vars(sudo_mode, environ); /* XXX - move this? */ #ifdef HAVE_LDAP if ((ld = sudo_ldap_open()) != NULL) @@ -292,6 +292,8 @@ main(argc, argv) def_closefrom = user_closefrom; } + pruned_environ = clean_env(environ); + cmnd_status = set_cmnd(sudo_mode); #ifdef HAVE_LDAP @@ -306,9 +308,6 @@ main(argc, argv) if (safe_cmnd == NULL) safe_cmnd = estrdup(user_cmnd); - /* Clean out the environment. */ - pruned_environ = clean_env(environ); - /* * Look up the timestamp dir owner if one is specified. */ @@ -495,10 +494,11 @@ main(argc, argv) * load the ``interfaces'' array. */ static void -init_vars(sudo_mode) +init_vars(sudo_mode, envp) int sudo_mode; + char **envp; { - char *p, thost[MAXHOSTNAMELEN]; + char *p, **ep, thost[MAXHOSTNAMELEN]; int nohostname; /* Sanity check command from user. */ @@ -546,6 +546,24 @@ init_vars(sudo_mode) } else user_tty = "unknown"; + for (ep = envp; *ep; ep++) { + switch (**ep) { + case 'P': + if (strncmp("PATH=", *ep, 5) == 0) + user_path = *ep + 5; + break; + case 'S': + if (strncmp("SHELL=", *ep, 6) == 0) + user_shell = *ep + 6; + else if (!user_prompt && strncmp("SUDO_PROMPT=", *ep, 12) == 0) + user_prompt = *ep + 12; + else if (strncmp("SUDO_USER=", *ep, 10) == 0) + prev_user = *ep + 10; + break; + + } + } + /* * Get a local copy of the user's struct passwd with the shadow password * if necessary. It is assumed that euid is 0 at this point so we -- 2.40.0