diff options
author | rsc <devnull@localhost> | 2005-02-08 20:58:10 +0000 |
---|---|---|
committer | rsc <devnull@localhost> | 2005-02-08 20:58:10 +0000 |
commit | 648bb6f75a801e6d605fcd061f0b14fecc07a8be (patch) | |
tree | ae995dfa5c1807dfa8902f5120ef6933911aebb5 /src/libauth/auth_proxy.c | |
parent | fa467fbe51e3aba23fce6639afd8939c046c8c2d (diff) | |
download | plan9port-648bb6f75a801e6d605fcd061f0b14fecc07a8be.tar.gz plan9port-648bb6f75a801e6d605fcd061f0b14fecc07a8be.tar.bz2 plan9port-648bb6f75a801e6d605fcd061f0b14fecc07a8be.zip |
lucho changes
Diffstat (limited to 'src/libauth/auth_proxy.c')
-rw-r--r-- | src/libauth/auth_proxy.c | 95 |
1 files changed, 88 insertions, 7 deletions
diff --git a/src/libauth/auth_proxy.c b/src/libauth/auth_proxy.c index 186031eb..436c1b77 100644 --- a/src/libauth/auth_proxy.c +++ b/src/libauth/auth_proxy.c @@ -2,6 +2,7 @@ #include <libc.h> #include <fcall.h> #include <auth.h> +#include <9pclient.h> #include "authlocal.h" enum { @@ -179,7 +180,6 @@ Error: AuthInfo* auth_proxy(int fd, AuthGetkey *getkey, char *fmt, ...) { - int afd; char *p; va_list arg; AuthInfo *ai; @@ -190,23 +190,104 @@ auth_proxy(int fd, AuthGetkey *getkey, char *fmt, ...) p = vsmprint(fmt, arg); va_end(arg); - afd = open("/mnt/factotum/rpc", ORDWR); - if(afd < 0){ - werrstr("opening /mnt/factotum/rpc: %r"); + rpc = auth_allocrpc(); + if(rpc == nil){ free(p); return nil; } - rpc = auth_allocrpc(afd); + ai = fauth_proxy(fd, rpc, getkey, p); + free(p); + auth_freerpc(rpc); + return ai; +} + +/* + * this just proxies what the factotum tells it to. + */ +AuthInfo* +fsfauth_proxy(CFid *fid, AuthRpc *rpc, AuthGetkey *getkey, char *params) +{ + char *buf; + int m, n, ret; + AuthInfo *a; + char oerr[ERRMAX]; + + rerrstr(oerr, sizeof oerr); + werrstr("UNKNOWN AUTH ERROR"); + + if(dorpc(rpc, "start", params, strlen(params), getkey) != ARok){ + werrstr("fauth_proxy start: %r"); + return nil; + } + + buf = malloc(AuthRpcMax); + if(buf == nil) + return nil; + for(;;){ + switch(dorpc(rpc, "read", nil, 0, getkey)){ + case ARdone: + free(buf); + a = auth_getinfo(rpc); + errstr(oerr, sizeof oerr); /* no error, restore whatever was there */ + return a; + case ARok: + if(fswrite(fid, rpc->arg, rpc->narg) != rpc->narg){ + werrstr("auth_proxy write fid: %r"); + goto Error; + } + break; + case ARphase: + n = 0; + memset(buf, 0, AuthRpcMax); + while((ret = dorpc(rpc, "write", buf, n, getkey)) == ARtoosmall){ + if(atoi(rpc->arg) > AuthRpcMax) + break; + m = fsread(fid, buf+n, atoi(rpc->arg)-n); + if(m <= 0){ + if(m == 0) + werrstr("auth_proxy short read: %s", buf); + goto Error; + } + n += m; + } + if(ret != ARok){ + werrstr("auth_proxy rpc write: %s: %r", buf); + goto Error; + } + break; + default: + werrstr("auth_proxy rpc: %r"); + goto Error; + } + } +Error: + free(buf); + return nil; +} + +AuthInfo* +fsauth_proxy(CFid *fid, AuthGetkey *getkey, char *fmt, ...) +{ + char *p; + va_list arg; + AuthInfo *ai; + AuthRpc *rpc; + + quotefmtinstall(); /* just in case */ + va_start(arg, fmt); + p = vsmprint(fmt, arg); + va_end(arg); + + rpc = auth_allocrpc(); if(rpc == nil){ free(p); return nil; } - ai = fauth_proxy(fd, rpc, getkey, p); + ai = fsfauth_proxy(fid, rpc, getkey, p); free(p); auth_freerpc(rpc); - close(afd); return ai; } |