From mboxrd@z Thu Jan 1 00:00:00 1970 Date: Fri, 18 Aug 1995 05:34:19 -0400 From: Vadim Antonov avg@postman.ncube.com Subject: Set User (aka su) Topicbox-Message-UUID: 184fbf80-eac8-11e9-9e20-41e7f4b1d025 Message-ID: <19950818093419.NOIrLSz1PNoVAo6_3AB0gntwH4XC1fku2Nkp1qXq1G4@z> Hi -- there's an equivalent of Unix "su" for Plan9, to allow to become a different user temporarily. It uses the file /lib/namespace.su to remount the root file system under new user name. On a CPU server or terminal running kfs that should be naiad% cat /lib/namespace.su mount -bc /srv/kfs / naiad% Does anybody know a better way to tell the file system that user name has changed? Also, note the magic incantation "cd `{pwd}". God, if feels like the quote from ken/slp.c. --vadim naiad% pwd /sys/src/cmd/auth naiad% diff mkfile.old mkfile 16a17 > su\ 37a39,41 > > $BIN/su:V: $O.su > cp $O.su /$objtype/bin/su naiad% cat su.c #include #include #include #include "authsrv.h" void main(int argc, char *argv[]) { char buf[32], pass[32], key[DESKEYLEN]; int fd; Chalstate ch; char *s; if( argc != 2 ) { fprint(2, "usage: su user\n"); exits("usage"); } s = getenv("service"); if(s && strcmp(s, "cpu") == 0){ fprint(2, "su must not be run on the cpu server\n"); exits("boofhead"); } if(getchal(&ch, argv[1]) < 0) { fprint(2, "Authentication failure\n"); exits("can't get challenge"); } readln("Password: ", pass, sizeof pass, 1); passtokey(key, pass); strcpy(buf, ch.chal); netcrypt(key, buf); if( chalreply(&ch, buf) < 0 ) { fprint(2, "Authentication failed\n"); exits("bad response"); } rfork(RFNAMEG|RFENVG); if( (fd = create("#e/prompt", OWRITE, 0644)) >= 0 ) { snprint(buf, sizeof buf, "[%s]%% ", argv[1]); write(fd, buf, strlen(buf)); close(fd); } if( (fd = create("#e/user", OWRITE, 0644)) >= 0 ) { write(fd, argv[1], strlen(argv[1])); close(fd); } /* Do some magic and start interactive shell */ execl("/bin/rc", "rc", "-c", ". /lib/namespace.su; cd `{pwd}; exec /bin/rc -i", 0); fprint(2, "Exec failed\n"); exits("exec"); } naiad%