12 gstring(uchar *p, uchar *ep, char **s)
32 gcarray(uchar *p, uchar *ep, uchar **s, int *np)
54 auth_freeAI(AuthInfo *ai)
66 convM2AI(uchar *p, int n, AuthInfo **aip)
71 ai = mallocz(sizeof(*ai), 1);
75 p = gstring(p, e, &ai->cuid);
76 p = gstring(p, e, &ai->suid);
77 p = gstring(p, e, &ai->cap);
78 p = gcarray(p, e, &ai->secret, &ai->nsecret);
87 auth_getinfo(AuthRpc *rpc)
91 if(auth_rpc(rpc, "authinfo", nil, 0) != ARok)
93 if(convM2AI((uchar*)rpc->arg, rpc->narg, &a) == nil){
94 werrstr("bad auth info from factotum");
101 dorpc(AuthRpc *rpc, char *verb, char *val, int len, AuthGetkey *getkey)
106 if((ret = auth_rpc(rpc, verb, val, len)) != ARneedkey && ret != ARbadkey)
109 return ARgiveup; /* don't know how */
110 if((*getkey)(rpc->arg) < 0)
111 return ARgiveup; /* user punted */
116 * this just proxies what the factotum tells it to.
119 fauth_proxy(int fd, AuthRpc *rpc, AuthGetkey *getkey, char *params)
127 werrstr("fauth_proxy - no factotum");
131 rerrstr(oerr, sizeof oerr);
132 werrstr("UNKNOWN AUTH ERROR");
134 if(dorpc(rpc, "start", params, strlen(params), getkey) != ARok){
135 werrstr("fauth_proxy start: %r");
139 buf = malloc(AuthRpcMax);
143 switch(dorpc(rpc, "read", nil, 0, getkey)){
146 a = auth_getinfo(rpc);
147 /* no error, restore whatever was there */
148 errstr(oerr, sizeof oerr);
151 if(write(fd, rpc->arg, rpc->narg) != rpc->narg){
152 werrstr("auth_proxy write fd: %r");
158 memset(buf, 0, AuthRpcMax);
159 while((ret = dorpc(rpc, "write", buf, n, getkey)) == ARtoosmall){
161 if(m <= n || m > AuthRpcMax)
163 m = read(fd, buf + n, m - n);
166 werrstr("auth_proxy short read");
168 werrstr("auth_proxy read fd: %r");
174 werrstr("auth_proxy rpc write: %r");
179 werrstr("auth_proxy rpc: %r");
189 auth_proxy(int fd, AuthGetkey *getkey, char *fmt, ...)
197 quotefmtinstall(); /* just in case */
199 p = vsmprint(fmt, arg);
203 afd = open("/mnt/factotum/rpc", ORDWR);
205 werrstr("opening /mnt/factotum/rpc: %r");
210 rpc = auth_allocrpc(afd);
212 ai = fauth_proxy(fd, rpc, getkey, p);