[alt.sources] another 'su encancer'

muts@fysak.fys.ruu.nl (Peter Mutsaers) (04/26/91)

Now that we are discussing a su encancer etc., here is a 'root' program that
I've been using the last 1.5 year.
The syntax is 'root command [args]' and runs one command with su privilege.
It is quite safe, and checks if the uid is right. (only works for one user).
Without args it executes a shell with su privilege.
Of course this program must also be owned by root and be setuid.
Change the number on the first line of main() to your own uid.

# This is a shell archive.  Remove anything before this line,
# then unpack it by saving it in a file and typing "sh file".
#
# Wrapped by Peter Mutsaers <muts@fysaq> on Fri Apr 26 09:30:05 1991
#
# This archive contains:
#	root.c	
#

LANG=""; export LANG
PATH=/bin:/usr/bin:$PATH; export PATH

echo x - root.c
cat >root.c <<'@EOF'
#include <stdio.h>
#include <string.h>

int main(argc, argv)
int argc;
char *argv[];

{
    if (1030 != getuid()) {
		fprintf(stderr,"sorry...");
		sleep(2);
		fprintf(stderr,"\n");
		exit(1);
	}

	setuid(geteuid());
	setgid(getegid());

	switch (argc) {

	case 1:
		execl("/bin/csh", "csh", (char *) 0);
		perror("csh");
		exit(1);

	default:
		execvp(argv[1], &argv[1]);
		perror(argv[1]);
		exit(1);
	}

}
@EOF

chmod 644 root.c

exit 0








--
Peter Mutsaers                          email:    muts@fysap.fys.ruu.nl     
Rijksuniversiteit Utrecht                         muts@fys.ruu.nl
Princetonplein 5                          tel:    (+31)-(0)30-533880
3584 CG Utrecht, Netherlands