home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / sys / hp / 9823 < prev    next >
Encoding:
Text File  |  1992-08-29  |  3.3 KB  |  114 lines

  1. Path: sparky!uunet!cis.ohio-state.edu!zaphod.mps.ohio-state.edu!usc!sol.ctr.columbia.edu!ursa!djms
  2. From: djms@bear.com (David J. Sullivan)
  3. Newsgroups: comp.sys.hp
  4. Subject: Program for single user security (HP 9000/700's)
  5. Message-ID: <TDJMS.92Aug28130618@bite.bear.com>
  6. Date: 28 Aug 92 17:06:18 GMT
  7. Sender: news@ursa.UUCP
  8. Organization: Bear, Stearns & Co. - FAST
  9. Lines: 103
  10.  
  11. As promised, here's my hack to have the hp's (700's runnning 8.0.7 at
  12. least) require the root password before entering single user mode.
  13.  
  14. In essence, move /bin/su to /bin/realsu and put this in its place.
  15.  
  16. --Cut here -----------------------------------------------------------
  17. /*
  18.  *  bsu - front end the ``real'' su program
  19.  *
  20.  *  This is to replace /bin/su, which has been moved to REAL_SU.
  21.  *  Its sole purpose is to ask for the root password if it is
  22.  *  called by root and it is called with no arguments or if the only
  23.  *  argument is `-'.  Ultimately this program calls the real su and
  24.  *  so needs not be setuid root.  (REAL_SU must remain so, though.)
  25.  *
  26.  *  This forces a user to supply the root password when a machine is
  27.  *  brought into single user mode, either with telinit -s or from
  28.  *  being booted.
  29.  *
  30.  *  A better solution might be to add a new flag to /bin/su, say -s,
  31.  *  and have init exec su with that flag when going single user to tell
  32.  *  su to ask for the root password.
  33.  *
  34.  *
  35.  *  Freely distributable.
  36.  *  Bear, Stearns & Co. --  FAST
  37.  *  David J. Sullivan, 20 August 1992 (djms@bear.com)
  38.  */
  39.  
  40. #include <stdio.h>
  41. #include <unistd.h>
  42. #include <pwd.h>
  43.  
  44. #define    REAL_SU        "/bin/realsu"    /*  Where the real /bin/su is    */
  45.  
  46. extern void exit();
  47.  
  48. main(argc, argv)
  49. int      argc;
  50. char    **argv;
  51. {
  52.     char        *password;
  53.     struct passwd    *pwEntry;
  54.     char        *encPassword;
  55.     
  56.  
  57.     /*
  58.      *  Check for root password if we're already root and we're
  59.      *  either not giving su arguments or only giving it `-'.
  60.      */
  61.     if ( getuid() == 0 &&
  62.          (argc == 1 || (argc == 2 && strcmp(argv[1], "-") == 0)) ) {
  63.  
  64.         /*
  65.          *  If no root user in password file, we're confused.
  66.          *  Punt!  In single user mode this will cause init
  67.          *  to spin and wait until you boot from some other device.
  68.           *  If /etc/passwd is clobbered, this is reasonable.
  69.          */
  70.         if ( (pwEntry = getpwnam( "root" )) == NULL ) {
  71.             (void) fprintf(stderr, "No root user!\n");
  72.             exit( 1 );
  73.         }
  74.  
  75.         /*
  76.          *  Wait for the correct root password.  Note that we
  77.          *  don't need to handle signals since init will keep 
  78.          *  restarting su if it is terminated.  In non-single user
  79.          *  state, killing this program simply stops execing the 
  80.          *  real su.
  81.          */
  82.         do {
  83.             if ( (password = getpass("Password: ")) == NULL ) {
  84.                 /*
  85.                  *  Couldn't open /dev/tty.  Punt!
  86.                  */
  87.                 exit( 2 );
  88.             }
  89.  
  90.             encPassword = crypt( password, pwEntry->pw_passwd );
  91.  
  92.         } while ( strcmp(pwEntry->pw_passwd, encPassword) );
  93.     }
  94.  
  95.     /*
  96.      *  Exec the real su program.
  97.      */
  98.     (void) execv( REAL_SU, argv );
  99.     
  100.  
  101.     /*
  102.      *  Should never reach here unless the REAL_SU program isn't
  103.      *  there.
  104.      */
  105.     (void) fprintf(stderr, "Couldn't exec %s!\n", REAL_SU );
  106.     exit( 3 );
  107. }
  108. --Cut here -----------------------------------------------------------
  109.  
  110. David J. Sullivan, Vice President    Bear, Stearns & Co.
  111. Internet: sullivan@bear.com        245 Park Avenue, FAST 5-122
  112. Usenet:   cmcl2!ursa!sullivan        New York, New York 10167
  113. 212/272-3668                Fax: 212/272-5850
  114.