home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 3 / 3236 < prev    next >
Encoding:
Internet Message Format  |  1991-04-24  |  2.6 KB

  1. From: paul@frcs.UUCP (Paul Nash)
  2. Newsgroups: alt.sources
  3. Subject: sux, an enhancer for su
  4. Message-ID: <462@frcs.UUCP>
  5. Date: 19 Apr 91 10:31:44 GMT
  6.  
  7.  
  8. I recently hacked up a fairly trivial enhancer for `su', that allows
  9. members of group `wheel' to su at will _without_ needing the root
  10. password.  Use it at your own risk, and distribute it to whom you
  11. will.  You may _not_ sell this code -- it must be given away for
  12. free. 
  13.  
  14. To install, `cc -o sux -O sux.c', `chown root sux', `chmod u+s sux'.
  15.  
  16.   ----   cut here   ----   cut here   ----   cut here   ---- 
  17.  
  18. /*
  19. **    A simple `su' enhancer.  This gets the uid of the user, thence
  20. **    the name, checks whether they are in group `wheel', and if so
  21. **    sets the euid to 0.  If not, leave euid alone.  After all of this,
  22. **    it execs `su' with all the command line options.
  23. **
  24. **    This program must be owned by, and setuid to `root'. 
  25. **
  26. **    Copyright (C) Free Range Computer Systems CC, 1991.
  27. **
  28. **    You may distrubute this code at will, provided that you do not
  29. **    _sell_ it, and leave this copyright notice unchanged.
  30. */
  31.  
  32. static char *copyright = "Copyright (C) Free Range Computer Systems CC, 1991.";
  33. static char *rcs_id = "$Header: /u/src/utils/RCS/sux.c,v 1.2 91/04/19 11:49:27 src Exp $";
  34.  
  35. /*
  36.  * $Log:    sux.c,v $
  37.  * Revision 1.2  91/04/19  11:49:27  src
  38.  * removed unnecessary check for `**group->gr_mem == '\0''.  The `group'
  39.  * entry ends with `*group->gr_mem == NULL', as it should.
  40.  * 
  41.  * Revision 1.1  91/04/19  11:48:18  src
  42.  * Initial revision
  43.  * 
  44.  */
  45.  
  46. #include <pwd.h>
  47. #include <grp.h>
  48. #include <stdio.h>
  49. #include <string.h>
  50.  
  51. struct group *getgrnam();
  52.  
  53. #define PRIV_GRP        "wheel"
  54. #define SU            "/bin/su"
  55. #define TRUE            ( 1 == 1 )
  56. #define FALSE            ( ! TRUE )
  57.  
  58. main( argc, argv )
  59. int   argc;
  60. char *argv[];
  61. {
  62.    unsigned int   uid,
  63.                   priviledged;
  64.    unsigned char *userid;
  65.    struct passwd *passwd;
  66.    struct group  *group;
  67.  
  68.    uid = getuid();
  69.    passwd = getpwuid( uid );
  70.    group  = getgrnam( PRIV_GRP );
  71.    if ( passwd == NULL || group == NULL ) {
  72.       fprintf( stderr, "cannot read password or group files, aborting\n" );
  73.       exit( 1 );
  74.    }
  75.    priviledged = FALSE;
  76.    while ( *group->gr_mem != NULL ) {
  77.       if ( strcmp( passwd->pw_name, *group->gr_mem++ ) == 0 ) {
  78.          priviledged = TRUE;
  79.          break;
  80.       }
  81.    }
  82.    if ( ! priviledged ) {
  83.       setuid( uid );
  84.    }
  85.    else {
  86.       setuid( 0 );
  87.    }
  88.    execv( SU, argv );
  89.    fprintf( stderr, "It seems that %s doesn't exist: sorry\n", SU );
  90. }
  91.  
  92.  
  93.  ---=---=---=---=---=---=---=---=---=---=---=---=---=---=---=---=---=---
  94. Paul Nash                   Free Range Computer Systems cc
  95. paul@frcs.UUCP                      ...!uunet!m2xenix!frcs!paul
  96.