1 #include <u.h> 2 #include <libc.h> 3 #include <auth.h> 4 #include <fcall.h> 5 #include "../boot/boot.h" 6 7 char *authaddr; 8 static void glenda(void); 9 10 void authentication(int cpuflag)11authentication(int cpuflag) 12 { 13 char *s; 14 char *argv[16], **av; 15 int ac; 16 17 if(access("/boot/factotum", AEXEC) < 0){ 18 glenda(); 19 return; 20 } 21 22 /* start agent */ 23 ac = 0; 24 av = argv; 25 av[ac++] = "factotum"; 26 if(getenv("debugfactotum")) 27 av[ac++] = "-p"; 28 s = getenv("factotumopts"); 29 if(s != nil && *s != '\0') 30 av[ac++] = s; 31 // av[ac++] = "-d"; /* debug traces */ 32 // av[ac++] = "-D"; /* 9p messages */ 33 if(cpuflag) 34 av[ac++] = "-S"; 35 else 36 av[ac++] = "-u"; 37 av[ac++] = "-sfactotum"; 38 if(authaddr != nil){ 39 av[ac++] = "-a"; 40 av[ac++] = authaddr; 41 } 42 av[ac] = 0; 43 switch(fork()){ 44 case -1: 45 fatal("starting factotum"); 46 case 0: 47 exec("/boot/factotum", av); 48 fatal("execing /boot/factotum"); 49 } 50 51 /* wait for agent to really be there */ 52 while(access("/mnt/factotum", 0) < 0) 53 sleep(250); 54 } 55 56 static void glenda(void)57glenda(void) 58 { 59 int fd; 60 char *s; 61 62 s = getenv("user"); 63 if(s == nil) 64 s = "glenda"; 65 66 fd = open("#c/hostowner", OWRITE); 67 if(fd >= 0){ 68 if(write(fd, s, strlen(s)) != strlen(s)) 69 fprint(2, "setting #c/hostowner to %s: %r\n", s); 70 close(fd); 71 } 72 } 73