#include #include #include void readenv(char*, char*, int); void setenv(char*, char*); void cpenv(char*, char*); void closefds(void); void fexec(void(*)(void)); void rcexec(void); void cpustart(void); void pass(int); char *service; char *cmd; char cpu[NAMELEN]; char sysname[NAMELEN]; int manual; int iscpu; void main(int argc, char *argv[]) { char user[NAMELEN]; int consctl, key; closefds(); service = "cpu"; manual = 0; ARGBEGIN{ case 'c': service = "cpu"; break; case 'm': manual = 1; break; case 't': service = "terminal"; break; }ARGEND cmd = *argv; readenv("#e/cputype", cpu, sizeof cpu); setenv("#e/objtype", cpu); setenv("#e/service", service); cpenv("/adm/timezone/local", "#e/timezone"); readenv("#c/user", user, sizeof user); readenv("#c/sysname", sysname, sizeof sysname); newns(user, 0); iscpu = strcmp(service, "cpu")==0; if(iscpu) fexec(cpustart); for(;;){ if(iscpu){ consctl = open("#c/consctl", OWRITE); key = open("#c/key", OREAD); if(consctl<0 || key<0 || write(consctl, "rawon", 5) != 5) print("init: can't check password; insecure\n"); else{ pass(key); write(consctl, "rawoff", 6); } close(consctl); close(key); } print("\ninit: starting /bin/rc\n"); fexec(rcexec); manual = 1; cmd = 0; sleep(1000); } } void pass(int fd) { char key[DESKEYLEN]; char typed[32]; char crypted[DESKEYLEN]; int i; for(;;){ readenv("#c/sysname", sysname, sizeof sysname); print("\n%s password:", sysname); for(i=0; i