1 /* $OpenBSD: yppush_svc.c,v 1.15 2015/11/17 18:21:48 tedu 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/types.h>
30 #include <sys/socket.h>
31 #include <netinet/in.h>
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <netdb.h>
35 #include <string.h>
36 #include <syslog.h>
37 #include <rpcsvc/yp.h>
38
39 #include "yppush.h"
40
41 #ifdef DEBUG
42 #define RPC_SVC_FG
43 #endif
44
45 #define _RPCSVC_CLOSEDOWN 120
46 int _rpcpmstart; /* Started by a port monitor ? */
47 int _rpcfdtype; /* Whether Stream or Datagram ? */
48 int _rpcsvcdirty; /* Still serving ? */
49
50 static
_msgout(char * msg)51 void _msgout(char *msg)
52 {
53 #ifdef RPC_SVC_FG
54 if (_rpcpmstart)
55 syslog(LOG_ERR, "%s", msg);
56 else
57 (void) fprintf(stderr, "%s\n", msg);
58 #else
59 syslog(LOG_ERR, "%s", msg);
60 #endif
61 }
62
63 void
yppush_xfrrespprog_1(struct svc_req * rqstp,SVCXPRT * transp)64 yppush_xfrrespprog_1(struct svc_req *rqstp, SVCXPRT *transp)
65 {
66 union argument {
67 int fill;
68 } argument;
69 char *result;
70 xdrproc_t xdr_argument, xdr_result;
71 char *(*local)(union argument *, struct svc_req *);
72
73 _rpcsvcdirty = 1;
74 switch (rqstp->rq_proc) {
75 case YPPUSHPROC_NULL:
76 xdr_argument = xdr_void;
77 xdr_result = xdr_void;
78 local = (char *(*)(union argument *, struct svc_req *))
79 yppushproc_null_1_svc;
80 break;
81
82 case YPPUSHPROC_XFRRESP:
83 xdr_argument = xdr_yppushresp_xfr;
84 xdr_result = xdr_void;
85 local = (char *(*)(union argument *, struct svc_req *))
86 yppushproc_xfrresp_1_svc;
87 break;
88
89 default:
90 svcerr_noproc(transp);
91 _rpcsvcdirty = 0;
92 exit(1);
93 return;
94 }
95 (void) memset(&argument, 0, sizeof(argument));
96 if (!svc_getargs(transp, xdr_argument, (caddr_t)&argument)) {
97 svcerr_decode(transp);
98 _rpcsvcdirty = 0;
99 exit(1);
100 return;
101 }
102 result = (*local)(&argument, rqstp);
103 if (result != NULL && !svc_sendreply(transp, xdr_result, result)) {
104 svcerr_systemerr(transp);
105 }
106 if (!svc_freeargs(transp, xdr_argument, (caddr_t)&argument)) {
107 _msgout("unable to free arguments");
108 exit(1);
109 }
110 _rpcsvcdirty = 0;
111 if (rqstp->rq_proc!=YPPUSHPROC_NULL)
112 exit(0);
113 }
114