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

2002/0202/port/devcap.c (diff list | history)

2001/0527/sys/src/9/port/devcap.c:251,2562002/0109/sys/src/9/port/devcap.c:251,257 (short | long)
Add devshutdown.
rsc Fri Mar 4 12:44:25 2005
2001/0527    
 
	devreset, 
	devinit, 
2002/0109    
	devshutdown, 
2001/0527    
	capattach, 
	capwalk, 
	capstat, 
2002/0109/sys/src/9/port/devcap.c:192,1982002/0202/sys/src/9/port/devcap.c:192,198 (short | long)
2001/0527    
	Caphash *p; 
	char *cp; 
	uchar hash[Hashlen]; 
	char *key, *user; 
2002/0202    
	char *key, *from, *to; 
2001/0527    
	char err[256]; 
 
	switch((ulong)c->qid.path){ 
2002/0109/sys/src/9/port/devcap.c:214,2352002/0202/sys/src/9/port/devcap.c:214,245
2001/0527    
		memmove(cp, va, n); 
		cp[n] = 0; 
 
		user = cp; 
		key = strchr(cp, '@'); 
2002/0202    
		from = cp; 
		key = strrchr(cp, '@'); 
2001/0527    
		if(key == nil) 
			error(Eshort); 
		*key++ = 0; 
 
		hmac_sha1((uchar*)user, strlen(user), (uchar*)key, strlen(key), hash, nil); 
2002/0202    
		hmac_sha1((uchar*)from, strlen(from), (uchar*)key, strlen(key), hash, nil); 
2001/0527    
 
		p = remcap(hash); 
		if(p == nil){ 
			snprint(err, sizeof err, "invalid capability %s@%s", user, key); 
2002/0202    
			snprint(err, sizeof err, "invalid capability %s@%s", from, key); 
2001/0527    
			error(err); 
		} 
 
2002/0202    
		/* if a from user is supplied, make sure it matches */ 
		to = strchr(from, '@'); 
		if(to == nil){ 
			to = from; 
		} else { 
			*to++ = 0; 
			if(strcmp(from, up->user) != 0) 
				error("capability must match user"); 
		} 
 
2001/0527    
		/* set user id */ 
		kstrdup(&up->user, user); 
2002/0202    
		kstrdup(&up->user, to); 
2001/0527    
		up->basepri = PriNormal; 
 
		free(p); 
2002/0202/sys/src/9/port/devcap.c:89,942002/0622/sys/src/9/port/devcap.c:89,96 (short | long)
2001/0527    
	qlock(&capalloc); 
	switch((ulong)c->qid.path){ 
	case Qhash: 
2002/0622    
		if(!iseve()) 
			error(Eperm); 
2001/0527    
		if(capalloc.opens > 0){ 
			qunlock(&capalloc); 
			error("exclusive use"); 
2002/0622/sys/src/9/port/devcap.c:29,352002/0623/sys/src/9/port/devcap.c:29,34 (short | long)
2001/0527    
struct 
{ 
	QLock; 
	int	opens; 
	Caphash	*first; 
	int	nhash; 
} capalloc; 
2002/0622/sys/src/9/port/devcap.c:41,532002/0623/sys/src/9/port/devcap.c:40,53
2001/0527    
	Quse, 
}; 
 
2002/0623    
/* caphash must be last */ 
2001/0527    
Dirtab capdir[] = 
{ 
	".",		{Qdir,0,QTDIR},	0,		DMDIR|0500, 
	"caphash",	{Qhash},	0,		0200, 
	"capuse",	{Quse},		0,		0222, 
2002/0623    
	"caphash",	{Qhash},	0,		0200, 
2001/0527    
}; 
#define NCAPDIR 3 
2002/0623    
int ncapdir = nelem(capdir); 
2001/0527    
 
static Chan* 
capattach(char *spec) 
2002/0622/sys/src/9/port/devcap.c:58,702002/0623/sys/src/9/port/devcap.c:58,80
2001/0527    
static Walkqid* 
capwalk(Chan *c, Chan *nc, char **name, int nname) 
{ 
	return devwalk(c, nc, name, nname, capdir, NCAPDIR, devgen); 
2002/0623    
	return devwalk(c, nc, name, nname, capdir, ncapdir, devgen); 
2001/0527    
} 
 
2002/0623    
static void 
capremove(Chan *c) 
{ 
	if(iseve() && c->qid.path == Qhash) 
		ncapdir = nelem(capdir)-1; 
	else 
		error(Eperm); 
} 
 
 
2001/0527    
static int 
capstat(Chan *c, uchar *db, int n) 
{ 
	return devstat(c, db, n, capdir, NCAPDIR, devgen); 
2002/0623    
	return devstat(c, db, n, capdir, ncapdir, devgen); 
2001/0527    
} 
 
/* 
2002/0622/sys/src/9/port/devcap.c:86,1052002/0623/sys/src/9/port/devcap.c:96,108
2001/0527    
		qunlock(&capalloc); 
		nexterror(); 
	} 
	qlock(&capalloc); 
	switch((ulong)c->qid.path){ 
	case Qhash: 
2002/0622    
		if(!iseve()) 
			error(Eperm); 
2001/0527    
		if(capalloc.opens > 0){ 
			qunlock(&capalloc); 
			error("exclusive use"); 
		} 
		capalloc.opens++; 
		break; 
	} 
	poperror(); 
	qunlock(&capalloc); 
 
	c->mode = openmode(omode); 
	c->flag |= COPEN; 
2002/0622/sys/src/9/port/devcap.c:164,1772002/0623/sys/src/9/port/devcap.c:167,174
2001/0527    
} 
 
static void 
capclose(Chan *c) 
2002/0623    
capclose(Chan*) 
2001/0527    
{ 
	if(c->flag & COPEN) 
		if(c->qid.path == Qhash){ 
			qlock(&capalloc); 
			capalloc.opens--; 
			qunlock(&capalloc); 
		} 
} 
 
static long 
2002/0622/sys/src/9/port/devcap.c:179,1852002/0623/sys/src/9/port/devcap.c:176,182
2001/0527    
{ 
	switch((ulong)c->qid.path){ 
	case Qdir: 
		return devdirread(c, va, n, capdir, nelem(capdir), devgen); 
2002/0623    
		return devdirread(c, va, n, capdir, ncapdir, devgen); 
2001/0527    
 
	default: 
		error(Eperm); 
2002/0622/sys/src/9/port/devcap.c:258,2792002/0623/sys/src/9/port/devcap.c:255,276
2001/0527    
} 
 
Dev capdevtab = { 
	L'¤', 
	"cap", 
2002/0623    
.dc=		L'¤', 
.name=		"cap", 
2001/0527    
 
	devreset, 
	devinit, 
2002/0109    
	devshutdown, 
2001/0527    
	capattach, 
	capwalk, 
	capstat, 
	capopen, 
	devcreate, 
	capclose, 
	capread, 
	devbread, 
	capwrite, 
	devbwrite, 
	devremove, 
	devwstat, 
2002/0623    
.reset=		devreset, 
.init=		devinit, 
.shutdown=	devshutdown, 
.attach=	capattach, 
.walk=		capwalk, 
.stat=		capstat, 
.open=		capopen, 
.create=	devcreate, 
.close=		capclose, 
.read=		capread, 
.bread=		devbread, 
.write=		capwrite, 
.bwrite=	devbwrite, 
.remove=	capremove, 
.wstat=		devwstat, 
2001/0527    
}; 
2002/0623/sys/src/9/port/devcap.c:92,1012002/0907/sys/src/9/port/devcap.c:92,97 (short | long)
2001/0527    
		return c; 
	} 
 
	if(waserror()){ 
		qunlock(&capalloc); 
		nexterror(); 
	} 
	switch((ulong)c->qid.path){ 
	case Qhash: 
2002/0622    
		if(!iseve()) 
2002/0623/sys/src/9/port/devcap.c:102,1082002/0907/sys/src/9/port/devcap.c:98,103
2002/0622    
			error(Eperm); 
2001/0527    
		break; 
	} 
	poperror(); 
 
	c->mode = openmode(omode); 
	c->flag |= COPEN; 
2002/0907/sys/src/9/port/devcap.c:250,2712003/0218/sys/src/9/port/devcap.c:250,271 (short | long)
2001/0527    
} 
 
Dev capdevtab = { 
2002/0623    
.dc=		L'¤', 
.name=		"cap", 
2003/0218    
	L'¤', 
	"cap", 
2001/0527    
 
2002/0623    
.reset=		devreset, 
.init=		devinit, 
.shutdown=	devshutdown, 
.attach=	capattach, 
.walk=		capwalk, 
.stat=		capstat, 
.open=		capopen, 
.create=	devcreate, 
.close=		capclose, 
.read=		capread, 
.bread=		devbread, 
.write=		capwrite, 
.bwrite=	devbwrite, 
.remove=	capremove, 
.wstat=		devwstat, 
2003/0218    
	devreset, 
	devinit, 
	devshutdown, 
	capattach, 
	capwalk, 
	capstat, 
	capopen, 
	devcreate, 
	capclose, 
	capread, 
	devbread, 
	capwrite, 
	devbwrite, 
	capremove, 
	devwstat 
2001/0527    
}; 
2003/0218/sys/src/9/port/devcap.c:105,1102003/0222/sys/src/9/port/devcap.c:105,122 (short | long)
2001/0527    
	return c; 
} 
 
2003/0222    
static char* 
hashstr(uchar *hash) 
{ 
	static char buf[256]; 
	int i; 
 
	for(i = 0; i < Hashlen; i++) 
		sprint(buf+2*i, "%2.2ux", hash[i]); 
	buf[2*Hashlen] = 0; 
	return buf; 
} 
 
2001/0527    
static Caphash* 
remcap(uchar *hash) 
{ 


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