Do setlogin() before changing uid/gid, since

`at/batch' requires this.

Obtained from: me && OpenBSD
This commit is contained in:
dima 1997-09-08 23:39:48 +00:00
parent e5a3229fdb
commit d58cb84dae

View File

@ -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",