yppush_svc.c revision 1.7
1/*	$OpenBSD: yppush_svc.c,v 1.7 2002/03/14 16:44:25 mpech 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.7 2002/03/14 16:44:25 mpech 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 <memory.h>
48#include <syslog.h>
49
50#ifdef DEBUG
51#define RPC_SVC_FG
52#endif
53
54#define _RPCSVC_CLOSEDOWN 120
55int _rpcpmstart;		/* Started by a port monitor ? */
56int _rpcfdtype;			/* Whether Stream or Datagram ? */
57int _rpcsvcdirty;		/* Still serving ? */
58
59static
60void _msgout(msg)
61	char *msg;
62{
63#ifdef RPC_SVC_FG
64	if (_rpcpmstart)
65		syslog(LOG_ERR, "%s", msg);
66	else
67		(void) fprintf(stderr, "%s\n", msg);
68#else
69	syslog(LOG_ERR, "%s", msg);
70#endif
71}
72
73void
74yppush_xfrrespprog_1(rqstp, transp)
75	struct svc_req *rqstp;
76	SVCXPRT *transp;
77{
78	union {
79		int fill;
80	} argument;
81	char *result;
82	bool_t (*xdr_argument)(), (*xdr_result)();
83	char *(*local)();
84
85	_rpcsvcdirty = 1;
86	switch (rqstp->rq_proc) {
87	case YPPUSHPROC_NULL:
88		xdr_argument = xdr_void;
89		xdr_result = xdr_void;
90		local = (char *(*)()) yppushproc_null_1_svc;
91		break;
92
93	case YPPUSHPROC_XFRRESP:
94		xdr_argument = xdr_yppushresp_xfr;
95		xdr_result = xdr_void;
96		local = (char *(*)()) yppushproc_xfrresp_1_svc;
97		break;
98
99	default:
100		svcerr_noproc(transp);
101		_rpcsvcdirty = 0;
102		exit(1);
103		return;
104	}
105	(void) memset((char *)&argument, 0, sizeof (argument));
106	if (!svc_getargs(transp, xdr_argument, (caddr_t) &argument)) {
107		svcerr_decode(transp);
108		_rpcsvcdirty = 0;
109		exit(1);
110		return;
111	}
112	result = (*local)(&argument, rqstp);
113	if (result != NULL && !svc_sendreply(transp, xdr_result, result)) {
114		svcerr_systemerr(transp);
115	}
116	if (!svc_freeargs(transp, xdr_argument, (caddr_t) &argument)) {
117		_msgout("unable to free arguments");
118		exit(1);
119	}
120	_rpcsvcdirty = 0;
121	if (rqstp->rq_proc!=YPPUSHPROC_NULL)
122		exit(0);
123	return;
124}
125