home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!cis.ohio-state.edu!zaphod.mps.ohio-state.edu!usc!sol.ctr.columbia.edu!ursa!djms
- From: djms@bear.com (David J. Sullivan)
- Newsgroups: comp.sys.hp
- Subject: Program for single user security (HP 9000/700's)
- Message-ID: <TDJMS.92Aug28130618@bite.bear.com>
- Date: 28 Aug 92 17:06:18 GMT
- Sender: news@ursa.UUCP
- Organization: Bear, Stearns & Co. - FAST
- Lines: 103
-
- As promised, here's my hack to have the hp's (700's runnning 8.0.7 at
- least) require the root password before entering single user mode.
-
- In essence, move /bin/su to /bin/realsu and put this in its place.
-
- --Cut here -----------------------------------------------------------
- /*
- * bsu - front end the ``real'' su program
- *
- * This is to replace /bin/su, which has been moved to REAL_SU.
- * Its sole purpose is to ask for the root password if it is
- * called by root and it is called with no arguments or if the only
- * argument is `-'. Ultimately this program calls the real su and
- * so needs not be setuid root. (REAL_SU must remain so, though.)
- *
- * This forces a user to supply the root password when a machine is
- * brought into single user mode, either with telinit -s or from
- * being booted.
- *
- * A better solution might be to add a new flag to /bin/su, say -s,
- * and have init exec su with that flag when going single user to tell
- * su to ask for the root password.
- *
- *
- * Freely distributable.
- * Bear, Stearns & Co. -- FAST
- * David J. Sullivan, 20 August 1992 (djms@bear.com)
- */
-
- #include <stdio.h>
- #include <unistd.h>
- #include <pwd.h>
-
- #define REAL_SU "/bin/realsu" /* Where the real /bin/su is */
-
- extern void exit();
-
- main(argc, argv)
- int argc;
- char **argv;
- {
- char *password;
- struct passwd *pwEntry;
- char *encPassword;
-
-
- /*
- * Check for root password if we're already root and we're
- * either not giving su arguments or only giving it `-'.
- */
- if ( getuid() == 0 &&
- (argc == 1 || (argc == 2 && strcmp(argv[1], "-") == 0)) ) {
-
- /*
- * If no root user in password file, we're confused.
- * Punt! In single user mode this will cause init
- * to spin and wait until you boot from some other device.
- * If /etc/passwd is clobbered, this is reasonable.
- */
- if ( (pwEntry = getpwnam( "root" )) == NULL ) {
- (void) fprintf(stderr, "No root user!\n");
- exit( 1 );
- }
-
- /*
- * Wait for the correct root password. Note that we
- * don't need to handle signals since init will keep
- * restarting su if it is terminated. In non-single user
- * state, killing this program simply stops execing the
- * real su.
- */
- do {
- if ( (password = getpass("Password: ")) == NULL ) {
- /*
- * Couldn't open /dev/tty. Punt!
- */
- exit( 2 );
- }
-
- encPassword = crypt( password, pwEntry->pw_passwd );
-
- } while ( strcmp(pwEntry->pw_passwd, encPassword) );
- }
-
- /*
- * Exec the real su program.
- */
- (void) execv( REAL_SU, argv );
-
-
- /*
- * Should never reach here unless the REAL_SU program isn't
- * there.
- */
- (void) fprintf(stderr, "Couldn't exec %s!\n", REAL_SU );
- exit( 3 );
- }
- --Cut here -----------------------------------------------------------
-
- David J. Sullivan, Vice President Bear, Stearns & Co.
- Internet: sullivan@bear.com 245 Park Avenue, FAST 5-122
- Usenet: cmcl2!ursa!sullivan New York, New York 10167
- 212/272-3668 Fax: 212/272-5850
-