[net.unix-wizards] atrun doesn't set all of user's groups

geoff@utcs.uucp (Geoff Collyer) (10/23/85)

Index:	usr.lib/atrun.c 4.2BSD

Description:
	atrun doesn't invoke initgroups(3) to set all the groups to which
	a user belongs.
Repeat-By:
	Type
		groups
		echo 'groups | mail me' | at
	Observe the different outputs from groups.
Fix:
	Amend at(1).  Apply these diffs to atrun.c.  Line numbers may vary.

*** /tmp/,RCSt1022307	Wed Oct 23 02:05:08 1985
--- /tmp/,RCSt2022307	Wed Oct 23 02:05:10 1985
***************
*** 5,10
   * Run programs submitted by at.
   */
  #include <stdio.h>
  #include <sys/param.h>
  #include <sys/dir.h>
  #include <sys/time.h>

--- 6,12 -----
   * Run programs submitted by at.
   */
  #include <stdio.h>
+ #include <pwd.h>
  #include <sys/param.h>
  #include <sys/dir.h>
  #include <sys/time.h>
***************
*** 80,85
  	struct stat stbuf;
  	register pid, i;
  	char sbuf[64];
  
  	/* printf("running %s\n", file); */
  	if (fork()!=0)

--- 85,92 -----
  	register pid, i;
  	struct stat stbuf;
  	char sbuf[64];
+ 	struct passwd *pwp;
+ 	struct passwd *getpwuid();
  
  	/* printf("running %s\n", file); */
  	if (fork()!=0)
***************
*** 101,106
  		exit(0);
  	}
  	setgid(stbuf.st_gid);
  	setuid(stbuf.st_uid);
  	execl("/bin/sh", "sh", file, 0);
  	execl("/usr/bin/sh", "sh", file, 0);

--- 108,116 -----
  		exit(0);
  	}
  	setgid(stbuf.st_gid);
+ 	if ((pwp = getpwuid(stbuf.st_uid)) == NULL)
+ 		exit(1);			/* no password file entry */
+ 	initgroups(pwp->pw_name, stbuf.st_gid);
  	setuid(stbuf.st_uid);
  	execl("/bin/sh", "sh", file, 0);
  	execl("/usr/bin/sh", "sh", file, 0);


-- 
Net news is the television of computing.