auth_getkey.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include <u.h>
  10. #include <libc.h>
  11. #include <auth.h>
  12. int
  13. auth_getkey(char *params)
  14. {
  15. char *name;
  16. Dir *d;
  17. int pid;
  18. Waitmsg *w;
  19. /* start /factotum to query for a key */
  20. name = "/factotum";
  21. d = dirstat(name);
  22. if(d == nil){
  23. name = "/boot/factotum";
  24. d = dirstat(name);
  25. }
  26. if(d == nil){
  27. werrstr("auth_getkey: no /factotum or /boot/factotum: didn't get key %s", params);
  28. return -1;
  29. }
  30. if(0) if(d->type != '/'){
  31. werrstr("auth_getkey: /factotum may be bad: didn't get key %s", params);
  32. return -1;
  33. }
  34. switch(pid = fork()){
  35. case -1:
  36. werrstr("can't fork for %s: %r", name);
  37. return -1;
  38. case 0:
  39. execl(name, "getkey", "-g", params, nil);
  40. exits(0);
  41. default:
  42. for(;;){
  43. w = wait();
  44. if(w == nil)
  45. break;
  46. if(w->pid == pid){
  47. if(w->msg[0] != '\0'){
  48. free(w);
  49. return -1;
  50. }
  51. free(w);
  52. return 0;
  53. }
  54. }
  55. }
  56. return 0;
  57. }