Package: cron
Version: 3.0pl1-116
Severity: wishlist

The default PATH of cron isn't very useful.  This patch adds an
option -P to leave PATH alone, so that it's inherited from whatever
execs cron.  In our case that is daemontools, but could also be
start-stop-daemon or whatever.  This puts our sysadmins in control
of cron's (and child processes') PATH, as they are able to set it in the 
run script.  Without the -P option, crontabs that don't set PATH
themselves get a value of /usr/bin:/bin, which is hardcoded as
_PATH_DEFPATH in pathnames.h.

diff --git a/cron.8 b/cron.8
index 586d9e5..41387fa 100644
--- a/cron.8
+++ b/cron.8
@@ -36,6 +36,9 @@ runlevels.
 .B -f
 Stay in foreground mode, don't daemonize.
 .TP
+.B -P
+Don't set PATH for child processes.  Let it inherit instead.
+.TP
 .B -l
 Enable LSB compliant names for /etc/cron.d files. This setting, however, does
 not affect the parsing of files under /etc/cron.hourly, /etc/cron.daily,
diff --git a/cron.c b/cron.c
index 5630b4d..638ca3f 100644
--- a/cron.c
+++ b/cron.c
@@ -93,7 +93,9 @@ main(argc, argv)
        set_cron_cwd();
 
 #if defined(POSIX)
-       setenv("PATH", _PATH_DEFPATH, 1);
+       if (change_child_path) {
+               setenv("PATH", _PATH_DEFPATH, 1);
+       }
 #endif
 
        /* Get the default locale character set for the mail
@@ -468,15 +470,19 @@ parse_args(argc, argv)
 
        log_level = 1;
        stay_foreground = 0;
+       change_child_path = 1;
         lsbsysinit_mode = 0;
 
-       while (EOF != (argch = getopt(argc, argv, "lfx:L:"))) {
+       while (EOF != (argch = getopt(argc, argv, "lfPx:L:"))) {
                switch (argch) {
                default:
                        usage();
                case 'f':
                        stay_foreground = 1;
                        break;
+               case 'P':
+                       change_child_path = 0;
+                       break;
                case 'x':
                        if (!set_debug_flags(optarg))
                                usage();
diff --git a/cron.h b/cron.h
index d1b2bcf..8e10393 100644
--- a/cron.h
+++ b/cron.h
@@ -304,6 +304,7 @@ time_min clockTime;
 static long GMToff;
 
 int    stay_foreground;
+int    change_child_path;
 int     lsbsysinit_mode;
 int     log_level = 1;
 char    cron_default_mail_charset[MAX_ENVSTR] = "";
diff --git a/debian/changelog b/debian/changelog
index 954b5ce..5bd7e51 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,10 @@
+cron (3.0pl1-124.1) unstable; urgency=low
+
+  * Non-maintainer upload.
+  * Add -P option to preserve PATH.
+
+ -- Tom Jones <[email protected]>  Tue, 25 Sep 2012 00:57:10 +0100
+
 cron (3.0pl1-124) unstable; urgency=medium
 
   [ Release targeted to Wheezy including fixes for critical/important bugs ]
diff --git a/entry.c b/entry.c
index f191143..492e36f 100644
--- a/entry.c
+++ b/entry.c
@@ -28,6 +28,7 @@ static char rcsid[] = "$Id: entry.c,v 2.12 1994/01/17 
03:20:37 vixie Exp $";
 
 #include "cron.h"
 
+extern int change_child_path;
 
 typedef        enum ecode {
        e_none, e_minute, e_hour, e_dom, e_month, e_dow,
@@ -285,7 +286,9 @@ load_entry(file, error_func, pw, envp)
                }
        }
        if (!env_get("PATH", e->envp)) {
-               snprintf(envstr, MAX_ENVSTR, "PATH=%s", _PATH_DEFPATH);
+               if (change_child_path) {
+                       snprintf(envstr, MAX_ENVSTR, "PATH=%s", _PATH_DEFPATH);
+               }
                if ((tenvp = env_set(e->envp, envstr))) {
                        e->envp = tenvp;
                } else {

-- Package-specific info:
--- EDITOR:

--- usr/bin/editor:
/bin/nano

--- /usr/bin/crontab:
-rwxr-sr-x 1 root crontab 30248 Dec 18  2010 /usr/bin/crontab

--- /var/spool/cron
drwxr-xr-x 5 root root 4096 Sep 25 01:11 /var/spool/cron

--- /var/spool/cron/crontabs
drwx-wx--T 2 root crontab 4096 Dec 20  2006 /var/spool/cron/crontabs


-- System Information:
Debian Release: 6.0.5
  APT prefers stable-updates
  APT policy: (500, 'stable-updates'), (500, 'stable')
Architecture: i386 (i686)

Kernel: Linux 2.6.32.33-kvm-i386-20111128-dirty (SMP w/1 CPU core)
Locale: LANG=en_GB, LC_CTYPE=en_GB (charmap=ISO-8859-1)
Shell: /bin/sh linked to /bin/bash

Versions of packages cron depends on:
ii  adduser               3.112+nmu2         add and remove users and groups
ii  debianutils           3.4                Miscellaneous utilities specific t
ii  dpkg                  1.15.8.12          Debian package management system
ii  libc6                 2.11.3-3           Embedded GNU C Library: Shared lib
ii  libpam-runtime        1.1.1-6.1+squeeze1 Runtime support for the PAM librar
ii  libpam0g              1.1.1-6.1+squeeze1 Pluggable Authentication Modules l
ii  libselinux1           2.0.96-1           SELinux runtime shared libraries
ii  lsb-base              3.2-23.2squeeze1   Linux Standard Base 3.2 init scrip

Versions of packages cron recommends:
ii  lockfile-progs          0.1.15           Programs for locking and unlocking
ii  postfix [mail-transport 2.7.1-1+squeeze1 High-performance mail transport ag

Versions of packages cron suggests:
pn  anacron                       <none>     (no description available)
pn  checksecurity                 <none>     (no description available)
ii  logrotate                     3.7.8-6    Log rotation utility

Versions of packages cron is related to:
pn  libnss-ldap                   <none>     (no description available)
pn  libnss-ldapd                  <none>     (no description available)
pn  libpam-ldap                   <none>     (no description available)
pn  libpam-mount                  <none>     (no description available)
pn  nis                           <none>     (no description available)
pn  nscd                          <none>     (no description available)

-- Configuration Files:
/etc/crontab changed [not included]

-- no debconf information


-- 
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]

Reply via email to