13 gstring(uchar *p, uchar *ep, char **s)
33 gcarray(uchar *p, uchar *ep, uchar **s, int *np)
55 auth_freeAI(AuthInfo *ai)
67 convM2AI(uchar *p, int n, AuthInfo **aip)
72 ai = mallocz(sizeof(*ai), 1);
76 p = gstring(p, e, &ai->cuid);
77 p = gstring(p, e, &ai->suid);
78 p = gstring(p, e, &ai->cap);
79 p = gcarray(p, e, &ai->secret, &ai->nsecret);
88 auth_getinfo(AuthRpc *rpc)
92 if(auth_rpc(rpc, "authinfo", nil, 0) != ARok)
95 if(convM2AI((uchar*)rpc->arg, rpc->narg, &a) == nil){
96 werrstr("bad auth info from factotum");
103 dorpc(AuthRpc *rpc, char *verb, char *val, int len, AuthGetkey *getkey)
108 if((ret = auth_rpc(rpc, verb, val, len)) != ARneedkey && ret != ARbadkey)
111 return ARgiveup; /* don't know how */
112 if((*getkey)(rpc->arg) < 0)
113 return ARgiveup; /* user punted */
118 * this just proxies what the factotum tells it to.
121 fauth_proxy(int fd, AuthRpc *rpc, AuthGetkey *getkey, char *params)
128 rerrstr(oerr, sizeof oerr);
129 werrstr("UNKNOWN AUTH ERROR");
131 if(dorpc(rpc, "start", params, strlen(params), getkey) != ARok){
132 werrstr("fauth_proxy start: %r");
136 buf = malloc(AuthRpcMax);
140 switch(dorpc(rpc, "read", nil, 0, getkey)){
143 a = auth_getinfo(rpc);
144 errstr(oerr, sizeof oerr); /* no error, restore whatever was there */
147 if(write(fd, rpc->arg, rpc->narg) != rpc->narg){
148 werrstr("auth_proxy write fd: %r");
154 memset(buf, 0, AuthRpcMax);
155 while((ret = dorpc(rpc, "write", buf, n, getkey)) == ARtoosmall){
156 if(atoi(rpc->arg) > AuthRpcMax)
158 m = read(fd, buf+n, atoi(rpc->arg)-n);
161 werrstr("auth_proxy short read: %s", buf);
167 werrstr("auth_proxy rpc write: %s: %r", buf);
172 werrstr("auth_proxy rpc: %r");
182 auth_proxy(int fd, AuthGetkey *getkey, char *fmt, ...)
189 quotefmtinstall(); /* just in case */
191 p = vsmprint(fmt, arg);
194 rpc = auth_allocrpc();
200 ai = fauth_proxy(fd, rpc, getkey, p);
207 * this just proxies what the factotum tells it to.
210 fsfauth_proxy(CFid *fid, AuthRpc *rpc, AuthGetkey *getkey, char *params)
217 rerrstr(oerr, sizeof oerr);
218 werrstr("UNKNOWN AUTH ERROR");
220 if(dorpc(rpc, "start", params, strlen(params), getkey) != ARok){
221 werrstr("fauth_proxy start: %r");
225 buf = malloc(AuthRpcMax);
229 switch(dorpc(rpc, "read", nil, 0, getkey)){
232 a = auth_getinfo(rpc);
233 errstr(oerr, sizeof oerr); /* no error, restore whatever was there */
236 if(fswrite(fid, rpc->arg, rpc->narg) != rpc->narg){
237 werrstr("auth_proxy write fid: %r");
243 memset(buf, 0, AuthRpcMax);
244 while((ret = dorpc(rpc, "write", buf, n, getkey)) == ARtoosmall){
245 if(atoi(rpc->arg) > AuthRpcMax)
247 m = fsread(fid, buf+n, atoi(rpc->arg)-n);
250 werrstr("auth_proxy short read: %s", buf);
256 werrstr("auth_proxy rpc write: %s: %r", buf);
261 werrstr("auth_proxy rpc: %r");
271 fsauth_proxy(CFid *fid, AuthGetkey *getkey, char *fmt, ...)
278 quotefmtinstall(); /* just in case */
280 p = vsmprint(fmt, arg);
283 rpc = auth_allocrpc();
289 ai = fsfauth_proxy(fid, rpc, getkey, p);