home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / unix_c / sysadmin / asroot.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-03-21  |  2.3 KB  |  79 lines

  1.  9-Dec-85 13:43:37-MST,2349;000000000001
  2. Return-Path: <unix-sources-request@BRL.ARPA>
  3. Received: from BRL-TGR.ARPA by SIMTEL20.ARPA with TCP; Mon 9 Dec 85 13:43:29-MST
  4. Received: from usenet by TGR.BRL.ARPA id a005932; 9 Dec 85 12:56 EST
  5. From: Kevin Szabo <ksbszabo@watvlsi.uucp>
  6. Newsgroups: net.sources
  7. Subject: asroot: a program that gives you root permissions for a single command
  8. Message-ID: <2821@watvlsi.UUCP>
  9. Date: 6 Dec 85 17:25:55 GMT
  10. To:       unix-sources@BRL-TGR.ARPA
  11.  
  12. Some time ago there was discussion about the single user
  13. systems and the problems of running as ROOT most of the
  14. time.  In a single user system you can easily become root
  15. (via SU) but it is dangerous to always run as ROOT since you can
  16. clobber yourself.  Unfortunately SU tends to be quite slow for
  17. those times when you only want to execute a single command.
  18.  
  19. Thus I have written a small command called 'asroot' which will
  20. momentarily give a process root permissions.  The use of the
  21. command is:
  22.  
  23.     $ asroot cmd arg1 arg2 ...
  24.  
  25. or you can type
  26.  
  27.     $ asroot
  28.  
  29. and 'asroot' will prompt you for command line.
  30.  
  31. I use 'asroot' frequently on my systemIII machine; it
  32. should run correctly on other version of UNIX as well.
  33.  
  34. PLEASE NOTE THAT THIS PROGRAM IS A MASSIVE SECURITY HOLE.
  35. YOU SHOULD NOT ALLOW IT TO EXIST ON A MULTI-USER SYSTEM,
  36. OR ONE WHICH MAY BE ACCESSED REMOTELY.
  37.  
  38. So here's the program.  It's too small for a shar file...
  39.  
  40.  
  41. #include    <stdio.h>
  42.  
  43. /*
  44.  *    Asroot    - execute a command with root permissions.
  45.  *          compile with 'cc -o asroot asroot.c'
  46.  *          then 'chown root asroot; chmod u+s asroot'.
  47.  *
  48.  *    This program is a convenience for single-user systems,
  49.  *    BUT it is a MASSIVE security hole.  Please use caution.
  50.  */
  51.  
  52. main( argc, argv )
  53.     int    argc;
  54.     char    **argv;
  55. {
  56.     extern    char    *gets();
  57.     int        retcode;
  58.  
  59.     char    string[260];
  60.  
  61.     setuid( geteuid() );
  62.  
  63.     if ( argc > 1 ) {
  64.         execvp( argv[1], &argv[1] );
  65.         fprintf( stderr,"%s: execution of '%s' failed: ", argv[0], argv[1] );
  66.         perror( "" );
  67.         exit( 1 );
  68.     } else {
  69.         printf("Enter string to be executed: ");
  70.         fflush( stdout );
  71.         retcode=system(  gets( string ) );
  72.         if ( retcode != 0 )
  73.             fprintf(stderr,"%s: the command '%s' exited with status %d\n", argv[0], string, retcode );
  74.         exit( retcode );
  75.     }
  76. }
  77. -- 
  78. Kevin Szabo' watmath!watvlsi!ksbszabo (U of W VLSI Group, Waterloo, Ont, Canada)
  79.