17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate * with the License.
87c478bd9Sstevel@tonic-gate *
97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate * and limitations under the License.
137c478bd9Sstevel@tonic-gate *
147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate *
207c478bd9Sstevel@tonic-gate * CDDL HEADER END
2161961e0fSrobinson */
2261961e0fSrobinson
2361961e0fSrobinson /*
24*e8031f0aSraf * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
257c478bd9Sstevel@tonic-gate * Use is subject to license terms.
267c478bd9Sstevel@tonic-gate */
277c478bd9Sstevel@tonic-gate
287c478bd9Sstevel@tonic-gate /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
297c478bd9Sstevel@tonic-gate /* All Rights Reserved */
307c478bd9Sstevel@tonic-gate
317c478bd9Sstevel@tonic-gate /*
327c478bd9Sstevel@tonic-gate * Portions of this source code were derived from Berkeley
337c478bd9Sstevel@tonic-gate * under license from the Regents of the University of
347c478bd9Sstevel@tonic-gate * California.
357c478bd9Sstevel@tonic-gate */
367c478bd9Sstevel@tonic-gate
377c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
387c478bd9Sstevel@tonic-gate
39*e8031f0aSraf #include "mt.h"
4061961e0fSrobinson #include <stdlib.h>
4161961e0fSrobinson #include <unistd.h>
427c478bd9Sstevel@tonic-gate #include <rpc/rpc.h>
437c478bd9Sstevel@tonic-gate #include <sys/types.h>
447c478bd9Sstevel@tonic-gate #include "yp_b.h"
457c478bd9Sstevel@tonic-gate #include <rpcsvc/yp_prot.h>
467c478bd9Sstevel@tonic-gate #include <rpcsvc/ypclnt.h>
477c478bd9Sstevel@tonic-gate #include <string.h>
487c478bd9Sstevel@tonic-gate
497c478bd9Sstevel@tonic-gate extern int __yp_dobind_cflookup(char *, struct dom_binding **, int);
507c478bd9Sstevel@tonic-gate
517c478bd9Sstevel@tonic-gate static int dofirst(char *, char *, struct dom_binding *, struct timeval,
527c478bd9Sstevel@tonic-gate char **, int *, char **, int *);
537c478bd9Sstevel@tonic-gate
547c478bd9Sstevel@tonic-gate static int donext(char *, char *, char *, int, struct dom_binding *,
557c478bd9Sstevel@tonic-gate struct timeval, char **, int *, char **val, int *);
567c478bd9Sstevel@tonic-gate
577c478bd9Sstevel@tonic-gate /*
587c478bd9Sstevel@tonic-gate * This requests the yp server associated with a given domain to return the
597c478bd9Sstevel@tonic-gate * first key/value pair from the map data base. The returned key should be
607c478bd9Sstevel@tonic-gate * used as an input to the call to ypclnt_next. This part does the parameter
617c478bd9Sstevel@tonic-gate * checking, and the do-until-success loop if 'hardlookup' is set.
627c478bd9Sstevel@tonic-gate */
637c478bd9Sstevel@tonic-gate int
__yp_first_cflookup(char * domain,char * map,char ** key,int * keylen,char ** val,int * vallen,int hardlookup)647c478bd9Sstevel@tonic-gate __yp_first_cflookup(
657c478bd9Sstevel@tonic-gate char *domain,
667c478bd9Sstevel@tonic-gate char *map,
677c478bd9Sstevel@tonic-gate char **key, /* return: key array */
687c478bd9Sstevel@tonic-gate int *keylen, /* return: bytes in key */
697c478bd9Sstevel@tonic-gate char **val, /* return: value array */
707c478bd9Sstevel@tonic-gate int *vallen, /* return: bytes in val */
717c478bd9Sstevel@tonic-gate int hardlookup)
727c478bd9Sstevel@tonic-gate {
737c478bd9Sstevel@tonic-gate size_t domlen;
747c478bd9Sstevel@tonic-gate size_t maplen;
757c478bd9Sstevel@tonic-gate struct dom_binding *pdomb;
767c478bd9Sstevel@tonic-gate int reason;
777c478bd9Sstevel@tonic-gate
7861961e0fSrobinson if ((map == NULL) || (domain == NULL))
797c478bd9Sstevel@tonic-gate return (YPERR_BADARGS);
807c478bd9Sstevel@tonic-gate
817c478bd9Sstevel@tonic-gate domlen = strlen(domain);
827c478bd9Sstevel@tonic-gate maplen = strlen(map);
837c478bd9Sstevel@tonic-gate
847c478bd9Sstevel@tonic-gate if ((domlen == 0) || (domlen > YPMAXDOMAIN) ||
8561961e0fSrobinson (maplen == 0) || (maplen > YPMAXMAP))
867c478bd9Sstevel@tonic-gate return (YPERR_BADARGS);
877c478bd9Sstevel@tonic-gate
887c478bd9Sstevel@tonic-gate for (;;) {
897c478bd9Sstevel@tonic-gate
9061961e0fSrobinson if (reason = __yp_dobind_cflookup(domain, &pdomb, hardlookup))
917c478bd9Sstevel@tonic-gate return (reason);
927c478bd9Sstevel@tonic-gate
937c478bd9Sstevel@tonic-gate if (pdomb->dom_binding->ypbind_hi_vers == YPVERS) {
947c478bd9Sstevel@tonic-gate
957c478bd9Sstevel@tonic-gate reason = dofirst(domain, map, pdomb, _ypserv_timeout,
967c478bd9Sstevel@tonic-gate key, keylen, val, vallen);
977c478bd9Sstevel@tonic-gate
987c478bd9Sstevel@tonic-gate __yp_rel_binding(pdomb);
997c478bd9Sstevel@tonic-gate if (reason == YPERR_RPC || reason == YPERR_YPSERV ||
1007c478bd9Sstevel@tonic-gate reason == YPERR_BUSY /* as if */) {
1017c478bd9Sstevel@tonic-gate yp_unbind(domain);
1027c478bd9Sstevel@tonic-gate if (hardlookup)
103*e8031f0aSraf (void) sleep(_ypsleeptime); /* retry */
10461961e0fSrobinson else
1057c478bd9Sstevel@tonic-gate return (reason);
1067c478bd9Sstevel@tonic-gate } else
1077c478bd9Sstevel@tonic-gate break;
1087c478bd9Sstevel@tonic-gate } else {
1097c478bd9Sstevel@tonic-gate __yp_rel_binding(pdomb);
1107c478bd9Sstevel@tonic-gate return (YPERR_VERS);
1117c478bd9Sstevel@tonic-gate }
1127c478bd9Sstevel@tonic-gate }
1137c478bd9Sstevel@tonic-gate return (reason);
1147c478bd9Sstevel@tonic-gate }
1157c478bd9Sstevel@tonic-gate
1167c478bd9Sstevel@tonic-gate int
yp_first(char * domain,char * map,char ** key,int * keylen,char ** val,int * vallen)1177c478bd9Sstevel@tonic-gate yp_first(
1187c478bd9Sstevel@tonic-gate char *domain,
1197c478bd9Sstevel@tonic-gate char *map,
1207c478bd9Sstevel@tonic-gate char **key, /* return: key array */
1217c478bd9Sstevel@tonic-gate int *keylen, /* return: bytes in key */
1227c478bd9Sstevel@tonic-gate char **val, /* return: value array */
1237c478bd9Sstevel@tonic-gate int *vallen) /* return: bytes in val */
1247c478bd9Sstevel@tonic-gate {
1257c478bd9Sstevel@tonic-gate /* traditional yp_firs loops forever until success */
1267c478bd9Sstevel@tonic-gate return (__yp_first_cflookup(domain, map, key, keylen, val, vallen, 1));
1277c478bd9Sstevel@tonic-gate }
1287c478bd9Sstevel@tonic-gate
1297c478bd9Sstevel@tonic-gate /*
1307c478bd9Sstevel@tonic-gate * This part of the "get first" interface talks to ypserv.
1317c478bd9Sstevel@tonic-gate */
1327c478bd9Sstevel@tonic-gate
1337c478bd9Sstevel@tonic-gate static int
dofirst(domain,map,pdomb,timeout,key,keylen,val,vallen)1347c478bd9Sstevel@tonic-gate dofirst(domain, map, pdomb, timeout, key, keylen, val, vallen)
1357c478bd9Sstevel@tonic-gate char *domain;
1367c478bd9Sstevel@tonic-gate char *map;
1377c478bd9Sstevel@tonic-gate struct dom_binding *pdomb;
1387c478bd9Sstevel@tonic-gate struct timeval timeout;
1397c478bd9Sstevel@tonic-gate char **key;
1407c478bd9Sstevel@tonic-gate int *keylen;
1417c478bd9Sstevel@tonic-gate char **val;
1427c478bd9Sstevel@tonic-gate int *vallen;
1437c478bd9Sstevel@tonic-gate
1447c478bd9Sstevel@tonic-gate {
1457c478bd9Sstevel@tonic-gate struct ypreq_nokey req;
1467c478bd9Sstevel@tonic-gate struct ypresp_key_val resp;
1477c478bd9Sstevel@tonic-gate unsigned int retval = 0;
1487c478bd9Sstevel@tonic-gate
1497c478bd9Sstevel@tonic-gate req.domain = domain;
1507c478bd9Sstevel@tonic-gate req.map = map;
1517c478bd9Sstevel@tonic-gate resp.keydat.dptr = resp.valdat.dptr = NULL;
1527c478bd9Sstevel@tonic-gate resp.keydat.dsize = resp.valdat.dsize = 0;
1537c478bd9Sstevel@tonic-gate
1547c478bd9Sstevel@tonic-gate /*
1557c478bd9Sstevel@tonic-gate * Do the get first request. If the rpc call failed, return with status
1567c478bd9Sstevel@tonic-gate * from this point.
1577c478bd9Sstevel@tonic-gate */
1587c478bd9Sstevel@tonic-gate
1597c478bd9Sstevel@tonic-gate (void) memset((char *)&resp, 0, sizeof (struct ypresp_key_val));
1607c478bd9Sstevel@tonic-gate
1617c478bd9Sstevel@tonic-gate switch (clnt_call(pdomb->dom_client, YPPROC_FIRST,
1627c478bd9Sstevel@tonic-gate (xdrproc_t)xdr_ypreq_nokey,
1637c478bd9Sstevel@tonic-gate (char *)&req, (xdrproc_t)xdr_ypresp_key_val,
1647c478bd9Sstevel@tonic-gate (char *)&resp, timeout)) {
1657c478bd9Sstevel@tonic-gate case RPC_SUCCESS:
1667c478bd9Sstevel@tonic-gate break;
1677c478bd9Sstevel@tonic-gate case RPC_TIMEDOUT:
1687c478bd9Sstevel@tonic-gate return (YPERR_YPSERV);
1697c478bd9Sstevel@tonic-gate default:
1707c478bd9Sstevel@tonic-gate return (YPERR_RPC);
1717c478bd9Sstevel@tonic-gate }
1727c478bd9Sstevel@tonic-gate
1737c478bd9Sstevel@tonic-gate /* See if the request succeeded */
1747c478bd9Sstevel@tonic-gate
1757c478bd9Sstevel@tonic-gate if (resp.status != YP_TRUE) {
1767c478bd9Sstevel@tonic-gate retval = ypprot_err(resp.status);
1777c478bd9Sstevel@tonic-gate }
1787c478bd9Sstevel@tonic-gate
1797c478bd9Sstevel@tonic-gate /* Get some memory which the user can get rid of as he likes */
1807c478bd9Sstevel@tonic-gate
1817c478bd9Sstevel@tonic-gate if (!retval) {
1827c478bd9Sstevel@tonic-gate
1837c478bd9Sstevel@tonic-gate if ((*key = malloc((size_t)resp.keydat.dsize + 2)) != NULL) {
1847c478bd9Sstevel@tonic-gate
1857c478bd9Sstevel@tonic-gate if ((*val = malloc(
1867c478bd9Sstevel@tonic-gate (size_t)resp.valdat.dsize + 2)) == NULL) {
18761961e0fSrobinson free(*key);
1887c478bd9Sstevel@tonic-gate retval = YPERR_RESRC;
1897c478bd9Sstevel@tonic-gate }
1907c478bd9Sstevel@tonic-gate
1917c478bd9Sstevel@tonic-gate } else {
1927c478bd9Sstevel@tonic-gate retval = YPERR_RESRC;
1937c478bd9Sstevel@tonic-gate }
1947c478bd9Sstevel@tonic-gate }
1957c478bd9Sstevel@tonic-gate
1967c478bd9Sstevel@tonic-gate /* Copy the returned key and value byte strings into the new memory */
1977c478bd9Sstevel@tonic-gate
1987c478bd9Sstevel@tonic-gate if (!retval) {
1997c478bd9Sstevel@tonic-gate *keylen = (int)resp.keydat.dsize;
2007c478bd9Sstevel@tonic-gate (void) memcpy(*key, resp.keydat.dptr,
2017c478bd9Sstevel@tonic-gate (size_t)resp.keydat.dsize);
2027c478bd9Sstevel@tonic-gate (*key)[resp.keydat.dsize] = '\n';
2037c478bd9Sstevel@tonic-gate (*key)[resp.keydat.dsize + 1] = '\0';
2047c478bd9Sstevel@tonic-gate
2057c478bd9Sstevel@tonic-gate *vallen = (int)resp.valdat.dsize;
2067c478bd9Sstevel@tonic-gate (void) memcpy(*val, resp.valdat.dptr,
2077c478bd9Sstevel@tonic-gate (size_t)resp.valdat.dsize);
2087c478bd9Sstevel@tonic-gate (*val)[resp.valdat.dsize] = '\n';
2097c478bd9Sstevel@tonic-gate (*val)[resp.valdat.dsize + 1] = '\0';
2107c478bd9Sstevel@tonic-gate }
2117c478bd9Sstevel@tonic-gate
2127c478bd9Sstevel@tonic-gate CLNT_FREERES(pdomb->dom_client,
2137c478bd9Sstevel@tonic-gate (xdrproc_t)xdr_ypresp_key_val, (char *)&resp);
2147c478bd9Sstevel@tonic-gate return (retval);
2157c478bd9Sstevel@tonic-gate }
2167c478bd9Sstevel@tonic-gate
2177c478bd9Sstevel@tonic-gate /*
2187c478bd9Sstevel@tonic-gate * This requests the yp server associated with a given domain to return the
2197c478bd9Sstevel@tonic-gate * "next" key/value pair from the map data base. The input key should be
2207c478bd9Sstevel@tonic-gate * one returned by ypclnt_first or a previous call to ypclnt_next. The
2217c478bd9Sstevel@tonic-gate * returned key should be used as an input to the next call to ypclnt_next.
2227c478bd9Sstevel@tonic-gate * This part does the parameter checking, and the do-until-success loop.
2237c478bd9Sstevel@tonic-gate * if 'hardlookup' is set.
2247c478bd9Sstevel@tonic-gate */
2257c478bd9Sstevel@tonic-gate int
__yp_next_cflookup(char * domain,char * map,char * inkey,int inkeylen,char ** outkey,int * outkeylen,char ** val,int * vallen,int hardlookup)2267c478bd9Sstevel@tonic-gate __yp_next_cflookup(
2277c478bd9Sstevel@tonic-gate char *domain,
2287c478bd9Sstevel@tonic-gate char *map,
2297c478bd9Sstevel@tonic-gate char *inkey,
2307c478bd9Sstevel@tonic-gate int inkeylen,
2317c478bd9Sstevel@tonic-gate char **outkey, /* return: key array associated with val */
2327c478bd9Sstevel@tonic-gate int *outkeylen, /* return: bytes in key */
2337c478bd9Sstevel@tonic-gate char **val, /* return: value array associated with outkey */
2347c478bd9Sstevel@tonic-gate int *vallen, /* return: bytes in val */
2357c478bd9Sstevel@tonic-gate int hardlookup)
2367c478bd9Sstevel@tonic-gate {
2377c478bd9Sstevel@tonic-gate size_t domlen;
2387c478bd9Sstevel@tonic-gate size_t maplen;
2397c478bd9Sstevel@tonic-gate struct dom_binding *pdomb;
2407c478bd9Sstevel@tonic-gate int reason;
2417c478bd9Sstevel@tonic-gate
2427c478bd9Sstevel@tonic-gate
24361961e0fSrobinson if ((map == NULL) || (domain == NULL) || (inkey == NULL))
2447c478bd9Sstevel@tonic-gate return (YPERR_BADARGS);
2457c478bd9Sstevel@tonic-gate
2467c478bd9Sstevel@tonic-gate domlen = strlen(domain);
2477c478bd9Sstevel@tonic-gate maplen = strlen(map);
2487c478bd9Sstevel@tonic-gate
2497c478bd9Sstevel@tonic-gate if ((domlen == 0) || (domlen > YPMAXDOMAIN) ||
25061961e0fSrobinson (maplen == 0) || (maplen > YPMAXMAP))
2517c478bd9Sstevel@tonic-gate return (YPERR_BADARGS);
2527c478bd9Sstevel@tonic-gate
2537c478bd9Sstevel@tonic-gate for (;;) {
25461961e0fSrobinson if (reason = __yp_dobind_cflookup(domain, &pdomb, hardlookup))
2557c478bd9Sstevel@tonic-gate return (reason);
2567c478bd9Sstevel@tonic-gate
2577c478bd9Sstevel@tonic-gate if (pdomb->dom_binding->ypbind_hi_vers == YPVERS) {
2587c478bd9Sstevel@tonic-gate
2597c478bd9Sstevel@tonic-gate reason = donext(domain, map, inkey, inkeylen, pdomb,
2607c478bd9Sstevel@tonic-gate _ypserv_timeout, outkey, outkeylen, val, vallen);
2617c478bd9Sstevel@tonic-gate
2627c478bd9Sstevel@tonic-gate __yp_rel_binding(pdomb);
2637c478bd9Sstevel@tonic-gate
2647c478bd9Sstevel@tonic-gate if (reason == YPERR_RPC || reason == YPERR_YPSERV ||
2657c478bd9Sstevel@tonic-gate reason == YPERR_BUSY /* as if */) {
2667c478bd9Sstevel@tonic-gate yp_unbind(domain);
2677c478bd9Sstevel@tonic-gate if (hardlookup)
268*e8031f0aSraf (void) sleep(_ypsleeptime); /* retry */
26961961e0fSrobinson else
2707c478bd9Sstevel@tonic-gate return (reason);
2717c478bd9Sstevel@tonic-gate } else
2727c478bd9Sstevel@tonic-gate break;
2737c478bd9Sstevel@tonic-gate } else {
2747c478bd9Sstevel@tonic-gate __yp_rel_binding(pdomb);
2757c478bd9Sstevel@tonic-gate return (YPERR_VERS);
2767c478bd9Sstevel@tonic-gate }
2777c478bd9Sstevel@tonic-gate }
2787c478bd9Sstevel@tonic-gate
2797c478bd9Sstevel@tonic-gate return (reason);
2807c478bd9Sstevel@tonic-gate }
2817c478bd9Sstevel@tonic-gate
2827c478bd9Sstevel@tonic-gate int
yp_next(char * domain,char * map,char * inkey,int inkeylen,char ** outkey,int * outkeylen,char ** val,int * vallen)2837c478bd9Sstevel@tonic-gate yp_next(
2847c478bd9Sstevel@tonic-gate char *domain,
2857c478bd9Sstevel@tonic-gate char *map,
2867c478bd9Sstevel@tonic-gate char *inkey,
2877c478bd9Sstevel@tonic-gate int inkeylen,
2887c478bd9Sstevel@tonic-gate char **outkey, /* return: key array associated with val */
2897c478bd9Sstevel@tonic-gate int *outkeylen, /* return: bytes in key */
2907c478bd9Sstevel@tonic-gate char **val, /* return: value array associated with outkey */
2917c478bd9Sstevel@tonic-gate int *vallen) /* return: bytes in val */
2927c478bd9Sstevel@tonic-gate {
2937c478bd9Sstevel@tonic-gate /* traditional yp_next loops forever until success */
2947c478bd9Sstevel@tonic-gate return (__yp_next_cflookup(domain, map, inkey, inkeylen, outkey,
2957c478bd9Sstevel@tonic-gate outkeylen, val, vallen, 1));
2967c478bd9Sstevel@tonic-gate }
2977c478bd9Sstevel@tonic-gate
2987c478bd9Sstevel@tonic-gate
2997c478bd9Sstevel@tonic-gate /*
3007c478bd9Sstevel@tonic-gate * This part of the "get next" interface talks to ypserv.
3017c478bd9Sstevel@tonic-gate */
3027c478bd9Sstevel@tonic-gate static int
donext(domain,map,inkey,inkeylen,pdomb,timeout,outkey,outkeylen,val,vallen)3037c478bd9Sstevel@tonic-gate donext(domain, map, inkey, inkeylen, pdomb, timeout, outkey, outkeylen,
3047c478bd9Sstevel@tonic-gate val, vallen)
3057c478bd9Sstevel@tonic-gate char *domain;
3067c478bd9Sstevel@tonic-gate char *map;
3077c478bd9Sstevel@tonic-gate char *inkey;
3087c478bd9Sstevel@tonic-gate int inkeylen;
3097c478bd9Sstevel@tonic-gate struct dom_binding *pdomb;
3107c478bd9Sstevel@tonic-gate struct timeval timeout;
3117c478bd9Sstevel@tonic-gate char **outkey; /* return: key array associated with val */
3127c478bd9Sstevel@tonic-gate int *outkeylen; /* return: bytes in key */
3137c478bd9Sstevel@tonic-gate char **val; /* return: value array associated with outkey */
3147c478bd9Sstevel@tonic-gate int *vallen; /* return: bytes in val */
3157c478bd9Sstevel@tonic-gate
3167c478bd9Sstevel@tonic-gate {
3177c478bd9Sstevel@tonic-gate struct ypreq_key req;
3187c478bd9Sstevel@tonic-gate struct ypresp_key_val resp;
3197c478bd9Sstevel@tonic-gate unsigned int retval = 0;
3207c478bd9Sstevel@tonic-gate
3217c478bd9Sstevel@tonic-gate req.domain = domain;
3227c478bd9Sstevel@tonic-gate req.map = map;
3237c478bd9Sstevel@tonic-gate req.keydat.dptr = inkey;
3247c478bd9Sstevel@tonic-gate req.keydat.dsize = inkeylen;
3257c478bd9Sstevel@tonic-gate
3267c478bd9Sstevel@tonic-gate resp.keydat.dptr = resp.valdat.dptr = NULL;
3277c478bd9Sstevel@tonic-gate resp.keydat.dsize = resp.valdat.dsize = 0;
3287c478bd9Sstevel@tonic-gate
3297c478bd9Sstevel@tonic-gate /*
3307c478bd9Sstevel@tonic-gate * Do the get next request. If the rpc call failed, return with status
3317c478bd9Sstevel@tonic-gate * from this point.
3327c478bd9Sstevel@tonic-gate */
3337c478bd9Sstevel@tonic-gate
3347c478bd9Sstevel@tonic-gate switch (clnt_call(pdomb->dom_client,
3357c478bd9Sstevel@tonic-gate YPPROC_NEXT, (xdrproc_t)xdr_ypreq_key, (char *)&req,
3367c478bd9Sstevel@tonic-gate (xdrproc_t)xdr_ypresp_key_val, (char *)&resp,
3377c478bd9Sstevel@tonic-gate timeout)) {
3387c478bd9Sstevel@tonic-gate case RPC_SUCCESS:
3397c478bd9Sstevel@tonic-gate break;
3407c478bd9Sstevel@tonic-gate case RPC_TIMEDOUT:
3417c478bd9Sstevel@tonic-gate return (YPERR_YPSERV);
3427c478bd9Sstevel@tonic-gate default:
3437c478bd9Sstevel@tonic-gate return (YPERR_RPC);
3447c478bd9Sstevel@tonic-gate }
3457c478bd9Sstevel@tonic-gate
3467c478bd9Sstevel@tonic-gate /* See if the request succeeded */
3477c478bd9Sstevel@tonic-gate
3487c478bd9Sstevel@tonic-gate if (resp.status != YP_TRUE) {
3497c478bd9Sstevel@tonic-gate retval = ypprot_err(resp.status);
3507c478bd9Sstevel@tonic-gate }
3517c478bd9Sstevel@tonic-gate
3527c478bd9Sstevel@tonic-gate /* Get some memory which the user can get rid of as he likes */
3537c478bd9Sstevel@tonic-gate
3547c478bd9Sstevel@tonic-gate if (!retval) {
3557c478bd9Sstevel@tonic-gate if ((*outkey = malloc((size_t)
3567c478bd9Sstevel@tonic-gate resp.keydat.dsize + 2)) != NULL) {
3577c478bd9Sstevel@tonic-gate
3587c478bd9Sstevel@tonic-gate if ((*val = malloc((size_t)
3597c478bd9Sstevel@tonic-gate resp.valdat.dsize + 2)) == NULL) {
36061961e0fSrobinson free(*outkey);
3617c478bd9Sstevel@tonic-gate retval = YPERR_RESRC;
3627c478bd9Sstevel@tonic-gate }
3637c478bd9Sstevel@tonic-gate
3647c478bd9Sstevel@tonic-gate } else {
3657c478bd9Sstevel@tonic-gate retval = YPERR_RESRC;
3667c478bd9Sstevel@tonic-gate }
3677c478bd9Sstevel@tonic-gate }
3687c478bd9Sstevel@tonic-gate
3697c478bd9Sstevel@tonic-gate /* Copy the returned key and value byte strings into the new memory */
3707c478bd9Sstevel@tonic-gate
3717c478bd9Sstevel@tonic-gate if (!retval) {
3727c478bd9Sstevel@tonic-gate *outkeylen = (int)resp.keydat.dsize;
3737c478bd9Sstevel@tonic-gate (void) memcpy(*outkey, resp.keydat.dptr,
3747c478bd9Sstevel@tonic-gate (size_t)resp.keydat.dsize);
3757c478bd9Sstevel@tonic-gate (*outkey)[resp.keydat.dsize] = '\n';
3767c478bd9Sstevel@tonic-gate (*outkey)[resp.keydat.dsize + 1] = '\0';
3777c478bd9Sstevel@tonic-gate
3787c478bd9Sstevel@tonic-gate *vallen = (int)resp.valdat.dsize;
3797c478bd9Sstevel@tonic-gate (void) memcpy(*val, resp.valdat.dptr,
3807c478bd9Sstevel@tonic-gate (size_t)resp.valdat.dsize);
3817c478bd9Sstevel@tonic-gate (*val)[resp.valdat.dsize] = '\n';
3827c478bd9Sstevel@tonic-gate (*val)[resp.valdat.dsize + 1] = '\0';
3837c478bd9Sstevel@tonic-gate }
3847c478bd9Sstevel@tonic-gate
3857c478bd9Sstevel@tonic-gate CLNT_FREERES(pdomb->dom_client, (xdrproc_t)xdr_ypresp_key_val,
3867c478bd9Sstevel@tonic-gate (char *)&resp);
3877c478bd9Sstevel@tonic-gate return (retval);
3887c478bd9Sstevel@tonic-gate }
389