3 * Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by Bill Paul.
16 * 4. Neither the name of the author nor the names of any co-contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * $FreeBSD: src/libexec/ypxfr/ypxfr_misc.c,v 1.9.2.2 2002/02/15 00:46:54 des Exp $
39 #include <sys/param.h>
41 #include <rpcsvc/yp.h>
42 struct dom_binding {};
43 #include <rpcsvc/ypclnt.h>
44 #include "ypxfr_extern.h"
47 ypxfrerr_string(ypxfrstat code)
51 return ("Map successfully transferred");
54 return ("Master's version not newer");
57 return ("No such map in server's domain");
60 return ("Domain not supported by server");
63 return ("Local resource allocation failure");
66 return ("RPC failure talking to server");
69 return ("Could not get master server address");
72 return ("NIS server/map database error");
75 return ("Request arguments bad");
78 return ("Local database operation failed");
81 return ("Local file I/O operation failed");
84 return ("Map version skew during transfer");
87 return ("Couldn't send \"clear\" request to local ypserv");
90 return ("No local order number in map -- use -f flag");
93 return ("General ypxfr error");
96 return ("Transfer request refused by ypserv");
99 return ("Unknown error code");
105 * These are wrappers for the usual yp_master() and yp_order() functions.
106 * They can use either local yplib functions (the real yp_master() and
107 * yp_order()) or do direct RPCs to a specified server. The latter is
108 * necessary if ypxfr is run on a machine that isn't configured as an
109 * NIS client (this can happen very easily: a given machine need not be
110 * an NIS client in order to be an NIS server).
114 * Careful: yp_master() returns a pointer to a dynamically allocated
115 * buffer. Calling ypproc_master_2() ourselves also returns a pointer
116 * to dynamically allocated memory, though this time it's memory
117 * allocated by the XDR routines. We have to rememver to free() or
118 * xdr_free() the memory as required to avoid leaking memory.
121 ypxfr_get_master(char *domain, char *map, char *source, const int yplib)
123 static char mastername[MAXPATHLEN + 2];
125 bzero((char *)&mastername, sizeof(mastername));
130 if ((res = yp_master(domain, map, &master))) {
133 yp_errno = YPXFR_NODOM;
136 yp_errno = YPXFR_NOMAP;
140 yp_errno = YPXFR_YPERR;
145 snprintf(mastername, sizeof(mastername), "%s", master);
147 return((char *)&mastername);
154 if ((clnt = clnt_create(source,YPPROG,YPVERS,"udp")) == NULL) {
155 yp_error("%s",clnt_spcreateerror("failed to \
156 create udp handle to ypserv"));
157 yp_errno = YPXFR_RPC;
163 if ((resp = ypproc_master_2(&req, clnt)) == NULL) {
164 yp_error("%s",clnt_sperror(clnt,"YPPROC_MASTER \
167 yp_errno = YPXFR_RPC;
171 if (resp->stat != YP_TRUE) {
172 switch (resp->stat) {
174 yp_errno = YPXFR_NODOM;
177 yp_errno = YPXFR_NOMAP;
181 yp_errno = YPXFR_YPERR;
186 snprintf(mastername, sizeof(mastername), "%s", resp->peer);
187 /* xdr_free(xdr_ypresp_master, (char *)&resp); */
188 return((char *)&mastername);
193 ypxfr_get_order(char *domain, char *map, char *source, const int yplib)
198 if ((res = yp_order(domain, map, (int *)&order))) {
201 yp_errno = YPXFR_NODOM;
204 yp_errno = YPXFR_NOMAP;
208 yp_errno = YPXFR_YPERR;
219 if ((clnt = clnt_create(source,YPPROG,YPVERS,"udp")) == NULL) {
220 yp_error("%s",clnt_spcreateerror("couldn't create \
221 udp handle to ypserv"));
222 yp_errno = YPXFR_RPC;
227 if ((resp = ypproc_order_2(&req, clnt)) == NULL) {
228 yp_error("%s", clnt_sperror(clnt, "YPPROC_ORDER \
231 yp_errno = YPXFR_RPC;
235 if (resp->stat != YP_TRUE) {
236 switch (resp->stat) {
238 yp_errno = YPXFR_NODOM;
241 yp_errno = YPXFR_NOMAP;
245 yp_errno = YPXFR_YPERR;
250 return(resp->ordernum);
255 ypxfr_match(char *server, char *domain, char *map, char *key,
256 unsigned long keylen)
261 static char buf[YPMAXRECORD + 2];
263 bzero((char *)buf, sizeof(buf));
265 if ((clnt = clnt_create(server, YPPROG,YPVERS,"udp")) == NULL) {
266 yp_error("failed to create UDP handle: %s",
267 clnt_spcreateerror(server));
271 ypkey.domain = domain;
273 ypkey.key.keydat_len = keylen;
274 ypkey.key.keydat_val = key;
276 if ((ypval = ypproc_match_2(&ypkey, clnt)) == NULL) {
278 yp_error("%s: %s", server,
279 clnt_sperror(clnt,"YPPROC_MATCH failed"));
285 if (ypval->stat != YP_TRUE) {
286 xdr_free((xdrproc_t)xdr_ypresp_val, ypval);
290 xdr_free((xdrproc_t)xdr_ypresp_val, ypval);