From 5d5bc03570f8b93f43e68377c646d4e534d5164a Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Thu, 12 Mar 1992 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 1992-03-12 --- port/devcons.c | 13 +++---------- port/devlance.c | 2 +- port/devmnt.c | 32 +++++++++++++++++++++++++++----- port/portfns.h | 1 - port/sysfile.c | 4 ++-- 5 files changed, 33 insertions(+), 19 deletions(-) diff --git a/port/devcons.c b/port/devcons.c index aa9e43e67340c3387a607d0657579407851a1c4b..341b5155204071e7e1aba06f543bfe5f764400b8 100644 --- a/port/devcons.c +++ b/port/devcons.c @@ -889,19 +889,12 @@ conswstat(Chan *c, char *dp) * Rand is huge and not worth it here. Be small. * Borrowed from the white book. */ -ulong randn; -void -srand(char *s) -{ - randn = MACHP(0)->ticks * boottime; - while(s && *s) - randn = (randn << 1) ^ *s++; -} - int nrand(int n) { - randn = randn*1103515245 + 12345; + static ulong randn; + + randn = randn*1103515245 + 12345 + MACHP(0)->ticks; return (randn>>16) % n; } diff --git a/port/devlance.c b/port/devlance.c index 74eaaa25165d8ceebf8989a5af03598b767e3b74..414e9776096cfa8cbf27408f64db340617465713 100644 --- a/port/devlance.c +++ b/port/devlance.c @@ -282,7 +282,7 @@ lanceoput(Queue *q, Block *bp ) qlock(&l); l.prom++; if(l.prom == 1) -/* lancestart(PROM, 1);/**/ + lancestart(PROM, 1);/**/ qunlock(&l); } freeb(bp); diff --git a/port/devmnt.c b/port/devmnt.c index 86ba9d04aff794ec2aabde8d66fe6b81ae9fa678..823825784bfeb0459688c4c3fc5ba1b16c279f55 100644 --- a/port/devmnt.c +++ b/port/devmnt.c @@ -130,7 +130,7 @@ mntattach(char *muxattach) struct bogus{ Chan *chan; char *spec; - char *auth; + char *serv; }bogus; bogus = *((struct bogus *)muxattach); @@ -141,7 +141,7 @@ mntattach(char *muxattach) if(m->ref > 0 && m->id && m->c == bogus.chan) { m->ref++; unlock(m); - return mattach(m, bogus.spec, bogus.auth); + return mattach(m, bogus.spec, bogus.serv); } unlock(m); } @@ -174,14 +174,16 @@ mntattach(char *muxattach) incref(m->c); unlock(m); - return mattach(m, bogus.spec, bogus.auth); + return mattach(m, bogus.spec, bogus.serv); } Chan * -mattach(Mnt *m, char *spec, char *auth) +mattach(Mnt *m, char *spec, char *serv) { Chan *c; Mntrpc *r; + char chal[8]; + int i; r = mntralloc(); @@ -191,6 +193,26 @@ mattach(Mnt *m, char *spec, char *auth) unlock(&mntalloc); c->mntindex = m-mntalloc.mntarena; + if(*serv && !waserror()){ + r->request.type = Tauth; + r->request.fid = c->fid; + memmove(r->request.uname, u->p->user, NAMELEN); + chal[0] = 1; + for(i = 1; i < sizeof chal; i++) + chal[i++] = nrand(256); + memmove(r->request.chal, chal, 8); + strncpy(r->request.chal+8, serv, NAMELEN); + encrypt(u->p->pgrp->crypt->key, r->request.chal, 8+NAMELEN); + mountrpc(m, r); + decrypt(u->p->pgrp->crypt->key, r->reply.chal, 2*8+2*DESKEYLEN); + chal[0] = 4; + if(memcmp(chal, r->reply.chal, 8) != 0) + error(Eperm); + memmove(r->request.auth, r->reply.chal+8+DESKEYLEN, 8+DESKEYLEN); + poperror(); + }else + memset(r->request.auth, 0, sizeof r->request.auth); + if(waserror()){ mntfree(r); close(c); @@ -200,7 +222,6 @@ mattach(Mnt *m, char *spec, char *auth) r->request.fid = c->fid; memmove(r->request.uname, u->p->user, NAMELEN); strncpy(r->request.aname, spec, NAMELEN); - strncpy(r->request.auth, auth, NAMELEN); mountrpc(m, r); c->qid = r->reply.qid; @@ -249,6 +270,7 @@ mntclone(Chan *c, Chan *nc) nc->mqid = c->qid; incref(m); + USED(alloc); poperror(); mntfree(r); return nc; diff --git a/port/portfns.h b/port/portfns.h index 9920f254fa2c114cc6ee6185b088baa6ffa3b2fb..6f9faab488cf5d7ba9af8c551b2deffb86f141b7 100644 --- a/port/portfns.h +++ b/port/portfns.h @@ -212,7 +212,6 @@ void sleep(Rendez*, int(*)(void*), void*); int splhi(void); int spllo(void); void splx(int); -void srand(char*); int streamclose(Chan*); int streamclose1(Stream*); int streamenter(Stream*); diff --git a/port/sysfile.c b/port/sysfile.c index 371fc3bd1576ba0d738fabba65a58c438bc5c285..d3c45c846d588e2a5f92ecf03a9d528883044143 100644 --- a/port/sysfile.c +++ b/port/sysfile.c @@ -393,7 +393,7 @@ bindmount(ulong *arg, int ismount) struct{ Chan *chan; char *spec; - char *auth; + char *serv; }bogus; flag = arg[2]; @@ -408,7 +408,7 @@ bindmount(ulong *arg, int ismount) validaddr(arg[4], 1, 0); if(vmemchr((char*)arg[4], '\0', NAMELEN) == 0) error(Ebadarg); - bogus.auth = (char*)arg[4]; + bogus.serv = (char*)arg[4]; ret = devno('M', 0); c0 = (*devtab[ret].attach)((char*)&bogus); }else{