xref: /titanic_53/usr/src/cmd/ypcmd/ypupdated/rpc.ypupdated.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 1990-2003 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*7c478bd9Sstevel@tonic-gate 
29*7c478bd9Sstevel@tonic-gate /*
30*7c478bd9Sstevel@tonic-gate  * NIS update service
31*7c478bd9Sstevel@tonic-gate  */
32*7c478bd9Sstevel@tonic-gate #include <stdio.h>
33*7c478bd9Sstevel@tonic-gate #include <sys/wait.h>
34*7c478bd9Sstevel@tonic-gate #include <sys/time.h>
35*7c478bd9Sstevel@tonic-gate #include <sys/file.h>
36*7c478bd9Sstevel@tonic-gate #include <ctype.h>
37*7c478bd9Sstevel@tonic-gate #include <rpc/rpc.h>
38*7c478bd9Sstevel@tonic-gate #include <rpc/auth_des.h>
39*7c478bd9Sstevel@tonic-gate #include <sys/socket.h>
40*7c478bd9Sstevel@tonic-gate #include <sys/signal.h>
41*7c478bd9Sstevel@tonic-gate #include <sys/stat.h>
42*7c478bd9Sstevel@tonic-gate #include <sys/termio.h>
43*7c478bd9Sstevel@tonic-gate #include <strings.h>
44*7c478bd9Sstevel@tonic-gate #include <rpcsvc/ypclnt.h>
45*7c478bd9Sstevel@tonic-gate #include <rpcsvc/yp_prot.h>
46*7c478bd9Sstevel@tonic-gate #include <netdir.h>
47*7c478bd9Sstevel@tonic-gate #include <rpcsvc/ypupd.h>
48*7c478bd9Sstevel@tonic-gate #include <netdb.h>
49*7c478bd9Sstevel@tonic-gate #include "shim.h"
50*7c478bd9Sstevel@tonic-gate #include "yptol.h"
51*7c478bd9Sstevel@tonic-gate 
52*7c478bd9Sstevel@tonic-gate #define	RPC_INETDSOCK	0	/* socket descriptor if using inetd */
53*7c478bd9Sstevel@tonic-gate #define	debug(msg)	/* turn off debugging */
54*7c478bd9Sstevel@tonic-gate 
55*7c478bd9Sstevel@tonic-gate char YPDIR[] = "/var/yp";
56*7c478bd9Sstevel@tonic-gate char UPDATEFILE[] = "updaters";
57*7c478bd9Sstevel@tonic-gate 
58*7c478bd9Sstevel@tonic-gate void ypupdate_prog();
59*7c478bd9Sstevel@tonic-gate void detachfromtty();
60*7c478bd9Sstevel@tonic-gate int insecure;
61*7c478bd9Sstevel@tonic-gate extern SVCXPRT *svctcp_create(int, uint_t, uint_t);
62*7c478bd9Sstevel@tonic-gate extern SVCXPRT *svcudp_create();
63*7c478bd9Sstevel@tonic-gate 
64*7c478bd9Sstevel@tonic-gate main(argc, argv)
65*7c478bd9Sstevel@tonic-gate 	int argc;
66*7c478bd9Sstevel@tonic-gate 	char *argv[];
67*7c478bd9Sstevel@tonic-gate {
68*7c478bd9Sstevel@tonic-gate 	char *cmd;
69*7c478bd9Sstevel@tonic-gate 	static int issock();
70*7c478bd9Sstevel@tonic-gate 	int connmaxrec = RPC_MAXDATASIZE;
71*7c478bd9Sstevel@tonic-gate 	struct stat filestat;
72*7c478bd9Sstevel@tonic-gate 
73*7c478bd9Sstevel@tonic-gate 	/*
74*7c478bd9Sstevel@tonic-gate 	 * Check if we are running in N2L mode. If so updated is unsuported.
75*7c478bd9Sstevel@tonic-gate 	 * This could be done by calling is_yptol_mode(), from libnisdb, but it
76*7c478bd9Sstevel@tonic-gate 	 * seems over complex to pull in an entire library for one check so
77*7c478bd9Sstevel@tonic-gate 	 * do it in line. Just pull in the name of file to check.
78*7c478bd9Sstevel@tonic-gate 	 */
79*7c478bd9Sstevel@tonic-gate 	if (stat(NTOL_MAP_FILE, &filestat) != -1) {
80*7c478bd9Sstevel@tonic-gate 		fprintf(stderr, "rpc.updated not supported in NIS to LDAP "
81*7c478bd9Sstevel@tonic-gate 				"transition mode.");
82*7c478bd9Sstevel@tonic-gate 		exit(1);
83*7c478bd9Sstevel@tonic-gate 	}
84*7c478bd9Sstevel@tonic-gate 
85*7c478bd9Sstevel@tonic-gate 
86*7c478bd9Sstevel@tonic-gate 	cmd = argv[0];
87*7c478bd9Sstevel@tonic-gate 	switch (argc) {
88*7c478bd9Sstevel@tonic-gate 	case 0:
89*7c478bd9Sstevel@tonic-gate 		cmd = "ypupdated";
90*7c478bd9Sstevel@tonic-gate 		break;
91*7c478bd9Sstevel@tonic-gate 	case 1:
92*7c478bd9Sstevel@tonic-gate 		break;
93*7c478bd9Sstevel@tonic-gate 	case 2:
94*7c478bd9Sstevel@tonic-gate 		if (strcmp(argv[1], "-i") == 0) {
95*7c478bd9Sstevel@tonic-gate 			insecure++;
96*7c478bd9Sstevel@tonic-gate 			break;
97*7c478bd9Sstevel@tonic-gate 		} else if (strcmp(argv[1], "-s") == 0) {
98*7c478bd9Sstevel@tonic-gate 			insecure = 0;
99*7c478bd9Sstevel@tonic-gate 			break;
100*7c478bd9Sstevel@tonic-gate 		}
101*7c478bd9Sstevel@tonic-gate 	default:
102*7c478bd9Sstevel@tonic-gate 		fprintf(stderr, "%s: warning -- options ignored\n", cmd);
103*7c478bd9Sstevel@tonic-gate 		break;
104*7c478bd9Sstevel@tonic-gate 	}
105*7c478bd9Sstevel@tonic-gate 
106*7c478bd9Sstevel@tonic-gate 	if (chdir(YPDIR) < 0) {
107*7c478bd9Sstevel@tonic-gate 		fprintf(stderr, "%s: can't chdir to ", cmd);
108*7c478bd9Sstevel@tonic-gate 		perror(YPDIR);
109*7c478bd9Sstevel@tonic-gate 		exit(1);
110*7c478bd9Sstevel@tonic-gate 	}
111*7c478bd9Sstevel@tonic-gate 
112*7c478bd9Sstevel@tonic-gate 	/*
113*7c478bd9Sstevel@tonic-gate 	 * Set non-blocking mode and maximum record size for
114*7c478bd9Sstevel@tonic-gate 	 * connection oriented RPC transports.
115*7c478bd9Sstevel@tonic-gate 	 */
116*7c478bd9Sstevel@tonic-gate 	if (!rpc_control(RPC_SVC_CONNMAXREC_SET, &connmaxrec)) {
117*7c478bd9Sstevel@tonic-gate 		fprintf(stderr, "unable to set maximum RPC record size");
118*7c478bd9Sstevel@tonic-gate 	}
119*7c478bd9Sstevel@tonic-gate 
120*7c478bd9Sstevel@tonic-gate 	if (issock(RPC_INETDSOCK)) {
121*7c478bd9Sstevel@tonic-gate 		SVCXPRT *transp;
122*7c478bd9Sstevel@tonic-gate 		int proto = 0;
123*7c478bd9Sstevel@tonic-gate 		transp = svctcp_create(RPC_INETDSOCK, 0, 0);
124*7c478bd9Sstevel@tonic-gate 		if (transp == NULL) {
125*7c478bd9Sstevel@tonic-gate 			fprintf(stderr, "%s: cannot create tcp service\n", cmd);
126*7c478bd9Sstevel@tonic-gate 			exit(1);
127*7c478bd9Sstevel@tonic-gate 		}
128*7c478bd9Sstevel@tonic-gate 		if (!svc_register(transp, YPU_PROG, YPU_VERS, ypupdate_prog,
129*7c478bd9Sstevel@tonic-gate 				proto)) {
130*7c478bd9Sstevel@tonic-gate 			fprintf(stderr, "%s: couldn't register service\n", cmd);
131*7c478bd9Sstevel@tonic-gate 			exit(1);
132*7c478bd9Sstevel@tonic-gate 		}
133*7c478bd9Sstevel@tonic-gate 	} else {
134*7c478bd9Sstevel@tonic-gate 		detachfromtty();
135*7c478bd9Sstevel@tonic-gate 		(void) rpcb_unset(YPU_PROG, YPU_VERS, 0);
136*7c478bd9Sstevel@tonic-gate 		if (!svc_create(ypupdate_prog, YPU_PROG, YPU_VERS, "tcp")) {
137*7c478bd9Sstevel@tonic-gate 			fprintf(stderr, "%s: cannot create tcp service\n", cmd);
138*7c478bd9Sstevel@tonic-gate 			exit(1);
139*7c478bd9Sstevel@tonic-gate 		}
140*7c478bd9Sstevel@tonic-gate 	}
141*7c478bd9Sstevel@tonic-gate 
142*7c478bd9Sstevel@tonic-gate 	if (!svc_create(ypupdate_prog, YPU_PROG, YPU_VERS, "udp")) {
143*7c478bd9Sstevel@tonic-gate 		fprintf(stderr, "%s: cannot create udp service\n", cmd);
144*7c478bd9Sstevel@tonic-gate 		exit(1);
145*7c478bd9Sstevel@tonic-gate 	}
146*7c478bd9Sstevel@tonic-gate 
147*7c478bd9Sstevel@tonic-gate 	svc_run();
148*7c478bd9Sstevel@tonic-gate 	abort();
149*7c478bd9Sstevel@tonic-gate 	/* NOTREACHED */
150*7c478bd9Sstevel@tonic-gate }
151*7c478bd9Sstevel@tonic-gate 
152*7c478bd9Sstevel@tonic-gate /*
153*7c478bd9Sstevel@tonic-gate  * Determine if a descriptor belongs to a socket or not
154*7c478bd9Sstevel@tonic-gate  */
155*7c478bd9Sstevel@tonic-gate static int
156*7c478bd9Sstevel@tonic-gate issock(fd)
157*7c478bd9Sstevel@tonic-gate 	int fd;
158*7c478bd9Sstevel@tonic-gate {
159*7c478bd9Sstevel@tonic-gate 	struct stat st;
160*7c478bd9Sstevel@tonic-gate 
161*7c478bd9Sstevel@tonic-gate 	if (fstat(fd, &st) == -1)
162*7c478bd9Sstevel@tonic-gate 		return (0);
163*7c478bd9Sstevel@tonic-gate 	else
164*7c478bd9Sstevel@tonic-gate 		return (S_ISSOCK(fd));
165*7c478bd9Sstevel@tonic-gate }
166*7c478bd9Sstevel@tonic-gate 
167*7c478bd9Sstevel@tonic-gate 
168*7c478bd9Sstevel@tonic-gate void
169*7c478bd9Sstevel@tonic-gate detachfromtty()
170*7c478bd9Sstevel@tonic-gate {
171*7c478bd9Sstevel@tonic-gate 	int tt;
172*7c478bd9Sstevel@tonic-gate 
173*7c478bd9Sstevel@tonic-gate 	close(0);
174*7c478bd9Sstevel@tonic-gate 	close(1);
175*7c478bd9Sstevel@tonic-gate 	close(2);
176*7c478bd9Sstevel@tonic-gate 	switch (fork()) {
177*7c478bd9Sstevel@tonic-gate 	case -1:
178*7c478bd9Sstevel@tonic-gate 		perror("fork");
179*7c478bd9Sstevel@tonic-gate 		break;
180*7c478bd9Sstevel@tonic-gate 	case 0:
181*7c478bd9Sstevel@tonic-gate 		break;
182*7c478bd9Sstevel@tonic-gate 	default:
183*7c478bd9Sstevel@tonic-gate 		exit(0);
184*7c478bd9Sstevel@tonic-gate 	}
185*7c478bd9Sstevel@tonic-gate 	tt = open("/dev/tty", O_RDWR, 0);
186*7c478bd9Sstevel@tonic-gate 	if (tt >= 0) {
187*7c478bd9Sstevel@tonic-gate 		ioctl(tt, TIOCNOTTY, 0);
188*7c478bd9Sstevel@tonic-gate 		close(tt);
189*7c478bd9Sstevel@tonic-gate 	}
190*7c478bd9Sstevel@tonic-gate 	open("/dev/null", O_RDWR, 0);
191*7c478bd9Sstevel@tonic-gate 	dup(0);
192*7c478bd9Sstevel@tonic-gate 	dup(0);
193*7c478bd9Sstevel@tonic-gate }
194*7c478bd9Sstevel@tonic-gate 
195*7c478bd9Sstevel@tonic-gate void
196*7c478bd9Sstevel@tonic-gate ypupdate_prog(rqstp, transp)
197*7c478bd9Sstevel@tonic-gate 	struct svc_req *rqstp;
198*7c478bd9Sstevel@tonic-gate 	SVCXPRT *transp;
199*7c478bd9Sstevel@tonic-gate {
200*7c478bd9Sstevel@tonic-gate 	struct ypupdate_args args;
201*7c478bd9Sstevel@tonic-gate 	uint_t rslt;
202*7c478bd9Sstevel@tonic-gate 	uint_t op;
203*7c478bd9Sstevel@tonic-gate 	char *netname;
204*7c478bd9Sstevel@tonic-gate 	char namebuf[MAXNETNAMELEN+1];
205*7c478bd9Sstevel@tonic-gate 	struct authunix_parms *aup;
206*7c478bd9Sstevel@tonic-gate 
207*7c478bd9Sstevel@tonic-gate 	switch (rqstp->rq_proc) {
208*7c478bd9Sstevel@tonic-gate 	case NULLPROC:
209*7c478bd9Sstevel@tonic-gate 		svc_sendreply(transp, xdr_void, NULL);
210*7c478bd9Sstevel@tonic-gate 		return;
211*7c478bd9Sstevel@tonic-gate 	case YPU_CHANGE:
212*7c478bd9Sstevel@tonic-gate 		op = YPOP_CHANGE;
213*7c478bd9Sstevel@tonic-gate 		break;
214*7c478bd9Sstevel@tonic-gate 	case YPU_DELETE:
215*7c478bd9Sstevel@tonic-gate 		op = YPOP_DELETE;
216*7c478bd9Sstevel@tonic-gate 		break;
217*7c478bd9Sstevel@tonic-gate 	case YPU_INSERT:
218*7c478bd9Sstevel@tonic-gate 		op = YPOP_INSERT;
219*7c478bd9Sstevel@tonic-gate 		break;
220*7c478bd9Sstevel@tonic-gate 	case YPU_STORE:
221*7c478bd9Sstevel@tonic-gate 		op = YPOP_STORE;
222*7c478bd9Sstevel@tonic-gate 		break;
223*7c478bd9Sstevel@tonic-gate 	default:
224*7c478bd9Sstevel@tonic-gate 		svcerr_noproc(transp);
225*7c478bd9Sstevel@tonic-gate 		return;
226*7c478bd9Sstevel@tonic-gate 	}
227*7c478bd9Sstevel@tonic-gate 	switch (rqstp->rq_cred.oa_flavor) {
228*7c478bd9Sstevel@tonic-gate 	case AUTH_DES:
229*7c478bd9Sstevel@tonic-gate 		netname = ((struct authdes_cred *)
230*7c478bd9Sstevel@tonic-gate 			rqstp->rq_clntcred)->adc_fullname.name;
231*7c478bd9Sstevel@tonic-gate 		break;
232*7c478bd9Sstevel@tonic-gate 	case AUTH_UNIX:
233*7c478bd9Sstevel@tonic-gate 		if (insecure) {
234*7c478bd9Sstevel@tonic-gate 			aup = (struct authunix_parms *)rqstp->rq_clntcred;
235*7c478bd9Sstevel@tonic-gate 			if (aup->aup_uid == 0) {
236*7c478bd9Sstevel@tonic-gate 			/*
237*7c478bd9Sstevel@tonic-gate 			 *	addr2netname(namebuf, svc_getcaller(transp));
238*7c478bd9Sstevel@tonic-gate 			 */
239*7c478bd9Sstevel@tonic-gate 				addr2netname(namebuf, transp);
240*7c478bd9Sstevel@tonic-gate 			} else {
241*7c478bd9Sstevel@tonic-gate 				user2netname(namebuf, aup->aup_uid, NULL);
242*7c478bd9Sstevel@tonic-gate 			}
243*7c478bd9Sstevel@tonic-gate 			netname = namebuf;
244*7c478bd9Sstevel@tonic-gate 			break;
245*7c478bd9Sstevel@tonic-gate 		}
246*7c478bd9Sstevel@tonic-gate 	default:
247*7c478bd9Sstevel@tonic-gate 		svcerr_weakauth(transp);
248*7c478bd9Sstevel@tonic-gate 		return;
249*7c478bd9Sstevel@tonic-gate 	}
250*7c478bd9Sstevel@tonic-gate 	bzero(&args, sizeof (args));
251*7c478bd9Sstevel@tonic-gate 	if (!svc_getargs(transp, xdr_ypupdate_args, (caddr_t)&args)) {
252*7c478bd9Sstevel@tonic-gate 		svcerr_decode(transp);
253*7c478bd9Sstevel@tonic-gate 		return;
254*7c478bd9Sstevel@tonic-gate 	}
255*7c478bd9Sstevel@tonic-gate 	rslt = update(netname,
256*7c478bd9Sstevel@tonic-gate 		args.mapname, op, args.key.yp_buf_len, args.key.yp_buf_val,
257*7c478bd9Sstevel@tonic-gate 		args.datum.yp_buf_len, args.datum.yp_buf_val);
258*7c478bd9Sstevel@tonic-gate 	if (!svc_sendreply(transp, xdr_u_int, (const caddr_t)&rslt)) {
259*7c478bd9Sstevel@tonic-gate 		debug("svc_sendreply failed");
260*7c478bd9Sstevel@tonic-gate 	}
261*7c478bd9Sstevel@tonic-gate 	if (!svc_freeargs(transp, xdr_ypupdate_args, (caddr_t)&args)) {
262*7c478bd9Sstevel@tonic-gate 		debug("svc_freeargs failed");
263*7c478bd9Sstevel@tonic-gate 	}
264*7c478bd9Sstevel@tonic-gate }
265*7c478bd9Sstevel@tonic-gate 
266*7c478bd9Sstevel@tonic-gate /*
267*7c478bd9Sstevel@tonic-gate  * Determine if requester is allowed to update the given map,
268*7c478bd9Sstevel@tonic-gate  * and update it if so. Returns the NIS status, which is zero
269*7c478bd9Sstevel@tonic-gate  * if there is no access violation.
270*7c478bd9Sstevel@tonic-gate  */
271*7c478bd9Sstevel@tonic-gate update(requester, mapname, op, keylen, key, datalen, data)
272*7c478bd9Sstevel@tonic-gate 	char *requester;
273*7c478bd9Sstevel@tonic-gate 	char *mapname;
274*7c478bd9Sstevel@tonic-gate 	uint_t op;
275*7c478bd9Sstevel@tonic-gate 	uint_t keylen;
276*7c478bd9Sstevel@tonic-gate 	char *key;
277*7c478bd9Sstevel@tonic-gate 	uint_t datalen;
278*7c478bd9Sstevel@tonic-gate 	char *data;
279*7c478bd9Sstevel@tonic-gate {
280*7c478bd9Sstevel@tonic-gate 	char updater[MAXMAPNAMELEN + 40];
281*7c478bd9Sstevel@tonic-gate 	FILE *childargs;
282*7c478bd9Sstevel@tonic-gate 	FILE *childrslt;
283*7c478bd9Sstevel@tonic-gate 	int status;
284*7c478bd9Sstevel@tonic-gate 	int yperrno;
285*7c478bd9Sstevel@tonic-gate 	int pid;
286*7c478bd9Sstevel@tonic-gate 	char default_domain[YPMAXDOMAIN];
287*7c478bd9Sstevel@tonic-gate 	int err;
288*7c478bd9Sstevel@tonic-gate 	char fake_key[10];
289*7c478bd9Sstevel@tonic-gate 	char *outval = NULL;
290*7c478bd9Sstevel@tonic-gate 	int outval_len;
291*7c478bd9Sstevel@tonic-gate 
292*7c478bd9Sstevel@tonic-gate 	if (getdomainname(default_domain, YPMAXDOMAIN)) {
293*7c478bd9Sstevel@tonic-gate 		debug("Couldn't get default domain name");
294*7c478bd9Sstevel@tonic-gate 		return (YPERR_YPERR);
295*7c478bd9Sstevel@tonic-gate 	}
296*7c478bd9Sstevel@tonic-gate 
297*7c478bd9Sstevel@tonic-gate 	/* check to see if we have a valid mapname */
298*7c478bd9Sstevel@tonic-gate 	strncpy(fake_key, "junk", 4);
299*7c478bd9Sstevel@tonic-gate 	err = yp_match(default_domain, mapname,
300*7c478bd9Sstevel@tonic-gate 			fake_key, strlen(fake_key), &outval, &outval_len);
301*7c478bd9Sstevel@tonic-gate 	switch (err) {
302*7c478bd9Sstevel@tonic-gate 		case YPERR_MAP:
303*7c478bd9Sstevel@tonic-gate 			return (YPERR_YPERR);
304*7c478bd9Sstevel@tonic-gate 			break;
305*7c478bd9Sstevel@tonic-gate 		default:
306*7c478bd9Sstevel@tonic-gate 			/* do nothing, only worry about above return code */
307*7c478bd9Sstevel@tonic-gate 			break;
308*7c478bd9Sstevel@tonic-gate 	}
309*7c478bd9Sstevel@tonic-gate 
310*7c478bd9Sstevel@tonic-gate 	/* valid map - continue */
311*7c478bd9Sstevel@tonic-gate 	sprintf(updater, "make -s -f %s %s", UPDATEFILE, mapname);
312*7c478bd9Sstevel@tonic-gate 	pid = _openchild(updater, &childargs, &childrslt);
313*7c478bd9Sstevel@tonic-gate 	if (pid < 0) {
314*7c478bd9Sstevel@tonic-gate 		debug("openpipes failed");
315*7c478bd9Sstevel@tonic-gate 		return (YPERR_YPERR);
316*7c478bd9Sstevel@tonic-gate 	}
317*7c478bd9Sstevel@tonic-gate 
318*7c478bd9Sstevel@tonic-gate 	/*
319*7c478bd9Sstevel@tonic-gate 	 * Write to child
320*7c478bd9Sstevel@tonic-gate 	 */
321*7c478bd9Sstevel@tonic-gate 	fprintf(childargs, "%s\n", requester);
322*7c478bd9Sstevel@tonic-gate 	fprintf(childargs, "%u\n", op);
323*7c478bd9Sstevel@tonic-gate 	fprintf(childargs, "%u\n", keylen);
324*7c478bd9Sstevel@tonic-gate 	fwrite(key, keylen, 1, childargs);
325*7c478bd9Sstevel@tonic-gate 	fprintf(childargs, "\n");
326*7c478bd9Sstevel@tonic-gate 	fprintf(childargs, "%u\n", datalen);
327*7c478bd9Sstevel@tonic-gate 	fwrite(data, datalen, 1, childargs);
328*7c478bd9Sstevel@tonic-gate 	fprintf(childargs, "\n");
329*7c478bd9Sstevel@tonic-gate 	fclose(childargs);
330*7c478bd9Sstevel@tonic-gate 
331*7c478bd9Sstevel@tonic-gate 	/*
332*7c478bd9Sstevel@tonic-gate 	 * Read from child
333*7c478bd9Sstevel@tonic-gate 	 */
334*7c478bd9Sstevel@tonic-gate 	fscanf(childrslt, "%d", &yperrno);
335*7c478bd9Sstevel@tonic-gate 	fclose(childrslt);
336*7c478bd9Sstevel@tonic-gate 
337*7c478bd9Sstevel@tonic-gate 	wait(&status);
338*7c478bd9Sstevel@tonic-gate 	if (!WIFEXITED(status)) {
339*7c478bd9Sstevel@tonic-gate 		return (YPERR_YPERR);
340*7c478bd9Sstevel@tonic-gate 	}
341*7c478bd9Sstevel@tonic-gate 	return (yperrno);
342*7c478bd9Sstevel@tonic-gate }
343*7c478bd9Sstevel@tonic-gate 
344*7c478bd9Sstevel@tonic-gate #if 0
345*7c478bd9Sstevel@tonic-gate addr2netname(namebuf, addr)
346*7c478bd9Sstevel@tonic-gate 	char *namebuf;
347*7c478bd9Sstevel@tonic-gate 	struct sockaddr_in *addr;
348*7c478bd9Sstevel@tonic-gate {
349*7c478bd9Sstevel@tonic-gate 	struct hostent *h;
350*7c478bd9Sstevel@tonic-gate 
351*7c478bd9Sstevel@tonic-gate 	h = gethostbyaddr((const char *) &addr->sin_addr,
352*7c478bd9Sstevel@tonic-gate 				sizeof (addr->sin_addr), AF_INET);
353*7c478bd9Sstevel@tonic-gate 	if (h == NULL) {
354*7c478bd9Sstevel@tonic-gate 		host2netname(namebuf, (const char *) inet_ntoa(addr->sin_addr),
355*7c478bd9Sstevel@tonic-gate 				NULL);
356*7c478bd9Sstevel@tonic-gate 	} else {
357*7c478bd9Sstevel@tonic-gate 		host2netname(namebuf, h->h_name, NULL);
358*7c478bd9Sstevel@tonic-gate 	}
359*7c478bd9Sstevel@tonic-gate }
360*7c478bd9Sstevel@tonic-gate #endif
361*7c478bd9Sstevel@tonic-gate 
362*7c478bd9Sstevel@tonic-gate 
363*7c478bd9Sstevel@tonic-gate static int
364*7c478bd9Sstevel@tonic-gate addr2netname(namebuf, transp)
365*7c478bd9Sstevel@tonic-gate 	char *namebuf;
366*7c478bd9Sstevel@tonic-gate 	SVCXPRT *transp;
367*7c478bd9Sstevel@tonic-gate {
368*7c478bd9Sstevel@tonic-gate 	struct nd_hostservlist *hostservs = NULL;
369*7c478bd9Sstevel@tonic-gate 	struct netconfig *nconf;
370*7c478bd9Sstevel@tonic-gate 	struct netbuf *who;
371*7c478bd9Sstevel@tonic-gate 
372*7c478bd9Sstevel@tonic-gate 	who = svc_getrpccaller(transp);
373*7c478bd9Sstevel@tonic-gate 	if ((who == NULL) || (who->len == 0))
374*7c478bd9Sstevel@tonic-gate 		return (-1);
375*7c478bd9Sstevel@tonic-gate 	if ((nconf = getnetconfigent(transp->xp_netid))
376*7c478bd9Sstevel@tonic-gate 		== (struct netconfig *)NULL)
377*7c478bd9Sstevel@tonic-gate 		return (-1);
378*7c478bd9Sstevel@tonic-gate 	if (netdir_getbyaddr(nconf, &hostservs, who) != 0) {
379*7c478bd9Sstevel@tonic-gate 		(void) freenetconfigent(nconf);
380*7c478bd9Sstevel@tonic-gate 		return (-1);
381*7c478bd9Sstevel@tonic-gate 	}
382*7c478bd9Sstevel@tonic-gate 	if (hostservs != NULL)
383*7c478bd9Sstevel@tonic-gate 		strcpy(namebuf, hostservs->h_hostservs->h_host);
384*7c478bd9Sstevel@tonic-gate 
385*7c478bd9Sstevel@tonic-gate 	(void) freenetconfigent(nconf);
386*7c478bd9Sstevel@tonic-gate 	netdir_free((char *)hostservs, ND_HOSTSERVLIST);
387*7c478bd9Sstevel@tonic-gate 	return (0);
388*7c478bd9Sstevel@tonic-gate }
389