~kris/9p

9hist

5d5bc03570f8b93f43e68377c646d4e534d5164a — David du Colombier 34 years ago c03433f
Plan 9 from Bell Labs 1992-03-12
5 files changed, 33 insertions(+), 19 deletions(-)

M port/devcons.c
M port/devlance.c
M port/devmnt.c
M port/portfns.h
M port/sysfile.c
M port/devcons.c => port/devcons.c +3 -10
@@ 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;
}


M port/devlance.c => port/devlance.c +1 -1
@@ 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);

M port/devmnt.c => port/devmnt.c +27 -5
@@ 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;

M port/portfns.h => port/portfns.h +0 -1
@@ 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*);

M port/sysfile.c => port/sysfile.c +2 -2
@@ 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{