Changeset View
Changeset View
Standalone View
Standalone View
usr.sbin/cron/cron/do_command.c
Show All 37 Lines | |||||
#endif | #endif | ||||
static void child_process(entry *, user *), | static void child_process(entry *, user *), | ||||
do_univ(user *); | do_univ(user *); | ||||
static WAIT_T wait_on_child(PID_T, const char *); | static WAIT_T wait_on_child(PID_T, const char *); | ||||
extern char *environ; | |||||
void | void | ||||
do_command(e, u) | do_command(e, u) | ||||
entry *e; | entry *e; | ||||
user *u; | user *u; | ||||
{ | { | ||||
pid_t pid; | pid_t pid; | ||||
Debug(DPROC, ("[%d] do_command(%s, (%s,%d,%d))\n", | Debug(DPROC, ("[%d] do_command(%s, (%s,%d,%d))\n", | ||||
▲ Show 20 Lines • Show All 226 Lines • ▼ Show 20 Lines | #endif | ||||
close(stdout_pipe[WRITE_PIPE]); | close(stdout_pipe[WRITE_PIPE]); | ||||
/* set our login universe. Do this in the grandchild | /* set our login universe. Do this in the grandchild | ||||
* so that the child can invoke /usr/lib/sendmail | * so that the child can invoke /usr/lib/sendmail | ||||
* without surprises. | * without surprises. | ||||
*/ | */ | ||||
do_univ(u); | do_univ(u); | ||||
environ = NULL; | |||||
# if defined(LOGIN_CAP) | # if defined(LOGIN_CAP) | ||||
/* Set user's entire context, but skip the environment | /* Set user's entire context, but note that PATH will | ||||
* as cron provides a separate interface for this | * be overridden later | ||||
*/ | */ | ||||
if ((pwd = getpwnam(usernm)) == NULL) | if ((pwd = getpwnam(usernm)) == NULL) | ||||
pwd = getpwuid(e->uid); | pwd = getpwuid(e->uid); | ||||
lc = NULL; | lc = NULL; | ||||
if (pwd != NULL) { | if (pwd != NULL) { | ||||
pwd->pw_gid = e->gid; | pwd->pw_gid = e->gid; | ||||
if (e->class != NULL) | if (e->class != NULL) | ||||
lc = login_getclass(e->class); | lc = login_getclass(e->class); | ||||
} | } | ||||
if (pwd && | if (pwd && | ||||
setusercontext(lc, pwd, e->uid, | setusercontext(lc, pwd, e->uid, | ||||
LOGIN_SETALL & ~(LOGIN_SETPATH|LOGIN_SETENV)) == 0) | LOGIN_SETALL) == 0) | ||||
(void) endpwent(); | (void) endpwent(); | ||||
else { | else { | ||||
/* fall back to the old method */ | /* fall back to the old method */ | ||||
(void) endpwent(); | (void) endpwent(); | ||||
# endif | # endif | ||||
/* set our directory, uid and gid. Set gid first, | /* set our directory, uid and gid. Set gid first, | ||||
* since once we set uid, we've lost root privileges. | * since once we set uid, we've lost root privileges. | ||||
*/ | */ | ||||
Show All 26 Lines | if (lc != NULL) | ||||
login_close(lc); | login_close(lc); | ||||
#endif | #endif | ||||
chdir(env_get("HOME", e->envp)); | chdir(env_get("HOME", e->envp)); | ||||
/* exec the command. | /* exec the command. | ||||
*/ | */ | ||||
{ | { | ||||
char *shell = env_get("SHELL", e->envp); | char *shell = env_get("SHELL", e->envp); | ||||
char **p; | |||||
/* Apply the environment from the entry, overriding existing | |||||
* values (this will always set PATH, LOGNAME, etc.) putenv | |||||
* should not fail unless malloc does. | |||||
*/ | |||||
for (p = e->envp; *p; ++p) { | |||||
if (putenv(*p) != 0) { | |||||
warn("putenv"); | |||||
_exit(ERROR_EXIT); | |||||
} | |||||
} | |||||
# if DEBUGGING | # if DEBUGGING | ||||
if (DebugFlags & DTEST) { | if (DebugFlags & DTEST) { | ||||
fprintf(stderr, | fprintf(stderr, | ||||
"debug DTEST is on, not exec'ing command.\n"); | "debug DTEST is on, not exec'ing command.\n"); | ||||
fprintf(stderr, | fprintf(stderr, | ||||
"\tcmd='%s' shell='%s'\n", e->cmd, shell); | "\tcmd='%s' shell='%s'\n", e->cmd, shell); | ||||
_exit(OK_EXIT); | _exit(OK_EXIT); | ||||
} | } | ||||
# endif /*DEBUGGING*/ | # endif /*DEBUGGING*/ | ||||
execle(shell, shell, "-c", e->cmd, (char *)NULL, | execl(shell, shell, "-c", e->cmd, (char *)NULL); | ||||
e->envp); | warn("execl: couldn't exec `%s'", shell); | ||||
warn("execle: couldn't exec `%s'", shell); | |||||
_exit(ERROR_EXIT); | _exit(ERROR_EXIT); | ||||
} | } | ||||
break; | break; | ||||
default: | default: | ||||
/* parent process */ | /* parent process */ | ||||
break; | break; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 302 Lines • Show Last 20 Lines |