From 80f906abb6f8a701a135ee7dd08d67eccd024fb1 Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Sun, 22 Mar 1992 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 1992-03-22 --- boot/boot.c | 12 ++++++++---- boot/boot.h | 1 - boot/getpasswd.c | 25 ------------------------- boot/key.c | 3 ++- boot/userpasswd.c | 6 ++---- port/devip.c | 10 ++++++++++ port/devlance.c | 3 +++ port/devmnt.c | 17 +++++++++-------- port/portdat.h | 2 +- port/tcpif.c | 10 ++++++++++ power/bboot.c | 9 ++++----- 11 files changed, 49 insertions(+), 49 deletions(-) diff --git a/boot/boot.c b/boot/boot.c index 4b9663322f81b1d4bd73058fddb4d5e6e3a22fff..e75a66183353a8a8b029ed086866791472f8246a 100644 --- a/boot/boot.c +++ b/boot/boot.c @@ -16,6 +16,7 @@ char username[NAMELEN]; int mflag; int fflag; int kflag; +int aflag; int cache(int); void swapproc(void); @@ -37,6 +38,9 @@ main(int argc, char *argv[]) open("#c/cons", OWRITE); ARGBEGIN{ + case 'a': + aflag = 1; + break; case 'u': strcpy(username, ARGF()); break; @@ -112,7 +116,7 @@ main(int argc, char *argv[]) swapproc(); sprint(cmd, "/%s/init", cputype); - sprint(flags, "-%s%s", cpuflag ? "c" : "t", mflag ? "m" : ""); + sprint(flags, "-%s%s%s", cpuflag ? "c" : "t", mflag ? "m" : "", aflag ? "a" : ""); execl(cmd, "init", flags, 0); fatal(cmd); } @@ -128,6 +132,7 @@ rootserver(char *arg) Method *mp; char *cp; int n; + int notfirst; mp = method; n = sprint(prompt, "root is from (%s", mp->name); @@ -139,10 +144,9 @@ rootserver(char *arg) strcpy(reply, arg); else strcpy(reply, method->name); - for(;;){ - if(arg == 0 || mflag) + for(notfirst = 0;; notfirst = 1){ + if(mflag || notfirst) outin(prompt, reply, sizeof(reply)); - arg = 0; for(mp = method; mp->name; mp++) if(*reply == *mp->name){ cp = strchr(reply, '!'); diff --git a/boot/boot.h b/boot/boot.h index 14d8468b03c12e87ec7415187c04110ed9c34dda..027dd2699990c5c7a5bd9a7d14cfc7e0a00731df 100644 --- a/boot/boot.h +++ b/boot/boot.h @@ -31,7 +31,6 @@ extern void key(int, Method*); extern void newkernel(void); extern void nop(int); extern int outin(char*, char*, int); -extern int passtokey(char*, char*, int); extern int plumb(char*, char*, int*, char*); extern int readenv(char*, char*, int); extern int sendmsg(int, char*); diff --git a/boot/getpasswd.c b/boot/getpasswd.c index d6f1f5f8666a54f409694a98b701ebe6d8de6813..b766e254389e869274319e2ba065cddc8f5783e1 100644 --- a/boot/getpasswd.c +++ b/boot/getpasswd.c @@ -2,31 +2,6 @@ #include #include <../boot/boot.h> -int -passtokey(char *key, char *p, int n) -{ - uchar t[10]; - int c; - - memset(t, ' ', sizeof t); - if(n < 5) - return 0; - if(n > 10) - n = 10; - strncpy((char*)t, p, n); - if(n >= 9){ - c = p[8] & 0xf; - if(n == 10) - c += p[9] << 4; - for(n = 0; n < 8; n++) - if(c & (1 << n)) - t[n] -= ' '; - } - for(n = 0; n < 7; n++) - key[n] = (t[n] >> n) + (t[n+1] << (8 - (n+1))); - return 1; -} - void getpasswd(char *p, int len) { diff --git a/boot/key.c b/boot/key.c index 4fefa6f4d3f36be7bc8ac752caccbe8078bff4cd..7fd3983afce0c7916a9d2d397cfb7a38b2367488 100644 --- a/boot/key.c +++ b/boot/key.c @@ -1,5 +1,6 @@ #include #include +#include #include <../boot/boot.h> void @@ -20,7 +21,7 @@ key(int islocal, Method *mp) if(prompt){ do getpasswd(password, sizeof password); - while(!passtokey(key, password, strlen(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"); diff --git a/boot/userpasswd.c b/boot/userpasswd.c index ad82cea1227168054458bef92ad6d2c370feeb2b..f94598e714dc7fa7ecfb351b76aa4bff41e79bb3 100644 --- a/boot/userpasswd.c +++ b/boot/userpasswd.c @@ -1,5 +1,6 @@ #include #include +#include #include <../boot/boot.h> char password[NAMELEN]; @@ -21,10 +22,7 @@ userpasswd(int islocal, Method *mp) crfd = fd = -1; while(strcmp(username, "none") != 0 && !islocal){ getpasswd(password, sizeof password); - if(!passtokey(key, password, strlen(password))){ - print("bad password; try again\n"); - continue; - } + passtokey(key, password); fd = open("#c/key", OWRITE); if(fd < 0) fatal("can't open #c/key; please reboot"); diff --git a/port/devip.c b/port/devip.c index 24f829c536b0bfe7146796657690fe3cb2d13947..b76b1077d282cfa11dcde3324fa816ca1b9ee22a 100644 --- a/port/devip.c +++ b/port/devip.c @@ -529,6 +529,10 @@ tcpstoput(Queue *q, Block *bp) case Established: case Close_wait: qlock(tcb); + if(waserror()) { + qunlock(tcb); + nexterror(); + } tcb->sndcnt += blen(bp); if(tcb->sndq == 0) tcb->sndq = bp; @@ -539,6 +543,7 @@ tcpstoput(Queue *q, Block *bp) } tcprcvwin(s); tcp_output(s); + poperror(); qunlock(tcb); break; @@ -707,7 +712,12 @@ tcpstclose(Queue *q) setstate(s, Last_ack); output: qlock(tcb); + if(waserror()) { + qunlock(tcb); + nexterror(); + } tcp_output(s); + poperror(); qunlock(tcb); break; } diff --git a/port/devlance.c b/port/devlance.c index 4900448b5be5c12d594e78121b3c96bab5e5ea5f..222daaac38c718b4c8302c35f94f4392c2e52e45 100644 --- a/port/devlance.c +++ b/port/devlance.c @@ -552,6 +552,9 @@ lanceattach(char *spec) kproc("lancekproc", lancekproc, 0);/**/ l.kstarted = 1; lancestart(0, 1); + print("lance ether: %.2x%.2x%.2x%.2x%.2x%.2x\n", + l.ea[0], l.ea[1], l.ea[2], l.ea[3], l.ea[4], l.ea[5]); + } return devattach('l', spec); } diff --git a/port/devmnt.c b/port/devmnt.c index 4bf27f798ca5f9894c164cf809245cffb25f9e22..daf00ed6d4dfe01f5ab119b250d3ea65391a37da 100644 --- a/port/devmnt.c +++ b/port/devmnt.c @@ -241,7 +241,7 @@ void mntauth(Mnt *m, Mntrpc *f, char *serv, ushort fid) { Mntrpc *r; - uchar chal[CHLEN]; + uchar chal[AUTHLEN]; int i; r = mntralloc(); @@ -254,22 +254,23 @@ mntauth(Mnt *m, Mntrpc *f, char *serv, ushort fid) r->request.fid = fid; memmove(r->request.uname, u->p->user, NAMELEN); chal[0] = FScchal; - for(i = 1; i < CHLEN; i++) + for(i = 1; i < AUTHLEN; i++) chal[i++] = nrand(256); - memmove(r->request.chal, chal, CHLEN); - strncpy(r->request.chal+CHLEN, serv, NAMELEN); - encrypt(u->p->pgrp->crypt->key, r->request.chal, CHLEN+NAMELEN); + memmove(r->request.chal, chal, AUTHLEN); + strncpy(r->request.chal+AUTHLEN, serv, NAMELEN); + encrypt(u->p->pgrp->crypt->key, r->request.chal, AUTHLEN+NAMELEN); mountrpc(m, r); - decrypt(u->p->pgrp->crypt->key, r->reply.chal, 2*CHLEN+2*DESKEYLEN); + + decrypt(u->p->pgrp->crypt->key, r->reply.chal, 2*AUTHLEN+2*DESKEYLEN); chal[0] = FSctick; poperror(); - if(memcmp(chal, r->reply.chal, CHLEN) != 0) { + if(memcmp(chal, r->reply.chal, AUTHLEN) != 0) { mntfree(r); error(Eperm); } - memmove(f->request.auth, r->reply.chal+CHLEN+DESKEYLEN, CHLEN+DESKEYLEN); + memmove(f->request.auth, r->reply.chal+AUTHLEN+DESKEYLEN, AUTHLEN+DESKEYLEN); mntfree(r); } diff --git a/port/portdat.h b/port/portdat.h index c654b3dccc8fe182eb57f422d2936b5bf03c63fc..f2c23f2948fada1736b18d595d075b7e15aaea55 100644 --- a/port/portdat.h +++ b/port/portdat.h @@ -705,7 +705,7 @@ extern char sysname[NAMELEN]; /* * auth messages */ -#define CHLEN 8 +#define AUTHLEN 8 enum{ FScchal = 1, FSschal, diff --git a/port/tcpif.c b/port/tcpif.c index 9f63290e92ad8512ed31ec737dfb28677342d788..965d452a768217814e8df11799c4bdd0c5da521b 100644 --- a/port/tcpif.c +++ b/port/tcpif.c @@ -42,10 +42,15 @@ state_upcall(Ipconv *s, char oldstate, char newstate) bp->flags |= S_DELIM; bp->type = M_HANGUP; qlock(s); + if(waserror()) { + qunlock(s); + nexterror(); + } if(s->readq == 0) freeb(bp); else PUTNEXT(s->readq, bp); + poperror(); qunlock(s); break; } @@ -81,9 +86,14 @@ tcpstart(Ipconv *s, int mode, ushort window, char tos) /* Send SYN, go into SYN_SENT state */ tcb->flags |= ACTIVE; qlock(tcb); + if(waserror()) { + qunlock(tcb); + nexterror(); + } send_syn(tcb); setstate(s, Syn_sent); tcp_output(s); + poperror(); qunlock(tcb); sleep(&tcb->syner, notsyner, tcb); if(tcb->state != Established && tcb->state != Syn_received) diff --git a/power/bboot.c b/power/bboot.c index 786b00a450d141f5ed9ab978d867ca2d1abc2343..551c2397a320a0bc7d6940808b88d66eceaefafe 100644 --- a/power/bboot.c +++ b/power/bboot.c @@ -61,7 +61,7 @@ main(int argc, char *argv[]) char cmd[64]; char flags[6]; int islocal; - char *bootfile; + char bootfile[NAMELEN]; sleep(1000); @@ -88,9 +88,9 @@ main(int argc, char *argv[]) readenv("terminal", terminal, sizeof(cputype)); readenv("sysname", sysname, sizeof(sysname)); if(argc > 1) - bootfile = argv[1]; + strcpy(bootfile, argv[1]); else - bootfile = DEFFILE; + strcpy(bootfile, DEFFILE); /* * pick a method and initialize it @@ -166,9 +166,8 @@ rootserver(char *arg) else strcpy(reply, method->name); for(;;){ - if(arg == 0 || mflag) + if(mflag) outin(prompt, reply, sizeof(reply)); - arg = 0; for(mp = method; mp->name; mp++) if(*reply == *mp->name){ cp = strchr(reply, '!');