xref: /openbsd-src/usr.sbin/amd/rpcx/amq_svc.c (revision 91f110e064cd7c194e59e019b83bb7496c1c84d4)
1 /*
2  * Copyright (c) 1990 Jan-Simon Pendry
3  * Copyright (c) 1990 Imperial College of Science, Technology & Medicine
4  * Copyright (c) 1990, 1993
5  *	The Regents of the University of California.  All rights reserved.
6  *
7  * This code is derived from software contributed to Berkeley by
8  * Jan-Simon Pendry at Imperial College, London.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. Neither the name of the University nor the names of its contributors
19  *    may be used to endorse or promote products derived from this software
20  *    without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32  * SUCH DAMAGE.
33  *
34  *	from: @(#)amq_svc.c	8.1 (Berkeley) 6/6/93
35  *	$Id: amq_svc.c,v 1.7 2003/07/18 22:58:56 david Exp $
36  *
37  */
38 
39 #include <sys/types.h>
40 #include <sys/socket.h>
41 #include <netinet/in.h>
42 #include <arpa/inet.h>
43 #include <syslog.h>
44 
45 #include "am.h"
46 #include "amq.h"
47 extern bool_t xdr_amq_mount_info_qelem();
48 
49 void
50 amq_program_1(struct svc_req *rqstp, SVCXPRT *transp)
51 {
52 	union {
53 		amq_string amqproc_mnttree_1_arg;
54 		amq_string amqproc_umnt_1_arg;
55 		amq_setopt amqproc_setopt_1_arg;
56 		amq_string amqproc_mount_1_arg;
57 	} argument;
58 	char *result;
59 	bool_t (*xdr_argument)(), (*xdr_result)();
60 	char *(*local)();
61 	extern SVCXPRT *lamqp;
62 
63 	if (transp != lamqp) {
64 		struct sockaddr_in *fromsin = svc_getcaller(transp);
65 
66 		syslog(LOG_WARNING,
67 		    "non-local amq attempt (might be from %s)",
68 		    inet_ntoa(fromsin->sin_addr));
69 		svcerr_noproc(transp);
70 		return;
71 	}
72 
73 	switch (rqstp->rq_proc) {
74 	case AMQPROC_NULL:
75 		xdr_argument = xdr_void;
76 		xdr_result = xdr_void;
77 		local = (char *(*)()) amqproc_null_1;
78 		break;
79 
80 	case AMQPROC_MNTTREE:
81 		xdr_argument = xdr_amq_string;
82 		xdr_result = xdr_amq_mount_tree_p;
83 		local = (char *(*)()) amqproc_mnttree_1;
84 		break;
85 
86 	case AMQPROC_UMNT:
87 		xdr_argument = xdr_amq_string;
88 		xdr_result = xdr_void;
89 		local = (char *(*)()) amqproc_umnt_1;
90 		break;
91 
92 	case AMQPROC_STATS:
93 		xdr_argument = xdr_void;
94 		xdr_result = xdr_amq_mount_stats;
95 		local = (char *(*)()) amqproc_stats_1;
96 		break;
97 
98 	case AMQPROC_EXPORT:
99 		xdr_argument = xdr_void;
100 		xdr_result = xdr_amq_mount_tree_list;
101 		local = (char *(*)()) amqproc_export_1;
102 		break;
103 
104 	case AMQPROC_SETOPT:
105 		xdr_argument = xdr_amq_setopt;
106 		xdr_result = xdr_int;
107 		local = (char *(*)()) amqproc_setopt_1;
108 		break;
109 
110 	case AMQPROC_GETMNTFS:
111 		xdr_argument = xdr_void;
112 		xdr_result = xdr_amq_mount_info_qelem;
113 		local = (char *(*)()) amqproc_getmntfs_1;
114 		break;
115 
116 	case AMQPROC_MOUNT:
117 		xdr_argument = xdr_amq_string;
118 		xdr_result = xdr_int;
119 		local = (char *(*)()) amqproc_mount_1;
120 		break;
121 
122 	case AMQPROC_GETVERS:
123 		xdr_argument = xdr_void;
124 		xdr_result = xdr_amq_string;
125 		local = (char *(*)()) amqproc_getvers_1;
126 		break;
127 
128 	default:
129 		svcerr_noproc(transp);
130 		return;
131 	}
132 	bzero((char *)&argument, sizeof(argument));
133 	if (!svc_getargs(transp, xdr_argument, (char *)&argument)) {
134 		svcerr_decode(transp);
135 		return;
136 	}
137 	result = (*local)(&argument, rqstp);
138 	if (result != NULL && !svc_sendreply(transp, xdr_result, result)) {
139 		svcerr_systemerr(transp);
140 	}
141 	if (!svc_freeargs(transp, xdr_argument, (char *)&argument)) {
142 		plog(XLOG_FATAL, "unable to free rpc arguments in amqprog_1");
143 		going_down(1);
144 	}
145 }
146