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