1*4be2f99dSchristos /* $NetBSD: yp_maplist.c,v 1.14 2024/01/03 18:41:53 christos Exp $ */
2159bafeaSjtc
3159bafeaSjtc /*
4159bafeaSjtc * Copyright (c) 1992, 1993 Theo de Raadt <deraadt@fsa.ca>
5159bafeaSjtc * All rights reserved.
6159bafeaSjtc *
7159bafeaSjtc * Redistribution and use in source and binary forms, with or without
8159bafeaSjtc * modification, are permitted provided that the following conditions
9159bafeaSjtc * are met:
10159bafeaSjtc * 1. Redistributions of source code must retain the above copyright
11159bafeaSjtc * notice, this list of conditions and the following disclaimer.
12159bafeaSjtc * 2. Redistributions in binary form must reproduce the above copyright
13159bafeaSjtc * notice, this list of conditions and the following disclaimer in the
14159bafeaSjtc * documentation and/or other materials provided with the distribution.
15159bafeaSjtc *
16159bafeaSjtc * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
17159bafeaSjtc * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18159bafeaSjtc * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19159bafeaSjtc * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
20159bafeaSjtc * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21159bafeaSjtc * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22159bafeaSjtc * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23159bafeaSjtc * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24159bafeaSjtc * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25159bafeaSjtc * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26159bafeaSjtc * SUCH DAMAGE.
27159bafeaSjtc */
28159bafeaSjtc
29e7cc5503Schristos #include <sys/cdefs.h>
30159bafeaSjtc #if defined(LIBC_SCCS) && !defined(lint)
31*4be2f99dSchristos __RCSID("$NetBSD: yp_maplist.c,v 1.14 2024/01/03 18:41:53 christos Exp $");
32159bafeaSjtc #endif
33159bafeaSjtc
3443fa6fe3Sjtc #include "namespace.h"
35e7cc5503Schristos #include <string.h>
36159bafeaSjtc #include <rpc/rpc.h>
37159bafeaSjtc #include <rpcsvc/yp_prot.h>
38159bafeaSjtc #include <rpcsvc/ypclnt.h>
39e7cc5503Schristos #include "local.h"
40159bafeaSjtc
4143fa6fe3Sjtc #ifdef __weak_alias
__weak_alias(yp_maplist,_yp_maplist)4260549036Smycroft __weak_alias(yp_maplist,_yp_maplist)
4343fa6fe3Sjtc #endif
4443fa6fe3Sjtc
45159bafeaSjtc int
469e66e6d7Sabs yp_maplist( const char *indomain, struct ypmaplist **outmaplist)
47159bafeaSjtc {
48159bafeaSjtc struct dom_binding *ysd;
49159bafeaSjtc struct ypresp_maplist ypml;
50409a9590Schristos int r, nerrs = 0;
51159bafeaSjtc
5242736edbSlukem if (_yp_invalid_domain(indomain))
5342736edbSlukem return YPERR_BADARGS;
54b035f7abSlukem if (outmaplist == NULL)
55b035f7abSlukem return YPERR_BADARGS;
56159bafeaSjtc again:
57159bafeaSjtc if (_yp_dobind(indomain, &ysd) != 0)
58159bafeaSjtc return YPERR_DOMAIN;
59159bafeaSjtc
60159bafeaSjtc memset(&ypml, 0, sizeof ypml);
61159bafeaSjtc
62473ea2c4Schristos r = clnt_call(ysd->dom_client, (rpcproc_t)YPPROC_MAPLIST,
63b2a14ab2Schristos (xdrproc_t)xdr_ypdomain_wrap_string, &indomain,
64b2a14ab2Schristos (xdrproc_t)xdr_ypresp_maplist, &ypml, _yplib_timeout);
65159bafeaSjtc if (r != RPC_SUCCESS) {
662b01a8adSchristos if (_yplib_bindtries <= 0 && ++nerrs == _yplib_nerrs) {
67159bafeaSjtc clnt_perror(ysd->dom_client, "yp_maplist: clnt_call");
68409a9590Schristos nerrs = 0;
692b01a8adSchristos } else if (_yplib_bindtries > 0 && ++nerrs == _yplib_bindtries)
702b01a8adSchristos return YPERR_YPSERV;
71159bafeaSjtc ysd->dom_vers = -1;
72159bafeaSjtc goto again;
73159bafeaSjtc }
74159bafeaSjtc *outmaplist = ypml.list;
75159bafeaSjtc /* NO: xdr_free(xdr_ypresp_maplist, &ypml); */
7643fa6fe3Sjtc __yp_unbind(ysd);
77159bafeaSjtc return ypprot_err(ypml.status);
78159bafeaSjtc }
79