M boot/boot.c => boot/boot.c +8 -2
@@ 12,11 12,13 @@ char cputype[NAMELEN];
char terminal[NAMELEN];
char sys[2*NAMELEN];
char username[NAMELEN];
+char *sauth = "";
int mflag;
int fflag;
int kflag;
int aflag;
+int pflag;
int cache(int);
void swapproc(void);
@@ 48,8 50,12 @@ main(int argc, char *argv[])
kflag = 1;
break;
case 'm':
+ pflag = 1;
mflag = 1;
break;
+ case 'p':
+ pflag = 1;
+ break;
case 'f':
fflag = 1;
break;
@@ 89,7 95,7 @@ main(int argc, char *argv[])
*/
if(bind("/", "/", MREPL) < 0)
fatal("bind");
- if(mount(fd, "/", MAFTER|MCREATE, "", "") < 0)
+ if(mount(fd, "/", MAFTER|MCREATE, "", sauth) < 0)
fatal("mount");
close(fd);
newkernel();
@@ 145,7 151,7 @@ rootserver(char *arg)
else
strcpy(reply, method->name);
for(notfirst = 0;; notfirst = 1){
- if(mflag || notfirst)
+ if(pflag || notfirst)
outin(prompt, reply, sizeof(reply));
for(mp = method; mp->name; mp++)
if(*reply == *mp->name){
M boot/key.c => boot/key.c +30 -11
@@ 3,10 3,22 @@
#include <auth.h>
#include <../boot/boot.h>
+static uchar
+cksum(char *key)
+{
+ int i, nvsum;
+
+ nvsum = 0;
+ for(i=0; i<DESKEYLEN; i++)
+ nvsum += key[i];
+ return nvsum & 0xff;
+}
+
void
key(int islocal, Method *mp)
{
- char password[20], key[7];
+ char password[20], key[DESKEYLEN];
+ uchar nvsum;
int prompt, fd;
USED(islocal);
@@ 18,24 30,31 @@ key(int islocal, Method *mp)
prompt = 1;
warning("can't open nvram");
}
+ if(seek(fd, 1024+900, 0) < 0
+ || read(fd, key, DESKEYLEN) != DESKEYLEN
+ || read(fd, &nvsum, 1) != 1)
+ warning("can't read nvram key");
+
if(prompt){
do
getpasswd(password, sizeof password);
while(!passtokey(key, password));
- }else if(seek(fd, 1024+900, 0) < 0 || read(fd, key, 7) != 7){
- close(fd);
- warning("can't read key from nvram");
+ }else if(cksum(key) != nvsum){
+ warning("bad nvram key; using password boofhead");
+ passtokey(key, "boofhead");
}
- if(kflag && (seek(fd, 1024+900, 0) < 0 || write(fd, key, 7) != 7)){
- close(fd);
- warning("can't write key to nvram");
+ 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");
}
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");
+ warning("can't open #c/key");
+ else if(write(fd, key, DESKEYLEN) != DESKEYLEN)
+ warning("can't set #c/key");
close(fd);
}
-
M boot/userpasswd.c => boot/userpasswd.c +8 -0
@@ 4,6 4,7 @@
#include <../boot/boot.h>
char password[NAMELEN];
+extern char *sauth;
/*
* get/set user name and password. verify password with auth server.
@@ 14,10 15,17 @@ userpasswd(int islocal, Method *mp)
char key[7];
char buf[8 + NAMELEN];
int fd, crfd;
+ char *p;
if(*username == 0 || strcmp(username, "none") == 0){
strcpy(username, "none");
outin("user", username, sizeof(username));
+ /* Hack to do authentication testing */
+ p = utfrrune(username, '!');
+ if(p && p > username) {
+ *p = '\0';
+ sauth = "any";
+ }
}
crfd = fd = -1;
while(strcmp(username, "none") != 0 && !islocal){
M pc/fns.h => pc/fns.h +2 -1
@@ 2,6 2,7 @@
void meminit(void);
void bigcursor(void);
+void bootargs(ulong);
#define clearmmucache() /* 386 doesn't have one */
void clock(Ureg*);
void clockinit(void);
@@ 55,7 56,7 @@ void screenputs(char*, int);
int serial(int);
void setvec(int, void (*)(Ureg*));
void systrap(void);
-void touser(void);
+void touser(void*);
void trapinit(void);
int tas(void*);
void uartclock(void);
M pc/l.s => pc/l.s +2 -1
@@ 563,7 563,8 @@ TEXT setlabel(SB),$0
*/
TEXT touser(SB),$0
PUSHL $(UDSEL) /* old ss */
- PUSHL $(USTKTOP) /* old sp */
+ MOVL sp+0(FP),AX /* old sp */
+ PUSHL AX
PUSHFL /* old flags */
PUSHL $(UESEL) /* old cs */
PUSHL $(UTZERO+32) /* old pc */
M pc/main.c => pc/main.c +45 -1
@@ 8,6 8,7 @@
#include "init.h"
int machtype;
+uchar *sp; /* stack pointer for /boot */
void
main(void)
@@ 93,7 94,7 @@ init0(void)
ksetenv("cputype", "386");
poperror();
}
- touser();
+ touser(sp);
}
void
@@ 103,6 104,7 @@ userinit(void)
Segment *s;
User *up;
KMap *k;
+ Page *pg;
p = newproc();
p->pgrp = newpgrp();
@@ 138,6 140,11 @@ userinit(void)
*/
s = newseg(SG_STACK, USTKTOP-BY2PG, 1);
p->seg[SSEG] = s;
+ pg = newpage(1, 0, USTKTOP-BY2PG);
+ segpage(s, pg);
+ k = kmap(pg);
+ bootargs(VA(k));
+ kunmap(k);
/*
* Text
@@ 152,6 159,43 @@ userinit(void)
ready(p);
}
+uchar *
+pusharg(char *p)
+{
+ int n;
+
+ n = strlen(p)+1;
+ sp -= n;
+ memmove(sp, p, n);
+ return sp;
+}
+
+void
+bootargs(ulong base)
+{
+ int i, ac;
+ uchar *av[32];
+ char *p, *pp;
+ uchar **lsp;
+
+ sp = (uchar*)base + BY2PG - MAXSYSARG*BY2WD;
+
+ ac = 0;
+ av[ac++] = pusharg("/386/9safari");
+ av[ac++] = pusharg("-p");
+
+ /* 4 byte word align stack */
+ sp = (uchar*)((ulong)sp & ~3);
+
+ /* build argc, argv on stack */
+ sp -= (ac+1)*sizeof(sp);
+ lsp = (uchar**)sp;
+ for(i = 0; i < ac; i++)
+ *lsp++ = av[i] + ((USTKTOP - BY2PG) - base);
+ *lsp = 0;
+ sp += (USTKTOP - BY2PG) - base - sizeof(ulong);
+}
+
Conf conf;
void
M port/devcons.c => port/devcons.c +10 -2
@@ 361,7 361,7 @@ Dirtab consdir[]={
"user", {Quser}, 0, 0666,
"chal", {Qchal}, 8, 0666,
"crypt", {Qcrypt}, 0, 0666,
- "key", {Qkey}, DESKEYLEN, 0222,
+ "key", {Qkey}, DESKEYLEN, 0622,
"klog", {Qklog}, 0, 0444,
"sysstat", {Qsysstat}, 0, 0666,
"sysname", {Qsysname}, 0, 0664,
@@ 597,7 597,7 @@ consread(Chan *c, void *buf, long n, ulong offset)
return n;
case Qchal:
- if(offset != 0 || n != 8)
+ if(offset!=0 || n!=8)
error(Ebadarg);
chal = u->p->pgrp->crypt->chal;
chal[0] = RXschal;
@@ 608,6 608,14 @@ consread(Chan *c, void *buf, long n, ulong offset)
chal[0] = RXstick;
return n;
+ case Qkey:
+ if(offset!=0 || n!=DESKEYLEN)
+ error(Ebadarg);
+ if(strcmp(u->p->user, eve)!=0 || conf.cntrlp==0)
+ error(Eperm);
+ memmove(buf, evekey, DESKEYLEN);
+ return n;
+
case Quser:
return readstr(offset, buf, n, u->p->user);