17 "toosmall", ARtoosmall,
22 rpcread(AuthRpc *rpc, void *buf, int buflen)
25 return read(rpc->afd, buf, buflen);
27 return fsread(rpc->afid, buf, buflen);
31 rpcwrite(AuthRpc *rpc, void *buf, int buflen)
34 return write(rpc->afd, buf, buflen);
36 return fswrite(rpc->afid, buf, buflen);
40 classify(char *buf, uint n, AuthRpc *rpc)
44 for(i=0; i<nelem(tab); i++){
45 len = strlen(tab[i].verb);
46 if(n >= len && memcmp(buf, tab[i].verb, len) == 0 && (n==len || buf[len]==' ')){
51 rpc->narg = n - (len+1);
52 rpc->arg = (char*)buf+len+1;
57 werrstr("malformed rpc response: %s", buf);
66 rpc = mallocz(sizeof(*rpc), 1);
69 rpc->afd = open("/mnt/factotum/rpc", ORDWR);
71 rpc->afid = nsopen("factotum", nil, "rpc", ORDWR);
81 auth_freerpc(AuthRpc *rpc)
93 auth_rpc(AuthRpc *rpc, char *verb, void *a, int na)
99 if(na+l+1 > AuthRpcMax){
100 werrstr("rpc too big");
104 memmove(rpc->obuf, verb, l);
106 memmove(rpc->obuf+l+1, a, na);
107 if((n=rpcwrite(rpc, rpc->obuf, l+1+na)) != l+1+na){
109 werrstr("auth_rpc short write");
113 if((n=rpcread(rpc, rpc->ibuf, AuthRpcMax)) < 0)
118 * Set error string for good default behavior.
120 switch(type = classify(rpc->ibuf, n, rpc)){
122 werrstr("unknown rpc type %d (bug in auth_rpc.c)", type);
130 werrstr("unspecified rpc error");
132 werrstr("%s", rpc->arg);
135 werrstr("needkey %s", rpc->arg);
138 if(getfields(rpc->arg, f, nelem(f), 0, "\n") < 2)
139 werrstr("badkey %s", rpc->arg);
141 werrstr("badkey %s", f[1]);
144 werrstr("phase error %s", rpc->arg);