|
|
1.1 root 1: #include <u.h>
2: #include <libc.h>
3: #include <auth.h>
4: #include <../boot/boot.h>
5:
6: static void
7: check(void *x, int len, uchar sum, char *msg)
8: {
9: if(nvcsum(x, len) == sum)
10: return;
11: memset(x, 0, len);
12: kflag = 1;
13: warning(msg);
14: }
15:
16: /*
17: * get info out of nvram. since there isn't room in the PC's nvram use
18: * a disk partition there.
19: */
20: void
21: key(int islocal, Method *mp)
22: {
23: int fd, safeoff;
24: Nvrsafe safe;
25: char password[20];
26:
27: USED(islocal);
28: USED(mp);
29:
30: if(strcmp(cputype, "sparc") == 0){
31: fd = open("#r/nvram", ORDWR);
32: safeoff = 1024+850;
33: } else if(strcmp(cputype, "386") == 0){
34: fd = open("#H/hd0nvram", ORDWR);
35: if(fd < 0)
36: fd = open("#w/sd0nvram", ORDWR);
37: safeoff = 0x0;
38: } else {
39: fd = open("#r/nvram", ORDWR);
40: safeoff = 1024+900;
41: }
42:
43: if(fd < 0
44: || seek(fd, safeoff, 0) < 0
45: || read(fd, &safe, sizeof safe) != sizeof safe){
46: memset(&safe, 0, sizeof(safe));
47: warning("can't read nvram");
48: }
49: check(safe.machkey, DESKEYLEN, safe.machsum, "bad nvram key");
50: check(safe.authid, NAMELEN, safe.authidsum, "bad authentication id");
51: check(safe.authdom, DOMLEN, safe.authdomsum, "bad authentication domain");
52: if(kflag){
53: do
54: getpasswd(password, sizeof password);
55: while(!passtokey(safe.machkey, password));
56: outin(0, "authid", safe.authid, sizeof(safe.authid));
57: outin(0, "authdom", safe.authdom, sizeof(safe.authdom));
58: safe.machsum = nvcsum(safe.machkey, DESKEYLEN);
59: safe.authidsum = nvcsum(safe.authid, sizeof(safe.authid));
60: safe.authdomsum = nvcsum(safe.authdom, sizeof(safe.authdom));
61: if(seek(fd, safeoff, 0) < 0
62: || write(fd, &safe, sizeof safe) != sizeof safe)
63: warning("can't write key to nvram");
64: }
65: close(fd);
66:
67: /* set host's key */
68: if(writefile("#c/key", safe.machkey, DESKEYLEN) < 0)
69: fatal("#c/key");
70:
71: /* set host's owner (and uid of current process) */
72: if(writefile("#c/hostowner", safe.authid, strlen(safe.authid)) < 0)
73: fatal("#c/hostowner");
74:
75: /* set host's domain */
76: if(writefile("#c/hostdomain", safe.authdom, strlen(safe.authdom)) < 0)
77: fatal("#c/hostdomain");
78: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.