URI:
       tauth_respond.c - plan9port - [fork] Plan 9 from user space
  HTML git clone git://src.adamsgaard.dk/plan9port
   DIR Log
   DIR Files
   DIR Refs
   DIR README
   DIR LICENSE
       ---
       tauth_respond.c (1295B)
       ---
            1 #include <u.h>
            2 #include <libc.h>
            3 #include <auth.h>
            4 #include <authsrv.h>
            5 #include "authlocal.h"
            6 
            7 enum {
            8         ARgiveup = 100
            9 };
           10 
           11 static int
           12 dorpc(AuthRpc *rpc, char *verb, char *val, int len, AuthGetkey *getkey)
           13 {
           14         int ret;
           15 
           16         for(;;){
           17                 if((ret = auth_rpc(rpc, verb, val, len)) != ARneedkey && ret != ARbadkey)
           18                         return ret;
           19                 if(getkey == nil)
           20                         return ARgiveup;        /* don't know how */
           21                 if((*getkey)(rpc->arg) < 0)
           22                         return ARgiveup;        /* user punted */
           23         }
           24 }
           25 
           26 int
           27 auth_respond(void *chal, uint nchal, char *user, uint nuser, void *resp, uint nresp, AuthGetkey *getkey, char *fmt, ...)
           28 {
           29         char *p, *s;
           30         va_list arg;
           31         AuthRpc *rpc;
           32         Attr *a;
           33 
           34         if((rpc = auth_allocrpc()) == nil)
           35                 return -1;
           36 
           37         quotefmtinstall();        /* just in case */
           38         va_start(arg, fmt);
           39         p = vsmprint(fmt, arg);
           40         va_end(arg);
           41 
           42         if(p==nil
           43         || dorpc(rpc, "start", p, strlen(p), getkey) != ARok
           44         || dorpc(rpc, "write", chal, nchal, getkey) != ARok
           45         || dorpc(rpc, "read", nil, 0, getkey) != ARok){
           46                 free(p);
           47                 auth_freerpc(rpc);
           48                 return -1;
           49         }
           50         free(p);
           51 
           52         if(rpc->narg < nresp)
           53                 nresp = rpc->narg;
           54         memmove(resp, rpc->arg, nresp);
           55 
           56         if((a = auth_attr(rpc)) != nil
           57         && (s = _strfindattr(a, "user")) != nil && strlen(s) < nuser)
           58                 strcpy(user, s);
           59         else if(nuser > 0)
           60                 user[0] = '\0';
           61 
           62         _freeattr(a);
           63         auth_freerpc(rpc);
           64         return nresp;
           65 }