NetBSD Problem Report #43591

From reed@reedmedia.net  Sat Jul 10 01:46:38 2010
Return-Path: <reed@reedmedia.net>
Received: from mail.netbsd.org (mail.netbsd.org [204.152.190.11])
	by www.NetBSD.org (Postfix) with ESMTP id 5E38663BAB7
	for <gnats-bugs@gnats.NetBSD.org>; Sat, 10 Jul 2010 01:46:38 +0000 (UTC)
Message-Id: <29080-1278726399@reedmedia.net>
Date: Fri, 09 Jul 2010 20:46:40 -0500
From: reed@reedmedia.net
Reply-To: reed@reedmedia.net
To: gnats-bugs@gnats.NetBSD.org
Subject: cron for user not defining PATH
X-Send-Pr-Version: 3.95

>Number:         43591
>Category:       bin
>Synopsis:       cron for user not defining PATH
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    bin-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Jul 10 01:50:00 +0000 2010
>Closed-Date:    Sun Jul 11 19:56:32 +0000 2010
>Last-Modified:  Sun Jul 11 19:56:32 +0000 2010
>Originator:     reed@reedmedia.net
>Release:        NetBSD 5.99
>Organization:
>Environment:


>Description:

One of my cron jobs failed since PATH was not defined.

I looked at my email headers and saw:

X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/home/jreed>
X-Cron-Env: <LOGNAME=jreed>
X-Cron-Env: <USER=jreed>
X-Cron-Env: </usr/bin:/bin:/usr/pkg/bin:/usr/local/bin>

Notice the last line probably should have PATH=. I looked at older email 
headers from an old cron and it did have PATH.

This is:

/usr/sbin/cron:
     $NetBSD: crt0.c,v 1.5 2007/09/27 10:51:18 dogcow Exp $
     $NetBSD: cron.c,v 1.6 2010/05/18 21:49:51 christos Exp $
     $NetBSD: database.c,v 1.2 2010/05/06 18:53:17 christos Exp $
     $NetBSD: do_command.c,v 1.2 2010/05/06 18:53:17 christos Exp $
     $NetBSD: entry.c,v 1.2 2010/05/06 18:53:17 christos Exp $
     $NetBSD: env.c,v 1.2 2010/05/06 18:53:17 christos Exp $
     $NetBSD: job.c,v 1.2 2010/05/06 18:53:17 christos Exp $
     $NetBSD: misc.c,v 1.2 2010/05/06 18:53:17 christos Exp $
     $NetBSD: popen.c,v 1.2 2010/05/06 18:53:17 christos Exp $
     $NetBSD: pw_dup.c,v 1.2 2010/05/06 18:53:17 christos Exp $

root's cron job does work. I have it run a script that simply is just 
one line:
echo $PATH

The cron email has:

X-Cron-Env: <PATH=/bin:/sbin:/usr/bin:/usr/sbin>

And the body is:

/bin:/sbin:/usr/bin:/usr/sbin

root's crontab specifically defines the PATH.

# crontab -l -u root | grep PATH
PATH=/bin:/sbin:/usr/bin:/usr/sbin

But running the shell script as a normal user does:

X-Cron-Env: </usr/bin:/bin:/usr/pkg/bin:/usr/local/bin>

(notice no PATH=)

The output is:
/usr/bin:/bin:/usr/pkg/bin:/usr/local/bin

(see it has different PATH)

So then I had it also run "env" and "export" in the shell script. For 
the root it is:

CRON_WITHIN=7200
PWD=/var/log
HOME=/var/log
PATH=/bin:/sbin:/usr/bin:/usr/sbin
USER=root
LOGNAME=root
SHELL=/bin/sh

CRON_WITHIN
HOME
LOGNAME
PATH
PWD
SHELL
USER

(notice root's does have PATH)

For the regular user it is:

PWD=/home/jreed
HOME=/home/jreed
USER=jreed
LOGNAME=jreed
SHELL=/bin/sh

HOME
LOGNAME
PWD
SHELL
USER

(notice no PATH)

Now when I do set PATH in the user's crontab, it is fixed:

X-Cron-Env: <PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/pkg/bin:/foo/bar>

and my output:

/bin:/sbin:/usr/bin:/usr/sbin:/usr/pkg/bin:/foo/bar

PWD=/home/jreed
HOME=/home/jreed
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/pkg/bin:/foo/bar
USER=jreed
LOGNAME=jreed
SHELL=/bin/sh

HOME
LOGNAME
PATH
PWD
SHELL
USER

Maybe the problem is related to the patches related to path for
login classes. I didn't test vixie-cron from pkgsrc to compare.

>How-To-Repeat:
cron job as a normal user (or maybe remove PATH from root's crontab?)
>Fix:


>Release-Note:

>Audit-Trail:
From: Christos Zoulas <christos@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/43591 CVS commit: src/external/bsd/cron/dist
Date: Sat, 10 Jul 2010 17:42:30 -0400

 Module Name:	src
 Committed By:	christos
 Date:		Sat Jul 10 21:42:30 UTC 2010

 Modified Files:
 	src/external/bsd/cron/dist: entry.c

 Log Message:
 PR bin/43591: Jeremy Reed: make sure that the default path is always set.


 To generate a diff of this commit:
 cvs rdiff -u -r1.2 -r1.3 src/external/bsd/cron/dist/entry.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: open->closed
State-Changed-By: dholland@NetBSD.org
State-Changed-When: Sun, 11 Jul 2010 19:56:32 +0000
State-Changed-Why:
fixed.


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.