yppush_svc.c revision 1.3 1 /* $NetBSD: yppush_svc.c,v 1.3 1997/10/07 14:59:37 lukem 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 <string.h>
50 #include <syslog.h>
51
52 #include <rpc/rpc.h>
53 #include <rpc/xdr.h>
54 #include <rpcsvc/yp_prot.h>
55
56 #include "yppush.h"
57
58 #ifdef __STDC__
59 #define SIG_PF void(*)(int)
60 #endif
61
62 #ifdef DEBUG
63 #define RPC_SVC_FG
64 #endif
65
66 #define _RPCSVC_CLOSEDOWN 120
67 int _rpcpmstart; /* Started by a port monitor ? */
68 int _rpcfdtype; /* Whether Stream or Datagram ? */
69 int _rpcsvcdirty; /* Still serving ? */
70
71 static void _msgout __P((char *));
72
73 static
74 void _msgout(msg)
75 char *msg;
76 {
77 #ifdef RPC_SVC_FG
78 if (_rpcpmstart)
79 syslog(LOG_ERR, msg);
80 else
81 warnx(msg);
82 #else
83 syslog(LOG_ERR, msg);
84 #endif
85 }
86
87 void
88 yppush_xfrrespprog_1(rqstp, transp)
89 struct svc_req *rqstp;
90 SVCXPRT *transp;
91 {
92 union {
93 struct yppushresp_xfr yppushproc_xfrresp_1_arg;
94 } argument;
95 void *result;
96 xdrproc_t xdr_argument, xdr_result;
97 void *(*local) __P((void *, struct svc_req *));
98
99 _rpcsvcdirty = 1;
100 switch (rqstp->rq_proc) {
101 case YPPUSHPROC_NULL:
102 xdr_argument = xdr_void;
103 xdr_result = xdr_void;
104 local = yppushproc_null_1_svc;
105 break;
106
107 case YPPUSHPROC_XFRRESP:
108 xdr_argument = xdr_yppushresp_xfr;
109 xdr_result = xdr_void;
110 local = yppushproc_xfrresp_1_svc;
111 break;
112
113 default:
114 svcerr_noproc(transp);
115 _rpcsvcdirty = 0;
116 exit(1);
117 return;
118 }
119
120 (void) memset((char *)&argument, 0, sizeof (argument));
121 if (!svc_getargs(transp, xdr_argument, (caddr_t) &argument)) {
122 svcerr_decode(transp);
123 _rpcsvcdirty = 0;
124 exit(1);
125 return;
126 }
127
128 result = (*local)(&argument, rqstp);
129 if (result != NULL && !svc_sendreply(transp, xdr_result, result))
130 svcerr_systemerr(transp);
131
132 if (!svc_freeargs(transp, xdr_argument, (caddr_t) &argument)) {
133 _msgout("unable to free arguments");
134 exit(1);
135 }
136 _rpcsvcdirty = 0;
137 if (rqstp->rq_proc != YPPUSHPROC_NULL)
138 exit(0);
139 return;
140 }
141