sux, an enhancer for su

Paul Nash paul at frcs.UUCP
Fri Apr 19 20:31:44 AEST 1991


I recently hacked up a fairly trivial enhancer for `su', that allows
members of group `wheel' to su at will _without_ needing the root
password.  Use it at your own risk, and distribute it to whom you
will.  You may _not_ sell this code -- it must be given away for
free. 

To install, `cc -o sux -O sux.c', `chown root sux', `chmod u+s sux'.

  ----   cut here   ----   cut here   ----   cut here   ---- 
 
/*
**	A simple `su' enhancer.  This gets the uid of the user, thence
**	the name, checks whether they are in group `wheel', and if so
**	sets the euid to 0.  If not, leave euid alone.  After all of this,
**	it execs `su' with all the command line options.
**
**	This program must be owned by, and setuid to `root'. 
**
**	Copyright (C) Free Range Computer Systems CC, 1991.
**
**	You may distrubute this code at will, provided that you do not
**	_sell_ it, and leave this copyright notice unchanged.
*/

static char *copyright = "Copyright (C) Free Range Computer Systems CC, 1991.";
static char *rcs_id = "$Header: /u/src/utils/RCS/sux.c,v 1.2 91/04/19 11:49:27 src Exp $";

/*
 * $Log:	sux.c,v $
 * Revision 1.2  91/04/19  11:49:27  src
 * removed unnecessary check for `**group->gr_mem == '\0''.  The `group'
 * entry ends with `*group->gr_mem == NULL', as it should.
 * 
 * Revision 1.1  91/04/19  11:48:18  src
 * Initial revision
 * 
 */

#include <pwd.h>
#include <grp.h>
#include <stdio.h>
#include <string.h>

struct group *getgrnam();

#define PRIV_GRP		"wheel"
#define SU			"/bin/su"
#define TRUE			( 1 == 1 )
#define FALSE			( ! TRUE )

main( argc, argv )
int   argc;
char *argv[];
{
   unsigned int   uid,
                  priviledged;
   unsigned char *userid;
   struct passwd *passwd;
   struct group  *group;

   uid = getuid();
   passwd = getpwuid( uid );
   group  = getgrnam( PRIV_GRP );
   if ( passwd == NULL || group == NULL ) {
      fprintf( stderr, "cannot read password or group files, aborting\n" );
      exit( 1 );
   }
   priviledged = FALSE;
   while ( *group->gr_mem != NULL ) {
      if ( strcmp( passwd->pw_name, *group->gr_mem++ ) == 0 ) {
         priviledged = TRUE;
         break;
      }
   }
   if ( ! priviledged ) {
      setuid( uid );
   }
   else {
      setuid( 0 );
   }
   execv( SU, argv );
   fprintf( stderr, "It seems that %s doesn't exist: sorry\n", SU );
}


 ---=---=---=---=---=---=---=---=---=---=---=---=---=---=---=---=---=---
Paul Nash				   Free Range Computer Systems cc
paul at frcs.UUCP				      ...!uunet!m2xenix!frcs!paul



More information about the Alt.sources mailing list