auth_getkey.c 865 B

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