xref: /onnv-gate/usr/src/cmd/ypcmd/ypserv_proc.c (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
24*0Sstevel@tonic-gate  * Use is subject to license terms.
25*0Sstevel@tonic-gate  */
26*0Sstevel@tonic-gate 
27*0Sstevel@tonic-gate /*	Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T	*/
28*0Sstevel@tonic-gate /*	  All Rights Reserved  	*/
29*0Sstevel@tonic-gate 
30*0Sstevel@tonic-gate /*
31*0Sstevel@tonic-gate  * Portions of this source code were derived from Berkeley 4.3 BSD
32*0Sstevel@tonic-gate  * under license from the Regents of the University of California.
33*0Sstevel@tonic-gate  */
34*0Sstevel@tonic-gate 
35*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
36*0Sstevel@tonic-gate 
37*0Sstevel@tonic-gate /*
38*0Sstevel@tonic-gate  *
39*0Sstevel@tonic-gate  * This contains YP server code which supplies the set of functions
40*0Sstevel@tonic-gate  * requested using rpc.   The top level functions in this module
41*0Sstevel@tonic-gate  * are those which have symbols of the form YPPROC_xxxx defined in
42*0Sstevel@tonic-gate  * yp_prot.h, and symbols of the form YPOLDPROC_xxxx defined in ypsym.h.
43*0Sstevel@tonic-gate  * The latter exist to provide compatibility to the old version of the yp
44*0Sstevel@tonic-gate  * protocol/server, and may emulate the behavior of the previous software
45*0Sstevel@tonic-gate  * by invoking some other program.
46*0Sstevel@tonic-gate  *
47*0Sstevel@tonic-gate  * This module also contains functions which are used by (and only by) the
48*0Sstevel@tonic-gate  * top-level functions here.
49*0Sstevel@tonic-gate  */
50*0Sstevel@tonic-gate 
51*0Sstevel@tonic-gate #include <sys/types.h>
52*0Sstevel@tonic-gate #include <sys/socket.h>
53*0Sstevel@tonic-gate #include <netinet/in.h>
54*0Sstevel@tonic-gate #include <arpa/inet.h>
55*0Sstevel@tonic-gate #include <dirent.h>
56*0Sstevel@tonic-gate #include <limits.h>
57*0Sstevel@tonic-gate #include <sys/systeminfo.h>
58*0Sstevel@tonic-gate #include <rpc/rpc.h>
59*0Sstevel@tonic-gate #include <string.h>
60*0Sstevel@tonic-gate #include <malloc.h>
61*0Sstevel@tonic-gate #include <stdlib.h>
62*0Sstevel@tonic-gate #include <unistd.h>
63*0Sstevel@tonic-gate #include <stdio.h>
64*0Sstevel@tonic-gate #include "ypsym.h"
65*0Sstevel@tonic-gate #include "ypdefs.h"
66*0Sstevel@tonic-gate #include <ctype.h>
67*0Sstevel@tonic-gate 
68*0Sstevel@tonic-gate /* Use shim version of DBM calls */
69*0Sstevel@tonic-gate #include "shim.h"
70*0Sstevel@tonic-gate #include "shim_hooks.h"
71*0Sstevel@tonic-gate 
72*0Sstevel@tonic-gate USE_YP_PREFIX
73*0Sstevel@tonic-gate USE_YP_SECURE
74*0Sstevel@tonic-gate USE_YP_INTERDOMAIN
75*0Sstevel@tonic-gate 
76*0Sstevel@tonic-gate #ifndef	YPXFR_PROC
77*0Sstevel@tonic-gate #define	YPXFR_PROC "/usr/lib/netsvc/yp/ypxfr"
78*0Sstevel@tonic-gate #endif
79*0Sstevel@tonic-gate static char ypxfr_proc[] = YPXFR_PROC;
80*0Sstevel@tonic-gate #ifndef	YPPUSH_PROC
81*0Sstevel@tonic-gate #define	YPPUSH_PROC "/usr/lib/netsvc/yp/yppush"
82*0Sstevel@tonic-gate #endif
83*0Sstevel@tonic-gate static char yppush_proc[] = YPPUSH_PROC;
84*0Sstevel@tonic-gate struct yppriv_sym {
85*0Sstevel@tonic-gate     char *sym;
86*0Sstevel@tonic-gate     unsigned len;
87*0Sstevel@tonic-gate };
88*0Sstevel@tonic-gate static	char err_fork[] = "ypserv:  %s fork failure.\n";
89*0Sstevel@tonic-gate #define	FORK_ERR logprintf(err_fork, fun)
90*0Sstevel@tonic-gate static char err_execl[] = "ypserv:  %s execl failure.\n";
91*0Sstevel@tonic-gate #define	EXEC_ERR logprintf(err_execl, fun)
92*0Sstevel@tonic-gate static char err_respond[] = "ypserv: %s can't respond to rpc request.\n";
93*0Sstevel@tonic-gate #define	RESPOND_ERR logprintf(err_respond, fun)
94*0Sstevel@tonic-gate static char err_free[] = "ypserv: %s can't free args.\n";
95*0Sstevel@tonic-gate #define	FREE_ERR logprintf(err_free, fun)
96*0Sstevel@tonic-gate static char err_map[] = "ypserv: %s no such map or access denied.\n";
97*0Sstevel@tonic-gate #define	MAP_ERR logprintf(err_map, fun)
98*0Sstevel@tonic-gate static char err_vers[] = "ypserv: %s version not supported.\n";
99*0Sstevel@tonic-gate #define	VERS_ERR logprintf(err_vers, fun)
100*0Sstevel@tonic-gate 
101*0Sstevel@tonic-gate static void ypfilter(DBM *fdb, datum *inkey, datum *outkey, datum *val,
102*0Sstevel@tonic-gate 			uint_t *status, bool_t update);
103*0Sstevel@tonic-gate static bool isypsym(datum *key);
104*0Sstevel@tonic-gate static bool xdrypserv_ypall(XDR *xdrs, struct ypreq_nokey *req);
105*0Sstevel@tonic-gate static int multihomed(struct ypreq_key req, struct ypresp_val *resp,
106*0Sstevel@tonic-gate 			SVCXPRT *xprt, DBM *fdb);
107*0Sstevel@tonic-gate static int omultihomed(struct yprequest req, struct ypresponse *resp,
108*0Sstevel@tonic-gate 			SVCXPRT *xprt, DBM *fdb);
109*0Sstevel@tonic-gate 
110*0Sstevel@tonic-gate 
111*0Sstevel@tonic-gate /* For DNS forwarding */
112*0Sstevel@tonic-gate extern bool dnsforward;
113*0Sstevel@tonic-gate extern bool client_setup_failure;
114*0Sstevel@tonic-gate extern int resolv_pid;
115*0Sstevel@tonic-gate extern CLIENT *resolv_client;
116*0Sstevel@tonic-gate extern char *resolv_tp;
117*0Sstevel@tonic-gate 
118*0Sstevel@tonic-gate /*
119*0Sstevel@tonic-gate  * This determines whether or not a passed domain is served by this
120*0Sstevel@tonic-gate  * server, and returns a boolean.  Used by both old and new protocol
121*0Sstevel@tonic-gate  * versions.
122*0Sstevel@tonic-gate  */
123*0Sstevel@tonic-gate void
ypdomain(SVCXPRT * transp,bool always_respond)124*0Sstevel@tonic-gate ypdomain(SVCXPRT *transp, bool always_respond)
125*0Sstevel@tonic-gate {
126*0Sstevel@tonic-gate 	char domain_name[YPMAXDOMAIN + 1];
127*0Sstevel@tonic-gate 	char *pdomain_name = domain_name;
128*0Sstevel@tonic-gate 	bool isserved;
129*0Sstevel@tonic-gate 	char *fun = "ypdomain";
130*0Sstevel@tonic-gate 	struct netbuf *nbuf;
131*0Sstevel@tonic-gate 	sa_family_t af;
132*0Sstevel@tonic-gate 
133*0Sstevel@tonic-gate 	memset(domain_name, 0, sizeof (domain_name));
134*0Sstevel@tonic-gate 
135*0Sstevel@tonic-gate 	if (!svc_getargs(transp, (xdrproc_t)xdr_ypdomain_wrap_string,
136*0Sstevel@tonic-gate 				(caddr_t)&pdomain_name)) {
137*0Sstevel@tonic-gate 		svcerr_decode(transp);
138*0Sstevel@tonic-gate 		return;
139*0Sstevel@tonic-gate 	}
140*0Sstevel@tonic-gate 
141*0Sstevel@tonic-gate 	/*
142*0Sstevel@tonic-gate 	 * If the file /var/yp/securenets is present on the server, and if
143*0Sstevel@tonic-gate 	 * the hostname is present in the file, then let the client bind to
144*0Sstevel@tonic-gate 	 * the server.
145*0Sstevel@tonic-gate 	 */
146*0Sstevel@tonic-gate 	nbuf = svc_getrpccaller(transp);
147*0Sstevel@tonic-gate 	af = ((struct sockaddr_storage *)nbuf->buf)->ss_family;
148*0Sstevel@tonic-gate 	if (af != AF_INET && af != AF_INET6) {
149*0Sstevel@tonic-gate 		logprintf("Protocol incorrect\n");
150*0Sstevel@tonic-gate 		return;
151*0Sstevel@tonic-gate 	}
152*0Sstevel@tonic-gate 
153*0Sstevel@tonic-gate 	if (!(check_secure_net_ti(nbuf, fun))) {
154*0Sstevel@tonic-gate 		MAP_ERR;
155*0Sstevel@tonic-gate 		return;
156*0Sstevel@tonic-gate 	}
157*0Sstevel@tonic-gate 
158*0Sstevel@tonic-gate 	isserved = ypcheck_domain(domain_name);
159*0Sstevel@tonic-gate 
160*0Sstevel@tonic-gate 	if (isserved || always_respond) {
161*0Sstevel@tonic-gate 
162*0Sstevel@tonic-gate 		if (!svc_sendreply(transp, xdr_bool, (char *)&isserved)) {
163*0Sstevel@tonic-gate 		    RESPOND_ERR;
164*0Sstevel@tonic-gate 		}
165*0Sstevel@tonic-gate 		if (!isserved)
166*0Sstevel@tonic-gate 			logprintf("Domain %s not supported\n",
167*0Sstevel@tonic-gate 					domain_name);
168*0Sstevel@tonic-gate 
169*0Sstevel@tonic-gate 	} else {
170*0Sstevel@tonic-gate 		/*
171*0Sstevel@tonic-gate 		 * This case is the one in which the domain is not
172*0Sstevel@tonic-gate 		 * supported, and in which we are not to respond in the
173*0Sstevel@tonic-gate 		 * unsupported case.  We are going to make an error happen
174*0Sstevel@tonic-gate 		 * to allow the portmapper to end his wait without the
175*0Sstevel@tonic-gate 		 * normal timeout period.  The assumption here is that
176*0Sstevel@tonic-gate 		 * the only process in the world which is using the function
177*0Sstevel@tonic-gate 		 * in its no-answer-if-nack form is the portmapper, which is
178*0Sstevel@tonic-gate 		 * doing the krock for pseudo-broadcast.  If some poor fool
179*0Sstevel@tonic-gate 		 * calls this function as a single-cast message, the nack
180*0Sstevel@tonic-gate 		 * case will look like an incomprehensible error.  Sigh...
181*0Sstevel@tonic-gate 		 * (The traditional Unix disclaimer)
182*0Sstevel@tonic-gate 		 */
183*0Sstevel@tonic-gate 
184*0Sstevel@tonic-gate 		svcerr_decode(transp);
185*0Sstevel@tonic-gate 		logprintf("Domain %s not supported (broadcast)\n",
186*0Sstevel@tonic-gate 				domain_name);
187*0Sstevel@tonic-gate 	}
188*0Sstevel@tonic-gate }
189*0Sstevel@tonic-gate 
190*0Sstevel@tonic-gate /*
191*0Sstevel@tonic-gate  * This implements the yp "match" function.
192*0Sstevel@tonic-gate  */
193*0Sstevel@tonic-gate void
ypmatch(SVCXPRT * transp,struct svc_req * rqstp)194*0Sstevel@tonic-gate ypmatch(SVCXPRT *transp, struct svc_req *rqstp)
195*0Sstevel@tonic-gate {
196*0Sstevel@tonic-gate 	struct ypreq_key req;
197*0Sstevel@tonic-gate 	struct ypresp_val resp;
198*0Sstevel@tonic-gate 	char *fun = "ypmatch";
199*0Sstevel@tonic-gate 	DBM *fdb;
200*0Sstevel@tonic-gate 
201*0Sstevel@tonic-gate 	memset(&req, 0, sizeof (req));
202*0Sstevel@tonic-gate 	memset(&resp, 0, sizeof (resp));
203*0Sstevel@tonic-gate 	resp.status = (unsigned)YP_NOKEY;
204*0Sstevel@tonic-gate 
205*0Sstevel@tonic-gate 	if (!svc_getargs(transp, (xdrproc_t)xdr_ypreq_key, (char *)&req)) {
206*0Sstevel@tonic-gate 		svcerr_decode(transp);
207*0Sstevel@tonic-gate 		return;
208*0Sstevel@tonic-gate 	}
209*0Sstevel@tonic-gate 
210*0Sstevel@tonic-gate 	/*
211*0Sstevel@tonic-gate 	 * sanity check the map name and to a DBM lookup
212*0Sstevel@tonic-gate 	 * also perform an access check...
213*0Sstevel@tonic-gate 	 */
214*0Sstevel@tonic-gate 	if ((fdb = ypset_current_map(req.map, req.domain,
215*0Sstevel@tonic-gate 					&resp.status)) != NULL &&
216*0Sstevel@tonic-gate 		yp_map_access(transp, &resp.status, fdb)) {
217*0Sstevel@tonic-gate 
218*0Sstevel@tonic-gate 		/* Check with the DBM database */
219*0Sstevel@tonic-gate 		resp.valdat = dbm_fetch(fdb, req.keydat);
220*0Sstevel@tonic-gate 		if (resp.valdat.dptr != NULL) {
221*0Sstevel@tonic-gate 			resp.status = YP_TRUE;
222*0Sstevel@tonic-gate 			if (!silent)
223*0Sstevel@tonic-gate 				printf("%s: dbm: %40.40s\n",
224*0Sstevel@tonic-gate 					fun, resp.valdat.dptr);
225*0Sstevel@tonic-gate 			goto send_reply;
226*0Sstevel@tonic-gate 		}
227*0Sstevel@tonic-gate 
228*0Sstevel@tonic-gate 		/*
229*0Sstevel@tonic-gate 		 * If we're being asked to match YP_SECURE or YP_INTERDOMAIN
230*0Sstevel@tonic-gate 		 * and we haven't found it in the dbm file, then we don't
231*0Sstevel@tonic-gate 		 * really want to waste any more time.  Specifically, we don't
232*0Sstevel@tonic-gate 		 * want to ask DNS
233*0Sstevel@tonic-gate 		 */
234*0Sstevel@tonic-gate 		if (req.keydat.dsize == 0 ||
235*0Sstevel@tonic-gate 		    req.keydat.dptr == NULL ||
236*0Sstevel@tonic-gate 		    req.keydat.dptr[0] == '\0' ||
237*0Sstevel@tonic-gate 	strncmp(req.keydat.dptr, yp_secure, req.keydat.dsize) == 0 ||
238*0Sstevel@tonic-gate 	strncmp(req.keydat.dptr, yp_interdomain, req.keydat.dsize) == 0) {
239*0Sstevel@tonic-gate 			goto send_reply;
240*0Sstevel@tonic-gate 		}
241*0Sstevel@tonic-gate 
242*0Sstevel@tonic-gate 		/* Let's try the YP_MULTI_ hack... */
243*0Sstevel@tonic-gate #ifdef MINUS_C_OPTION
244*0Sstevel@tonic-gate 		if (multiflag == TRUE && multihomed(req, &resp, transp, fdb))
245*0Sstevel@tonic-gate 			goto send_reply;
246*0Sstevel@tonic-gate #else
247*0Sstevel@tonic-gate 		if (multihomed(req, &resp, transp, fdb))
248*0Sstevel@tonic-gate 			goto send_reply;
249*0Sstevel@tonic-gate #endif
250*0Sstevel@tonic-gate 
251*0Sstevel@tonic-gate 		/*
252*0Sstevel@tonic-gate 		 * Let's try DNS, but if client_setup_failure is set,
253*0Sstevel@tonic-gate 		 * we have tried DNS in the past and failed, there is
254*0Sstevel@tonic-gate 		 * no reason in forcing an infinite loop by turning
255*0Sstevel@tonic-gate 		 * off DNS in setup_resolv() only to turn it back on
256*0Sstevel@tonic-gate 		 * again here.
257*0Sstevel@tonic-gate 		 */
258*0Sstevel@tonic-gate 		if (!dnsforward && !client_setup_failure) {
259*0Sstevel@tonic-gate 			datum idkey, idval;
260*0Sstevel@tonic-gate 			idkey.dptr = yp_interdomain;
261*0Sstevel@tonic-gate 			idkey.dsize = yp_interdomain_sz;
262*0Sstevel@tonic-gate 			idval = dbm_fetch(fdb, idkey);
263*0Sstevel@tonic-gate 			if (idval.dptr)
264*0Sstevel@tonic-gate 				dnsforward = TRUE;
265*0Sstevel@tonic-gate 		}
266*0Sstevel@tonic-gate 
267*0Sstevel@tonic-gate 		if (dnsforward) {
268*0Sstevel@tonic-gate 			if (!resolv_pid || !resolv_client) {
269*0Sstevel@tonic-gate 				setup_resolv(&dnsforward, &resolv_pid,
270*0Sstevel@tonic-gate 						&resolv_client, resolv_tp, 0);
271*0Sstevel@tonic-gate 				if (resolv_client == NULL)
272*0Sstevel@tonic-gate 					client_setup_failure = TRUE;
273*0Sstevel@tonic-gate 			}
274*0Sstevel@tonic-gate 
275*0Sstevel@tonic-gate 			if (resolv_req(&dnsforward, &resolv_client,
276*0Sstevel@tonic-gate 						&resolv_pid, resolv_tp,
277*0Sstevel@tonic-gate 						rqstp->rq_xprt, &req,
278*0Sstevel@tonic-gate 						req.map) == TRUE)
279*0Sstevel@tonic-gate 				goto free_args;
280*0Sstevel@tonic-gate 		}
281*0Sstevel@tonic-gate 	}
282*0Sstevel@tonic-gate 	send_reply:
283*0Sstevel@tonic-gate 
284*0Sstevel@tonic-gate 	if (!svc_sendreply(transp, (xdrproc_t)xdr_ypresp_val,
285*0Sstevel@tonic-gate 				(caddr_t)&resp)) {
286*0Sstevel@tonic-gate 		RESPOND_ERR;
287*0Sstevel@tonic-gate 	}
288*0Sstevel@tonic-gate 
289*0Sstevel@tonic-gate 	free_args:
290*0Sstevel@tonic-gate 
291*0Sstevel@tonic-gate 	if (!svc_freeargs(transp, (xdrproc_t)xdr_ypreq_key,
292*0Sstevel@tonic-gate 				(char *)&req)) {
293*0Sstevel@tonic-gate 		FREE_ERR;
294*0Sstevel@tonic-gate 	}
295*0Sstevel@tonic-gate }
296*0Sstevel@tonic-gate 
297*0Sstevel@tonic-gate 
298*0Sstevel@tonic-gate /*
299*0Sstevel@tonic-gate  * This implements the yp "get first" function.
300*0Sstevel@tonic-gate  */
301*0Sstevel@tonic-gate void
ypfirst(SVCXPRT * transp)302*0Sstevel@tonic-gate ypfirst(SVCXPRT *transp)
303*0Sstevel@tonic-gate {
304*0Sstevel@tonic-gate 	struct ypreq_nokey req;
305*0Sstevel@tonic-gate 	struct ypresp_key_val resp;
306*0Sstevel@tonic-gate 	char *fun = "ypfirst";
307*0Sstevel@tonic-gate 	DBM *fdb;
308*0Sstevel@tonic-gate 
309*0Sstevel@tonic-gate 	memset(&req, 0, sizeof (req));
310*0Sstevel@tonic-gate 	memset(&resp, 0, sizeof (resp));
311*0Sstevel@tonic-gate 
312*0Sstevel@tonic-gate 	if (!svc_getargs(transp,
313*0Sstevel@tonic-gate 				(xdrproc_t)xdr_ypreq_nokey,
314*0Sstevel@tonic-gate 				(char *)&req)) {
315*0Sstevel@tonic-gate 		svcerr_decode(transp);
316*0Sstevel@tonic-gate 		return;
317*0Sstevel@tonic-gate 	}
318*0Sstevel@tonic-gate 
319*0Sstevel@tonic-gate 	if ((fdb = ypset_current_map(req.map, req.domain,
320*0Sstevel@tonic-gate 					&resp.status)) != NULL &&
321*0Sstevel@tonic-gate 		yp_map_access(transp, &resp.status, fdb)) {
322*0Sstevel@tonic-gate 		ypfilter(fdb, NULL,
323*0Sstevel@tonic-gate 			&resp.keydat, &resp.valdat, &resp.status, FALSE);
324*0Sstevel@tonic-gate 	}
325*0Sstevel@tonic-gate 
326*0Sstevel@tonic-gate 	if (!svc_sendreply(transp,
327*0Sstevel@tonic-gate 				(xdrproc_t)xdr_ypresp_key_val,
328*0Sstevel@tonic-gate 				(char *)&resp)) {
329*0Sstevel@tonic-gate 		RESPOND_ERR;
330*0Sstevel@tonic-gate 	}
331*0Sstevel@tonic-gate 
332*0Sstevel@tonic-gate 	if (!svc_freeargs(transp, (xdrproc_t)xdr_ypreq_nokey,
333*0Sstevel@tonic-gate 				(char *)&req)) {
334*0Sstevel@tonic-gate 		FREE_ERR;
335*0Sstevel@tonic-gate 	}
336*0Sstevel@tonic-gate }
337*0Sstevel@tonic-gate 
338*0Sstevel@tonic-gate /*
339*0Sstevel@tonic-gate  * This implements the yp "get next" function.
340*0Sstevel@tonic-gate  */
341*0Sstevel@tonic-gate void
ypnext(SVCXPRT * transp)342*0Sstevel@tonic-gate ypnext(SVCXPRT *transp)
343*0Sstevel@tonic-gate {
344*0Sstevel@tonic-gate 	struct ypreq_key req;
345*0Sstevel@tonic-gate 	struct ypresp_key_val resp;
346*0Sstevel@tonic-gate 	char *fun = "ypnext";
347*0Sstevel@tonic-gate 	DBM *fdb;
348*0Sstevel@tonic-gate 
349*0Sstevel@tonic-gate 	memset(&req, 0, sizeof (req));
350*0Sstevel@tonic-gate 	memset(&resp, 0, sizeof (resp));
351*0Sstevel@tonic-gate 
352*0Sstevel@tonic-gate 	if (!svc_getargs(transp, (xdrproc_t)xdr_ypreq_key, (char *)&req)) {
353*0Sstevel@tonic-gate 		svcerr_decode(transp);
354*0Sstevel@tonic-gate 		return;
355*0Sstevel@tonic-gate 	}
356*0Sstevel@tonic-gate 
357*0Sstevel@tonic-gate 	if ((fdb = ypset_current_map(req.map, req.domain,
358*0Sstevel@tonic-gate 					&resp.status)) != NULL &&
359*0Sstevel@tonic-gate 		yp_map_access(transp, &resp.status, fdb)) {
360*0Sstevel@tonic-gate 		ypfilter(fdb, &req.keydat,
361*0Sstevel@tonic-gate 			&resp.keydat, &resp.valdat, &resp.status, FALSE);
362*0Sstevel@tonic-gate 	}
363*0Sstevel@tonic-gate 
364*0Sstevel@tonic-gate 	if (!svc_sendreply(transp,
365*0Sstevel@tonic-gate 				(xdrproc_t)xdr_ypresp_key_val,
366*0Sstevel@tonic-gate 				(char *)&resp)) {
367*0Sstevel@tonic-gate 		RESPOND_ERR;
368*0Sstevel@tonic-gate 	}
369*0Sstevel@tonic-gate 
370*0Sstevel@tonic-gate 	if (!svc_freeargs(transp,
371*0Sstevel@tonic-gate 				(xdrproc_t)xdr_ypreq_key,
372*0Sstevel@tonic-gate 				(char *)&req)) {
373*0Sstevel@tonic-gate 		FREE_ERR;
374*0Sstevel@tonic-gate 	}
375*0Sstevel@tonic-gate }
376*0Sstevel@tonic-gate 
377*0Sstevel@tonic-gate /*
378*0Sstevel@tonic-gate  * This implements the "transfer map" function.  It takes the domain
379*0Sstevel@tonic-gate  * and map names and the callback information provided by the
380*0Sstevel@tonic-gate  * requester (yppush on some node), and execs a ypxfr process to do
381*0Sstevel@tonic-gate  * the actual transfer.
382*0Sstevel@tonic-gate  */
383*0Sstevel@tonic-gate void
ypxfr(SVCXPRT * transp,int prog)384*0Sstevel@tonic-gate ypxfr(SVCXPRT *transp, int prog)
385*0Sstevel@tonic-gate {
386*0Sstevel@tonic-gate 	struct ypreq_newxfr newreq;
387*0Sstevel@tonic-gate 	struct ypreq_xfr oldreq;
388*0Sstevel@tonic-gate 	struct ypresp_val resp;  /* not returned to the caller */
389*0Sstevel@tonic-gate 	char transid[32];
390*0Sstevel@tonic-gate 	char proto[32];
391*0Sstevel@tonic-gate 	char name[256];
392*0Sstevel@tonic-gate 	char *pdomain, *pmap;
393*0Sstevel@tonic-gate 	pid_t pid = -1;
394*0Sstevel@tonic-gate 	char *fun = "ypxfr";
395*0Sstevel@tonic-gate 	DBM *fdb;
396*0Sstevel@tonic-gate 
397*0Sstevel@tonic-gate 	if (prog == YPPROC_NEWXFR) {
398*0Sstevel@tonic-gate 		memset(&newreq, 0, sizeof (newreq));
399*0Sstevel@tonic-gate 		if (!svc_getargs(transp, (xdrproc_t)xdr_ypreq_newxfr,
400*0Sstevel@tonic-gate 				(char *)&newreq)) {
401*0Sstevel@tonic-gate 			svcerr_decode(transp);
402*0Sstevel@tonic-gate 			return;
403*0Sstevel@tonic-gate 		}
404*0Sstevel@tonic-gate 
405*0Sstevel@tonic-gate #ifdef OPCOM_DEBUG
406*0Sstevel@tonic-gate 		fprintf(stderr, "newreq:\n"
407*0Sstevel@tonic-gate 			"\tmap_parms:\n"
408*0Sstevel@tonic-gate 			"\t\tdomain:    %s\n"
409*0Sstevel@tonic-gate 			"\t\tmap:       %s\n"
410*0Sstevel@tonic-gate 			"\t\tordernum:  %u\n"
411*0Sstevel@tonic-gate 			"\t\towner:     %s\n"
412*0Sstevel@tonic-gate 			"\ttransid:    %u\n"
413*0Sstevel@tonic-gate 			"\tproto:      %u\n"
414*0Sstevel@tonic-gate 			"\tname:       %s\n\n",
415*0Sstevel@tonic-gate 			newreq.map_parms.domain,
416*0Sstevel@tonic-gate 			newreq.map_parms.map,
417*0Sstevel@tonic-gate 			newreq.map_parms.ordernum,
418*0Sstevel@tonic-gate 			newreq.map_parms.owner,
419*0Sstevel@tonic-gate 			newreq.transid,
420*0Sstevel@tonic-gate 			newreq.proto,
421*0Sstevel@tonic-gate 			newreq.name);
422*0Sstevel@tonic-gate #endif
423*0Sstevel@tonic-gate 		sprintf(transid, "%u", newreq.transid);
424*0Sstevel@tonic-gate 		sprintf(proto, "%u", newreq.proto);
425*0Sstevel@tonic-gate 		sprintf(name, "%s", newreq.ypxfr_owner);
426*0Sstevel@tonic-gate 		pdomain = newreq.ypxfr_domain;
427*0Sstevel@tonic-gate 		pmap = newreq.ypxfr_map;
428*0Sstevel@tonic-gate 	} else if (prog == YPPROC_XFR) {
429*0Sstevel@tonic-gate 		memset(&oldreq, 0, sizeof (oldreq));
430*0Sstevel@tonic-gate 		if (!svc_getargs(transp,
431*0Sstevel@tonic-gate 					(xdrproc_t)xdr_ypreq_xfr,
432*0Sstevel@tonic-gate 					(char *)&oldreq)) {
433*0Sstevel@tonic-gate 		    svcerr_decode(transp);
434*0Sstevel@tonic-gate 		    return;
435*0Sstevel@tonic-gate 		}
436*0Sstevel@tonic-gate 
437*0Sstevel@tonic-gate #ifdef OPCOM_DEBUG
438*0Sstevel@tonic-gate 		fprintf(stderr, "oldreq:\n"
439*0Sstevel@tonic-gate 			"\tmap_parms:\n"
440*0Sstevel@tonic-gate 			"\t\tdomain:    %s\n"
441*0Sstevel@tonic-gate 			"\t\tmap:       %s\n"
442*0Sstevel@tonic-gate 			"\t\tordernum:  %u\n"
443*0Sstevel@tonic-gate 			"\t\towner:     %s\n"
444*0Sstevel@tonic-gate 			"\ttransid:    %u\n"
445*0Sstevel@tonic-gate 			"\tproto:      %u\n"
446*0Sstevel@tonic-gate 			"\tport:       %u\n\n",
447*0Sstevel@tonic-gate 			oldreq.map_parms.domain,
448*0Sstevel@tonic-gate 			oldreq.map_parms.map,
449*0Sstevel@tonic-gate 			oldreq.map_parms.ordernum,
450*0Sstevel@tonic-gate 			oldreq.map_parms.owner,
451*0Sstevel@tonic-gate 			oldreq.transid,
452*0Sstevel@tonic-gate 			oldreq.proto,
453*0Sstevel@tonic-gate 			oldreq.port);
454*0Sstevel@tonic-gate #endif
455*0Sstevel@tonic-gate 
456*0Sstevel@tonic-gate 		sprintf(transid, "%u", oldreq.transid);
457*0Sstevel@tonic-gate 		sprintf(proto, "%u", oldreq.proto);
458*0Sstevel@tonic-gate 		sprintf(name, "%s", oldreq.ypxfr_owner);
459*0Sstevel@tonic-gate 		pdomain = oldreq.ypxfr_domain;
460*0Sstevel@tonic-gate 		pmap = oldreq.ypxfr_map;
461*0Sstevel@tonic-gate 	} else {
462*0Sstevel@tonic-gate 		VERS_ERR;
463*0Sstevel@tonic-gate 	}
464*0Sstevel@tonic-gate 
465*0Sstevel@tonic-gate 	/* Check that the map exists and is accessible */
466*0Sstevel@tonic-gate 	if ((fdb = ypset_current_map(pmap, pdomain, &resp.status)) != NULL &&
467*0Sstevel@tonic-gate 		yp_map_access(transp, &resp.status, fdb)) {
468*0Sstevel@tonic-gate 
469*0Sstevel@tonic-gate 		pid = vfork();
470*0Sstevel@tonic-gate 		if (pid == -1) {
471*0Sstevel@tonic-gate 			FORK_ERR;
472*0Sstevel@tonic-gate 		} else if (pid == 0) {
473*0Sstevel@tonic-gate 		    if (prog == YPPROC_NEWXFR || prog == YPPROC_XFR) {
474*0Sstevel@tonic-gate #ifdef OPCOM_DEBUG
475*0Sstevel@tonic-gate 			fprintf(stderr,
476*0Sstevel@tonic-gate 				"EXECL: %s, -d, %s, -C, %s, %s, %s, %s\n",
477*0Sstevel@tonic-gate 				ypxfr_proc, pdomain,
478*0Sstevel@tonic-gate 				transid, proto, name, pmap);
479*0Sstevel@tonic-gate #endif
480*0Sstevel@tonic-gate 			if (execl(ypxfr_proc, "ypxfr", "-d",
481*0Sstevel@tonic-gate 					pdomain, "-C", transid, proto,
482*0Sstevel@tonic-gate 					name, pmap, NULL))
483*0Sstevel@tonic-gate 			    EXEC_ERR;
484*0Sstevel@tonic-gate 		    } else {
485*0Sstevel@tonic-gate 			VERS_ERR;
486*0Sstevel@tonic-gate 		    }
487*0Sstevel@tonic-gate 		    _exit(1);
488*0Sstevel@tonic-gate 		}
489*0Sstevel@tonic-gate 
490*0Sstevel@tonic-gate 	} else {
491*0Sstevel@tonic-gate 		MAP_ERR;
492*0Sstevel@tonic-gate 	}
493*0Sstevel@tonic-gate 	if (!svc_sendreply(transp, xdr_void, 0)) {
494*0Sstevel@tonic-gate 		RESPOND_ERR;
495*0Sstevel@tonic-gate 	}
496*0Sstevel@tonic-gate 
497*0Sstevel@tonic-gate 	if (prog == YPPROC_NEWXFR) {
498*0Sstevel@tonic-gate 		if (!svc_freeargs(transp,
499*0Sstevel@tonic-gate 					(xdrproc_t)xdr_ypreq_newxfr,
500*0Sstevel@tonic-gate 					(char *)&newreq)) {
501*0Sstevel@tonic-gate 		    FREE_ERR;
502*0Sstevel@tonic-gate 		}
503*0Sstevel@tonic-gate 	}
504*0Sstevel@tonic-gate }
505*0Sstevel@tonic-gate 
506*0Sstevel@tonic-gate /*
507*0Sstevel@tonic-gate  * This implements the "get all" function.
508*0Sstevel@tonic-gate  */
509*0Sstevel@tonic-gate void
ypall(SVCXPRT * transp)510*0Sstevel@tonic-gate ypall(SVCXPRT *transp)
511*0Sstevel@tonic-gate {
512*0Sstevel@tonic-gate 	struct ypreq_nokey req;
513*0Sstevel@tonic-gate 	struct ypresp_val resp;  /* not returned to the caller */
514*0Sstevel@tonic-gate 	pid_t pid;
515*0Sstevel@tonic-gate 	char *fun = "ypall";
516*0Sstevel@tonic-gate 	DBM *fdb;
517*0Sstevel@tonic-gate 
518*0Sstevel@tonic-gate 	req.domain = req.map = NULL;
519*0Sstevel@tonic-gate 
520*0Sstevel@tonic-gate 	memset((char *)&req, 0, sizeof (req));
521*0Sstevel@tonic-gate 
522*0Sstevel@tonic-gate 	if (!svc_getargs(transp,
523*0Sstevel@tonic-gate 				(xdrproc_t)xdr_ypreq_nokey,
524*0Sstevel@tonic-gate 				(char *)&req)) {
525*0Sstevel@tonic-gate 		svcerr_decode(transp);
526*0Sstevel@tonic-gate 		return;
527*0Sstevel@tonic-gate 	}
528*0Sstevel@tonic-gate 
529*0Sstevel@tonic-gate 	pid = fork1();
530*0Sstevel@tonic-gate 
531*0Sstevel@tonic-gate 	if (pid) {
532*0Sstevel@tonic-gate 
533*0Sstevel@tonic-gate 		if (pid == -1) {
534*0Sstevel@tonic-gate 			FORK_ERR;
535*0Sstevel@tonic-gate 		}
536*0Sstevel@tonic-gate 
537*0Sstevel@tonic-gate 		if (!svc_freeargs(transp,
538*0Sstevel@tonic-gate 					(xdrproc_t)xdr_ypreq_nokey,
539*0Sstevel@tonic-gate 					(char *)&req)) {
540*0Sstevel@tonic-gate 			FREE_ERR;
541*0Sstevel@tonic-gate 		}
542*0Sstevel@tonic-gate 
543*0Sstevel@tonic-gate 		return;
544*0Sstevel@tonic-gate 	}
545*0Sstevel@tonic-gate 
546*0Sstevel@tonic-gate 	/*
547*0Sstevel@tonic-gate 	 * access control hack:  If denied then invalidate the map name.
548*0Sstevel@tonic-gate 	 */
549*0Sstevel@tonic-gate 	ypclr_current_map();
550*0Sstevel@tonic-gate 	if ((fdb = ypset_current_map(req.map,
551*0Sstevel@tonic-gate 		req.domain, &resp.status)) != NULL &&
552*0Sstevel@tonic-gate 		!yp_map_access(transp, &resp.status, fdb)) {
553*0Sstevel@tonic-gate 
554*0Sstevel@tonic-gate 		req.map[0] = '-';
555*0Sstevel@tonic-gate 	}
556*0Sstevel@tonic-gate 
557*0Sstevel@tonic-gate 	/*
558*0Sstevel@tonic-gate 	 * This is the child process.  The work gets done by xdrypserv_ypall/
559*0Sstevel@tonic-gate 	 * we must clear the "current map" first so that we do not
560*0Sstevel@tonic-gate 	 * share a seek pointer with the parent server.
561*0Sstevel@tonic-gate 	 */
562*0Sstevel@tonic-gate 
563*0Sstevel@tonic-gate 	if (!svc_sendreply(transp,
564*0Sstevel@tonic-gate 				(xdrproc_t)xdrypserv_ypall,
565*0Sstevel@tonic-gate 				(char *)&req)) {
566*0Sstevel@tonic-gate 		RESPOND_ERR;
567*0Sstevel@tonic-gate 	}
568*0Sstevel@tonic-gate 
569*0Sstevel@tonic-gate 	if (!svc_freeargs(transp,
570*0Sstevel@tonic-gate 				(xdrproc_t)xdr_ypreq_nokey,
571*0Sstevel@tonic-gate 				(char *)&req)) {
572*0Sstevel@tonic-gate 		FREE_ERR;
573*0Sstevel@tonic-gate 	}
574*0Sstevel@tonic-gate 
575*0Sstevel@tonic-gate 	/*
576*0Sstevel@tonic-gate 	 * In yptol mode we may start a cache update thread within a child
577*0Sstevel@tonic-gate 	 * process. It is thus important that child processes do not exit,
578*0Sstevel@tonic-gate 	 * killing any such threads, before the thread has completed.
579*0Sstevel@tonic-gate 	 */
580*0Sstevel@tonic-gate 	if (yptol_mode) {
581*0Sstevel@tonic-gate 		thr_join(0, NULL, NULL);
582*0Sstevel@tonic-gate 	}
583*0Sstevel@tonic-gate 
584*0Sstevel@tonic-gate 	exit(0);
585*0Sstevel@tonic-gate }
586*0Sstevel@tonic-gate 
587*0Sstevel@tonic-gate /*
588*0Sstevel@tonic-gate  * This implements the "get master name" function.
589*0Sstevel@tonic-gate  */
590*0Sstevel@tonic-gate void
ypmaster(SVCXPRT * transp)591*0Sstevel@tonic-gate ypmaster(SVCXPRT *transp)
592*0Sstevel@tonic-gate {
593*0Sstevel@tonic-gate 	struct ypreq_nokey req;
594*0Sstevel@tonic-gate 	struct ypresp_master resp;
595*0Sstevel@tonic-gate 	char *nullstring = "";
596*0Sstevel@tonic-gate 	char *fun = "ypmaster";
597*0Sstevel@tonic-gate 	DBM *fdb;
598*0Sstevel@tonic-gate 
599*0Sstevel@tonic-gate 	memset((char *)&req, 0, sizeof (req));
600*0Sstevel@tonic-gate 	resp.master = nullstring;
601*0Sstevel@tonic-gate 	resp.status = YP_TRUE;
602*0Sstevel@tonic-gate 
603*0Sstevel@tonic-gate 	if (!svc_getargs(transp,
604*0Sstevel@tonic-gate 				(xdrproc_t)xdr_ypreq_nokey,
605*0Sstevel@tonic-gate 				(char *)&req)) {
606*0Sstevel@tonic-gate 		svcerr_decode(transp);
607*0Sstevel@tonic-gate 		return;
608*0Sstevel@tonic-gate 	}
609*0Sstevel@tonic-gate 
610*0Sstevel@tonic-gate 	if ((fdb = ypset_current_map(req.map,
611*0Sstevel@tonic-gate 		req.domain, &resp.status)) != NULL &&
612*0Sstevel@tonic-gate 		yp_map_access(transp, &resp.status, fdb)) {
613*0Sstevel@tonic-gate 
614*0Sstevel@tonic-gate 		if (!ypget_map_master(&resp.master, fdb)) {
615*0Sstevel@tonic-gate 			resp.status = (unsigned)YP_BADDB;
616*0Sstevel@tonic-gate 		}
617*0Sstevel@tonic-gate 	}
618*0Sstevel@tonic-gate 
619*0Sstevel@tonic-gate 	if (!svc_sendreply(transp,
620*0Sstevel@tonic-gate 				(xdrproc_t)xdr_ypresp_master,
621*0Sstevel@tonic-gate 				(char *)&resp)) {
622*0Sstevel@tonic-gate 		RESPOND_ERR;
623*0Sstevel@tonic-gate 	}
624*0Sstevel@tonic-gate 
625*0Sstevel@tonic-gate 	if (!svc_freeargs(transp,
626*0Sstevel@tonic-gate 				(xdrproc_t)xdr_ypreq_nokey,
627*0Sstevel@tonic-gate 				(char *)&req)) {
628*0Sstevel@tonic-gate 		FREE_ERR;
629*0Sstevel@tonic-gate 	}
630*0Sstevel@tonic-gate }
631*0Sstevel@tonic-gate 
632*0Sstevel@tonic-gate /*
633*0Sstevel@tonic-gate  * This implements the "get order number" function.
634*0Sstevel@tonic-gate  */
635*0Sstevel@tonic-gate void
yporder(SVCXPRT * transp)636*0Sstevel@tonic-gate yporder(SVCXPRT *transp)
637*0Sstevel@tonic-gate {
638*0Sstevel@tonic-gate 	struct ypreq_nokey req;
639*0Sstevel@tonic-gate 	struct ypresp_order resp;
640*0Sstevel@tonic-gate 	char *fun = "yporder";
641*0Sstevel@tonic-gate 	DBM *fdb;
642*0Sstevel@tonic-gate 
643*0Sstevel@tonic-gate 	req.domain = req.map = NULL;
644*0Sstevel@tonic-gate 	resp.status  = YP_TRUE;
645*0Sstevel@tonic-gate 	resp.ordernum  = 0;
646*0Sstevel@tonic-gate 
647*0Sstevel@tonic-gate 	memset((char *)&req, 0, sizeof (req));
648*0Sstevel@tonic-gate 
649*0Sstevel@tonic-gate 	if (!svc_getargs(transp,
650*0Sstevel@tonic-gate 				(xdrproc_t)xdr_ypreq_nokey,
651*0Sstevel@tonic-gate 				(char *)&req)) {
652*0Sstevel@tonic-gate 		svcerr_decode(transp);
653*0Sstevel@tonic-gate 		return;
654*0Sstevel@tonic-gate 	}
655*0Sstevel@tonic-gate 
656*0Sstevel@tonic-gate 	resp.ordernum = 0;
657*0Sstevel@tonic-gate 
658*0Sstevel@tonic-gate 	if ((fdb = ypset_current_map(req.map,
659*0Sstevel@tonic-gate 					req.domain,
660*0Sstevel@tonic-gate 					&resp.status)) != NULL &&
661*0Sstevel@tonic-gate 		yp_map_access(transp, &resp.status, fdb)) {
662*0Sstevel@tonic-gate 
663*0Sstevel@tonic-gate 		if (!ypget_map_order(req.map, req.domain, &resp.ordernum)) {
664*0Sstevel@tonic-gate 			resp.status = (unsigned)YP_BADDB;
665*0Sstevel@tonic-gate 		}
666*0Sstevel@tonic-gate 	}
667*0Sstevel@tonic-gate 
668*0Sstevel@tonic-gate 	if (!svc_sendreply(transp,
669*0Sstevel@tonic-gate 				(xdrproc_t)xdr_ypresp_order,
670*0Sstevel@tonic-gate 				(char *)&resp)) {
671*0Sstevel@tonic-gate 		RESPOND_ERR;
672*0Sstevel@tonic-gate 	}
673*0Sstevel@tonic-gate 
674*0Sstevel@tonic-gate 	if (!svc_freeargs(transp,
675*0Sstevel@tonic-gate 				(xdrproc_t)xdr_ypreq_nokey,
676*0Sstevel@tonic-gate 				(char *)&req)) {
677*0Sstevel@tonic-gate 		FREE_ERR;
678*0Sstevel@tonic-gate 	}
679*0Sstevel@tonic-gate }
680*0Sstevel@tonic-gate 
681*0Sstevel@tonic-gate void
ypmaplist(SVCXPRT * transp)682*0Sstevel@tonic-gate ypmaplist(SVCXPRT *transp)
683*0Sstevel@tonic-gate {
684*0Sstevel@tonic-gate 	char domain_name[YPMAXDOMAIN + 1];
685*0Sstevel@tonic-gate 	char *pdomain = domain_name;
686*0Sstevel@tonic-gate 	char *fun = "ypmaplist";
687*0Sstevel@tonic-gate 	struct ypresp_maplist maplist;
688*0Sstevel@tonic-gate 	struct ypmaplist *tmp;
689*0Sstevel@tonic-gate 
690*0Sstevel@tonic-gate 	maplist.list = (struct ypmaplist *)NULL;
691*0Sstevel@tonic-gate 
692*0Sstevel@tonic-gate 	memset(domain_name, 0, sizeof (domain_name));
693*0Sstevel@tonic-gate 
694*0Sstevel@tonic-gate 	if (!svc_getargs(transp,
695*0Sstevel@tonic-gate 				(xdrproc_t)xdr_ypdomain_wrap_string,
696*0Sstevel@tonic-gate 				(caddr_t)&pdomain)) {
697*0Sstevel@tonic-gate 		svcerr_decode(transp);
698*0Sstevel@tonic-gate 		return;
699*0Sstevel@tonic-gate 	}
700*0Sstevel@tonic-gate 
701*0Sstevel@tonic-gate 	maplist.status = yplist_maps(domain_name, &maplist.list);
702*0Sstevel@tonic-gate 
703*0Sstevel@tonic-gate 	if (!svc_sendreply(transp,
704*0Sstevel@tonic-gate 				(xdrproc_t)xdr_ypresp_maplist,
705*0Sstevel@tonic-gate 				(char *)&maplist)) {
706*0Sstevel@tonic-gate 		RESPOND_ERR;
707*0Sstevel@tonic-gate 	}
708*0Sstevel@tonic-gate 
709*0Sstevel@tonic-gate 	while (maplist.list) {
710*0Sstevel@tonic-gate 		tmp = maplist.list->ypml_next;
711*0Sstevel@tonic-gate 		free((char *)maplist.list);
712*0Sstevel@tonic-gate 		maplist.list = tmp;
713*0Sstevel@tonic-gate 	}
714*0Sstevel@tonic-gate }
715*0Sstevel@tonic-gate 
716*0Sstevel@tonic-gate /*
717*0Sstevel@tonic-gate  * Ancillary functions used by the top-level functions within this
718*0Sstevel@tonic-gate  * module
719*0Sstevel@tonic-gate  */
720*0Sstevel@tonic-gate 
721*0Sstevel@tonic-gate /*
722*0Sstevel@tonic-gate  * This returns TRUE if a given key is a yp-private symbol, otherwise
723*0Sstevel@tonic-gate  * FALSE
724*0Sstevel@tonic-gate  */
725*0Sstevel@tonic-gate static bool
isypsym(datum * key)726*0Sstevel@tonic-gate isypsym(datum *key)
727*0Sstevel@tonic-gate {
728*0Sstevel@tonic-gate 	if ((key->dptr == NULL) ||
729*0Sstevel@tonic-gate 		(key->dsize < yp_prefix_sz) ||
730*0Sstevel@tonic-gate 		memcmp(yp_prefix, key->dptr, yp_prefix_sz) ||
731*0Sstevel@tonic-gate 		(!memcmp(key->dptr, "YP_MULTI_", 9))) {
732*0Sstevel@tonic-gate 		return (FALSE);
733*0Sstevel@tonic-gate 	}
734*0Sstevel@tonic-gate 	return (TRUE);
735*0Sstevel@tonic-gate }
736*0Sstevel@tonic-gate 
737*0Sstevel@tonic-gate /*
738*0Sstevel@tonic-gate  * This provides private-symbol filtration for the enumeration functions.
739*0Sstevel@tonic-gate  */
740*0Sstevel@tonic-gate static void
ypfilter(DBM * fdb,datum * inkey,datum * outkey,datum * val,uint_t * status,bool_t update)741*0Sstevel@tonic-gate ypfilter(DBM *fdb, datum *inkey, datum *outkey, datum *val, uint_t *status,
742*0Sstevel@tonic-gate 							bool_t update)
743*0Sstevel@tonic-gate {
744*0Sstevel@tonic-gate 	datum k;
745*0Sstevel@tonic-gate 
746*0Sstevel@tonic-gate 	if (inkey) {
747*0Sstevel@tonic-gate 
748*0Sstevel@tonic-gate 		if (isypsym(inkey)) {
749*0Sstevel@tonic-gate 			*status = (unsigned)YP_BADARGS;
750*0Sstevel@tonic-gate 			return;
751*0Sstevel@tonic-gate 		}
752*0Sstevel@tonic-gate 
753*0Sstevel@tonic-gate 		k = dbm_do_nextkey(fdb, *inkey);
754*0Sstevel@tonic-gate 	} else {
755*0Sstevel@tonic-gate 		k = dbm_firstkey(fdb);
756*0Sstevel@tonic-gate 	}
757*0Sstevel@tonic-gate 
758*0Sstevel@tonic-gate 	while (k.dptr && isypsym(&k)) {
759*0Sstevel@tonic-gate 		k = dbm_nextkey(fdb);
760*0Sstevel@tonic-gate 	}
761*0Sstevel@tonic-gate 
762*0Sstevel@tonic-gate 	if (k.dptr == NULL) {
763*0Sstevel@tonic-gate 		*status = YP_NOMORE;
764*0Sstevel@tonic-gate 		return;
765*0Sstevel@tonic-gate 	}
766*0Sstevel@tonic-gate 
767*0Sstevel@tonic-gate 	*outkey = k;
768*0Sstevel@tonic-gate 
769*0Sstevel@tonic-gate 	/*
770*0Sstevel@tonic-gate 	 * In N2L mode we must call a version of dbm_fetch() that either does
771*0Sstevel@tonic-gate 	 * or does not check for entry updates. In non N2L mode both of these
772*0Sstevel@tonic-gate 	 * will end up doing a normal dbm_fetch().
773*0Sstevel@tonic-gate 	 */
774*0Sstevel@tonic-gate 	if (update)
775*0Sstevel@tonic-gate 		*val = shim_dbm_fetch(fdb, k);
776*0Sstevel@tonic-gate 	else
777*0Sstevel@tonic-gate 		*val = shim_dbm_fetch_noupdate(fdb, k);
778*0Sstevel@tonic-gate 
779*0Sstevel@tonic-gate 	if (val->dptr != NULL) {
780*0Sstevel@tonic-gate 		*status = YP_TRUE;
781*0Sstevel@tonic-gate 	} else {
782*0Sstevel@tonic-gate 		*status = (unsigned)YP_BADDB;
783*0Sstevel@tonic-gate 	}
784*0Sstevel@tonic-gate }
785*0Sstevel@tonic-gate 
786*0Sstevel@tonic-gate /*
787*0Sstevel@tonic-gate  * Serializes a stream of struct ypresp_key_val's.  This is used
788*0Sstevel@tonic-gate  * only by the ypserv side of the transaction.
789*0Sstevel@tonic-gate  */
790*0Sstevel@tonic-gate static bool
xdrypserv_ypall(XDR * xdrs,struct ypreq_nokey * req)791*0Sstevel@tonic-gate xdrypserv_ypall(XDR *xdrs, struct ypreq_nokey *req)
792*0Sstevel@tonic-gate {
793*0Sstevel@tonic-gate 	bool_t more = TRUE;
794*0Sstevel@tonic-gate 	struct ypresp_key_val resp;
795*0Sstevel@tonic-gate 	DBM *fdb;
796*0Sstevel@tonic-gate 
797*0Sstevel@tonic-gate 	resp.keydat.dptr = resp.valdat.dptr = (char *)NULL;
798*0Sstevel@tonic-gate 	resp.keydat.dsize = resp.valdat.dsize = 0;
799*0Sstevel@tonic-gate 
800*0Sstevel@tonic-gate 	if ((fdb = ypset_current_map(req->map, req->domain,
801*0Sstevel@tonic-gate 					&resp.status)) != NULL) {
802*0Sstevel@tonic-gate 		ypfilter(fdb, (datum *) NULL, &resp.keydat, &resp.valdat,
803*0Sstevel@tonic-gate 				&resp.status, FALSE);
804*0Sstevel@tonic-gate 
805*0Sstevel@tonic-gate 		while (resp.status == YP_TRUE) {
806*0Sstevel@tonic-gate 			if (!xdr_bool(xdrs, &more)) {
807*0Sstevel@tonic-gate 				return (FALSE);
808*0Sstevel@tonic-gate 			}
809*0Sstevel@tonic-gate 
810*0Sstevel@tonic-gate 			if (!xdr_ypresp_key_val(xdrs, &resp)) {
811*0Sstevel@tonic-gate 				return (FALSE);
812*0Sstevel@tonic-gate 			}
813*0Sstevel@tonic-gate 
814*0Sstevel@tonic-gate 			ypfilter(fdb, &resp.keydat, &resp.keydat, &resp.valdat,
815*0Sstevel@tonic-gate 					&resp.status, FALSE);
816*0Sstevel@tonic-gate 		}
817*0Sstevel@tonic-gate 	}
818*0Sstevel@tonic-gate 
819*0Sstevel@tonic-gate 	if (!xdr_bool(xdrs, &more)) {
820*0Sstevel@tonic-gate 		return (FALSE);
821*0Sstevel@tonic-gate 	}
822*0Sstevel@tonic-gate 
823*0Sstevel@tonic-gate 	if (!xdr_ypresp_key_val(xdrs, &resp)) {
824*0Sstevel@tonic-gate 		return (FALSE);
825*0Sstevel@tonic-gate 	}
826*0Sstevel@tonic-gate 
827*0Sstevel@tonic-gate 	more = FALSE;
828*0Sstevel@tonic-gate 
829*0Sstevel@tonic-gate 	if (!xdr_bool(xdrs, &more)) {
830*0Sstevel@tonic-gate 		return (FALSE);
831*0Sstevel@tonic-gate 	}
832*0Sstevel@tonic-gate 
833*0Sstevel@tonic-gate 	return (TRUE);
834*0Sstevel@tonic-gate }
835*0Sstevel@tonic-gate 
836*0Sstevel@tonic-gate /*
837*0Sstevel@tonic-gate  * Additions for sparc cluster support
838*0Sstevel@tonic-gate  */
839*0Sstevel@tonic-gate 
840*0Sstevel@tonic-gate /*
841*0Sstevel@tonic-gate  * Check for special multihomed host cookie in the key.  If there,
842*0Sstevel@tonic-gate  * collect the addresses from the comma separated list and return
843*0Sstevel@tonic-gate  * the one that's nearest the client.
844*0Sstevel@tonic-gate  */
845*0Sstevel@tonic-gate static int
multihomed(struct ypreq_key req,struct ypresp_val * resp,SVCXPRT * xprt,DBM * fdb)846*0Sstevel@tonic-gate multihomed(struct ypreq_key req, struct ypresp_val *resp,
847*0Sstevel@tonic-gate 		SVCXPRT *xprt, DBM *fdb)
848*0Sstevel@tonic-gate {
849*0Sstevel@tonic-gate 	char *cp, *bp;
850*0Sstevel@tonic-gate 	ulong_t bestaddr, call_addr;
851*0Sstevel@tonic-gate 	struct netbuf *nbuf;
852*0Sstevel@tonic-gate 	char name[PATH_MAX];
853*0Sstevel@tonic-gate 	static char localbuf[_PBLKSIZ];	/* buffer for multihomed IPv6 addr */
854*0Sstevel@tonic-gate 
855*0Sstevel@tonic-gate 	if (strcmp(req.map, "hosts.byname") &&
856*0Sstevel@tonic-gate 			strcmp(req.map, "ipnodes.byname"))
857*0Sstevel@tonic-gate 		/* default status is YP_NOKEY */
858*0Sstevel@tonic-gate 		return (0);
859*0Sstevel@tonic-gate 
860*0Sstevel@tonic-gate 	if (strncmp(req.keydat.dptr, "YP_MULTI_", 9)) {
861*0Sstevel@tonic-gate 		datum tmpname;
862*0Sstevel@tonic-gate 
863*0Sstevel@tonic-gate 		strncpy(name, "YP_MULTI_", 9);
864*0Sstevel@tonic-gate 		strncpy(name + 9, req.keydat.dptr, req.keydat.dsize);
865*0Sstevel@tonic-gate 		tmpname.dsize = req.keydat.dsize + 9;
866*0Sstevel@tonic-gate 		tmpname.dptr = name;
867*0Sstevel@tonic-gate 		resp->valdat = dbm_fetch(fdb, tmpname);
868*0Sstevel@tonic-gate 	} else {
869*0Sstevel@tonic-gate 		/*
870*0Sstevel@tonic-gate 		 * Return whole line (for debugging) if YP_MULTI_hostnam
871*0Sstevel@tonic-gate 		 * is specified.
872*0Sstevel@tonic-gate 		 */
873*0Sstevel@tonic-gate 		resp->valdat = dbm_fetch(fdb, req.keydat);
874*0Sstevel@tonic-gate 		if (resp->valdat.dptr != NULL)
875*0Sstevel@tonic-gate 			return (1);
876*0Sstevel@tonic-gate 	}
877*0Sstevel@tonic-gate 
878*0Sstevel@tonic-gate 	if (resp->valdat.dptr == NULL)
879*0Sstevel@tonic-gate 		return (0);
880*0Sstevel@tonic-gate 
881*0Sstevel@tonic-gate 	strncpy(name, req.keydat.dptr, req.keydat.dsize);
882*0Sstevel@tonic-gate 	name[req.keydat.dsize] = NULL;
883*0Sstevel@tonic-gate 
884*0Sstevel@tonic-gate 	if (strcmp(req.map, "ipnodes.byname") == 0) {
885*0Sstevel@tonic-gate 		/*
886*0Sstevel@tonic-gate 		 * This section handles multihomed IPv6 addresses.
887*0Sstevel@tonic-gate 		 * It returns all the IPv6 addresses one per line and only
888*0Sstevel@tonic-gate 		 * the requested hostname is returned.  NO aliases will be
889*0Sstevel@tonic-gate 		 * returned.  This is done exactly the same way DNS forwarding
890*0Sstevel@tonic-gate 		 * daemon handles multihomed hosts.
891*0Sstevel@tonic-gate 		 * New IPv6 enabled clients should be able to handle this
892*0Sstevel@tonic-gate 		 * information returned.  The sorting is also the client's
893*0Sstevel@tonic-gate 		 * responsibility.
894*0Sstevel@tonic-gate 		 */
895*0Sstevel@tonic-gate 
896*0Sstevel@tonic-gate 		char *buf, *endbuf;
897*0Sstevel@tonic-gate 
898*0Sstevel@tonic-gate 		if ((buf = strdup(resp->valdat.dptr)) == NULL) /* no memory */
899*0Sstevel@tonic-gate 			return (0);
900*0Sstevel@tonic-gate 		if ((bp = strtok(buf, " \t")) == NULL) { /* no address field */
901*0Sstevel@tonic-gate 			free(buf);
902*0Sstevel@tonic-gate 			return (0);
903*0Sstevel@tonic-gate 		}
904*0Sstevel@tonic-gate 		if ((cp = strtok(NULL, "")) == NULL) { /* no host field */
905*0Sstevel@tonic-gate 			free(buf);
906*0Sstevel@tonic-gate 			return (0);
907*0Sstevel@tonic-gate 		}
908*0Sstevel@tonic-gate 		if ((cp = strtok(bp, ",")) != NULL) { /* multihomed host */
909*0Sstevel@tonic-gate 			int bsize;
910*0Sstevel@tonic-gate 
911*0Sstevel@tonic-gate 			localbuf[0] = '\0';
912*0Sstevel@tonic-gate 			bsize = sizeof (localbuf);
913*0Sstevel@tonic-gate 			endbuf = localbuf;
914*0Sstevel@tonic-gate 
915*0Sstevel@tonic-gate 			while (cp) {
916*0Sstevel@tonic-gate 				if ((strlen(cp) + strlen(name)) >= bsize) {
917*0Sstevel@tonic-gate 					/* out of range */
918*0Sstevel@tonic-gate 					break;
919*0Sstevel@tonic-gate 				}
920*0Sstevel@tonic-gate 				sprintf(endbuf, "%s %s\n", cp, name);
921*0Sstevel@tonic-gate 				cp = strtok(NULL, ",");
922*0Sstevel@tonic-gate 				endbuf = &endbuf[strlen(endbuf)];
923*0Sstevel@tonic-gate 				bsize = &localbuf[sizeof (localbuf)] - endbuf;
924*0Sstevel@tonic-gate 			}
925*0Sstevel@tonic-gate 			resp->valdat.dptr = localbuf;
926*0Sstevel@tonic-gate 			resp->valdat.dsize = strlen(localbuf);
927*0Sstevel@tonic-gate 		}
928*0Sstevel@tonic-gate 
929*0Sstevel@tonic-gate 		free(buf);
930*0Sstevel@tonic-gate 		/* remove trailing newline */
931*0Sstevel@tonic-gate 		if (resp->valdat.dsize &&
932*0Sstevel@tonic-gate 			resp->valdat.dptr[resp->valdat.dsize-1] == '\n') {
933*0Sstevel@tonic-gate 			resp->valdat.dptr[resp->valdat.dsize-1] = '\0';
934*0Sstevel@tonic-gate 			resp->valdat.dsize -= 1;
935*0Sstevel@tonic-gate 		}
936*0Sstevel@tonic-gate 
937*0Sstevel@tonic-gate 		resp->status = YP_TRUE;
938*0Sstevel@tonic-gate 		return (1);
939*0Sstevel@tonic-gate 	}
940*0Sstevel@tonic-gate 	nbuf = svc_getrpccaller(xprt);
941*0Sstevel@tonic-gate 	/*
942*0Sstevel@tonic-gate 	 * OK, now I have a netbuf structure which I'm supposed to
943*0Sstevel@tonic-gate 	 * treat as opaque...  I hate transport independance!
944*0Sstevel@tonic-gate 	 * So, we're just gonna doit wrong...  By wrong I mean that
945*0Sstevel@tonic-gate 	 * we assume that the buf part of the netbuf structure is going
946*0Sstevel@tonic-gate 	 * to be a sockaddr_in.  We'll then check the assumed family
947*0Sstevel@tonic-gate 	 * member and hope that we find AF_INET in there...  if not
948*0Sstevel@tonic-gate 	 * then we can't continue.
949*0Sstevel@tonic-gate 	 */
950*0Sstevel@tonic-gate 	if (((struct sockaddr_in *)(nbuf->buf))->sin_family != AF_INET)
951*0Sstevel@tonic-gate 		return (0);
952*0Sstevel@tonic-gate 
953*0Sstevel@tonic-gate 	call_addr = ((struct sockaddr_in *)(nbuf->buf))->sin_addr.s_addr;
954*0Sstevel@tonic-gate 
955*0Sstevel@tonic-gate 	cp = resp->valdat.dptr;
956*0Sstevel@tonic-gate 	if ((bp = strtok(cp, " \t")) == NULL) /* no address field */
957*0Sstevel@tonic-gate 		return (0);
958*0Sstevel@tonic-gate 	if ((cp = strtok(NULL, "")) == NULL)  /* no host field */
959*0Sstevel@tonic-gate 		return (0);
960*0Sstevel@tonic-gate 	bp = strtok(bp, ",");
961*0Sstevel@tonic-gate 
962*0Sstevel@tonic-gate 	bestaddr = inet_addr(bp);
963*0Sstevel@tonic-gate 	while (cp = strtok(NULL, ",")) {
964*0Sstevel@tonic-gate 		ulong_t taddr;
965*0Sstevel@tonic-gate 
966*0Sstevel@tonic-gate 		taddr = inet_addr(cp);
967*0Sstevel@tonic-gate 		if (ntohl(call_addr ^ taddr) < ntohl(call_addr ^ bestaddr))
968*0Sstevel@tonic-gate 			bestaddr = taddr;
969*0Sstevel@tonic-gate 	}
970*0Sstevel@tonic-gate 	cp = resp->valdat.dptr;
971*0Sstevel@tonic-gate 	sprintf(cp, "%s %s", inet_ntoa(*(struct in_addr *)&bestaddr), name);
972*0Sstevel@tonic-gate 	resp->valdat.dsize = strlen(cp);
973*0Sstevel@tonic-gate 
974*0Sstevel@tonic-gate 	resp->status = YP_TRUE;
975*0Sstevel@tonic-gate 
976*0Sstevel@tonic-gate 	return (1);
977*0Sstevel@tonic-gate }
978*0Sstevel@tonic-gate 
979*0Sstevel@tonic-gate /* V1 dispatch routines */
980*0Sstevel@tonic-gate void
ypoldmatch(SVCXPRT * transp,struct svc_req * rqstp)981*0Sstevel@tonic-gate ypoldmatch(SVCXPRT *transp, struct svc_req *rqstp)
982*0Sstevel@tonic-gate {
983*0Sstevel@tonic-gate 	bool dbmop_ok = TRUE;
984*0Sstevel@tonic-gate 	struct yprequest req;
985*0Sstevel@tonic-gate 	struct ypreq_key nrq;
986*0Sstevel@tonic-gate 	struct ypresponse resp;
987*0Sstevel@tonic-gate 	char *fun = "ypoldmatch";
988*0Sstevel@tonic-gate 	DBM *fdb;
989*0Sstevel@tonic-gate 
990*0Sstevel@tonic-gate 	memset((void *) &req, 0, sizeof (req));
991*0Sstevel@tonic-gate 	memset((void *) &resp, 0, sizeof (resp));
992*0Sstevel@tonic-gate 
993*0Sstevel@tonic-gate 	if (!svc_getargs(transp,
994*0Sstevel@tonic-gate 				(xdrproc_t)_xdr_yprequest,
995*0Sstevel@tonic-gate 				(caddr_t)&req)) {
996*0Sstevel@tonic-gate 		svcerr_decode(transp);
997*0Sstevel@tonic-gate 		return;
998*0Sstevel@tonic-gate 	}
999*0Sstevel@tonic-gate 
1000*0Sstevel@tonic-gate 	if (req.yp_reqtype != YPMATCH_REQTYPE) {
1001*0Sstevel@tonic-gate 		resp.ypmatch_resp_status = (unsigned)YP_BADARGS;
1002*0Sstevel@tonic-gate 		dbmop_ok = FALSE;
1003*0Sstevel@tonic-gate 	}
1004*0Sstevel@tonic-gate 
1005*0Sstevel@tonic-gate 	if (dbmop_ok &&
1006*0Sstevel@tonic-gate 		(((fdb = ypset_current_map(req.ypmatch_req_map,
1007*0Sstevel@tonic-gate 						req.ypmatch_req_domain,
1008*0Sstevel@tonic-gate 						&resp.ypmatch_resp_status))
1009*0Sstevel@tonic-gate 						!= NULL) &&
1010*0Sstevel@tonic-gate 						yp_map_access(transp,
1011*0Sstevel@tonic-gate 						&resp.ypmatch_resp_status,
1012*0Sstevel@tonic-gate 						fdb))) {
1013*0Sstevel@tonic-gate 
1014*0Sstevel@tonic-gate 		/* Check with the DBM database */
1015*0Sstevel@tonic-gate 		resp.ypmatch_resp_valdat = dbm_fetch(fdb,
1016*0Sstevel@tonic-gate 						req.ypmatch_req_keydat);
1017*0Sstevel@tonic-gate 
1018*0Sstevel@tonic-gate 		if (resp.ypmatch_resp_valptr != NULL) {
1019*0Sstevel@tonic-gate 			resp.ypmatch_resp_status = YP_TRUE;
1020*0Sstevel@tonic-gate 			if (!silent)
1021*0Sstevel@tonic-gate 				printf("%s: dbm: %s\n",
1022*0Sstevel@tonic-gate 					fun, resp.ypmatch_resp_valptr);
1023*0Sstevel@tonic-gate 			goto send_oldreply;
1024*0Sstevel@tonic-gate 		}
1025*0Sstevel@tonic-gate 
1026*0Sstevel@tonic-gate 		/*
1027*0Sstevel@tonic-gate 		 * If we're being asked to match YP_SECURE or YP_INTERDOMAIN
1028*0Sstevel@tonic-gate 		 * and we haven't found it in the dbm file, then we don't
1029*0Sstevel@tonic-gate 		 * really want to waste any more time.  Specifically, we don't
1030*0Sstevel@tonic-gate 		 * want to ask DNS
1031*0Sstevel@tonic-gate 		 */
1032*0Sstevel@tonic-gate 		if (req.ypmatch_req_keysize == 0 ||
1033*0Sstevel@tonic-gate 		    req.ypmatch_req_keyptr == NULL ||
1034*0Sstevel@tonic-gate 		    req.ypmatch_req_keyptr[0] == '\0' ||
1035*0Sstevel@tonic-gate 		    strncmp(req.ypmatch_req_keyptr, "YP_SECURE", 9) == 0 ||
1036*0Sstevel@tonic-gate 		    strncmp(req.ypmatch_req_keyptr, "YP_INTERDOMAIN", 14) == 0)
1037*0Sstevel@tonic-gate 
1038*0Sstevel@tonic-gate 		    goto send_oldreply;
1039*0Sstevel@tonic-gate 
1040*0Sstevel@tonic-gate 		/* Let's try the YP_MULTI_ hack... */
1041*0Sstevel@tonic-gate #ifdef MINUS_C_OPTION
1042*0Sstevel@tonic-gate 		if (multiflag == TRUE && omultihomed(req, &resp, transp, fdb))
1043*0Sstevel@tonic-gate 			goto send_oldreply;
1044*0Sstevel@tonic-gate #else
1045*0Sstevel@tonic-gate 		if (omultihomed(req, &resp, transp, fdb))
1046*0Sstevel@tonic-gate 			goto send_oldreply;
1047*0Sstevel@tonic-gate #endif
1048*0Sstevel@tonic-gate 
1049*0Sstevel@tonic-gate 		/* Let's try DNS */
1050*0Sstevel@tonic-gate 		if (!dnsforward) {
1051*0Sstevel@tonic-gate 			USE_YP_INTERDOMAIN
1052*0Sstevel@tonic-gate 			datum idkey, idval;
1053*0Sstevel@tonic-gate 			idkey.dptr = yp_interdomain;
1054*0Sstevel@tonic-gate 			idkey.dsize = yp_interdomain_sz;
1055*0Sstevel@tonic-gate 			idval = dbm_fetch(fdb, idkey);
1056*0Sstevel@tonic-gate 			if (idval.dptr)
1057*0Sstevel@tonic-gate 				dnsforward = TRUE;
1058*0Sstevel@tonic-gate 		}
1059*0Sstevel@tonic-gate 
1060*0Sstevel@tonic-gate 		if (dnsforward) {
1061*0Sstevel@tonic-gate 		    if (!resolv_pid)
1062*0Sstevel@tonic-gate 			setup_resolv(&dnsforward, &resolv_pid, &resolv_client,
1063*0Sstevel@tonic-gate 					resolv_tp, 0);
1064*0Sstevel@tonic-gate 
1065*0Sstevel@tonic-gate 		    if (req.yp_reqtype == YPREQ_KEY) {
1066*0Sstevel@tonic-gate 			nrq = req.yp_reqbody.yp_req_keytype;
1067*0Sstevel@tonic-gate 
1068*0Sstevel@tonic-gate 			resolv_req(&dnsforward, &resolv_client, &resolv_pid,
1069*0Sstevel@tonic-gate 					resolv_tp, rqstp->rq_xprt,
1070*0Sstevel@tonic-gate 					&nrq, nrq.map);
1071*0Sstevel@tonic-gate 		    }
1072*0Sstevel@tonic-gate 		    return;
1073*0Sstevel@tonic-gate 		}
1074*0Sstevel@tonic-gate 	}
1075*0Sstevel@tonic-gate 
1076*0Sstevel@tonic-gate 	send_oldreply:
1077*0Sstevel@tonic-gate 
1078*0Sstevel@tonic-gate 	if (!svc_sendreply(transp,
1079*0Sstevel@tonic-gate 				(xdrproc_t)_xdr_ypresponse,
1080*0Sstevel@tonic-gate 				(caddr_t)&resp)) {
1081*0Sstevel@tonic-gate 		RESPOND_ERR;
1082*0Sstevel@tonic-gate 	}
1083*0Sstevel@tonic-gate 
1084*0Sstevel@tonic-gate 	if (!svc_freeargs(transp,
1085*0Sstevel@tonic-gate 				(xdrproc_t)_xdr_yprequest,
1086*0Sstevel@tonic-gate 				(char *)&req)) {
1087*0Sstevel@tonic-gate 		FREE_ERR;
1088*0Sstevel@tonic-gate 	}
1089*0Sstevel@tonic-gate }
1090*0Sstevel@tonic-gate 
1091*0Sstevel@tonic-gate void
ypoldfirst(SVCXPRT * transp)1092*0Sstevel@tonic-gate ypoldfirst(SVCXPRT *transp)
1093*0Sstevel@tonic-gate {
1094*0Sstevel@tonic-gate 	bool dbmop_ok = TRUE;
1095*0Sstevel@tonic-gate 	struct yprequest req;
1096*0Sstevel@tonic-gate 	struct ypresponse resp;
1097*0Sstevel@tonic-gate 	char *fun = "ypoldfirst";
1098*0Sstevel@tonic-gate 	DBM *fdb;
1099*0Sstevel@tonic-gate 
1100*0Sstevel@tonic-gate 	memset((void *) &req, 0, sizeof (req));
1101*0Sstevel@tonic-gate 	memset((void *) &resp, 0, sizeof (resp));
1102*0Sstevel@tonic-gate 
1103*0Sstevel@tonic-gate 	if (!svc_getargs(transp,
1104*0Sstevel@tonic-gate 				(xdrproc_t)_xdr_yprequest,
1105*0Sstevel@tonic-gate 				(caddr_t)&req)) {
1106*0Sstevel@tonic-gate 		svcerr_decode(transp);
1107*0Sstevel@tonic-gate 		return;
1108*0Sstevel@tonic-gate 	}
1109*0Sstevel@tonic-gate 
1110*0Sstevel@tonic-gate 	if (req.yp_reqtype != YPFIRST_REQTYPE) {
1111*0Sstevel@tonic-gate 		resp.ypfirst_resp_status = (unsigned)YP_BADARGS;
1112*0Sstevel@tonic-gate 		dbmop_ok = FALSE;
1113*0Sstevel@tonic-gate 	}
1114*0Sstevel@tonic-gate 
1115*0Sstevel@tonic-gate 	if (dbmop_ok &&
1116*0Sstevel@tonic-gate 		((fdb = ypset_current_map(req.ypfirst_req_map,
1117*0Sstevel@tonic-gate 						req.ypfirst_req_domain,
1118*0Sstevel@tonic-gate 						&resp.ypfirst_resp_status))
1119*0Sstevel@tonic-gate 						!= NULL) &&
1120*0Sstevel@tonic-gate 						yp_map_access(transp,
1121*0Sstevel@tonic-gate 						&resp.ypfirst_resp_status,
1122*0Sstevel@tonic-gate 						fdb)) {
1123*0Sstevel@tonic-gate 
1124*0Sstevel@tonic-gate 		resp.ypfirst_resp_keydat = dbm_firstkey(fdb);
1125*0Sstevel@tonic-gate 
1126*0Sstevel@tonic-gate 		if (resp.ypfirst_resp_keyptr != NULL) {
1127*0Sstevel@tonic-gate 			resp.ypfirst_resp_valdat =
1128*0Sstevel@tonic-gate 				dbm_fetch(fdb, resp.ypfirst_resp_keydat);
1129*0Sstevel@tonic-gate 
1130*0Sstevel@tonic-gate 			if (resp.ypfirst_resp_valptr != NULL) {
1131*0Sstevel@tonic-gate 				resp.ypfirst_resp_status = YP_TRUE;
1132*0Sstevel@tonic-gate 			} else {
1133*0Sstevel@tonic-gate 				resp.ypfirst_resp_status = (unsigned)YP_BADDB;
1134*0Sstevel@tonic-gate 			}
1135*0Sstevel@tonic-gate 		} else {
1136*0Sstevel@tonic-gate 			resp.ypfirst_resp_status = (unsigned)YP_NOKEY;
1137*0Sstevel@tonic-gate 		}
1138*0Sstevel@tonic-gate 	}
1139*0Sstevel@tonic-gate 
1140*0Sstevel@tonic-gate 	resp.yp_resptype = YPFIRST_RESPTYPE;
1141*0Sstevel@tonic-gate 
1142*0Sstevel@tonic-gate 	if (!svc_sendreply(transp,
1143*0Sstevel@tonic-gate 				(xdrproc_t)_xdr_ypresponse,
1144*0Sstevel@tonic-gate 				(caddr_t)&resp)) {
1145*0Sstevel@tonic-gate 		RESPOND_ERR;
1146*0Sstevel@tonic-gate 	}
1147*0Sstevel@tonic-gate 
1148*0Sstevel@tonic-gate 	if (!svc_freeargs(transp,
1149*0Sstevel@tonic-gate 				(xdrproc_t)_xdr_yprequest,
1150*0Sstevel@tonic-gate 				(caddr_t)&req)) {
1151*0Sstevel@tonic-gate 		FREE_ERR;
1152*0Sstevel@tonic-gate 	}
1153*0Sstevel@tonic-gate }
1154*0Sstevel@tonic-gate 
1155*0Sstevel@tonic-gate void
ypoldnext(SVCXPRT * transp)1156*0Sstevel@tonic-gate ypoldnext(SVCXPRT *transp)
1157*0Sstevel@tonic-gate {
1158*0Sstevel@tonic-gate 	bool dbmop_ok = TRUE;
1159*0Sstevel@tonic-gate 	struct yprequest req;
1160*0Sstevel@tonic-gate 	struct ypresponse resp;
1161*0Sstevel@tonic-gate 	char *fun = "ypoldnext";
1162*0Sstevel@tonic-gate 	DBM *fdb;
1163*0Sstevel@tonic-gate 
1164*0Sstevel@tonic-gate 	memset((void *) &req, 0, sizeof (req));
1165*0Sstevel@tonic-gate 	memset((void *) &resp, 0, sizeof (resp));
1166*0Sstevel@tonic-gate 
1167*0Sstevel@tonic-gate 	if (!svc_getargs(transp,
1168*0Sstevel@tonic-gate 				(xdrproc_t)_xdr_yprequest,
1169*0Sstevel@tonic-gate 				(caddr_t)&req)) {
1170*0Sstevel@tonic-gate 		svcerr_decode(transp);
1171*0Sstevel@tonic-gate 		return;
1172*0Sstevel@tonic-gate 	}
1173*0Sstevel@tonic-gate 
1174*0Sstevel@tonic-gate 	if (req.yp_reqtype != YPNEXT_REQTYPE) {
1175*0Sstevel@tonic-gate 		resp.ypnext_resp_status = (unsigned)YP_BADARGS;
1176*0Sstevel@tonic-gate 		dbmop_ok = FALSE;
1177*0Sstevel@tonic-gate 	}
1178*0Sstevel@tonic-gate 
1179*0Sstevel@tonic-gate 	if (dbmop_ok &&
1180*0Sstevel@tonic-gate 		((fdb = ypset_current_map(req.ypnext_req_map,
1181*0Sstevel@tonic-gate 					req.ypnext_req_domain,
1182*0Sstevel@tonic-gate 					&resp.ypnext_resp_status)) != NULL &&
1183*0Sstevel@tonic-gate 		yp_map_access(transp, &resp.ypnext_resp_status, fdb))) {
1184*0Sstevel@tonic-gate 
1185*0Sstevel@tonic-gate 		resp.ypnext_resp_keydat = dbm_nextkey(fdb);
1186*0Sstevel@tonic-gate 
1187*0Sstevel@tonic-gate 		if (resp.ypnext_resp_keyptr != NULL) {
1188*0Sstevel@tonic-gate 			resp.ypnext_resp_valdat =
1189*0Sstevel@tonic-gate 			dbm_fetch(fdb, resp.ypnext_resp_keydat);
1190*0Sstevel@tonic-gate 
1191*0Sstevel@tonic-gate 			if (resp.ypnext_resp_valptr != NULL) {
1192*0Sstevel@tonic-gate 				resp.ypnext_resp_status = YP_TRUE;
1193*0Sstevel@tonic-gate 			} else {
1194*0Sstevel@tonic-gate 				resp.ypnext_resp_status = (unsigned)YP_BADDB;
1195*0Sstevel@tonic-gate 			}
1196*0Sstevel@tonic-gate 		} else {
1197*0Sstevel@tonic-gate 			resp.ypnext_resp_status = (unsigned)YP_NOMORE;
1198*0Sstevel@tonic-gate 		}
1199*0Sstevel@tonic-gate 	}
1200*0Sstevel@tonic-gate 
1201*0Sstevel@tonic-gate 	resp.yp_resptype = YPNEXT_RESPTYPE;
1202*0Sstevel@tonic-gate 
1203*0Sstevel@tonic-gate 	if (!svc_sendreply(transp,
1204*0Sstevel@tonic-gate 				(xdrproc_t)_xdr_ypresponse,
1205*0Sstevel@tonic-gate 				(caddr_t)&resp)) {
1206*0Sstevel@tonic-gate 		RESPOND_ERR;
1207*0Sstevel@tonic-gate 	}
1208*0Sstevel@tonic-gate 
1209*0Sstevel@tonic-gate 	if (!svc_freeargs(transp,
1210*0Sstevel@tonic-gate 				(xdrproc_t)_xdr_yprequest,
1211*0Sstevel@tonic-gate 				(caddr_t)&req)) {
1212*0Sstevel@tonic-gate 		FREE_ERR;
1213*0Sstevel@tonic-gate 	}
1214*0Sstevel@tonic-gate }
1215*0Sstevel@tonic-gate 
1216*0Sstevel@tonic-gate /*
1217*0Sstevel@tonic-gate  * This retrieves the order number and master peer name from the map.
1218*0Sstevel@tonic-gate  * The conditions for the various message fields are: domain is filled
1219*0Sstevel@tonic-gate  * in iff the domain exists.  map is filled in iff the map exists.
1220*0Sstevel@tonic-gate  * order number is filled in iff it's in the map.  owner is filled in
1221*0Sstevel@tonic-gate  * iff the master peer is in the map.
1222*0Sstevel@tonic-gate  */
1223*0Sstevel@tonic-gate void
ypoldpoll(SVCXPRT * transp)1224*0Sstevel@tonic-gate ypoldpoll(SVCXPRT *transp)
1225*0Sstevel@tonic-gate {
1226*0Sstevel@tonic-gate 	struct yprequest req;
1227*0Sstevel@tonic-gate 	struct ypresponse resp;
1228*0Sstevel@tonic-gate 	char *map = "";
1229*0Sstevel@tonic-gate 	char *domain = "";
1230*0Sstevel@tonic-gate 	char *owner = "";
1231*0Sstevel@tonic-gate 	uint_t error;
1232*0Sstevel@tonic-gate 	char *fun = "ypoldpoll";
1233*0Sstevel@tonic-gate 	DBM *fdb;
1234*0Sstevel@tonic-gate 
1235*0Sstevel@tonic-gate 	memset((void *) &req, 0, sizeof (req));
1236*0Sstevel@tonic-gate 	memset((void *) &resp, 0, sizeof (resp));
1237*0Sstevel@tonic-gate 
1238*0Sstevel@tonic-gate 	if (!svc_getargs(transp,
1239*0Sstevel@tonic-gate 				(xdrproc_t)_xdr_yprequest,
1240*0Sstevel@tonic-gate 				(caddr_t)&req)) {
1241*0Sstevel@tonic-gate 		svcerr_decode(transp);
1242*0Sstevel@tonic-gate 		return;
1243*0Sstevel@tonic-gate 	}
1244*0Sstevel@tonic-gate 
1245*0Sstevel@tonic-gate 	if (req.yp_reqtype == YPPOLL_REQTYPE) {
1246*0Sstevel@tonic-gate 		if (strcmp(req.yppoll_req_domain, "yp_private") == 0 ||
1247*0Sstevel@tonic-gate 			strcmp(req.yppoll_req_map, "ypdomains") == 0 ||
1248*0Sstevel@tonic-gate 			strcmp(req.yppoll_req_map, "ypmaps") == 0) {
1249*0Sstevel@tonic-gate 
1250*0Sstevel@tonic-gate 			/*
1251*0Sstevel@tonic-gate 			 * Backward comatibility for 2.0 NIS servers
1252*0Sstevel@tonic-gate 			 */
1253*0Sstevel@tonic-gate 			domain = req.yppoll_req_domain;
1254*0Sstevel@tonic-gate 			map = req.yppoll_req_map;
1255*0Sstevel@tonic-gate 		} else if ((fdb = ypset_current_map(req.yppoll_req_map,
1256*0Sstevel@tonic-gate 				req.yppoll_req_domain,
1257*0Sstevel@tonic-gate 				&error)) != NULL) {
1258*0Sstevel@tonic-gate 			domain = req.yppoll_req_domain;
1259*0Sstevel@tonic-gate 			map = req.yppoll_req_map;
1260*0Sstevel@tonic-gate 			ypget_map_order(map, domain,
1261*0Sstevel@tonic-gate 					&resp.yppoll_resp_ordernum);
1262*0Sstevel@tonic-gate 			ypget_map_master(&owner, fdb);
1263*0Sstevel@tonic-gate 		} else {
1264*0Sstevel@tonic-gate 			switch ((int)error) {
1265*0Sstevel@tonic-gate 			case YP_BADDB:
1266*0Sstevel@tonic-gate 				map = req.yppoll_req_map;
1267*0Sstevel@tonic-gate 				/* Fall through to set the domain too. */
1268*0Sstevel@tonic-gate 
1269*0Sstevel@tonic-gate 			case YP_NOMAP:
1270*0Sstevel@tonic-gate 				domain = req.yppoll_req_domain;
1271*0Sstevel@tonic-gate 				break;
1272*0Sstevel@tonic-gate 			}
1273*0Sstevel@tonic-gate 		}
1274*0Sstevel@tonic-gate 	}
1275*0Sstevel@tonic-gate 
1276*0Sstevel@tonic-gate 	resp.yp_resptype = YPPOLL_RESPTYPE;
1277*0Sstevel@tonic-gate 	resp.yppoll_resp_domain = domain;
1278*0Sstevel@tonic-gate 	resp.yppoll_resp_map = map;
1279*0Sstevel@tonic-gate 	resp.yppoll_resp_owner = owner;
1280*0Sstevel@tonic-gate 
1281*0Sstevel@tonic-gate 	if (!svc_sendreply(transp,
1282*0Sstevel@tonic-gate 				(xdrproc_t)_xdr_ypresponse,
1283*0Sstevel@tonic-gate 				(caddr_t)&resp)) {
1284*0Sstevel@tonic-gate 		RESPOND_ERR;
1285*0Sstevel@tonic-gate 	}
1286*0Sstevel@tonic-gate 
1287*0Sstevel@tonic-gate 	if (!svc_freeargs(transp,
1288*0Sstevel@tonic-gate 				(xdrproc_t)_xdr_yprequest,
1289*0Sstevel@tonic-gate 				(caddr_t)&req)) {
1290*0Sstevel@tonic-gate 		FREE_ERR;
1291*0Sstevel@tonic-gate 	}
1292*0Sstevel@tonic-gate }
1293*0Sstevel@tonic-gate 
1294*0Sstevel@tonic-gate void
ypoldpush(SVCXPRT * transp)1295*0Sstevel@tonic-gate ypoldpush(SVCXPRT *transp)
1296*0Sstevel@tonic-gate {
1297*0Sstevel@tonic-gate 	struct yprequest req;
1298*0Sstevel@tonic-gate 	struct ypresp_val resp;
1299*0Sstevel@tonic-gate 	pid_t pid = -1;
1300*0Sstevel@tonic-gate 	char *fun = "ypoldpush";
1301*0Sstevel@tonic-gate 	DBM *fdb;
1302*0Sstevel@tonic-gate 
1303*0Sstevel@tonic-gate 	memset((void *) &req, 0, sizeof (req));
1304*0Sstevel@tonic-gate 
1305*0Sstevel@tonic-gate 	if (!svc_getargs(transp,
1306*0Sstevel@tonic-gate 				(xdrproc_t)_xdr_yprequest,
1307*0Sstevel@tonic-gate 				(caddr_t)&req)) {
1308*0Sstevel@tonic-gate 		svcerr_decode(transp);
1309*0Sstevel@tonic-gate 		return;
1310*0Sstevel@tonic-gate 	}
1311*0Sstevel@tonic-gate 
1312*0Sstevel@tonic-gate 	if (((fdb = ypset_current_map(req.yppush_req_map,
1313*0Sstevel@tonic-gate 					req.yppush_req_domain,
1314*0Sstevel@tonic-gate 					&resp.status)) != NULL) &&
1315*0Sstevel@tonic-gate 		(yp_map_access(transp, &resp.status, fdb))) {
1316*0Sstevel@tonic-gate 
1317*0Sstevel@tonic-gate 		pid = vfork();
1318*0Sstevel@tonic-gate 	}
1319*0Sstevel@tonic-gate 
1320*0Sstevel@tonic-gate 	if (pid == -1) {
1321*0Sstevel@tonic-gate 		FORK_ERR;
1322*0Sstevel@tonic-gate 	} else if (pid == 0) {
1323*0Sstevel@tonic-gate 		ypclr_current_map();
1324*0Sstevel@tonic-gate 
1325*0Sstevel@tonic-gate 		if (execl(yppush_proc, "yppush", "-d", req.yppush_req_domain,
1326*0Sstevel@tonic-gate 				req.yppush_req_map, NULL)) {
1327*0Sstevel@tonic-gate 			EXEC_ERR;
1328*0Sstevel@tonic-gate 		}
1329*0Sstevel@tonic-gate 		_exit(1);
1330*0Sstevel@tonic-gate 	}
1331*0Sstevel@tonic-gate 
1332*0Sstevel@tonic-gate 	if (!svc_sendreply(transp,
1333*0Sstevel@tonic-gate 				(xdrproc_t)xdr_void,
1334*0Sstevel@tonic-gate 				(caddr_t)NULL)) {
1335*0Sstevel@tonic-gate 		RESPOND_ERR;
1336*0Sstevel@tonic-gate 	}
1337*0Sstevel@tonic-gate 
1338*0Sstevel@tonic-gate 	if (!svc_freeargs(transp,
1339*0Sstevel@tonic-gate 				(xdrproc_t)_xdr_yprequest,
1340*0Sstevel@tonic-gate 				(caddr_t)&req)) {
1341*0Sstevel@tonic-gate 		FREE_ERR;
1342*0Sstevel@tonic-gate 	}
1343*0Sstevel@tonic-gate }
1344*0Sstevel@tonic-gate 
1345*0Sstevel@tonic-gate void
ypoldpull(SVCXPRT * transp)1346*0Sstevel@tonic-gate ypoldpull(SVCXPRT *transp)
1347*0Sstevel@tonic-gate {
1348*0Sstevel@tonic-gate 	struct yprequest req;
1349*0Sstevel@tonic-gate 	struct ypresp_val resp;
1350*0Sstevel@tonic-gate 	pid_t pid = -1;
1351*0Sstevel@tonic-gate 	char *fun = "ypoldpull";
1352*0Sstevel@tonic-gate 	DBM *fdb;
1353*0Sstevel@tonic-gate 
1354*0Sstevel@tonic-gate 	memset((void *) &req, 0, sizeof (req));
1355*0Sstevel@tonic-gate 
1356*0Sstevel@tonic-gate 	if (!svc_getargs(transp,
1357*0Sstevel@tonic-gate 				(xdrproc_t)_xdr_yprequest,
1358*0Sstevel@tonic-gate 				(caddr_t)&req)) {
1359*0Sstevel@tonic-gate 		svcerr_decode(transp);
1360*0Sstevel@tonic-gate 		return;
1361*0Sstevel@tonic-gate 	}
1362*0Sstevel@tonic-gate 
1363*0Sstevel@tonic-gate 	if (req.yp_reqtype == YPPULL_REQTYPE) {
1364*0Sstevel@tonic-gate 
1365*0Sstevel@tonic-gate 		if (((fdb = ypset_current_map(req.yppull_req_map,
1366*0Sstevel@tonic-gate 						req.yppull_req_domain,
1367*0Sstevel@tonic-gate 						&resp.status)) == NULL) ||
1368*0Sstevel@tonic-gate 			(yp_map_access(transp, &resp.status, fdb))) {
1369*0Sstevel@tonic-gate 			pid = vfork();
1370*0Sstevel@tonic-gate 		}
1371*0Sstevel@tonic-gate 
1372*0Sstevel@tonic-gate 		if (pid == -1) {
1373*0Sstevel@tonic-gate 			FORK_ERR;
1374*0Sstevel@tonic-gate 		} else if (pid == 0) {
1375*0Sstevel@tonic-gate 			ypclr_current_map();
1376*0Sstevel@tonic-gate 
1377*0Sstevel@tonic-gate 			if (execl(ypxfr_proc, "ypxfr", "-d",
1378*0Sstevel@tonic-gate 					req.yppull_req_domain,
1379*0Sstevel@tonic-gate 					req.yppull_req_map, NULL)) {
1380*0Sstevel@tonic-gate 				EXEC_ERR;
1381*0Sstevel@tonic-gate 			}
1382*0Sstevel@tonic-gate 			_exit(1);
1383*0Sstevel@tonic-gate 		}
1384*0Sstevel@tonic-gate 	}
1385*0Sstevel@tonic-gate 
1386*0Sstevel@tonic-gate 	if (!svc_freeargs(transp,
1387*0Sstevel@tonic-gate 				(xdrproc_t)_xdr_yprequest,
1388*0Sstevel@tonic-gate 				(caddr_t)&req)) {
1389*0Sstevel@tonic-gate 		FREE_ERR;
1390*0Sstevel@tonic-gate 	}
1391*0Sstevel@tonic-gate }
1392*0Sstevel@tonic-gate 
1393*0Sstevel@tonic-gate void
ypoldget(SVCXPRT * transp)1394*0Sstevel@tonic-gate ypoldget(SVCXPRT *transp)
1395*0Sstevel@tonic-gate {
1396*0Sstevel@tonic-gate 	struct yprequest req;
1397*0Sstevel@tonic-gate 	struct ypresp_val resp;
1398*0Sstevel@tonic-gate 	pid_t pid = -1;
1399*0Sstevel@tonic-gate 	char *fun = "ypoldget";
1400*0Sstevel@tonic-gate 	DBM *fdb;
1401*0Sstevel@tonic-gate 
1402*0Sstevel@tonic-gate 	memset((void *) &req, 0, sizeof (req));
1403*0Sstevel@tonic-gate 
1404*0Sstevel@tonic-gate 	if (!svc_getargs(transp,
1405*0Sstevel@tonic-gate 				(xdrproc_t)_xdr_yprequest,
1406*0Sstevel@tonic-gate 				(caddr_t)&req)) {
1407*0Sstevel@tonic-gate 		svcerr_decode(transp);
1408*0Sstevel@tonic-gate 		return;
1409*0Sstevel@tonic-gate 	}
1410*0Sstevel@tonic-gate 
1411*0Sstevel@tonic-gate 	if (!svc_sendreply(transp, xdr_void, 0)) {
1412*0Sstevel@tonic-gate 		RESPOND_ERR;
1413*0Sstevel@tonic-gate 	}
1414*0Sstevel@tonic-gate 
1415*0Sstevel@tonic-gate 	if (req.yp_reqtype == YPGET_REQTYPE) {
1416*0Sstevel@tonic-gate 
1417*0Sstevel@tonic-gate 		if (((fdb = ypset_current_map(req.ypget_req_map,
1418*0Sstevel@tonic-gate 						req.ypget_req_domain,
1419*0Sstevel@tonic-gate 						&resp.status)) == NULL) ||
1420*0Sstevel@tonic-gate 			(yp_map_access(transp, &resp.status, fdb))) {
1421*0Sstevel@tonic-gate 
1422*0Sstevel@tonic-gate 			pid = vfork();
1423*0Sstevel@tonic-gate 		}
1424*0Sstevel@tonic-gate 
1425*0Sstevel@tonic-gate 		if (pid == -1) {
1426*0Sstevel@tonic-gate 			FORK_ERR;
1427*0Sstevel@tonic-gate 		} else if (pid == 0) {
1428*0Sstevel@tonic-gate 
1429*0Sstevel@tonic-gate 			ypclr_current_map();
1430*0Sstevel@tonic-gate 
1431*0Sstevel@tonic-gate 			if (execl(ypxfr_proc, "ypxfr", "-d",
1432*0Sstevel@tonic-gate 					req.ypget_req_domain, "-h",
1433*0Sstevel@tonic-gate 					req.ypget_req_owner,
1434*0Sstevel@tonic-gate 					req.ypget_req_map, NULL)) {
1435*0Sstevel@tonic-gate 
1436*0Sstevel@tonic-gate 				EXEC_ERR;
1437*0Sstevel@tonic-gate 			}
1438*0Sstevel@tonic-gate 			_exit(1);
1439*0Sstevel@tonic-gate 		}
1440*0Sstevel@tonic-gate 	}
1441*0Sstevel@tonic-gate 
1442*0Sstevel@tonic-gate 	if (!svc_freeargs(transp,
1443*0Sstevel@tonic-gate 				(xdrproc_t)_xdr_yprequest,
1444*0Sstevel@tonic-gate 				(caddr_t)&req)) {
1445*0Sstevel@tonic-gate 		RESPOND_ERR;
1446*0Sstevel@tonic-gate 	}
1447*0Sstevel@tonic-gate }
1448*0Sstevel@tonic-gate 
1449*0Sstevel@tonic-gate static int
omultihomed(struct yprequest req,struct ypresponse * resp,SVCXPRT * xprt,DBM * fdb)1450*0Sstevel@tonic-gate omultihomed(struct yprequest req,
1451*0Sstevel@tonic-gate 	    struct ypresponse *resp, SVCXPRT *xprt, DBM *fdb)
1452*0Sstevel@tonic-gate {
1453*0Sstevel@tonic-gate 	char *cp, *bp;
1454*0Sstevel@tonic-gate 	char name[PATH_MAX];
1455*0Sstevel@tonic-gate 	struct netbuf *nbuf;
1456*0Sstevel@tonic-gate 	ulong_t bestaddr, call_addr;
1457*0Sstevel@tonic-gate 
1458*0Sstevel@tonic-gate 	if (strcmp(req.ypmatch_req_map, "hosts.byname"))
1459*0Sstevel@tonic-gate 		return (0);
1460*0Sstevel@tonic-gate 
1461*0Sstevel@tonic-gate 	if (strncmp(req.ypmatch_req_keyptr, "YP_MULTI_", 9)) {
1462*0Sstevel@tonic-gate 		datum tmpname;
1463*0Sstevel@tonic-gate 
1464*0Sstevel@tonic-gate 		strncpy(name, "YP_MULTI_", 9);
1465*0Sstevel@tonic-gate 		strncpy(name + 9, req.ypmatch_req_keyptr,
1466*0Sstevel@tonic-gate 			req.ypmatch_req_keysize);
1467*0Sstevel@tonic-gate 		tmpname.dsize = req.ypmatch_req_keysize + 9;
1468*0Sstevel@tonic-gate 		tmpname.dptr = name;
1469*0Sstevel@tonic-gate 		resp->ypmatch_resp_valdat = dbm_fetch(fdb, tmpname);
1470*0Sstevel@tonic-gate 	} else {
1471*0Sstevel@tonic-gate 		resp->ypmatch_resp_valdat =
1472*0Sstevel@tonic-gate 			dbm_fetch(fdb, req.ypmatch_req_keydat);
1473*0Sstevel@tonic-gate 		if (resp->ypmatch_resp_valptr != NULL)
1474*0Sstevel@tonic-gate 			return (1);
1475*0Sstevel@tonic-gate 	}
1476*0Sstevel@tonic-gate 
1477*0Sstevel@tonic-gate 	if (resp->ypmatch_resp_valptr == NULL)
1478*0Sstevel@tonic-gate 		return (0);
1479*0Sstevel@tonic-gate 
1480*0Sstevel@tonic-gate 	strncpy(name, req.ypmatch_req_keyptr, req.ypmatch_req_keysize);
1481*0Sstevel@tonic-gate 	name[req.ypmatch_req_keysize] = NULL;
1482*0Sstevel@tonic-gate 
1483*0Sstevel@tonic-gate 	nbuf = svc_getrpccaller(xprt);
1484*0Sstevel@tonic-gate 
1485*0Sstevel@tonic-gate 	/*
1486*0Sstevel@tonic-gate 	 * OK, now I have a netbuf structure which I'm supposed to treat
1487*0Sstevel@tonic-gate 	 * as opaque...  I hate transport independance!  So, we're just
1488*0Sstevel@tonic-gate 	 * gonna doit wrong...  By wrong I mean that we assume that the
1489*0Sstevel@tonic-gate 	 * buf part of the netbuf structure is going to be a sockaddr_in.
1490*0Sstevel@tonic-gate 	 * We'll then check the assumed family member and hope that we
1491*0Sstevel@tonic-gate 	 * find AF_INET in there...  if not then we can't continue.
1492*0Sstevel@tonic-gate 	 */
1493*0Sstevel@tonic-gate 	if (((struct sockaddr_in *)(nbuf->buf))->sin_family != AF_INET)
1494*0Sstevel@tonic-gate 		return (0);
1495*0Sstevel@tonic-gate 
1496*0Sstevel@tonic-gate 	call_addr = ((struct sockaddr_in *)(nbuf->buf))->sin_addr.s_addr;
1497*0Sstevel@tonic-gate 
1498*0Sstevel@tonic-gate 	cp = resp->ypmatch_resp_valptr;
1499*0Sstevel@tonic-gate 	if ((bp = strtok(cp, "\t")) == NULL)	/* No address field */
1500*0Sstevel@tonic-gate 		return (0);
1501*0Sstevel@tonic-gate 	if ((cp = strtok(NULL, "")) == NULL)	/* No host field */
1502*0Sstevel@tonic-gate 		return (0);
1503*0Sstevel@tonic-gate 	bp = strtok(bp, ",");
1504*0Sstevel@tonic-gate 
1505*0Sstevel@tonic-gate 	bestaddr = inet_addr(bp);
1506*0Sstevel@tonic-gate 	while (cp = strtok(NULL, ",")) {
1507*0Sstevel@tonic-gate 		ulong_t taddr;
1508*0Sstevel@tonic-gate 
1509*0Sstevel@tonic-gate 		taddr = inet_addr(cp);
1510*0Sstevel@tonic-gate 		if (ntohl(call_addr ^ taddr) < ntohl(call_addr ^ bestaddr))
1511*0Sstevel@tonic-gate 			bestaddr = taddr;
1512*0Sstevel@tonic-gate 	}
1513*0Sstevel@tonic-gate 
1514*0Sstevel@tonic-gate 	cp = resp->ypmatch_resp_valptr;
1515*0Sstevel@tonic-gate 	sprintf(cp, "%s %s", inet_ntoa(*(struct in_addr *)&bestaddr), name);
1516*0Sstevel@tonic-gate 	resp->ypmatch_resp_valsize = strlen(cp);
1517*0Sstevel@tonic-gate 
1518*0Sstevel@tonic-gate 	resp->ypmatch_resp_status = YP_TRUE;
1519*0Sstevel@tonic-gate 
1520*0Sstevel@tonic-gate 	return (1);
1521*0Sstevel@tonic-gate }
1522