From: John C. Wingenbach (w6i@ornl.gov)
Date: 07/01/93


From: w6i@ornl.gov (John C. Wingenbach)
Subject: Re: Is there # for Linux ?
Date: Thu, 1 Jul 1993 18:40:05 GMT

In article <MUTS.93Jul1001004@muts.hacktic.nl> muts@muts.hacktic.nl (Peter Mutsaers) writes:

>On 30 Jun 1993 13:50:02 GMT, dragan@mpi-sb.mpg.de (Dragan Cvetkovic) said:

> DC> time I want to perform something as root and not as normal user,
> DC> and I don't want to have root privilegies all the time
> DC> (dangerous!).

>I always use this:

>root.c:
>#include <stdio.h>

>/* fill in your uid here */
>#define MY_UID 1234

>main(int argc, char **argv)
>{
> if (getuid()!=MY_UID) {
> fprintf(stderr,"Sorry...\n");
> sleep(1);
> exit(1);
> }

> setuid(geteuid());

> if (argc>1) {
> execvp(argv[1],&argv[1]);
> perror("execle");
> exit(1);
> }
> execlp("bash","bash",0);
> perror("execlp");
> exit(1);
>}

Hey why do all that work?? Let the OS do it for you. Just use:
#include <stdio.h>
main(int argc, char **argv)
{
  if (argc>1) {
    execvp(argv[1],&argv[1]);
    perror("execle");
  }
  exit(1);
}

Compile the program. Rename executable to '#' if you wish.
chown root:wheel '#' or whatever group is authorized to be root
chmod 4750 '#'

John C. Wingenbach Martin Marietta Energy Systems
                                   Data Systems Research & Development
w6i@ornl.gov Oak Ridge Technical Center III
(615) 574-8345 1099 Commerce Park
(615) 574-0792 (FAX) Oak Ridge, TN 37830