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
34 static const char rcsid[] =
42 #include <sys/param.h>
44 #include <rpcsvc/yp.h>
45 struct dom_binding {};
46 #include <rpcsvc/ypclnt.h>
47 #include "ypxfr_extern.h"
50 ypxfrerr_string(ypxfrstat code)
54 return ("Map successfully transferred");
57 return ("Master's version not newer");
60 return ("No such map in server's domain");
63 return ("Domain not supported by server");
66 return ("Local resource allocation failure");
69 return ("RPC failure talking to server");
72 return ("Could not get master server address");
75 return ("NIS server/map database error");
78 return ("Request arguments bad");
81 return ("Local database operation failed");
84 return ("Local file I/O operation failed");
87 return ("Map version skew during transfer");
90 return ("Couldn't send \"clear\" request to local ypserv");
93 return ("No local order number in map -- use -f flag");
96 return ("General ypxfr error");
99 return ("Transfer request refused by ypserv");
102 return ("Unknown error code");
108 * These are wrappers for the usual yp_master() and yp_order() functions.
109 * They can use either local yplib functions (the real yp_master() and
110 * yp_order()) or do direct RPCs to a specified server. The latter is
111 * necessary if ypxfr is run on a machine that isn't configured as an
112 * NIS client (this can happen very easily: a given machine need not be
113 * an NIS client in order to be an NIS server).
117 * Careful: yp_master() returns a pointer to a dynamically allocated
118 * buffer. Calling ypproc_master_2() ourselves also returns a pointer
119 * to dynamically allocated memory, though this time it's memory
120 * allocated by the XDR routines. We have to rememver to free() or
121 * xdr_free() the memory as required to avoid leaking memory.
124 ypxfr_get_master(char *domain, char *map, char *source, const int yplib)
126 static char mastername[MAXPATHLEN + 2];
128 bzero((char *)&mastername, sizeof(mastername));
133 if ((res = yp_master(domain, map, &master))) {
136 yp_errno = YPXFR_NODOM;
139 yp_errno = YPXFR_NOMAP;
143 yp_errno = YPXFR_YPERR;
148 snprintf(mastername, sizeof(mastername), "%s", master);
150 return((char *)&mastername);
157 if ((clnt = clnt_create(source,YPPROG,YPVERS,"udp")) == NULL) {
158 yp_error("%s",clnt_spcreateerror("failed to \
159 create udp handle to ypserv"));
160 yp_errno = YPXFR_RPC;
166 if ((resp = ypproc_master_2(&req, clnt)) == NULL) {
167 yp_error("%s",clnt_sperror(clnt,"YPPROC_MASTER \
170 yp_errno = YPXFR_RPC;
174 if (resp->stat != YP_TRUE) {
175 switch (resp->stat) {
177 yp_errno = YPXFR_NODOM;
180 yp_errno = YPXFR_NOMAP;
184 yp_errno = YPXFR_YPERR;
189 snprintf(mastername, sizeof(mastername), "%s", resp->peer);
190 /* xdr_free(xdr_ypresp_master, (char *)&resp); */
191 return((char *)&mastername);
196 ypxfr_get_order(char *domain, char *map, char *source, const int yplib)
201 if ((res = yp_order(domain, map, (int *)&order))) {
204 yp_errno = YPXFR_NODOM;
207 yp_errno = YPXFR_NOMAP;
211 yp_errno = YPXFR_YPERR;
222 if ((clnt = clnt_create(source,YPPROG,YPVERS,"udp")) == NULL) {
223 yp_error("%s",clnt_spcreateerror("couldn't create \
224 udp handle to ypserv"));
225 yp_errno = YPXFR_RPC;
230 if ((resp = ypproc_order_2(&req, clnt)) == NULL) {
231 yp_error("%s", clnt_sperror(clnt, "YPPROC_ORDER \
234 yp_errno = YPXFR_RPC;
238 if (resp->stat != YP_TRUE) {
239 switch (resp->stat) {
241 yp_errno = YPXFR_NODOM;
244 yp_errno = YPXFR_NOMAP;
248 yp_errno = YPXFR_YPERR;
253 return(resp->ordernum);
258 ypxfr_match(char *server, char *domain, char *map, char *key,
259 unsigned long keylen)
264 static char buf[YPMAXRECORD + 2];
266 bzero(buf, sizeof(buf));
268 if ((clnt = clnt_create(server, YPPROG,YPVERS,"udp")) == NULL) {
269 yp_error("failed to create UDP handle: %s",
270 clnt_spcreateerror(server));
274 ypkey.domain = domain;
276 ypkey.key.keydat_len = keylen;
277 ypkey.key.keydat_val = key;
279 if ((ypval = ypproc_match_2(&ypkey, clnt)) == NULL) {
281 yp_error("%s: %s", server,
282 clnt_sperror(clnt,"YPPROC_MATCH failed"));
288 if (ypval->stat != YP_TRUE) {
289 xdr_free((xdrproc_t)xdr_ypresp_val, ypval);
293 xdr_free((xdrproc_t)xdr_ypresp_val, ypval);