## diffname boot/key.c 1992/0317 ## diff -e /dev/null /n/bootesdump/1992/0317/sys/src/9/boot/key.c 0a #include #include #include <../boot/boot.h> void key(Method *mp) { char password[20], key[7]; int prompt, fd; USED(mp); prompt = kflag; fd = open("#r/nvram", ORDWR); if(fd < 0){ prompt = 1; warning("can't open nvram"); } if(prompt){ do if(getpasswd(password, sizeof password) < 0){ warning("can't read cons"); return; } while(!passtokey(key, password, strlen(password))); }else if(seek(fd, 1024+900, 0) < 0 || read(fd, key, 7) != 7){ close(fd); warning("can't read key from nvram"); } if(kflag && seek(fd, 1024+900, 0) < 0 || write(fd, key, 7) != 7){ close(fd); warning("can't write key to nvram"); } close(fd); fd = open("#c/key", OWRITE); if(fd < 0) warning("can't open key"); else if(write(fd, key, 7) != 7) warning("can't write key"); close(fd); } . ## diffname boot/key.c 1992/0318 ## diff -e /n/bootesdump/1992/0317/sys/src/9/boot/key.c /n/bootesdump/1992/0318/sys/src/9/boot/key.c 30c if(kflag && (seek(fd, 1024+900, 0) < 0 || write(fd, key, 7) != 7)){ . 21,24c getpasswd(password, sizeof password); . 10a USED(islocal); . 6c key(int islocal, Method *mp) . ## diffname boot/key.c 1992/0322 ## diff -e /n/bootesdump/1992/0318/sys/src/9/boot/key.c /n/bootesdump/1992/0322/sys/src/9/boot/key.c 23c while(!passtokey(key, password)); . 2a #include . ## diffname boot/key.c 1992/0323 ## diff -e /n/bootesdump/1992/0322/sys/src/9/boot/key.c /n/bootesdump/1992/0323/sys/src/9/boot/key.c 41d 36,38c warning("can't open #c/key"); else if(write(fd, key, DESKEYLEN) != DESKEYLEN) warning("can't set #c/key"); . 29,31c nvsum = cksum(key); if(kflag){ if(seek(fd, 1024+900, 0) < 0 || write(fd, key, DESKEYLEN) != DESKEYLEN || write(fd, &nvsum, 1) != 1) warning("can't write key to nvram"); . 25,27c }else if(cksum(key) != nvsum){ warning("bad nvram key; using password boofhead"); passtokey(key, "boofhead"); . 20a if(seek(fd, 1024+900, 0) < 0 || read(fd, key, DESKEYLEN) != DESKEYLEN || read(fd, &nvsum, 1) != 1) warning("can't read nvram key"); . 9c char password[20], key[DESKEYLEN]; uchar nvsum; . 5a static uchar cksum(char *key) { int i, nvsum; nvsum = 0; for(i=0; iauthdom, strlen(safe->authdom)) < 0) . 72c if(writefile("#c/hostowner", safe->authid, strlen(safe->authid)) < 0) . 68c if(writefile("#c/key", safe->machkey, DESKEYLEN) < 0) . 62c || write(fd, buf, safelen) != safelen) . 55,60c while(!passtokey(safe->machkey, password)); outin("authid", safe->authid, sizeof(safe->authid)); outin("authdom", safe->authdom, sizeof(safe->authdom)); safe->machsum = nvcsum(safe->machkey, DESKEYLEN); safe->authidsum = nvcsum(safe->authid, sizeof(safe->authid)); safe->authdomsum = nvcsum(safe->authdom, sizeof(safe->authdom)); . 49,51c check(safe->machkey, DESKEYLEN, safe->machsum, "bad nvram key"); check(safe->authid, NAMELEN, safe->authidsum, "bad authentication id"); check(safe->authdom, DOMLEN, safe->authdomsum, "bad authentication domain"); . 45,46c || read(fd, buf, safelen) != safelen){ memset(safe, 0, sizeof(safe)); . 37c if(fd < 0){ fd = open("#f/fd0disk", ORDWR); if(fd >= 0){ if(dirfstat(fd, &d) >= 0){ safeoff = d.length - 512; safelen = 512; } else { close(fd); fd = -1; } } } . 29a safe = (Nvrsafe*)buf; safelen = sizeof(Nvrsafe); safeoff = 0; . 25a Dir d; . 23,24c int fd, safeoff, safelen; char buf[1024]; Nvrsafe *safe; . ## diffname boot/key.c 1997/0910 ## diff -e /n/emeliedump/1997/0909/sys/src/brazil/boot/key.c /n/emeliedump/1997/0910/sys/src/brazil/boot/key.c 94a } typedef struct Dosboot Dosboot; struct Dosboot{ uchar magic[3]; /* really an xx86 JMP instruction */ uchar version[8]; uchar sectsize[2]; uchar clustsize; uchar nresrv[2]; uchar nfats; uchar rootsize[2]; uchar volsize[2]; uchar mediadesc; uchar fatsize[2]; uchar trksize[2]; uchar nheads[2]; uchar nhidden[4]; uchar bigvolsize[4]; uchar driveno; uchar reserved0; uchar bootsig; uchar volid[4]; uchar label[11]; uchar type[8]; }; #define GETSHORT(p) (((p)[1]<<8) | (p)[0]) #define GETLONG(p) ((GETSHORT((p)+2) << 16) | GETSHORT((p))) typedef struct Dosdir Dosdir; struct Dosdir { char name[8]; char ext[3]; uchar attr; uchar reserved[10]; uchar time[2]; uchar date[2]; uchar start[2]; uchar length[4]; }; static char* dosparse(char *from, char *to, int len) { char c; memset(to, ' ', len); if(from == 0) return 0; while(len-- > 0){ c = *from++; if(c == '.') return from; if(c == 0) break; if(c >= 'a' && c <= 'z') *to++ = c + 'A' - 'a'; else *to++ = c; } return 0; } /* * return offset of first file block * * This is a very simplistic dos file system. It only * works on floppies, only looks in the root, and only * returns a pointer to the first block of a file. * * This exists for cpu servers that have no hard disk * or nvram to store the key on. * * Please don't make this any smarter: it stays resident * and I'ld prefer not to waste the space on something that * runs only at boottime -- presotto. */ static long finddosfile(int fd, char *file) { uchar secbuf[512]; char name[8]; char ext[3]; Dosboot *b; Dosdir *root, *dp; int nroot, sectsize, rootoff, rootsects, n; /* dos'ize file name */ file = dosparse(file, name, 8); dosparse(file, ext, 3); /* read boot block, check for sanity */ b = (Dosboot*)secbuf; if(read(fd, secbuf, sizeof(secbuf)) != sizeof(secbuf)) return -1; if(b->magic[0] != 0xEB || b->magic[1] != 0x3C || b->magic[2] != 0x90) return -1; sectsize = GETSHORT(b->sectsize); if(sectsize != 512) return -1; rootoff = (1 + b->nfats*GETSHORT(b->fatsize)) * sectsize; if(seek(fd, rootoff, 0) < 0) return -1; nroot = GETSHORT(b->rootsize); rootsects = (nroot*sizeof(Dosdir)+sectsize-1)/sectsize; if(rootsects <= 0 || rootsects > 20) return -1; /* * read root. it is contiguous to make stuff like * this easier */ root = malloc(rootsects*sectsize); if(read(fd, root, rootsects*sectsize) != rootsects*sectsize) return -1; n = -1; for(dp = root; dp < &root[nroot]; dp++) if(memcmp(name, dp->name, 8) == 0 && memcmp(ext, dp->ext, 3) == 0){ n = GETSHORT(dp->start); break; } free(root); if(n < 0) return -1; /* * dp->start is in cluster units, not sectors. The first * cluster is cluster 2 which starts immediately after the * root directory */ return rootoff + rootsects*sectsize + (n-2)*sectsize*b->clustsize; . 52a safelen = 512; . 46,49c safeoff = finddosfile(fd, "plan9.nvr"); if(safeoff < 0){ . 44a if(fd < 0) fd = open("#f/fd1disk", ORDWR); . 27d 5a static long finddosfile(int, char*); . ## diffname boot/key.c 1999/0618 ## diff -e /n/emeliedump/1997/0910/sys/src/brazil/boot/key.c /n/emeliedump/1999/0618/sys/src/brazil/boot/key.c 85a //fprint(2, "hostowner = %s\n", safe->authid); //fprint(2, "hostdomain = %s\n", safe->authdom); . ## diffname boot/key.c 2000/0401 ## diff -e /n/emeliedump/1999/0618/sys/src/brazil/boot/key.c /n/emeliedump/2000/0401/sys/src/9/boot/key.c 85,87d 40c } else if(strcmp(cputype, "386") == 0 || strcmp(cputype, "alpha") == 0){ . ## diffname boot/key.c 2000/0518 ## diff -e /n/emeliedump/2000/0401/sys/src/9/boot/key.c /n/emeliedump/2000/0518/sys/src/9/boot/key.c 43c fd = open("#S/sd00/nvram", ORDWR); . 41c fd = open("#S/sdC0/nvram", ORDWR); . ## diffname boot/key.c 2000/0708 ## diff -e /n/emeliedump/2000/0518/sys/src/9/boot/key.c /n/emeliedump/2000/0708/sys/src/9/boot/key.c 94a if(*safe->authdom == 0) strcpy(safe->authdom, "plan9"); . ## diffname boot/key.c 2000/0722 ## diff -e /n/emeliedump/2000/0708/sys/src/9/boot/key.c /n/emeliedump/2000/0722/sys/src/9/boot/key.c 98c warning("#c/hostdomain"); . 92c warning("#c/hostowner"); . 88c warning("#c/key"); . ## diffname boot/key.c 2000/0825 ## diff -e /n/emeliedump/2000/0722/sys/src/9/boot/key.c /n/emeliedump/2000/0825/sys/src/9/boot/key.c 41a if(fd < 0){ fd = open("#S/sdC0/9fat", ORDWR); if(fd >= 0){ safeoff = finddosfile(fd, "plan9.nvr"); if(safeoff < 0){ close(fd); fd = -1; } print("safeoff = %d\n", safeoff); safelen = 512; } } . ## diffname boot/key.c 2000/0829 ## diff -e /n/emeliedump/2000/0825/sys/src/9/boot/key.c /n/emeliedump/2000/0829/sys/src/9/boot/key.c 50d ## diffname boot/key.c 2000/0914 ## diff -e /n/emeliedump/2000/0829/sys/src/9/boot/key.c /n/emeliedump/2000/0914/sys/src/9/boot/key.c 215c if(rootsects <= 0 || rootsects > 64) . 210c rootoff = (GETSHORT(b->nresrv) + b->nfats*GETSHORT(b->fatsize)) * sectsize; . ## diffname boot/key.c 2001/0527 ## diff -e /n/emeliedump/2000/0914/sys/src/9/boot/key.c /n/emeliedump/2001/0527/sys/src/9/boot/key.c 80a #undef NAMELEN . 79a #define NAMELEN 28 /*BUG: THIS IS TOTALLY BOGUS */ . ## diffname boot/key.c 2001/0924 ## diff -e /n/emeliedump/2001/0527/sys/src/9/boot/key.c /n/emeliedump/2001/0924/sys/src/9/boot/key.c 80,83c check(safe->authid, ANAMELEN, safe->authidsum, "bad authentication id"); . ## diffname boot/key.c 2001/1107 # deleted ## diff -e /n/emeliedump/2001/0924/sys/src/9/boot/key.c /n/emeliedump/2001/1107/sys/src/9/boot/key.c 1,242d