16 "toosmall", ARtoosmall,
21 classify(char *buf, uint n, AuthRpc *rpc)
25 for(i=0; i<nelem(tab); i++){
26 len = strlen(tab[i].verb);
27 if(n >= len && memcmp(buf, tab[i].verb, len) == 0 && (n==len || buf[len]==' ')){
32 rpc->narg = n - (len+1);
33 rpc->arg = (char*)buf+len+1;
38 werrstr("malformed rpc response: %s", buf);
43 auth_allocrpc(int afd)
47 rpc = mallocz(sizeof(*rpc), 1);
55 auth_freerpc(AuthRpc *rpc)
61 auth_rpc(AuthRpc *rpc, char *verb, void *a, int na)
67 if(na+l+1 > AuthRpcMax){
68 werrstr("rpc too big");
72 memmove(rpc->obuf, verb, l);
74 memmove(rpc->obuf+l+1, a, na);
75 if((n=write(rpc->afd, rpc->obuf, l+1+na)) != l+1+na){
77 werrstr("auth_rpc short write");
81 if((n=read(rpc->afd, rpc->ibuf, AuthRpcMax)) < 0)
86 * Set error string for good default behavior.
88 switch(type = classify(rpc->ibuf, n, rpc)){
90 werrstr("unknown rpc type %d (bug in auth_rpc.c)", type);
98 werrstr("unspecified rpc error");
100 werrstr("%s", rpc->arg);
103 werrstr("needkey %s", rpc->arg);
106 if(getfields(rpc->arg, f, nelem(f), 0, "\n") < 2)
107 werrstr("badkey %s", rpc->arg);
109 werrstr("badkey %s", f[1]);
112 werrstr("phase error %s", rpc->arg);