From db7290d79e86abfdab490e793073a4936c8e1e5f Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Sun, 1 May 2011 07:07:32 +0000 Subject: [PATCH] cwfs: fix network listener, relay auth errors. boot(8): split bootargs only on first ! char, prepare /net so cwfs can announce 9fs --- sys/src/9/boot/bootrc | 13 +++++-------- sys/src/9/boot/tcp.rc | 4 ---- sys/src/cmd/cwfs/9p2.c | 11 +++++++---- sys/src/cmd/cwfs/auth.c | 39 ++++++++++++++++++++++++++++---------- sys/src/cmd/cwfs/net.c | 22 ++++++++++----------- sys/src/cmd/cwfs/portdat.h | 2 ++ sys/src/cmd/cwfs/portfns.h | 4 ++-- 7 files changed, 56 insertions(+), 39 deletions(-) diff --git a/sys/src/9/boot/bootrc b/sys/src/9/boot/bootrc index 9b6fc6a28..4590c4a38 100644 --- a/sys/src/9/boot/bootrc +++ b/sys/src/9/boot/bootrc @@ -70,20 +70,13 @@ fn main{ } if not bootargs=$nobootprompt mn=`{echo $bootargs | awk -F! '{print $1}'} - ma=`{echo $bootargs | awk -F! '{print $2}'} + ma=`{echo $bootargs | sed 's/[^!]+!//'} for(i in `{seq 1 $#mt}){ if(~ $mt($i) m^$mn) mp=$$mt($i) } } - switch($mn){ - case local - islocal=1 - case hybrid - ishybrid=1 - } - # config method $mp(1) $ma @@ -149,6 +142,10 @@ if(! ~ $#kbmap 0){ cat $"kbmap >/dev/kbmap } +# bind in an ip interface +for(i in I l`{seq 0 3}) + bind -qa '#'$i /net + configlocal # add partitions and binds while(){ diff --git a/sys/src/9/boot/tcp.rc b/sys/src/9/boot/tcp.rc index 18e45edb2..63a6b56c5 100755 --- a/sys/src/9/boot/tcp.rc +++ b/sys/src/9/boot/tcp.rc @@ -1,10 +1,6 @@ #!/bin/rc fn configtcp{ - # bind in an ip interface - for(i in I l`{seq 0 3}) - bind -qa '#'$i /net - must ip/ipconfig -p $* if(~ $#fs 0) diff --git a/sys/src/cmd/cwfs/9p2.c b/sys/src/cmd/cwfs/9p2.c index 584b1904f..30dfdef64 100644 --- a/sys/src/cmd/cwfs/9p2.c +++ b/sys/src/cmd/cwfs/9p2.c @@ -242,7 +242,7 @@ authorize(Chan* chan, Fcall* f) } /* fake read to get auth info */ - authread(af, nil, 0); + authread(chan, af, nil, 0); uid = af->uid; if(db) print("authorize: uid is %d\n", uid); @@ -1001,7 +1001,7 @@ fs_read(Chan* chan, Fcall* f, Fcall* r, uchar* data) goto out; } if(file->qid.type & QTAUTH){ - nread = authread(file, (uchar*)data, count); + nread = authread(chan, file, (uchar*)data, count); if(nread < 0) error = Eauth2; goto out; @@ -1198,7 +1198,7 @@ fs_write(Chan* chan, Fcall* f, Fcall* r) } if(file->qid.type & QTAUTH){ - nwrite = authwrite(file, (uchar*)f->data, count); + nwrite = authwrite(chan, file, (uchar*)f->data, count); if(nwrite < 0) error = Eauth2; goto out; @@ -1733,6 +1733,7 @@ print("didn't like %d byte message\n", mb->count); r.tag = f.tag; error = 0; data = nil; + chan->err[0] = 0; switch(type){ default: @@ -1786,7 +1787,9 @@ print("didn't like %d byte message\n", mb->count); if(error != 0){ r.type = Rerror; - if(error >= MAXERR){ + if(chan->err[0]) + r.ename = chan->err; + else if(error >= MAXERR){ snprint(ename, sizeof(ename), "error %d", error); r.ename = ename; } else diff --git a/sys/src/cmd/cwfs/auth.c b/sys/src/cmd/cwfs/auth.c index d54a40dee..1e7765918 100644 --- a/sys/src/cmd/cwfs/auth.c +++ b/sys/src/cmd/cwfs/auth.c @@ -119,43 +119,62 @@ authfree(void *auth) } int -authread(File *file, uchar *data, int count) +authread(Chan *chan, File *file, uchar *data, int count) { AuthInfo *ai; AuthRpc *rpc; - if((rpc = file->auth) == nil) + if((rpc = file->auth) == nil){ + snprint(chan->err, sizeof(chan->err), + "not an auth fid"); return -1; + } + switch(auth_rpc(rpc, "read", nil, 0)){ + default: + snprint(chan->err, sizeof(chan->err), + "authread: auth protocol not finished"); + return -1; case ARdone: if((ai = auth_getinfo(rpc)) == nil) - return -1; + goto Phase; file->uid = strtouid(ai->cuid); auth_freeAI(ai); - if(file->uid < 0) + if(file->uid < 0){ + snprint(chan->err, sizeof(chan->err), + "unknown user '%s'", ai->cuid); return -1; + } return 0; case ARok: - if(count < rpc->narg) + if(count < rpc->narg){ + snprint(chan->err, sizeof(chan->err), + "not enough data in auth read"); return -1; + } memmove(data, rpc->arg, rpc->narg); return rpc->narg; case ARphase: - return -1; - default: + Phase: + rerrstr(chan->err, sizeof(chan->err)); return -1; } } int -authwrite(File *file, uchar *data, int count) +authwrite(Chan *chan, File *file, uchar *data, int count) { AuthRpc *rpc; - if((rpc = file->auth) == nil) + if((rpc = file->auth) == nil){ + snprint(chan->err, sizeof(chan->err), + "not an auth fid"); return -1; - if(auth_rpc(rpc, "write", data, count) != ARok) + } + if(auth_rpc(rpc, "write", data, count) != ARok){ + rerrstr(chan->err, sizeof(chan->err)); return -1; + } return count; } diff --git a/sys/src/cmd/cwfs/net.c b/sys/src/cmd/cwfs/net.c index ed6abe280..e8df40302 100644 --- a/sys/src/cmd/cwfs/net.c +++ b/sys/src/cmd/cwfs/net.c @@ -54,19 +54,18 @@ neti(void *v) 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; - } + if(chatty) + print("net%di\n", net->ctlrno); for(;;) { + if((lisfd = listen(net->anndir, net->lisdir)) < 0){ + fprint(2, "listen %s failed: %r\n", net->anndir); + break; + } /* got new call on lisfd */ if((accfd = accept(lisfd, net->lisdir)) < 0){ - print("accept %d (from %s) failed: %r\n", - lisfd, net->lisdir); + fprint(2, "accept %d (from %s) failed: %r\n", lisfd, net->lisdir); close(lisfd); - goto Listen; + continue; } nci = getnetconninfo(net->lisdir, accfd); srvchan(accfd, nci->raddr); @@ -97,10 +96,11 @@ netinit(void) if(net->dialstr == nil) continue; if((net->annfd = announce(net->dialstr, net->anndir)) < 0){ - print("can't announce %s: %r", net->dialstr); + fprint(2, "can't announce %s: %r", net->dialstr); net->dialstr = nil; continue; } - print("netinit: announced on %s\n", net->dialstr); + if(chatty) + print("netinit: announced on %s\n", net->dialstr); } } diff --git a/sys/src/cmd/cwfs/portdat.h b/sys/src/cmd/cwfs/portdat.h index 820cb99a2..a0bca86e0 100644 --- a/sys/src/cmd/cwfs/portdat.h +++ b/sys/src/cmd/cwfs/portdat.h @@ -267,6 +267,8 @@ struct Chan uchar authinfo[64]; void* pdata; /* sometimes is a Netconn* */ + + char err[ERRMAX]; }; struct Filsys diff --git a/sys/src/cmd/cwfs/portfns.h b/sys/src/cmd/cwfs/portfns.h index 7790b70e5..856f23b4d 100644 --- a/sys/src/cmd/cwfs/portfns.h +++ b/sys/src/cmd/cwfs/portfns.h @@ -4,8 +4,8 @@ void arpstart(void); void arginit(void); void* authnew(void); void authfree(void*); -int authread(File*, uchar*, int); -int authwrite(File*, uchar*, int); +int authread(Chan*, File*, uchar*, int); +int authwrite(Chan*, File*, uchar*, int); void cdiag(char*, int); int cnumb(void); Device* config(void);