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
566786d5eSdjl  * Common Development and Distribution License (the "License").
666786d5eSdjl  *  You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22b1cdc720SAlex Wilson  * Copyright 2017 Joyent Inc
23d67944fbSScott Rotondo  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate /*
287c478bd9Sstevel@tonic-gate  * NIS update service
297c478bd9Sstevel@tonic-gate  */
307c478bd9Sstevel@tonic-gate #include <stdio.h>
317c478bd9Sstevel@tonic-gate #include <sys/wait.h>
327c478bd9Sstevel@tonic-gate #include <sys/time.h>
337c478bd9Sstevel@tonic-gate #include <sys/file.h>
347c478bd9Sstevel@tonic-gate #include <ctype.h>
35*9bba04feSToomas Soome #define	PORTMAP
367c478bd9Sstevel@tonic-gate #include <rpc/rpc.h>
377c478bd9Sstevel@tonic-gate #include <rpc/auth_des.h>
387c478bd9Sstevel@tonic-gate #include <sys/socket.h>
397c478bd9Sstevel@tonic-gate #include <sys/signal.h>
407c478bd9Sstevel@tonic-gate #include <sys/stat.h>
417c478bd9Sstevel@tonic-gate #include <sys/termio.h>
42b1cdc720SAlex Wilson #include <sys/debug.h>
437c478bd9Sstevel@tonic-gate #include <strings.h>
447c478bd9Sstevel@tonic-gate #include <rpcsvc/ypclnt.h>
457c478bd9Sstevel@tonic-gate #include <rpcsvc/yp_prot.h>
467c478bd9Sstevel@tonic-gate #include <netdir.h>
477c478bd9Sstevel@tonic-gate #include <rpcsvc/ypupd.h>
487c478bd9Sstevel@tonic-gate #include <netdb.h>
497c478bd9Sstevel@tonic-gate #include "shim.h"
507c478bd9Sstevel@tonic-gate #include "yptol.h"
517c478bd9Sstevel@tonic-gate 
527c478bd9Sstevel@tonic-gate #define	RPC_INETDSOCK	0	/* socket descriptor if using inetd */
537c478bd9Sstevel@tonic-gate #define	debug(msg)	/* turn off debugging */
547c478bd9Sstevel@tonic-gate 
557c478bd9Sstevel@tonic-gate char YPDIR[] = "/var/yp";
567c478bd9Sstevel@tonic-gate char UPDATEFILE[] = "updaters";
577c478bd9Sstevel@tonic-gate 
58*9bba04feSToomas Soome void ypupdate_prog(struct svc_req *rqstp, SVCXPRT *transp);
59*9bba04feSToomas Soome void detachfromtty(void);
60a506a34cSth 
61a506a34cSth static int addr2netname(char *, SVCXPRT *);
62*9bba04feSToomas Soome static int issock(int);
63a506a34cSth 
647c478bd9Sstevel@tonic-gate int insecure;
657c478bd9Sstevel@tonic-gate 
66a506a34cSth int
main(int argc,char * argv[])67*9bba04feSToomas Soome main(int argc, char *argv[])
687c478bd9Sstevel@tonic-gate {
697c478bd9Sstevel@tonic-gate 	char *cmd;
707c478bd9Sstevel@tonic-gate 	int connmaxrec = RPC_MAXDATASIZE;
717c478bd9Sstevel@tonic-gate 	struct stat filestat;
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate 	/*
747c478bd9Sstevel@tonic-gate 	 * Check if we are running in N2L mode. If so updated is unsuported.
757c478bd9Sstevel@tonic-gate 	 * This could be done by calling is_yptol_mode(), from libnisdb, but it
767c478bd9Sstevel@tonic-gate 	 * seems over complex to pull in an entire library for one check so
777c478bd9Sstevel@tonic-gate 	 * do it in line. Just pull in the name of file to check.
787c478bd9Sstevel@tonic-gate 	 */
797c478bd9Sstevel@tonic-gate 	if (stat(NTOL_MAP_FILE, &filestat) != -1) {
807c478bd9Sstevel@tonic-gate 		fprintf(stderr, "rpc.updated not supported in NIS to LDAP "
81*9bba04feSToomas Soome 		    "transition mode.");
827c478bd9Sstevel@tonic-gate 		exit(1);
837c478bd9Sstevel@tonic-gate 	}
847c478bd9Sstevel@tonic-gate 
857c478bd9Sstevel@tonic-gate 
867c478bd9Sstevel@tonic-gate 	cmd = argv[0];
877c478bd9Sstevel@tonic-gate 	switch (argc) {
887c478bd9Sstevel@tonic-gate 	case 0:
897c478bd9Sstevel@tonic-gate 		cmd = "ypupdated";
907c478bd9Sstevel@tonic-gate 		break;
917c478bd9Sstevel@tonic-gate 	case 1:
927c478bd9Sstevel@tonic-gate 		break;
937c478bd9Sstevel@tonic-gate 	case 2:
947c478bd9Sstevel@tonic-gate 		if (strcmp(argv[1], "-i") == 0) {
957c478bd9Sstevel@tonic-gate 			insecure++;
967c478bd9Sstevel@tonic-gate 			break;
977c478bd9Sstevel@tonic-gate 		} else if (strcmp(argv[1], "-s") == 0) {
987c478bd9Sstevel@tonic-gate 			insecure = 0;
997c478bd9Sstevel@tonic-gate 			break;
1007c478bd9Sstevel@tonic-gate 		}
101*9bba04feSToomas Soome 		/* FALLTHROUGH */
1027c478bd9Sstevel@tonic-gate 	default:
1037c478bd9Sstevel@tonic-gate 		fprintf(stderr, "%s: warning -- options ignored\n", cmd);
1047c478bd9Sstevel@tonic-gate 		break;
1057c478bd9Sstevel@tonic-gate 	}
1067c478bd9Sstevel@tonic-gate 
1077c478bd9Sstevel@tonic-gate 	if (chdir(YPDIR) < 0) {
1087c478bd9Sstevel@tonic-gate 		fprintf(stderr, "%s: can't chdir to ", cmd);
1097c478bd9Sstevel@tonic-gate 		perror(YPDIR);
1107c478bd9Sstevel@tonic-gate 		exit(1);
1117c478bd9Sstevel@tonic-gate 	}
1127c478bd9Sstevel@tonic-gate 
1137c478bd9Sstevel@tonic-gate 	/*
1147c478bd9Sstevel@tonic-gate 	 * Set non-blocking mode and maximum record size for
1157c478bd9Sstevel@tonic-gate 	 * connection oriented RPC transports.
1167c478bd9Sstevel@tonic-gate 	 */
1177c478bd9Sstevel@tonic-gate 	if (!rpc_control(RPC_SVC_CONNMAXREC_SET, &connmaxrec)) {
1187c478bd9Sstevel@tonic-gate 		fprintf(stderr, "unable to set maximum RPC record size");
1197c478bd9Sstevel@tonic-gate 	}
1207c478bd9Sstevel@tonic-gate 
1217c478bd9Sstevel@tonic-gate 	if (issock(RPC_INETDSOCK)) {
1227c478bd9Sstevel@tonic-gate 		SVCXPRT *transp;
1237c478bd9Sstevel@tonic-gate 		int proto = 0;
1247c478bd9Sstevel@tonic-gate 		transp = svctcp_create(RPC_INETDSOCK, 0, 0);
1257c478bd9Sstevel@tonic-gate 		if (transp == NULL) {
1267c478bd9Sstevel@tonic-gate 			fprintf(stderr, "%s: cannot create tcp service\n", cmd);
1277c478bd9Sstevel@tonic-gate 			exit(1);
1287c478bd9Sstevel@tonic-gate 		}
1297c478bd9Sstevel@tonic-gate 		if (!svc_register(transp, YPU_PROG, YPU_VERS, ypupdate_prog,
130*9bba04feSToomas Soome 		    proto)) {
1317c478bd9Sstevel@tonic-gate 			fprintf(stderr, "%s: couldn't register service\n", cmd);
1327c478bd9Sstevel@tonic-gate 			exit(1);
1337c478bd9Sstevel@tonic-gate 		}
1347c478bd9Sstevel@tonic-gate 	} else {
1357c478bd9Sstevel@tonic-gate 		detachfromtty();
1367c478bd9Sstevel@tonic-gate 		(void) rpcb_unset(YPU_PROG, YPU_VERS, 0);
1377c478bd9Sstevel@tonic-gate 		if (!svc_create(ypupdate_prog, YPU_PROG, YPU_VERS, "tcp")) {
1387c478bd9Sstevel@tonic-gate 			fprintf(stderr, "%s: cannot create tcp service\n", cmd);
1397c478bd9Sstevel@tonic-gate 			exit(1);
1407c478bd9Sstevel@tonic-gate 		}
1417c478bd9Sstevel@tonic-gate 	}
1427c478bd9Sstevel@tonic-gate 
1437c478bd9Sstevel@tonic-gate 	if (!svc_create(ypupdate_prog, YPU_PROG, YPU_VERS, "udp")) {
1447c478bd9Sstevel@tonic-gate 		fprintf(stderr, "%s: cannot create udp service\n", cmd);
1457c478bd9Sstevel@tonic-gate 		exit(1);
1467c478bd9Sstevel@tonic-gate 	}
1477c478bd9Sstevel@tonic-gate 
1487c478bd9Sstevel@tonic-gate 	svc_run();
1497c478bd9Sstevel@tonic-gate 	abort();
1507c478bd9Sstevel@tonic-gate 	/* NOTREACHED */
151a506a34cSth 	return (1);
1527c478bd9Sstevel@tonic-gate }
1537c478bd9Sstevel@tonic-gate 
1547c478bd9Sstevel@tonic-gate /*
1557c478bd9Sstevel@tonic-gate  * Determine if a descriptor belongs to a socket or not
1567c478bd9Sstevel@tonic-gate  */
1577c478bd9Sstevel@tonic-gate static int
issock(int fd)158*9bba04feSToomas Soome issock(int fd)
1597c478bd9Sstevel@tonic-gate {
1607c478bd9Sstevel@tonic-gate 	struct stat st;
1617c478bd9Sstevel@tonic-gate 
1627c478bd9Sstevel@tonic-gate 	if (fstat(fd, &st) == -1)
1637c478bd9Sstevel@tonic-gate 		return (0);
1647c478bd9Sstevel@tonic-gate 	else
1657c478bd9Sstevel@tonic-gate 		return (S_ISSOCK(fd));
1667c478bd9Sstevel@tonic-gate }
1677c478bd9Sstevel@tonic-gate 
1687c478bd9Sstevel@tonic-gate 
1697c478bd9Sstevel@tonic-gate void
detachfromtty(void)170*9bba04feSToomas Soome detachfromtty(void)
1717c478bd9Sstevel@tonic-gate {
1727c478bd9Sstevel@tonic-gate 	int tt;
1737c478bd9Sstevel@tonic-gate 
1747c478bd9Sstevel@tonic-gate 	close(0);
1757c478bd9Sstevel@tonic-gate 	close(1);
1767c478bd9Sstevel@tonic-gate 	close(2);
1777c478bd9Sstevel@tonic-gate 	switch (fork()) {
1787c478bd9Sstevel@tonic-gate 	case -1:
1797c478bd9Sstevel@tonic-gate 		perror("fork");
1807c478bd9Sstevel@tonic-gate 		break;
1817c478bd9Sstevel@tonic-gate 	case 0:
1827c478bd9Sstevel@tonic-gate 		break;
1837c478bd9Sstevel@tonic-gate 	default:
1847c478bd9Sstevel@tonic-gate 		exit(0);
1857c478bd9Sstevel@tonic-gate 	}
1867c478bd9Sstevel@tonic-gate 	tt = open("/dev/tty", O_RDWR, 0);
1877c478bd9Sstevel@tonic-gate 	if (tt >= 0) {
1887c478bd9Sstevel@tonic-gate 		ioctl(tt, TIOCNOTTY, 0);
1897c478bd9Sstevel@tonic-gate 		close(tt);
1907c478bd9Sstevel@tonic-gate 	}
1917c478bd9Sstevel@tonic-gate 	open("/dev/null", O_RDWR, 0);
1927c478bd9Sstevel@tonic-gate 	dup(0);
1937c478bd9Sstevel@tonic-gate 	dup(0);
1947c478bd9Sstevel@tonic-gate }
1957c478bd9Sstevel@tonic-gate 
1967c478bd9Sstevel@tonic-gate void
ypupdate_prog(struct svc_req * rqstp,SVCXPRT * transp)197*9bba04feSToomas Soome ypupdate_prog(struct svc_req *rqstp, SVCXPRT *transp)
1987c478bd9Sstevel@tonic-gate {
1997c478bd9Sstevel@tonic-gate 	struct ypupdate_args args;
2007c478bd9Sstevel@tonic-gate 	uint_t rslt;
2017c478bd9Sstevel@tonic-gate 	uint_t op;
2027c478bd9Sstevel@tonic-gate 	char *netname;
2037c478bd9Sstevel@tonic-gate 	char namebuf[MAXNETNAMELEN+1];
2047c478bd9Sstevel@tonic-gate 	struct authunix_parms *aup;
2057c478bd9Sstevel@tonic-gate 
206*9bba04feSToomas Soome 	CTASSERT(sizeof (struct authdes_cred) <= RQCRED_SIZE);
207*9bba04feSToomas Soome 	CTASSERT(sizeof (struct authunix_parms) <= RQCRED_SIZE);
208*9bba04feSToomas Soome 
2097c478bd9Sstevel@tonic-gate 	switch (rqstp->rq_proc) {
2107c478bd9Sstevel@tonic-gate 	case NULLPROC:
2117c478bd9Sstevel@tonic-gate 		svc_sendreply(transp, xdr_void, NULL);
2127c478bd9Sstevel@tonic-gate 		return;
2137c478bd9Sstevel@tonic-gate 	case YPU_CHANGE:
2147c478bd9Sstevel@tonic-gate 		op = YPOP_CHANGE;
2157c478bd9Sstevel@tonic-gate 		break;
2167c478bd9Sstevel@tonic-gate 	case YPU_DELETE:
2177c478bd9Sstevel@tonic-gate 		op = YPOP_DELETE;
2187c478bd9Sstevel@tonic-gate 		break;
2197c478bd9Sstevel@tonic-gate 	case YPU_INSERT:
2207c478bd9Sstevel@tonic-gate 		op = YPOP_INSERT;
2217c478bd9Sstevel@tonic-gate 		break;
2227c478bd9Sstevel@tonic-gate 	case YPU_STORE:
2237c478bd9Sstevel@tonic-gate 		op = YPOP_STORE;
2247c478bd9Sstevel@tonic-gate 		break;
2257c478bd9Sstevel@tonic-gate 	default:
2267c478bd9Sstevel@tonic-gate 		svcerr_noproc(transp);
2277c478bd9Sstevel@tonic-gate 		return;
2287c478bd9Sstevel@tonic-gate 	}
229b1cdc720SAlex Wilson 
2307c478bd9Sstevel@tonic-gate 	switch (rqstp->rq_cred.oa_flavor) {
2317c478bd9Sstevel@tonic-gate 	case AUTH_DES:
2327c478bd9Sstevel@tonic-gate 		netname = ((struct authdes_cred *)
233*9bba04feSToomas Soome 		    rqstp->rq_clntcred)->adc_fullname.name;
2347c478bd9Sstevel@tonic-gate 		break;
2357c478bd9Sstevel@tonic-gate 	case AUTH_UNIX:
2367c478bd9Sstevel@tonic-gate 		if (insecure) {
2377c478bd9Sstevel@tonic-gate 			aup = (struct authunix_parms *)rqstp->rq_clntcred;
2387c478bd9Sstevel@tonic-gate 			if (aup->aup_uid == 0) {
2397c478bd9Sstevel@tonic-gate 			/*
2407c478bd9Sstevel@tonic-gate 			 *	addr2netname(namebuf, svc_getcaller(transp));
2417c478bd9Sstevel@tonic-gate 			 */
2427c478bd9Sstevel@tonic-gate 				addr2netname(namebuf, transp);
2437c478bd9Sstevel@tonic-gate 			} else {
2447c478bd9Sstevel@tonic-gate 				user2netname(namebuf, aup->aup_uid, NULL);
2457c478bd9Sstevel@tonic-gate 			}
2467c478bd9Sstevel@tonic-gate 			netname = namebuf;
2477c478bd9Sstevel@tonic-gate 			break;
2487c478bd9Sstevel@tonic-gate 		}
249*9bba04feSToomas Soome 		/* FALLTHROUGH */
2507c478bd9Sstevel@tonic-gate 	default:
2517c478bd9Sstevel@tonic-gate 		svcerr_weakauth(transp);
2527c478bd9Sstevel@tonic-gate 		return;
2537c478bd9Sstevel@tonic-gate 	}
2547c478bd9Sstevel@tonic-gate 	bzero(&args, sizeof (args));
2557c478bd9Sstevel@tonic-gate 	if (!svc_getargs(transp, xdr_ypupdate_args, (caddr_t)&args)) {
2567c478bd9Sstevel@tonic-gate 		svcerr_decode(transp);
2577c478bd9Sstevel@tonic-gate 		return;
2587c478bd9Sstevel@tonic-gate 	}
2597c478bd9Sstevel@tonic-gate 	rslt = update(netname,
260*9bba04feSToomas Soome 	    args.mapname, op, args.key.yp_buf_len, args.key.yp_buf_val,
261*9bba04feSToomas Soome 	    args.datum.yp_buf_len, args.datum.yp_buf_val);
2627c478bd9Sstevel@tonic-gate 	if (!svc_sendreply(transp, xdr_u_int, (const caddr_t)&rslt)) {
2637c478bd9Sstevel@tonic-gate 		debug("svc_sendreply failed");
2647c478bd9Sstevel@tonic-gate 	}
2657c478bd9Sstevel@tonic-gate 	if (!svc_freeargs(transp, xdr_ypupdate_args, (caddr_t)&args)) {
2667c478bd9Sstevel@tonic-gate 		debug("svc_freeargs failed");
2677c478bd9Sstevel@tonic-gate 	}
2687c478bd9Sstevel@tonic-gate }
2697c478bd9Sstevel@tonic-gate 
2707c478bd9Sstevel@tonic-gate /*
2717c478bd9Sstevel@tonic-gate  * Determine if requester is allowed to update the given map,
2727c478bd9Sstevel@tonic-gate  * and update it if so. Returns the NIS status, which is zero
2737c478bd9Sstevel@tonic-gate  * if there is no access violation.
2747c478bd9Sstevel@tonic-gate  */
275a506a34cSth int
update(char * requester,char * mapname,uint_t op,uint_t keylen,char * key,uint_t datalen,char * data)276*9bba04feSToomas Soome update(char *requester, char *mapname, uint_t op, uint_t keylen, char *key,
277*9bba04feSToomas Soome     uint_t datalen, char *data)
2787c478bd9Sstevel@tonic-gate {
2797c478bd9Sstevel@tonic-gate 	char updater[MAXMAPNAMELEN + 40];
2807c478bd9Sstevel@tonic-gate 	FILE *childargs;
2817c478bd9Sstevel@tonic-gate 	FILE *childrslt;
2827c478bd9Sstevel@tonic-gate 	int status;
2837c478bd9Sstevel@tonic-gate 	int yperrno;
2847c478bd9Sstevel@tonic-gate 	int pid;
2857c478bd9Sstevel@tonic-gate 	char default_domain[YPMAXDOMAIN];
2867c478bd9Sstevel@tonic-gate 	int err;
2877c478bd9Sstevel@tonic-gate 	char fake_key[10];
2887c478bd9Sstevel@tonic-gate 	char *outval = NULL;
2897c478bd9Sstevel@tonic-gate 	int outval_len;
2907c478bd9Sstevel@tonic-gate 
2917c478bd9Sstevel@tonic-gate 	if (getdomainname(default_domain, YPMAXDOMAIN)) {
2927c478bd9Sstevel@tonic-gate 		debug("Couldn't get default domain name");
2937c478bd9Sstevel@tonic-gate 		return (YPERR_YPERR);
2947c478bd9Sstevel@tonic-gate 	}
2957c478bd9Sstevel@tonic-gate 
2967c478bd9Sstevel@tonic-gate 	/* check to see if we have a valid mapname */
2977c478bd9Sstevel@tonic-gate 	strncpy(fake_key, "junk", 4);
2987c478bd9Sstevel@tonic-gate 	err = yp_match(default_domain, mapname,
299*9bba04feSToomas Soome 	    fake_key, strlen(fake_key), &outval, &outval_len);
3007c478bd9Sstevel@tonic-gate 	switch (err) {
30166786d5eSdjl 		case 0:
30266786d5eSdjl 		case YPERR_KEY:
30366786d5eSdjl 			/* do nothing, only worry about above return code */
3047c478bd9Sstevel@tonic-gate 			break;
3057c478bd9Sstevel@tonic-gate 		default:
30666786d5eSdjl 			/* defensive programming */
30766786d5eSdjl 			return (YPERR_YPERR);
3087c478bd9Sstevel@tonic-gate 			break;
3097c478bd9Sstevel@tonic-gate 	}
3107c478bd9Sstevel@tonic-gate 
3117c478bd9Sstevel@tonic-gate 	/* valid map - continue */
3127c478bd9Sstevel@tonic-gate 	sprintf(updater, "make -s -f %s %s", UPDATEFILE, mapname);
3137c478bd9Sstevel@tonic-gate 	pid = _openchild(updater, &childargs, &childrslt);
3147c478bd9Sstevel@tonic-gate 	if (pid < 0) {
3157c478bd9Sstevel@tonic-gate 		debug("openpipes failed");
3167c478bd9Sstevel@tonic-gate 		return (YPERR_YPERR);
3177c478bd9Sstevel@tonic-gate 	}
3187c478bd9Sstevel@tonic-gate 
3197c478bd9Sstevel@tonic-gate 	/*
3207c478bd9Sstevel@tonic-gate 	 * Write to child
3217c478bd9Sstevel@tonic-gate 	 */
3227c478bd9Sstevel@tonic-gate 	fprintf(childargs, "%s\n", requester);
3237c478bd9Sstevel@tonic-gate 	fprintf(childargs, "%u\n", op);
3247c478bd9Sstevel@tonic-gate 	fprintf(childargs, "%u\n", keylen);
3257c478bd9Sstevel@tonic-gate 	fwrite(key, keylen, 1, childargs);
3267c478bd9Sstevel@tonic-gate 	fprintf(childargs, "\n");
3277c478bd9Sstevel@tonic-gate 	fprintf(childargs, "%u\n", datalen);
3287c478bd9Sstevel@tonic-gate 	fwrite(data, datalen, 1, childargs);
3297c478bd9Sstevel@tonic-gate 	fprintf(childargs, "\n");
3307c478bd9Sstevel@tonic-gate 	fclose(childargs);
3317c478bd9Sstevel@tonic-gate 
3327c478bd9Sstevel@tonic-gate 	/*
3337c478bd9Sstevel@tonic-gate 	 * Read from child
3347c478bd9Sstevel@tonic-gate 	 */
3357c478bd9Sstevel@tonic-gate 	fscanf(childrslt, "%d", &yperrno);
3367c478bd9Sstevel@tonic-gate 	fclose(childrslt);
3377c478bd9Sstevel@tonic-gate 
3387c478bd9Sstevel@tonic-gate 	wait(&status);
3397c478bd9Sstevel@tonic-gate 	if (!WIFEXITED(status)) {
3407c478bd9Sstevel@tonic-gate 		return (YPERR_YPERR);
3417c478bd9Sstevel@tonic-gate 	}
3427c478bd9Sstevel@tonic-gate 	return (yperrno);
3437c478bd9Sstevel@tonic-gate }
3447c478bd9Sstevel@tonic-gate 
3457c478bd9Sstevel@tonic-gate #if 0
346*9bba04feSToomas Soome addr2netname(char *namebuf, struct sockaddr_in *addr)
3477c478bd9Sstevel@tonic-gate {
3487c478bd9Sstevel@tonic-gate 	struct hostent *h;
3497c478bd9Sstevel@tonic-gate 
3507c478bd9Sstevel@tonic-gate 	h = gethostbyaddr((const char *) &addr->sin_addr,
351*9bba04feSToomas Soome 	    sizeof (addr->sin_addr), AF_INET);
3527c478bd9Sstevel@tonic-gate 	if (h == NULL) {
3537c478bd9Sstevel@tonic-gate 		host2netname(namebuf, (const char *) inet_ntoa(addr->sin_addr),
354*9bba04feSToomas Soome 		    NULL);
3557c478bd9Sstevel@tonic-gate 	} else {
3567c478bd9Sstevel@tonic-gate 		host2netname(namebuf, h->h_name, NULL);
3577c478bd9Sstevel@tonic-gate 	}
3587c478bd9Sstevel@tonic-gate }
3597c478bd9Sstevel@tonic-gate #endif
3607c478bd9Sstevel@tonic-gate 
3617c478bd9Sstevel@tonic-gate 
3627c478bd9Sstevel@tonic-gate static int
addr2netname(char * namebuf,SVCXPRT * transp)363*9bba04feSToomas Soome addr2netname(char *namebuf, SVCXPRT *transp)
3647c478bd9Sstevel@tonic-gate {
3657c478bd9Sstevel@tonic-gate 	struct nd_hostservlist *hostservs = NULL;
3667c478bd9Sstevel@tonic-gate 	struct netconfig *nconf;
3677c478bd9Sstevel@tonic-gate 	struct netbuf *who;
3687c478bd9Sstevel@tonic-gate 
3697c478bd9Sstevel@tonic-gate 	who = svc_getrpccaller(transp);
3707c478bd9Sstevel@tonic-gate 	if ((who == NULL) || (who->len == 0))
3717c478bd9Sstevel@tonic-gate 		return (-1);
372*9bba04feSToomas Soome 	if ((nconf = getnetconfigent(transp->xp_netid)) == NULL)
3737c478bd9Sstevel@tonic-gate 		return (-1);
3747c478bd9Sstevel@tonic-gate 	if (netdir_getbyaddr(nconf, &hostservs, who) != 0) {
3757c478bd9Sstevel@tonic-gate 		(void) freenetconfigent(nconf);
3767c478bd9Sstevel@tonic-gate 		return (-1);
3777c478bd9Sstevel@tonic-gate 	}
3787c478bd9Sstevel@tonic-gate 	if (hostservs != NULL)
3797c478bd9Sstevel@tonic-gate 		strcpy(namebuf, hostservs->h_hostservs->h_host);
3807c478bd9Sstevel@tonic-gate 
3817c478bd9Sstevel@tonic-gate 	(void) freenetconfigent(nconf);
3827c478bd9Sstevel@tonic-gate 	netdir_free((char *)hostservs, ND_HOSTSERVLIST);
3837c478bd9Sstevel@tonic-gate 	return (0);
3847c478bd9Sstevel@tonic-gate }
385