aboutsummaryrefslogtreecommitdiff
path: root/src/libsunrpc
diff options
context:
space:
mode:
authorrsc <devnull@localhost>2005-05-19 14:39:10 +0000
committerrsc <devnull@localhost>2005-05-19 14:39:10 +0000
commit4c06b8eec1a1d71f67561d4fa9860850795c56aa (patch)
treea05deac604e8554498945a9f32deb524acfe95ec /src/libsunrpc
parentf92a2ceba411689890e6f8aab81a03f30b802b10 (diff)
downloadplan9port-4c06b8eec1a1d71f67561d4fa9860850795c56aa.tar.gz
plan9port-4c06b8eec1a1d71f67561d4fa9860850795c56aa.tar.bz2
plan9port-4c06b8eec1a1d71f67561d4fa9860850795c56aa.zip
fixes for vnfs
Diffstat (limited to 'src/libsunrpc')
-rw-r--r--src/libsunrpc/client.c18
-rw-r--r--src/libsunrpc/net.c17
-rw-r--r--src/libsunrpc/portmap.c2
-rw-r--r--src/libsunrpc/prog.c2
-rw-r--r--src/libsunrpc/rpc.c13
-rw-r--r--src/libsunrpc/server.c8
-rw-r--r--src/libsunrpc/udp.c21
7 files changed, 64 insertions, 17 deletions
diff --git a/src/libsunrpc/client.c b/src/libsunrpc/client.c
index f20208a2..9efe6d92 100644
--- a/src/libsunrpc/client.c
+++ b/src/libsunrpc/client.c
@@ -156,6 +156,7 @@ rpcMuxThread(void *v)
Out *o, **out;
SunRpc rpc;
SunClient *cli;
+ SunStatus ok;
cli = v;
mout = 16;
@@ -262,7 +263,7 @@ if(cli->chatty) fprint(2, "resend %lux %lud %lud\n", o->xid, t, o->t);
n = (p[0]<<24)|(p[1]<<16)|(p[2]<<8)|p[3];
p += 4;
ep = p+n;
- if(sunrpcunpack(p, ep, &p, &rpc) < 0){
+ if((ok = sunrpcunpack(p, ep, &p, &rpc)) != SunSuccess){
fprint(2, "%s: in: %.*H unpack failed\n", argv0, n, buf+4);
free(buf);
break;
@@ -288,9 +289,9 @@ if(cli->chatty) fprint(2, "resend %lux %lud %lud\n", o->xid, t, o->t);
out[i] = out[--nout];
free(o->p);
o->p = nil;
+ o->rpc = rpc;
if(rpc.status == SunSuccess){
o->p = buf;
- o->rpc = rpc;
}else{
o->p = nil;
free(buf);
@@ -353,9 +354,9 @@ sunclientclose(SunClient *cli)
if(!cli->timertid)
n++;
while(n < 2){
- threadint(cli->nettid);
- if(cli->timertid)
- threadint(cli->timertid);
+ // threadint(cli->nettid);
+ // if(cli->timertid)
+ // threadint(cli->timertid);
yield();
while(nbrecv(cli->dying, nil) == 1)
n++;
@@ -469,6 +470,13 @@ sunclientrpc(SunClient *cli, ulong tag, SunCall *tx, SunCall *rx, uchar **tofree
rx->rpc.prog = tx->rpc.prog;
rx->rpc.vers = tx->rpc.vers;
rx->type = (rx->rpc.proc<<1)|1;
+ if(rx->rpc.status != SunSuccess){
+ sunerrstr(rx->rpc.status);
+ werrstr("unpack: %r");
+ free(o.p);
+ return -1;
+ }
+
if((ok = suncallunpack(prog, p, ep, &p, rx)) != SunSuccess){
sunerrstr(ok);
werrstr("unpack: %r");
diff --git a/src/libsunrpc/net.c b/src/libsunrpc/net.c
index 28890d6c..a8b917e0 100644
--- a/src/libsunrpc/net.c
+++ b/src/libsunrpc/net.c
@@ -1,5 +1,6 @@
#include <u.h>
#include <libc.h>
+#include <ip.h>
#include <thread.h>
#include <sunrpc.h>
@@ -16,7 +17,10 @@ sunnetlisten(void *v)
{
int fd, lcfd;
char ldir[40];
+ uchar ip[IPaddrlen];
+ int port;
Arg *a = v;
+ NetConnInfo *nci;
for(;;){
lcfd = listen(a->adir, ldir);
@@ -26,6 +30,19 @@ sunnetlisten(void *v)
close(lcfd);
if(fd < 0)
continue;
+ if(a->srv->ipokay){
+ if((nci = getnetconninfo(nil, fd)) == nil){
+ close(fd);
+ continue;
+ }
+ port = atoi(nci->rserv);
+ parseip(ip, nci->raddr);
+ freenetconninfo(nci);
+ if(!a->srv->ipokay(ip, port)){
+ close(fd);
+ continue;
+ }
+ }
if(!sunsrvfd(a->srv, fd))
close(fd);
}
diff --git a/src/libsunrpc/portmap.c b/src/libsunrpc/portmap.c
index 4a3069dd..2bb40153 100644
--- a/src/libsunrpc/portmap.c
+++ b/src/libsunrpc/portmap.c
@@ -489,7 +489,7 @@ static SunProc proc[] = {
(P)portRCallitPack, (P)portRCallitUnpack, (S)portRCallitSize, (F)portRCallitPrint, sizeof(PortRCallit),
};
-SunProg portProg =
+SunProg portprog =
{
PortProgram,
PortVersion,
diff --git a/src/libsunrpc/prog.c b/src/libsunrpc/prog.c
index 628fc21e..914d61fc 100644
--- a/src/libsunrpc/prog.c
+++ b/src/libsunrpc/prog.c
@@ -29,7 +29,7 @@ suncallunpack(SunProg *prog, uchar *a, uchar *ea, uchar **pa, SunCall *c)
if(c->type < 0 || c->type >= prog->nproc || (unpack=prog->proc[c->type].unpack) == nil)
return SunProcUnavail;
if((*unpack)(a, ea, pa, c) < 0){
- fprint(2, "%lud %d: %.*H unpack failed\n", prog->prog, c->type, (int)(ea-a), a);
+ fprint(2, "%lud %d: '%.*H' unpack failed\n", prog->prog, c->type, (int)(ea-a), a);
return SunGarbageArgs;
}
return SunSuccess;
diff --git a/src/libsunrpc/rpc.c b/src/libsunrpc/rpc.c
index 43835934..837ead21 100644
--- a/src/libsunrpc/rpc.c
+++ b/src/libsunrpc/rpc.c
@@ -68,12 +68,17 @@ sunrpcpack(uchar *a, uchar *ea, uchar **pa, SunRpc *rpc)
|| sunauthinfopack(a, ea, &a, &rpc->verf) < 0)
goto Err;
break;
+ case SunAuthError:
+ if(sunuint32pack(a, ea, &a, (x=MsgDenied, &x)) < 0
+ || sunuint32pack(a, ea, &a, (x=MsgAuthError, &x)) < 0)
+ goto Err;
+ break;
default:
if(sunuint32pack(a, ea, &a, (x=MsgDenied, &x)) < 0)
goto Err;
break;
}
-
+
switch(rpc->status){
case SunSuccess:
if(sunuint32pack(a, ea, &a, (x=MsgSuccess, &x)) < 0
@@ -90,6 +95,7 @@ sunrpcpack(uchar *a, uchar *ea, uchar **pa, SunRpc *rpc)
default:
if(sunuint32pack(a, ea, &a, (x=rpc->status&0xFFFF, &x)) < 0)
goto Err;
+
break;
}
}
@@ -119,6 +125,9 @@ sunrpcsize(SunRpc *rpc)
case SunAcceptError:
a += 4+sunauthinfosize(&rpc->verf);
break;
+ case SunAuthError:
+ a += 4+4;
+ break;
default:
a += 4;
break;
@@ -169,6 +178,7 @@ sunrpcunpack(uchar *a, uchar *ea, uchar **pa, SunRpc *rpc)
rpc->iscall = 0;
if(sunuint32unpack(a, ea, &a, &x) < 0)
goto Err;
+fprint(2, "x %x\n", x);
switch(x){
default:
goto Err;
@@ -200,6 +210,7 @@ sunrpcunpack(uchar *a, uchar *ea, uchar **pa, SunRpc *rpc)
case MsgDenied:
if(sunuint32unpack(a, ea, &a, &x) < 0)
goto Err;
+fprint(2, "xx %ux\n", x);
switch(x){
default:
goto Err;
diff --git a/src/libsunrpc/server.c b/src/libsunrpc/server.c
index 8b45b44c..81358587 100644
--- a/src/libsunrpc/server.c
+++ b/src/libsunrpc/server.c
@@ -1,5 +1,6 @@
#include <u.h>
#include <libc.h>
+#include <ip.h>
#include <thread.h>
#include <sunrpc.h>
@@ -79,6 +80,7 @@ sunsrvthreadcreate(SunSrv *srv, void (*fn)(void*), void *arg)
static void
sunrpcrequestthread(void *v)
{
+ int status;
uchar *p, *ep;
Channel *c;
SunSrv *srv = v;
@@ -93,6 +95,7 @@ if(srv->chatty) fprint(2, "sun msg %p count %d\n", m, m->count);
m->srv = srv;
p = m->data;
ep = p+m->count;
+ status = m->rpc.status;
if(sunrpcunpack(p, ep, &p, &m->rpc) != SunSuccess){
fprint(2, "in: %.*H unpack failed\n", m->count, m->data);
sunmsgdrop(m);
@@ -100,7 +103,10 @@ if(srv->chatty) fprint(2, "sun msg %p count %d\n", m, m->count);
}
if(srv->chatty)
fprint(2, "in: %B\n", &m->rpc);
-
+ if(status){
+ sunmsgreplyerror(m, status);
+ continue;
+ }
if(srv->alwaysreject){
if(srv->chatty)
fprint(2, "\trejecting\n");
diff --git a/src/libsunrpc/udp.c b/src/libsunrpc/udp.c
index ff668f83..2e107e65 100644
--- a/src/libsunrpc/udp.c
+++ b/src/libsunrpc/udp.c
@@ -48,8 +48,18 @@ sunudpread(void *v)
while((n = udpread(arg.fd, &udp, buf, UdpMaxRead)) > 0){
if(arg.srv->chatty)
fprint(2, "udpread got %d (%d) from %I\n", n, Udphdrsize, udp.raddr);
+ msg = emalloc(sizeof(SunMsgUdp));
+ msg->udp = udp;
+ msg->msg.data = emalloc(n);
+ msg->msg.count = n;
+ memmove(msg->msg.data, buf, n);
+ msg->msg.creply = arg.creply;
+ msg->msg.srv = arg.srv;
+ if(arg.srv->chatty)
+ fprint(2, "message %p count %d\n", msg, msg->msg.count);
if((srv->localonly || srv->localparanoia) && ipcmp(udp.raddr, localip) != 0){
fprint(2, "dropping message from %I: not local\n", udp.raddr);
+ sunmsgreplyerror(&msg->msg, SunAuthTooWeak);
continue;
}
if(srv->localparanoia){
@@ -59,17 +69,12 @@ sunudpread(void *v)
paraport = port;
}else if(paraport != port){
fprint(2, "dropping message from %I: not port %d\n", udp.raddr, port);
+ sunmsgreplyerror(&msg->msg, SunAuthTooWeak);
continue;
}
}
- msg = emalloc(sizeof(SunMsgUdp));
- msg->udp = udp;
- msg->msg.data = emalloc(n);
- msg->msg.count = n;
- memmove(msg->msg.data, buf, n);
- msg->msg.creply = arg.creply;
- if(arg.srv->chatty)
- fprint(2, "message %p count %d\n", msg, msg->msg.count);
+ if(srv->ipokay && !srv->ipokay(udp.raddr, nhgets(udp.rport)))
+ msg->msg.rpc.status = SunProgUnavail;
sendp(arg.srv->crequest, msg);
}
}