Annotation of src/lib/libc/yp/yp_first.c, Revision 1.1
1.1 ! jtc 1: /* $NetBSD: yplib.c,v 1.21 1996/05/15 05:27:53 jtc Exp $ */
! 2:
! 3: /*
! 4: * Copyright (c) 1992, 1993 Theo de Raadt <deraadt@fsa.ca>
! 5: * All rights reserved.
! 6: *
! 7: * Redistribution and use in source and binary forms, with or without
! 8: * modification, are permitted provided that the following conditions
! 9: * are met:
! 10: * 1. Redistributions of source code must retain the above copyright
! 11: * notice, this list of conditions and the following disclaimer.
! 12: * 2. Redistributions in binary form must reproduce the above copyright
! 13: * notice, this list of conditions and the following disclaimer in the
! 14: * documentation and/or other materials provided with the distribution.
! 15: * 3. All advertising materials mentioning features or use of this software
! 16: * must display the following acknowledgement:
! 17: * This product includes software developed by Theo de Raadt.
! 18: * 4. The name of the author may not be used to endorse or promote products
! 19: * derived from this software without specific prior written permission.
! 20: *
! 21: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
! 22: * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
! 23: * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
! 24: * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
! 25: * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
! 26: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
! 27: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
! 28: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
! 29: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
! 30: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
! 31: * SUCH DAMAGE.
! 32: */
! 33:
! 34: #if defined(LIBC_SCCS) && !defined(lint)
! 35: static char rcsid[] = "$NetBSD: yplib.c,v 1.21 1996/05/15 05:27:53 jtc Exp $";
! 36: #endif
! 37:
! 38: #include <stdlib.h>
! 39: #include <rpc/rpc.h>
! 40: #include <rpcsvc/yp_prot.h>
! 41: #include <rpcsvc/ypclnt.h>
! 42:
! 43: extern struct timeval _yplib_timeout;
! 44:
! 45: int
! 46: yp_first(indomain, inmap, outkey, outkeylen, outval, outvallen)
! 47: const char *indomain;
! 48: const char *inmap;
! 49: char **outkey;
! 50: int *outkeylen;
! 51: char **outval;
! 52: int *outvallen;
! 53: {
! 54: struct ypresp_key_val yprkv;
! 55: struct ypreq_nokey yprnk;
! 56: struct dom_binding *ysd;
! 57: int r;
! 58:
! 59: if (indomain == NULL || *indomain == '\0'
! 60: || strlen(indomain) > YPMAXDOMAIN)
! 61: return YPERR_BADARGS;
! 62: if (inmap == NULL || *inmap == '\0'
! 63: || strlen(inmap) > YPMAXMAP)
! 64: return YPERR_BADARGS;
! 65:
! 66: *outkey = *outval = NULL;
! 67: *outkeylen = *outvallen = 0;
! 68:
! 69: again:
! 70: if (_yp_dobind(indomain, &ysd) != 0)
! 71: return YPERR_DOMAIN;
! 72:
! 73: yprnk.domain = indomain;
! 74: yprnk.map = inmap;
! 75: (void)memset(&yprkv, 0, sizeof yprkv);
! 76:
! 77: r = clnt_call(ysd->dom_client, YPPROC_FIRST,
! 78: xdr_ypreq_nokey, &yprnk, xdr_ypresp_key_val, &yprkv,
! 79: _yplib_timeout);
! 80: if (r != RPC_SUCCESS) {
! 81: clnt_perror(ysd->dom_client, "yp_first: clnt_call");
! 82: ysd->dom_vers = -1;
! 83: goto again;
! 84: }
! 85: if (!(r = ypprot_err(yprkv.status))) {
! 86: *outkeylen = yprkv.keydat.dsize;
! 87: if ((*outkey = malloc(*outkeylen + 1)) == NULL)
! 88: r = YPERR_RESRC;
! 89: else {
! 90: (void)memcpy(*outkey, yprkv.keydat.dptr, *outkeylen);
! 91: (*outkey)[*outkeylen] = '\0';
! 92: }
! 93: *outvallen = yprkv.valdat.dsize;
! 94: if ((*outval = malloc(*outvallen + 1)) == NULL)
! 95: r = YPERR_RESRC;
! 96: else {
! 97: (void)memcpy(*outval, yprkv.valdat.dptr, *outvallen);
! 98: (*outval)[*outvallen] = '\0';
! 99: }
! 100: }
! 101: xdr_free(xdr_ypresp_key_val, (char *) &yprkv);
! 102: _yp_unbind(ysd);
! 103: return r;
! 104: }
! 105:
! 106: int
! 107: yp_next(indomain, inmap, inkey, inkeylen, outkey, outkeylen, outval, outvallen)
! 108: const char *indomain;
! 109: const char *inmap;
! 110: const char *inkey;
! 111: int inkeylen;
! 112: char **outkey;
! 113: int *outkeylen;
! 114: char **outval;
! 115: int *outvallen;
! 116: {
! 117: struct ypresp_key_val yprkv;
! 118: struct ypreq_key yprk;
! 119: struct dom_binding *ysd;
! 120: int r;
! 121:
! 122: if (indomain == NULL || *indomain == '\0'
! 123: || strlen(indomain) > YPMAXDOMAIN)
! 124: return YPERR_BADARGS;
! 125: if (inmap == NULL || *inmap == '\0'
! 126: || strlen(inmap) > YPMAXMAP)
! 127: return YPERR_BADARGS;
! 128:
! 129: *outkey = *outval = NULL;
! 130: *outkeylen = *outvallen = 0;
! 131:
! 132: again:
! 133: if (_yp_dobind(indomain, &ysd) != 0)
! 134: return YPERR_DOMAIN;
! 135:
! 136: yprk.domain = indomain;
! 137: yprk.map = inmap;
! 138: yprk.keydat.dptr = inkey;
! 139: yprk.keydat.dsize = inkeylen;
! 140: (void)memset(&yprkv, 0, sizeof yprkv);
! 141:
! 142: r = clnt_call(ysd->dom_client, YPPROC_NEXT,
! 143: xdr_ypreq_key, &yprk, xdr_ypresp_key_val, &yprkv,
! 144: _yplib_timeout);
! 145: if (r != RPC_SUCCESS) {
! 146: clnt_perror(ysd->dom_client, "yp_next: clnt_call");
! 147: ysd->dom_vers = -1;
! 148: goto again;
! 149: }
! 150: if (!(r = ypprot_err(yprkv.status))) {
! 151: *outkeylen = yprkv.keydat.dsize;
! 152: if ((*outkey = malloc(*outkeylen + 1)) == NULL)
! 153: r = YPERR_RESRC;
! 154: else {
! 155: (void)memcpy(*outkey, yprkv.keydat.dptr, *outkeylen);
! 156: (*outkey)[*outkeylen] = '\0';
! 157: }
! 158: *outvallen = yprkv.valdat.dsize;
! 159: if ((*outval = malloc(*outvallen + 1)) == NULL)
! 160: r = YPERR_RESRC;
! 161: else {
! 162: (void)memcpy(*outval, yprkv.valdat.dptr, *outvallen);
! 163: (*outval)[*outvallen] = '\0';
! 164: }
! 165: }
! 166: xdr_free(xdr_ypresp_key_val, (char *) &yprkv);
! 167: _yp_unbind(ysd);
! 168: return r;
! 169: }
CVSweb <webmaster@jp.NetBSD.org>