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)
94 if(convM2AI((uchar*)rpc->arg, rpc->narg, &a) == nil){
95 werrstr("bad auth info from factotum");
102 dorpc(AuthRpc *rpc, char *verb, char *val, int len, AuthGetkey *getkey)
107 if((ret = auth_rpc(rpc, verb, val, len)) != ARneedkey && ret != ARbadkey)
110 return ARgiveup; /* don't know how */
111 if((*getkey)(rpc->arg) < 0)
112 return ARgiveup; /* user punted */
117 * this just proxies what the factotum tells it to.
120 fauth_proxy(int fd, AuthRpc *rpc, AuthGetkey *getkey, char *params)
127 rerrstr(oerr, sizeof oerr);
128 werrstr("UNKNOWN AUTH ERROR");
130 if(dorpc(rpc, "start", params, strlen(params), getkey) != ARok){
131 werrstr("fauth_proxy start: %r");
135 buf = malloc(AuthRpcMax);
139 switch(dorpc(rpc, "read", nil, 0, getkey)){
142 a = auth_getinfo(rpc);
143 errstr(oerr, sizeof oerr); /* no error, restore whatever was there */
146 if(write(fd, rpc->arg, rpc->narg) != rpc->narg){
147 werrstr("auth_proxy write fd: %r");
153 memset(buf, 0, AuthRpcMax);
154 while((ret = dorpc(rpc, "write", buf, n, getkey)) == ARtoosmall){
155 if(atoi(rpc->arg) > AuthRpcMax)
157 m = read(fd, buf+n, atoi(rpc->arg)-n);
160 werrstr("auth_proxy short read: %s", buf);
166 werrstr("auth_proxy rpc write: %s: %r", buf);
171 werrstr("auth_proxy rpc: %r");
181 auth_proxy(int fd, AuthGetkey *getkey, char *fmt, ...)
188 quotefmtinstall(); /* just in case */
190 p = vsmprint(fmt, arg);
193 rpc = auth_allocrpc();
199 ai = fauth_proxy(fd, rpc, getkey, p);
206 * this just proxies what the factotum tells it to.
209 fsfauth_proxy(CFid *fid, AuthRpc *rpc, AuthGetkey *getkey, char *params)
216 rerrstr(oerr, sizeof oerr);
217 werrstr("UNKNOWN AUTH ERROR");
219 if(dorpc(rpc, "start", params, strlen(params), getkey) != ARok){
220 werrstr("fauth_proxy start: %r");
224 buf = malloc(AuthRpcMax);
228 switch(dorpc(rpc, "read", nil, 0, getkey)){
231 a = auth_getinfo(rpc);
232 errstr(oerr, sizeof oerr); /* no error, restore whatever was there */
235 if(fswrite(fid, rpc->arg, rpc->narg) != rpc->narg){
236 werrstr("auth_proxy write fid: %r");
242 memset(buf, 0, AuthRpcMax);
243 while((ret = dorpc(rpc, "write", buf, n, getkey)) == ARtoosmall){
244 if(atoi(rpc->arg) > AuthRpcMax)
246 m = fsread(fid, buf+n, atoi(rpc->arg)-n);
249 werrstr("auth_proxy short read: %s", buf);
255 werrstr("auth_proxy rpc write: %s: %r", buf);
260 werrstr("auth_proxy rpc: %r");
270 fsauth_proxy(CFid *fid, AuthGetkey *getkey, char *fmt, ...)
277 quotefmtinstall(); /* just in case */
279 p = vsmprint(fmt, arg);
282 rpc = auth_allocrpc();
288 ai = fsfauth_proxy(fid, rpc, getkey, p);