1e8636dfdSBill Paul /* 2e8636dfdSBill Paul * Sun RPC is a product of Sun Microsystems, Inc. and is provided for 3e8636dfdSBill Paul * unrestricted use provided that this legend is included on all tape 4e8636dfdSBill Paul * media and as a part of the software program in whole or part. Users 5e8636dfdSBill Paul * may copy or modify Sun RPC without charge, but are not authorized 6e8636dfdSBill Paul * to license or distribute it to anyone else except as part of a product or 7e8636dfdSBill Paul * program developed by the user. 8e8636dfdSBill Paul * 9e8636dfdSBill Paul * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE 10e8636dfdSBill Paul * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR 11e8636dfdSBill Paul * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. 12e8636dfdSBill Paul * 13e8636dfdSBill Paul * Sun RPC is provided with no support and without any obligation on the 14e8636dfdSBill Paul * part of Sun Microsystems, Inc. to assist in its use, correction, 15e8636dfdSBill Paul * modification or enhancement. 16e8636dfdSBill Paul * 17e8636dfdSBill Paul * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE 18e8636dfdSBill Paul * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC 19e8636dfdSBill Paul * OR ANY PART THEREOF. 20e8636dfdSBill Paul * 21e8636dfdSBill Paul * In no event will Sun Microsystems, Inc. be liable for any lost revenue 22e8636dfdSBill Paul * or profits or other special, indirect and consequential damages, even if 23e8636dfdSBill Paul * Sun has been advised of the possibility of such damages. 24e8636dfdSBill Paul * 25e8636dfdSBill Paul * Sun Microsystems, Inc. 26e8636dfdSBill Paul * 2550 Garcia Avenue 27e8636dfdSBill Paul * Mountain View, California 94043 28e8636dfdSBill Paul */ 29e8636dfdSBill Paul /* 30e8636dfdSBill Paul * Copyright (c) 1986-1991 by Sun Microsystems Inc. 3192927338SJason Evans * 3292927338SJason Evans * $FreeBSD$ 33e8636dfdSBill Paul */ 34e8636dfdSBill Paul 35e8636dfdSBill Paul #ident "@(#)key_call.c 1.25 94/04/24 SMI" 36e8636dfdSBill Paul 37e8636dfdSBill Paul /* 38e8636dfdSBill Paul * key_call.c, Interface to keyserver 39e8636dfdSBill Paul * 40e8636dfdSBill Paul * setsecretkey(key) - set your secret key 41e8636dfdSBill Paul * encryptsessionkey(agent, deskey) - encrypt a session key to talk to agent 42e8636dfdSBill Paul * decryptsessionkey(agent, deskey) - decrypt ditto 43e8636dfdSBill Paul * gendeskey(deskey) - generate a secure des key 44e8636dfdSBill Paul */ 45e8636dfdSBill Paul 46d201fe46SDaniel Eischen #include "namespace.h" 47e8636dfdSBill Paul #include <stdio.h> 48e8636dfdSBill Paul #include <stdlib.h> 49e8636dfdSBill Paul #include <unistd.h> 50e8636dfdSBill Paul #include <errno.h> 51e8636dfdSBill Paul #include <rpc/rpc.h> 52e8636dfdSBill Paul #include <rpc/auth.h> 53e8636dfdSBill Paul #include <rpc/auth_unix.h> 54e8636dfdSBill Paul #include <rpc/key_prot.h> 55e8636dfdSBill Paul #include <string.h> 56e8636dfdSBill Paul #include <sys/utsname.h> 57e8636dfdSBill Paul #include <stdlib.h> 58e8636dfdSBill Paul #include <signal.h> 59e8636dfdSBill Paul #include <sys/wait.h> 60e8636dfdSBill Paul #include <sys/fcntl.h> 61d201fe46SDaniel Eischen #include "un-namespace.h" 62e8636dfdSBill Paul 63e8636dfdSBill Paul 64e8636dfdSBill Paul #define KEY_TIMEOUT 5 /* per-try timeout in seconds */ 65e8636dfdSBill Paul #define KEY_NRETRY 12 /* number of retries */ 66e8636dfdSBill Paul 67e8636dfdSBill Paul #ifdef DEBUG 68e8636dfdSBill Paul #define debug(msg) (void) fprintf(stderr, "%s\n", msg); 69e8636dfdSBill Paul #else 70e8636dfdSBill Paul #define debug(msg) 71e8636dfdSBill Paul #endif /* DEBUG */ 72e8636dfdSBill Paul 73e8636dfdSBill Paul /* 74e8636dfdSBill Paul * Hack to allow the keyserver to use AUTH_DES (for authenticated 75e8636dfdSBill Paul * NIS+ calls, for example). The only functions that get called 76e8636dfdSBill Paul * are key_encryptsession_pk, key_decryptsession_pk, and key_gendes. 77e8636dfdSBill Paul * 78e8636dfdSBill Paul * The approach is to have the keyserver fill in pointers to local 79e8636dfdSBill Paul * implementations of these functions, and to call those in key_call(). 80e8636dfdSBill Paul */ 81e8636dfdSBill Paul 82e8636dfdSBill Paul cryptkeyres *(*__key_encryptsession_pk_LOCAL)() = 0; 83e8636dfdSBill Paul cryptkeyres *(*__key_decryptsession_pk_LOCAL)() = 0; 84e8636dfdSBill Paul des_block *(*__key_gendes_LOCAL)() = 0; 85e8636dfdSBill Paul 86e8636dfdSBill Paul static int key_call __P(( u_long, xdrproc_t, char *, xdrproc_t, char * )); 87e8636dfdSBill Paul 88e8636dfdSBill Paul int 89e8636dfdSBill Paul key_setsecret(secretkey) 90e8636dfdSBill Paul const char *secretkey; 91e8636dfdSBill Paul { 92e8636dfdSBill Paul keystatus status; 93e8636dfdSBill Paul 94e8636dfdSBill Paul if (!key_call((u_long) KEY_SET, xdr_keybuf, (char *) secretkey, 95e8636dfdSBill Paul xdr_keystatus, (char *)&status)) { 96e8636dfdSBill Paul return (-1); 97e8636dfdSBill Paul } 98e8636dfdSBill Paul if (status != KEY_SUCCESS) { 99e8636dfdSBill Paul debug("set status is nonzero"); 100e8636dfdSBill Paul return (-1); 101e8636dfdSBill Paul } 102e8636dfdSBill Paul return (0); 103e8636dfdSBill Paul } 104e8636dfdSBill Paul 105e8636dfdSBill Paul 106e8636dfdSBill Paul /* key_secretkey_is_set() returns 1 if the keyserver has a secret key 107e8636dfdSBill Paul * stored for the caller's effective uid; it returns 0 otherwise 108e8636dfdSBill Paul * 109e8636dfdSBill Paul * N.B.: The KEY_NET_GET key call is undocumented. Applications shouldn't 110e8636dfdSBill Paul * be using it, because it allows them to get the user's secret key. 111e8636dfdSBill Paul */ 112e8636dfdSBill Paul 113e8636dfdSBill Paul int 114e8636dfdSBill Paul key_secretkey_is_set(void) 115e8636dfdSBill Paul { 116e8636dfdSBill Paul struct key_netstres kres; 117e8636dfdSBill Paul 118e8636dfdSBill Paul memset((void*)&kres, 0, sizeof (kres)); 119e8636dfdSBill Paul if (key_call((u_long) KEY_NET_GET, xdr_void, (char *)NULL, 120e8636dfdSBill Paul xdr_key_netstres, (char *) &kres) && 121e8636dfdSBill Paul (kres.status == KEY_SUCCESS) && 122e8636dfdSBill Paul (kres.key_netstres_u.knet.st_priv_key[0] != 0)) { 123e8636dfdSBill Paul /* avoid leaving secret key in memory */ 124e8636dfdSBill Paul memset(kres.key_netstres_u.knet.st_priv_key, 0, HEXKEYBYTES); 125e8636dfdSBill Paul return (1); 126e8636dfdSBill Paul } 127e8636dfdSBill Paul return (0); 128e8636dfdSBill Paul } 129e8636dfdSBill Paul 130e8636dfdSBill Paul int 131e8636dfdSBill Paul key_encryptsession_pk(remotename, remotekey, deskey) 132e8636dfdSBill Paul char *remotename; 133e8636dfdSBill Paul netobj *remotekey; 134e8636dfdSBill Paul des_block *deskey; 135e8636dfdSBill Paul { 136e8636dfdSBill Paul cryptkeyarg2 arg; 137e8636dfdSBill Paul cryptkeyres res; 138e8636dfdSBill Paul 139e8636dfdSBill Paul arg.remotename = remotename; 140e8636dfdSBill Paul arg.remotekey = *remotekey; 141e8636dfdSBill Paul arg.deskey = *deskey; 142e8636dfdSBill Paul if (!key_call((u_long)KEY_ENCRYPT_PK, xdr_cryptkeyarg2, (char *)&arg, 143e8636dfdSBill Paul xdr_cryptkeyres, (char *)&res)) { 144e8636dfdSBill Paul return (-1); 145e8636dfdSBill Paul } 146e8636dfdSBill Paul if (res.status != KEY_SUCCESS) { 147e8636dfdSBill Paul debug("encrypt status is nonzero"); 148e8636dfdSBill Paul return (-1); 149e8636dfdSBill Paul } 150e8636dfdSBill Paul *deskey = res.cryptkeyres_u.deskey; 151e8636dfdSBill Paul return (0); 152e8636dfdSBill Paul } 153e8636dfdSBill Paul 154e8636dfdSBill Paul int 155e8636dfdSBill Paul key_decryptsession_pk(remotename, remotekey, deskey) 156e8636dfdSBill Paul char *remotename; 157e8636dfdSBill Paul netobj *remotekey; 158e8636dfdSBill Paul des_block *deskey; 159e8636dfdSBill Paul { 160e8636dfdSBill Paul cryptkeyarg2 arg; 161e8636dfdSBill Paul cryptkeyres res; 162e8636dfdSBill Paul 163e8636dfdSBill Paul arg.remotename = remotename; 164e8636dfdSBill Paul arg.remotekey = *remotekey; 165e8636dfdSBill Paul arg.deskey = *deskey; 166e8636dfdSBill Paul if (!key_call((u_long)KEY_DECRYPT_PK, xdr_cryptkeyarg2, (char *)&arg, 167e8636dfdSBill Paul xdr_cryptkeyres, (char *)&res)) { 168e8636dfdSBill Paul return (-1); 169e8636dfdSBill Paul } 170e8636dfdSBill Paul if (res.status != KEY_SUCCESS) { 171e8636dfdSBill Paul debug("decrypt status is nonzero"); 172e8636dfdSBill Paul return (-1); 173e8636dfdSBill Paul } 174e8636dfdSBill Paul *deskey = res.cryptkeyres_u.deskey; 175e8636dfdSBill Paul return (0); 176e8636dfdSBill Paul } 177e8636dfdSBill Paul 178e8636dfdSBill Paul int 179e8636dfdSBill Paul key_encryptsession(remotename, deskey) 180e8636dfdSBill Paul const char *remotename; 181e8636dfdSBill Paul des_block *deskey; 182e8636dfdSBill Paul { 183e8636dfdSBill Paul cryptkeyarg arg; 184e8636dfdSBill Paul cryptkeyres res; 185e8636dfdSBill Paul 186e8636dfdSBill Paul arg.remotename = (char *) remotename; 187e8636dfdSBill Paul arg.deskey = *deskey; 188e8636dfdSBill Paul if (!key_call((u_long)KEY_ENCRYPT, xdr_cryptkeyarg, (char *)&arg, 189e8636dfdSBill Paul xdr_cryptkeyres, (char *)&res)) { 190e8636dfdSBill Paul return (-1); 191e8636dfdSBill Paul } 192e8636dfdSBill Paul if (res.status != KEY_SUCCESS) { 193e8636dfdSBill Paul debug("encrypt status is nonzero"); 194e8636dfdSBill Paul return (-1); 195e8636dfdSBill Paul } 196e8636dfdSBill Paul *deskey = res.cryptkeyres_u.deskey; 197e8636dfdSBill Paul return (0); 198e8636dfdSBill Paul } 199e8636dfdSBill Paul 200e8636dfdSBill Paul int 201e8636dfdSBill Paul key_decryptsession(remotename, deskey) 202e8636dfdSBill Paul const char *remotename; 203e8636dfdSBill Paul des_block *deskey; 204e8636dfdSBill Paul { 205e8636dfdSBill Paul cryptkeyarg arg; 206e8636dfdSBill Paul cryptkeyres res; 207e8636dfdSBill Paul 208e8636dfdSBill Paul arg.remotename = (char *) remotename; 209e8636dfdSBill Paul arg.deskey = *deskey; 210e8636dfdSBill Paul if (!key_call((u_long)KEY_DECRYPT, xdr_cryptkeyarg, (char *)&arg, 211e8636dfdSBill Paul xdr_cryptkeyres, (char *)&res)) { 212e8636dfdSBill Paul return (-1); 213e8636dfdSBill Paul } 214e8636dfdSBill Paul if (res.status != KEY_SUCCESS) { 215e8636dfdSBill Paul debug("decrypt status is nonzero"); 216e8636dfdSBill Paul return (-1); 217e8636dfdSBill Paul } 218e8636dfdSBill Paul *deskey = res.cryptkeyres_u.deskey; 219e8636dfdSBill Paul return (0); 220e8636dfdSBill Paul } 221e8636dfdSBill Paul 222e8636dfdSBill Paul int 223e8636dfdSBill Paul key_gendes(key) 224e8636dfdSBill Paul des_block *key; 225e8636dfdSBill Paul { 226e8636dfdSBill Paul if (!key_call((u_long)KEY_GEN, xdr_void, (char *)NULL, 227e8636dfdSBill Paul xdr_des_block, (char *)key)) { 228e8636dfdSBill Paul return (-1); 229e8636dfdSBill Paul } 230e8636dfdSBill Paul return (0); 231e8636dfdSBill Paul } 232e8636dfdSBill Paul 233e8636dfdSBill Paul int 234e8636dfdSBill Paul key_setnet(arg) 235e8636dfdSBill Paul struct netstarg *arg; 236e8636dfdSBill Paul { 237e8636dfdSBill Paul keystatus status; 238e8636dfdSBill Paul 239e8636dfdSBill Paul 240e8636dfdSBill Paul if (!key_call((u_long) KEY_NET_PUT, xdr_key_netstarg, (char *) arg, 241e8636dfdSBill Paul xdr_keystatus, (char *) &status)){ 242e8636dfdSBill Paul return (-1); 243e8636dfdSBill Paul } 244e8636dfdSBill Paul 245e8636dfdSBill Paul if (status != KEY_SUCCESS) { 246e8636dfdSBill Paul debug("key_setnet status is nonzero"); 247e8636dfdSBill Paul return (-1); 248e8636dfdSBill Paul } 249e8636dfdSBill Paul return (1); 250e8636dfdSBill Paul } 251e8636dfdSBill Paul 252e8636dfdSBill Paul 253e8636dfdSBill Paul int 254e8636dfdSBill Paul key_get_conv(pkey, deskey) 255e8636dfdSBill Paul char *pkey; 256e8636dfdSBill Paul des_block *deskey; 257e8636dfdSBill Paul { 258e8636dfdSBill Paul cryptkeyres res; 259e8636dfdSBill Paul 260e8636dfdSBill Paul if (!key_call((u_long) KEY_GET_CONV, xdr_keybuf, pkey, 261e8636dfdSBill Paul xdr_cryptkeyres, (char *)&res)) { 262e8636dfdSBill Paul return (-1); 263e8636dfdSBill Paul } 264e8636dfdSBill Paul if (res.status != KEY_SUCCESS) { 265e8636dfdSBill Paul debug("get_conv status is nonzero"); 266e8636dfdSBill Paul return (-1); 267e8636dfdSBill Paul } 268e8636dfdSBill Paul *deskey = res.cryptkeyres_u.deskey; 269e8636dfdSBill Paul return (0); 270e8636dfdSBill Paul } 271e8636dfdSBill Paul 272e8636dfdSBill Paul struct key_call_private { 273e8636dfdSBill Paul CLIENT *client; /* Client handle */ 274e8636dfdSBill Paul pid_t pid; /* process-id at moment of creation */ 275e8636dfdSBill Paul uid_t uid; /* user-id at last authorization */ 276e8636dfdSBill Paul }; 277e8636dfdSBill Paul static struct key_call_private *key_call_private_main = NULL; 278e8636dfdSBill Paul 279e8636dfdSBill Paul #ifdef foo 280e8636dfdSBill Paul static void 281e8636dfdSBill Paul key_call_destroy(void *vp) 282e8636dfdSBill Paul { 283e8636dfdSBill Paul register struct key_call_private *kcp = (struct key_call_private *)vp; 284e8636dfdSBill Paul 285e8636dfdSBill Paul if (kcp) { 286e8636dfdSBill Paul if (kcp->client) 287e8636dfdSBill Paul clnt_destroy(kcp->client); 288e8636dfdSBill Paul free(kcp); 289e8636dfdSBill Paul } 290e8636dfdSBill Paul } 291e8636dfdSBill Paul #endif 292e8636dfdSBill Paul 293e8636dfdSBill Paul /* 294e8636dfdSBill Paul * Keep the handle cached. This call may be made quite often. 295e8636dfdSBill Paul */ 296e8636dfdSBill Paul static CLIENT * 297e8636dfdSBill Paul getkeyserv_handle(vers) 298e8636dfdSBill Paul int vers; 299e8636dfdSBill Paul { 300e8636dfdSBill Paul struct key_call_private *kcp = key_call_private_main; 301e8636dfdSBill Paul struct timeval wait_time; 302e8636dfdSBill Paul int fd; 303e8636dfdSBill Paul struct sockaddr_un name; 304e8636dfdSBill Paul int namelen = sizeof(struct sockaddr_un); 305e8636dfdSBill Paul 306e8636dfdSBill Paul #define TOTAL_TIMEOUT 30 /* total timeout talking to keyserver */ 307e8636dfdSBill Paul #define TOTAL_TRIES 5 /* Number of tries */ 308e8636dfdSBill Paul 309e8636dfdSBill Paul if (kcp == (struct key_call_private *)NULL) { 310e8636dfdSBill Paul kcp = (struct key_call_private *)malloc(sizeof (*kcp)); 311e8636dfdSBill Paul if (kcp == (struct key_call_private *)NULL) { 312e8636dfdSBill Paul return ((CLIENT *) NULL); 313e8636dfdSBill Paul } 314e8636dfdSBill Paul key_call_private_main = kcp; 315e8636dfdSBill Paul kcp->client = NULL; 316e8636dfdSBill Paul } 317e8636dfdSBill Paul 318e8636dfdSBill Paul /* if pid has changed, destroy client and rebuild */ 319e8636dfdSBill Paul if (kcp->client != NULL && kcp->pid != getpid()) { 320e8636dfdSBill Paul clnt_destroy(kcp->client); 321e8636dfdSBill Paul kcp->client = NULL; 322e8636dfdSBill Paul } 323e8636dfdSBill Paul 324e8636dfdSBill Paul if (kcp->client != NULL) { 325e8636dfdSBill Paul /* if other side closed socket, build handle again */ 326e8636dfdSBill Paul clnt_control(kcp->client, CLGET_FD, (char *)&fd); 327d201fe46SDaniel Eischen if (_getpeername(fd,(struct sockaddr *)&name,&namelen) == -1) { 328e8636dfdSBill Paul auth_destroy(kcp->client->cl_auth); 329e8636dfdSBill Paul clnt_destroy(kcp->client); 330e8636dfdSBill Paul kcp->client = NULL; 331e8636dfdSBill Paul } 332e8636dfdSBill Paul } 333e8636dfdSBill Paul 334e8636dfdSBill Paul if (kcp->client != NULL) { 335e8636dfdSBill Paul /* if uid has changed, build client handle again */ 336e8636dfdSBill Paul if (kcp->uid != geteuid()) { 337e8636dfdSBill Paul kcp->uid = geteuid(); 338e8636dfdSBill Paul auth_destroy(kcp->client->cl_auth); 339e8636dfdSBill Paul kcp->client->cl_auth = 340e8636dfdSBill Paul authsys_create("", kcp->uid, 0, 0, NULL); 341e8636dfdSBill Paul if (kcp->client->cl_auth == NULL) { 342e8636dfdSBill Paul clnt_destroy(kcp->client); 343e8636dfdSBill Paul kcp->client = NULL; 344e8636dfdSBill Paul return ((CLIENT *) NULL); 345e8636dfdSBill Paul } 346e8636dfdSBill Paul } 347e8636dfdSBill Paul /* Change the version number to the new one */ 348e8636dfdSBill Paul clnt_control(kcp->client, CLSET_VERS, (void *)&vers); 349e8636dfdSBill Paul return (kcp->client); 350e8636dfdSBill Paul } 351e8636dfdSBill Paul 352e8636dfdSBill Paul if ((kcp->client == (CLIENT *) NULL)) 353e8636dfdSBill Paul /* Use the AF_UNIX transport */ 354e8636dfdSBill Paul kcp->client = clnt_create("/var/run/keyservsock", KEY_PROG, 355e8636dfdSBill Paul vers, "unix"); 356e8636dfdSBill Paul 357e8636dfdSBill Paul if (kcp->client == (CLIENT *) NULL) { 358e8636dfdSBill Paul return ((CLIENT *) NULL); 359e8636dfdSBill Paul } 360e8636dfdSBill Paul kcp->uid = geteuid(); 361e8636dfdSBill Paul kcp->pid = getpid(); 362e8636dfdSBill Paul kcp->client->cl_auth = authsys_create("", kcp->uid, 0, 0, NULL); 363e8636dfdSBill Paul if (kcp->client->cl_auth == NULL) { 364e8636dfdSBill Paul clnt_destroy(kcp->client); 365e8636dfdSBill Paul kcp->client = NULL; 366e8636dfdSBill Paul return ((CLIENT *) NULL); 367e8636dfdSBill Paul } 368e8636dfdSBill Paul 369e8636dfdSBill Paul wait_time.tv_sec = TOTAL_TIMEOUT/TOTAL_TRIES; 370e8636dfdSBill Paul wait_time.tv_usec = 0; 371e8636dfdSBill Paul (void) clnt_control(kcp->client, CLSET_RETRY_TIMEOUT, 372e8636dfdSBill Paul (char *)&wait_time); 373e8636dfdSBill Paul if (clnt_control(kcp->client, CLGET_FD, (char *)&fd)) 3749233c4d9SJason Evans _fcntl(fd, F_SETFD, 1); /* make it "close on exec" */ 375e8636dfdSBill Paul 376e8636dfdSBill Paul return (kcp->client); 377e8636dfdSBill Paul } 378e8636dfdSBill Paul 379e8636dfdSBill Paul /* returns 0 on failure, 1 on success */ 380e8636dfdSBill Paul 381e8636dfdSBill Paul static int 382e8636dfdSBill Paul key_call(proc, xdr_arg, arg, xdr_rslt, rslt) 383e8636dfdSBill Paul u_long proc; 384e8636dfdSBill Paul xdrproc_t xdr_arg; 385e8636dfdSBill Paul char *arg; 386e8636dfdSBill Paul xdrproc_t xdr_rslt; 387e8636dfdSBill Paul char *rslt; 388e8636dfdSBill Paul { 389e8636dfdSBill Paul CLIENT *clnt; 390e8636dfdSBill Paul struct timeval wait_time; 391e8636dfdSBill Paul 392e8636dfdSBill Paul if (proc == KEY_ENCRYPT_PK && __key_encryptsession_pk_LOCAL) { 393e8636dfdSBill Paul cryptkeyres *res; 394e8636dfdSBill Paul res = (*__key_encryptsession_pk_LOCAL)(geteuid(), arg); 395e8636dfdSBill Paul *(cryptkeyres*)rslt = *res; 396e8636dfdSBill Paul return (1); 397e8636dfdSBill Paul } else if (proc == KEY_DECRYPT_PK && __key_decryptsession_pk_LOCAL) { 398e8636dfdSBill Paul cryptkeyres *res; 399e8636dfdSBill Paul res = (*__key_decryptsession_pk_LOCAL)(geteuid(), arg); 400e8636dfdSBill Paul *(cryptkeyres*)rslt = *res; 401e8636dfdSBill Paul return (1); 402e8636dfdSBill Paul } else if (proc == KEY_GEN && __key_gendes_LOCAL) { 403e8636dfdSBill Paul des_block *res; 404e8636dfdSBill Paul res = (*__key_gendes_LOCAL)(geteuid(), 0); 405e8636dfdSBill Paul *(des_block*)rslt = *res; 406e8636dfdSBill Paul return (1); 407e8636dfdSBill Paul } 408e8636dfdSBill Paul 409e8636dfdSBill Paul if ((proc == KEY_ENCRYPT_PK) || (proc == KEY_DECRYPT_PK) || 410e8636dfdSBill Paul (proc == KEY_NET_GET) || (proc == KEY_NET_PUT) || 411e8636dfdSBill Paul (proc == KEY_GET_CONV)) 412e8636dfdSBill Paul clnt = getkeyserv_handle(2); /* talk to version 2 */ 413e8636dfdSBill Paul else 414e8636dfdSBill Paul clnt = getkeyserv_handle(1); /* talk to version 1 */ 415e8636dfdSBill Paul 416e8636dfdSBill Paul if (clnt == NULL) { 417e8636dfdSBill Paul return (0); 418e8636dfdSBill Paul } 419e8636dfdSBill Paul 420e8636dfdSBill Paul wait_time.tv_sec = TOTAL_TIMEOUT; 421e8636dfdSBill Paul wait_time.tv_usec = 0; 422e8636dfdSBill Paul 423e8636dfdSBill Paul if (clnt_call(clnt, proc, xdr_arg, arg, xdr_rslt, rslt, 424e8636dfdSBill Paul wait_time) == RPC_SUCCESS) { 425e8636dfdSBill Paul return (1); 426e8636dfdSBill Paul } else { 427e8636dfdSBill Paul return (0); 428e8636dfdSBill Paul } 429e8636dfdSBill Paul } 430