aboutsummaryrefslogtreecommitdiff
path: root/src/libauth/auth_rpc.c
diff options
context:
space:
mode:
authorrsc <devnull@localhost>2005-02-08 20:58:10 +0000
committerrsc <devnull@localhost>2005-02-08 20:58:10 +0000
commit648bb6f75a801e6d605fcd061f0b14fecc07a8be (patch)
treeae995dfa5c1807dfa8902f5120ef6933911aebb5 /src/libauth/auth_rpc.c
parentfa467fbe51e3aba23fce6639afd8939c046c8c2d (diff)
downloadplan9port-648bb6f75a801e6d605fcd061f0b14fecc07a8be.tar.gz
plan9port-648bb6f75a801e6d605fcd061f0b14fecc07a8be.tar.bz2
plan9port-648bb6f75a801e6d605fcd061f0b14fecc07a8be.zip
lucho changes
Diffstat (limited to 'src/libauth/auth_rpc.c')
-rw-r--r--src/libauth/auth_rpc.c38
1 files changed, 34 insertions, 4 deletions
diff --git a/src/libauth/auth_rpc.c b/src/libauth/auth_rpc.c
index 4333a738..ffe3b08e 100644
--- a/src/libauth/auth_rpc.c
+++ b/src/libauth/auth_rpc.c
@@ -1,6 +1,7 @@
#include <u.h>
#include <libc.h>
#include <auth.h>
+#include <9pclient.h>
#include "authlocal.h"
static struct {
@@ -17,6 +18,24 @@ static struct {
"error", ARerror,
};
+static long
+rpcread(AuthRpc *rpc, void *buf, int buflen)
+{
+ if (rpc->afd >= 0)
+ return read(rpc->afd, buf, buflen);
+ else
+ return fsread(rpc->afid, buf, buflen);
+}
+
+static long
+rpcwrite(AuthRpc *rpc, void *buf, int buflen)
+{
+ if (rpc->afd >= 0)
+ return write(rpc->afd, buf, buflen);
+ else
+ return fswrite(rpc->afid, buf, buflen);
+}
+
static int
classify(char *buf, uint n, AuthRpc *rpc)
{
@@ -40,20 +59,31 @@ classify(char *buf, uint n, AuthRpc *rpc)
}
AuthRpc*
-auth_allocrpc(int afd)
+auth_allocrpc(void)
{
AuthRpc *rpc;
rpc = mallocz(sizeof(*rpc), 1);
if(rpc == nil)
return nil;
- rpc->afd = afd;
+ rpc->afd = open("/mnt/factotum/rpc", ORDWR);
+ if(rpc->afd < 0){
+ rpc->afid = nsopen("factotum", nil, "factotum/rpc", ORDWR);
+ if(rpc->afid == nil){
+ free(rpc);
+ return nil;
+ }
+ }
return rpc;
}
void
auth_freerpc(AuthRpc *rpc)
{
+ if(rpc->afd >= 0)
+ close(rpc->afd);
+ if(rpc->afid == nil)
+ fsclose(rpc->afid);
free(rpc);
}
@@ -72,13 +102,13 @@ auth_rpc(AuthRpc *rpc, char *verb, void *a, int na)
memmove(rpc->obuf, verb, l);
rpc->obuf[l] = ' ';
memmove(rpc->obuf+l+1, a, na);
- if((n=write(rpc->afd, rpc->obuf, l+1+na)) != l+1+na){
+ if((n=rpcwrite(rpc, rpc->obuf, l+1+na)) != l+1+na){
if(n >= 0)
werrstr("auth_rpc short write");
return ARrpcfailure;
}
- if((n=read(rpc->afd, rpc->ibuf, AuthRpcMax)) < 0)
+ if((n=rpcread(rpc, rpc->ibuf, AuthRpcMax)) < 0)
return ARrpcfailure;
rpc->ibuf[n] = '\0';