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

  1. 12-Dec-85 03:47:55-MST,2569;000000000001
  2. Return-Path: <unix-sources-request@BRL.ARPA>
  3. Received: from BRL-TGR.ARPA by SIMTEL20.ARPA with TCP; Thu 12 Dec 85 03:47:49-MST
  4. Received: from usenet by TGR.BRL.ARPA id a029847; 12 Dec 85 3:40 EST
  5. From: Paul Summers <paul@wjvax.uucp>
  6. Newsgroups: net.sources
  7. Subject: Re: force.c
  8. Message-ID: <628@wjvax.wjvax.UUCP>
  9. Date: 10 Dec 85 18:51:53 GMT
  10. To:       unix-sources@BRL-TGR.ARPA
  11.  
  12. With the rash of un-secure programs that turn the average user into
  13. root without the courtesy of using su,  I felt that I should post a 
  14. program that we have been using fairly successfully here at wjvax.
  15. The main difference between this program and 'asroot' and its spiritual
  16. bretheren is that it keeps a copy of the encrypted root password,
  17. and prompts for it before letting the casual terminal snatcher get
  18. away with murder or worse.
  19.  
  20. I make no guarantees about portability (we're running bsd 4.2) or
  21. security.  The main point that I am stressing is the password.  A little time
  22. is sacrificed to make sure that only super user privilidged people can use
  23. this program.
  24. (I know of a particular system that has 'chown' set userid root...)
  25.  
  26. The main idea is to save time. 
  27. Have any of you tried the '-f' option on su?
  28.  
  29. ---------------------cut here-------------------------------------
  30. /*
  31.  *    force.c:  execute $* as user root.
  32.  *
  33.  *    A relatively secure program that executes its arguments
  34.  *    as the super user.  A small speed sacrifice is made to prompt
  35.  *    for a password.  Install the program with mode 4750, owner
  36.  *    root, group root (or operator).
  37.  *
  38.  *    Written by:    Paul M. Summers        (wjvax!paul)
  39.  *            10/85
  40.  *
  41.  *    Compile: cc -o /usr/local/bin/force force.c
  42.  *         chmod 4750 /usr/local/bin/force
  43.  */
  44. #include    <pwd.h>
  45. /*
  46.  *    Modify the next 2 lines as appropriate.
  47.  */
  48. #define SA    "System Administrator's name"
  49. #define    ROOTPW    "Encrypted root password from /etc/passwd"
  50.  
  51. main(argc,argv)
  52. int argc;
  53. char *argv[];
  54. {
  55. char *pwd,*cpwd,*crypt(),*getpass(),salt[2];
  56. struct passwd *getpwuid(),*pwdent;
  57.  
  58. pwd = getpass("Password: ");
  59.  
  60. strncpy(salt,ROOTPW,2);
  61. cpwd = crypt(pwd,salt);
  62.  
  63. if (strcmp(ROOTPW,cpwd) == 0) {
  64.     setuid(0);
  65. /*    nice(-5);    /* Overdrive... */
  66.     execvp(argv[1],&argv[1]);
  67.     printf("%s: command not found\n",argv[1]);
  68.     exit(1);
  69. }
  70.  
  71. /*
  72.  *    Check for changed root password.
  73.  */
  74.  
  75. setpwent();
  76. pwdent = getpwuid(0);
  77.  
  78. if (strcmp(pwdent->pw_passwd,ROOTPW) != 0) {
  79.     printf("Root password has changed to %s\n",pwdent->pw_passwd);
  80.     printf("Notify %s that force must be changed\n",SA);
  81. }
  82. else
  83.     printf("Bad password.\n");
  84. }
  85.