/*
* 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)
{
char **ep, **end;
struct environment pruned_env;
- extern char *prev_user;
/* Find the end of the environment. */
for (end = envp; *end; end++)
*/
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 {
/*
* 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));
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)
def_closefrom = user_closefrom;
}
+ pruned_environ = clean_env(environ);
+
cmnd_status = set_cmnd(sudo_mode);
#ifdef HAVE_LDAP
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.
*/
* 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. */
} 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