xref: /openbsd-src/usr.sbin/amd/rpcx/nfs_prot_svc.c (revision b2ea75c1b17e1a9a339660e7ed45cd24946b230e)
1 /*
2  * Copyright (c) 1989 Jan-Simon Pendry
3  * Copyright (c) 1989 Imperial College of Science, Technology & Medicine
4  * Copyright (c) 1989, 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. All advertising materials mentioning features or use of this software
19  *    must display the following acknowledgement:
20  *	This product includes software developed by the University of
21  *	California, Berkeley and its contributors.
22  * 4. Neither the name of the University nor the names of its contributors
23  *    may be used to endorse or promote products derived from this software
24  *    without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36  * SUCH DAMAGE.
37  *
38  *	from: @(#)nfs_prot_svc.c	8.1 (Berkeley) 6/6/93
39  *	$Id: nfs_prot_svc.c,v 1.1.1.1 1995/10/18 08:47:23 deraadt Exp $
40  *
41  */
42 
43 #include "am.h"
44 
45 void nfs_program_2(rqstp, transp)
46 struct svc_req *rqstp;
47 SVCXPRT *transp;
48 {
49 	union {
50 		nfs_fh nfsproc_getattr_2_arg;
51 		sattrargs nfsproc_setattr_2_arg;
52 		diropargs nfsproc_lookup_2_arg;
53 		nfs_fh nfsproc_readlink_2_arg;
54 		readargs nfsproc_read_2_arg;
55 		writeargs nfsproc_write_2_arg;
56 		createargs nfsproc_create_2_arg;
57 		diropargs nfsproc_remove_2_arg;
58 		renameargs nfsproc_rename_2_arg;
59 		linkargs nfsproc_link_2_arg;
60 		symlinkargs nfsproc_symlink_2_arg;
61 		createargs nfsproc_mkdir_2_arg;
62 		diropargs nfsproc_rmdir_2_arg;
63 		readdirargs nfsproc_readdir_2_arg;
64 		nfs_fh nfsproc_statfs_2_arg;
65 	} argument;
66 	char *result;
67 	bool_t (*xdr_argument)(), (*xdr_result)();
68 	char *(*local)();
69 
70 	switch (rqstp->rq_proc) {
71 	case NFSPROC_NULL:
72 		xdr_argument = xdr_void;
73 		xdr_result = xdr_void;
74 		local = (char *(*)()) nfsproc_null_2;
75 		break;
76 
77 	case NFSPROC_GETATTR:
78 		xdr_argument = xdr_nfs_fh;
79 		xdr_result = xdr_attrstat;
80 		local = (char *(*)()) nfsproc_getattr_2;
81 		break;
82 
83 	case NFSPROC_SETATTR:
84 		xdr_argument = xdr_sattrargs;
85 		xdr_result = xdr_attrstat;
86 		local = (char *(*)()) nfsproc_setattr_2;
87 		break;
88 
89 	case NFSPROC_ROOT:
90 		xdr_argument = xdr_void;
91 		xdr_result = xdr_void;
92 		local = (char *(*)()) nfsproc_root_2;
93 		break;
94 
95 	case NFSPROC_LOOKUP:
96 		xdr_argument = xdr_diropargs;
97 		xdr_result = xdr_diropres;
98 		local = (char *(*)()) nfsproc_lookup_2;
99 		break;
100 
101 	case NFSPROC_READLINK:
102 		xdr_argument = xdr_nfs_fh;
103 		xdr_result = xdr_readlinkres;
104 		local = (char *(*)()) nfsproc_readlink_2;
105 		break;
106 
107 	case NFSPROC_READ:
108 		xdr_argument = xdr_readargs;
109 		xdr_result = xdr_readres;
110 		local = (char *(*)()) nfsproc_read_2;
111 		break;
112 
113 	case NFSPROC_WRITECACHE:
114 		xdr_argument = xdr_void;
115 		xdr_result = xdr_void;
116 		local = (char *(*)()) nfsproc_writecache_2;
117 		break;
118 
119 	case NFSPROC_WRITE:
120 		xdr_argument = xdr_writeargs;
121 		xdr_result = xdr_attrstat;
122 		local = (char *(*)()) nfsproc_write_2;
123 		break;
124 
125 	case NFSPROC_CREATE:
126 		xdr_argument = xdr_createargs;
127 		xdr_result = xdr_diropres;
128 		local = (char *(*)()) nfsproc_create_2;
129 		break;
130 
131 	case NFSPROC_REMOVE:
132 		xdr_argument = xdr_diropargs;
133 		xdr_result = xdr_nfsstat;
134 		local = (char *(*)()) nfsproc_remove_2;
135 		break;
136 
137 	case NFSPROC_RENAME:
138 		xdr_argument = xdr_renameargs;
139 		xdr_result = xdr_nfsstat;
140 		local = (char *(*)()) nfsproc_rename_2;
141 		break;
142 
143 	case NFSPROC_LINK:
144 		xdr_argument = xdr_linkargs;
145 		xdr_result = xdr_nfsstat;
146 		local = (char *(*)()) nfsproc_link_2;
147 		break;
148 
149 	case NFSPROC_SYMLINK:
150 		xdr_argument = xdr_symlinkargs;
151 		xdr_result = xdr_nfsstat;
152 		local = (char *(*)()) nfsproc_symlink_2;
153 		break;
154 
155 	case NFSPROC_MKDIR:
156 		xdr_argument = xdr_createargs;
157 		xdr_result = xdr_diropres;
158 		local = (char *(*)()) nfsproc_mkdir_2;
159 		break;
160 
161 	case NFSPROC_RMDIR:
162 		xdr_argument = xdr_diropargs;
163 		xdr_result = xdr_nfsstat;
164 		local = (char *(*)()) nfsproc_rmdir_2;
165 		break;
166 
167 	case NFSPROC_READDIR:
168 		xdr_argument = xdr_readdirargs;
169 		xdr_result = xdr_readdirres;
170 		local = (char *(*)()) nfsproc_readdir_2;
171 		break;
172 
173 	case NFSPROC_STATFS:
174 		xdr_argument = xdr_nfs_fh;
175 		xdr_result = xdr_statfsres;
176 		local = (char *(*)()) nfsproc_statfs_2;
177 		break;
178 
179 	default:
180 		svcerr_noproc(transp);
181 		return;
182 	}
183 	bzero((char *)&argument, sizeof(argument));
184 	if (!svc_getargs(transp, xdr_argument, (caddr_t) &argument)) {
185 		svcerr_decode(transp);
186 		return;
187 	}
188 	result = (*local)(&argument, rqstp);
189 	if (result != NULL && !svc_sendreply(transp, xdr_result, result)) {
190 		svcerr_systemerr(transp);
191 	}
192 	if (!svc_freeargs(transp, xdr_argument, (caddr_t) &argument)) {
193 		plog(XLOG_FATAL, "unable to free rpc arguments in nfs_program_1");
194 		going_down(1);
195 	}
196 }
197 
198