[pe.cust.sources] Simple program to allow users to shut the system down

earlw@pesnta.UUCP (Earl Wallace ) (06/06/85)

Here is a very simple interface to the /etc/shutdown script that allows
users, with access to the system console, to shut the system down for
whatever reason (backups, maint. , etc.).  Its not great but it does work.
The security is ok but hasn't been tested for every little hole.  Have fun!
-earlw

----------------------------- CUT HERE -----------------------------
/*
 * special shutdown program for the rest of us - earlw
 * The executable file should be owned by 'root' with group 'sys' and 
 * mode 6111
 */

main()
{
	register char	*tty, *user;
	extern	char	*getlogin(), *ttyname(), *getcwd();

	/* check user */
	if (strcmp((user=getlogin()), "root") &&
	    strcmp(user, "you") &&
	    strcmp(user, "me") &&
	    strcmp(user, "thedog") &&
	    strcmp(user, "thecat") ) {
		printf("Sorry %s, ", user);
		printf("You must be an authorized user to run the ");
		printf("shutdown program\n");
		exit(2);
	}
	if (strncmp(getcwd((char *)0, 64), "/", 64)) {
		printf("You must be in / to run the shutdown program!\n");
		exit(3);
	}
	if (!(tty=ttyname(0))) {
		printf("Don't run the shutdown program in the background!\n");
		exit(4);
	}
	if (strcmp(tty, "/dev/console")) {
		printf("You must be at the system console to run the ");
		printf("shutdown program\n");
		exit(1);
	}
	setgid(0);
	setuid(0);
	printf("calling shutdown now...\n");
	execlp("/etc/shutdown", "SHUTDOWN", "120", 0);
	printf("shutdown failed!\n");
	exit(0);
}