diff options
author | rsc <devnull@localhost> | 2004-06-17 03:27:35 +0000 |
---|---|---|
committer | rsc <devnull@localhost> | 2004-06-17 03:27:35 +0000 |
commit | be8b315d1522fa1c109a49435c1638bafd838b91 (patch) | |
tree | 4d8e2a0799ab463160b0a80feb0a008940d11230 /src/libauth/auth_getuserpasswd.c | |
parent | d9c8a7c5366aea63aa45b4afc6a75d133192786d (diff) | |
download | plan9port-be8b315d1522fa1c109a49435c1638bafd838b91.tar.gz plan9port-be8b315d1522fa1c109a49435c1638bafd838b91.tar.bz2 plan9port-be8b315d1522fa1c109a49435c1638bafd838b91.zip |
basically none of these build
Diffstat (limited to 'src/libauth/auth_getuserpasswd.c')
-rw-r--r-- | src/libauth/auth_getuserpasswd.c | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/src/libauth/auth_getuserpasswd.c b/src/libauth/auth_getuserpasswd.c new file mode 100644 index 00000000..4d66dcec --- /dev/null +++ b/src/libauth/auth_getuserpasswd.c @@ -0,0 +1,75 @@ +#include <u.h> +#include <libc.h> +#include <auth.h> +#include "authlocal.h" + +enum { + ARgiveup = 100, +}; + +static int +dorpc(AuthRpc *rpc, char *verb, char *val, int len, AuthGetkey *getkey) +{ + int ret; + + for(;;){ + if((ret = auth_rpc(rpc, verb, val, len)) != ARneedkey && ret != ARbadkey) + return ret; + if(getkey == nil) + return ARgiveup; /* don't know how */ + if((*getkey)(rpc->arg) < 0) + return ARgiveup; /* user punted */ + } +} + +UserPasswd* +auth_getuserpasswd(AuthGetkey *getkey, char *fmt, ...) +{ + AuthRpc *rpc; + char *f[3], *p, *params; + int fd; + va_list arg; + UserPasswd *up; + + up = nil; + rpc = nil; + params = nil; + + fd = open("/mnt/factotum/rpc", ORDWR); + if(fd < 0) + goto out; + rpc = auth_allocrpc(fd); + if(rpc == nil) + goto out; + quotefmtinstall(); /* just in case */ + va_start(arg, fmt); + params = vsmprint(fmt, arg); + va_end(arg); + if(params == nil) + goto out; + + if(dorpc(rpc, "start", params, strlen(params), getkey) != ARok + || dorpc(rpc, "read", nil, 0, getkey) != ARok) + goto out; + + rpc->arg[rpc->narg] = '\0'; + if(tokenize(rpc->arg, f, 2) != 2){ + werrstr("bad answer from factotum"); + goto out; + } + up = malloc(sizeof(*up)+rpc->narg+1); + if(up == nil) + goto out; + p = (char*)&up[1]; + strcpy(p, f[0]); + up->user = p; + p += strlen(p)+1; + strcpy(p, f[1]); + up->passwd = p; + +out: + free(params); + auth_freerpc(rpc); + close(fd); + return up; +} |