From b02ab4ec85832ef0ff99daa6dcbb373f594367a2 Mon Sep 17 00:00:00 2001 From: Dennis Ritchie Date: Tue, 13 May 1975 19:50:00 -0500 Subject: [PATCH] Research V6 development Work on file usr/source/s2/su.c Co-Authored-By: Ken Thompson Synthesized-from: v6 --- usr/source/s2/su.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 usr/source/s2/su.c diff --git a/usr/source/s2/su.c b/usr/source/s2/su.c new file mode 100644 index 0000000000..679502c2c1 --- /dev/null +++ b/usr/source/s2/su.c @@ -0,0 +1,46 @@ +/* su -- become super-user */ + +char password[100]; +char pwbuf[100]; +int ttybuf[3]; +main() +{ + register char *p, *q; + extern fin; + + if(getpw(0, pwbuf)) + goto badpw; + (&fin)[1] = 0; + p = pwbuf; + while(*p != ':') + if(*p++ == '\0') + goto badpw; + if(*++p == ':') + goto ok; + gtty(0, ttybuf); + ttybuf[2] =& ~010; + stty(0, ttybuf); + printf("password: "); + q = password; + while((*q = getchar()) != '\n') + if(*q++ == '\0') + return; + *q = '\0'; + ttybuf[2] =| 010; + stty(0, ttybuf); + printf("\n"); + q = crypt(password); + while(*q++ == *p++); + if(*--q == '\0' && *--p == ':') + goto ok; + goto error; + +badpw: + printf("bad password file\n"); +ok: + setuid(0); + execl("/bin/sh", "-", 0); + printf("cannot execute shell\n"); +error: + printf("sorry\n"); +} -- 2.20.1