URI:
       tauth_getuserpasswd.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_getuserpasswd.c (1275B)
       ---
            1 #include <u.h>
            2 #include <libc.h>
            3 #include <auth.h>
            4 #include "authlocal.h"
            5 
            6 enum {
            7         ARgiveup = 100
            8 };
            9 
           10 static int
           11 dorpc(AuthRpc *rpc, char *verb, char *val, int len, AuthGetkey *getkey)
           12 {
           13         int ret;
           14 
           15         for(;;){
           16                 if((ret = auth_rpc(rpc, verb, val, len)) != ARneedkey && ret != ARbadkey)
           17                         return ret;
           18                 if(getkey == nil)
           19                         return ARgiveup;        /* don't know how */
           20                 if((*getkey)(rpc->arg) < 0)
           21                         return ARgiveup;        /* user punted */
           22         }
           23 }
           24 
           25 UserPasswd*
           26 auth_getuserpasswd(AuthGetkey *getkey, char *fmt, ...)
           27 {
           28         AuthRpc *rpc;
           29         char *f[3], *p, *params;
           30         va_list arg;
           31         UserPasswd *up;
           32 
           33         up = nil;
           34         rpc = nil;
           35         params = nil;
           36 
           37         rpc = auth_allocrpc();
           38         if(rpc == nil)
           39                 goto out;
           40         quotefmtinstall();        /* just in case */
           41         va_start(arg, fmt);
           42         params = vsmprint(fmt, arg);
           43         va_end(arg);
           44         if(params == nil)
           45                 goto out;
           46 
           47         if(dorpc(rpc, "start", params, strlen(params), getkey) != ARok
           48         || dorpc(rpc, "read", nil, 0, getkey) != ARok)
           49                 goto out;
           50 
           51         rpc->arg[rpc->narg] = '\0';
           52         if(tokenize(rpc->arg, f, 2) != 2){
           53                 werrstr("bad answer from factotum");
           54                 goto out;
           55         }
           56         up = malloc(sizeof(*up)+rpc->narg+1);
           57         if(up == nil)
           58                 goto out;
           59         p = (char*)&up[1];
           60         strcpy(p, f[0]);
           61         up->user = p;
           62         p += strlen(p)+1;
           63         strcpy(p, f[1]);
           64         up->passwd = p;
           65 
           66 out:
           67         free(params);
           68         auth_freerpc(rpc);
           69         return up;
           70 }