1 /*
2 * Copyright (c) 1997-2006 Erez Zadok
3 * Copyright (c) 1989 Jan-Simon Pendry
4 * Copyright (c) 1989 Imperial College of Science, Technology & Medicine
5 * Copyright (c) 1989 The Regents of the University of California.
6 * All rights reserved.
7 *
8 * This code is derived from software contributed to Berkeley by
9 * Jan-Simon Pendry at Imperial College, London.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
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.
26 *
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
37 * SUCH DAMAGE.
38 *
39 *
40 * File: am-utils/hlfsd/nfs_prot_svc.c
41 *
42 */
43
44 #ifdef HAVE_CONFIG_H
45 # include <config.h>
46 #endif /* HAVE_CONFIG_H */
47 #include <am_defs.h>
48 #include <hlfsd.h>
49
50 /* EXTERNAL FUNCTIONS */
51 extern voidp nfsproc_null_2_svc(voidp, struct svc_req *);
52 extern nfsattrstat *nfsproc_getattr_2_svc(am_nfs_fh *, struct svc_req *);
53 extern nfsattrstat *nfsproc_setattr_2_svc(nfssattrargs *, struct svc_req *);
54 extern voidp nfsproc_root_2_svc(voidp, struct svc_req *);
55 extern nfsdiropres *nfsproc_lookup_2_svc(nfsdiropargs *, struct svc_req *);
56 extern nfsreadlinkres *nfsproc_readlink_2_svc(am_nfs_fh *, struct svc_req *);
57 extern nfsreadres *nfsproc_read_2_svc(nfsreadargs *, struct svc_req *);
58 extern voidp nfsproc_writecache_2_svc(voidp, struct svc_req *);
59 extern nfsattrstat *nfsproc_write_2_svc(nfswriteargs *, struct svc_req *);
60 extern nfsdiropres *nfsproc_create_2_svc(nfscreateargs *, struct svc_req *);
61 extern nfsstat *nfsproc_remove_2_svc(nfsdiropargs *, struct svc_req *);
62 extern nfsstat *nfsproc_rename_2_svc(nfsrenameargs *, struct svc_req *);
63 extern nfsstat *nfsproc_link_2_svc(nfslinkargs *, struct svc_req *);
64 extern nfsstat *nfsproc_symlink_2_svc(nfssymlinkargs *, struct svc_req *);
65 extern nfsdiropres *nfsproc_mkdir_2_svc(nfscreateargs *, struct svc_req *);
66 extern nfsstat *nfsproc_rmdir_2_svc(nfsdiropargs *, struct svc_req *);
67 extern nfsreaddirres *nfsproc_readdir_2_svc(nfsreaddirargs *, struct svc_req *);
68 extern nfsstatfsres *nfsproc_statfs_2_svc(am_nfs_fh *, struct svc_req *);
69
70 /* GLOBALS */
71 SVCXPRT *nfs_program_2_transp;
72
73 /* TYPEDEFS */
74 typedef char *(*nfssvcproc_t)(voidp, struct svc_req *);
75
76
77 void
nfs_program_2(struct svc_req * rqstp,SVCXPRT * transp)78 nfs_program_2(struct svc_req *rqstp, SVCXPRT *transp)
79 {
80 union {
81 am_nfs_fh nfsproc_getattr_2_arg;
82 nfssattrargs nfsproc_setattr_2_arg;
83 nfsdiropargs nfsproc_lookup_2_arg;
84 am_nfs_fh nfsproc_readlink_2_arg;
85 nfsreadargs nfsproc_read_2_arg;
86 nfswriteargs nfsproc_write_2_arg;
87 nfscreateargs nfsproc_create_2_arg;
88 nfsdiropargs nfsproc_remove_2_arg;
89 nfsrenameargs nfsproc_rename_2_arg;
90 nfslinkargs nfsproc_link_2_arg;
91 nfssymlinkargs nfsproc_symlink_2_arg;
92 nfscreateargs nfsproc_mkdir_2_arg;
93 nfsdiropargs nfsproc_rmdir_2_arg;
94 nfsreaddirargs nfsproc_readdir_2_arg;
95 am_nfs_fh nfsproc_statfs_2_arg;
96 } argument;
97 char *result;
98 xdrproc_t xdr_argument, xdr_result;
99 nfssvcproc_t local;
100
101 nfs_program_2_transp = NULL;
102
103 switch (rqstp->rq_proc) {
104
105 case NFSPROC_NULL:
106 xdr_argument = (xdrproc_t) xdr_void;
107 xdr_result = (xdrproc_t) xdr_void;
108 local = (nfssvcproc_t) nfsproc_null_2_svc;
109 break;
110
111 case NFSPROC_GETATTR:
112 xdr_argument = (xdrproc_t) xdr_nfs_fh;
113 xdr_result = (xdrproc_t) xdr_attrstat;
114 local = (nfssvcproc_t) nfsproc_getattr_2_svc;
115 break;
116
117 case NFSPROC_SETATTR:
118 xdr_argument = (xdrproc_t) xdr_sattrargs;
119 xdr_result = (xdrproc_t) xdr_attrstat;
120 local = (nfssvcproc_t) nfsproc_setattr_2_svc;
121 break;
122
123 case NFSPROC_ROOT:
124 xdr_argument = (xdrproc_t) xdr_void;
125 xdr_result = (xdrproc_t) xdr_void;
126 local = (nfssvcproc_t) nfsproc_root_2_svc;
127 break;
128
129 case NFSPROC_LOOKUP:
130 xdr_argument = (xdrproc_t) xdr_diropargs;
131 xdr_result = (xdrproc_t) xdr_diropres;
132 local = (nfssvcproc_t) nfsproc_lookup_2_svc;
133 /*
134 * Cheap way to pass transp down to afs_lookuppn so it can
135 * be stored in the am_node structure and later used for
136 * quick_reply().
137 */
138 nfs_program_2_transp = transp;
139 break;
140
141 case NFSPROC_READLINK:
142 xdr_argument = (xdrproc_t) xdr_nfs_fh;
143 xdr_result = (xdrproc_t) xdr_readlinkres;
144 local = (nfssvcproc_t) nfsproc_readlink_2_svc;
145 break;
146
147 case NFSPROC_READ:
148 xdr_argument = (xdrproc_t) xdr_readargs;
149 xdr_result = (xdrproc_t) xdr_readres;
150 local = (nfssvcproc_t) nfsproc_read_2_svc;
151 break;
152
153 case NFSPROC_WRITECACHE:
154 xdr_argument = (xdrproc_t) xdr_void;
155 xdr_result = (xdrproc_t) xdr_void;
156 local = (nfssvcproc_t) nfsproc_writecache_2_svc;
157 break;
158
159 case NFSPROC_WRITE:
160 xdr_argument = (xdrproc_t) xdr_writeargs;
161 xdr_result = (xdrproc_t) xdr_attrstat;
162 local = (nfssvcproc_t) nfsproc_write_2_svc;
163 break;
164
165 case NFSPROC_CREATE:
166 xdr_argument = (xdrproc_t) xdr_createargs;
167 xdr_result = (xdrproc_t) xdr_diropres;
168 local = (nfssvcproc_t) nfsproc_create_2_svc;
169 break;
170
171 case NFSPROC_REMOVE:
172 xdr_argument = (xdrproc_t) xdr_diropargs;
173 xdr_result = (xdrproc_t) xdr_nfsstat;
174 local = (nfssvcproc_t) nfsproc_remove_2_svc;
175 break;
176
177 case NFSPROC_RENAME:
178 xdr_argument = (xdrproc_t) xdr_renameargs;
179 xdr_result = (xdrproc_t) xdr_nfsstat;
180 local = (nfssvcproc_t) nfsproc_rename_2_svc;
181 break;
182
183 case NFSPROC_LINK:
184 xdr_argument = (xdrproc_t) xdr_linkargs;
185 xdr_result = (xdrproc_t) xdr_nfsstat;
186 local = (nfssvcproc_t) nfsproc_link_2_svc;
187 break;
188
189 case NFSPROC_SYMLINK:
190 xdr_argument = (xdrproc_t) xdr_symlinkargs;
191 xdr_result = (xdrproc_t) xdr_nfsstat;
192 local = (nfssvcproc_t) nfsproc_symlink_2_svc;
193 break;
194
195 case NFSPROC_MKDIR:
196 xdr_argument = (xdrproc_t) xdr_createargs;
197 xdr_result = (xdrproc_t) xdr_diropres;
198 local = (nfssvcproc_t) nfsproc_mkdir_2_svc;
199 break;
200
201 case NFSPROC_RMDIR:
202 xdr_argument = (xdrproc_t) xdr_diropargs;
203 xdr_result = (xdrproc_t) xdr_nfsstat;
204 local = (nfssvcproc_t) nfsproc_rmdir_2_svc;
205 break;
206
207 case NFSPROC_READDIR:
208 xdr_argument = (xdrproc_t) xdr_readdirargs;
209 xdr_result = (xdrproc_t) xdr_readdirres;
210 local = (nfssvcproc_t) nfsproc_readdir_2_svc;
211 break;
212
213 case NFSPROC_STATFS:
214 xdr_argument = (xdrproc_t) xdr_nfs_fh;
215 xdr_result = (xdrproc_t) xdr_statfsres;
216 local = (nfssvcproc_t) nfsproc_statfs_2_svc;
217 break;
218
219 default:
220 svcerr_noproc(transp);
221 return;
222 }
223
224 memset((char *) &argument, 0, sizeof(argument));
225 if (!svc_getargs(transp,
226 (XDRPROC_T_TYPE) xdr_argument,
227 (SVC_IN_ARG_TYPE) &argument)) {
228 plog(XLOG_ERROR,
229 "NFS xdr decode failed for %d %d %d",
230 (int) rqstp->rq_prog, (int) rqstp->rq_vers, (int) rqstp->rq_proc);
231 svcerr_decode(transp);
232 return;
233 }
234 result = (*local) (&argument, rqstp);
235
236 nfs_program_2_transp = NULL;
237
238 if (result != NULL && !svc_sendreply(transp,
239 (XDRPROC_T_TYPE) xdr_result,
240 result)) {
241 svcerr_systemerr(transp);
242 }
243 if (!svc_freeargs(transp,
244 (XDRPROC_T_TYPE) xdr_argument,
245 (SVC_IN_ARG_TYPE) & argument)) {
246 plog(XLOG_FATAL, "unable to free rpc arguments in nfs_program_2");
247 going_down(1);
248 }
249 }
250