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

1993/0501/port/auth.c (diff list | history)

1993/0428/sys/src/9/port/auth.c:15,251993/0501/sys/src/9/port/auth.c:15,23 (short | long | prev | next)
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; 
} 
 


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