From: Tom Jones Date: Thu, 11 Oct 2012 12:00:56 +0000 (+0200) Subject: The sysadmin may want to arrange for the PATH to be correct in the X-Git-Tag: cronie1.4.9~3 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6cfe58734d68de972786742690cd3c14933fa8e1;p=cronie The sysadmin may want to arrange for the PATH to be correct in the environment from which cron is launched. This new option tells cron to not overwrite this path for itself or for the child cron jobs. Signed-off-by: Marcela Mašláňová --- diff --git a/man/cron.8 b/man/cron.8 index d378927..ab21f2a 100644 --- a/man/cron.8 +++ b/man/cron.8 @@ -167,6 +167,9 @@ installed or if mail is disabled. .TP .B "\-x" This option allows you to set debug flags. +.TP +.B "\-P" +Don't set PATH. PATH is instead inherited from the environment. .SH SIGNALS When the \s-2SIGHUP\s+2 is received, the .I Cron diff --git a/src/cron.c b/src/cron.c index ee1d2a8..a532850 100644 --- a/src/cron.c +++ b/src/cron.c @@ -192,6 +192,7 @@ int main(int argc, char *argv[]) { SyslogOutput = 0; NoFork = 0; + ChangePath = 1; parse_args(argc, argv); bzero((char *) &sact, sizeof sact); @@ -212,9 +213,12 @@ int main(int argc, char *argv[]) { set_cron_uid(); check_spool_dir(); - if (putenv("PATH=" _PATH_DEFPATH) < 0) { - log_it("CRON", pid, "DEATH", "can't putenv PATH", errno); - exit(1); + if (ChangePath) { + if (putenv("PATH=" _PATH_DEFPATH) < 0) { + log_it("CRON", pid, "DEATH", "can't putenv PATH", + errno); + exit(1); + } } /* Get the default locale character set for the mail @@ -650,7 +654,7 @@ static void sigchld_reaper(void) { static void parse_args(int argc, char *argv[]) { int argch; - while (-1 != (argch = getopt(argc, argv, "hnpsix:m:c"))) { + while (-1 != (argch = getopt(argc, argv, "hnpsiPx:m:c"))) { switch (argch) { case 'x': if (!set_debug_flags(optarg)) @@ -668,6 +672,9 @@ static void parse_args(int argc, char *argv[]) { case 'i': DisableInotify = 1; break; + case 'P': + ChangePath = 0; + break; case 'm': strncpy(MailCmd, optarg, MAX_COMMAND); break; diff --git a/src/entry.c b/src/entry.c index 8eff42a..f09427c 100644 --- a/src/entry.c +++ b/src/entry.c @@ -314,7 +314,7 @@ entry *load_entry(FILE * file, void (*error_func) (), struct passwd *pw, } #ifndef LOGIN_CAP /* If login.conf is in used we will get the default PATH later. */ - if (!env_get("PATH", e->envp)) { + if (ChangePath && !env_get("PATH", e->envp)) { if (glue_strings(envstr, sizeof envstr, "PATH", _PATH_DEFPATH, '=')) { if ((tenvp = env_set(e->envp, envstr)) == NULL) { ecode = e_memory; diff --git a/src/globals.h b/src/globals.h index c7a811d..8abdb73 100644 --- a/src/globals.h +++ b/src/globals.h @@ -73,6 +73,7 @@ XTRN int PermitAnyCrontab; XTRN char MailCmd[MAX_COMMAND]; XTRN char cron_default_mail_charset[MAX_ENVSTR]; XTRN int EnableClustering; +XTRN int ChangePath; #if DEBUGGING XTRN int DebugFlags INIT(0);