xref: /titanic_51/usr/src/cmd/ypcmd/ypupdated.c (revision 4b3b7fc6e1f62f5e2bee41aafc52e9234c484bc0)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*
23*4b3b7fc6SAlex Wilson  * Copyright 2017 Joyent Inc
247c478bd9Sstevel@tonic-gate  * Copyright 2000 Sun Microsystems, Inc.  All rights reserved.
257c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
267c478bd9Sstevel@tonic-gate  */
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate /*	Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T	*/
297c478bd9Sstevel@tonic-gate /*	  All Rights Reserved	*/
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate /*
327c478bd9Sstevel@tonic-gate  * Portions of this source code were derived from Berkeley 4.3 BSD
337c478bd9Sstevel@tonic-gate  * under license from the Regents of the University of California.
347c478bd9Sstevel@tonic-gate  */
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate /*
377c478bd9Sstevel@tonic-gate  * YP update service
387c478bd9Sstevel@tonic-gate  */
397c478bd9Sstevel@tonic-gate #include <stdio.h>
407c478bd9Sstevel@tonic-gate #include <stdlib.h>
417c478bd9Sstevel@tonic-gate #include <sys/types.h>
427c478bd9Sstevel@tonic-gate #include <sys/file.h>
437c478bd9Sstevel@tonic-gate #include <sys/signal.h>
447c478bd9Sstevel@tonic-gate #include <sys/wait.h>
457c478bd9Sstevel@tonic-gate #include <rpc/rpc.h>
467c478bd9Sstevel@tonic-gate #include <rpc/nettype.h>
477c478bd9Sstevel@tonic-gate #include <rpcsvc/ypupd.h>
487c478bd9Sstevel@tonic-gate #include <rpcsvc/ypclnt.h>
49*4b3b7fc6SAlex Wilson #include <sys/debug.h>
507c478bd9Sstevel@tonic-gate #include <netdir.h>
517c478bd9Sstevel@tonic-gate #include <stropts.h>
527c478bd9Sstevel@tonic-gate #ifdef SYSLOG
537c478bd9Sstevel@tonic-gate #include <syslog.h>
547c478bd9Sstevel@tonic-gate #else
557c478bd9Sstevel@tonic-gate #define	LOG_ERR 1
567c478bd9Sstevel@tonic-gate #define	openlog(a, b, c)
577c478bd9Sstevel@tonic-gate #endif
587c478bd9Sstevel@tonic-gate 
597c478bd9Sstevel@tonic-gate #ifdef DEBUG
607c478bd9Sstevel@tonic-gate #define	RPC_SVC_FG
617c478bd9Sstevel@tonic-gate #define	debug(msg)	fprintf(stderr, "%s\n", msg);
627c478bd9Sstevel@tonic-gate #else
637c478bd9Sstevel@tonic-gate #define	debug(msg)	/* turn off debugging */
647c478bd9Sstevel@tonic-gate #endif
657c478bd9Sstevel@tonic-gate 
667c478bd9Sstevel@tonic-gate static char YPDIR[] = "/var/yp";
677c478bd9Sstevel@tonic-gate static char UPDATEFILE[] = "/var/yp/updaters";
687c478bd9Sstevel@tonic-gate #define	_RPCSVC_CLOSEDOWN 120
697c478bd9Sstevel@tonic-gate 
707c478bd9Sstevel@tonic-gate static int addr2netname();
717c478bd9Sstevel@tonic-gate static void closedown();
727c478bd9Sstevel@tonic-gate static void ypupdate_prog();
737c478bd9Sstevel@tonic-gate static void msgout();
747c478bd9Sstevel@tonic-gate static int update();
757c478bd9Sstevel@tonic-gate static int insecure;
767c478bd9Sstevel@tonic-gate static int _rpcpmstart;		/* Started by a port monitor ? */
777c478bd9Sstevel@tonic-gate static int _rpcsvcdirty;	/* Still serving ? */
787c478bd9Sstevel@tonic-gate 
797c478bd9Sstevel@tonic-gate extern unsigned int alarm();
807c478bd9Sstevel@tonic-gate extern void exit();
817c478bd9Sstevel@tonic-gate extern int close();
827c478bd9Sstevel@tonic-gate extern long fork();
837c478bd9Sstevel@tonic-gate extern int free();
847c478bd9Sstevel@tonic-gate extern struct netconfig *getnetconfigent();
857c478bd9Sstevel@tonic-gate extern int strcmp();
867c478bd9Sstevel@tonic-gate extern int strcpy();
877c478bd9Sstevel@tonic-gate extern int syslog();
887c478bd9Sstevel@tonic-gate extern void *signal();
897c478bd9Sstevel@tonic-gate extern int setsid();
907c478bd9Sstevel@tonic-gate extern int t_getinfo();
917c478bd9Sstevel@tonic-gate extern int user2netname();
927c478bd9Sstevel@tonic-gate extern int _openchild();
937c478bd9Sstevel@tonic-gate 
947c478bd9Sstevel@tonic-gate main(argc, argv)
957c478bd9Sstevel@tonic-gate 	int argc;
967c478bd9Sstevel@tonic-gate 	char *argv[];
977c478bd9Sstevel@tonic-gate {
987c478bd9Sstevel@tonic-gate 	pid_t	pid;
997c478bd9Sstevel@tonic-gate 	char *cmd;
1007c478bd9Sstevel@tonic-gate 	char mname[FMNAMESZ + 1];
1017c478bd9Sstevel@tonic-gate 
1027c478bd9Sstevel@tonic-gate 	if (geteuid() != 0) {
1037c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr, "must be root to run %s\n", argv[0]);
1047c478bd9Sstevel@tonic-gate 		exit(1);
1057c478bd9Sstevel@tonic-gate 	}
1067c478bd9Sstevel@tonic-gate 
1077c478bd9Sstevel@tonic-gate 	cmd = argv[0];
1087c478bd9Sstevel@tonic-gate 	switch (argc) {
1097c478bd9Sstevel@tonic-gate 	case 0:
1107c478bd9Sstevel@tonic-gate 		cmd = "ypupdated";
1117c478bd9Sstevel@tonic-gate 		break;
1127c478bd9Sstevel@tonic-gate 	case 1:
1137c478bd9Sstevel@tonic-gate 		break;
1147c478bd9Sstevel@tonic-gate 	case 2:
1157c478bd9Sstevel@tonic-gate 		if (strcmp(argv[1], "-i") == 0) {
1167c478bd9Sstevel@tonic-gate 			insecure++;
1177c478bd9Sstevel@tonic-gate 			break;
1187c478bd9Sstevel@tonic-gate 		}
1197c478bd9Sstevel@tonic-gate 	default:
1207c478bd9Sstevel@tonic-gate 		fprintf(stderr, "%s: warning -- options ignored\n", cmd);
1217c478bd9Sstevel@tonic-gate 		break;
1227c478bd9Sstevel@tonic-gate 	}
1237c478bd9Sstevel@tonic-gate 
1247c478bd9Sstevel@tonic-gate 	if (chdir(YPDIR) < 0) {
1257c478bd9Sstevel@tonic-gate 		fprintf(stderr, "%s: can't chdir to ", cmd);
1267c478bd9Sstevel@tonic-gate 		perror(YPDIR);
1277c478bd9Sstevel@tonic-gate 		exit(1);
1287c478bd9Sstevel@tonic-gate 	}
1297c478bd9Sstevel@tonic-gate 
1307c478bd9Sstevel@tonic-gate 	if (!ioctl(0, I_LOOK, mname) &&
1317c478bd9Sstevel@tonic-gate 		(strcmp(mname, "sockmod") == 0 ||
1327c478bd9Sstevel@tonic-gate 				strcmp(mname, "timod") == 0)) {
1337c478bd9Sstevel@tonic-gate 		/*
1347c478bd9Sstevel@tonic-gate 		 * Started from port monitor: use 0 as fd
1357c478bd9Sstevel@tonic-gate 		 */
1367c478bd9Sstevel@tonic-gate 		char *netid;
1377c478bd9Sstevel@tonic-gate 		struct netconfig *nconf = NULL;
1387c478bd9Sstevel@tonic-gate 		SVCXPRT *transp;
1397c478bd9Sstevel@tonic-gate 		int pmclose;
1407c478bd9Sstevel@tonic-gate 		extern char *getenv();
1417c478bd9Sstevel@tonic-gate 
1427c478bd9Sstevel@tonic-gate 		_rpcpmstart = 1;
1437c478bd9Sstevel@tonic-gate 		if ((netid = getenv("NLSPROVIDER")) == NULL) {
1447c478bd9Sstevel@tonic-gate 			msgout("cannot get transport name");
1457c478bd9Sstevel@tonic-gate 		}
1467c478bd9Sstevel@tonic-gate 		if ((nconf = getnetconfigent(netid)) == NULL) {
1477c478bd9Sstevel@tonic-gate 			msgout("cannot get transport info");
1487c478bd9Sstevel@tonic-gate 		}
1497c478bd9Sstevel@tonic-gate 		if (strcmp(mname, "sockmod") == 0) {
1507c478bd9Sstevel@tonic-gate 			if (ioctl(0, I_POP, 0) || ioctl(0, I_PUSH, "timod")) {
1517c478bd9Sstevel@tonic-gate 				msgout("could not get the right module");
1527c478bd9Sstevel@tonic-gate 				exit(1);
1537c478bd9Sstevel@tonic-gate 			}
1547c478bd9Sstevel@tonic-gate 		}
1557c478bd9Sstevel@tonic-gate 		pmclose = (t_getstate(0) != T_DATAXFER);
1567c478bd9Sstevel@tonic-gate 		if ((transp = svc_tli_create(0, nconf, NULL, 0, 0)) == NULL) {
1577c478bd9Sstevel@tonic-gate 			msgout("cannot create update server handle");
1587c478bd9Sstevel@tonic-gate 			exit(1);
1597c478bd9Sstevel@tonic-gate 		}
1607c478bd9Sstevel@tonic-gate 		if (!svc_reg(transp, YPU_PROG, YPU_VERS, ypupdate_prog, 0)) {
1617c478bd9Sstevel@tonic-gate 			msgout("unable to register (YPBINDPROG, YPBINDVERS).");
1627c478bd9Sstevel@tonic-gate 			exit(1);
1637c478bd9Sstevel@tonic-gate 		}
1647c478bd9Sstevel@tonic-gate 		if (nconf)
1657c478bd9Sstevel@tonic-gate 			freenetconfigent(nconf);
1667c478bd9Sstevel@tonic-gate 
1677c478bd9Sstevel@tonic-gate 		if (pmclose) {
1687c478bd9Sstevel@tonic-gate 			(void) signal(SIGALRM, closedown);
1697c478bd9Sstevel@tonic-gate 			(void) alarm(_RPCSVC_CLOSEDOWN);
1707c478bd9Sstevel@tonic-gate 		}
1717c478bd9Sstevel@tonic-gate 		svc_run();
1727c478bd9Sstevel@tonic-gate 		exit(1);
1737c478bd9Sstevel@tonic-gate 	}
1747c478bd9Sstevel@tonic-gate #ifndef RPC_SVC_FG
1757c478bd9Sstevel@tonic-gate 	/*
1767c478bd9Sstevel@tonic-gate 	 * Started from shell; background thyself and run
1777c478bd9Sstevel@tonic-gate 	 */
1787c478bd9Sstevel@tonic-gate 	pid = fork();
1797c478bd9Sstevel@tonic-gate 
1807c478bd9Sstevel@tonic-gate 	if (pid < 0) {
1817c478bd9Sstevel@tonic-gate 		perror("cannot fork");
1827c478bd9Sstevel@tonic-gate 		exit(1);
1837c478bd9Sstevel@tonic-gate 	}
1847c478bd9Sstevel@tonic-gate 	if (pid)
1857c478bd9Sstevel@tonic-gate 		exit(0);
1867c478bd9Sstevel@tonic-gate 	closefrom(0);
1877c478bd9Sstevel@tonic-gate 	(void) setsid();
1887c478bd9Sstevel@tonic-gate 	openlog("ypupdated", LOG_PID, LOG_DAEMON);
1897c478bd9Sstevel@tonic-gate #endif
1907c478bd9Sstevel@tonic-gate 	if (!svc_create(ypupdate_prog, YPU_PROG, YPU_VERS, "netpath")) {
1917c478bd9Sstevel@tonic-gate 		msgout("unable to create (YPU_PROG, YPU_VERS) for netpath.");
1927c478bd9Sstevel@tonic-gate 		exit(1);
1937c478bd9Sstevel@tonic-gate 	}
1947c478bd9Sstevel@tonic-gate 
1957c478bd9Sstevel@tonic-gate 	svc_run();
1967c478bd9Sstevel@tonic-gate 	msgout("svc_run returned");
1977c478bd9Sstevel@tonic-gate 	exit(1);
1987c478bd9Sstevel@tonic-gate 	/* NOTREACHED */
1997c478bd9Sstevel@tonic-gate }
2007c478bd9Sstevel@tonic-gate 
2017c478bd9Sstevel@tonic-gate static void
2027c478bd9Sstevel@tonic-gate ypupdate_prog(rqstp, transp)
2037c478bd9Sstevel@tonic-gate 	struct svc_req *rqstp;
2047c478bd9Sstevel@tonic-gate 	SVCXPRT *transp;
2057c478bd9Sstevel@tonic-gate {
2067c478bd9Sstevel@tonic-gate 	struct ypupdate_args args;
2077c478bd9Sstevel@tonic-gate 	uint_t rslt;
2087c478bd9Sstevel@tonic-gate 	uint_t op;
2097c478bd9Sstevel@tonic-gate 	char *netname;
2107c478bd9Sstevel@tonic-gate 	char namebuf[MAXNETNAMELEN+1];
2117c478bd9Sstevel@tonic-gate 	struct authunix_parms *aup;
2127c478bd9Sstevel@tonic-gate 
2137c478bd9Sstevel@tonic-gate 	switch (rqstp->rq_proc) {
2147c478bd9Sstevel@tonic-gate 	case NULLPROC:
2157c478bd9Sstevel@tonic-gate 		svc_sendreply(transp, xdr_void, NULL);
2167c478bd9Sstevel@tonic-gate 		return;
2177c478bd9Sstevel@tonic-gate 	case YPU_CHANGE:
2187c478bd9Sstevel@tonic-gate 		op = YPOP_CHANGE;
2197c478bd9Sstevel@tonic-gate 		break;
2207c478bd9Sstevel@tonic-gate 	case YPU_DELETE:
2217c478bd9Sstevel@tonic-gate 		op = YPOP_DELETE;
2227c478bd9Sstevel@tonic-gate 		break;
2237c478bd9Sstevel@tonic-gate 	case YPU_INSERT:
2247c478bd9Sstevel@tonic-gate 		op = YPOP_INSERT;
2257c478bd9Sstevel@tonic-gate 		break;
2267c478bd9Sstevel@tonic-gate 	case YPU_STORE:
2277c478bd9Sstevel@tonic-gate 		op = YPOP_STORE;
2287c478bd9Sstevel@tonic-gate 		break;
2297c478bd9Sstevel@tonic-gate 	default:
2307c478bd9Sstevel@tonic-gate 		svcerr_noproc(transp);
2317c478bd9Sstevel@tonic-gate 		return;
2327c478bd9Sstevel@tonic-gate 	}
2337c478bd9Sstevel@tonic-gate #ifdef DEBUG
2347c478bd9Sstevel@tonic-gate 	fprintf(stderr, "ypupdated: request received\n");
2357c478bd9Sstevel@tonic-gate #endif
2367c478bd9Sstevel@tonic-gate 	switch (rqstp->rq_cred.oa_flavor) {
2377c478bd9Sstevel@tonic-gate 	case AUTH_DES:
238*4b3b7fc6SAlex Wilson 		CTASSERT(sizeof (struct authdes_cred) <= RQCRED_SIZE);
2397c478bd9Sstevel@tonic-gate 		netname = ((struct authdes_cred *)
2407c478bd9Sstevel@tonic-gate 			rqstp->rq_clntcred)->adc_fullname.name;
2417c478bd9Sstevel@tonic-gate 		break;
2427c478bd9Sstevel@tonic-gate 	case AUTH_UNIX:
2437c478bd9Sstevel@tonic-gate 		if (insecure) {
244*4b3b7fc6SAlex Wilson 			CTASSERT(sizeof (struct authunix_parms) <= RQCRED_SIZE);
2457c478bd9Sstevel@tonic-gate 			aup = (struct authunix_parms *)rqstp->rq_clntcred;
2467c478bd9Sstevel@tonic-gate 			if (aup->aup_uid == 0) {
2477c478bd9Sstevel@tonic-gate 				if (addr2netname(namebuf, transp) != 0) {
2487c478bd9Sstevel@tonic-gate 					fprintf(stderr,
2497c478bd9Sstevel@tonic-gate 						"addr2netname failing for %d\n",
2507c478bd9Sstevel@tonic-gate 						aup->aup_uid);
2517c478bd9Sstevel@tonic-gate 					svcerr_systemerr(transp);
2527c478bd9Sstevel@tonic-gate 					return;
2537c478bd9Sstevel@tonic-gate 				}
2547c478bd9Sstevel@tonic-gate 			} else {
2557c478bd9Sstevel@tonic-gate 				if (user2netname(namebuf, aup->aup_uid, NULL)
2567c478bd9Sstevel@tonic-gate 				    != 0) {
2577c478bd9Sstevel@tonic-gate 					fprintf(stderr,
2587c478bd9Sstevel@tonic-gate 						"user2netname failing for %d\n",
2597c478bd9Sstevel@tonic-gate 						aup->aup_uid);
2607c478bd9Sstevel@tonic-gate 					svcerr_systemerr(transp);
2617c478bd9Sstevel@tonic-gate 					return;
2627c478bd9Sstevel@tonic-gate 				}
2637c478bd9Sstevel@tonic-gate 			}
2647c478bd9Sstevel@tonic-gate 			netname = namebuf;
2657c478bd9Sstevel@tonic-gate 			break;
2667c478bd9Sstevel@tonic-gate 		}
2677c478bd9Sstevel@tonic-gate 	default:
2687c478bd9Sstevel@tonic-gate 		svcerr_weakauth(transp);
2697c478bd9Sstevel@tonic-gate 		return;
2707c478bd9Sstevel@tonic-gate 	}
2717c478bd9Sstevel@tonic-gate 	memset(&args, 0, sizeof (args));
2727c478bd9Sstevel@tonic-gate 	if (!svc_getargs(transp, xdr_ypupdate_args, (char *)&args)) {
2737c478bd9Sstevel@tonic-gate 		svcerr_decode(transp);
2747c478bd9Sstevel@tonic-gate 		return;
2757c478bd9Sstevel@tonic-gate 	}
2767c478bd9Sstevel@tonic-gate #ifdef DEBUG
2777c478bd9Sstevel@tonic-gate 	fprintf(stderr, "netname = %s\n, map=%s\n key=%s\n",
2787c478bd9Sstevel@tonic-gate 		netname, args.mapname, args.key.yp_buf_val);
2797c478bd9Sstevel@tonic-gate #endif
2807c478bd9Sstevel@tonic-gate 	rslt = update(netname, args.mapname, op,
2817c478bd9Sstevel@tonic-gate 		args.key.yp_buf_len, args.key.yp_buf_val,
2827c478bd9Sstevel@tonic-gate 		args.datum.yp_buf_len, args.datum.yp_buf_val);
2837c478bd9Sstevel@tonic-gate 	if (!svc_sendreply(transp, xdr_u_int, (char *)&rslt)) {
2847c478bd9Sstevel@tonic-gate 		debug("svc_sendreply failed");
2857c478bd9Sstevel@tonic-gate 	}
2867c478bd9Sstevel@tonic-gate 	if (!svc_freeargs(transp, xdr_ypupdate_args, (char *)&args)) {
2877c478bd9Sstevel@tonic-gate 		debug("svc_freeargs failed");
2887c478bd9Sstevel@tonic-gate 	}
2897c478bd9Sstevel@tonic-gate }
2907c478bd9Sstevel@tonic-gate 
2917c478bd9Sstevel@tonic-gate /*
2927c478bd9Sstevel@tonic-gate  * Determine if requester is allowed to update the given map,
2937c478bd9Sstevel@tonic-gate  * and update it if so. Returns the yp status, which is zero
2947c478bd9Sstevel@tonic-gate  * if there is no access violation.
2957c478bd9Sstevel@tonic-gate  */
2967c478bd9Sstevel@tonic-gate static
2977c478bd9Sstevel@tonic-gate update(requester, mapname, op, keylen, key, datalen, data)
2987c478bd9Sstevel@tonic-gate 	char *requester;
2997c478bd9Sstevel@tonic-gate 	char *mapname;
3007c478bd9Sstevel@tonic-gate 	uint_t op;
3017c478bd9Sstevel@tonic-gate 	uint_t keylen;
3027c478bd9Sstevel@tonic-gate 	char *key;
3037c478bd9Sstevel@tonic-gate 	uint_t datalen;
3047c478bd9Sstevel@tonic-gate 	char *data;
3057c478bd9Sstevel@tonic-gate {
3067c478bd9Sstevel@tonic-gate 	char updater[MAXMAPNAMELEN + 40];
3077c478bd9Sstevel@tonic-gate 	FILE *childargs;
3087c478bd9Sstevel@tonic-gate 	FILE *childrslt;
3097c478bd9Sstevel@tonic-gate 	int status;
3107c478bd9Sstevel@tonic-gate 	int yperrno = 0;
3117c478bd9Sstevel@tonic-gate 	int pid;
3127c478bd9Sstevel@tonic-gate 
3137c478bd9Sstevel@tonic-gate 	sprintf(updater, "/usr/ccs/bin/make -s -f %s %s", UPDATEFILE, mapname);
3147c478bd9Sstevel@tonic-gate #ifdef DEBUG
3157c478bd9Sstevel@tonic-gate 	fprintf(stderr, "updater: %s\n", updater);
3167c478bd9Sstevel@tonic-gate 	fprintf(stderr, "requestor = %s, op = %d, key = %s\n",
3177c478bd9Sstevel@tonic-gate 		requester, op, key);
3187c478bd9Sstevel@tonic-gate 	fprintf(stderr, "data = %s\n", data);
3197c478bd9Sstevel@tonic-gate #endif
3207c478bd9Sstevel@tonic-gate 	pid = _openchild(updater, &childargs, &childrslt);
3217c478bd9Sstevel@tonic-gate 	if (pid < 0) {
3227c478bd9Sstevel@tonic-gate 		debug("openpipes failed");
3237c478bd9Sstevel@tonic-gate 		return (YPERR_YPERR);
3247c478bd9Sstevel@tonic-gate 	}
3257c478bd9Sstevel@tonic-gate 
3267c478bd9Sstevel@tonic-gate 	/*
3277c478bd9Sstevel@tonic-gate 	 * Write to child
3287c478bd9Sstevel@tonic-gate 	 */
3297c478bd9Sstevel@tonic-gate 	fprintf(childargs, "%s\n", requester);
3307c478bd9Sstevel@tonic-gate 	fprintf(childargs, "%u\n", op);
3317c478bd9Sstevel@tonic-gate 	fprintf(childargs, "%u\n", keylen);
3327c478bd9Sstevel@tonic-gate 	fwrite(key, keylen, 1, childargs);
3337c478bd9Sstevel@tonic-gate 	fprintf(childargs, "\n");
3347c478bd9Sstevel@tonic-gate 	fprintf(childargs, "%u\n", datalen);
3357c478bd9Sstevel@tonic-gate 	fwrite(data, datalen, 1, childargs);
3367c478bd9Sstevel@tonic-gate 	fprintf(childargs, "\n");
3377c478bd9Sstevel@tonic-gate 	fclose(childargs);
3387c478bd9Sstevel@tonic-gate 
3397c478bd9Sstevel@tonic-gate 	/*
3407c478bd9Sstevel@tonic-gate 	 * Read from child
3417c478bd9Sstevel@tonic-gate 	 */
3427c478bd9Sstevel@tonic-gate 	fscanf(childrslt, "%d", &yperrno);
3437c478bd9Sstevel@tonic-gate 	fclose(childrslt);
3447c478bd9Sstevel@tonic-gate 
3457c478bd9Sstevel@tonic-gate 	wait(&status);
3467c478bd9Sstevel@tonic-gate 	if (!WIFEXITED(status)) {
3477c478bd9Sstevel@tonic-gate 		return (YPERR_YPERR);
3487c478bd9Sstevel@tonic-gate 	}
3497c478bd9Sstevel@tonic-gate 	return (yperrno);
3507c478bd9Sstevel@tonic-gate }
3517c478bd9Sstevel@tonic-gate 
3527c478bd9Sstevel@tonic-gate static void
3537c478bd9Sstevel@tonic-gate msgout(msg)
3547c478bd9Sstevel@tonic-gate 	char *msg;
3557c478bd9Sstevel@tonic-gate {
3567c478bd9Sstevel@tonic-gate 	if (_rpcpmstart)
3577c478bd9Sstevel@tonic-gate 		syslog(LOG_ERR, msg);
3587c478bd9Sstevel@tonic-gate 	else
3597c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr, "%s\n", msg);
3607c478bd9Sstevel@tonic-gate }
3617c478bd9Sstevel@tonic-gate 
3627c478bd9Sstevel@tonic-gate void
3637c478bd9Sstevel@tonic-gate closedown()
3647c478bd9Sstevel@tonic-gate {
3657c478bd9Sstevel@tonic-gate 	if (_rpcsvcdirty == 0) {
3667c478bd9Sstevel@tonic-gate 		int i, openfd;
3677c478bd9Sstevel@tonic-gate 		struct t_info tinfo;
3687c478bd9Sstevel@tonic-gate 
3697c478bd9Sstevel@tonic-gate 		if (t_getinfo(0, tinfo) || (tinfo.servtype == T_CLTS))
3707c478bd9Sstevel@tonic-gate 			exit(0);
3717c478bd9Sstevel@tonic-gate 
3727c478bd9Sstevel@tonic-gate 		for (i = 0, openfd = 0; i < svc_max_pollfd && openfd < 2; i++)
3737c478bd9Sstevel@tonic-gate 			if (svc_pollfd[i].fd >= 0)
3747c478bd9Sstevel@tonic-gate 				openfd++;
3757c478bd9Sstevel@tonic-gate 
3767c478bd9Sstevel@tonic-gate 		if (openfd <= 1)
3777c478bd9Sstevel@tonic-gate 			exit(0);
3787c478bd9Sstevel@tonic-gate 	}
3797c478bd9Sstevel@tonic-gate 	(void) alarm(_RPCSVC_CLOSEDOWN);
3807c478bd9Sstevel@tonic-gate }
3817c478bd9Sstevel@tonic-gate 
3827c478bd9Sstevel@tonic-gate static int
3837c478bd9Sstevel@tonic-gate addr2netname(namebuf, transp)
3847c478bd9Sstevel@tonic-gate 	char *namebuf;
3857c478bd9Sstevel@tonic-gate 	SVCXPRT *transp;
3867c478bd9Sstevel@tonic-gate {
3877c478bd9Sstevel@tonic-gate 	struct nd_hostservlist *hostservs = NULL;
3887c478bd9Sstevel@tonic-gate 	struct netconfig *nconf;
3897c478bd9Sstevel@tonic-gate 	struct netbuf *who;
3907c478bd9Sstevel@tonic-gate 
3917c478bd9Sstevel@tonic-gate 	who = svc_getrpccaller(transp);
3927c478bd9Sstevel@tonic-gate 	if ((who == NULL) || (who->len == 0))
3937c478bd9Sstevel@tonic-gate 		return (-1);
3947c478bd9Sstevel@tonic-gate 	if ((nconf = getnetconfigent(transp->xp_netid))
3957c478bd9Sstevel@tonic-gate 		== (struct netconfig *)NULL)
3967c478bd9Sstevel@tonic-gate 		return (-1);
3977c478bd9Sstevel@tonic-gate 	if (netdir_getbyaddr(nconf, &hostservs, who) != 0) {
3987c478bd9Sstevel@tonic-gate 		(void) freenetconfigent(nconf);
3997c478bd9Sstevel@tonic-gate 		return (-1);
4007c478bd9Sstevel@tonic-gate 	}
4017c478bd9Sstevel@tonic-gate 	if (hostservs == NULL) {
4027c478bd9Sstevel@tonic-gate 		msgout("ypupdated: netdir_getbyaddr failed\n");
4037c478bd9Sstevel@tonic-gate 	} else {
4047c478bd9Sstevel@tonic-gate 		strcpy(namebuf, hostservs->h_hostservs->h_host);
4057c478bd9Sstevel@tonic-gate 	}
4067c478bd9Sstevel@tonic-gate 	(void) freenetconfigent(nconf);
4077c478bd9Sstevel@tonic-gate 	netdir_free((char *)hostservs, ND_HOSTSERVLIST);
4087c478bd9Sstevel@tonic-gate 	return (0);
4097c478bd9Sstevel@tonic-gate }
410