8 gstring(uchar *p, uchar *ep, char **s)
28 gcarray(uchar *p, uchar *ep, uchar **s, int *np)
50 convM2AI(uchar *p, int n, AuthInfo **aip)
55 ai = mallocz(sizeof(*ai), 1);
59 p = gstring(p, e, &ai->cuid);
60 p = gstring(p, e, &ai->suid);
61 p = gstring(p, e, &ai->cap);
62 p = gcarray(p, e, &ai->secret, &ai->nsecret);
71 dorpc(AuthRpc *rpc, char *verb, char *val, int len, AuthGetkey *getkey)
76 if((ret = auth_rpc(rpc, verb, val, len)) != ARneedkey && ret != ARbadkey)
79 return ARgiveup; /* don't know how */
80 if((*getkey)(rpc->arg) < 0)
81 return ARgiveup; /* user punted */
86 doread(Session *s, Fid *f, void *buf, int n)
88 s->f.fid = f - s->fids;
91 if(xmesg(s, Tread) < 0)
94 memmove(buf, s->f.data, n);
99 dowrite(Session *s, Fid *f, void *buf, int n)
101 s->f.fid = f - s->fids;
104 s->f.data = (char *)buf;
105 if(xmesg(s, Twrite) < 0)
111 * this just proxies what the factotum tells it to.
114 authproto(Session *s, Fid *f, AuthRpc *rpc, AuthGetkey *getkey, char *params)
121 rerrstr(oerr, sizeof oerr);
122 werrstr("UNKNOWN AUTH ERROR");
124 if(dorpc(rpc, "start", params, strlen(params), getkey) != ARok){
125 werrstr("fauth_proxy start: %r");
129 buf = malloc(AuthRpcMax);
133 switch(dorpc(rpc, "read", nil, 0, getkey)){
136 a = auth_getinfo(rpc);
137 errstr(oerr, sizeof oerr); /* no error, restore whatever was there */
140 if(dowrite(s, f, rpc->arg, rpc->narg) != rpc->narg){
141 werrstr("auth_proxy write fd: %r");
147 memset(buf, 0, AuthRpcMax);
148 while((ret = dorpc(rpc, "write", buf, n, getkey)) == ARtoosmall){
149 if(atoi(rpc->arg) > AuthRpcMax)
151 m = doread(s, f, buf+n, atoi(rpc->arg)-n);
154 werrstr("auth_proxy short read: %s", buf);
160 werrstr("auth_proxy rpc write: %s: %r", buf);
165 werrstr("auth_proxy rpc: %r");
174 /* returns 0 if auth succeeded (or unneeded), -1 otherwise */
176 authhostowner(Session *s)
184 /* get a fid to authenticate over */
187 s->f.afid = af - s->fids;
188 s->f.uname = getuser();
189 s->f.aname = s->spec;
196 quotefmtinstall(); /* just in case */
198 afd = open("/mnt/factotum/rpc", ORDWR);
200 werrstr("opening /mnt/factotum/rpc: %r");
204 rpc = auth_allocrpc(afd);
208 ai = authproto(s, af, rpc, auth_getkey, "proto=p9any role=client");
216 /* try attaching with the afid */
217 chat("attaching as hostowner...");
219 s->f.fid = f - s->fids;
220 s->f.afid = af - s->fids;;
221 s->f.uname = getuser();
222 s->f.aname = s->spec;
223 if(xmesg(s, Tattach) == 0)
228 s->f.fid = af - s->fids;
233 s->f.fid = f - s->fids;