From 8fad2d7e997c858b845b61802aba6765198f40ed Mon Sep 17 00:00:00 2001 From: Dima Ruban Date: Mon, 8 Sep 1997 23:39:48 +0000 Subject: [PATCH] Do setlogin() before changing uid/gid, since `at/batch' requires this. Obtained from: me && OpenBSD --- libexec/atrun/atrun.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/libexec/atrun/atrun.c b/libexec/atrun/atrun.c index b96969d1645a..6616e41c6084 100644 --- a/libexec/atrun/atrun.c +++ b/libexec/atrun/atrun.c @@ -79,7 +79,7 @@ /* File scope variables */ static char *namep; -static char rcsid[] = "$Id: atrun.c,v 1.9 1997/03/28 15:48:03 imp Exp $"; +static char rcsid[] = "$Id: atrun.c,v 1.10 1997/04/12 01:04:50 davidn Exp $"; static debug = 0; void perr(const char *a); @@ -283,18 +283,21 @@ run_file(const char *filename, uid_t uid, gid_t gid) nice(tolower(queue) - 'a'); - if (chdir(pentry->pw_dir)) - chdir("/"); - if (initgroups(pentry->pw_name,pentry->pw_gid)) perr("Cannot delete saved userids"); - if (setgid(gid) < 0) + if (setgid(gid) < 0 || setegid(pentry->pw_gid) < 0) perr("Cannot change group"); - if (setuid(uid) < 0) + if (setlogin(pentry->pw_name)) + perr("Cannot set login name"); + + if (setuid(uid) < 0 || seteuid(uid) < 0) perr("Cannot set user id"); + if (chdir(pentry->pw_dir)) + chdir("/"); + if(execle("/bin/sh","sh",(char *) NULL, nenvp) != 0) perr("Exec failed for /bin/sh"); @@ -318,18 +321,21 @@ run_file(const char *filename, uid_t uid, gid_t gid) { PRIV_START - if (chdir(pentry->pw_dir)) - chdir("/"); - if (initgroups(pentry->pw_name,pentry->pw_gid)) perr("Cannot delete saved userids"); - if (setgid(gid) < 0) + if (setgid(gid) < 0 || setegid(pentry->pw_gid) < 0) perr("Cannot change group"); - if (setuid(uid) < 0) + if (setlogin(pentry->pw_name)) + perr("Cannot set login name"); + + if (setuid(uid) < 0 || seteuid(uid) < 0) perr("Cannot set user id"); + if (chdir(pentry->pw_dir)) + chdir("/"); + #ifdef __FreeBSD__ execl(_PATH_SENDMAIL, "sendmail", "-F", "Atrun Service", "-odi", "-oem",