Home | History | Annotate | Line # | Download | only in yppush
yppush_svc.c revision 1.1
      1 /*	$NetBSD: yppush_svc.c,v 1.1 1996/08/09 10:15:02 thorpej Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1996 Mats O Jansson <moj (at) 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 /*
     35  * Originally from an rpcgen-generated file, then cleaned up
     36  * by Jason R. Thorpe <thorpej (at) NetBSD.ORG>.
     37  */
     38 
     39 #include <sys/types.h>
     40 #include <sys/socket.h>
     41 
     42 #include <netinet/in.h>
     43 
     44 #include <err.h>
     45 #include <stdio.h>
     46 #include <stdlib.h>
     47 #include <netdb.h>
     48 #include <signal.h>
     49 #include <memory.h>
     50 
     51 #include <rpc/rpc.h>
     52 #include <rpc/xdr.h>
     53 #include <rpcsvc/yp_prot.h>
     54 
     55 #ifdef SYSLOG
     56 #include <syslog.h>
     57 #else
     58 #define LOG_ERR 1
     59 #define openlog(a, b, c)
     60 #endif
     61 
     62 #include "yppush.h"
     63 
     64 #ifdef __STDC__
     65 #define SIG_PF void(*)(int)
     66 #endif
     67 
     68 #ifdef DEBUG
     69 #define RPC_SVC_FG
     70 #endif
     71 
     72 #define _RPCSVC_CLOSEDOWN 120
     73 int _rpcpmstart;		/* Started by a port monitor ? */
     74 int _rpcfdtype;			/* Whether Stream or Datagram ? */
     75 int _rpcsvcdirty;		/* Still serving ? */
     76 
     77 static
     78 void _msgout(msg)
     79 	char *msg;
     80 {
     81 #ifdef RPC_SVC_FG
     82 	if (_rpcpmstart)
     83 		syslog(LOG_ERR, msg);
     84 	else
     85 		warnx(msg);
     86 #else
     87 	syslog(LOG_ERR, msg);
     88 #endif
     89 }
     90 
     91 void
     92 yppush_xfrrespprog_1(rqstp, transp)
     93 	struct svc_req *rqstp;
     94 	register SVCXPRT *transp;
     95 {
     96 	union {
     97 		struct yppushresp_xfr yppushproc_xfrresp_1_arg;
     98 	} argument;
     99 	void *result;
    100 	xdrproc_t xdr_argument, xdr_result;
    101 	void *(*local) __P((void *, struct svc_req *));
    102 
    103 	_rpcsvcdirty = 1;
    104 	switch (rqstp->rq_proc) {
    105 	case YPPUSHPROC_NULL:
    106 		xdr_argument = xdr_void;
    107 		xdr_result = xdr_void;
    108 		local = yppushproc_null_1_svc;
    109 		break;
    110 
    111 	case YPPUSHPROC_XFRRESP:
    112 		xdr_argument = xdr_yppushresp_xfr;
    113 		xdr_result = xdr_void;
    114 		local = yppushproc_xfrresp_1_svc;
    115 		break;
    116 
    117 	default:
    118 		svcerr_noproc(transp);
    119 		_rpcsvcdirty = 0;
    120 		exit(1);
    121 		return;
    122 	}
    123 
    124 	(void) memset((char *)&argument, 0, sizeof (argument));
    125 	if (!svc_getargs(transp, xdr_argument, (caddr_t) &argument)) {
    126 		svcerr_decode(transp);
    127 		_rpcsvcdirty = 0;
    128 		exit(1);
    129 		return;
    130 	}
    131 
    132 	result = (*local)(&argument, rqstp);
    133 	if (result != NULL && !svc_sendreply(transp, xdr_result, result))
    134 		svcerr_systemerr(transp);
    135 
    136 	if (!svc_freeargs(transp, xdr_argument, (caddr_t) &argument)) {
    137 		_msgout("unable to free arguments");
    138 		exit(1);
    139 	}
    140 	_rpcsvcdirty = 0;
    141 	if (rqstp->rq_proc != YPPUSHPROC_NULL)
    142 		exit(0);
    143 	return;
    144 }
    145