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