1: #include <stdio.h>
   2: #include <pwd.h>
   3: 
   4: struct  passwd *pwd,*getpwnam();
   5: char    *crypt();
   6: char    *getpass();
   7: char    **environ;
   8: 
   9: main(argc,argv)
  10: int argc;
  11: char    **argv;
  12: {
  13:     register char **p;
  14:     char *nptr;
  15:     char *password;
  16:     int badsw = 0;
  17:     char *shell = "/bin/sh";
  18: 
  19:     if(argc > 1)
  20:         nptr = argv[1];
  21:     else
  22:         nptr = "root";
  23:     if((pwd=getpwnam(nptr)) == NULL) {
  24:         printf("Unknown id: %s\n",nptr);
  25:         exit(1);
  26:     }
  27:     if(pwd->pw_passwd[0] == '\0' || getuid() == 0)
  28:         goto ok;
  29:     password = getpass("Password:");
  30:     if(badsw || (strcmp(pwd->pw_passwd, crypt(password, pwd->pw_passwd)) != 0)) {
  31:         printf("Sorry\n");
  32:         exit(2);
  33:     }
  34: 
  35: ok:
  36:     endpwent();
  37:     setgid(pwd->pw_gid);
  38:     setuid(pwd->pw_uid);
  39:     if (pwd->pw_shell && *pwd->pw_shell)
  40:         shell = pwd->pw_shell;
  41:     for (p=environ; *p; p++) {
  42:         if (strncmp("PS1=", *p, 4) == 0) {
  43:             *p = "PS1=# ";
  44:             break;
  45:         }
  46:     }
  47:     execl(shell, "su", 0);
  48:     printf("No shell\n");
  49:     exit(3);
  50: }

Defined functions

main defined in line 9; never used

Defined variables

environ defined in line 7; used 1 times
  • in line 41
pwd defined in line 4; used 9 times
Last modified: 1979-05-05
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 630
Valid CSS Valid XHTML 1.0 Strict