cwfs: fix network listener, relay auth errors. boot(8): split bootargs only on first ! char, prepare /net so cwfs can announce 9fs
This commit is contained in:
parent
064bce0841
commit
db7290d79e
7 changed files with 56 additions and 39 deletions
|
@ -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(){
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -267,6 +267,8 @@ struct Chan
|
|||
uchar authinfo[64];
|
||||
|
||||
void* pdata; /* sometimes is a Netconn* */
|
||||
|
||||
char err[ERRMAX];
|
||||
};
|
||||
|
||||
struct Filsys
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue