lucho changes

This commit is contained in:
rsc 2005-02-08 20:58:10 +00:00
parent fa467fbe51
commit 648bb6f75a
9 changed files with 147 additions and 75 deletions

View file

@ -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';