1*2d62dde8Sderaadt /* $OpenBSD: yp_maplist.c,v 1.10 2022/08/02 16:59:30 deraadt Exp $ */
218128546Sderaadt /*
318128546Sderaadt * Copyright (c) 1992, 1993 Theo de Raadt <deraadt@theos.com>
418128546Sderaadt * All rights reserved.
518128546Sderaadt *
618128546Sderaadt * Redistribution and use in source and binary forms, with or without
718128546Sderaadt * modification, are permitted provided that the following conditions
818128546Sderaadt * are met:
918128546Sderaadt * 1. Redistributions of source code must retain the above copyright
1018128546Sderaadt * notice, this list of conditions and the following disclaimer.
1118128546Sderaadt * 2. Redistributions in binary form must reproduce the above copyright
1218128546Sderaadt * notice, this list of conditions and the following disclaimer in the
1318128546Sderaadt * documentation and/or other materials provided with the distribution.
1418128546Sderaadt *
1518128546Sderaadt * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
1618128546Sderaadt * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
1718128546Sderaadt * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1818128546Sderaadt * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
1918128546Sderaadt * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2018128546Sderaadt * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2118128546Sderaadt * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2218128546Sderaadt * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2318128546Sderaadt * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2418128546Sderaadt * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2518128546Sderaadt * SUCH DAMAGE.
2618128546Sderaadt */
2718128546Sderaadt
2818128546Sderaadt #include <sys/types.h>
2918128546Sderaadt #include <string.h>
30aea60beeSderaadt #include <limits.h>
3118128546Sderaadt #include <rpc/rpc.h>
3218128546Sderaadt #include <rpc/xdr.h>
3318128546Sderaadt #include <rpcsvc/yp.h>
3418128546Sderaadt #include <rpcsvc/ypclnt.h>
3518128546Sderaadt #include "ypinternal.h"
3618128546Sderaadt
3718128546Sderaadt int
yp_maplist(const char * indomain,struct ypmaplist ** outmaplist)3811e5d692Sderaadt yp_maplist(const char *indomain, struct ypmaplist **outmaplist)
3918128546Sderaadt {
4018128546Sderaadt struct dom_binding *ysd;
4118128546Sderaadt struct ypresp_maplist ypml;
4218128546Sderaadt struct timeval tv;
4377124a50Sderaadt int tries = 0, r;
4418128546Sderaadt
4518128546Sderaadt again:
4618128546Sderaadt if (_yp_dobind(indomain, &ysd) != 0)
4718128546Sderaadt return YPERR_DOMAIN;
4818128546Sderaadt
4918128546Sderaadt tv.tv_sec = _yplib_timeout;
5018128546Sderaadt tv.tv_usec = 0;
5118128546Sderaadt
5218128546Sderaadt memset(&ypml, 0, sizeof ypml);
5318128546Sderaadt
5418128546Sderaadt r = clnt_call(ysd->dom_client, YPPROC_MAPLIST,
5518128546Sderaadt xdr_domainname, &indomain, xdr_ypresp_maplist, &ypml, tv);
5618128546Sderaadt if (r != RPC_SUCCESS) {
5777124a50Sderaadt if (tries++)
5818128546Sderaadt clnt_perror(ysd->dom_client, "yp_maplist: clnt_call");
59*2d62dde8Sderaadt _yp_unbind(ysd);
6018128546Sderaadt goto again;
6118128546Sderaadt }
6218128546Sderaadt *outmaplist = ypml.maps;
6318128546Sderaadt /* NO: xdr_free(xdr_ypresp_maplist, &ypml); */
6418128546Sderaadt _yp_unbind(ysd);
6518128546Sderaadt return ypprot_err(ypml.stat);
6618128546Sderaadt }
67