1 #include <u.h> 2 #include <libc.h> 3 #include <auth.h> 4 5 int auth_getkey(char * params)6auth_getkey(char *params) 7 { 8 char *name; 9 Dir *d; 10 int pid; 11 Waitmsg *w; 12 13 /* start /factotum to query for a key */ 14 name = "/factotum"; 15 d = dirstat(name); 16 if(d == nil){ 17 name = "/boot/factotum"; 18 d = dirstat(name); 19 } 20 if(d == nil){ 21 werrstr("auth_getkey: no /factotum or /boot/factotum: didn't get key %s", params); 22 return -1; 23 } 24 if(0) if(d->type != '/'){ 25 werrstr("auth_getkey: /factotum may be bad: didn't get key %s", params); 26 return -1; 27 } 28 switch(pid = fork()){ 29 case -1: 30 werrstr("can't fork for %s: %r", name); 31 return -1; 32 case 0: 33 execl(name, "getkey", "-g", params, nil); 34 exits(0); 35 default: 36 for(;;){ 37 w = wait(); 38 if(w == nil) 39 break; 40 if(w->pid == pid){ 41 if(w->msg[0] != '\0'){ 42 free(w); 43 return -1; 44 } 45 free(w); 46 return 0; 47 } 48 } 49 } 50 return 0; 51 } 52