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

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

port/auth.c on 1993/0330
1993/0330    
#include	"u.h" 
#include	"../port/lib.h" 
#include	"mem.h" 
#include	"dat.h" 
#include	"fns.h" 
#include	"../port/error.h" 
 
2001/0925    
#include	<authsrv.h> 
1993/0330    
 
2001/0527    
char	*eve; 
1993/0330    
char	hostdomain[DOMLEN]; 
 
/* 
 *  return true if current user is eve 
 */ 
int 
iseve(void) 
{ 
1993/0501    
	return strcmp(eve, up->user) == 0; 
1993/0330    
} 
 
long 
2001/0527    
sysfversion(ulong *arg) 
1993/0330    
{ 
2001/0527    
	char *vers; 
2001/0819    
	uint arglen, m, msize; 
1993/0330    
	Chan *c; 
 
2001/0527    
	msize = arg[1]; 
	vers = (char*)arg[2]; 
	arglen = arg[3]; 
	validaddr(arg[2], arglen, 1); 
	/* check there's a NUL in the version string */ 
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()){ 
1997/0327    
		cclose(c); 
1993/0330    
		nexterror(); 
	} 
1993/0407    
 
2001/0819    
	m = mntversion(c, vers, msize, arglen); 
2001/0527    
 
1997/0327    
	cclose(c); 
1993/0407    
	poperror(); 
2001/0527    
	return m; 
1993/0330    
} 
 
2001/0808    
long 
2001/0819    
sys_fsession(ulong *arg) 
1993/0330    
{ 
2001/0819    
	/* deprecated; backwards compatibility only */ 
1993/0330    
 
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); 
		nexterror(); 
	} 
 
2001/0819    
	ac = mntauth(c, aname); 
2001/0527    
	if(waserror()){ 
2001/0819    
		cclose(ac); 
2001/0527    
		nexterror(); 
1993/0330    
	} 
 
2001/0819    
	fd = newfd(ac); 
	if(fd < 0) 
		error(Enofd); 
	poperror();	/* ac */ 
	poperror();	/* c */ 
1993/0330    
 
2001/0819    
	/* always mark it close on exec */ 
	ac->flag |= CCEXEC; 
1993/0731    
 
2001/0819    
	return fd; 
1993/0731    
} 
 
/* 
1993/0330    
 *  called by devcons() for user device 
 * 
 *  anyone can become none 
 */ 
long 
userwrite(char *a, int n) 
{ 
2002/0410    
	if(n!=4 || strncmp(a, "none", 4)!=0) 
1993/0330    
		error(Eperm); 
2001/0527    
	kstrdup(&up->user, "none"); 
1995/0110    
	up->basepri = PriNormal; 
1993/0330    
	return n; 
} 
 
/* 
 *  called by devcons() for host owner/domain 
 * 
 *  writing hostowner also sets user 
 */ 
long 
hostownerwrite(char *a, int n) 
{ 
2001/0527    
	char buf[128]; 
1993/0330    
 
	if(!iseve()) 
		error(Eperm); 
2002/0221    
	if(n <= 0 || n >= sizeof buf) 
1993/0330    
		error(Ebadarg); 
2002/0221    
	memmove(buf, a, n); 
	buf[n] = 0; 
2001/0527    
 
1994/1027    
	renameuser(eve, buf); 
2001/0527    
	kstrdup(&eve, buf); 
	kstrdup(&up->user, buf); 
1995/0110    
	up->basepri = PriNormal; 
1993/0330    
	return n; 
} 
 
long 
hostdomainwrite(char *a, int n) 
{ 
	char buf[DOMLEN]; 
 
	if(!iseve()) 
		error(Eperm); 
	if(n >= DOMLEN) 
		error(Ebadarg); 
	memset(buf, 0, DOMLEN); 
	strncpy(buf, a, n); 
	if(buf[0] == 0) 
		error(Ebadarg); 
	memmove(hostdomain, buf, DOMLEN); 
	return n; 
} 


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