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

2001/0819/port/auth.c (diff list | history)

2001/0808/sys/src/9/port/auth.c:23,342001/0819/sys/src/9/port/auth.c:23,31 (short | long | prev | next)
1993/0330    
long 
2001/0527    
sysfversion(ulong *arg) 
1993/0330    
{ 
2001/0527    
	Fcall f;	/* two Fcalls should be big enough for reply */ 
	uchar *msg; 
	char *vers; 
	uint arglen, n, m, msize; 
2001/0819    
	uint arglen, m, msize; 
1993/0330    
	Chan *c; 
2001/0527    
	uvlong oo; 
1993/0330    
 
2001/0527    
	msize = arg[1]; 
	vers = (char*)arg[2]; 
2001/0808/sys/src/9/port/auth.c:35,412001/0819/sys/src/9/port/auth.c:32,38
2001/0527    
	arglen = arg[3]; 
	validaddr(arg[2], arglen, 1); 
	/* check there's a NUL in the version string */ 
	if(memchr(vers, 0, arglen) == 0) 
2001/0819    
	if(arglen==0 || memchr(vers, 0, arglen)==0) 
2001/0527    
		error(Ebadarg); 
	c = fdtochan(arg[0], ORDWR, 0, 1); 
1993/0407    
	if(waserror()){ 
2001/0808/sys/src/9/port/auth.c:43,1112001/0819/sys/src/9/port/auth.c:40,47
1993/0330    
		nexterror(); 
	} 
1993/0407    
 
2001/0527    
	if((c->flag&CMSG) && c->version!=nil) /* BUG: insufficient; should check compatibility */ 
		goto Return; 
2001/0819    
	m = mntversion(c, vers, msize, arglen); 
2001/0527    
 
	f.type = Tversion; 
	f.tag = NOTAG; 
	if(msize == 0) 
		msize = IOHDRSZ+8192;	/* reasonable default */ 
	f.msize = msize; 
	if(vers[0] == '\0') 
		vers = VERSION9P; 
	f.version = vers; 
2001/0529    
	msg = smalloc(8192+IOHDRSZ); 
2001/0527    
	if(waserror()){ 
		free(msg); 
		nexterror(); 
1993/0731    
	} 
2001/0529    
	n = convS2M(&f, msg, 8192+IOHDRSZ); 
2001/0527    
	if(n == 0) 
		error("bad fversion conversion on send"); 
                 
	lock(c); 
	oo = c->offset; 
	c->offset += n; 
1993/0731    
	unlock(c); 
1993/0407    
                 
2001/0527    
	m = devtab[c->type]->write(c, msg, n, oo); 
1993/0731    
                 
2001/0527    
	if(m < n){ 
		lock(c); 
		c->offset -= n - m; 
		unlock(c); 
		error("short write in fversion"); 
1993/0330    
	} 
                 
2001/0527    
	/* message sent; receive and decode reply */ 
2001/0529    
	m = devtab[c->type]->read(c, msg, 8192+IOHDRSZ, c->offset); 
2001/0527    
	if(m <= 0) 
		error("EOF receiving fversion reply"); 
1993/0330    
                 
2001/0527    
	lock(c); 
	c->offset += m; 
	unlock(c); 
1993/0330    
                 
2001/0527    
	n = convM2S(msg, m, &f); 
	if(n != m) 
		error("bad fversion conversion on reply"); 
	if(f.type != Rversion) 
		error("unexpected reply type in fversion"); 
	if(f.msize > msize) 
		error("server tries to increase msize in fversion"); 
	if(f.msize<256 || f.msize>1024*1024) 
		error("nonsense value of msize in fversion"); 
	kstrdup(&c->version, f.version); 
	c->iounit = f.msize; 
	free(msg); 
	poperror(); 
                 
Return: 
	m = strlen(c->version); 
	if(m > arglen) 
		m = arglen; 
	memmove((char*)arg[2], c->version, m); 
                 
1997/0327    
	cclose(c); 
1993/0407    
	poperror(); 
2001/0527    
	return m; 
2001/0808/sys/src/9/port/auth.c:112,1282001/0819/sys/src/9/port/auth.c:48,74
1993/0330    
} 
 
2001/0808    
long 
sysfsession(ulong *arg) 
2001/0819    
sys_fsession(ulong *arg) 
1993/0330    
{ 
2001/0527    
	Fcall f; 
	uchar *msg; 
2001/0808    
	uint authlen, n, m; 
	Chan *c; 
2001/0527    
	uvlong oo; 
2001/0819    
	/* deprecated; backwards compatibility only */ 
1993/0330    
 
2001/0808    
//BUG print("warning: stub fsession being used\n"); 
	authlen = arg[2]; 
	validaddr(arg[1], authlen, 1); 
2001/0819    
	if(arg[2] == 0) 
		error(Ebadarg); 
	validaddr(arg[1], arg[2], 1); 
	((uchar*)arg[1])[0] = '\0'; 
	return 0; 
} 
 
long 
sysfauth(ulong *arg) 
{ 
	Chan *c, *ac; 
	char *aname; 
	int fd; 
 
	validaddr(arg[1], 1, 0); 
	aname = (char*)arg[1]; 
	validname(aname, 0); 
2001/0808    
	c = fdtochan(arg[0], ORDWR, 0, 1); 
	if(waserror()){ 
		cclose(c); 
2001/0808/sys/src/9/port/auth.c:129,2012001/0819/sys/src/9/port/auth.c:75,96
2001/0808    
		nexterror(); 
	} 
 
	if(c->flag & CMSG){ 
//BUG what to do? 
		((uchar*)arg[1])[0] = 0; 
		poperror(); 
		cclose(c); 
		return 0; 
	} 
                 
2001/0527    
	f.type = Tsession; 
	f.tag = NOTAG; 
2001/0808    
	f.nchal = 0; 
	f.chal = (uchar*)""; 
2001/0529    
	msg = smalloc(8192+IOHDRSZ); 
2001/0819    
	ac = mntauth(c, aname); 
2001/0527    
	if(waserror()){ 
		free(msg); 
2001/0819    
		cclose(ac); 
2001/0527    
		nexterror(); 
1993/0330    
	} 
2001/0529    
	n = convS2M(&f, msg, 8192+IOHDRSZ); 
2001/0527    
	if(n == 0) 
		error("bad fsession conversion on send"); 
1993/0330    
 
2001/0527    
	lock(c); 
	oo = c->offset; 
	c->offset += n; 
	unlock(c); 
2001/0819    
	fd = newfd(ac); 
	if(fd < 0) 
		error(Enofd); 
	poperror();	/* ac */ 
	poperror();	/* c */ 
1993/0330    
 
2001/0527    
	m = devtab[c->type]->write(c, msg, n, oo); 
2001/0819    
	/* always mark it close on exec */ 
	ac->flag |= CCEXEC; 
1993/0731    
 
2001/0527    
	if(m < n){ 
		lock(c); 
		c->offset -= n - m; 
		unlock(c); 
		error("short write in fsession"); 
1993/0330    
	} 
                 
2001/0527    
	/* message sent; receive and decode reply */ 
2001/0529    
	m = devtab[c->type]->read(c, msg, 8192+IOHDRSZ, c->offset); 
2001/0527    
	if(m <= 0) 
		error("EOF receiving fsession reply"); 
1993/0330    
                 
2001/0527    
	lock(c); 
	c->offset += m; 
	unlock(c); 
1993/0731    
                 
2001/0527    
	n = convM2S(msg, m, &f); 
	if(n != m) 
		error("bad fsession conversion on reply"); 
	if(f.type != Rsession) 
		error("unexpected reply type in fsession"); 
2001/0808    
	m = f.nchal; 
	if(m > authlen) 
		error(Eshort); 
//BUG print("auth stuff ignored; noauth by default\n"); 
	((uchar*)arg[1])[0] = 0; 
1993/0731    
                 
2001/0527    
	free(msg); 
	poperror(); 
	poperror(); 
	cclose(c); 
2001/0808    
	return m; 
1993/0330    
} 
                 
long 
2001/0808    
sysfauth(ulong *) 
1993/0330    
{ 
2001/0808    
	error("sysfauth unimplemented"); 
	return -1; 
2001/0819    
	return fd; 
1993/0731    
} 
 
/* 


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