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