cwfs: code cleanup
This commit is contained in:
parent
049c2c3434
commit
ec338af87b
6 changed files with 71 additions and 180 deletions
|
@ -152,14 +152,14 @@ version(Chan* chan, Fcall* f, Fcall* r)
|
|||
return 0;
|
||||
}
|
||||
|
||||
struct {
|
||||
Lock;
|
||||
ulong hi;
|
||||
} authpath;
|
||||
|
||||
static int
|
||||
auth(Chan* chan, Fcall* f, Fcall* r)
|
||||
{
|
||||
static struct {
|
||||
Lock;
|
||||
ulong hi;
|
||||
} authpath;
|
||||
char *aname;
|
||||
File *file;
|
||||
Filsys *fs;
|
||||
|
@ -195,13 +195,12 @@ auth(Chan* chan, Fcall* f, Fcall* r)
|
|||
file->open = FREAD+FWRITE;
|
||||
freewp(file->wpath);
|
||||
file->wpath = 0;
|
||||
file->auth = authnew(f->uname, f->aname);
|
||||
if(file->auth == nil){
|
||||
file->uid = -1;
|
||||
if((file->auth = authnew()) == nil){
|
||||
error = Eauthfile;
|
||||
goto out;
|
||||
}
|
||||
r->aqid = file->qid;
|
||||
|
||||
out:
|
||||
if((cons.flags & attachflag) && error)
|
||||
print("9p2: auth %s %T SUCK EGGS --- %s\n",
|
||||
|
@ -218,7 +217,7 @@ static int
|
|||
authorize(Chan* chan, Fcall* f)
|
||||
{
|
||||
File* af;
|
||||
int db, uid = -1;
|
||||
int db, uid;
|
||||
|
||||
db = cons.flags & authdebugflag;
|
||||
|
||||
|
@ -247,26 +246,9 @@ authorize(Chan* chan, Fcall* f)
|
|||
|
||||
/* fake read to get auth info */
|
||||
authread(af, nil, 0);
|
||||
|
||||
if(af->auth == nil){
|
||||
if(db)
|
||||
print("authorize: af->auth == nil\n");
|
||||
goto out;
|
||||
}
|
||||
if(strcmp(f->uname, authuname(af->auth)) != 0){
|
||||
if(db)
|
||||
print("authorize: strcmp(f->uname, authuname(af->auth)) != 0\n");
|
||||
goto out;
|
||||
}
|
||||
if(strcmp(f->aname, authaname(af->auth)) != 0){
|
||||
if(db)
|
||||
print("authorize: strcmp(f->aname, authaname(af->auth)) != 0\n");
|
||||
goto out;
|
||||
}
|
||||
uid = authuid(af->auth);
|
||||
uid = af->uid;
|
||||
if(db)
|
||||
print("authorize: uid is %d\n", uid);
|
||||
out:
|
||||
qunlock(af);
|
||||
return uid;
|
||||
}
|
||||
|
@ -1321,6 +1303,7 @@ _clunk(File* file, int remove, int wok)
|
|||
file->open = 0;
|
||||
freewp(file->wpath);
|
||||
authfree(file->auth);
|
||||
file->auth = 0;
|
||||
freefp(file);
|
||||
qunlock(file);
|
||||
|
||||
|
@ -1368,7 +1351,7 @@ fs_stat(Chan* chan, Fcall* f, Fcall* r, uchar* data)
|
|||
d = &dentry;
|
||||
mkqid9p1(&d->qid, &file->qid);
|
||||
strcpy(d->name, "#¿");
|
||||
d->uid = authuid(file->auth);
|
||||
d->uid = file->uid;
|
||||
d->gid = d->uid;
|
||||
d->muid = d->uid;
|
||||
d->atime = time(nil);
|
||||
|
|
|
@ -16,7 +16,6 @@ nvrgetconfig(void)
|
|||
/*
|
||||
* we shouldn't be writing nvram any more.
|
||||
* the secstore/config field is now just secstore key.
|
||||
* we still use authid, authdom and machkey for authentication.
|
||||
*/
|
||||
|
||||
int
|
||||
|
@ -84,161 +83,77 @@ conslock(void)
|
|||
return 1;
|
||||
}
|
||||
|
||||
/* authentication structure */
|
||||
struct Auth
|
||||
{
|
||||
int inuse;
|
||||
char uname[NAMELEN]; /* requestor's remote user name */
|
||||
char aname[NAMELEN]; /* requested aname */
|
||||
Userid uid; /* uid decided on */
|
||||
AuthRpc *rpc;
|
||||
};
|
||||
static char *keyspec = "proto=p9any role=server";
|
||||
|
||||
Auth* auths;
|
||||
Lock authlock;
|
||||
|
||||
void
|
||||
authinit(void)
|
||||
{
|
||||
auths = malloc(conf.nauth * sizeof(*auths));
|
||||
}
|
||||
|
||||
static int
|
||||
failure(Auth *s, char *why)
|
||||
void*
|
||||
authnew(void)
|
||||
{
|
||||
AuthRpc *rpc;
|
||||
int fd;
|
||||
|
||||
if(why && *why)print("authentication failed: %s: %r\n", why);
|
||||
s->uid = -1;
|
||||
if(rpc = s->rpc){
|
||||
s->rpc = 0;
|
||||
if(access("/mnt/factotum", 0) < 0)
|
||||
if((fd = open("/srv/factotum", ORDWR)) >= 0)
|
||||
mount(fd, -1, "/mnt", MBEFORE, "");
|
||||
if((fd = open("/mnt/factotum/rpc", ORDWR)) < 0)
|
||||
return nil;
|
||||
if((rpc = auth_allocrpc(fd)) == nil){
|
||||
close(fd);
|
||||
return nil;
|
||||
}
|
||||
if(auth_rpc(rpc, "start", keyspec, strlen(keyspec)) != ARok){
|
||||
auth_freerpc(rpc);
|
||||
return nil;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
Auth*
|
||||
authnew(char *uname, char *aname)
|
||||
{
|
||||
static int si = 0;
|
||||
int afd, i, nwrap;
|
||||
Auth *s;
|
||||
|
||||
i = si;
|
||||
nwrap = 0;
|
||||
for(;;){
|
||||
if(i < 0 || i >= conf.nauth){
|
||||
if(++nwrap > 1)
|
||||
return nil;
|
||||
i = 0;
|
||||
}
|
||||
s = &auths[i++];
|
||||
if(s->inuse)
|
||||
continue;
|
||||
lock(&authlock);
|
||||
if(s->inuse == 0){
|
||||
s->inuse = 1;
|
||||
strncpy(s->uname, uname, NAMELEN-1);
|
||||
strncpy(s->aname, aname, NAMELEN-1);
|
||||
failure(s, "");
|
||||
si = i;
|
||||
unlock(&authlock);
|
||||
break;
|
||||
}
|
||||
unlock(&authlock);
|
||||
}
|
||||
if((afd = open("/mnt/factotum/rpc", ORDWR)) < 0){
|
||||
failure(s, "open /mnt/factotum/rpc");
|
||||
return s;
|
||||
}
|
||||
if((s->rpc = auth_allocrpc(afd)) == 0){
|
||||
failure(s, "auth_allocrpc");
|
||||
close(afd);
|
||||
return s;
|
||||
}
|
||||
if(auth_rpc(s->rpc, "start", "proto=p9any role=server", 23) != ARok)
|
||||
failure(s, "auth_rpc: start");
|
||||
return s;
|
||||
return rpc;
|
||||
}
|
||||
|
||||
void
|
||||
authfree(Auth *s)
|
||||
authfree(void *auth)
|
||||
{
|
||||
if(s){
|
||||
failure(s, "");
|
||||
s->inuse = 0;
|
||||
}
|
||||
AuthRpc *rpc;
|
||||
|
||||
if(rpc = auth)
|
||||
auth_freerpc(rpc);
|
||||
}
|
||||
|
||||
int
|
||||
authread(File* file, uchar* data, int n)
|
||||
authread(File *file, uchar *data, int count)
|
||||
{
|
||||
AuthInfo *ai;
|
||||
Auth *s;
|
||||
AuthRpc *rpc;
|
||||
|
||||
s = file->auth;
|
||||
if(s == nil)
|
||||
if((rpc = file->auth) == nil)
|
||||
return -1;
|
||||
if(s->rpc == nil)
|
||||
return -1;
|
||||
switch(auth_rpc(s->rpc, "read", nil, 0)){
|
||||
default:
|
||||
failure(s, "auth_rpc: read");
|
||||
break;
|
||||
switch(auth_rpc(rpc, "read", nil, 0)){
|
||||
case ARdone:
|
||||
if((ai = auth_getinfo(s->rpc)) == nil){
|
||||
failure(s, "auth_getinfo failed");
|
||||
break;
|
||||
}
|
||||
if(ai->cuid == nil || *ai->cuid == '\0'){
|
||||
failure(s, "auth with no cuid");
|
||||
auth_freeAI(ai);
|
||||
break;
|
||||
}
|
||||
failure(s, "");
|
||||
s->uid = strtouid(ai->cuid);
|
||||
if((ai = auth_getinfo(rpc)) == nil)
|
||||
return -1;
|
||||
file->uid = strtouid(ai->cuid);
|
||||
auth_freeAI(ai);
|
||||
if(file->uid < 0)
|
||||
return -1;
|
||||
return 0;
|
||||
case ARok:
|
||||
if(n < s->rpc->narg)
|
||||
break;
|
||||
memmove(data, s->rpc->arg, s->rpc->narg);
|
||||
return s->rpc->narg;
|
||||
if(count < rpc->narg)
|
||||
return -1;
|
||||
memmove(data, rpc->arg, rpc->narg);
|
||||
return rpc->narg;
|
||||
case ARphase:
|
||||
return -1;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int
|
||||
authwrite(File* file, uchar *data, int n)
|
||||
authwrite(File *file, uchar *data, int count)
|
||||
{
|
||||
Auth *s;
|
||||
AuthRpc *rpc;
|
||||
|
||||
s = file->auth;
|
||||
if(s == nil)
|
||||
if((rpc = file->auth) == nil)
|
||||
return -1;
|
||||
if(s->rpc == nil)
|
||||
if(auth_rpc(rpc, "write", data, count) != ARok)
|
||||
return -1;
|
||||
if(auth_rpc(s->rpc, "write", data, n) != ARok){
|
||||
failure(s, "auth_rpc: write");
|
||||
return -1;
|
||||
}
|
||||
return n;
|
||||
return count;
|
||||
}
|
||||
|
||||
int
|
||||
authuid(Auth* s)
|
||||
{
|
||||
return s->uid;
|
||||
}
|
||||
|
||||
char*
|
||||
authaname(Auth* s)
|
||||
{
|
||||
return s->aname;
|
||||
}
|
||||
|
||||
char*
|
||||
authuname(Auth* s)
|
||||
{
|
||||
return s->uname;
|
||||
}
|
||||
|
|
|
@ -140,7 +140,6 @@ confinit(void)
|
|||
localconfinit();
|
||||
|
||||
conf.nwpath = conf.nfile*8;
|
||||
conf.nauth = conf.nfile/10;
|
||||
conf.gidspace = conf.nuid*3;
|
||||
|
||||
cons.flags = 0;
|
||||
|
@ -364,7 +363,6 @@ main(int argc, char **argv)
|
|||
wpaths = malloc(conf.nwpath * sizeof(*wpaths));
|
||||
uid = malloc(conf.nuid * sizeof(*uid));
|
||||
gidspace = malloc(conf.gidspace * sizeof(*gidspace));
|
||||
authinit();
|
||||
|
||||
print("iobufinit\n");
|
||||
iobufinit();
|
||||
|
|
|
@ -52,30 +52,27 @@ static void
|
|||
neti(void *v)
|
||||
{
|
||||
int lisfd, accfd;
|
||||
Network *net;
|
||||
NetConnInfo *nci;
|
||||
Network *net;
|
||||
|
||||
net = v;
|
||||
print("net%di\n", net->ctlrno);
|
||||
Listen:
|
||||
if((lisfd = listen(net->anndir, net->lisdir)) < 0){
|
||||
print("listen %s failed: %r\n", net->anndir);
|
||||
return;
|
||||
}
|
||||
for(;;) {
|
||||
lisfd = listen(net->anndir, net->lisdir);
|
||||
if (lisfd < 0) {
|
||||
print("listen %s failed: %r\n", net->anndir);
|
||||
continue;
|
||||
}
|
||||
|
||||
/* got new call on lisfd */
|
||||
accfd = accept(lisfd, net->lisdir);
|
||||
if (accfd < 0) {
|
||||
if((accfd = accept(lisfd, net->lisdir)) < 0){
|
||||
print("accept %d (from %s) failed: %r\n",
|
||||
lisfd, net->lisdir);
|
||||
continue;
|
||||
close(lisfd);
|
||||
goto Listen;
|
||||
}
|
||||
|
||||
nci = getnetconninfo(net->lisdir, accfd);
|
||||
srvchan(accfd, nci->raddr);
|
||||
freenetconninfo(nci);
|
||||
close(lisfd);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -85,7 +82,7 @@ netstart(void)
|
|||
Network *net;
|
||||
|
||||
for(net = &netif[0]; net < &netif[Maxnets]; net++){
|
||||
if(net->dialstr == nil)
|
||||
if(net->dialstr == nil || *net->anndir == 0)
|
||||
continue;
|
||||
sprint(net->name, "net%di", net->ctlrno);
|
||||
newproc(neti, net, net->name);
|
||||
|
@ -99,10 +96,13 @@ netinit(void)
|
|||
|
||||
for (net = netif; net < netif + Maxnets; net++) {
|
||||
net->dialstr = annstrs[net - netif];
|
||||
if (net->dialstr == nil)
|
||||
if(net->dialstr == nil)
|
||||
continue;
|
||||
if((net->annfd = announce(net->dialstr, net->anndir)) < 0)
|
||||
if((net->annfd = announce(net->dialstr, net->anndir)) < 0){
|
||||
print("can't announce %s: %r", net->dialstr);
|
||||
net->dialstr = nil;
|
||||
continue;
|
||||
}
|
||||
print("netinit: announced on %s\n", net->dialstr);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -358,7 +358,7 @@ struct File
|
|||
Off lastra; /* read ahead address */
|
||||
ulong fid;
|
||||
Userid uid;
|
||||
Auth *auth;
|
||||
void *auth;
|
||||
char open;
|
||||
#define FREAD 1
|
||||
#define FWRITE 2
|
||||
|
@ -434,7 +434,6 @@ struct Conf
|
|||
char *confdev;
|
||||
char *devmap; /* name of config->file device mapping file */
|
||||
|
||||
ulong nauth; /* number of Auth structs */
|
||||
uchar nodump; /* no periodic dumps */
|
||||
uchar dumpreread; /* read and compare in dump copy */
|
||||
};
|
||||
|
|
|
@ -2,13 +2,9 @@ void accessdir(Iobuf*, Dentry*, int, int);
|
|||
void addfree(Device*, Off, Superb*);
|
||||
void arpstart(void);
|
||||
void arginit(void);
|
||||
char* authaname(Auth*);
|
||||
void authinit(void);
|
||||
void authfree(Auth*);
|
||||
Auth* authnew(char*, char*);
|
||||
void* authnew(void);
|
||||
void authfree(void*);
|
||||
int authread(File*, uchar*, int);
|
||||
int authuid(Auth*);
|
||||
char* authuname(Auth*);
|
||||
int authwrite(File*, uchar*, int);
|
||||
void cdiag(char*, int);
|
||||
int cnumb(void);
|
||||
|
|
Loading…
Reference in a new issue