diff options
author | dima <dima@FreeBSD.org> | 1997-09-08 23:39:48 +0000 |
---|---|---|
committer | dima <dima@FreeBSD.org> | 1997-09-08 23:39:48 +0000 |
commit | d58cb84dae579b2a1bfc078493c903609e669b0a (patch) | |
tree | 9c5390569fd543528e2cff4b8bc4ff4a1daebc2c /libexec/atrun/atrun.c | |
parent | e5a3229fdb428920d0c40e03c2c7859b2ddcbb6c (diff) | |
download | FreeBSD-src-d58cb84dae579b2a1bfc078493c903609e669b0a.zip FreeBSD-src-d58cb84dae579b2a1bfc078493c903609e669b0a.tar.gz |
Do setlogin() before changing uid/gid, since
`at/batch' requires this.
Obtained from: me && OpenBSD
Diffstat (limited to 'libexec/atrun/atrun.c')
-rw-r--r-- | libexec/atrun/atrun.c | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/libexec/atrun/atrun.c b/libexec/atrun/atrun.c index b96969d..6616e41 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", |