Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: utzoo!linus!decvax!harpo!seismo!hao!hplabs!sri-unix!dpk@brl-vgr
From: dpk@brl-vgr@sri-unix.UUCP
Newsgroups: net.unix-wizards
Subject: Re:  enhanced cron.c, anyone?
Message-ID: <3351@sri-arpa.UUCP>
Date: Fri, 22-Jul-83 12:42:33 EDT
Article-I.D.: sri-arpa.3351
Posted: Fri Jul 22 12:42:33 1983
Date-Received: Sun, 24-Jul-83 02:35:24 EDT
Lines: 77

From:      Doug Kingston 

	On our pdp-11's we modified cron to have a username field prior
to the command.  In the interest of compatability we did not do this on
the Vaxes.  Instead, we wrote a program called "alias" which is used
like nohup or nice (e.g.  "alias user programs args ...") which if run
by the superuser (like from crontab) will run the given program as the
specified user.  All you need to is add "alias user " to the fron of the
command string in the crontab entry.

						Cheers,
							-Doug-

PS.  The following is alias.c.  Enjoy!

/*
 *			A L I A S . C
 *
 *	To compile:  cc alias.c -O -o alias
 *
 *	This program allows the superuser to run a program with
 *	arbitrary arguments with the uid/gid of any account on
 *	the system.  If no program is specified,   /bin/sh  is
 *	assumed.
 *
 *	% alias  [[]]
 *
 *	R E V I S I O N   H I S T O R Y
 *
 *	05/20/78  RNJ	Any program may be run, not just shell.
 *			New /etc/passwd lookup function.
 *
 *	10/25/81  DPK	Converted to integer UIDs and GIDs & LIB7.
 *
 *	12/23/81  RSM	Fixed to not "blow away" V7 environment.
 *			Default case now sets argv[0] to "-Alias(account)"
 */

#include 
#include 

char	namebuf[30];		/* Argument 0 to new shell */

main(argc, argv)
char **argv;
{
	register char *program;	/* name of program to be exec ed   */
	register struct passwd *pw;

	if( argc <2 )  {
		printf("Usage:  %s account [ []]\n", argv[0]);
		exit(1);
	}
	if ((pw = getpwnam(argv[1])) == 0)  {
		printf("%s: account not found\n", argv[1]);
		exit(2);
	}

	if (setgid( pw->pw_gid ) < 0)
		perror ("setgid");
	if (setuid( pw->pw_uid ) < 0)
		perror ("setuid");

	if( argc <= 2 )  {
		program = "/bin/sh";
		printf("UID = %d; GID = %d\n", pw->pw_uid, pw->pw_gid);
		sprintf(namebuf, "-Alias(%s)", argv[1]);
		execl(program, namebuf, 0);
	} else {
		program = argv[2];
		argv[argc] = 0;
		execv(program, &argv[2]);
	}

	perror(program);
	exit(3);
}