Subject: bin/17211: getlogin(2) returns "root" in processes invoked by cron(8)
To: None <gnats-bugs@gnats.netbsd.org>
From: None <itohy@netbsd.org>
List: netbsd-bugs
Date: 06/11/2002 16:24:22
>Number: 17211
>Category: bin
>Synopsis: getlogin(2) returns "root" in processes invoked by cron(8)
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: bin-bug-people
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Tue Jun 11 00:25:00 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator: ITOH Yasufumi
>Release: 1.6A
>Organization:
>Environment:
System: NetBSD zun.my.domain 1.6A NetBSD 1.6A (ZUN) #39: Wed May 29 23:37:04 JST 2002 itohy@zun.my.domain:/usr/src/sys/arch/i386/compile/ZUN i386
Architecture: i386
Machine: i386
>Description:
If a process is invoked by cron(8),
getlogin(2) always returns "root" in the processes
and in the descendants.
Zsh will incorrectly set LOGNAME to root because of this.
>How-To-Repeat:
1. crontab -e
and add a line
* * * * * id -p
2. Wait a while....
3. You will have a mail, which says
login root <==== here!
uid itohy
groups users wheel
4. Don't forget to removed the line added by 1.
>Fix:
Apply this patch.
Should we consider using setusercontext(3)?
diff -uF^[a-zA-Z_][a-z A-Z0-9_]*([^;]*$ src/usr.sbin/cron/do_command.c.orig src/usr.sbin/cron/do_command.c
--- src/usr.sbin/cron/do_command.c.orig Mon Mar 25 19:59:01 2002
+++ src/usr.sbin/cron/do_command.c Tue Jun 11 14:14:52 2002
@@ -193,6 +193,9 @@ child_process(e, u)
free(x);
}
+ if (setlogin(usernm) < 0)
+ syslog(LOG_ERR, "setlogin() failure: %m");
+
/* that's the last thing we'll log. close the log files.
*/
#ifdef SYSLOG
>Release-Note:
>Audit-Trail:
>Unformatted: