mirror of
https://github.com/sudo-project/sudo.git
synced 2025-09-01 14:55:12 +00:00
now set SUDO_ envariables
This commit is contained in:
42
sudo.c
42
sudo.c
@@ -97,6 +97,7 @@ extern char *strdup();
|
|||||||
*/
|
*/
|
||||||
static void usage __P((void));
|
static void usage __P((void));
|
||||||
static void load_globals __P((void));
|
static void load_globals __P((void));
|
||||||
|
static void add_env __P((void));
|
||||||
static void rmenv __P((char **, char *, int));
|
static void rmenv __P((char **, char *, int));
|
||||||
static void clean_env __P((char **));
|
static void clean_env __P((char **));
|
||||||
|
|
||||||
@@ -167,6 +168,8 @@ main(argc, argv)
|
|||||||
|
|
||||||
load_globals(); /* load the user host cmnd and uid variables */
|
load_globals(); /* load the user host cmnd and uid variables */
|
||||||
|
|
||||||
|
add_env(); /* add in SUDO_* envariables */
|
||||||
|
|
||||||
rtn = validate();
|
rtn = validate();
|
||||||
switch (rtn) {
|
switch (rtn) {
|
||||||
|
|
||||||
@@ -452,3 +455,42 @@ static void rmenv(envp, s, len)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**********************************************************************
|
||||||
|
*
|
||||||
|
* add_env()
|
||||||
|
*
|
||||||
|
* this function adds sudo-specific variables into the environment
|
||||||
|
*/
|
||||||
|
|
||||||
|
static void add_env()
|
||||||
|
{
|
||||||
|
char *envar;
|
||||||
|
int len, n;
|
||||||
|
|
||||||
|
/* add the SUDO_USER envariable */
|
||||||
|
envar = (char *) malloc(strlen(user) + 10);
|
||||||
|
if (envar == NULL) {
|
||||||
|
perror("malloc");
|
||||||
|
(void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
(void) strcpy(envar, "SUDO_USER=");
|
||||||
|
(void) strcpy(envar+10, user);
|
||||||
|
(void) putenv(envar);
|
||||||
|
|
||||||
|
/* add the SUDO_UID envariable */
|
||||||
|
for (len = 1 + (uid < 0), n = (int)uid; (n = n / 10) != 0; )
|
||||||
|
++len;
|
||||||
|
|
||||||
|
envar = (char *) malloc(len+9);
|
||||||
|
if (envar == NULL) {
|
||||||
|
perror("malloc");
|
||||||
|
(void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
(void) sprintf(envar, "SUDO_UID=%d", (int)uid);
|
||||||
|
(void) putenv(envar);
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user