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 2000 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 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */ 28*7c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 29*7c478bd9Sstevel@tonic-gate 30*7c478bd9Sstevel@tonic-gate /* 31*7c478bd9Sstevel@tonic-gate * Portions of this source code were derived from Berkeley 4.3 BSD 32*7c478bd9Sstevel@tonic-gate * under license from the Regents of the University of California. 33*7c478bd9Sstevel@tonic-gate */ 34*7c478bd9Sstevel@tonic-gate 35*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 36*7c478bd9Sstevel@tonic-gate 37*7c478bd9Sstevel@tonic-gate #ifndef lint 38*7c478bd9Sstevel@tonic-gate static char sccsid[] = "@(#)rpc.ypupdated.c 1.9 87/10/30 Copyr 1986 Sun Micro"; 39*7c478bd9Sstevel@tonic-gate #endif 40*7c478bd9Sstevel@tonic-gate 41*7c478bd9Sstevel@tonic-gate /* 42*7c478bd9Sstevel@tonic-gate * YP update service 43*7c478bd9Sstevel@tonic-gate */ 44*7c478bd9Sstevel@tonic-gate #include <stdio.h> 45*7c478bd9Sstevel@tonic-gate #include <stdlib.h> 46*7c478bd9Sstevel@tonic-gate #include <sys/types.h> 47*7c478bd9Sstevel@tonic-gate #include <sys/file.h> 48*7c478bd9Sstevel@tonic-gate #include <sys/signal.h> 49*7c478bd9Sstevel@tonic-gate #include <sys/wait.h> 50*7c478bd9Sstevel@tonic-gate #include <rpc/rpc.h> 51*7c478bd9Sstevel@tonic-gate #include <rpc/nettype.h> 52*7c478bd9Sstevel@tonic-gate #include <rpcsvc/ypupd.h> 53*7c478bd9Sstevel@tonic-gate #include <rpcsvc/ypclnt.h> 54*7c478bd9Sstevel@tonic-gate #include <netdir.h> 55*7c478bd9Sstevel@tonic-gate #include <stropts.h> 56*7c478bd9Sstevel@tonic-gate #ifdef SYSLOG 57*7c478bd9Sstevel@tonic-gate #include <syslog.h> 58*7c478bd9Sstevel@tonic-gate #else 59*7c478bd9Sstevel@tonic-gate #define LOG_ERR 1 60*7c478bd9Sstevel@tonic-gate #define openlog(a, b, c) 61*7c478bd9Sstevel@tonic-gate #endif 62*7c478bd9Sstevel@tonic-gate 63*7c478bd9Sstevel@tonic-gate #ifdef DEBUG 64*7c478bd9Sstevel@tonic-gate #define RPC_SVC_FG 65*7c478bd9Sstevel@tonic-gate #define debug(msg) fprintf(stderr, "%s\n", msg); 66*7c478bd9Sstevel@tonic-gate #else 67*7c478bd9Sstevel@tonic-gate #define debug(msg) /* turn off debugging */ 68*7c478bd9Sstevel@tonic-gate #endif 69*7c478bd9Sstevel@tonic-gate 70*7c478bd9Sstevel@tonic-gate static char YPDIR[] = "/var/yp"; 71*7c478bd9Sstevel@tonic-gate static char UPDATEFILE[] = "/var/yp/updaters"; 72*7c478bd9Sstevel@tonic-gate #define _RPCSVC_CLOSEDOWN 120 73*7c478bd9Sstevel@tonic-gate 74*7c478bd9Sstevel@tonic-gate static int addr2netname(); 75*7c478bd9Sstevel@tonic-gate static void closedown(); 76*7c478bd9Sstevel@tonic-gate static void ypupdate_prog(); 77*7c478bd9Sstevel@tonic-gate static void msgout(); 78*7c478bd9Sstevel@tonic-gate static int update(); 79*7c478bd9Sstevel@tonic-gate static int insecure; 80*7c478bd9Sstevel@tonic-gate static int _rpcpmstart; /* Started by a port monitor ? */ 81*7c478bd9Sstevel@tonic-gate static int _rpcsvcdirty; /* Still serving ? */ 82*7c478bd9Sstevel@tonic-gate 83*7c478bd9Sstevel@tonic-gate extern unsigned int alarm(); 84*7c478bd9Sstevel@tonic-gate extern void exit(); 85*7c478bd9Sstevel@tonic-gate extern int close(); 86*7c478bd9Sstevel@tonic-gate extern long fork(); 87*7c478bd9Sstevel@tonic-gate extern int free(); 88*7c478bd9Sstevel@tonic-gate extern struct netconfig *getnetconfigent(); 89*7c478bd9Sstevel@tonic-gate extern int strcmp(); 90*7c478bd9Sstevel@tonic-gate extern int strcpy(); 91*7c478bd9Sstevel@tonic-gate extern int syslog(); 92*7c478bd9Sstevel@tonic-gate extern void *signal(); 93*7c478bd9Sstevel@tonic-gate extern int setsid(); 94*7c478bd9Sstevel@tonic-gate extern int t_getinfo(); 95*7c478bd9Sstevel@tonic-gate extern int user2netname(); 96*7c478bd9Sstevel@tonic-gate extern int _openchild(); 97*7c478bd9Sstevel@tonic-gate 98*7c478bd9Sstevel@tonic-gate main(argc, argv) 99*7c478bd9Sstevel@tonic-gate int argc; 100*7c478bd9Sstevel@tonic-gate char *argv[]; 101*7c478bd9Sstevel@tonic-gate { 102*7c478bd9Sstevel@tonic-gate pid_t pid; 103*7c478bd9Sstevel@tonic-gate char *cmd; 104*7c478bd9Sstevel@tonic-gate char mname[FMNAMESZ + 1]; 105*7c478bd9Sstevel@tonic-gate 106*7c478bd9Sstevel@tonic-gate if (geteuid() != 0) { 107*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "must be root to run %s\n", argv[0]); 108*7c478bd9Sstevel@tonic-gate exit(1); 109*7c478bd9Sstevel@tonic-gate } 110*7c478bd9Sstevel@tonic-gate 111*7c478bd9Sstevel@tonic-gate cmd = argv[0]; 112*7c478bd9Sstevel@tonic-gate switch (argc) { 113*7c478bd9Sstevel@tonic-gate case 0: 114*7c478bd9Sstevel@tonic-gate cmd = "ypupdated"; 115*7c478bd9Sstevel@tonic-gate break; 116*7c478bd9Sstevel@tonic-gate case 1: 117*7c478bd9Sstevel@tonic-gate break; 118*7c478bd9Sstevel@tonic-gate case 2: 119*7c478bd9Sstevel@tonic-gate if (strcmp(argv[1], "-i") == 0) { 120*7c478bd9Sstevel@tonic-gate insecure++; 121*7c478bd9Sstevel@tonic-gate break; 122*7c478bd9Sstevel@tonic-gate } 123*7c478bd9Sstevel@tonic-gate default: 124*7c478bd9Sstevel@tonic-gate fprintf(stderr, "%s: warning -- options ignored\n", cmd); 125*7c478bd9Sstevel@tonic-gate break; 126*7c478bd9Sstevel@tonic-gate } 127*7c478bd9Sstevel@tonic-gate 128*7c478bd9Sstevel@tonic-gate if (chdir(YPDIR) < 0) { 129*7c478bd9Sstevel@tonic-gate fprintf(stderr, "%s: can't chdir to ", cmd); 130*7c478bd9Sstevel@tonic-gate perror(YPDIR); 131*7c478bd9Sstevel@tonic-gate exit(1); 132*7c478bd9Sstevel@tonic-gate } 133*7c478bd9Sstevel@tonic-gate 134*7c478bd9Sstevel@tonic-gate if (!ioctl(0, I_LOOK, mname) && 135*7c478bd9Sstevel@tonic-gate (strcmp(mname, "sockmod") == 0 || 136*7c478bd9Sstevel@tonic-gate strcmp(mname, "timod") == 0)) { 137*7c478bd9Sstevel@tonic-gate /* 138*7c478bd9Sstevel@tonic-gate * Started from port monitor: use 0 as fd 139*7c478bd9Sstevel@tonic-gate */ 140*7c478bd9Sstevel@tonic-gate char *netid; 141*7c478bd9Sstevel@tonic-gate struct netconfig *nconf = NULL; 142*7c478bd9Sstevel@tonic-gate SVCXPRT *transp; 143*7c478bd9Sstevel@tonic-gate int pmclose; 144*7c478bd9Sstevel@tonic-gate extern char *getenv(); 145*7c478bd9Sstevel@tonic-gate 146*7c478bd9Sstevel@tonic-gate _rpcpmstart = 1; 147*7c478bd9Sstevel@tonic-gate if ((netid = getenv("NLSPROVIDER")) == NULL) { 148*7c478bd9Sstevel@tonic-gate msgout("cannot get transport name"); 149*7c478bd9Sstevel@tonic-gate } 150*7c478bd9Sstevel@tonic-gate if ((nconf = getnetconfigent(netid)) == NULL) { 151*7c478bd9Sstevel@tonic-gate msgout("cannot get transport info"); 152*7c478bd9Sstevel@tonic-gate } 153*7c478bd9Sstevel@tonic-gate if (strcmp(mname, "sockmod") == 0) { 154*7c478bd9Sstevel@tonic-gate if (ioctl(0, I_POP, 0) || ioctl(0, I_PUSH, "timod")) { 155*7c478bd9Sstevel@tonic-gate msgout("could not get the right module"); 156*7c478bd9Sstevel@tonic-gate exit(1); 157*7c478bd9Sstevel@tonic-gate } 158*7c478bd9Sstevel@tonic-gate } 159*7c478bd9Sstevel@tonic-gate pmclose = (t_getstate(0) != T_DATAXFER); 160*7c478bd9Sstevel@tonic-gate if ((transp = svc_tli_create(0, nconf, NULL, 0, 0)) == NULL) { 161*7c478bd9Sstevel@tonic-gate msgout("cannot create update server handle"); 162*7c478bd9Sstevel@tonic-gate exit(1); 163*7c478bd9Sstevel@tonic-gate } 164*7c478bd9Sstevel@tonic-gate if (!svc_reg(transp, YPU_PROG, YPU_VERS, ypupdate_prog, 0)) { 165*7c478bd9Sstevel@tonic-gate msgout("unable to register (YPBINDPROG, YPBINDVERS)."); 166*7c478bd9Sstevel@tonic-gate exit(1); 167*7c478bd9Sstevel@tonic-gate } 168*7c478bd9Sstevel@tonic-gate if (nconf) 169*7c478bd9Sstevel@tonic-gate freenetconfigent(nconf); 170*7c478bd9Sstevel@tonic-gate 171*7c478bd9Sstevel@tonic-gate if (pmclose) { 172*7c478bd9Sstevel@tonic-gate (void) signal(SIGALRM, closedown); 173*7c478bd9Sstevel@tonic-gate (void) alarm(_RPCSVC_CLOSEDOWN); 174*7c478bd9Sstevel@tonic-gate } 175*7c478bd9Sstevel@tonic-gate svc_run(); 176*7c478bd9Sstevel@tonic-gate exit(1); 177*7c478bd9Sstevel@tonic-gate } 178*7c478bd9Sstevel@tonic-gate #ifndef RPC_SVC_FG 179*7c478bd9Sstevel@tonic-gate /* 180*7c478bd9Sstevel@tonic-gate * Started from shell; background thyself and run 181*7c478bd9Sstevel@tonic-gate */ 182*7c478bd9Sstevel@tonic-gate pid = fork(); 183*7c478bd9Sstevel@tonic-gate 184*7c478bd9Sstevel@tonic-gate if (pid < 0) { 185*7c478bd9Sstevel@tonic-gate perror("cannot fork"); 186*7c478bd9Sstevel@tonic-gate exit(1); 187*7c478bd9Sstevel@tonic-gate } 188*7c478bd9Sstevel@tonic-gate if (pid) 189*7c478bd9Sstevel@tonic-gate exit(0); 190*7c478bd9Sstevel@tonic-gate closefrom(0); 191*7c478bd9Sstevel@tonic-gate (void) setsid(); 192*7c478bd9Sstevel@tonic-gate openlog("ypupdated", LOG_PID, LOG_DAEMON); 193*7c478bd9Sstevel@tonic-gate #endif 194*7c478bd9Sstevel@tonic-gate if (!svc_create(ypupdate_prog, YPU_PROG, YPU_VERS, "netpath")) { 195*7c478bd9Sstevel@tonic-gate msgout("unable to create (YPU_PROG, YPU_VERS) for netpath."); 196*7c478bd9Sstevel@tonic-gate exit(1); 197*7c478bd9Sstevel@tonic-gate } 198*7c478bd9Sstevel@tonic-gate 199*7c478bd9Sstevel@tonic-gate svc_run(); 200*7c478bd9Sstevel@tonic-gate msgout("svc_run returned"); 201*7c478bd9Sstevel@tonic-gate exit(1); 202*7c478bd9Sstevel@tonic-gate /* NOTREACHED */ 203*7c478bd9Sstevel@tonic-gate } 204*7c478bd9Sstevel@tonic-gate 205*7c478bd9Sstevel@tonic-gate static void 206*7c478bd9Sstevel@tonic-gate ypupdate_prog(rqstp, transp) 207*7c478bd9Sstevel@tonic-gate struct svc_req *rqstp; 208*7c478bd9Sstevel@tonic-gate SVCXPRT *transp; 209*7c478bd9Sstevel@tonic-gate { 210*7c478bd9Sstevel@tonic-gate struct ypupdate_args args; 211*7c478bd9Sstevel@tonic-gate uint_t rslt; 212*7c478bd9Sstevel@tonic-gate uint_t op; 213*7c478bd9Sstevel@tonic-gate char *netname; 214*7c478bd9Sstevel@tonic-gate char namebuf[MAXNETNAMELEN+1]; 215*7c478bd9Sstevel@tonic-gate struct authunix_parms *aup; 216*7c478bd9Sstevel@tonic-gate 217*7c478bd9Sstevel@tonic-gate switch (rqstp->rq_proc) { 218*7c478bd9Sstevel@tonic-gate case NULLPROC: 219*7c478bd9Sstevel@tonic-gate svc_sendreply(transp, xdr_void, NULL); 220*7c478bd9Sstevel@tonic-gate return; 221*7c478bd9Sstevel@tonic-gate case YPU_CHANGE: 222*7c478bd9Sstevel@tonic-gate op = YPOP_CHANGE; 223*7c478bd9Sstevel@tonic-gate break; 224*7c478bd9Sstevel@tonic-gate case YPU_DELETE: 225*7c478bd9Sstevel@tonic-gate op = YPOP_DELETE; 226*7c478bd9Sstevel@tonic-gate break; 227*7c478bd9Sstevel@tonic-gate case YPU_INSERT: 228*7c478bd9Sstevel@tonic-gate op = YPOP_INSERT; 229*7c478bd9Sstevel@tonic-gate break; 230*7c478bd9Sstevel@tonic-gate case YPU_STORE: 231*7c478bd9Sstevel@tonic-gate op = YPOP_STORE; 232*7c478bd9Sstevel@tonic-gate break; 233*7c478bd9Sstevel@tonic-gate default: 234*7c478bd9Sstevel@tonic-gate svcerr_noproc(transp); 235*7c478bd9Sstevel@tonic-gate return; 236*7c478bd9Sstevel@tonic-gate } 237*7c478bd9Sstevel@tonic-gate #ifdef DEBUG 238*7c478bd9Sstevel@tonic-gate fprintf(stderr, "ypupdated: request received\n"); 239*7c478bd9Sstevel@tonic-gate #endif 240*7c478bd9Sstevel@tonic-gate switch (rqstp->rq_cred.oa_flavor) { 241*7c478bd9Sstevel@tonic-gate case AUTH_DES: 242*7c478bd9Sstevel@tonic-gate netname = ((struct authdes_cred *) 243*7c478bd9Sstevel@tonic-gate rqstp->rq_clntcred)->adc_fullname.name; 244*7c478bd9Sstevel@tonic-gate break; 245*7c478bd9Sstevel@tonic-gate case AUTH_UNIX: 246*7c478bd9Sstevel@tonic-gate if (insecure) { 247*7c478bd9Sstevel@tonic-gate aup = (struct authunix_parms *)rqstp->rq_clntcred; 248*7c478bd9Sstevel@tonic-gate if (aup->aup_uid == 0) { 249*7c478bd9Sstevel@tonic-gate if (addr2netname(namebuf, transp) != 0) { 250*7c478bd9Sstevel@tonic-gate fprintf(stderr, 251*7c478bd9Sstevel@tonic-gate "addr2netname failing for %d\n", 252*7c478bd9Sstevel@tonic-gate aup->aup_uid); 253*7c478bd9Sstevel@tonic-gate svcerr_systemerr(transp); 254*7c478bd9Sstevel@tonic-gate return; 255*7c478bd9Sstevel@tonic-gate } 256*7c478bd9Sstevel@tonic-gate } else { 257*7c478bd9Sstevel@tonic-gate if (user2netname(namebuf, aup->aup_uid, NULL) 258*7c478bd9Sstevel@tonic-gate != 0) { 259*7c478bd9Sstevel@tonic-gate fprintf(stderr, 260*7c478bd9Sstevel@tonic-gate "user2netname failing for %d\n", 261*7c478bd9Sstevel@tonic-gate aup->aup_uid); 262*7c478bd9Sstevel@tonic-gate svcerr_systemerr(transp); 263*7c478bd9Sstevel@tonic-gate return; 264*7c478bd9Sstevel@tonic-gate } 265*7c478bd9Sstevel@tonic-gate } 266*7c478bd9Sstevel@tonic-gate netname = namebuf; 267*7c478bd9Sstevel@tonic-gate break; 268*7c478bd9Sstevel@tonic-gate } 269*7c478bd9Sstevel@tonic-gate default: 270*7c478bd9Sstevel@tonic-gate svcerr_weakauth(transp); 271*7c478bd9Sstevel@tonic-gate return; 272*7c478bd9Sstevel@tonic-gate } 273*7c478bd9Sstevel@tonic-gate memset(&args, 0, sizeof (args)); 274*7c478bd9Sstevel@tonic-gate if (!svc_getargs(transp, xdr_ypupdate_args, (char *)&args)) { 275*7c478bd9Sstevel@tonic-gate svcerr_decode(transp); 276*7c478bd9Sstevel@tonic-gate return; 277*7c478bd9Sstevel@tonic-gate } 278*7c478bd9Sstevel@tonic-gate #ifdef DEBUG 279*7c478bd9Sstevel@tonic-gate fprintf(stderr, "netname = %s\n, map=%s\n key=%s\n", 280*7c478bd9Sstevel@tonic-gate netname, args.mapname, args.key.yp_buf_val); 281*7c478bd9Sstevel@tonic-gate #endif 282*7c478bd9Sstevel@tonic-gate rslt = update(netname, args.mapname, op, 283*7c478bd9Sstevel@tonic-gate args.key.yp_buf_len, args.key.yp_buf_val, 284*7c478bd9Sstevel@tonic-gate args.datum.yp_buf_len, args.datum.yp_buf_val); 285*7c478bd9Sstevel@tonic-gate if (!svc_sendreply(transp, xdr_u_int, (char *)&rslt)) { 286*7c478bd9Sstevel@tonic-gate debug("svc_sendreply failed"); 287*7c478bd9Sstevel@tonic-gate } 288*7c478bd9Sstevel@tonic-gate if (!svc_freeargs(transp, xdr_ypupdate_args, (char *)&args)) { 289*7c478bd9Sstevel@tonic-gate debug("svc_freeargs failed"); 290*7c478bd9Sstevel@tonic-gate } 291*7c478bd9Sstevel@tonic-gate } 292*7c478bd9Sstevel@tonic-gate 293*7c478bd9Sstevel@tonic-gate /* 294*7c478bd9Sstevel@tonic-gate * Determine if requester is allowed to update the given map, 295*7c478bd9Sstevel@tonic-gate * and update it if so. Returns the yp status, which is zero 296*7c478bd9Sstevel@tonic-gate * if there is no access violation. 297*7c478bd9Sstevel@tonic-gate */ 298*7c478bd9Sstevel@tonic-gate static 299*7c478bd9Sstevel@tonic-gate update(requester, mapname, op, keylen, key, datalen, data) 300*7c478bd9Sstevel@tonic-gate char *requester; 301*7c478bd9Sstevel@tonic-gate char *mapname; 302*7c478bd9Sstevel@tonic-gate uint_t op; 303*7c478bd9Sstevel@tonic-gate uint_t keylen; 304*7c478bd9Sstevel@tonic-gate char *key; 305*7c478bd9Sstevel@tonic-gate uint_t datalen; 306*7c478bd9Sstevel@tonic-gate char *data; 307*7c478bd9Sstevel@tonic-gate { 308*7c478bd9Sstevel@tonic-gate char updater[MAXMAPNAMELEN + 40]; 309*7c478bd9Sstevel@tonic-gate FILE *childargs; 310*7c478bd9Sstevel@tonic-gate FILE *childrslt; 311*7c478bd9Sstevel@tonic-gate int status; 312*7c478bd9Sstevel@tonic-gate int yperrno = 0; 313*7c478bd9Sstevel@tonic-gate int pid; 314*7c478bd9Sstevel@tonic-gate 315*7c478bd9Sstevel@tonic-gate sprintf(updater, "/usr/ccs/bin/make -s -f %s %s", UPDATEFILE, mapname); 316*7c478bd9Sstevel@tonic-gate #ifdef DEBUG 317*7c478bd9Sstevel@tonic-gate fprintf(stderr, "updater: %s\n", updater); 318*7c478bd9Sstevel@tonic-gate fprintf(stderr, "requestor = %s, op = %d, key = %s\n", 319*7c478bd9Sstevel@tonic-gate requester, op, key); 320*7c478bd9Sstevel@tonic-gate fprintf(stderr, "data = %s\n", data); 321*7c478bd9Sstevel@tonic-gate #endif 322*7c478bd9Sstevel@tonic-gate pid = _openchild(updater, &childargs, &childrslt); 323*7c478bd9Sstevel@tonic-gate if (pid < 0) { 324*7c478bd9Sstevel@tonic-gate debug("openpipes failed"); 325*7c478bd9Sstevel@tonic-gate return (YPERR_YPERR); 326*7c478bd9Sstevel@tonic-gate } 327*7c478bd9Sstevel@tonic-gate 328*7c478bd9Sstevel@tonic-gate /* 329*7c478bd9Sstevel@tonic-gate * Write to child 330*7c478bd9Sstevel@tonic-gate */ 331*7c478bd9Sstevel@tonic-gate fprintf(childargs, "%s\n", requester); 332*7c478bd9Sstevel@tonic-gate fprintf(childargs, "%u\n", op); 333*7c478bd9Sstevel@tonic-gate fprintf(childargs, "%u\n", keylen); 334*7c478bd9Sstevel@tonic-gate fwrite(key, keylen, 1, childargs); 335*7c478bd9Sstevel@tonic-gate fprintf(childargs, "\n"); 336*7c478bd9Sstevel@tonic-gate fprintf(childargs, "%u\n", datalen); 337*7c478bd9Sstevel@tonic-gate fwrite(data, datalen, 1, childargs); 338*7c478bd9Sstevel@tonic-gate fprintf(childargs, "\n"); 339*7c478bd9Sstevel@tonic-gate fclose(childargs); 340*7c478bd9Sstevel@tonic-gate 341*7c478bd9Sstevel@tonic-gate /* 342*7c478bd9Sstevel@tonic-gate * Read from child 343*7c478bd9Sstevel@tonic-gate */ 344*7c478bd9Sstevel@tonic-gate fscanf(childrslt, "%d", &yperrno); 345*7c478bd9Sstevel@tonic-gate fclose(childrslt); 346*7c478bd9Sstevel@tonic-gate 347*7c478bd9Sstevel@tonic-gate wait(&status); 348*7c478bd9Sstevel@tonic-gate if (!WIFEXITED(status)) { 349*7c478bd9Sstevel@tonic-gate return (YPERR_YPERR); 350*7c478bd9Sstevel@tonic-gate } 351*7c478bd9Sstevel@tonic-gate return (yperrno); 352*7c478bd9Sstevel@tonic-gate } 353*7c478bd9Sstevel@tonic-gate 354*7c478bd9Sstevel@tonic-gate static void 355*7c478bd9Sstevel@tonic-gate msgout(msg) 356*7c478bd9Sstevel@tonic-gate char *msg; 357*7c478bd9Sstevel@tonic-gate { 358*7c478bd9Sstevel@tonic-gate if (_rpcpmstart) 359*7c478bd9Sstevel@tonic-gate syslog(LOG_ERR, msg); 360*7c478bd9Sstevel@tonic-gate else 361*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "%s\n", msg); 362*7c478bd9Sstevel@tonic-gate } 363*7c478bd9Sstevel@tonic-gate 364*7c478bd9Sstevel@tonic-gate void 365*7c478bd9Sstevel@tonic-gate closedown() 366*7c478bd9Sstevel@tonic-gate { 367*7c478bd9Sstevel@tonic-gate if (_rpcsvcdirty == 0) { 368*7c478bd9Sstevel@tonic-gate int i, openfd; 369*7c478bd9Sstevel@tonic-gate struct t_info tinfo; 370*7c478bd9Sstevel@tonic-gate 371*7c478bd9Sstevel@tonic-gate if (t_getinfo(0, tinfo) || (tinfo.servtype == T_CLTS)) 372*7c478bd9Sstevel@tonic-gate exit(0); 373*7c478bd9Sstevel@tonic-gate 374*7c478bd9Sstevel@tonic-gate for (i = 0, openfd = 0; i < svc_max_pollfd && openfd < 2; i++) 375*7c478bd9Sstevel@tonic-gate if (svc_pollfd[i].fd >= 0) 376*7c478bd9Sstevel@tonic-gate openfd++; 377*7c478bd9Sstevel@tonic-gate 378*7c478bd9Sstevel@tonic-gate if (openfd <= 1) 379*7c478bd9Sstevel@tonic-gate exit(0); 380*7c478bd9Sstevel@tonic-gate } 381*7c478bd9Sstevel@tonic-gate (void) alarm(_RPCSVC_CLOSEDOWN); 382*7c478bd9Sstevel@tonic-gate } 383*7c478bd9Sstevel@tonic-gate 384*7c478bd9Sstevel@tonic-gate static int 385*7c478bd9Sstevel@tonic-gate addr2netname(namebuf, transp) 386*7c478bd9Sstevel@tonic-gate char *namebuf; 387*7c478bd9Sstevel@tonic-gate SVCXPRT *transp; 388*7c478bd9Sstevel@tonic-gate { 389*7c478bd9Sstevel@tonic-gate struct nd_hostservlist *hostservs = NULL; 390*7c478bd9Sstevel@tonic-gate struct netconfig *nconf; 391*7c478bd9Sstevel@tonic-gate struct netbuf *who; 392*7c478bd9Sstevel@tonic-gate 393*7c478bd9Sstevel@tonic-gate who = svc_getrpccaller(transp); 394*7c478bd9Sstevel@tonic-gate if ((who == NULL) || (who->len == 0)) 395*7c478bd9Sstevel@tonic-gate return (-1); 396*7c478bd9Sstevel@tonic-gate if ((nconf = getnetconfigent(transp->xp_netid)) 397*7c478bd9Sstevel@tonic-gate == (struct netconfig *)NULL) 398*7c478bd9Sstevel@tonic-gate return (-1); 399*7c478bd9Sstevel@tonic-gate if (netdir_getbyaddr(nconf, &hostservs, who) != 0) { 400*7c478bd9Sstevel@tonic-gate (void) freenetconfigent(nconf); 401*7c478bd9Sstevel@tonic-gate return (-1); 402*7c478bd9Sstevel@tonic-gate } 403*7c478bd9Sstevel@tonic-gate if (hostservs == NULL) { 404*7c478bd9Sstevel@tonic-gate msgout("ypupdated: netdir_getbyaddr failed\n"); 405*7c478bd9Sstevel@tonic-gate } else { 406*7c478bd9Sstevel@tonic-gate strcpy(namebuf, hostservs->h_hostservs->h_host); 407*7c478bd9Sstevel@tonic-gate } 408*7c478bd9Sstevel@tonic-gate (void) freenetconfigent(nconf); 409*7c478bd9Sstevel@tonic-gate netdir_free((char *)hostservs, ND_HOSTSERVLIST); 410*7c478bd9Sstevel@tonic-gate return (0); 411*7c478bd9Sstevel@tonic-gate } 412