plan 9 kernel history: overview | file list | diff list

2002/0517/port/auth.c (diff list | history)

1993/0330/sys/src/9/port/auth.c:135,1411993/0402/sys/src/9/port/auth.c:135,144 (short | long)
Hack around Datakit OK. Report bad cuid as auth error.
rsc Fri Mar 4 12:44:25 2005
1993/0330    
		n = convS2M(f, buf); 
		if((*devtab[c->type].write)(c, buf, n, 0) != n) 
			error(Emountrpc); 
1993/0402    
	dkhack: 
1993/0330    
		n = (*devtab[c->type].read)(c, buf, MAXMSG, 0); 
1993/0402    
		if(n == 2 && buf[0] == 'O' && buf[1] == 'K') 
			goto dkhack; 
1993/0330    
		if(convM2S(buf, f, n) == 0) 
			error(Emountrpc); 
		if(f->type == Rsession){ 
1993/0330/sys/src/9/port/auth.c:409,4161993/0402/sys/src/9/port/auth.c:412,421
1993/0330    
		c->aux = newcrypt(); 
	cp = c->aux; 
	convM2T(a, &cp->t, evekey); 
	if(cp->t.num != AuthTc || strcmp(u->p->user, cp->t.cuid)) 
1993/0402    
	if(cp->t.num != AuthTc) 
1993/0330    
		error(Ebadarg); 
1993/0402    
	if(strcmp(u->p->user, cp->t.cuid)) 
		error(cp->t.cuid); 
1993/0330    
	convM2A(a+TICKETLEN, &cp->a, cp->t.key); 
	if(cp->a.num != AuthAs || memcmp(cp->t.chal, cp->a.chal, CHALLEN)) 
		error(Eperm); 
1993/0402/sys/src/9/port/auth.c:130,1351993/0403/sys/src/9/port/auth.c:130,136 (short | long)
1993/0330    
		memset(s, 0, sizeof(Session)); 
		for(i = 0; i < CHALLEN; i++) 
			s->cchal[i] = nrand(256); 
1993/0403    
		f->tag = NOTAG; 
1993/0330    
		f->type = Tsession; 
		memmove(f->chal, s->cchal, CHALLEN); 
		n = convS2M(f, buf); 
1993/0402/sys/src/9/port/auth.c:237,2461993/0403/sys/src/9/port/auth.c:238,249
1993/0330    
void 
freesession(Session *s) 
{ 
	Crypt *cp; 
1993/0403    
	Crypt *cp, *next; 
1993/0330    
 
	for(cp = s->cache; cp; cp = cp->next) 
1993/0403    
	for(cp = s->cache; cp; cp = next) { 
		next = cp->next; 
1993/0330    
		freecrypt(cp); 
1993/0403    
	} 
1993/0330    
	free(s); 
} 
 
1993/0402/sys/src/9/port/auth.c:262,2701993/0403/sys/src/9/port/auth.c:265,278
1993/0330    
 
	/* look for ticket in cache */ 
	dofree = 0; 
1993/0403    
	lock(s); 
1993/0330    
	for(cp = s->cache; cp; cp = cp->next) 
		if(strcmp(cp->t.cuid, u->p->user) == 0) 
			break; 
1993/0403    
 
	id = s->cid++; 
	unlock(s); 
 
1993/0330    
	if(cp == 0){ 
		/* 
		 *  create a ticket using hostkey, this solves the 
1993/0402/sys/src/9/port/auth.c:280,2881993/0403/sys/src/9/port/auth.c:288,293
1993/0330    
		dofree = 1; 
	} else 
		memmove(f->ticket, cp->tbuf, TICKETLEN); 
	lock(s); 
	id = s->cid++; 
	unlock(s); 
 
	/* create an authenticator */ 
	memmove(cp->a.chal, s->schal, CHALLEN); 
1993/0402/sys/src/9/port/auth.c:305,3131993/0403/sys/src/9/port/auth.c:310,320
1993/0330    
	if(s == 0) 
		return; 
 
1993/0403    
	lock(s); 
1993/0330    
	for(cp = s->cache; cp; cp = cp->next) 
		if(strcmp(cp->t.cuid, u->p->user) == 0) 
			break; 
1993/0403    
	unlock(s); 
1993/0330    
 
	/* we're getting around authentication */ 
	if(s == 0 || cp == 0 || s->authid[0] == 0 || strcmp(u->p->user, "none") == 0) 
1993/0403/sys/src/9/port/auth.c:96,1531993/0407/sys/src/9/port/auth.c:96,166 (short | long)
1993/0330    
{ 
	int i, n; 
	Chan *c; 
	Fcall *f; 
	char *buf; 
	Crypt *cp; 
	Session *s; 
	Ticketreq tr; 
1993/0407    
	Fcall f; 
	char buf[MAXMSG]; 
1993/0330    
 
	validaddr(arg[1], TICKREQLEN, 1); 
	f = malloc(sizeof(Fcall)); 
	if(f == 0) 
		error(Enomem); 
	buf = malloc(MAXMSG); 
	if(buf == 0){ 
		free(f); 
		error(Enomem); 
	} 
	c = fdtochan(arg[0], OWRITE, 0, 1); 
	s = 0; 
	if(waserror()) { 
		if(s) 
			free(s); 
1993/0407    
	if(waserror()){ 
1993/0330    
		close(c); 
		free(buf); 
		free(f); 
		nexterror(); 
	} 
1993/0407    
 
	/* 
	 *  if two processes get here at the same 
	 *  time with no session exchanged, we have 
	 *  a race. 
	 */ 
1993/0330    
	s = c->session; 
	if(s == 0){ 
		/*  exchange a session message with the server */ 
1993/0407    
		/* 
		 *  no session exchanged yet 
		 */ 
1993/0330    
		s = malloc(sizeof(Session)); 
		if(s == 0) 
			error(Enomem); 
		memset(s, 0, sizeof(Session)); 
		for(i = 0; i < CHALLEN; i++) 
			s->cchal[i] = nrand(256); 
1993/0403    
		f->tag = NOTAG; 
1993/0330    
		f->type = Tsession; 
		memmove(f->chal, s->cchal, CHALLEN); 
		n = convS2M(f, buf); 
		if((*devtab[c->type].write)(c, buf, n, 0) != n) 
			error(Emountrpc); 
1993/0402    
	dkhack: 
1993/0330    
		n = (*devtab[c->type].read)(c, buf, MAXMSG, 0); 
1993/0402    
		if(n == 2 && buf[0] == 'O' && buf[1] == 'K') 
			goto dkhack; 
1993/0330    
		if(convM2S(buf, f, n) == 0) 
			error(Emountrpc); 
		if(f->type == Rsession){ 
			memmove(s->schal, f->chal, CHALLEN); 
			memmove(s->authid, f->authid, NAMELEN); 
			memmove(s->authdom, f->authdom, DOMLEN); 
1993/0407    
 
		/* 
		 *  Exchange a session message with the server. 
		 *  If an error occurs reading or writing, 
		 *  assume this is a mount of a mount and turn off 
		 *  authentication. 
		 */ 
		if(!waserror()){ 
			for(i = 0; i < CHALLEN; i++) 
				s->cchal[i] = nrand(256); 
			f.tag = NOTAG; 
			f.type = Tsession; 
			memmove(f.chal, s->cchal, CHALLEN); 
			n = convS2M(&f, buf); 
			if((*devtab[c->type].write)(c, buf, n, 0) != n) 
				error(Emountrpc); 
			n = (*devtab[c->type].read)(c, buf, sizeof buf, 0); 
			if(n == 2 && buf[0] == 'O' && buf[1] == 'K') 
				n = (*devtab[c->type].read)(c, buf, sizeof buf, 0); 
			poperror(); 
			if(convM2S(buf, &f, n) == 0){ 
				free(s); 
				error(Emountrpc); 
			} 
			switch(f.type){ 
			case Rsession: 
				memmove(s->schal, f.chal, CHALLEN); 
				memmove(s->authid, f.authid, NAMELEN); 
				memmove(s->authdom, f.authdom, DOMLEN); 
				break; 
			case Rerror: 
				free(s); 
				error(f.ename); 
			default: 
				free(s); 
				error(Emountrpc); 
			} 
1993/0330    
		} 
		s->cid = 0; 
		c->session = s; 
	} 
 
1993/0403/sys/src/9/port/auth.c:172,1811993/0407/sys/src/9/port/auth.c:185,192
1993/0330    
	memmove(tr.hostid, eve, NAMELEN); 
	convTR2M(&tr, (char*)arg[1]); 
 
	poperror(); 
	close(c); 
	free(buf); 
	free(f); 
1993/0407    
	poperror(); 
1993/0330    
	return 0; 
} 
 
1993/0407/sys/src/9/port/auth.c:19,241993/0408/sys/src/9/port/auth.c:19,25 (short | long)
1993/0330    
struct Session 
{ 
	Lock; 
1993/0408    
	Lock	send; 
1993/0330    
	Crypt	*cache;			/* cache of tickets */ 
	char	cchal[CHALLEN];		/* client challenge */ 
	char	schal[CHALLEN];		/* server challenge */ 
1993/0407/sys/src/9/port/auth.c:25,301993/0408/sys/src/9/port/auth.c:26,32
1993/0330    
	char	authid[NAMELEN];	/* server encryption uid */ 
	char	authdom[DOMLEN];	/* server encryption domain */ 
	ulong	cid;			/* challenge id */ 
1993/0408    
	int	valid; 
1993/0330    
}; 
 
struct 
1993/0407/sys/src/9/port/auth.c:109,1291993/0408/sys/src/9/port/auth.c:111,134
1993/0330    
		nexterror(); 
	} 
1993/0407    
 
	/* 
	 *  if two processes get here at the same 
	 *  time with no session exchanged, we have 
	 *  a race. 
	 */ 
1993/0408    
	/* add a session structure to the channel if it has none */ 
	lock(c); 
1993/0330    
	s = c->session; 
	if(s == 0){ 
1993/0407    
		/* 
		 *  no session exchanged yet 
		 */ 
1993/0330    
		s = malloc(sizeof(Session)); 
		if(s == 0) 
1993/0408    
		if(s == 0){ 
			unlock(c); 
1993/0330    
			error(Enomem); 
		memset(s, 0, sizeof(Session)); 
1993/0408    
		} 
		c->session = s; 
	} 
	unlock(c); 
1993/0407    
 
1993/0408    
	/* back off if someone else is doing an fsession */ 
	while(!canlock(&s->send)) 
		sched(); 
 
	if(s->valid == 0){ 
1993/0407    
		/* 
		 *  Exchange a session message with the server. 
		 *  If an error occurs reading or writing, 
1993/0407/sys/src/9/port/auth.c:144,1501993/0408/sys/src/9/port/auth.c:149,155
1993/0407    
				n = (*devtab[c->type].read)(c, buf, sizeof buf, 0); 
			poperror(); 
			if(convM2S(buf, &f, n) == 0){ 
				free(s); 
1993/0408    
				unlock(s); 
1993/0407    
				error(Emountrpc); 
			} 
			switch(f.type){ 
1993/0407/sys/src/9/port/auth.c:154,1681993/0408/sys/src/9/port/auth.c:159,174
1993/0407    
				memmove(s->authdom, f.authdom, DOMLEN); 
				break; 
			case Rerror: 
				free(s); 
1993/0408    
				unlock(s); 
1993/0407    
				error(f.ename); 
			default: 
				free(s); 
1993/0408    
				unlock(s); 
1993/0407    
				error(Emountrpc); 
			} 
1993/0330    
		} 
		c->session = s; 
1993/0408    
		s->valid = 1; 
1993/0330    
	} 
1993/0408    
	unlock(&s->send); 
1993/0330    
 
	/*  
	 *  If server requires no ticket, or user is "none", or a ticket 
1993/0407/sys/src/9/port/auth.c:169,1861993/0408/sys/src/9/port/auth.c:175,196
1993/0330    
	 *  is already cached, zero the request type 
	 */ 
	tr.type = AuthTreq; 
	if(strcmp(u->p->user, "none") == 0 || c->session->authid[0] == 0) 
1993/0408    
	if(strcmp(u->p->user, "none") == 0 || s->authid[0] == 0) 
1993/0330    
		tr.type = 0; 
	else for(cp = s->cache; cp; cp = cp->next) 
		if(strcmp(cp->t.cuid, u->p->user) == 0){ 
			tr.type = 0; 
			break; 
		} 
1993/0408    
	else{ 
		lock(s); 
		for(cp = s->cache; cp; cp = cp->next) 
			if(strcmp(cp->t.cuid, u->p->user) == 0){ 
				tr.type = 0; 
				break; 
			} 
		unlock(s); 
	} 
1993/0330    
 
	/*  create ticket request */ 
	memmove(tr.chal, c->session->schal, CHALLEN); 
	memmove(tr.authid, c->session->authid, NAMELEN); 
	memmove(tr.authdom, c->session->authdom, DOMLEN); 
1993/0408    
	memmove(tr.chal, s->schal, CHALLEN); 
	memmove(tr.authid, s->authid, NAMELEN); 
	memmove(tr.authdom, s->authdom, DOMLEN); 
1993/0330    
	memmove(tr.uid, u->p->user, NAMELEN); 
	memmove(tr.hostid, eve, NAMELEN); 
	convTR2M(&tr, (char*)arg[1]); 
1993/0408/sys/src/9/port/auth.c:149,1551993/0411/sys/src/9/port/auth.c:149,155 (short | long)
1993/0407    
				n = (*devtab[c->type].read)(c, buf, sizeof buf, 0); 
			poperror(); 
			if(convM2S(buf, &f, n) == 0){ 
1993/0408    
				unlock(s); 
1993/0411    
				unlock(&s->send); 
1993/0407    
				error(Emountrpc); 
			} 
			switch(f.type){ 
1993/0408/sys/src/9/port/auth.c:159,1681993/0411/sys/src/9/port/auth.c:159,168
1993/0407    
				memmove(s->authdom, f.authdom, DOMLEN); 
				break; 
			case Rerror: 
1993/0408    
				unlock(s); 
1993/0411    
				unlock(&s->send); 
1993/0407    
				error(f.ename); 
			default: 
1993/0408    
				unlock(s); 
1993/0411    
				unlock(&s->send); 
1993/0407    
				error(Emountrpc); 
			} 
1993/0330    
		} 
1993/0411/sys/src/9/port/auth.c:150,1551993/0427/sys/src/9/port/auth.c:150,156 (short | long)
1993/0407    
			poperror(); 
			if(convM2S(buf, &f, n) == 0){ 
1993/0411    
				unlock(&s->send); 
1993/0427    
print("error converting %d bytes %ux %ux %ux\n", n, buf[0], buf[1], buf[2]); 
1993/0407    
				error(Emountrpc); 
			} 
			switch(f.type){ 
1993/0411/sys/src/9/port/auth.c:163,1681993/0427/sys/src/9/port/auth.c:164,170
1993/0407    
				error(f.ename); 
			default: 
1993/0411    
				unlock(&s->send); 
1993/0427    
print("error using %d bytes %ux %ux %ux\n", n, buf[0], buf[1], buf[2]); 
1993/0407    
				error(Emountrpc); 
			} 
1993/0330    
		} 
1993/0427/sys/src/9/port/auth.c:150,1561993/0428/sys/src/9/port/auth.c:150,155 (short | long)
1993/0407    
			poperror(); 
			if(convM2S(buf, &f, n) == 0){ 
1993/0411    
				unlock(&s->send); 
1993/0427    
print("error converting %d bytes %ux %ux %ux\n", n, buf[0], buf[1], buf[2]); 
1993/0407    
				error(Emountrpc); 
			} 
			switch(f.type){ 
1993/0427/sys/src/9/port/auth.c:164,1701993/0428/sys/src/9/port/auth.c:163,168
1993/0407    
				error(f.ename); 
			default: 
1993/0411    
				unlock(&s->send); 
1993/0427    
print("error using %d bytes %ux %ux %ux\n", n, buf[0], buf[1], buf[2]); 
1993/0407    
				error(Emountrpc); 
			} 
1993/0330    
		} 
1993/0427/sys/src/9/port/auth.c:363,3701993/0428/sys/src/9/port/auth.c:361,368
1993/0330    
 * 
 *  The protocol is 
 *	1) read ticket request from #c/authenticate 
 *	2) write ticket to #c/authenticate. if it matchs the challenge the 
 *	  user is changed to the suid field of the ticket 
1993/0428    
 *	2) write ticket+authenticator to #c/authenticate. if it matches 
 *	  the challenge the user is changed to the suid field of the ticket 
1993/0330    
 *	3) read authenticator (to confirm this is the server advertised) 
 */ 
long 
1993/0427/sys/src/9/port/auth.c:382,3871993/0428/sys/src/9/port/auth.c:380,386
1993/0330    
			error(Ebadarg); 
		c->aux = newcrypt(); 
		cp = c->aux; 
1993/0428    
 
1993/0330    
		memset(&tr, 0, sizeof(tr)); 
		tr.type = AuthTreq; 
		strcpy(tr.hostid, eve); 
1993/0427/sys/src/9/port/auth.c:399,4081993/0428/sys/src/9/port/auth.c:398,410
1993/0330    
		if(n != AUTHENTLEN) 
			error(Ebadarg); 
		cp = c->aux; 
1993/0428    
 
1993/0330    
		cp->a.num = AuthAs; 
		memmove(cp->a.chal, cp->t.chal, CHALLEN); 
		cp->a.id = 0; 
		convA2M(&cp->a, a, cp->t.key); 
1993/0428    
		convA2M(&cp->a, cp->tbuf, cp->t.key); 
		memmove(a, cp->tbuf, AUTHENTLEN); 
 
1993/0330    
		freecrypt(cp); 
		c->aux = 0; 
	} 
1993/0427/sys/src/9/port/auth.c:414,4271993/0428/sys/src/9/port/auth.c:416,437
1993/0330    
{ 
	Crypt *cp; 
 
	if(n != TICKETLEN) 
1993/0428    
	if(n != TICKETLEN+AUTHENTLEN) 
1993/0330    
		error(Ebadarg); 
	if(c->aux == 0) 
		error(Ebadarg); 
	cp = c->aux; 
	convM2T(a, &cp->t, evekey); 
1993/0428    
 
	memmove(cp->tbuf, a, TICKETLEN); 
	convM2T(cp->tbuf, &cp->t, evekey); 
1993/0330    
	if(cp->t.num != AuthTs || memcmp(cp->a.chal, cp->t.chal, CHALLEN)) 
		error(Eperm); 
1993/0428    
 
	memmove(cp->tbuf, a+TICKETLEN, AUTHENTLEN); 
	convM2A(cp->tbuf, &cp->a, cp->t.key); 
	if(cp->a.num != AuthAc || memcmp(cp->a.chal, cp->t.chal, CHALLEN)) 
		error(Eperm); 
 
1993/0330    
	memmove(u->p->user, cp->t.suid, NAMELEN); 
	return n; 
} 
1993/0427/sys/src/9/port/auth.c:441,4541993/0428/sys/src/9/port/auth.c:451,514
1993/0330    
	if(c->aux == 0) 
		c->aux = newcrypt(); 
	cp = c->aux; 
	convM2T(a, &cp->t, evekey); 
1993/0428    
 
	memmove(cp->tbuf, a, TICKETLEN); 
	convM2T(cp->tbuf, &cp->t, evekey); 
1993/0402    
	if(cp->t.num != AuthTc) 
1993/0330    
		error(Ebadarg); 
1993/0402    
	if(strcmp(u->p->user, cp->t.cuid)) 
		error(cp->t.cuid); 
1993/0330    
	convM2A(a+TICKETLEN, &cp->a, cp->t.key); 
1993/0428    
 
	memmove(cp->tbuf, a+TICKETLEN, AUTHENTLEN); 
	convM2A(cp->tbuf, &cp->a, cp->t.key); 
1993/0330    
	if(cp->a.num != AuthAs || memcmp(cp->t.chal, cp->a.chal, CHALLEN)) 
		error(Eperm); 
1993/0428    
 
	return n; 
} 
 
/* 
 *  called by devcons() for #c/authenticator 
 * 
 *  a read after a write of a ticket returns an authenticator 
 *  for that ticket. 
 */ 
long 
authentwrite(Chan *c, char *a, int n) 
{ 
	Crypt *cp; 
 
	if(n != TICKETLEN) 
		error(Ebadarg); 
	if(c->aux == 0) 
		c->aux = newcrypt(); 
	cp = c->aux; 
 
	memmove(cp->tbuf, a, TICKETLEN); 
	convM2T(cp->tbuf, &cp->t, evekey); 
	if(cp->t.num != AuthTc || strcmp(cp->t.cuid, u->p->user)){ 
		freecrypt(cp); 
		c->aux = 0; 
		error(Ebadarg); 
	} 
 
	return n; 
} 
long 
authentread(Chan *c, char *a, int n) 
{ 
	Crypt *cp; 
 
	cp = c->aux; 
	if(cp == 0) 
		error("authenticator read must follow a write"); 
 
	cp->a.num = AuthAc; 
	memmove(cp->a.chal, cp->t.chal, CHALLEN); 
	cp->a.id = 0; 
	convA2M(&cp->a, cp->tbuf, cp->t.key); 
	memmove(a, cp->tbuf, AUTHENTLEN); 
 
1993/0330    
	return n; 
} 
 
1993/0428/sys/src/9/port/auth.c:15,251993/0501/sys/src/9/port/auth.c:15,23 (short | long)
1993/0330    
	char		tbuf[TICKETLEN];	/* remote ticket */ 
}; 
 
typedef struct Session	Session; 
struct Session 
{ 
	Lock; 
1993/0408    
	Lock	send; 
1993/0330    
	Crypt	*cache;			/* cache of tickets */ 
	char	cchal[CHALLEN];		/* client challenge */ 
	char	schal[CHALLEN];		/* server challenge */ 
1993/0428/sys/src/9/port/auth.c:26,321993/0501/sys/src/9/port/auth.c:24,29
1993/0330    
	char	authid[NAMELEN];	/* server encryption uid */ 
	char	authdom[DOMLEN];	/* server encryption domain */ 
	ulong	cid;			/* challenge id */ 
1993/0408    
	int	valid; 
1993/0330    
}; 
 
struct 
1993/0428/sys/src/9/port/auth.c:45,511993/0501/sys/src/9/port/auth.c:42,48
1993/0330    
int 
iseve(void) 
{ 
	return strcmp(eve, u->p->user) == 0; 
1993/0501    
	return strcmp(eve, up->user) == 0; 
1993/0330    
} 
 
/* 
1993/0428/sys/src/9/port/auth.c:111,1341993/0501/sys/src/9/port/auth.c:108,128
1993/0330    
		nexterror(); 
	} 
1993/0407    
 
1993/0408    
	/* add a session structure to the channel if it has none */ 
	lock(c); 
1993/0501    
	/* 
	 *  if two processes get here at the same 
	 *  time with no session exchanged, we have 
	 *  a race. 
	 */ 
1993/0330    
	s = c->session; 
	if(s == 0){ 
1993/0501    
		/* 
		 *  no session exchanged yet 
		 */ 
1993/0330    
		s = malloc(sizeof(Session)); 
1993/0408    
		if(s == 0){ 
			unlock(c); 
1993/0501    
		if(s == 0) 
1993/0330    
			error(Enomem); 
1993/0408    
		} 
		c->session = s; 
	} 
	unlock(c); 
1993/0501    
		memset(s, 0, sizeof(Session)); 
1993/0407    
 
1993/0408    
	/* back off if someone else is doing an fsession */ 
	while(!canlock(&s->send)) 
		sched(); 
                 
	if(s->valid == 0){ 
1993/0407    
		/* 
		 *  Exchange a session message with the server. 
		 *  If an error occurs reading or writing, 
1993/0428/sys/src/9/port/auth.c:144,1551993/0501/sys/src/9/port/auth.c:138,150
1993/0407    
			n = convS2M(&f, buf); 
			if((*devtab[c->type].write)(c, buf, n, 0) != n) 
				error(Emountrpc); 
1993/0501    
		dkhack: 
1993/0407    
			n = (*devtab[c->type].read)(c, buf, sizeof buf, 0); 
			if(n == 2 && buf[0] == 'O' && buf[1] == 'K') 
				n = (*devtab[c->type].read)(c, buf, sizeof buf, 0); 
1993/0501    
				goto dkhack; 
1993/0407    
			poperror(); 
			if(convM2S(buf, &f, n) == 0){ 
1993/0411    
				unlock(&s->send); 
1993/0501    
				free(s); 
1993/0407    
				error(Emountrpc); 
			} 
			switch(f.type){ 
1993/0428/sys/src/9/port/auth.c:159,1741993/0501/sys/src/9/port/auth.c:154,168
1993/0407    
				memmove(s->authdom, f.authdom, DOMLEN); 
				break; 
			case Rerror: 
1993/0411    
				unlock(&s->send); 
1993/0501    
				free(s); 
1993/0407    
				error(f.ename); 
			default: 
1993/0411    
				unlock(&s->send); 
1993/0501    
				free(s); 
1993/0407    
				error(Emountrpc); 
			} 
1993/0330    
		} 
1993/0408    
		s->valid = 1; 
1993/0501    
		c->session = s; 
1993/0330    
	} 
1993/0408    
	unlock(&s->send); 
1993/0330    
 
	/*  
	 *  If server requires no ticket, or user is "none", or a ticket 
1993/0428/sys/src/9/port/auth.c:175,1971993/0501/sys/src/9/port/auth.c:169,187
1993/0330    
	 *  is already cached, zero the request type 
	 */ 
	tr.type = AuthTreq; 
1993/0408    
	if(strcmp(u->p->user, "none") == 0 || s->authid[0] == 0) 
1993/0501    
	if(strcmp(up->user, "none") == 0 || c->session->authid[0] == 0) 
1993/0330    
		tr.type = 0; 
1993/0408    
	else{ 
		lock(s); 
		for(cp = s->cache; cp; cp = cp->next) 
			if(strcmp(cp->t.cuid, u->p->user) == 0){ 
				tr.type = 0; 
				break; 
			} 
		unlock(s); 
	} 
1993/0501    
	else for(cp = s->cache; cp; cp = cp->next) 
		if(strcmp(cp->t.cuid, up->user) == 0){ 
			tr.type = 0; 
			break; 
		} 
1993/0330    
 
	/*  create ticket request */ 
1993/0408    
	memmove(tr.chal, s->schal, CHALLEN); 
	memmove(tr.authid, s->authid, NAMELEN); 
	memmove(tr.authdom, s->authdom, DOMLEN); 
1993/0330    
	memmove(tr.uid, u->p->user, NAMELEN); 
1993/0501    
	memmove(tr.chal, c->session->schal, CHALLEN); 
	memmove(tr.authid, c->session->authid, NAMELEN); 
	memmove(tr.authdom, c->session->authdom, DOMLEN); 
	memmove(tr.uid, up->user, NAMELEN); 
1993/0330    
	memmove(tr.hostid, eve, NAMELEN); 
	convTR2M(&tr, (char*)arg[1]); 
 
1993/0428/sys/src/9/port/auth.c:229,2351993/0501/sys/src/9/port/auth.c:219,225
1993/0330    
	convM2T(tbuf, &cp->t, evekey); 
	if(cp->t.num != AuthTc) 
		error("bad AuthTc in ticket"); 
	if(strncmp(u->p->user, cp->t.cuid, NAMELEN) != 0) 
1993/0501    
	if(strncmp(up->user, cp->t.cuid, NAMELEN) != 0) 
1993/0330    
		error("bad uid in ticket"); 
	if(memcmp(cp->t.chal, s->schal, CHALLEN) != 0) 
		error("bad chal in ticket"); 
1993/0428/sys/src/9/port/auth.c:239,2451993/0501/sys/src/9/port/auth.c:229,235
1993/0330    
	lock(s); 
	l = &s->cache; 
	for(ncp = s->cache; ncp; ncp = *l){ 
		if(strcmp(ncp->t.cuid, u->p->user) == 0){ 
1993/0501    
		if(strcmp(ncp->t.cuid, up->user) == 0){ 
1993/0330    
			*l = ncp->next; 
			freecrypt(ncp); 
			break; 
1993/0428/sys/src/9/port/auth.c:278,2841993/0501/sys/src/9/port/auth.c:268,274
1993/0330    
	ulong id, dofree; 
 
	/* no authentication if user is "none" or if no ticket required by remote */ 
	if(s == 0 || s->authid[0] == 0 || strcmp(u->p->user, "none") == 0){ 
1993/0501    
	if(s == 0 || s->authid[0] == 0 || strcmp(up->user, "none") == 0){ 
1993/0330    
		memset(f->ticket, 0, TICKETLEN); 
		memset(f->auth, 0, AUTHENTLEN); 
		return 0; 
1993/0428/sys/src/9/port/auth.c:288,2941993/0501/sys/src/9/port/auth.c:278,284
1993/0330    
	dofree = 0; 
1993/0403    
	lock(s); 
1993/0330    
	for(cp = s->cache; cp; cp = cp->next) 
		if(strcmp(cp->t.cuid, u->p->user) == 0) 
1993/0501    
		if(strcmp(cp->t.cuid, up->user) == 0) 
1993/0330    
			break; 
1993/0403    
 
	id = s->cid++; 
1993/0428/sys/src/9/port/auth.c:302,3091993/0501/sys/src/9/port/auth.c:292,299
1993/0330    
		cp = newcrypt(); 
		cp->t.num = AuthTs; 
		memmove(cp->t.chal, s->schal, CHALLEN); 
		memmove(cp->t.cuid, u->p->user, NAMELEN); 
		memmove(cp->t.suid, u->p->user, NAMELEN); 
1993/0501    
		memmove(cp->t.cuid, up->user, NAMELEN); 
		memmove(cp->t.suid, up->user, NAMELEN); 
1993/0330    
		memmove(cp->t.key, evekey, DESKEYLEN); 
		convT2M(&cp->t, f->ticket, evekey); 
		dofree = 1; 
1993/0428/sys/src/9/port/auth.c:333,3441993/0501/sys/src/9/port/auth.c:323,334
1993/0330    
 
1993/0403    
	lock(s); 
1993/0330    
	for(cp = s->cache; cp; cp = cp->next) 
		if(strcmp(cp->t.cuid, u->p->user) == 0) 
1993/0501    
		if(strcmp(cp->t.cuid, up->user) == 0) 
1993/0330    
			break; 
1993/0403    
	unlock(s); 
1993/0330    
 
	/* we're getting around authentication */ 
	if(s == 0 || cp == 0 || s->authid[0] == 0 || strcmp(u->p->user, "none") == 0) 
1993/0501    
	if(s == 0 || cp == 0 || s->authid[0] == 0 || strcmp(up->user, "none") == 0) 
1993/0330    
		return; 
 
	convM2A(f->rauth, &cp->a, cp->t.key); 
1993/0428/sys/src/9/port/auth.c:361,3681993/0501/sys/src/9/port/auth.c:351,358
1993/0330    
 * 
 *  The protocol is 
 *	1) read ticket request from #c/authenticate 
1993/0428    
 *	2) write ticket+authenticator to #c/authenticate. if it matches 
 *	  the challenge the user is changed to the suid field of the ticket 
1993/0501    
 *	2) write ticket to #c/authenticate. if it matchs the challenge the 
 *	  user is changed to the suid field of the ticket 
1993/0330    
 *	3) read authenticator (to confirm this is the server advertised) 
 */ 
long 
1993/0428/sys/src/9/port/auth.c:380,3921993/0501/sys/src/9/port/auth.c:370,381
1993/0330    
			error(Ebadarg); 
		c->aux = newcrypt(); 
		cp = c->aux; 
1993/0428    
                 
1993/0330    
		memset(&tr, 0, sizeof(tr)); 
		tr.type = AuthTreq; 
		strcpy(tr.hostid, eve); 
		strcpy(tr.authid, eve); 
		strcpy(tr.authdom, hostdomain); 
		strcpy(tr.uid, u->p->user); 
1993/0501    
		strcpy(tr.uid, up->user); 
1993/0330    
		for(i = 0; i < CHALLEN; i++) 
			tr.chal[i] = nrand(256); 
		memmove(cp->a.chal, tr.chal, CHALLEN); 
1993/0428/sys/src/9/port/auth.c:398,4101993/0501/sys/src/9/port/auth.c:387,396
1993/0330    
		if(n != AUTHENTLEN) 
			error(Ebadarg); 
		cp = c->aux; 
1993/0428    
                 
1993/0330    
		cp->a.num = AuthAs; 
		memmove(cp->a.chal, cp->t.chal, CHALLEN); 
		cp->a.id = 0; 
1993/0428    
		convA2M(&cp->a, cp->tbuf, cp->t.key); 
		memmove(a, cp->tbuf, AUTHENTLEN); 
                 
1993/0501    
		convA2M(&cp->a, a, cp->t.key); 
1993/0330    
		freecrypt(cp); 
		c->aux = 0; 
	} 
1993/0428/sys/src/9/port/auth.c:416,4381993/0501/sys/src/9/port/auth.c:402,416
1993/0330    
{ 
	Crypt *cp; 
 
1993/0428    
	if(n != TICKETLEN+AUTHENTLEN) 
1993/0501    
	if(n != TICKETLEN) 
1993/0330    
		error(Ebadarg); 
	if(c->aux == 0) 
		error(Ebadarg); 
	cp = c->aux; 
1993/0428    
                 
	memmove(cp->tbuf, a, TICKETLEN); 
	convM2T(cp->tbuf, &cp->t, evekey); 
1993/0501    
	convM2T(a, &cp->t, evekey); 
1993/0330    
	if(cp->t.num != AuthTs || memcmp(cp->a.chal, cp->t.chal, CHALLEN)) 
		error(Eperm); 
1993/0428    
                 
	memmove(cp->tbuf, a+TICKETLEN, AUTHENTLEN); 
	convM2A(cp->tbuf, &cp->a, cp->t.key); 
	if(cp->a.num != AuthAc || memcmp(cp->a.chal, cp->t.chal, CHALLEN)) 
		error(Eperm); 
                 
1993/0330    
	memmove(u->p->user, cp->t.suid, NAMELEN); 
1993/0501    
	memmove(up->user, cp->t.suid, NAMELEN); 
1993/0330    
	return n; 
} 
 
1993/0428/sys/src/9/port/auth.c:451,5171993/0501/sys/src/9/port/auth.c:429,445
1993/0330    
	if(c->aux == 0) 
		c->aux = newcrypt(); 
	cp = c->aux; 
1993/0428    
                 
	memmove(cp->tbuf, a, TICKETLEN); 
	convM2T(cp->tbuf, &cp->t, evekey); 
1993/0501    
	convM2T(a, &cp->t, evekey); 
1993/0402    
	if(cp->t.num != AuthTc) 
1993/0330    
		error(Ebadarg); 
1993/0402    
	if(strcmp(u->p->user, cp->t.cuid)) 
1993/0501    
	if(strcmp(up->user, cp->t.cuid)) 
1993/0402    
		error(cp->t.cuid); 
1993/0428    
                 
	memmove(cp->tbuf, a+TICKETLEN, AUTHENTLEN); 
	convM2A(cp->tbuf, &cp->a, cp->t.key); 
1993/0501    
	convM2A(a+TICKETLEN, &cp->a, cp->t.key); 
1993/0330    
	if(cp->a.num != AuthAs || memcmp(cp->t.chal, cp->a.chal, CHALLEN)) 
		error(Eperm); 
1993/0428    
                 
	return n; 
} 
 
/* 
 *  called by devcons() for #c/authenticator 
 * 
 *  a read after a write of a ticket returns an authenticator 
 *  for that ticket. 
 */ 
long 
authentwrite(Chan *c, char *a, int n) 
{ 
	Crypt *cp; 
                 
	if(n != TICKETLEN) 
		error(Ebadarg); 
	if(c->aux == 0) 
		c->aux = newcrypt(); 
	cp = c->aux; 
                 
	memmove(cp->tbuf, a, TICKETLEN); 
	convM2T(cp->tbuf, &cp->t, evekey); 
	if(cp->t.num != AuthTc || strcmp(cp->t.cuid, u->p->user)){ 
		freecrypt(cp); 
		c->aux = 0; 
		error(Ebadarg); 
	} 
                 
	return n; 
} 
long 
authentread(Chan *c, char *a, int n) 
{ 
	Crypt *cp; 
                 
	cp = c->aux; 
	if(cp == 0) 
		error("authenticator read must follow a write"); 
                 
	cp->a.num = AuthAc; 
	memmove(cp->a.chal, cp->t.chal, CHALLEN); 
	cp->a.id = 0; 
	convA2M(&cp->a, cp->tbuf, cp->t.key); 
	memmove(a, cp->tbuf, AUTHENTLEN); 
                 
1993/0330    
	return n; 
} 
                 
void 
authclose(Chan *c) 
{ 
1993/0428/sys/src/9/port/auth.c:557,5641993/0501/sys/src/9/port/auth.c:485,492
1993/0330    
		error(Ebadarg); 
	if(strcmp(a, "none") != 0) 
		error(Eperm); 
	memset(u->p->user, 0, NAMELEN); 
	strcpy(u->p->user, "none"); 
1993/0501    
	memset(up->user, 0, NAMELEN); 
	strcpy(up->user, "none"); 
1993/0330    
	return n; 
} 
 
1993/0428/sys/src/9/port/auth.c:581,5871993/0501/sys/src/9/port/auth.c:509,515
1993/0330    
	if(buf[0] == 0) 
		error(Ebadarg); 
	memmove(eve, buf, NAMELEN); 
	memmove(u->p->user, buf, NAMELEN); 
1993/0501    
	memmove(up->user, buf, NAMELEN); 
1993/0330    
	return n; 
} 
 
1993/0501/sys/src/9/port/auth.c:15,231993/0731/sys/src/9/port/auth.c:15,25 (short | long)
1993/0330    
	char		tbuf[TICKETLEN];	/* remote ticket */ 
}; 
 
1993/0731    
typedef struct Session	Session; 
1993/0330    
struct Session 
{ 
	Lock; 
1993/0731    
	Lock	send; 
1993/0330    
	Crypt	*cache;			/* cache of tickets */ 
	char	cchal[CHALLEN];		/* client challenge */ 
	char	schal[CHALLEN];		/* server challenge */ 
1993/0501/sys/src/9/port/auth.c:24,291993/0731/sys/src/9/port/auth.c:26,32
1993/0330    
	char	authid[NAMELEN];	/* server encryption uid */ 
	char	authdom[DOMLEN];	/* server encryption domain */ 
	ulong	cid;			/* challenge id */ 
1993/0731    
	int	valid; 
1993/0330    
}; 
 
struct 
1993/0501/sys/src/9/port/auth.c:108,1281993/0731/sys/src/9/port/auth.c:111,134
1993/0330    
		nexterror(); 
	} 
1993/0407    
 
1993/0501    
	/* 
	 *  if two processes get here at the same 
	 *  time with no session exchanged, we have 
	 *  a race. 
	 */ 
1993/0731    
	/* add a session structure to the channel if it has none */ 
	lock(c); 
1993/0330    
	s = c->session; 
	if(s == 0){ 
1993/0501    
		/* 
		 *  no session exchanged yet 
		 */ 
1993/0330    
		s = malloc(sizeof(Session)); 
1993/0501    
		if(s == 0) 
1993/0731    
		if(s == 0){ 
			unlock(c); 
1993/0330    
			error(Enomem); 
1993/0501    
		memset(s, 0, sizeof(Session)); 
1993/0731    
		} 
		c->session = s; 
	} 
	unlock(c); 
1993/0407    
 
1993/0731    
	/* back off if someone else is doing an fsession */ 
	while(!canlock(&s->send)) 
		sched(); 
 
	if(s->valid == 0){ 
1993/0407    
		/* 
		 *  Exchange a session message with the server. 
		 *  If an error occurs reading or writing, 
1993/0501/sys/src/9/port/auth.c:138,1501993/0731/sys/src/9/port/auth.c:144,155
1993/0407    
			n = convS2M(&f, buf); 
			if((*devtab[c->type].write)(c, buf, n, 0) != n) 
				error(Emountrpc); 
1993/0501    
		dkhack: 
1993/0407    
			n = (*devtab[c->type].read)(c, buf, sizeof buf, 0); 
			if(n == 2 && buf[0] == 'O' && buf[1] == 'K') 
1993/0501    
				goto dkhack; 
1993/0731    
				n = (*devtab[c->type].read)(c, buf, sizeof buf, 0); 
1993/0407    
			poperror(); 
			if(convM2S(buf, &f, n) == 0){ 
1993/0501    
				free(s); 
1993/0731    
				unlock(&s->send); 
1993/0407    
				error(Emountrpc); 
			} 
			switch(f.type){ 
1993/0501/sys/src/9/port/auth.c:154,1681993/0731/sys/src/9/port/auth.c:159,174
1993/0407    
				memmove(s->authdom, f.authdom, DOMLEN); 
				break; 
			case Rerror: 
1993/0501    
				free(s); 
1993/0731    
				unlock(&s->send); 
1993/0407    
				error(f.ename); 
			default: 
1993/0501    
				free(s); 
1993/0731    
				unlock(&s->send); 
1993/0407    
				error(Emountrpc); 
			} 
1993/0330    
		} 
1993/0501    
		c->session = s; 
1993/0731    
		s->valid = 1; 
1993/0330    
	} 
1993/0731    
	unlock(&s->send); 
1993/0330    
 
	/*  
	 *  If server requires no ticket, or user is "none", or a ticket 
1993/0501/sys/src/9/port/auth.c:169,1861993/0731/sys/src/9/port/auth.c:175,196
1993/0330    
	 *  is already cached, zero the request type 
	 */ 
	tr.type = AuthTreq; 
1993/0501    
	if(strcmp(up->user, "none") == 0 || c->session->authid[0] == 0) 
1993/0731    
	if(strcmp(up->user, "none") == 0 || s->authid[0] == 0) 
1993/0330    
		tr.type = 0; 
1993/0501    
	else for(cp = s->cache; cp; cp = cp->next) 
		if(strcmp(cp->t.cuid, up->user) == 0){ 
			tr.type = 0; 
			break; 
		} 
1993/0731    
	else{ 
		lock(s); 
		for(cp = s->cache; cp; cp = cp->next) 
			if(strcmp(cp->t.cuid, up->user) == 0){ 
				tr.type = 0; 
				break; 
			} 
		unlock(s); 
	} 
1993/0330    
 
	/*  create ticket request */ 
1993/0501    
	memmove(tr.chal, c->session->schal, CHALLEN); 
	memmove(tr.authid, c->session->authid, NAMELEN); 
	memmove(tr.authdom, c->session->authdom, DOMLEN); 
1993/0731    
	memmove(tr.chal, s->schal, CHALLEN); 
	memmove(tr.authid, s->authid, NAMELEN); 
	memmove(tr.authdom, s->authdom, DOMLEN); 
1993/0501    
	memmove(tr.uid, up->user, NAMELEN); 
1993/0330    
	memmove(tr.hostid, eve, NAMELEN); 
	convTR2M(&tr, (char*)arg[1]); 
1993/0501/sys/src/9/port/auth.c:351,3581993/0731/sys/src/9/port/auth.c:361,368
1993/0330    
 * 
 *  The protocol is 
 *	1) read ticket request from #c/authenticate 
1993/0501    
 *	2) write ticket to #c/authenticate. if it matchs the challenge the 
 *	  user is changed to the suid field of the ticket 
1993/0731    
 *	2) write ticket+authenticator to #c/authenticate. if it matches 
 *	  the challenge the user is changed to the suid field of the ticket 
1993/0330    
 *	3) read authenticator (to confirm this is the server advertised) 
 */ 
long 
1993/0501/sys/src/9/port/auth.c:370,3751993/0731/sys/src/9/port/auth.c:380,386
1993/0330    
			error(Ebadarg); 
		c->aux = newcrypt(); 
		cp = c->aux; 
1993/0731    
 
1993/0330    
		memset(&tr, 0, sizeof(tr)); 
		tr.type = AuthTreq; 
		strcpy(tr.hostid, eve); 
1993/0501/sys/src/9/port/auth.c:387,3961993/0731/sys/src/9/port/auth.c:398,410
1993/0330    
		if(n != AUTHENTLEN) 
			error(Ebadarg); 
		cp = c->aux; 
1993/0731    
 
1993/0330    
		cp->a.num = AuthAs; 
		memmove(cp->a.chal, cp->t.chal, CHALLEN); 
		cp->a.id = 0; 
1993/0501    
		convA2M(&cp->a, a, cp->t.key); 
1993/0731    
		convA2M(&cp->a, cp->tbuf, cp->t.key); 
		memmove(a, cp->tbuf, AUTHENTLEN); 
 
1993/0330    
		freecrypt(cp); 
		c->aux = 0; 
	} 
1993/0501/sys/src/9/port/auth.c:402,4151993/0731/sys/src/9/port/auth.c:416,437
1993/0330    
{ 
	Crypt *cp; 
 
1993/0501    
	if(n != TICKETLEN) 
1993/0731    
	if(n != TICKETLEN+AUTHENTLEN) 
1993/0330    
		error(Ebadarg); 
	if(c->aux == 0) 
		error(Ebadarg); 
	cp = c->aux; 
1993/0501    
	convM2T(a, &cp->t, evekey); 
1993/0731    
 
	memmove(cp->tbuf, a, TICKETLEN); 
	convM2T(cp->tbuf, &cp->t, evekey); 
1993/0330    
	if(cp->t.num != AuthTs || memcmp(cp->a.chal, cp->t.chal, CHALLEN)) 
		error(Eperm); 
1993/0731    
 
	memmove(cp->tbuf, a+TICKETLEN, AUTHENTLEN); 
	convM2A(cp->tbuf, &cp->a, cp->t.key); 
	if(cp->a.num != AuthAc || memcmp(cp->a.chal, cp->t.chal, CHALLEN)) 
		error(Eperm); 
 
1993/0501    
	memmove(up->user, cp->t.suid, NAMELEN); 
1993/0330    
	return n; 
} 
1993/0501/sys/src/9/port/auth.c:417,4421993/0731/sys/src/9/port/auth.c:439,529
1993/0330    
/* 
 *  called by devcons() for #c/authcheck 
 * 
 *  a write of a ticket+authenticator succeeds if they match 
1993/0731    
 *  a write of a ticket+authenticator [+challenge+id] succeeds if they match 
1993/0330    
 */ 
long 
authcheck(Chan *c, char *a, int n) 
{ 
	Crypt *cp; 
1993/0731    
	char *chal; 
	ulong id; 
1993/0330    
 
	if(n != TICKETLEN+AUTHENTLEN) 
1993/0731    
	if(n != TICKETLEN+AUTHENTLEN && n != TICKETLEN+AUTHENTLEN+CHALLEN+4) 
1993/0330    
		error(Ebadarg); 
	if(c->aux == 0) 
		c->aux = newcrypt(); 
	cp = c->aux; 
1993/0501    
	convM2T(a, &cp->t, evekey); 
1993/0731    
 
	memmove(cp->tbuf, a, TICKETLEN); 
	convM2T(cp->tbuf, &cp->t, evekey); 
1993/0402    
	if(cp->t.num != AuthTc) 
1993/0330    
		error(Ebadarg); 
1993/0501    
	if(strcmp(up->user, cp->t.cuid)) 
1993/0402    
		error(cp->t.cuid); 
1993/0501    
	convM2A(a+TICKETLEN, &cp->a, cp->t.key); 
1993/0330    
	if(cp->a.num != AuthAs || memcmp(cp->t.chal, cp->a.chal, CHALLEN)) 
1993/0731    
 
	memmove(cp->tbuf, a+TICKETLEN, AUTHENTLEN); 
	convM2A(cp->tbuf, &cp->a, cp->t.key); 
	if(n == TICKETLEN+AUTHENTLEN+CHALLEN+4){ 
		uchar *p = (uchar *)&a[TICKETLEN+AUTHENTLEN+CHALLEN]; 
		id = p[0] | (p[1]<<8) | (p[2]<<16) | (p[3]<<24); 
		chal = &a[TICKETLEN+AUTHENTLEN]; 
	}else{ 
		id = 0; 
		chal = cp->t.chal; 
	} 
	if(cp->a.num != AuthAs || memcmp(chal, cp->a.chal, CHALLEN) || cp->a.id != id) 
1993/0330    
		error(Eperm); 
1993/0731    
 
	return n; 
} 
 
/* 
 *  called by devcons() for #c/authenticator 
 * 
 *  a read after a write of a ticket (or ticket+id) returns an authenticator 
 *  for that ticket. 
 */ 
long 
authentwrite(Chan *c, char *a, int n) 
{ 
	Crypt *cp; 
 
	if(n != TICKETLEN && n != TICKETLEN+4) 
		error(Ebadarg); 
	if(c->aux == 0) 
		c->aux = newcrypt(); 
	cp = c->aux; 
 
	memmove(cp->tbuf, a, TICKETLEN); 
	convM2T(cp->tbuf, &cp->t, evekey); 
	if(cp->t.num != AuthTc || strcmp(cp->t.cuid, up->user)){ 
		freecrypt(cp); 
		c->aux = 0; 
		error(Ebadarg); 
	} 
	if(n == TICKETLEN+4){ 
		uchar *p = (uchar *)&a[TICKETLEN]; 
		cp->a.id = p[0] | (p[1]<<8) | (p[2]<<16) | (p[3]<<24); 
	}else 
		cp->a.id = 0; 
 
	return n; 
} 
 
long 
authentread(Chan *c, char *a, int n) 
{ 
	Crypt *cp; 
 
	cp = c->aux; 
	if(cp == 0) 
		error("authenticator read must follow a write"); 
 
	cp->a.num = AuthAc; 
	memmove(cp->a.chal, cp->t.chal, CHALLEN); 
	convA2M(&cp->a, cp->tbuf, cp->t.key); 
	memmove(a, cp->tbuf, AUTHENTLEN); 
 
1993/0428    
	return n; 
} 
 
1993/0731/sys/src/9/port/auth.c:3,91994/0624/sys/src/9/port/auth.c:3,8 (short | long)
1993/0330    
#include	"mem.h" 
#include	"dat.h" 
#include	"fns.h" 
#include	"io.h" 
#include	"../port/error.h" 
 
typedef struct Crypt	Crypt; 
1994/0624/sys/src/9/port/auth.c:573,5781994/0915/sys/src/9/port/auth.c:573,579 (short | long)
1993/0330    
		error(Eperm); 
1993/0501    
	memset(up->user, 0, NAMELEN); 
	strcpy(up->user, "none"); 
1994/0915    
	up->basepri = PriNormal; 
1993/0330    
	return n; 
} 
 
1994/0624/sys/src/9/port/auth.c:596,6011994/0915/sys/src/9/port/auth.c:597,603
1993/0330    
		error(Ebadarg); 
	memmove(eve, buf, NAMELEN); 
1993/0501    
	memmove(up->user, buf, NAMELEN); 
1994/0915    
	up->basepri = PriNormal; 
1993/0330    
	return n; 
} 
 
1994/0915/sys/src/9/port/auth.c:34,401994/1027/sys/src/9/port/auth.c:34,40 (short | long)
1993/0330    
	Crypt		*free; 
} cryptalloc; 
 
char	eve[NAMELEN] = "bootes"; 
1994/1027    
char	eve[NAMELEN]; 
1993/0330    
char	evekey[DESKEYLEN]; 
char	hostdomain[DOMLEN]; 
 
1994/0915/sys/src/9/port/auth.c:595,6001994/1027/sys/src/9/port/auth.c:595,601
1993/0330    
	strncpy(buf, a, n); 
	if(buf[0] == 0) 
		error(Ebadarg); 
1994/1027    
	renameuser(eve, buf); 
1993/0330    
	memmove(eve, buf, NAMELEN); 
1993/0501    
	memmove(up->user, buf, NAMELEN); 
1994/0915    
	up->basepri = PriNormal; 
1994/1027/sys/src/9/port/auth.c:573,5791995/0102/sys/src/9/port/auth.c:573,579 (short | long)
1993/0330    
		error(Eperm); 
1993/0501    
	memset(up->user, 0, NAMELEN); 
	strcpy(up->user, "none"); 
1994/0915    
	up->basepri = PriNormal; 
1995/0102    
	up->nice = NiceNormal; 
1993/0330    
	return n; 
} 
 
1994/1027/sys/src/9/port/auth.c:598,6041995/0102/sys/src/9/port/auth.c:598,604
1994/1027    
	renameuser(eve, buf); 
1993/0330    
	memmove(eve, buf, NAMELEN); 
1993/0501    
	memmove(up->user, buf, NAMELEN); 
1994/0915    
	up->basepri = PriNormal; 
1995/0102    
	up->nice = NiceNormal; 
1993/0330    
	return n; 
} 
 
1995/0102/sys/src/9/port/auth.c:124,1311995/0106/sys/src/9/port/auth.c:124,133 (short | long)
1993/0731    
	unlock(c); 
1993/0407    
 
1993/0731    
	/* back off if someone else is doing an fsession */ 
	while(!canlock(&s->send)) 
1995/0106    
	while(!canlock(&s->send)) { 
		up->yield = 1; 
1993/0731    
		sched(); 
1995/0106    
	} 
1993/0731    
 
	if(s->valid == 0){ 
1993/0407    
		/* 
1995/0106/sys/src/9/port/auth.c:124,1331995/0110/sys/src/9/port/auth.c:124,131 (short | long)
1993/0731    
	unlock(c); 
1993/0407    
 
1993/0731    
	/* back off if someone else is doing an fsession */ 
1995/0106    
	while(!canlock(&s->send)) { 
		up->yield = 1; 
1995/0110    
	while(!canlock(&s->send)) 
1993/0731    
		sched(); 
1995/0106    
	} 
1993/0731    
 
	if(s->valid == 0){ 
1993/0407    
		/* 
1995/0106/sys/src/9/port/auth.c:575,5811995/0110/sys/src/9/port/auth.c:573,579
1993/0330    
		error(Eperm); 
1993/0501    
	memset(up->user, 0, NAMELEN); 
	strcpy(up->user, "none"); 
1995/0102    
	up->nice = NiceNormal; 
1995/0110    
	up->basepri = PriNormal; 
1993/0330    
	return n; 
} 
 
1995/0106/sys/src/9/port/auth.c:600,6061995/0110/sys/src/9/port/auth.c:598,604
1994/1027    
	renameuser(eve, buf); 
1993/0330    
	memmove(eve, buf, NAMELEN); 
1993/0501    
	memmove(up->user, buf, NAMELEN); 
1995/0102    
	up->nice = NiceNormal; 
1995/0110    
	up->basepri = PriNormal; 
1993/0330    
	return n; 
} 
 
1995/0110/sys/src/9/port/auth.c:542,5481995/0113/sys/src/9/port/auth.c:542,548 (short | long)
1993/0330    
{ 
	if(n<DESKEYLEN || offset != 0) 
		error(Ebadarg); 
	if(!iseve()) 
1995/0113    
	if(!cpuserver || !iseve()) 
1993/0330    
		error(Eperm); 
	memmove(a, evekey, DESKEYLEN); 
	return DESKEYLEN; 
1995/0113/sys/src/9/port/auth.c:127,1331995/0414/sys/src/9/port/auth.c:127,134 (short | long)
1995/0110    
	while(!canlock(&s->send)) 
1993/0731    
		sched(); 
 
	if(s->valid == 0){ 
1995/0414    
	if(s->valid == 0 && (c->flag & CMSG) == 0){ 
 
1993/0407    
		/* 
		 *  Exchange a session message with the server. 
		 *  If an error occurs reading or writing, 
1995/0414/sys/src/9/port/auth.c:106,1121997/0327/sys/src/9/port/auth.c:106,112 (short | long)
1993/0330    
	validaddr(arg[1], TICKREQLEN, 1); 
	c = fdtochan(arg[0], OWRITE, 0, 1); 
1993/0407    
	if(waserror()){ 
1993/0330    
		close(c); 
1997/0327    
		cclose(c); 
1993/0330    
		nexterror(); 
	} 
1993/0407    
 
1995/0414/sys/src/9/port/auth.c:142,1521997/0327/sys/src/9/port/auth.c:142,152
1993/0407    
			f.type = Tsession; 
			memmove(f.chal, s->cchal, CHALLEN); 
			n = convS2M(&f, buf); 
			if((*devtab[c->type].write)(c, buf, n, 0) != n) 
1997/0327    
			if(devtab[c->type]->write(c, buf, n, 0) != n) 
1993/0407    
				error(Emountrpc); 
			n = (*devtab[c->type].read)(c, buf, sizeof buf, 0); 
1997/0327    
			n = devtab[c->type]->read(c, buf, sizeof buf, 0); 
1993/0407    
			if(n == 2 && buf[0] == 'O' && buf[1] == 'K') 
1993/0731    
				n = (*devtab[c->type].read)(c, buf, sizeof buf, 0); 
1997/0327    
				n = devtab[c->type]->read(c, buf, sizeof buf, 0); 
1993/0407    
			poperror(); 
			if(convM2S(buf, &f, n) == 0){ 
1993/0731    
				unlock(&s->send); 
1995/0414/sys/src/9/port/auth.c:195,2011997/0327/sys/src/9/port/auth.c:195,201
1993/0330    
	memmove(tr.hostid, eve, NAMELEN); 
	convTR2M(&tr, (char*)arg[1]); 
 
	close(c); 
1997/0327    
	cclose(c); 
1993/0407    
	poperror(); 
1993/0330    
	return 0; 
} 
1997/0327/sys/src/9/port/auth.c:478,4831998/0404/sys/src/9/port/auth.c:478,501 (short | long)
Add authcheckread.
rsc Fri Mar 4 12:44:25 2005
1993/0731    
} 
 
/* 
1998/0404    
 *  reading authcheck after writing into it yields the 
 *  nonce key 
 */ 
long 
authcheckread(Chan *c, char *a, int n) 
{ 
	Crypt *cp; 
 
	cp = c->aux; 
	if(cp == nil) 
		error(Ebadarg); 
	if(n < TICKETLEN)) 
		error(Ebadarg); 
	convT2M(&cp->t, a, nil); 
	return sizeof(cp->t); 
} 
 
/* 
1993/0731    
 *  called by devcons() for #c/authenticator 
 * 
 *  a read after a write of a ticket (or ticket+id) returns an authenticator 
1997/0327/sys/src/9/port/auth.c:522,5281998/0404/sys/src/9/port/auth.c:540,550
1993/0731    
	cp->a.num = AuthAc; 
	memmove(cp->a.chal, cp->t.chal, CHALLEN); 
	convA2M(&cp->a, cp->tbuf, cp->t.key); 
	memmove(a, cp->tbuf, AUTHENTLEN); 
1998/0404    
 
	if(n >= AUTHENTLEN) 
		memmove(a, cp->tbuf, AUTHENTLEN); 
	if(n >= AUTHENTLEN + TICKETLEN) 
		convT2M(&cp->t, a+AUTHENTLEN, nil); 
1993/0731    
 
1993/0428    
	return n; 
} 
1998/0404/sys/src/9/port/auth.c:489,4951998/0406/sys/src/9/port/auth.c:489,495 (short | long)
Syntax edit.
rsc Fri Mar 4 12:44:25 2005
1998/0404    
	cp = c->aux; 
	if(cp == nil) 
		error(Ebadarg); 
	if(n < TICKETLEN)) 
1998/0406    
	if(n < TICKETLEN) 
1998/0404    
		error(Ebadarg); 
	convT2M(&cp->t, a, nil); 
	return sizeof(cp->t); 
1998/0406/sys/src/9/port/auth.c:479,4851998/0407/sys/src/9/port/auth.c:479,485 (short | long)
Comment edits.
rsc Fri Mar 4 12:44:25 2005
1993/0731    
 
/* 
1998/0404    
 *  reading authcheck after writing into it yields the 
 *  nonce key 
1998/0407    
 *  unencrypted ticket 
1998/0404    
 */ 
long 
authcheckread(Chan *c, char *a, int n) 
1998/0406/sys/src/9/port/auth.c:528,5331998/0407/sys/src/9/port/auth.c:528,537
1993/0731    
	return n; 
} 
 
1998/0407    
/* 
 *  create an authenticator and return it and optionally the 
 *  unencripted ticket 
 */ 
1993/0731    
long 
authentread(Chan *c, char *a, int n) 
{ 
1998/0407/sys/src/9/port/auth.c:395,4011998/0422/sys/src/9/port/auth.c:395,401 (short | long)
Return decrypted ticket from authread instead of authentread.
rsc Fri Mar 4 12:44:25 2005
1993/0330    
		/* 
		 *  subsequent read returns an authenticator 
		 */ 
		if(n != AUTHENTLEN) 
1998/0422    
		if(n < AUTHENTLEN) 
1993/0330    
			error(Ebadarg); 
		cp = c->aux; 
1993/0731    
 
1998/0407/sys/src/9/port/auth.c:405,4101998/0422/sys/src/9/port/auth.c:405,413
1993/0731    
		convA2M(&cp->a, cp->tbuf, cp->t.key); 
		memmove(a, cp->tbuf, AUTHENTLEN); 
 
1998/0422    
		if(n >= AUTHENTLEN + TICKETLEN) 
			convT2M(&cp->t, a+AUTHENTLEN, nil); 
 
1993/0330    
		freecrypt(cp); 
		c->aux = 0; 
	} 
1998/0407/sys/src/9/port/auth.c:547,5551998/0422/sys/src/9/port/auth.c:550,555
1998/0404    
 
	if(n >= AUTHENTLEN) 
		memmove(a, cp->tbuf, AUTHENTLEN); 
	if(n >= AUTHENTLEN + TICKETLEN) 
		convT2M(&cp->t, a+AUTHENTLEN, nil); 
1993/0731    
                 
1993/0428    
	return n; 
} 
 
1998/0422/sys/src/9/port/auth.c:170,1761998/0512/sys/src/9/port/auth.c:170,176 (short | long)
Whitespace edit.
rsc Fri Mar 4 12:44:25 2005
1993/0330    
	} 
1993/0731    
	unlock(&s->send); 
1993/0330    
 
	/*  
1998/0512    
	/* 
1993/0330    
	 *  If server requires no ticket, or user is "none", or a ticket 
	 *  is already cached, zero the request type 
	 */ 
1998/0422/sys/src/9/port/auth.c:349,3551998/0512/sys/src/9/port/auth.c:349,355
1993/0330    
	if(memcmp(cp->a.chal, s->cchal, sizeof(cp->a.chal))){ 
		print("bad returned challenge\n"); 
		error("server lies"); 
	}	 
1998/0512    
	} 
1993/0330    
	if(cp->a.id != id){ 
		print("bad returned id\n"); 
		error("server lies"); 
1998/0512/sys/src/9/port/auth.c:215,2241999/0331/sys/src/9/port/auth.c:215,227 (short | long)
1993/0330    
	validaddr(arg[1], 2*TICKETLEN, 0); 
	c = fdtochan(arg[0], OWRITE, 0, 1); 
	s = c->session; 
	if(s == 0) 
1999/0331    
	if(s == 0){ 
		cclose(c); 
1993/0330    
		error("fauth must follow fsession"); 
1999/0331    
	} 
1993/0330    
	cp = newcrypt(); 
	if(waserror()){ 
1999/0331    
		cclose(c); 
1993/0330    
		freecrypt(cp); 
		nexterror(); 
	} 
1998/0512/sys/src/9/port/auth.c:249,2541999/0331/sys/src/9/port/auth.c:252,258
1993/0330    
	cp->next = s->cache; 
	s->cache = cp; 
	unlock(s); 
1999/0331    
	cclose(c); 
1993/0330    
	poperror(); 
	return 0; 
} 
1999/0331/sys/src/9/port/auth.c:537,5431999/1224/sys/src/9/port/auth.c:537,543 (short | long)
1993/0731    
 
1998/0407    
/* 
 *  create an authenticator and return it and optionally the 
 *  unencripted ticket 
1999/1224    
 *  unencrypted ticket 
1998/0407    
 */ 
1993/0731    
long 
authentread(Chan *c, char *a, int n) 
Too many diffs (26 > 25). Stopping.


source code copyright © 1990-2005 Lucent Technologies; see license
Plan 9 distribution
comments to russ cox (rsc@swtch.com)