# ifndef lint static char Sccs_id[] = "@(#)sup.c 1.5\t(Achilles)\t10/28/89"; # endif # define DO_LOG # define BSD # define LOGFILE "/usr/adm/sup.log" # define AUTHOR 201 /* * sup: execute a command in su mode */ # include # include # ifdef BSD # include # include # endif # ifdef DO_LOG FILE *log; FILE *fopen (); struct passwd *pw; struct passwd *getpwuid (); char *ctime (); char nowstr[30]; long time (); long now; # endif main (argc, argv) register int argc; register char **argv; { char comm[10240]; register char *s; extern char *getenv (); int uid; # ifdef DO_LOG now = time (0); uid = getuid (); # endif strcpy (comm, "exec "); if (!(s = getenv ("SHELL"))) s = "/bin/csh"; while (--argc) { strcat (comm, *++argv); if (argc > 1) strcat (comm, " "); } # ifdef DO_LOG if (getuid () == AUTHOR) goto exec_comm; if (!(log = fopen (LOGFILE, "a"))) { perror (LOGFILE); exit (1); } pw = getpwuid (uid); endpwent (); strcpy (nowstr, ctime (&now)); nowstr[24] = '\0'; fprintf (log, "%s\t%-8.8s\t'%s'\n", nowstr, pw -> pw_name, comm + 5); fclose (log); exec_comm: # endif setuid (0); setgid (0); # ifdef BSD setegid (0); seteuid (0); setpriority (PRIO_PROCESS, getpid (), -10); # else nice (10); # endif execlp (s, "sup", (strcmp (s, "/bin/sh") == 0) ? "-ce" : "-cf", comm, 0); exit (-3); }