2 * Copyright (c) 1997-2006 Erez Zadok
3 * Copyright (c) 1990 Jan-Simon Pendry
4 * Copyright (c) 1990 Imperial College of Science, Technology & Medicine
5 * Copyright (c) 1990 The Regents of the University of California.
8 * This code is derived from software contributed to Berkeley by
9 * Jan-Simon Pendry at Imperial College, London.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgment:
21 * This product includes software developed by the University of
22 * California, Berkeley and its contributors.
23 * 4. Neither the name of the University nor the names of its contributors
24 * may be used to endorse or promote products derived from this software
25 * without specific prior written permission.
27 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
28 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
31 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
40 * File: am-utils/amd/amq_svc.c
46 #endif /* HAVE_CONFIG_H */
51 typedef char *(*amqsvcproc_t)(voidp, struct svc_req *);
53 #if defined(HAVE_TCPD_H) && defined(HAVE_LIBWRAP)
54 # ifdef NEED_LIBWRAP_SEVERITY_VARIABLES
56 * Some systems that define libwrap already define these two variables
57 * in libwrap, while others don't: so I need to know precisely iff
58 * to define these two severity variables.
60 int allow_severity=0, deny_severity=0;
61 # endif /* NEED_LIBWRAP_SEVERITY_VARIABLES */
64 * check if remote amq is authorized to access this amd.
65 * Returns: 1=allowed, 0=denied.
68 amqsvc_is_client_allowed(const struct sockaddr_in *addr, char *remote)
71 char *name = NULL, **ad;
72 int ret = 0; /* default is 0==denied */
74 /* Check IP address */
75 if (hosts_ctl(AMD_SERVICE_NAME, "", remote, "")) {
80 if (!(h = gethostbyaddr((const char *)&(addr->sin_addr),
81 sizeof(addr->sin_addr),
84 if (!(name = strdup(h->h_name)))
87 if (!(h = gethostbyname(name)))
89 for (ad = h->h_addr_list; *ad; ad++)
90 if (!memcmp(*ad, &(addr->sin_addr), h->h_length))
94 if (hosts_ctl(AMD_SERVICE_NAME, "", h->h_name, "")) {
99 for (ad = h->h_aliases; *ad; ad++)
100 if (hosts_ctl(AMD_SERVICE_NAME, "", *ad, "")) {
110 #endif /* defined(HAVE_TCPD_H) && defined(HAVE_LIBWRAP) */
114 amq_program_1(struct svc_req *rqstp, SVCXPRT *transp)
117 amq_string amqproc_mnttree_1_arg;
118 amq_string amqproc_umnt_1_arg;
119 amq_setopt amqproc_setopt_1_arg;
122 xdrproc_t xdr_argument, xdr_result;
125 #if defined(HAVE_TCPD_H) && defined(HAVE_LIBWRAP)
126 if (gopt.flags & CFM_USE_TCPWRAPPERS) {
127 struct sockaddr_in *remote_addr = svc_getcaller(rqstp->rq_xprt);
128 char *remote_hostname = inet_ntoa(remote_addr->sin_addr);
130 if (!amqsvc_is_client_allowed(remote_addr, remote_hostname)) {
131 plog(XLOG_WARNING, "Amd denied remote amq service to %s", remote_hostname);
132 svcerr_auth(transp, AUTH_FAILED);
135 dlog("Amd allowed remote amq service to %s", remote_hostname);
138 #endif /* defined(HAVE_TCPD_H) && defined(HAVE_LIBWRAP) */
140 switch (rqstp->rq_proc) {
143 xdr_argument = (xdrproc_t) xdr_void;
144 xdr_result = (xdrproc_t) xdr_void;
145 local = (amqsvcproc_t) amqproc_null_1_svc;
148 case AMQPROC_MNTTREE:
149 xdr_argument = (xdrproc_t) xdr_amq_string;
150 xdr_result = (xdrproc_t) xdr_amq_mount_tree_p;
151 local = (amqsvcproc_t) amqproc_mnttree_1_svc;
155 xdr_argument = (xdrproc_t) xdr_amq_string;
156 xdr_result = (xdrproc_t) xdr_void;
157 local = (amqsvcproc_t) amqproc_umnt_1_svc;
161 xdr_argument = (xdrproc_t) xdr_void;
162 xdr_result = (xdrproc_t) xdr_amq_mount_stats;
163 local = (amqsvcproc_t) amqproc_stats_1_svc;
167 xdr_argument = (xdrproc_t) xdr_void;
168 xdr_result = (xdrproc_t) xdr_amq_mount_tree_list;
169 local = (amqsvcproc_t) amqproc_export_1_svc;
173 xdr_argument = (xdrproc_t) xdr_amq_setopt;
174 xdr_result = (xdrproc_t) xdr_int;
175 local = (amqsvcproc_t) amqproc_setopt_1_svc;
178 case AMQPROC_GETMNTFS:
179 xdr_argument = (xdrproc_t) xdr_void;
180 xdr_result = (xdrproc_t) xdr_amq_mount_info_qelem;
181 local = (amqsvcproc_t) amqproc_getmntfs_1_svc;
184 case AMQPROC_GETVERS:
185 xdr_argument = (xdrproc_t) xdr_void;
186 xdr_result = (xdrproc_t) xdr_amq_string;
187 local = (amqsvcproc_t) amqproc_getvers_1_svc;
191 xdr_argument = (xdrproc_t) xdr_void;
192 xdr_result = (xdrproc_t) xdr_int;
193 local = (amqsvcproc_t) amqproc_getpid_1_svc;
197 xdr_argument = (xdrproc_t) xdr_amq_string;
198 xdr_result = (xdrproc_t) xdr_amq_string;
199 local = (amqsvcproc_t) amqproc_pawd_1_svc;
203 svcerr_noproc(transp);
207 memset((char *) &argument, 0, sizeof(argument));
208 if (!svc_getargs(transp,
209 (XDRPROC_T_TYPE) xdr_argument,
210 (SVC_IN_ARG_TYPE) & argument)) {
211 svcerr_decode(transp);
215 result = (*local) (&argument, rqstp);
217 if (result != NULL && !svc_sendreply(transp,
218 (XDRPROC_T_TYPE) xdr_result,
220 svcerr_systemerr(transp);
223 if (!svc_freeargs(transp,
224 (XDRPROC_T_TYPE) xdr_argument,
225 (SVC_IN_ARG_TYPE) & argument)) {
226 plog(XLOG_FATAL, "unable to free rpc arguments in amqprog_1");