bootauth.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. //av[ac++] = "-d";
  22. //av[ac++] = "-D"; //9p messages
  23. if(cpuflag)
  24. av[ac++] = "-S";
  25. else
  26. av[ac++] = "-u";
  27. av[ac++] = "-sfactotum";
  28. if(authaddr != nil){
  29. av[ac++] = "-a";
  30. av[ac++] = authaddr;
  31. }
  32. av[ac] = 0;
  33. switch(fork()){
  34. case -1:
  35. fatal("starting factotum: %r");
  36. case 0:
  37. exec("/boot/factotum", av);
  38. fatal("execing /boot/factotum");
  39. default:
  40. break;
  41. }
  42. /* wait for agent to really be there */
  43. while(access("/mnt/factotum", 0) < 0)
  44. sleep(250);
  45. if(cpuflag)
  46. return;
  47. }
  48. static void
  49. glenda(void)
  50. {
  51. int fd;
  52. char *s;
  53. s = getenv("user");
  54. if(s == nil)
  55. s = "glenda";
  56. fd = open("#c/hostowner", OWRITE);
  57. if(fd >= 0){
  58. if(write(fd, s, strlen(s)) != strlen(s))
  59. fprint(2, "setting #c/hostowner to %s: %r\n", s);
  60. close(fd);
  61. }
  62. }