yppush_svc.c revision 1.4
1/* $OpenBSD: yppush_svc.c,v 1.4 2000/10/12 09:47:28 deraadt 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#ifndef lint 35static char rcsid[] = "$OpenBSD: yppush_svc.c,v 1.4 2000/10/12 09:47:28 deraadt Exp $"; 36#endif /* not lint */ 37 38#include "yppush.h" 39 40#include <sys/types.h> 41#include <sys/ttycom.h> 42#include <sys/socket.h> 43#include <netinet/in.h> 44#include <stdio.h> 45#include <stdlib.h> 46#include <netdb.h> 47#include <signal.h> 48#include <memory.h> 49#include <syslog.h> 50 51#ifdef __STDC__ 52#define SIG_PF void(*)(int) 53#endif 54 55#ifdef DEBUG 56#define RPC_SVC_FG 57#endif 58 59#define _RPCSVC_CLOSEDOWN 120 60int _rpcpmstart; /* Started by a port monitor ? */ 61int _rpcfdtype; /* Whether Stream or Datagram ? */ 62int _rpcsvcdirty; /* Still serving ? */ 63 64static 65void _msgout(msg) 66 char *msg; 67{ 68#ifdef RPC_SVC_FG 69 if (_rpcpmstart) 70 syslog(LOG_ERR, "%s", msg); 71 else 72 (void) fprintf(stderr, "%s\n", msg); 73#else 74 syslog(LOG_ERR, "%s", msg); 75#endif 76} 77 78void 79yppush_xfrrespprog_1(rqstp, transp) 80 struct svc_req *rqstp; 81 register SVCXPRT *transp; 82{ 83 union { 84 int fill; 85 } argument; 86 char *result; 87 bool_t (*xdr_argument)(), (*xdr_result)(); 88 char *(*local)(); 89 90 _rpcsvcdirty = 1; 91 switch (rqstp->rq_proc) { 92 case YPPUSHPROC_NULL: 93 xdr_argument = xdr_void; 94 xdr_result = xdr_void; 95 local = (char *(*)()) yppushproc_null_1_svc; 96 break; 97 98 case YPPUSHPROC_XFRRESP: 99 xdr_argument = xdr_yppushresp_xfr; 100 xdr_result = xdr_void; 101 local = (char *(*)()) yppushproc_xfrresp_1_svc; 102 break; 103 104 default: 105 svcerr_noproc(transp); 106 _rpcsvcdirty = 0; 107 exit(1); 108 return; 109 } 110 (void) memset((char *)&argument, 0, sizeof (argument)); 111 if (!svc_getargs(transp, xdr_argument, (caddr_t) &argument)) { 112 svcerr_decode(transp); 113 _rpcsvcdirty = 0; 114 exit(1); 115 return; 116 } 117 result = (*local)(&argument, rqstp); 118 if (result != NULL && !svc_sendreply(transp, xdr_result, result)) { 119 svcerr_systemerr(transp); 120 } 121 if (!svc_freeargs(transp, xdr_argument, (caddr_t) &argument)) { 122 _msgout("unable to free arguments"); 123 exit(1); 124 } 125 _rpcsvcdirty = 0; 126 if (rqstp->rq_proc!=YPPUSHPROC_NULL) 127 exit(0); 128 return; 129} 130