From fe24661d444598b0e263dab2da3473e2e5ad09bf Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Tue, 9 Sep 1997 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 1997-09-09 --- boot/key.c | 53 +++++++++++++++++++++++++++++++++++------------------ 1 file changed, 35 insertions(+), 18 deletions(-) diff --git a/boot/key.c b/boot/key.c index 2d670c933e3667f2b407b90e9ee10153b40e283f..660d157ee260e26e0734acee9b603e98c4098096 100644 --- a/boot/key.c +++ b/boot/key.c @@ -20,13 +20,19 @@ check(void *x, int len, uchar sum, char *msg) void key(int islocal, Method *mp) { - int fd, safeoff; - Nvrsafe safe; + int fd, safeoff, safelen; + char buf[1024]; + Nvrsafe *safe; char password[20]; + Dir d; USED(islocal); USED(mp); + safe = (Nvrsafe*)buf; + safelen = sizeof(Nvrsafe); + safeoff = 0; + if(strcmp(cputype, "sparc") == 0){ fd = open("#r/nvram", ORDWR); safeoff = 1024+850; @@ -34,7 +40,18 @@ key(int islocal, Method *mp) fd = open("#H/hd0nvram", ORDWR); if(fd < 0) fd = open("#w/sd0nvram", ORDWR); - safeoff = 0x0; + 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; + } + } + } } else { fd = open("#r/nvram", ORDWR); safeoff = 1024+900; @@ -42,37 +59,37 @@ key(int islocal, Method *mp) if(fd < 0 || seek(fd, safeoff, 0) < 0 - || read(fd, &safe, sizeof safe) != sizeof safe){ - memset(&safe, 0, sizeof(safe)); + || read(fd, buf, safelen) != safelen){ + memset(safe, 0, sizeof(safe)); warning("can't read nvram"); } - 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"); + 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"); if(kflag){ do getpasswd(password, sizeof password); - 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)); + 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)); if(seek(fd, safeoff, 0) < 0 - || write(fd, &safe, sizeof safe) != sizeof safe) + || write(fd, buf, safelen) != safelen) warning("can't write key to nvram"); } close(fd); /* set host's key */ - if(writefile("#c/key", safe.machkey, DESKEYLEN) < 0) + if(writefile("#c/key", safe->machkey, DESKEYLEN) < 0) fatal("#c/key"); /* set host's owner (and uid of current process) */ - if(writefile("#c/hostowner", safe.authid, strlen(safe.authid)) < 0) + if(writefile("#c/hostowner", safe->authid, strlen(safe->authid)) < 0) fatal("#c/hostowner"); /* set host's domain */ - if(writefile("#c/hostdomain", safe.authdom, strlen(safe.authdom)) < 0) + if(writefile("#c/hostdomain", safe->authdom, strlen(safe->authdom)) < 0) fatal("#c/hostdomain"); }