1 /* $NetBSD: yppush_svc.c,v 1.10 2011/08/30 17:06:22 plunky 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 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
17 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
28
29 #include <sys/cdefs.h>
30 #ifndef lint
31 __RCSID("$NetBSD: yppush_svc.c,v 1.10 2011/08/30 17:06:22 plunky Exp $");
32 #endif
33
34 /*
35 * Originally from an rpcgen-generated file, then cleaned up
36 * by Jason R. Thorpe <thorpej@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 DEBUG
59 #define RPC_SVC_FG
60 #endif
61
62 #define _RPCSVC_CLOSEDOWN 120
63 int _rpcpmstart; /* Started by a port monitor ? */
64 int _rpcfdtype; /* Whether Stream or Datagram ? */
65 int _rpcsvcdirty; /* Still serving ? */
66
67 static void _msgout(const char *);
68
69 static
_msgout(const char * msg)70 void _msgout(const char *msg)
71 {
72 #ifdef RPC_SVC_FG
73 if (_rpcpmstart)
74 syslog(LOG_ERR, "%s", msg);
75 else
76 warnx("%s", msg);
77 #else
78 syslog(LOG_ERR, "%s", msg);
79 #endif
80 }
81
82 void
yppush_xfrrespprog_1(struct svc_req * rqstp,SVCXPRT * transp)83 yppush_xfrrespprog_1(struct svc_req *rqstp, SVCXPRT *transp)
84 {
85 union {
86 struct yppushresp_xfr yppushproc_xfrresp_1_arg;
87 } argument;
88 void *result;
89 xdrproc_t xdr_argument, xdr_result;
90 void *(*local)(void *, struct svc_req *);
91
92 _rpcsvcdirty = 1;
93 switch (rqstp->rq_proc) {
94 case YPPUSHPROC_NULL:
95 xdr_argument = (xdrproc_t)xdr_void;
96 xdr_result = (xdrproc_t)xdr_void;
97 local = yppushproc_null_1_svc;
98 break;
99
100 case YPPUSHPROC_XFRRESP:
101 xdr_argument = (xdrproc_t)xdr_yppushresp_xfr;
102 xdr_result = (xdrproc_t)xdr_void;
103 local = yppushproc_xfrresp_1_svc;
104 break;
105
106 default:
107 svcerr_noproc(transp);
108 _rpcsvcdirty = 0;
109 exit(1);
110 return;
111 }
112
113 (void) memset((char *)&argument, 0, sizeof (argument));
114 if (!svc_getargs(transp, xdr_argument, (caddr_t) &argument)) {
115 svcerr_decode(transp);
116 _rpcsvcdirty = 0;
117 exit(1);
118 return;
119 }
120
121 result = (*local)(&argument, rqstp);
122 if (result != NULL && !svc_sendreply(transp, xdr_result, result))
123 svcerr_systemerr(transp);
124
125 if (!svc_freeargs(transp, xdr_argument, (caddr_t) &argument)) {
126 _msgout("unable to free arguments");
127 exit(1);
128 }
129 _rpcsvcdirty = 0;
130 if (rqstp->rq_proc != YPPUSHPROC_NULL)
131 exit(0);
132 return;
133 }
134