Home | History | Annotate | Line # | Download | only in yppush
yppush_svc.c revision 1.7
      1 /*	$NetBSD: yppush_svc.c,v 1.7 2003/11/12 13:31:08 grant 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 #include <sys/cdefs.h>
     35 #ifndef lint
     36 __RCSID("$NetBSD: yppush_svc.c,v 1.7 2003/11/12 13:31:08 grant Exp $");
     37 #endif
     38 
     39 /*
     40  * Originally from an rpcgen-generated file, then cleaned up
     41  * by Jason R. Thorpe <thorpej (at) 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 DEBUG
     64 #define RPC_SVC_FG
     65 #endif
     66 
     67 #define _RPCSVC_CLOSEDOWN 120
     68 int _rpcpmstart;		/* Started by a port monitor ? */
     69 int _rpcfdtype;			/* Whether Stream or Datagram ? */
     70 int _rpcsvcdirty;		/* Still serving ? */
     71 
     72 static	void _msgout(char *);
     73 
     74 static
     75 void _msgout(char *msg)
     76 {
     77 #ifdef RPC_SVC_FG
     78 	if (_rpcpmstart)
     79 		syslog(LOG_ERR, "%s", msg);
     80 	else
     81 		warnx("%s", msg);
     82 #else
     83 	syslog(LOG_ERR, "%s", msg);
     84 #endif
     85 }
     86 
     87 void
     88 yppush_xfrrespprog_1(struct svc_req *rqstp, SVCXPRT *transp)
     89 {
     90 	union {
     91 		struct yppushresp_xfr yppushproc_xfrresp_1_arg;
     92 	} argument;
     93 	void *result;
     94 	xdrproc_t xdr_argument, xdr_result;
     95 	void *(*local)(void *, struct svc_req *);
     96 
     97 	_rpcsvcdirty = 1;
     98 	switch (rqstp->rq_proc) {
     99 	case YPPUSHPROC_NULL:
    100 		xdr_argument = xdr_void;
    101 		xdr_result = xdr_void;
    102 		local = yppushproc_null_1_svc;
    103 		break;
    104 
    105 	case YPPUSHPROC_XFRRESP:
    106 		xdr_argument = xdr_yppushresp_xfr;
    107 		xdr_result = xdr_void;
    108 		local = yppushproc_xfrresp_1_svc;
    109 		break;
    110 
    111 	default:
    112 		svcerr_noproc(transp);
    113 		_rpcsvcdirty = 0;
    114 		exit(1);
    115 		return;
    116 	}
    117 
    118 	(void) memset((char *)&argument, 0, sizeof (argument));
    119 	if (!svc_getargs(transp, xdr_argument, (caddr_t) &argument)) {
    120 		svcerr_decode(transp);
    121 		_rpcsvcdirty = 0;
    122 		exit(1);
    123 		return;
    124 	}
    125 
    126 	result = (*local)(&argument, rqstp);
    127 	if (result != NULL && !svc_sendreply(transp, xdr_result, result))
    128 		svcerr_systemerr(transp);
    129 
    130 	if (!svc_freeargs(transp, xdr_argument, (caddr_t) &argument)) {
    131 		_msgout("unable to free arguments");
    132 		exit(1);
    133 	}
    134 	_rpcsvcdirty = 0;
    135 	if (rqstp->rq_proc != YPPUSHPROC_NULL)
    136 		exit(0);
    137 	return;
    138 }
    139