Bell 32V development
authorTom London <tbl@research.uucp>
Mon, 27 Nov 1978 03:46:43 +0000 (22:46 -0500)
committerTom London <tbl@research.uucp>
Mon, 27 Nov 1978 03:46:43 +0000 (22:46 -0500)
Work on file usr/src/cmd/su.c

Co-Authored-By: John Reiser <jfr@research.uucp>
Synthesized-from: 32v

usr/src/cmd/su.c [new file with mode: 0644]

diff --git a/usr/src/cmd/su.c b/usr/src/cmd/su.c
new file mode 100644 (file)
index 0000000..58f8e71
--- /dev/null
@@ -0,0 +1,42 @@
+#include <stdio.h>
+#include <pwd.h>
+
+struct passwd *pwd,*getpwnam();
+char   *crypt();
+char   *getpass();
+
+main(argc,argv)
+int    argc;
+char   **argv;
+{
+       char *nptr;
+       char *password;
+       int badsw = 0;
+       char *shell = "/bin/sh";
+
+       if(argc > 1)
+               nptr = argv[1];
+       else
+               nptr = "root";
+       if((pwd=getpwnam(nptr)) == NULL) {
+               printf("Unknown id: %s\n",nptr);
+               exit(1);
+       }
+       if(pwd->pw_passwd[0] == '\0' || getuid() == 0)
+               goto ok;
+       password = getpass("Password:");
+       if(badsw || (strcmp(pwd->pw_passwd, crypt(password, pwd->pw_passwd)) != 0)) {
+               printf("Sorry\n");
+               exit(2);
+       }
+
+ok:
+       endpwent();
+       setgid(pwd->pw_gid);
+       setuid(pwd->pw_uid);
+       if (pwd->pw_shell && *pwd->pw_shell)
+               shell = pwd->pw_shell;
+       execl(shell, "su", 0);
+       printf("No shell\n");
+       exit(3);
+}