1 /* $NetBSD: yppush_svc.c,v 1.5 1997/11/18 07:01:52 lukem Exp $ */ 2 3 /* 4 * Copyright (c) 1996 Mats O Jansson <moj@stacken.kth.se> 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. All advertising materials mentioning features or use of this software 16 * must display the following acknowledgement: 17 * This product includes software developed by Mats O Jansson 18 * 4. The name of the author may not be used to endorse or promote products 19 * derived from this software without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS 22 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 25 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 */ 33 34 #include <sys/cdefs.h> 35 #ifndef lint 36 __RCSID("$NetBSD: yppush_svc.c,v 1.5 1997/11/18 07:01:52 lukem Exp $"); 37 #endif 38 39 /* 40 * Originally from an rpcgen-generated file, then cleaned up 41 * by Jason R. Thorpe <thorpej@NetBSD.ORG>. 42 */ 43 44 #include <sys/types.h> 45 #include <sys/socket.h> 46 47 #include <netinet/in.h> 48 49 #include <err.h> 50 #include <stdio.h> 51 #include <stdlib.h> 52 #include <netdb.h> 53 #include <signal.h> 54 #include <string.h> 55 #include <syslog.h> 56 57 #include <rpc/rpc.h> 58 #include <rpc/xdr.h> 59 #include <rpcsvc/yp_prot.h> 60 61 #include "yppush.h" 62 63 #ifdef __STDC__ 64 #define SIG_PF void(*)(int) 65 #endif 66 67 #ifdef DEBUG 68 #define RPC_SVC_FG 69 #endif 70 71 #define _RPCSVC_CLOSEDOWN 120 72 int _rpcpmstart; /* Started by a port monitor ? */ 73 int _rpcfdtype; /* Whether Stream or Datagram ? */ 74 int _rpcsvcdirty; /* Still serving ? */ 75 76 static void _msgout __P((char *)); 77 78 static 79 void _msgout(msg) 80 char *msg; 81 { 82 #ifdef RPC_SVC_FG 83 if (_rpcpmstart) 84 syslog(LOG_ERR, "%s", msg); 85 else 86 warnx("%s", msg); 87 #else 88 syslog(LOG_ERR, "%s", msg); 89 #endif 90 } 91 92 void 93 yppush_xfrrespprog_1(rqstp, transp) 94 struct svc_req *rqstp; 95 SVCXPRT *transp; 96 { 97 union { 98 struct yppushresp_xfr yppushproc_xfrresp_1_arg; 99 } argument; 100 void *result; 101 xdrproc_t xdr_argument, xdr_result; 102 void *(*local) __P((void *, struct svc_req *)); 103 104 _rpcsvcdirty = 1; 105 switch (rqstp->rq_proc) { 106 case YPPUSHPROC_NULL: 107 xdr_argument = xdr_void; 108 xdr_result = xdr_void; 109 local = yppushproc_null_1_svc; 110 break; 111 112 case YPPUSHPROC_XFRRESP: 113 xdr_argument = xdr_yppushresp_xfr; 114 xdr_result = xdr_void; 115 local = yppushproc_xfrresp_1_svc; 116 break; 117 118 default: 119 svcerr_noproc(transp); 120 _rpcsvcdirty = 0; 121 exit(1); 122 return; 123 } 124 125 (void) memset((char *)&argument, 0, sizeof (argument)); 126 if (!svc_getargs(transp, xdr_argument, (caddr_t) &argument)) { 127 svcerr_decode(transp); 128 _rpcsvcdirty = 0; 129 exit(1); 130 return; 131 } 132 133 result = (*local)(&argument, rqstp); 134 if (result != NULL && !svc_sendreply(transp, xdr_result, result)) 135 svcerr_systemerr(transp); 136 137 if (!svc_freeargs(transp, xdr_argument, (caddr_t) &argument)) { 138 _msgout("unable to free arguments"); 139 exit(1); 140 } 141 _rpcsvcdirty = 0; 142 if (rqstp->rq_proc != YPPUSHPROC_NULL) 143 exit(0); 144 return; 145 } 146