bootauth.c 1.1 KB

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