bootauth.c 1.6 KB

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