/*-1* SPDX-License-Identifier: BSD-4-Clause2*3* Copyright (c) 19954* Bill Paul <[email protected]>. All rights reserved.5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions8* are met:9* 1. Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11* 2. Redistributions in binary form must reproduce the above copyright12* notice, this list of conditions and the following disclaimer in the13* documentation and/or other materials provided with the distribution.14* 3. All advertising materials mentioning features or use of this software15* must display the following acknowledgement:16* This product includes software developed by Bill Paul.17* 4. Neither the name of the author nor the names of any co-contributors18* may be used to endorse or promote products derived from this software19* without specific prior written permission.20*21* THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND22* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE23* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE24* ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR CONTRIBUTORS BE LIABLE25* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL26* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS27* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)28* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT29* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY30* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF31* SUCH DAMAGE.32*/3334#include <sys/cdefs.h>35#include <stdio.h>36#include <time.h>37#include <sys/types.h>38#include <rpc/rpc.h>39#include <rpc/xdr.h>40#include <rpcsvc/yp.h>41#include "ypxfr_extern.h"4243extern bool_t xdr_ypresp_all_seq(XDR *, unsigned long *);4445extern int (*ypresp_allfn)();46extern void *ypresp_data;47extern DB *specdbp;48extern enum ypstat yp_errno;4950/*51* This is largely the same as yp_all() except we do the transfer52* from a specific server without the aid of ypbind(8). We need to53* be able to specify the source host explicitly since ypxfr may54* only transfer maps from the NIS master server for any given domain.55* However, if we use the libc version of yp_all(), we could end up56* talking to one of the slaves instead. We do need to dig into libc57* a little though, since it contains the magic XDR function we need.58*/59int60ypxfr_get_map(char *map, char *domain, char *host,61int (*callback)(int, char *, int, char *, int, char*))62{63CLIENT *clnt;64ypreq_nokey req;65unsigned long status;66struct timeval timeout;6768timeout.tv_usec = 0;69timeout.tv_sec = 10;7071/* YPPROC_ALL is a TCP service */72if ((clnt = clnt_create(host, YPPROG, YPVERS, "tcp")) == NULL) {73yp_error("%s", clnt_spcreateerror("failed to \74create tcp handle"));75yp_errno = (enum ypstat)YPXFR_YPERR;76return(1);77}7879req.domain = domain;80req.map = map;81ypresp_allfn = callback;82ypresp_data = NULL;8384(void)clnt_call(clnt, YPPROC_ALL, (xdrproc_t)xdr_ypreq_nokey, &req,85(xdrproc_t)xdr_ypresp_all_seq, &status, timeout);8687clnt_destroy(clnt);8889if (status == YP_NOMORE)90return(0);9192if (status != YP_TRUE) {93yp_errno = (enum ypstat)YPXFR_YPERR;94return(1);95}9697return(0);98}99100101