nfs_nfsdsubs.c revision 1.3 1 1.3 pgoyette /* $NetBSD: nfs_nfsdsubs.c,v 1.3 2016/11/18 08:31:30 pgoyette Exp $ */
2 1.1 dholland /*-
3 1.1 dholland * Copyright (c) 1989, 1993
4 1.1 dholland * The Regents of the University of California. All rights reserved.
5 1.1 dholland *
6 1.1 dholland * This code is derived from software contributed to Berkeley by
7 1.1 dholland * Rick Macklem at The University of Guelph.
8 1.1 dholland *
9 1.1 dholland * Redistribution and use in source and binary forms, with or without
10 1.1 dholland * modification, are permitted provided that the following conditions
11 1.1 dholland * are met:
12 1.1 dholland * 1. Redistributions of source code must retain the above copyright
13 1.1 dholland * notice, this list of conditions and the following disclaimer.
14 1.1 dholland * 2. Redistributions in binary form must reproduce the above copyright
15 1.1 dholland * notice, this list of conditions and the following disclaimer in the
16 1.1 dholland * documentation and/or other materials provided with the distribution.
17 1.1 dholland * 4. Neither the name of the University nor the names of its contributors
18 1.1 dholland * may be used to endorse or promote products derived from this software
19 1.1 dholland * without specific prior written permission.
20 1.1 dholland *
21 1.1 dholland * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 1.1 dholland * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 1.1 dholland * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 1.1 dholland * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 1.1 dholland * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 1.1 dholland * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 1.1 dholland * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 1.1 dholland * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 1.1 dholland * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 1.1 dholland * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 1.1 dholland * SUCH DAMAGE.
32 1.1 dholland *
33 1.1 dholland */
34 1.1 dholland
35 1.1 dholland #include <sys/cdefs.h>
36 1.3 pgoyette /* __FBSDID("FreeBSD: head/sys/fs/nfsserver/nfs_nfsdsubs.c 298523 2016-04-23 21:18:45Z rmacklem "); */
37 1.3 pgoyette __RCSID("$NetBSD: nfs_nfsdsubs.c,v 1.3 2016/11/18 08:31:30 pgoyette Exp $");
38 1.1 dholland
39 1.1 dholland #ifndef APPLEKEXT
40 1.1 dholland /*
41 1.1 dholland * These functions support the macros and help fiddle mbuf chains for
42 1.1 dholland * the nfs op functions. They do things like create the rpc header and
43 1.1 dholland * copy data between mbuf chains and uio lists.
44 1.1 dholland */
45 1.1 dholland #include <fs/nfs/nfsport.h>
46 1.1 dholland
47 1.1 dholland extern u_int32_t newnfs_true, newnfs_false;
48 1.1 dholland extern int nfs_pubfhset;
49 1.3 pgoyette extern struct nfsclienthashhead *nfsclienthash;
50 1.3 pgoyette extern int nfsrv_clienthashsize;
51 1.3 pgoyette extern struct nfslockhashhead *nfslockhash;
52 1.3 pgoyette extern int nfsrv_lockhashsize;
53 1.3 pgoyette extern struct nfssessionhash *nfssessionhash;
54 1.3 pgoyette extern int nfsrv_sessionhashsize;
55 1.1 dholland extern int nfsrv_useacl;
56 1.1 dholland extern uid_t nfsrv_defaultuid;
57 1.1 dholland extern gid_t nfsrv_defaultgid;
58 1.1 dholland
59 1.1 dholland char nfs_v2pubfh[NFSX_V2FH];
60 1.1 dholland static nfstype newnfsv2_type[9] = { NFNON, NFREG, NFDIR, NFBLK, NFCHR, NFLNK,
61 1.1 dholland NFNON, NFCHR, NFNON };
62 1.1 dholland extern nfstype nfsv34_type[9];
63 1.1 dholland #endif /* !APPLEKEXT */
64 1.1 dholland
65 1.3 pgoyette static u_int32_t nfsrv_isannfserr(u_int32_t);
66 1.3 pgoyette
67 1.1 dholland SYSCTL_DECL(_vfs_nfsd);
68 1.1 dholland
69 1.3 pgoyette static int enable_checkutf8 = 1;
70 1.3 pgoyette SYSCTL_INT(_vfs_nfsd, OID_AUTO, enable_checkutf8, CTLFLAG_RW,
71 1.3 pgoyette &enable_checkutf8, 0,
72 1.3 pgoyette "Enable the NFSv4 check for the UTF8 compliant name required by rfc3530");
73 1.3 pgoyette
74 1.3 pgoyette static int enable_nobodycheck = 1;
75 1.3 pgoyette SYSCTL_INT(_vfs_nfsd, OID_AUTO, enable_nobodycheck, CTLFLAG_RW,
76 1.3 pgoyette &enable_nobodycheck, 0,
77 1.3 pgoyette "Enable the NFSv4 check when setting user nobody as owner");
78 1.3 pgoyette
79 1.3 pgoyette static int enable_nogroupcheck = 1;
80 1.3 pgoyette SYSCTL_INT(_vfs_nfsd, OID_AUTO, enable_nogroupcheck, CTLFLAG_RW,
81 1.3 pgoyette &enable_nogroupcheck, 0,
82 1.3 pgoyette "Enable the NFSv4 check when setting group nogroup as owner");
83 1.1 dholland
84 1.1 dholland static char nfsrv_hexdigit(char, int *);
85 1.1 dholland
86 1.1 dholland /*
87 1.1 dholland * Maps errno values to nfs error numbers.
88 1.1 dholland * Use NFSERR_IO as the catch all for ones not specifically defined in
89 1.3 pgoyette * RFC 1094. (It now includes the errors added for NFSv3.)
90 1.1 dholland */
91 1.3 pgoyette static u_char nfsrv_v2errmap[NFSERR_REMOTE] = {
92 1.1 dholland NFSERR_PERM, NFSERR_NOENT, NFSERR_IO, NFSERR_IO, NFSERR_IO,
93 1.1 dholland NFSERR_NXIO, NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO,
94 1.1 dholland NFSERR_IO, NFSERR_IO, NFSERR_ACCES, NFSERR_IO, NFSERR_IO,
95 1.3 pgoyette NFSERR_IO, NFSERR_EXIST, NFSERR_XDEV, NFSERR_NODEV, NFSERR_NOTDIR,
96 1.3 pgoyette NFSERR_ISDIR, NFSERR_INVAL, NFSERR_IO, NFSERR_IO, NFSERR_IO,
97 1.1 dholland NFSERR_IO, NFSERR_FBIG, NFSERR_NOSPC, NFSERR_IO, NFSERR_ROFS,
98 1.3 pgoyette NFSERR_MLINK, NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO,
99 1.1 dholland NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO,
100 1.1 dholland NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO,
101 1.1 dholland NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO,
102 1.1 dholland NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO,
103 1.1 dholland NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO,
104 1.1 dholland NFSERR_IO, NFSERR_IO, NFSERR_NAMETOL, NFSERR_IO, NFSERR_IO,
105 1.1 dholland NFSERR_NOTEMPTY, NFSERR_IO, NFSERR_IO, NFSERR_DQUOT, NFSERR_STALE,
106 1.3 pgoyette NFSERR_REMOTE,
107 1.1 dholland };
108 1.1 dholland
109 1.1 dholland /*
110 1.1 dholland * Maps errno values to nfs error numbers.
111 1.1 dholland * Although it is not obvious whether or not NFS clients really care if
112 1.1 dholland * a returned error value is in the specified list for the procedure, the
113 1.1 dholland * safest thing to do is filter them appropriately. For Version 2, the
114 1.1 dholland * X/Open XNFS document is the only specification that defines error values
115 1.1 dholland * for each RPC (The RFC simply lists all possible error values for all RPCs),
116 1.1 dholland * so I have decided to not do this for Version 2.
117 1.1 dholland * The first entry is the default error return and the rest are the valid
118 1.1 dholland * errors for that RPC in increasing numeric order.
119 1.1 dholland */
120 1.1 dholland static short nfsv3err_null[] = {
121 1.1 dholland 0,
122 1.1 dholland 0,
123 1.1 dholland };
124 1.1 dholland
125 1.1 dholland static short nfsv3err_getattr[] = {
126 1.1 dholland NFSERR_IO,
127 1.1 dholland NFSERR_IO,
128 1.1 dholland NFSERR_STALE,
129 1.1 dholland NFSERR_BADHANDLE,
130 1.1 dholland NFSERR_SERVERFAULT,
131 1.1 dholland NFSERR_DELAY,
132 1.1 dholland 0,
133 1.1 dholland };
134 1.1 dholland
135 1.1 dholland static short nfsv3err_setattr[] = {
136 1.1 dholland NFSERR_IO,
137 1.1 dholland NFSERR_ACCES,
138 1.1 dholland NFSERR_PERM,
139 1.1 dholland NFSERR_IO,
140 1.1 dholland NFSERR_INVAL,
141 1.1 dholland NFSERR_NOSPC,
142 1.1 dholland NFSERR_ROFS,
143 1.1 dholland NFSERR_DQUOT,
144 1.1 dholland NFSERR_STALE,
145 1.1 dholland NFSERR_BADHANDLE,
146 1.1 dholland NFSERR_NOT_SYNC,
147 1.1 dholland NFSERR_SERVERFAULT,
148 1.1 dholland NFSERR_DELAY,
149 1.1 dholland 0,
150 1.1 dholland };
151 1.1 dholland
152 1.1 dholland static short nfsv3err_lookup[] = {
153 1.1 dholland NFSERR_IO,
154 1.1 dholland NFSERR_NOENT,
155 1.1 dholland NFSERR_ACCES,
156 1.1 dholland NFSERR_NAMETOL,
157 1.1 dholland NFSERR_IO,
158 1.1 dholland NFSERR_NOTDIR,
159 1.1 dholland NFSERR_STALE,
160 1.1 dholland NFSERR_BADHANDLE,
161 1.1 dholland NFSERR_SERVERFAULT,
162 1.1 dholland NFSERR_DELAY,
163 1.1 dholland 0,
164 1.1 dholland };
165 1.1 dholland
166 1.1 dholland static short nfsv3err_access[] = {
167 1.1 dholland NFSERR_IO,
168 1.1 dholland NFSERR_IO,
169 1.1 dholland NFSERR_STALE,
170 1.1 dholland NFSERR_BADHANDLE,
171 1.1 dholland NFSERR_SERVERFAULT,
172 1.1 dholland NFSERR_DELAY,
173 1.1 dholland 0,
174 1.1 dholland };
175 1.1 dholland
176 1.1 dholland static short nfsv3err_readlink[] = {
177 1.1 dholland NFSERR_IO,
178 1.1 dholland NFSERR_IO,
179 1.1 dholland NFSERR_ACCES,
180 1.1 dholland NFSERR_INVAL,
181 1.1 dholland NFSERR_STALE,
182 1.1 dholland NFSERR_BADHANDLE,
183 1.1 dholland NFSERR_NOTSUPP,
184 1.1 dholland NFSERR_SERVERFAULT,
185 1.1 dholland NFSERR_DELAY,
186 1.1 dholland 0,
187 1.1 dholland };
188 1.1 dholland
189 1.1 dholland static short nfsv3err_read[] = {
190 1.1 dholland NFSERR_IO,
191 1.1 dholland NFSERR_IO,
192 1.1 dholland NFSERR_NXIO,
193 1.1 dholland NFSERR_ACCES,
194 1.1 dholland NFSERR_INVAL,
195 1.1 dholland NFSERR_STALE,
196 1.1 dholland NFSERR_BADHANDLE,
197 1.1 dholland NFSERR_SERVERFAULT,
198 1.1 dholland NFSERR_DELAY,
199 1.1 dholland 0,
200 1.1 dholland };
201 1.1 dholland
202 1.1 dholland static short nfsv3err_write[] = {
203 1.1 dholland NFSERR_IO,
204 1.1 dholland NFSERR_IO,
205 1.1 dholland NFSERR_ACCES,
206 1.1 dholland NFSERR_NOSPC,
207 1.1 dholland NFSERR_INVAL,
208 1.1 dholland NFSERR_FBIG,
209 1.1 dholland NFSERR_ROFS,
210 1.1 dholland NFSERR_DQUOT,
211 1.1 dholland NFSERR_STALE,
212 1.1 dholland NFSERR_BADHANDLE,
213 1.1 dholland NFSERR_SERVERFAULT,
214 1.1 dholland NFSERR_DELAY,
215 1.1 dholland 0,
216 1.1 dholland };
217 1.1 dholland
218 1.1 dholland static short nfsv3err_create[] = {
219 1.1 dholland NFSERR_IO,
220 1.1 dholland NFSERR_EXIST,
221 1.1 dholland NFSERR_NAMETOL,
222 1.1 dholland NFSERR_ACCES,
223 1.1 dholland NFSERR_IO,
224 1.1 dholland NFSERR_NOTDIR,
225 1.1 dholland NFSERR_NOSPC,
226 1.1 dholland NFSERR_ROFS,
227 1.1 dholland NFSERR_DQUOT,
228 1.1 dholland NFSERR_STALE,
229 1.1 dholland NFSERR_BADHANDLE,
230 1.1 dholland NFSERR_NOTSUPP,
231 1.1 dholland NFSERR_SERVERFAULT,
232 1.1 dholland NFSERR_DELAY,
233 1.1 dholland 0,
234 1.1 dholland };
235 1.1 dholland
236 1.1 dholland static short nfsv3err_mkdir[] = {
237 1.1 dholland NFSERR_IO,
238 1.1 dholland NFSERR_EXIST,
239 1.1 dholland NFSERR_ACCES,
240 1.1 dholland NFSERR_NAMETOL,
241 1.1 dholland NFSERR_IO,
242 1.1 dholland NFSERR_NOTDIR,
243 1.1 dholland NFSERR_NOSPC,
244 1.1 dholland NFSERR_ROFS,
245 1.1 dholland NFSERR_DQUOT,
246 1.1 dholland NFSERR_STALE,
247 1.1 dholland NFSERR_BADHANDLE,
248 1.1 dholland NFSERR_NOTSUPP,
249 1.1 dholland NFSERR_SERVERFAULT,
250 1.1 dholland NFSERR_DELAY,
251 1.1 dholland 0,
252 1.1 dholland };
253 1.1 dholland
254 1.1 dholland static short nfsv3err_symlink[] = {
255 1.1 dholland NFSERR_IO,
256 1.1 dholland NFSERR_ACCES,
257 1.1 dholland NFSERR_EXIST,
258 1.1 dholland NFSERR_NAMETOL,
259 1.1 dholland NFSERR_NOSPC,
260 1.1 dholland NFSERR_IO,
261 1.1 dholland NFSERR_NOTDIR,
262 1.1 dholland NFSERR_ROFS,
263 1.1 dholland NFSERR_DQUOT,
264 1.1 dholland NFSERR_STALE,
265 1.1 dholland NFSERR_BADHANDLE,
266 1.1 dholland NFSERR_NOTSUPP,
267 1.1 dholland NFSERR_SERVERFAULT,
268 1.1 dholland NFSERR_DELAY,
269 1.1 dholland 0,
270 1.1 dholland };
271 1.1 dholland
272 1.1 dholland static short nfsv3err_mknod[] = {
273 1.1 dholland NFSERR_IO,
274 1.1 dholland NFSERR_ACCES,
275 1.1 dholland NFSERR_EXIST,
276 1.1 dholland NFSERR_NAMETOL,
277 1.1 dholland NFSERR_NOSPC,
278 1.1 dholland NFSERR_IO,
279 1.1 dholland NFSERR_NOTDIR,
280 1.1 dholland NFSERR_ROFS,
281 1.1 dholland NFSERR_DQUOT,
282 1.1 dholland NFSERR_STALE,
283 1.1 dholland NFSERR_BADHANDLE,
284 1.1 dholland NFSERR_NOTSUPP,
285 1.1 dholland NFSERR_SERVERFAULT,
286 1.1 dholland NFSERR_DELAY,
287 1.1 dholland NFSERR_BADTYPE,
288 1.1 dholland 0,
289 1.1 dholland };
290 1.1 dholland
291 1.1 dholland static short nfsv3err_remove[] = {
292 1.1 dholland NFSERR_IO,
293 1.1 dholland NFSERR_NOENT,
294 1.1 dholland NFSERR_ACCES,
295 1.1 dholland NFSERR_NAMETOL,
296 1.1 dholland NFSERR_IO,
297 1.1 dholland NFSERR_NOTDIR,
298 1.1 dholland NFSERR_ROFS,
299 1.1 dholland NFSERR_STALE,
300 1.1 dholland NFSERR_BADHANDLE,
301 1.1 dholland NFSERR_SERVERFAULT,
302 1.1 dholland NFSERR_DELAY,
303 1.1 dholland 0,
304 1.1 dholland };
305 1.1 dholland
306 1.1 dholland static short nfsv3err_rmdir[] = {
307 1.1 dholland NFSERR_IO,
308 1.1 dholland NFSERR_NOENT,
309 1.1 dholland NFSERR_ACCES,
310 1.1 dholland NFSERR_NOTDIR,
311 1.1 dholland NFSERR_NAMETOL,
312 1.1 dholland NFSERR_IO,
313 1.1 dholland NFSERR_EXIST,
314 1.1 dholland NFSERR_INVAL,
315 1.1 dholland NFSERR_ROFS,
316 1.1 dholland NFSERR_NOTEMPTY,
317 1.1 dholland NFSERR_STALE,
318 1.1 dholland NFSERR_BADHANDLE,
319 1.1 dholland NFSERR_NOTSUPP,
320 1.1 dholland NFSERR_SERVERFAULT,
321 1.1 dholland NFSERR_DELAY,
322 1.1 dholland 0,
323 1.1 dholland };
324 1.1 dholland
325 1.1 dholland static short nfsv3err_rename[] = {
326 1.1 dholland NFSERR_IO,
327 1.1 dholland NFSERR_NOENT,
328 1.1 dholland NFSERR_ACCES,
329 1.1 dholland NFSERR_EXIST,
330 1.1 dholland NFSERR_NAMETOL,
331 1.1 dholland NFSERR_XDEV,
332 1.1 dholland NFSERR_IO,
333 1.1 dholland NFSERR_NOTDIR,
334 1.1 dholland NFSERR_ISDIR,
335 1.1 dholland NFSERR_INVAL,
336 1.1 dholland NFSERR_NOSPC,
337 1.1 dholland NFSERR_ROFS,
338 1.1 dholland NFSERR_MLINK,
339 1.1 dholland NFSERR_NOTEMPTY,
340 1.1 dholland NFSERR_DQUOT,
341 1.1 dholland NFSERR_STALE,
342 1.1 dholland NFSERR_BADHANDLE,
343 1.1 dholland NFSERR_NOTSUPP,
344 1.1 dholland NFSERR_SERVERFAULT,
345 1.1 dholland NFSERR_DELAY,
346 1.1 dholland 0,
347 1.1 dholland };
348 1.1 dholland
349 1.1 dholland static short nfsv3err_link[] = {
350 1.1 dholland NFSERR_IO,
351 1.1 dholland NFSERR_ACCES,
352 1.1 dholland NFSERR_EXIST,
353 1.1 dholland NFSERR_NAMETOL,
354 1.1 dholland NFSERR_IO,
355 1.1 dholland NFSERR_XDEV,
356 1.1 dholland NFSERR_NOTDIR,
357 1.1 dholland NFSERR_INVAL,
358 1.1 dholland NFSERR_NOSPC,
359 1.1 dholland NFSERR_ROFS,
360 1.1 dholland NFSERR_MLINK,
361 1.1 dholland NFSERR_DQUOT,
362 1.1 dholland NFSERR_STALE,
363 1.1 dholland NFSERR_BADHANDLE,
364 1.1 dholland NFSERR_NOTSUPP,
365 1.1 dholland NFSERR_SERVERFAULT,
366 1.1 dholland NFSERR_DELAY,
367 1.1 dholland 0,
368 1.1 dholland };
369 1.1 dholland
370 1.1 dholland static short nfsv3err_readdir[] = {
371 1.1 dholland NFSERR_IO,
372 1.1 dholland NFSERR_ACCES,
373 1.1 dholland NFSERR_NOTDIR,
374 1.1 dholland NFSERR_IO,
375 1.1 dholland NFSERR_STALE,
376 1.1 dholland NFSERR_BADHANDLE,
377 1.1 dholland NFSERR_BAD_COOKIE,
378 1.1 dholland NFSERR_TOOSMALL,
379 1.1 dholland NFSERR_SERVERFAULT,
380 1.1 dholland NFSERR_DELAY,
381 1.1 dholland 0,
382 1.1 dholland };
383 1.1 dholland
384 1.1 dholland static short nfsv3err_readdirplus[] = {
385 1.1 dholland NFSERR_IO,
386 1.1 dholland NFSERR_ACCES,
387 1.1 dholland NFSERR_NOTDIR,
388 1.1 dholland NFSERR_IO,
389 1.1 dholland NFSERR_STALE,
390 1.1 dholland NFSERR_BADHANDLE,
391 1.1 dholland NFSERR_BAD_COOKIE,
392 1.1 dholland NFSERR_NOTSUPP,
393 1.1 dholland NFSERR_TOOSMALL,
394 1.1 dholland NFSERR_SERVERFAULT,
395 1.1 dholland NFSERR_DELAY,
396 1.1 dholland 0,
397 1.1 dholland };
398 1.1 dholland
399 1.1 dholland static short nfsv3err_fsstat[] = {
400 1.1 dholland NFSERR_IO,
401 1.1 dholland NFSERR_IO,
402 1.1 dholland NFSERR_STALE,
403 1.1 dholland NFSERR_BADHANDLE,
404 1.1 dholland NFSERR_SERVERFAULT,
405 1.1 dholland NFSERR_DELAY,
406 1.1 dholland 0,
407 1.1 dholland };
408 1.1 dholland
409 1.1 dholland static short nfsv3err_fsinfo[] = {
410 1.1 dholland NFSERR_STALE,
411 1.1 dholland NFSERR_STALE,
412 1.1 dholland NFSERR_BADHANDLE,
413 1.1 dholland NFSERR_SERVERFAULT,
414 1.1 dholland NFSERR_DELAY,
415 1.1 dholland 0,
416 1.1 dholland };
417 1.1 dholland
418 1.1 dholland static short nfsv3err_pathconf[] = {
419 1.1 dholland NFSERR_STALE,
420 1.1 dholland NFSERR_STALE,
421 1.1 dholland NFSERR_BADHANDLE,
422 1.1 dholland NFSERR_SERVERFAULT,
423 1.1 dholland NFSERR_DELAY,
424 1.1 dholland 0,
425 1.1 dholland };
426 1.1 dholland
427 1.1 dholland static short nfsv3err_commit[] = {
428 1.1 dholland NFSERR_IO,
429 1.1 dholland NFSERR_IO,
430 1.1 dholland NFSERR_STALE,
431 1.1 dholland NFSERR_BADHANDLE,
432 1.1 dholland NFSERR_SERVERFAULT,
433 1.1 dholland NFSERR_DELAY,
434 1.1 dholland 0,
435 1.1 dholland };
436 1.1 dholland
437 1.1 dholland static short *nfsrv_v3errmap[] = {
438 1.1 dholland nfsv3err_null,
439 1.1 dholland nfsv3err_getattr,
440 1.1 dholland nfsv3err_setattr,
441 1.1 dholland nfsv3err_lookup,
442 1.1 dholland nfsv3err_access,
443 1.1 dholland nfsv3err_readlink,
444 1.1 dholland nfsv3err_read,
445 1.1 dholland nfsv3err_write,
446 1.1 dholland nfsv3err_create,
447 1.1 dholland nfsv3err_mkdir,
448 1.1 dholland nfsv3err_symlink,
449 1.1 dholland nfsv3err_mknod,
450 1.1 dholland nfsv3err_remove,
451 1.1 dholland nfsv3err_rmdir,
452 1.1 dholland nfsv3err_rename,
453 1.1 dholland nfsv3err_link,
454 1.1 dholland nfsv3err_readdir,
455 1.1 dholland nfsv3err_readdirplus,
456 1.1 dholland nfsv3err_fsstat,
457 1.1 dholland nfsv3err_fsinfo,
458 1.1 dholland nfsv3err_pathconf,
459 1.1 dholland nfsv3err_commit,
460 1.1 dholland };
461 1.1 dholland
462 1.1 dholland /*
463 1.1 dholland * And the same for V4.
464 1.1 dholland */
465 1.1 dholland static short nfsv4err_null[] = {
466 1.1 dholland 0,
467 1.1 dholland 0,
468 1.1 dholland };
469 1.1 dholland
470 1.1 dholland static short nfsv4err_access[] = {
471 1.1 dholland NFSERR_IO,
472 1.1 dholland NFSERR_ACCES,
473 1.1 dholland NFSERR_BADHANDLE,
474 1.1 dholland NFSERR_BADXDR,
475 1.1 dholland NFSERR_DELAY,
476 1.1 dholland NFSERR_FHEXPIRED,
477 1.1 dholland NFSERR_INVAL,
478 1.1 dholland NFSERR_IO,
479 1.1 dholland NFSERR_MOVED,
480 1.1 dholland NFSERR_NOFILEHANDLE,
481 1.1 dholland NFSERR_RESOURCE,
482 1.1 dholland NFSERR_SERVERFAULT,
483 1.1 dholland NFSERR_STALE,
484 1.1 dholland 0,
485 1.1 dholland };
486 1.1 dholland
487 1.1 dholland static short nfsv4err_close[] = {
488 1.1 dholland NFSERR_EXPIRED,
489 1.1 dholland NFSERR_ADMINREVOKED,
490 1.1 dholland NFSERR_BADHANDLE,
491 1.1 dholland NFSERR_BADSEQID,
492 1.1 dholland NFSERR_BADSTATEID,
493 1.1 dholland NFSERR_BADXDR,
494 1.1 dholland NFSERR_DELAY,
495 1.1 dholland NFSERR_EXPIRED,
496 1.1 dholland NFSERR_FHEXPIRED,
497 1.1 dholland NFSERR_INVAL,
498 1.1 dholland NFSERR_ISDIR,
499 1.1 dholland NFSERR_LEASEMOVED,
500 1.1 dholland NFSERR_LOCKSHELD,
501 1.1 dholland NFSERR_MOVED,
502 1.1 dholland NFSERR_NOFILEHANDLE,
503 1.1 dholland NFSERR_OLDSTATEID,
504 1.1 dholland NFSERR_RESOURCE,
505 1.1 dholland NFSERR_SERVERFAULT,
506 1.1 dholland NFSERR_STALE,
507 1.1 dholland NFSERR_STALESTATEID,
508 1.1 dholland 0,
509 1.1 dholland };
510 1.1 dholland
511 1.1 dholland static short nfsv4err_commit[] = {
512 1.1 dholland NFSERR_IO,
513 1.1 dholland NFSERR_ACCES,
514 1.1 dholland NFSERR_BADHANDLE,
515 1.1 dholland NFSERR_BADXDR,
516 1.1 dholland NFSERR_FHEXPIRED,
517 1.1 dholland NFSERR_INVAL,
518 1.1 dholland NFSERR_IO,
519 1.1 dholland NFSERR_ISDIR,
520 1.1 dholland NFSERR_MOVED,
521 1.1 dholland NFSERR_NOFILEHANDLE,
522 1.1 dholland NFSERR_RESOURCE,
523 1.1 dholland NFSERR_ROFS,
524 1.1 dholland NFSERR_SERVERFAULT,
525 1.1 dholland NFSERR_STALE,
526 1.1 dholland 0,
527 1.1 dholland };
528 1.1 dholland
529 1.1 dholland static short nfsv4err_create[] = {
530 1.1 dholland NFSERR_IO,
531 1.1 dholland NFSERR_ACCES,
532 1.1 dholland NFSERR_ATTRNOTSUPP,
533 1.1 dholland NFSERR_BADCHAR,
534 1.1 dholland NFSERR_BADHANDLE,
535 1.1 dholland NFSERR_BADNAME,
536 1.1 dholland NFSERR_BADOWNER,
537 1.1 dholland NFSERR_BADTYPE,
538 1.1 dholland NFSERR_BADXDR,
539 1.1 dholland NFSERR_DELAY,
540 1.1 dholland NFSERR_DQUOT,
541 1.1 dholland NFSERR_EXIST,
542 1.1 dholland NFSERR_FHEXPIRED,
543 1.1 dholland NFSERR_INVAL,
544 1.1 dholland NFSERR_IO,
545 1.1 dholland NFSERR_MOVED,
546 1.1 dholland NFSERR_NAMETOL,
547 1.1 dholland NFSERR_NOFILEHANDLE,
548 1.1 dholland NFSERR_NOSPC,
549 1.1 dholland NFSERR_NOTDIR,
550 1.1 dholland NFSERR_PERM,
551 1.1 dholland NFSERR_RESOURCE,
552 1.1 dholland NFSERR_ROFS,
553 1.1 dholland NFSERR_SERVERFAULT,
554 1.1 dholland NFSERR_STALE,
555 1.1 dholland 0,
556 1.1 dholland };
557 1.1 dholland
558 1.1 dholland static short nfsv4err_delegpurge[] = {
559 1.1 dholland NFSERR_SERVERFAULT,
560 1.1 dholland NFSERR_BADXDR,
561 1.1 dholland NFSERR_NOTSUPP,
562 1.1 dholland NFSERR_LEASEMOVED,
563 1.1 dholland NFSERR_MOVED,
564 1.1 dholland NFSERR_RESOURCE,
565 1.1 dholland NFSERR_SERVERFAULT,
566 1.1 dholland NFSERR_STALECLIENTID,
567 1.1 dholland 0,
568 1.1 dholland };
569 1.1 dholland
570 1.1 dholland static short nfsv4err_delegreturn[] = {
571 1.1 dholland NFSERR_SERVERFAULT,
572 1.1 dholland NFSERR_ADMINREVOKED,
573 1.1 dholland NFSERR_BADSTATEID,
574 1.1 dholland NFSERR_BADXDR,
575 1.1 dholland NFSERR_EXPIRED,
576 1.1 dholland NFSERR_INVAL,
577 1.1 dholland NFSERR_LEASEMOVED,
578 1.1 dholland NFSERR_MOVED,
579 1.1 dholland NFSERR_NOFILEHANDLE,
580 1.1 dholland NFSERR_NOTSUPP,
581 1.1 dholland NFSERR_OLDSTATEID,
582 1.1 dholland NFSERR_RESOURCE,
583 1.1 dholland NFSERR_SERVERFAULT,
584 1.1 dholland NFSERR_STALE,
585 1.1 dholland NFSERR_STALESTATEID,
586 1.1 dholland 0,
587 1.1 dholland };
588 1.1 dholland
589 1.1 dholland static short nfsv4err_getattr[] = {
590 1.1 dholland NFSERR_IO,
591 1.1 dholland NFSERR_ACCES,
592 1.1 dholland NFSERR_BADHANDLE,
593 1.1 dholland NFSERR_BADXDR,
594 1.1 dholland NFSERR_DELAY,
595 1.1 dholland NFSERR_FHEXPIRED,
596 1.1 dholland NFSERR_INVAL,
597 1.1 dholland NFSERR_IO,
598 1.1 dholland NFSERR_MOVED,
599 1.1 dholland NFSERR_NOFILEHANDLE,
600 1.1 dholland NFSERR_RESOURCE,
601 1.1 dholland NFSERR_SERVERFAULT,
602 1.1 dholland NFSERR_STALE,
603 1.1 dholland 0,
604 1.1 dholland };
605 1.1 dholland
606 1.1 dholland static short nfsv4err_getfh[] = {
607 1.1 dholland NFSERR_BADHANDLE,
608 1.1 dholland NFSERR_BADHANDLE,
609 1.1 dholland NFSERR_FHEXPIRED,
610 1.1 dholland NFSERR_MOVED,
611 1.1 dholland NFSERR_NOFILEHANDLE,
612 1.1 dholland NFSERR_RESOURCE,
613 1.1 dholland NFSERR_SERVERFAULT,
614 1.1 dholland NFSERR_STALE,
615 1.1 dholland 0,
616 1.1 dholland };
617 1.1 dholland
618 1.1 dholland static short nfsv4err_link[] = {
619 1.1 dholland NFSERR_IO,
620 1.1 dholland NFSERR_ACCES,
621 1.1 dholland NFSERR_BADCHAR,
622 1.1 dholland NFSERR_BADHANDLE,
623 1.1 dholland NFSERR_BADNAME,
624 1.1 dholland NFSERR_BADXDR,
625 1.1 dholland NFSERR_DELAY,
626 1.1 dholland NFSERR_DQUOT,
627 1.1 dholland NFSERR_EXIST,
628 1.1 dholland NFSERR_FHEXPIRED,
629 1.1 dholland NFSERR_FILEOPEN,
630 1.1 dholland NFSERR_INVAL,
631 1.1 dholland NFSERR_IO,
632 1.1 dholland NFSERR_ISDIR,
633 1.1 dholland NFSERR_MLINK,
634 1.1 dholland NFSERR_MOVED,
635 1.1 dholland NFSERR_NAMETOL,
636 1.1 dholland NFSERR_NOENT,
637 1.1 dholland NFSERR_NOFILEHANDLE,
638 1.1 dholland NFSERR_NOSPC,
639 1.1 dholland NFSERR_NOTDIR,
640 1.1 dholland NFSERR_NOTSUPP,
641 1.1 dholland NFSERR_RESOURCE,
642 1.1 dholland NFSERR_ROFS,
643 1.1 dholland NFSERR_SERVERFAULT,
644 1.1 dholland NFSERR_STALE,
645 1.1 dholland NFSERR_WRONGSEC,
646 1.1 dholland NFSERR_XDEV,
647 1.1 dholland 0,
648 1.1 dholland };
649 1.1 dholland
650 1.1 dholland static short nfsv4err_lock[] = {
651 1.1 dholland NFSERR_SERVERFAULT,
652 1.1 dholland NFSERR_ACCES,
653 1.1 dholland NFSERR_ADMINREVOKED,
654 1.1 dholland NFSERR_BADHANDLE,
655 1.1 dholland NFSERR_BADRANGE,
656 1.1 dholland NFSERR_BADSEQID,
657 1.1 dholland NFSERR_BADSTATEID,
658 1.1 dholland NFSERR_BADXDR,
659 1.1 dholland NFSERR_DEADLOCK,
660 1.1 dholland NFSERR_DELAY,
661 1.1 dholland NFSERR_DENIED,
662 1.1 dholland NFSERR_EXPIRED,
663 1.1 dholland NFSERR_FHEXPIRED,
664 1.1 dholland NFSERR_GRACE,
665 1.1 dholland NFSERR_INVAL,
666 1.1 dholland NFSERR_ISDIR,
667 1.1 dholland NFSERR_LEASEMOVED,
668 1.1 dholland NFSERR_LOCKNOTSUPP,
669 1.1 dholland NFSERR_LOCKRANGE,
670 1.1 dholland NFSERR_MOVED,
671 1.1 dholland NFSERR_NOFILEHANDLE,
672 1.1 dholland NFSERR_NOGRACE,
673 1.1 dholland NFSERR_OLDSTATEID,
674 1.1 dholland NFSERR_OPENMODE,
675 1.1 dholland NFSERR_RECLAIMBAD,
676 1.1 dholland NFSERR_RECLAIMCONFLICT,
677 1.1 dholland NFSERR_RESOURCE,
678 1.1 dholland NFSERR_SERVERFAULT,
679 1.1 dholland NFSERR_STALE,
680 1.1 dholland NFSERR_STALECLIENTID,
681 1.1 dholland NFSERR_STALESTATEID,
682 1.1 dholland 0,
683 1.1 dholland };
684 1.1 dholland
685 1.1 dholland static short nfsv4err_lockt[] = {
686 1.1 dholland NFSERR_SERVERFAULT,
687 1.1 dholland NFSERR_ACCES,
688 1.1 dholland NFSERR_BADHANDLE,
689 1.1 dholland NFSERR_BADRANGE,
690 1.1 dholland NFSERR_BADXDR,
691 1.1 dholland NFSERR_DELAY,
692 1.1 dholland NFSERR_DENIED,
693 1.1 dholland NFSERR_FHEXPIRED,
694 1.1 dholland NFSERR_GRACE,
695 1.1 dholland NFSERR_INVAL,
696 1.1 dholland NFSERR_ISDIR,
697 1.1 dholland NFSERR_LEASEMOVED,
698 1.1 dholland NFSERR_LOCKRANGE,
699 1.1 dholland NFSERR_MOVED,
700 1.1 dholland NFSERR_NOFILEHANDLE,
701 1.1 dholland NFSERR_RESOURCE,
702 1.1 dholland NFSERR_SERVERFAULT,
703 1.1 dholland NFSERR_STALE,
704 1.1 dholland NFSERR_STALECLIENTID,
705 1.1 dholland 0,
706 1.1 dholland };
707 1.1 dholland
708 1.1 dholland static short nfsv4err_locku[] = {
709 1.1 dholland NFSERR_SERVERFAULT,
710 1.1 dholland NFSERR_ACCES,
711 1.1 dholland NFSERR_ADMINREVOKED,
712 1.1 dholland NFSERR_BADHANDLE,
713 1.1 dholland NFSERR_BADRANGE,
714 1.1 dholland NFSERR_BADSEQID,
715 1.1 dholland NFSERR_BADSTATEID,
716 1.1 dholland NFSERR_BADXDR,
717 1.1 dholland NFSERR_EXPIRED,
718 1.1 dholland NFSERR_FHEXPIRED,
719 1.1 dholland NFSERR_GRACE,
720 1.1 dholland NFSERR_INVAL,
721 1.1 dholland NFSERR_ISDIR,
722 1.1 dholland NFSERR_LEASEMOVED,
723 1.1 dholland NFSERR_LOCKRANGE,
724 1.1 dholland NFSERR_MOVED,
725 1.1 dholland NFSERR_NOFILEHANDLE,
726 1.1 dholland NFSERR_OLDSTATEID,
727 1.1 dholland NFSERR_RESOURCE,
728 1.1 dholland NFSERR_SERVERFAULT,
729 1.1 dholland NFSERR_STALE,
730 1.1 dholland NFSERR_STALESTATEID,
731 1.1 dholland 0,
732 1.1 dholland };
733 1.1 dholland
734 1.1 dholland static short nfsv4err_lookup[] = {
735 1.1 dholland NFSERR_IO,
736 1.1 dholland NFSERR_ACCES,
737 1.1 dholland NFSERR_BADCHAR,
738 1.1 dholland NFSERR_BADHANDLE,
739 1.1 dholland NFSERR_BADNAME,
740 1.1 dholland NFSERR_BADXDR,
741 1.1 dholland NFSERR_FHEXPIRED,
742 1.1 dholland NFSERR_INVAL,
743 1.1 dholland NFSERR_IO,
744 1.1 dholland NFSERR_MOVED,
745 1.1 dholland NFSERR_NAMETOL,
746 1.1 dholland NFSERR_NOENT,
747 1.1 dholland NFSERR_NOFILEHANDLE,
748 1.1 dholland NFSERR_NOTDIR,
749 1.1 dholland NFSERR_RESOURCE,
750 1.1 dholland NFSERR_SERVERFAULT,
751 1.1 dholland NFSERR_STALE,
752 1.1 dholland NFSERR_SYMLINK,
753 1.1 dholland NFSERR_WRONGSEC,
754 1.1 dholland 0,
755 1.1 dholland };
756 1.1 dholland
757 1.1 dholland static short nfsv4err_lookupp[] = {
758 1.1 dholland NFSERR_IO,
759 1.1 dholland NFSERR_ACCES,
760 1.1 dholland NFSERR_BADHANDLE,
761 1.1 dholland NFSERR_FHEXPIRED,
762 1.1 dholland NFSERR_IO,
763 1.1 dholland NFSERR_MOVED,
764 1.1 dholland NFSERR_NOENT,
765 1.1 dholland NFSERR_NOFILEHANDLE,
766 1.1 dholland NFSERR_NOTDIR,
767 1.1 dholland NFSERR_RESOURCE,
768 1.1 dholland NFSERR_SERVERFAULT,
769 1.1 dholland NFSERR_STALE,
770 1.1 dholland 0,
771 1.1 dholland };
772 1.1 dholland
773 1.1 dholland static short nfsv4err_nverify[] = {
774 1.1 dholland NFSERR_IO,
775 1.1 dholland NFSERR_ACCES,
776 1.1 dholland NFSERR_ATTRNOTSUPP,
777 1.1 dholland NFSERR_BADCHAR,
778 1.1 dholland NFSERR_BADHANDLE,
779 1.1 dholland NFSERR_BADXDR,
780 1.1 dholland NFSERR_DELAY,
781 1.1 dholland NFSERR_FHEXPIRED,
782 1.1 dholland NFSERR_INVAL,
783 1.1 dholland NFSERR_IO,
784 1.1 dholland NFSERR_MOVED,
785 1.1 dholland NFSERR_NOFILEHANDLE,
786 1.1 dholland NFSERR_RESOURCE,
787 1.1 dholland NFSERR_SAME,
788 1.1 dholland NFSERR_SERVERFAULT,
789 1.1 dholland NFSERR_STALE,
790 1.1 dholland 0,
791 1.1 dholland };
792 1.1 dholland
793 1.1 dholland static short nfsv4err_open[] = {
794 1.1 dholland NFSERR_IO,
795 1.1 dholland NFSERR_ACCES,
796 1.1 dholland NFSERR_ADMINREVOKED,
797 1.1 dholland NFSERR_ATTRNOTSUPP,
798 1.1 dholland NFSERR_BADCHAR,
799 1.1 dholland NFSERR_BADHANDLE,
800 1.1 dholland NFSERR_BADNAME,
801 1.1 dholland NFSERR_BADOWNER,
802 1.1 dholland NFSERR_BADSEQID,
803 1.1 dholland NFSERR_BADXDR,
804 1.1 dholland NFSERR_DELAY,
805 1.1 dholland NFSERR_DQUOT,
806 1.1 dholland NFSERR_EXIST,
807 1.1 dholland NFSERR_EXPIRED,
808 1.1 dholland NFSERR_FHEXPIRED,
809 1.1 dholland NFSERR_GRACE,
810 1.1 dholland NFSERR_IO,
811 1.1 dholland NFSERR_INVAL,
812 1.1 dholland NFSERR_ISDIR,
813 1.1 dholland NFSERR_LEASEMOVED,
814 1.1 dholland NFSERR_MOVED,
815 1.1 dholland NFSERR_NAMETOL,
816 1.1 dholland NFSERR_NOENT,
817 1.1 dholland NFSERR_NOFILEHANDLE,
818 1.1 dholland NFSERR_NOGRACE,
819 1.1 dholland NFSERR_NOSPC,
820 1.1 dholland NFSERR_NOTDIR,
821 1.1 dholland NFSERR_NOTSUPP,
822 1.1 dholland NFSERR_PERM,
823 1.1 dholland NFSERR_RECLAIMBAD,
824 1.1 dholland NFSERR_RECLAIMCONFLICT,
825 1.1 dholland NFSERR_RESOURCE,
826 1.1 dholland NFSERR_ROFS,
827 1.1 dholland NFSERR_SERVERFAULT,
828 1.1 dholland NFSERR_SHAREDENIED,
829 1.1 dholland NFSERR_STALE,
830 1.1 dholland NFSERR_STALECLIENTID,
831 1.1 dholland NFSERR_SYMLINK,
832 1.1 dholland NFSERR_WRONGSEC,
833 1.1 dholland 0,
834 1.1 dholland };
835 1.1 dholland
836 1.1 dholland static short nfsv4err_openattr[] = {
837 1.1 dholland NFSERR_IO,
838 1.1 dholland NFSERR_ACCES,
839 1.1 dholland NFSERR_BADHANDLE,
840 1.1 dholland NFSERR_BADXDR,
841 1.1 dholland NFSERR_DELAY,
842 1.1 dholland NFSERR_DQUOT,
843 1.1 dholland NFSERR_FHEXPIRED,
844 1.1 dholland NFSERR_IO,
845 1.1 dholland NFSERR_MOVED,
846 1.1 dholland NFSERR_NOENT,
847 1.1 dholland NFSERR_NOFILEHANDLE,
848 1.1 dholland NFSERR_NOSPC,
849 1.1 dholland NFSERR_NOTSUPP,
850 1.1 dholland NFSERR_RESOURCE,
851 1.1 dholland NFSERR_ROFS,
852 1.1 dholland NFSERR_SERVERFAULT,
853 1.1 dholland NFSERR_STALE,
854 1.1 dholland 0,
855 1.1 dholland };
856 1.1 dholland
857 1.1 dholland static short nfsv4err_openconfirm[] = {
858 1.1 dholland NFSERR_SERVERFAULT,
859 1.1 dholland NFSERR_ADMINREVOKED,
860 1.1 dholland NFSERR_BADHANDLE,
861 1.1 dholland NFSERR_BADSEQID,
862 1.1 dholland NFSERR_BADSTATEID,
863 1.1 dholland NFSERR_BADXDR,
864 1.1 dholland NFSERR_EXPIRED,
865 1.1 dholland NFSERR_FHEXPIRED,
866 1.1 dholland NFSERR_INVAL,
867 1.1 dholland NFSERR_ISDIR,
868 1.1 dholland NFSERR_MOVED,
869 1.1 dholland NFSERR_NOFILEHANDLE,
870 1.1 dholland NFSERR_OLDSTATEID,
871 1.1 dholland NFSERR_RESOURCE,
872 1.1 dholland NFSERR_SERVERFAULT,
873 1.1 dholland NFSERR_STALE,
874 1.1 dholland NFSERR_STALESTATEID,
875 1.1 dholland 0,
876 1.1 dholland };
877 1.1 dholland
878 1.1 dholland static short nfsv4err_opendowngrade[] = {
879 1.1 dholland NFSERR_SERVERFAULT,
880 1.1 dholland NFSERR_ADMINREVOKED,
881 1.1 dholland NFSERR_BADHANDLE,
882 1.1 dholland NFSERR_BADSEQID,
883 1.1 dholland NFSERR_BADSTATEID,
884 1.1 dholland NFSERR_BADXDR,
885 1.1 dholland NFSERR_EXPIRED,
886 1.1 dholland NFSERR_FHEXPIRED,
887 1.1 dholland NFSERR_INVAL,
888 1.1 dholland NFSERR_MOVED,
889 1.1 dholland NFSERR_NOFILEHANDLE,
890 1.1 dholland NFSERR_OLDSTATEID,
891 1.1 dholland NFSERR_RESOURCE,
892 1.1 dholland NFSERR_SERVERFAULT,
893 1.1 dholland NFSERR_STALE,
894 1.1 dholland NFSERR_STALESTATEID,
895 1.1 dholland 0,
896 1.1 dholland };
897 1.1 dholland
898 1.1 dholland static short nfsv4err_putfh[] = {
899 1.1 dholland NFSERR_SERVERFAULT,
900 1.1 dholland NFSERR_BADHANDLE,
901 1.1 dholland NFSERR_BADXDR,
902 1.1 dholland NFSERR_FHEXPIRED,
903 1.1 dholland NFSERR_MOVED,
904 1.1 dholland NFSERR_RESOURCE,
905 1.1 dholland NFSERR_SERVERFAULT,
906 1.1 dholland NFSERR_STALE,
907 1.1 dholland NFSERR_WRONGSEC,
908 1.1 dholland 0,
909 1.1 dholland };
910 1.1 dholland
911 1.1 dholland static short nfsv4err_putpubfh[] = {
912 1.1 dholland NFSERR_SERVERFAULT,
913 1.1 dholland NFSERR_RESOURCE,
914 1.1 dholland NFSERR_SERVERFAULT,
915 1.1 dholland NFSERR_WRONGSEC,
916 1.1 dholland 0,
917 1.1 dholland };
918 1.1 dholland
919 1.1 dholland static short nfsv4err_putrootfh[] = {
920 1.1 dholland NFSERR_SERVERFAULT,
921 1.1 dholland NFSERR_RESOURCE,
922 1.1 dholland NFSERR_SERVERFAULT,
923 1.1 dholland NFSERR_WRONGSEC,
924 1.1 dholland 0,
925 1.1 dholland };
926 1.1 dholland
927 1.1 dholland static short nfsv4err_read[] = {
928 1.1 dholland NFSERR_IO,
929 1.1 dholland NFSERR_ACCES,
930 1.1 dholland NFSERR_ADMINREVOKED,
931 1.1 dholland NFSERR_BADHANDLE,
932 1.1 dholland NFSERR_BADSTATEID,
933 1.1 dholland NFSERR_BADXDR,
934 1.1 dholland NFSERR_DELAY,
935 1.1 dholland NFSERR_EXPIRED,
936 1.1 dholland NFSERR_FHEXPIRED,
937 1.1 dholland NFSERR_GRACE,
938 1.1 dholland NFSERR_IO,
939 1.1 dholland NFSERR_INVAL,
940 1.1 dholland NFSERR_ISDIR,
941 1.1 dholland NFSERR_LEASEMOVED,
942 1.1 dholland NFSERR_LOCKED,
943 1.1 dholland NFSERR_MOVED,
944 1.1 dholland NFSERR_NOFILEHANDLE,
945 1.1 dholland NFSERR_NXIO,
946 1.1 dholland NFSERR_OLDSTATEID,
947 1.1 dholland NFSERR_OPENMODE,
948 1.1 dholland NFSERR_RESOURCE,
949 1.1 dholland NFSERR_SERVERFAULT,
950 1.1 dholland NFSERR_STALE,
951 1.1 dholland NFSERR_STALESTATEID,
952 1.1 dholland 0,
953 1.1 dholland };
954 1.1 dholland
955 1.1 dholland static short nfsv4err_readdir[] = {
956 1.1 dholland NFSERR_IO,
957 1.1 dholland NFSERR_ACCES,
958 1.1 dholland NFSERR_BADHANDLE,
959 1.1 dholland NFSERR_BAD_COOKIE,
960 1.1 dholland NFSERR_BADXDR,
961 1.1 dholland NFSERR_DELAY,
962 1.1 dholland NFSERR_FHEXPIRED,
963 1.1 dholland NFSERR_INVAL,
964 1.1 dholland NFSERR_IO,
965 1.1 dholland NFSERR_MOVED,
966 1.1 dholland NFSERR_NOFILEHANDLE,
967 1.1 dholland NFSERR_NOTDIR,
968 1.1 dholland NFSERR_NOTSAME,
969 1.1 dholland NFSERR_RESOURCE,
970 1.1 dholland NFSERR_SERVERFAULT,
971 1.1 dholland NFSERR_STALE,
972 1.1 dholland NFSERR_TOOSMALL,
973 1.1 dholland 0,
974 1.1 dholland };
975 1.1 dholland
976 1.1 dholland static short nfsv4err_readlink[] = {
977 1.1 dholland NFSERR_IO,
978 1.1 dholland NFSERR_ACCES,
979 1.1 dholland NFSERR_BADHANDLE,
980 1.1 dholland NFSERR_DELAY,
981 1.1 dholland NFSERR_FHEXPIRED,
982 1.1 dholland NFSERR_INVAL,
983 1.1 dholland NFSERR_IO,
984 1.1 dholland NFSERR_ISDIR,
985 1.1 dholland NFSERR_MOVED,
986 1.1 dholland NFSERR_NOFILEHANDLE,
987 1.1 dholland NFSERR_NOTSUPP,
988 1.1 dholland NFSERR_RESOURCE,
989 1.1 dholland NFSERR_SERVERFAULT,
990 1.1 dholland NFSERR_STALE,
991 1.1 dholland 0,
992 1.1 dholland };
993 1.1 dholland
994 1.1 dholland static short nfsv4err_remove[] = {
995 1.1 dholland NFSERR_IO,
996 1.1 dholland NFSERR_ACCES,
997 1.1 dholland NFSERR_BADCHAR,
998 1.1 dholland NFSERR_BADHANDLE,
999 1.1 dholland NFSERR_BADNAME,
1000 1.1 dholland NFSERR_BADXDR,
1001 1.1 dholland NFSERR_DELAY,
1002 1.1 dholland NFSERR_FHEXPIRED,
1003 1.1 dholland NFSERR_FILEOPEN,
1004 1.1 dholland NFSERR_INVAL,
1005 1.1 dholland NFSERR_IO,
1006 1.1 dholland NFSERR_MOVED,
1007 1.1 dholland NFSERR_NAMETOL,
1008 1.1 dholland NFSERR_NOENT,
1009 1.1 dholland NFSERR_NOFILEHANDLE,
1010 1.1 dholland NFSERR_NOTDIR,
1011 1.1 dholland NFSERR_NOTEMPTY,
1012 1.1 dholland NFSERR_RESOURCE,
1013 1.1 dholland NFSERR_ROFS,
1014 1.1 dholland NFSERR_SERVERFAULT,
1015 1.1 dholland NFSERR_STALE,
1016 1.1 dholland 0,
1017 1.1 dholland };
1018 1.1 dholland
1019 1.1 dholland static short nfsv4err_rename[] = {
1020 1.1 dholland NFSERR_IO,
1021 1.1 dholland NFSERR_ACCES,
1022 1.1 dholland NFSERR_BADCHAR,
1023 1.1 dholland NFSERR_BADHANDLE,
1024 1.1 dholland NFSERR_BADNAME,
1025 1.1 dholland NFSERR_BADXDR,
1026 1.1 dholland NFSERR_DELAY,
1027 1.1 dholland NFSERR_DQUOT,
1028 1.1 dholland NFSERR_EXIST,
1029 1.1 dholland NFSERR_FHEXPIRED,
1030 1.1 dholland NFSERR_FILEOPEN,
1031 1.1 dholland NFSERR_INVAL,
1032 1.1 dholland NFSERR_IO,
1033 1.1 dholland NFSERR_MOVED,
1034 1.1 dholland NFSERR_NAMETOL,
1035 1.1 dholland NFSERR_NOENT,
1036 1.1 dholland NFSERR_NOFILEHANDLE,
1037 1.1 dholland NFSERR_NOSPC,
1038 1.1 dholland NFSERR_NOTDIR,
1039 1.1 dholland NFSERR_NOTEMPTY,
1040 1.1 dholland NFSERR_RESOURCE,
1041 1.1 dholland NFSERR_ROFS,
1042 1.1 dholland NFSERR_SERVERFAULT,
1043 1.1 dholland NFSERR_STALE,
1044 1.1 dholland NFSERR_WRONGSEC,
1045 1.1 dholland NFSERR_XDEV,
1046 1.1 dholland 0,
1047 1.1 dholland };
1048 1.1 dholland
1049 1.1 dholland static short nfsv4err_renew[] = {
1050 1.1 dholland NFSERR_SERVERFAULT,
1051 1.1 dholland NFSERR_ACCES,
1052 1.1 dholland NFSERR_ADMINREVOKED,
1053 1.1 dholland NFSERR_BADXDR,
1054 1.1 dholland NFSERR_CBPATHDOWN,
1055 1.1 dholland NFSERR_EXPIRED,
1056 1.1 dholland NFSERR_LEASEMOVED,
1057 1.1 dholland NFSERR_RESOURCE,
1058 1.1 dholland NFSERR_SERVERFAULT,
1059 1.1 dholland NFSERR_STALECLIENTID,
1060 1.1 dholland 0,
1061 1.1 dholland };
1062 1.1 dholland
1063 1.1 dholland static short nfsv4err_restorefh[] = {
1064 1.1 dholland NFSERR_SERVERFAULT,
1065 1.1 dholland NFSERR_BADHANDLE,
1066 1.1 dholland NFSERR_FHEXPIRED,
1067 1.1 dholland NFSERR_MOVED,
1068 1.1 dholland NFSERR_RESOURCE,
1069 1.1 dholland NFSERR_RESTOREFH,
1070 1.1 dholland NFSERR_SERVERFAULT,
1071 1.1 dholland NFSERR_STALE,
1072 1.1 dholland NFSERR_WRONGSEC,
1073 1.1 dholland 0,
1074 1.1 dholland };
1075 1.1 dholland
1076 1.1 dholland static short nfsv4err_savefh[] = {
1077 1.1 dholland NFSERR_SERVERFAULT,
1078 1.1 dholland NFSERR_BADHANDLE,
1079 1.1 dholland NFSERR_FHEXPIRED,
1080 1.1 dholland NFSERR_MOVED,
1081 1.1 dholland NFSERR_NOFILEHANDLE,
1082 1.1 dholland NFSERR_RESOURCE,
1083 1.1 dholland NFSERR_SERVERFAULT,
1084 1.1 dholland NFSERR_STALE,
1085 1.1 dholland 0,
1086 1.1 dholland };
1087 1.1 dholland
1088 1.1 dholland static short nfsv4err_secinfo[] = {
1089 1.1 dholland NFSERR_SERVERFAULT,
1090 1.1 dholland NFSERR_ACCES,
1091 1.1 dholland NFSERR_BADCHAR,
1092 1.1 dholland NFSERR_BADHANDLE,
1093 1.1 dholland NFSERR_BADNAME,
1094 1.1 dholland NFSERR_BADXDR,
1095 1.1 dholland NFSERR_FHEXPIRED,
1096 1.1 dholland NFSERR_INVAL,
1097 1.1 dholland NFSERR_MOVED,
1098 1.1 dholland NFSERR_NAMETOL,
1099 1.1 dholland NFSERR_NOENT,
1100 1.1 dholland NFSERR_NOFILEHANDLE,
1101 1.1 dholland NFSERR_NOTDIR,
1102 1.1 dholland NFSERR_RESOURCE,
1103 1.1 dholland NFSERR_SERVERFAULT,
1104 1.1 dholland NFSERR_STALE,
1105 1.1 dholland 0,
1106 1.1 dholland };
1107 1.1 dholland
1108 1.1 dholland static short nfsv4err_setattr[] = {
1109 1.1 dholland NFSERR_IO,
1110 1.1 dholland NFSERR_ACCES,
1111 1.1 dholland NFSERR_ADMINREVOKED,
1112 1.1 dholland NFSERR_ATTRNOTSUPP,
1113 1.1 dholland NFSERR_BADCHAR,
1114 1.1 dholland NFSERR_BADHANDLE,
1115 1.1 dholland NFSERR_BADOWNER,
1116 1.1 dholland NFSERR_BADSTATEID,
1117 1.1 dholland NFSERR_BADXDR,
1118 1.1 dholland NFSERR_DELAY,
1119 1.1 dholland NFSERR_DQUOT,
1120 1.1 dholland NFSERR_EXPIRED,
1121 1.1 dholland NFSERR_FBIG,
1122 1.1 dholland NFSERR_FHEXPIRED,
1123 1.1 dholland NFSERR_GRACE,
1124 1.1 dholland NFSERR_INVAL,
1125 1.1 dholland NFSERR_IO,
1126 1.1 dholland NFSERR_ISDIR,
1127 1.1 dholland NFSERR_LOCKED,
1128 1.1 dholland NFSERR_MOVED,
1129 1.1 dholland NFSERR_NOFILEHANDLE,
1130 1.1 dholland NFSERR_NOSPC,
1131 1.1 dholland NFSERR_OLDSTATEID,
1132 1.1 dholland NFSERR_OPENMODE,
1133 1.1 dholland NFSERR_PERM,
1134 1.1 dholland NFSERR_RESOURCE,
1135 1.1 dholland NFSERR_ROFS,
1136 1.1 dholland NFSERR_SERVERFAULT,
1137 1.1 dholland NFSERR_STALE,
1138 1.1 dholland NFSERR_STALESTATEID,
1139 1.1 dholland 0,
1140 1.1 dholland };
1141 1.1 dholland
1142 1.1 dholland static short nfsv4err_setclientid[] = {
1143 1.1 dholland NFSERR_SERVERFAULT,
1144 1.1 dholland NFSERR_BADXDR,
1145 1.1 dholland NFSERR_CLIDINUSE,
1146 1.1 dholland NFSERR_INVAL,
1147 1.1 dholland NFSERR_RESOURCE,
1148 1.1 dholland NFSERR_SERVERFAULT,
1149 1.3 pgoyette NFSERR_WRONGSEC,
1150 1.1 dholland 0,
1151 1.1 dholland };
1152 1.1 dholland
1153 1.1 dholland static short nfsv4err_setclientidconfirm[] = {
1154 1.1 dholland NFSERR_SERVERFAULT,
1155 1.1 dholland NFSERR_BADXDR,
1156 1.1 dholland NFSERR_CLIDINUSE,
1157 1.1 dholland NFSERR_RESOURCE,
1158 1.1 dholland NFSERR_SERVERFAULT,
1159 1.1 dholland NFSERR_STALECLIENTID,
1160 1.1 dholland 0,
1161 1.1 dholland };
1162 1.1 dholland
1163 1.1 dholland static short nfsv4err_verify[] = {
1164 1.1 dholland NFSERR_SERVERFAULT,
1165 1.1 dholland NFSERR_ACCES,
1166 1.1 dholland NFSERR_ATTRNOTSUPP,
1167 1.1 dholland NFSERR_BADCHAR,
1168 1.1 dholland NFSERR_BADHANDLE,
1169 1.1 dholland NFSERR_BADXDR,
1170 1.1 dholland NFSERR_DELAY,
1171 1.1 dholland NFSERR_FHEXPIRED,
1172 1.1 dholland NFSERR_INVAL,
1173 1.1 dholland NFSERR_MOVED,
1174 1.1 dholland NFSERR_NOFILEHANDLE,
1175 1.1 dholland NFSERR_NOTSAME,
1176 1.1 dholland NFSERR_RESOURCE,
1177 1.1 dholland NFSERR_SERVERFAULT,
1178 1.1 dholland NFSERR_STALE,
1179 1.1 dholland 0,
1180 1.1 dholland };
1181 1.1 dholland
1182 1.1 dholland static short nfsv4err_write[] = {
1183 1.1 dholland NFSERR_IO,
1184 1.1 dholland NFSERR_ACCES,
1185 1.1 dholland NFSERR_ADMINREVOKED,
1186 1.1 dholland NFSERR_BADHANDLE,
1187 1.1 dholland NFSERR_BADSTATEID,
1188 1.1 dholland NFSERR_BADXDR,
1189 1.1 dholland NFSERR_DELAY,
1190 1.1 dholland NFSERR_DQUOT,
1191 1.1 dholland NFSERR_EXPIRED,
1192 1.1 dholland NFSERR_FBIG,
1193 1.1 dholland NFSERR_FHEXPIRED,
1194 1.1 dholland NFSERR_GRACE,
1195 1.1 dholland NFSERR_INVAL,
1196 1.1 dholland NFSERR_IO,
1197 1.1 dholland NFSERR_ISDIR,
1198 1.1 dholland NFSERR_LEASEMOVED,
1199 1.1 dholland NFSERR_LOCKED,
1200 1.1 dholland NFSERR_MOVED,
1201 1.1 dholland NFSERR_NOFILEHANDLE,
1202 1.1 dholland NFSERR_NOSPC,
1203 1.1 dholland NFSERR_NXIO,
1204 1.1 dholland NFSERR_OLDSTATEID,
1205 1.1 dholland NFSERR_OPENMODE,
1206 1.1 dholland NFSERR_RESOURCE,
1207 1.1 dholland NFSERR_ROFS,
1208 1.1 dholland NFSERR_SERVERFAULT,
1209 1.1 dholland NFSERR_STALE,
1210 1.1 dholland NFSERR_STALESTATEID,
1211 1.1 dholland 0,
1212 1.1 dholland };
1213 1.1 dholland
1214 1.1 dholland static short nfsv4err_releaselockowner[] = {
1215 1.1 dholland NFSERR_SERVERFAULT,
1216 1.1 dholland NFSERR_ADMINREVOKED,
1217 1.1 dholland NFSERR_BADXDR,
1218 1.1 dholland NFSERR_EXPIRED,
1219 1.1 dholland NFSERR_LEASEMOVED,
1220 1.1 dholland NFSERR_LOCKSHELD,
1221 1.1 dholland NFSERR_RESOURCE,
1222 1.1 dholland NFSERR_SERVERFAULT,
1223 1.1 dholland NFSERR_STALECLIENTID,
1224 1.1 dholland 0,
1225 1.1 dholland };
1226 1.1 dholland
1227 1.1 dholland static short *nfsrv_v4errmap[] = {
1228 1.1 dholland nfsv4err_null,
1229 1.1 dholland nfsv4err_null,
1230 1.1 dholland nfsv4err_null,
1231 1.1 dholland nfsv4err_access,
1232 1.1 dholland nfsv4err_close,
1233 1.1 dholland nfsv4err_commit,
1234 1.1 dholland nfsv4err_create,
1235 1.1 dholland nfsv4err_delegpurge,
1236 1.1 dholland nfsv4err_delegreturn,
1237 1.1 dholland nfsv4err_getattr,
1238 1.1 dholland nfsv4err_getfh,
1239 1.1 dholland nfsv4err_link,
1240 1.1 dholland nfsv4err_lock,
1241 1.1 dholland nfsv4err_lockt,
1242 1.1 dholland nfsv4err_locku,
1243 1.1 dholland nfsv4err_lookup,
1244 1.1 dholland nfsv4err_lookupp,
1245 1.1 dholland nfsv4err_nverify,
1246 1.1 dholland nfsv4err_open,
1247 1.1 dholland nfsv4err_openattr,
1248 1.1 dholland nfsv4err_openconfirm,
1249 1.1 dholland nfsv4err_opendowngrade,
1250 1.1 dholland nfsv4err_putfh,
1251 1.1 dholland nfsv4err_putpubfh,
1252 1.1 dholland nfsv4err_putrootfh,
1253 1.1 dholland nfsv4err_read,
1254 1.1 dholland nfsv4err_readdir,
1255 1.1 dholland nfsv4err_readlink,
1256 1.1 dholland nfsv4err_remove,
1257 1.1 dholland nfsv4err_rename,
1258 1.1 dholland nfsv4err_renew,
1259 1.1 dholland nfsv4err_restorefh,
1260 1.1 dholland nfsv4err_savefh,
1261 1.1 dholland nfsv4err_secinfo,
1262 1.1 dholland nfsv4err_setattr,
1263 1.1 dholland nfsv4err_setclientid,
1264 1.1 dholland nfsv4err_setclientidconfirm,
1265 1.1 dholland nfsv4err_verify,
1266 1.1 dholland nfsv4err_write,
1267 1.1 dholland nfsv4err_releaselockowner,
1268 1.1 dholland };
1269 1.1 dholland
1270 1.1 dholland /*
1271 1.1 dholland * A fiddled version of m_adj() that ensures null fill to a long
1272 1.1 dholland * boundary and only trims off the back end
1273 1.1 dholland */
1274 1.1 dholland APPLESTATIC void
1275 1.1 dholland nfsrv_adj(mbuf_t mp, int len, int nul)
1276 1.1 dholland {
1277 1.1 dholland mbuf_t m;
1278 1.1 dholland int count, i;
1279 1.1 dholland char *cp;
1280 1.1 dholland
1281 1.1 dholland /*
1282 1.1 dholland * Trim from tail. Scan the mbuf chain,
1283 1.1 dholland * calculating its length and finding the last mbuf.
1284 1.1 dholland * If the adjustment only affects this mbuf, then just
1285 1.1 dholland * adjust and return. Otherwise, rescan and truncate
1286 1.1 dholland * after the remaining size.
1287 1.1 dholland */
1288 1.1 dholland count = 0;
1289 1.1 dholland m = mp;
1290 1.1 dholland for (;;) {
1291 1.1 dholland count += mbuf_len(m);
1292 1.1 dholland if (mbuf_next(m) == NULL)
1293 1.1 dholland break;
1294 1.1 dholland m = mbuf_next(m);
1295 1.1 dholland }
1296 1.1 dholland if (mbuf_len(m) > len) {
1297 1.1 dholland mbuf_setlen(m, mbuf_len(m) - len);
1298 1.1 dholland if (nul > 0) {
1299 1.1 dholland cp = NFSMTOD(m, caddr_t) + mbuf_len(m) - nul;
1300 1.1 dholland for (i = 0; i < nul; i++)
1301 1.1 dholland *cp++ = '\0';
1302 1.1 dholland }
1303 1.1 dholland return;
1304 1.1 dholland }
1305 1.1 dholland count -= len;
1306 1.1 dholland if (count < 0)
1307 1.1 dholland count = 0;
1308 1.1 dholland /*
1309 1.1 dholland * Correct length for chain is "count".
1310 1.1 dholland * Find the mbuf with last data, adjust its length,
1311 1.1 dholland * and toss data from remaining mbufs on chain.
1312 1.1 dholland */
1313 1.1 dholland for (m = mp; m; m = mbuf_next(m)) {
1314 1.1 dholland if (mbuf_len(m) >= count) {
1315 1.1 dholland mbuf_setlen(m, count);
1316 1.1 dholland if (nul > 0) {
1317 1.1 dholland cp = NFSMTOD(m, caddr_t) + mbuf_len(m) - nul;
1318 1.1 dholland for (i = 0; i < nul; i++)
1319 1.1 dholland *cp++ = '\0';
1320 1.1 dholland }
1321 1.1 dholland break;
1322 1.1 dholland }
1323 1.1 dholland count -= mbuf_len(m);
1324 1.1 dholland }
1325 1.1 dholland for (m = mbuf_next(m); m; m = mbuf_next(m))
1326 1.1 dholland mbuf_setlen(m, 0);
1327 1.1 dholland }
1328 1.1 dholland
1329 1.1 dholland /*
1330 1.1 dholland * Make these functions instead of macros, so that the kernel text size
1331 1.1 dholland * doesn't get too big...
1332 1.1 dholland */
1333 1.1 dholland APPLESTATIC void
1334 1.1 dholland nfsrv_wcc(struct nfsrv_descript *nd, int before_ret,
1335 1.1 dholland struct nfsvattr *before_nvap, int after_ret, struct nfsvattr *after_nvap)
1336 1.1 dholland {
1337 1.1 dholland u_int32_t *tl;
1338 1.1 dholland
1339 1.1 dholland if (before_ret) {
1340 1.1 dholland NFSM_BUILD(tl, u_int32_t *, NFSX_UNSIGNED);
1341 1.1 dholland *tl = newnfs_false;
1342 1.1 dholland } else {
1343 1.1 dholland NFSM_BUILD(tl, u_int32_t *, 7 * NFSX_UNSIGNED);
1344 1.1 dholland *tl++ = newnfs_true;
1345 1.1 dholland txdr_hyper(before_nvap->na_size, tl);
1346 1.1 dholland tl += 2;
1347 1.1 dholland txdr_nfsv3time(&(before_nvap->na_mtime), tl);
1348 1.1 dholland tl += 2;
1349 1.1 dholland txdr_nfsv3time(&(before_nvap->na_ctime), tl);
1350 1.1 dholland }
1351 1.1 dholland nfsrv_postopattr(nd, after_ret, after_nvap);
1352 1.1 dholland }
1353 1.1 dholland
1354 1.1 dholland APPLESTATIC void
1355 1.1 dholland nfsrv_postopattr(struct nfsrv_descript *nd, int after_ret,
1356 1.1 dholland struct nfsvattr *after_nvap)
1357 1.1 dholland {
1358 1.1 dholland u_int32_t *tl;
1359 1.1 dholland
1360 1.1 dholland NFSM_BUILD(tl, u_int32_t *, NFSX_UNSIGNED);
1361 1.1 dholland if (after_ret)
1362 1.1 dholland *tl = newnfs_false;
1363 1.1 dholland else {
1364 1.1 dholland *tl = newnfs_true;
1365 1.1 dholland nfsrv_fillattr(nd, after_nvap);
1366 1.1 dholland }
1367 1.1 dholland }
1368 1.1 dholland
1369 1.1 dholland /*
1370 1.1 dholland * Fill in file attributes for V2 and 3. For V4, call a separate
1371 1.1 dholland * routine that sifts through all the attribute bits.
1372 1.1 dholland */
1373 1.1 dholland APPLESTATIC void
1374 1.1 dholland nfsrv_fillattr(struct nfsrv_descript *nd, struct nfsvattr *nvap)
1375 1.1 dholland {
1376 1.1 dholland struct nfs_fattr *fp;
1377 1.1 dholland int fattr_size;
1378 1.1 dholland
1379 1.1 dholland /*
1380 1.1 dholland * Build space for the attribute structure.
1381 1.1 dholland */
1382 1.1 dholland if (nd->nd_flag & ND_NFSV3)
1383 1.1 dholland fattr_size = NFSX_V3FATTR;
1384 1.1 dholland else
1385 1.1 dholland fattr_size = NFSX_V2FATTR;
1386 1.1 dholland NFSM_BUILD(fp, struct nfs_fattr *, fattr_size);
1387 1.1 dholland
1388 1.1 dholland /*
1389 1.1 dholland * Now just fill it all in.
1390 1.1 dholland */
1391 1.1 dholland fp->fa_nlink = txdr_unsigned(nvap->na_nlink);
1392 1.1 dholland fp->fa_uid = txdr_unsigned(nvap->na_uid);
1393 1.1 dholland fp->fa_gid = txdr_unsigned(nvap->na_gid);
1394 1.1 dholland if (nd->nd_flag & ND_NFSV3) {
1395 1.1 dholland fp->fa_type = vtonfsv34_type(nvap->na_type);
1396 1.1 dholland fp->fa_mode = vtonfsv34_mode(nvap->na_mode);
1397 1.1 dholland txdr_hyper(nvap->na_size, &fp->fa3_size);
1398 1.1 dholland txdr_hyper(nvap->na_bytes, &fp->fa3_used);
1399 1.1 dholland fp->fa3_rdev.specdata1 = txdr_unsigned(NFSMAJOR(nvap->na_rdev));
1400 1.1 dholland fp->fa3_rdev.specdata2 = txdr_unsigned(NFSMINOR(nvap->na_rdev));
1401 1.1 dholland fp->fa3_fsid.nfsuquad[0] = 0;
1402 1.1 dholland fp->fa3_fsid.nfsuquad[1] = txdr_unsigned(nvap->na_fsid);
1403 1.1 dholland fp->fa3_fileid.nfsuquad[0] = 0;
1404 1.1 dholland fp->fa3_fileid.nfsuquad[1] = txdr_unsigned(nvap->na_fileid);
1405 1.1 dholland txdr_nfsv3time(&nvap->na_atime, &fp->fa3_atime);
1406 1.1 dholland txdr_nfsv3time(&nvap->na_mtime, &fp->fa3_mtime);
1407 1.1 dholland txdr_nfsv3time(&nvap->na_ctime, &fp->fa3_ctime);
1408 1.1 dholland } else {
1409 1.1 dholland fp->fa_type = vtonfsv2_type(nvap->na_type);
1410 1.1 dholland fp->fa_mode = vtonfsv2_mode(nvap->na_type, nvap->na_mode);
1411 1.1 dholland fp->fa2_size = txdr_unsigned(nvap->na_size);
1412 1.1 dholland fp->fa2_blocksize = txdr_unsigned(nvap->na_blocksize);
1413 1.1 dholland if (nvap->na_type == VFIFO)
1414 1.1 dholland fp->fa2_rdev = 0xffffffff;
1415 1.1 dholland else
1416 1.1 dholland fp->fa2_rdev = txdr_unsigned(nvap->na_rdev);
1417 1.1 dholland fp->fa2_blocks = txdr_unsigned(nvap->na_bytes / NFS_FABLKSIZE);
1418 1.1 dholland fp->fa2_fsid = txdr_unsigned(nvap->na_fsid);
1419 1.1 dholland fp->fa2_fileid = txdr_unsigned(nvap->na_fileid);
1420 1.1 dholland txdr_nfsv2time(&nvap->na_atime, &fp->fa2_atime);
1421 1.1 dholland txdr_nfsv2time(&nvap->na_mtime, &fp->fa2_mtime);
1422 1.1 dholland txdr_nfsv2time(&nvap->na_ctime, &fp->fa2_ctime);
1423 1.1 dholland }
1424 1.1 dholland }
1425 1.1 dholland
1426 1.1 dholland /*
1427 1.1 dholland * This function gets a file handle out of an mbuf list.
1428 1.1 dholland * It returns 0 for success, EBADRPC otherwise.
1429 1.1 dholland * If sets the third flagp argument to 1 if the file handle is
1430 1.1 dholland * the public file handle.
1431 1.1 dholland * For NFSv4, if the length is incorrect, set nd_repstat == NFSERR_BADHANDLE
1432 1.1 dholland */
1433 1.1 dholland APPLESTATIC int
1434 1.1 dholland nfsrv_mtofh(struct nfsrv_descript *nd, struct nfsrvfh *fhp)
1435 1.1 dholland {
1436 1.1 dholland u_int32_t *tl;
1437 1.1 dholland int error = 0, len, copylen;
1438 1.1 dholland
1439 1.1 dholland if (nd->nd_flag & (ND_NFSV3 | ND_NFSV4)) {
1440 1.1 dholland NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED);
1441 1.1 dholland len = fxdr_unsigned(int, *tl);
1442 1.1 dholland if (len == 0 && nfs_pubfhset && (nd->nd_flag & ND_NFSV3) &&
1443 1.1 dholland nd->nd_procnum == NFSPROC_LOOKUP) {
1444 1.1 dholland nd->nd_flag |= ND_PUBLOOKUP;
1445 1.1 dholland goto nfsmout;
1446 1.1 dholland }
1447 1.1 dholland if (len < NFSRV_MINFH || len > NFSRV_MAXFH) {
1448 1.1 dholland if (nd->nd_flag & ND_NFSV4) {
1449 1.1 dholland if (len > 0 && len <= NFSX_V4FHMAX) {
1450 1.1 dholland error = nfsm_advance(nd, NFSM_RNDUP(len), -1);
1451 1.1 dholland if (error)
1452 1.1 dholland goto nfsmout;
1453 1.1 dholland nd->nd_repstat = NFSERR_BADHANDLE;
1454 1.1 dholland goto nfsmout;
1455 1.1 dholland } else {
1456 1.1 dholland error = EBADRPC;
1457 1.1 dholland goto nfsmout;
1458 1.1 dholland }
1459 1.1 dholland } else {
1460 1.1 dholland error = EBADRPC;
1461 1.1 dholland goto nfsmout;
1462 1.1 dholland }
1463 1.1 dholland }
1464 1.1 dholland copylen = len;
1465 1.1 dholland } else {
1466 1.1 dholland /*
1467 1.1 dholland * For NFSv2, the file handle is always 32 bytes on the
1468 1.1 dholland * wire, but this server only cares about the first
1469 1.1 dholland * NFSRV_MAXFH bytes.
1470 1.1 dholland */
1471 1.1 dholland len = NFSX_V2FH;
1472 1.1 dholland copylen = NFSRV_MAXFH;
1473 1.1 dholland }
1474 1.1 dholland NFSM_DISSECT(tl, u_int32_t *, len);
1475 1.1 dholland if ((nd->nd_flag & ND_NFSV2) && nfs_pubfhset &&
1476 1.1 dholland nd->nd_procnum == NFSPROC_LOOKUP &&
1477 1.1 dholland !NFSBCMP((caddr_t)tl, nfs_v2pubfh, NFSX_V2FH)) {
1478 1.1 dholland nd->nd_flag |= ND_PUBLOOKUP;
1479 1.1 dholland goto nfsmout;
1480 1.1 dholland }
1481 1.1 dholland NFSBCOPY(tl, (caddr_t)fhp->nfsrvfh_data, copylen);
1482 1.1 dholland fhp->nfsrvfh_len = copylen;
1483 1.1 dholland nfsmout:
1484 1.1 dholland NFSEXITCODE2(error, nd);
1485 1.1 dholland return (error);
1486 1.1 dholland }
1487 1.1 dholland
1488 1.1 dholland /*
1489 1.1 dholland * Map errnos to NFS error numbers. For Version 3 and 4 also filter out error
1490 1.1 dholland * numbers not specified for the associated procedure.
1491 1.1 dholland * NFSPROC_NOOP is a special case, where the high order bits of nd_repstat
1492 1.1 dholland * should be cleared. NFSPROC_NOOP is used to return errors when a valid
1493 1.1 dholland * RPC procedure is not involved.
1494 1.1 dholland * Returns the error number in XDR.
1495 1.1 dholland */
1496 1.1 dholland APPLESTATIC int
1497 1.1 dholland nfsd_errmap(struct nfsrv_descript *nd)
1498 1.1 dholland {
1499 1.1 dholland short *defaulterrp, *errp;
1500 1.1 dholland
1501 1.1 dholland if (!nd->nd_repstat)
1502 1.1 dholland return (0);
1503 1.1 dholland if (nd->nd_flag & (ND_NFSV3 | ND_NFSV4)) {
1504 1.1 dholland if (nd->nd_procnum == NFSPROC_NOOP)
1505 1.1 dholland return (txdr_unsigned(nd->nd_repstat & 0xffff));
1506 1.1 dholland if (nd->nd_flag & ND_NFSV3)
1507 1.1 dholland errp = defaulterrp = nfsrv_v3errmap[nd->nd_procnum];
1508 1.1 dholland else if (nd->nd_repstat == EBADRPC)
1509 1.1 dholland return (txdr_unsigned(NFSERR_BADXDR));
1510 1.1 dholland else if (nd->nd_repstat == NFSERR_MINORVERMISMATCH ||
1511 1.1 dholland nd->nd_repstat == NFSERR_OPILLEGAL)
1512 1.1 dholland return (txdr_unsigned(nd->nd_repstat));
1513 1.3 pgoyette else if ((nd->nd_flag & ND_NFSV41) != 0) {
1514 1.3 pgoyette if (nd->nd_repstat == EOPNOTSUPP)
1515 1.3 pgoyette nd->nd_repstat = NFSERR_NOTSUPP;
1516 1.3 pgoyette nd->nd_repstat = nfsrv_isannfserr(nd->nd_repstat);
1517 1.3 pgoyette return (txdr_unsigned(nd->nd_repstat));
1518 1.3 pgoyette } else
1519 1.1 dholland errp = defaulterrp = nfsrv_v4errmap[nd->nd_procnum];
1520 1.1 dholland while (*++errp)
1521 1.1 dholland if (*errp == nd->nd_repstat)
1522 1.1 dholland return (txdr_unsigned(nd->nd_repstat));
1523 1.1 dholland return (txdr_unsigned(*defaulterrp));
1524 1.1 dholland }
1525 1.3 pgoyette if (nd->nd_repstat <= NFSERR_REMOTE)
1526 1.1 dholland return (txdr_unsigned(nfsrv_v2errmap[nd->nd_repstat - 1]));
1527 1.1 dholland return (txdr_unsigned(NFSERR_IO));
1528 1.1 dholland }
1529 1.1 dholland
1530 1.1 dholland /*
1531 1.3 pgoyette * Check to see if the error is a valid NFS one. If not, replace it with
1532 1.3 pgoyette * NFSERR_IO.
1533 1.3 pgoyette */
1534 1.3 pgoyette static u_int32_t
1535 1.3 pgoyette nfsrv_isannfserr(u_int32_t errval)
1536 1.3 pgoyette {
1537 1.3 pgoyette
1538 1.3 pgoyette if (errval == NFSERR_OK)
1539 1.3 pgoyette return (errval);
1540 1.3 pgoyette if (errval >= NFSERR_BADHANDLE && errval <= NFSERR_DELEGREVOKED)
1541 1.3 pgoyette return (errval);
1542 1.3 pgoyette if (errval > 0 && errval <= NFSERR_REMOTE)
1543 1.3 pgoyette return (nfsrv_v2errmap[errval - 1]);
1544 1.3 pgoyette return (NFSERR_IO);
1545 1.3 pgoyette }
1546 1.3 pgoyette
1547 1.3 pgoyette /*
1548 1.1 dholland * Check to see if setting a uid/gid is permitted when creating a new
1549 1.1 dholland * file object. (Called when uid and/or gid is specified in the
1550 1.1 dholland * settable attributes for V4.
1551 1.1 dholland */
1552 1.1 dholland APPLESTATIC int
1553 1.1 dholland nfsrv_checkuidgid(struct nfsrv_descript *nd, struct nfsvattr *nvap)
1554 1.1 dholland {
1555 1.1 dholland int error = 0;
1556 1.1 dholland
1557 1.1 dholland /*
1558 1.1 dholland * If not setting either uid nor gid, it's OK.
1559 1.1 dholland */
1560 1.1 dholland if (NFSVNO_NOTSETUID(nvap) && NFSVNO_NOTSETGID(nvap))
1561 1.1 dholland goto out;
1562 1.3 pgoyette if ((NFSVNO_ISSETUID(nvap) && nvap->na_uid == nfsrv_defaultuid &&
1563 1.3 pgoyette enable_nobodycheck == 1)
1564 1.3 pgoyette || (NFSVNO_ISSETGID(nvap) && nvap->na_gid == nfsrv_defaultgid &&
1565 1.3 pgoyette enable_nogroupcheck == 1)) {
1566 1.1 dholland error = NFSERR_BADOWNER;
1567 1.1 dholland goto out;
1568 1.1 dholland }
1569 1.1 dholland if (nd->nd_cred->cr_uid == 0)
1570 1.1 dholland goto out;
1571 1.1 dholland if ((NFSVNO_ISSETUID(nvap) && nvap->na_uid != nd->nd_cred->cr_uid) ||
1572 1.1 dholland (NFSVNO_ISSETGID(nvap) && nvap->na_gid != nd->nd_cred->cr_gid &&
1573 1.1 dholland !groupmember(nvap->na_gid, nd->nd_cred)))
1574 1.1 dholland error = NFSERR_PERM;
1575 1.1 dholland
1576 1.1 dholland out:
1577 1.1 dholland NFSEXITCODE2(error, nd);
1578 1.1 dholland return (error);
1579 1.1 dholland }
1580 1.1 dholland
1581 1.1 dholland /*
1582 1.1 dholland * and this routine fixes up the settable attributes for V4 if allowed
1583 1.1 dholland * by nfsrv_checkuidgid().
1584 1.1 dholland */
1585 1.1 dholland APPLESTATIC void
1586 1.1 dholland nfsrv_fixattr(struct nfsrv_descript *nd, vnode_t vp,
1587 1.1 dholland struct nfsvattr *nvap, NFSACL_T *aclp, NFSPROC_T *p, nfsattrbit_t *attrbitp,
1588 1.1 dholland struct nfsexstuff *exp)
1589 1.1 dholland {
1590 1.1 dholland int change = 0;
1591 1.1 dholland struct nfsvattr nva;
1592 1.1 dholland uid_t tuid;
1593 1.1 dholland int error;
1594 1.1 dholland nfsattrbit_t nattrbits;
1595 1.1 dholland
1596 1.1 dholland /*
1597 1.1 dholland * Maybe this should be done for V2 and 3 but it never has been
1598 1.1 dholland * and nobody seems to be upset, so I think it's best not to change
1599 1.1 dholland * the V2 and 3 semantics.
1600 1.1 dholland */
1601 1.1 dholland if ((nd->nd_flag & ND_NFSV4) == 0)
1602 1.1 dholland goto out;
1603 1.1 dholland NFSVNO_ATTRINIT(&nva);
1604 1.1 dholland NFSZERO_ATTRBIT(&nattrbits);
1605 1.1 dholland tuid = nd->nd_cred->cr_uid;
1606 1.1 dholland if (NFSISSET_ATTRBIT(attrbitp, NFSATTRBIT_OWNER) &&
1607 1.1 dholland NFSVNO_ISSETUID(nvap) &&
1608 1.1 dholland nvap->na_uid != nd->nd_cred->cr_uid) {
1609 1.1 dholland if (nd->nd_cred->cr_uid == 0) {
1610 1.1 dholland nva.na_uid = nvap->na_uid;
1611 1.1 dholland change++;
1612 1.1 dholland NFSSETBIT_ATTRBIT(&nattrbits, NFSATTRBIT_OWNER);
1613 1.1 dholland } else {
1614 1.1 dholland NFSCLRBIT_ATTRBIT(attrbitp, NFSATTRBIT_OWNER);
1615 1.1 dholland }
1616 1.1 dholland }
1617 1.1 dholland if (NFSISSET_ATTRBIT(attrbitp, NFSATTRBIT_TIMEACCESSSET) &&
1618 1.1 dholland NFSVNO_ISSETATIME(nvap)) {
1619 1.1 dholland nva.na_atime = nvap->na_atime;
1620 1.1 dholland change++;
1621 1.1 dholland NFSSETBIT_ATTRBIT(&nattrbits, NFSATTRBIT_TIMEACCESSSET);
1622 1.1 dholland }
1623 1.1 dholland if (NFSISSET_ATTRBIT(attrbitp, NFSATTRBIT_TIMEMODIFYSET) &&
1624 1.1 dholland NFSVNO_ISSETMTIME(nvap)) {
1625 1.1 dholland nva.na_mtime = nvap->na_mtime;
1626 1.1 dholland change++;
1627 1.1 dholland NFSSETBIT_ATTRBIT(&nattrbits, NFSATTRBIT_TIMEMODIFYSET);
1628 1.1 dholland }
1629 1.1 dholland if (NFSISSET_ATTRBIT(attrbitp, NFSATTRBIT_OWNERGROUP) &&
1630 1.1 dholland NFSVNO_ISSETGID(nvap)) {
1631 1.1 dholland if (nvap->na_gid == nd->nd_cred->cr_gid ||
1632 1.1 dholland groupmember(nvap->na_gid, nd->nd_cred)) {
1633 1.1 dholland nd->nd_cred->cr_uid = 0;
1634 1.1 dholland nva.na_gid = nvap->na_gid;
1635 1.1 dholland change++;
1636 1.1 dholland NFSSETBIT_ATTRBIT(&nattrbits, NFSATTRBIT_OWNERGROUP);
1637 1.1 dholland } else {
1638 1.1 dholland NFSCLRBIT_ATTRBIT(attrbitp, NFSATTRBIT_OWNERGROUP);
1639 1.1 dholland }
1640 1.1 dholland }
1641 1.1 dholland if (change) {
1642 1.1 dholland error = nfsvno_setattr(vp, &nva, nd->nd_cred, p, exp);
1643 1.1 dholland if (error) {
1644 1.1 dholland NFSCLRALL_ATTRBIT(attrbitp, &nattrbits);
1645 1.1 dholland }
1646 1.1 dholland }
1647 1.1 dholland if (NFSISSET_ATTRBIT(attrbitp, NFSATTRBIT_SIZE) &&
1648 1.1 dholland NFSVNO_ISSETSIZE(nvap) && nvap->na_size != (u_quad_t)0) {
1649 1.1 dholland NFSCLRBIT_ATTRBIT(attrbitp, NFSATTRBIT_SIZE);
1650 1.1 dholland }
1651 1.1 dholland #ifdef NFS4_ACL_EXTATTR_NAME
1652 1.1 dholland if (NFSISSET_ATTRBIT(attrbitp, NFSATTRBIT_ACL) &&
1653 1.1 dholland nfsrv_useacl != 0 && aclp != NULL) {
1654 1.1 dholland if (aclp->acl_cnt > 0) {
1655 1.1 dholland error = nfsrv_setacl(vp, aclp, nd->nd_cred, p);
1656 1.1 dholland if (error) {
1657 1.1 dholland NFSCLRBIT_ATTRBIT(attrbitp, NFSATTRBIT_ACL);
1658 1.1 dholland }
1659 1.1 dholland }
1660 1.1 dholland } else
1661 1.1 dholland #endif
1662 1.1 dholland NFSCLRBIT_ATTRBIT(attrbitp, NFSATTRBIT_ACL);
1663 1.1 dholland nd->nd_cred->cr_uid = tuid;
1664 1.1 dholland
1665 1.1 dholland out:
1666 1.1 dholland NFSEXITCODE2(0, nd);
1667 1.1 dholland }
1668 1.1 dholland
1669 1.1 dholland /*
1670 1.2 snj * Translate an ASCII hex digit to its binary value. Return -1 if the
1671 1.1 dholland * char isn't a hex digit.
1672 1.1 dholland */
1673 1.1 dholland static char
1674 1.1 dholland nfsrv_hexdigit(char c, int *err)
1675 1.1 dholland {
1676 1.1 dholland
1677 1.1 dholland *err = 0;
1678 1.1 dholland if (c >= '0' && c <= '9')
1679 1.1 dholland return (c - '0');
1680 1.1 dholland if (c >= 'a' && c <= 'f')
1681 1.1 dholland return (c - 'a' + ((char)10));
1682 1.1 dholland if (c >= 'A' && c <= 'F')
1683 1.1 dholland return (c - 'A' + ((char)10));
1684 1.1 dholland /* Not valid ! */
1685 1.1 dholland *err = 1;
1686 1.1 dholland return (1); /* BOGUS */
1687 1.1 dholland }
1688 1.1 dholland
1689 1.1 dholland /*
1690 1.1 dholland * Check to see if NFSERR_MOVED can be returned for this op. Return 1 iff
1691 1.1 dholland * it can be.
1692 1.1 dholland */
1693 1.1 dholland APPLESTATIC int
1694 1.1 dholland nfsrv_errmoved(int op)
1695 1.1 dholland {
1696 1.1 dholland short *errp;
1697 1.1 dholland
1698 1.1 dholland errp = nfsrv_v4errmap[op];
1699 1.1 dholland while (*errp != 0) {
1700 1.1 dholland if (*errp == NFSERR_MOVED)
1701 1.1 dholland return (1);
1702 1.1 dholland errp++;
1703 1.1 dholland }
1704 1.1 dholland return (0);
1705 1.1 dholland }
1706 1.1 dholland
1707 1.1 dholland /*
1708 1.1 dholland * Fill in attributes for a Referral.
1709 1.1 dholland * (Return the number of bytes of XDR created.)
1710 1.1 dholland */
1711 1.1 dholland APPLESTATIC int
1712 1.1 dholland nfsrv_putreferralattr(struct nfsrv_descript *nd, nfsattrbit_t *retbitp,
1713 1.1 dholland struct nfsreferral *refp, int getattr, int *reterrp)
1714 1.1 dholland {
1715 1.1 dholland u_int32_t *tl, *retnump;
1716 1.1 dholland u_char *cp, *cp2;
1717 1.1 dholland int prefixnum, retnum = 0, i, len, bitpos, rderrbit = 0, nonrefbit = 0;
1718 1.1 dholland int fslocationsbit = 0;
1719 1.1 dholland nfsattrbit_t tmpbits, refbits;
1720 1.1 dholland
1721 1.1 dholland NFSREFERRAL_ATTRBIT(&refbits);
1722 1.1 dholland if (getattr)
1723 1.1 dholland NFSCLRBIT_ATTRBIT(&refbits, NFSATTRBIT_RDATTRERROR);
1724 1.1 dholland else if (NFSISSET_ATTRBIT(retbitp, NFSATTRBIT_RDATTRERROR))
1725 1.1 dholland rderrbit = 1;
1726 1.1 dholland if (NFSISSET_ATTRBIT(retbitp, NFSATTRBIT_FSLOCATIONS))
1727 1.1 dholland fslocationsbit = 1;
1728 1.1 dholland
1729 1.1 dholland /*
1730 1.1 dholland * Check for the case where unsupported referral attributes are
1731 1.1 dholland * requested.
1732 1.1 dholland */
1733 1.1 dholland NFSSET_ATTRBIT(&tmpbits, retbitp);
1734 1.1 dholland NFSCLRALL_ATTRBIT(&tmpbits, &refbits);
1735 1.1 dholland if (NFSNONZERO_ATTRBIT(&tmpbits))
1736 1.1 dholland nonrefbit = 1;
1737 1.1 dholland
1738 1.1 dholland if (nonrefbit && !fslocationsbit && (getattr || !rderrbit)) {
1739 1.1 dholland *reterrp = NFSERR_MOVED;
1740 1.1 dholland return (0);
1741 1.1 dholland }
1742 1.1 dholland
1743 1.1 dholland /*
1744 1.1 dholland * Now we can fill in the attributes.
1745 1.1 dholland */
1746 1.1 dholland NFSSET_ATTRBIT(&tmpbits, retbitp);
1747 1.1 dholland NFSCLRNOT_ATTRBIT(&tmpbits, &refbits);
1748 1.1 dholland
1749 1.1 dholland /*
1750 1.1 dholland * Put out the attribute bitmap for the ones being filled in
1751 1.1 dholland * and get the field for the number of attributes returned.
1752 1.1 dholland */
1753 1.1 dholland prefixnum = nfsrv_putattrbit(nd, &tmpbits);
1754 1.1 dholland NFSM_BUILD(retnump, u_int32_t *, NFSX_UNSIGNED);
1755 1.1 dholland prefixnum += NFSX_UNSIGNED;
1756 1.1 dholland
1757 1.1 dholland /*
1758 1.1 dholland * Now, loop around filling in the attributes for each bit set.
1759 1.1 dholland */
1760 1.1 dholland for (bitpos = 0; bitpos < NFSATTRBIT_MAX; bitpos++) {
1761 1.1 dholland if (NFSISSET_ATTRBIT(&tmpbits, bitpos)) {
1762 1.1 dholland switch (bitpos) {
1763 1.1 dholland case NFSATTRBIT_TYPE:
1764 1.1 dholland NFSM_BUILD(tl, u_int32_t *, NFSX_UNSIGNED);
1765 1.1 dholland *tl = txdr_unsigned(NFDIR);
1766 1.1 dholland retnum += NFSX_UNSIGNED;
1767 1.1 dholland break;
1768 1.1 dholland case NFSATTRBIT_FSID:
1769 1.1 dholland NFSM_BUILD(tl, u_int32_t *, NFSX_V4FSID);
1770 1.1 dholland *tl++ = 0;
1771 1.1 dholland *tl++ = txdr_unsigned(NFSV4ROOT_FSID0);
1772 1.1 dholland *tl++ = 0;
1773 1.1 dholland *tl = txdr_unsigned(NFSV4ROOT_REFERRAL);
1774 1.1 dholland retnum += NFSX_V4FSID;
1775 1.1 dholland break;
1776 1.1 dholland case NFSATTRBIT_RDATTRERROR:
1777 1.1 dholland NFSM_BUILD(tl, u_int32_t *, NFSX_UNSIGNED);
1778 1.1 dholland if (nonrefbit)
1779 1.1 dholland *tl = txdr_unsigned(NFSERR_MOVED);
1780 1.1 dholland else
1781 1.1 dholland *tl = 0;
1782 1.1 dholland retnum += NFSX_UNSIGNED;
1783 1.1 dholland break;
1784 1.1 dholland case NFSATTRBIT_FSLOCATIONS:
1785 1.1 dholland retnum += nfsm_strtom(nd, "/", 1);
1786 1.1 dholland NFSM_BUILD(tl, u_int32_t *, NFSX_UNSIGNED);
1787 1.1 dholland *tl = txdr_unsigned(refp->nfr_srvcnt);
1788 1.1 dholland retnum += NFSX_UNSIGNED;
1789 1.1 dholland cp = refp->nfr_srvlist;
1790 1.1 dholland for (i = 0; i < refp->nfr_srvcnt; i++) {
1791 1.1 dholland NFSM_BUILD(tl, u_int32_t *, NFSX_UNSIGNED);
1792 1.1 dholland *tl = txdr_unsigned(1);
1793 1.1 dholland retnum += NFSX_UNSIGNED;
1794 1.1 dholland cp2 = STRCHR(cp, ':');
1795 1.1 dholland if (cp2 != NULL)
1796 1.1 dholland len = cp2 - cp;
1797 1.1 dholland else
1798 1.1 dholland len = 1;
1799 1.1 dholland retnum += nfsm_strtom(nd, cp, len);
1800 1.1 dholland if (cp2 != NULL)
1801 1.1 dholland cp = cp2 + 1;
1802 1.1 dholland cp2 = STRCHR(cp, ',');
1803 1.1 dholland if (cp2 != NULL)
1804 1.1 dholland len = cp2 - cp;
1805 1.1 dholland else
1806 1.1 dholland len = strlen(cp);
1807 1.1 dholland retnum += nfsm_strtom(nd, cp, len);
1808 1.1 dholland if (cp2 != NULL)
1809 1.1 dholland cp = cp2 + 1;
1810 1.1 dholland }
1811 1.1 dholland break;
1812 1.1 dholland case NFSATTRBIT_MOUNTEDONFILEID:
1813 1.1 dholland NFSM_BUILD(tl, u_int32_t *, NFSX_HYPER);
1814 1.1 dholland *tl++ = 0;
1815 1.1 dholland *tl = txdr_unsigned(refp->nfr_dfileno);
1816 1.1 dholland retnum += NFSX_HYPER;
1817 1.1 dholland break;
1818 1.1 dholland default:
1819 1.1 dholland printf("EEK! Bad V4 refattr bitpos=%d\n", bitpos);
1820 1.3 pgoyette }
1821 1.1 dholland }
1822 1.1 dholland }
1823 1.1 dholland *retnump = txdr_unsigned(retnum);
1824 1.1 dholland return (retnum + prefixnum);
1825 1.1 dholland }
1826 1.1 dholland
1827 1.1 dholland /*
1828 1.1 dholland * Parse a file name out of a request.
1829 1.1 dholland */
1830 1.1 dholland APPLESTATIC int
1831 1.1 dholland nfsrv_parsename(struct nfsrv_descript *nd, char *bufp, u_long *hashp,
1832 1.1 dholland NFSPATHLEN_T *outlenp)
1833 1.1 dholland {
1834 1.1 dholland char *fromcp, *tocp, val = '\0';
1835 1.1 dholland mbuf_t md;
1836 1.1 dholland int i;
1837 1.1 dholland int rem, len, error = 0, pubtype = 0, outlen = 0, percent = 0;
1838 1.1 dholland char digit;
1839 1.1 dholland u_int32_t *tl;
1840 1.1 dholland u_long hash = 0;
1841 1.1 dholland
1842 1.1 dholland if (hashp != NULL)
1843 1.1 dholland *hashp = 0;
1844 1.1 dholland tocp = bufp;
1845 1.1 dholland /*
1846 1.1 dholland * For V4, check for lookup parent.
1847 1.1 dholland * Otherwise, get the component name.
1848 1.1 dholland */
1849 1.1 dholland if ((nd->nd_flag & ND_NFSV4) && nd->nd_procnum == NFSV4OP_LOOKUPP) {
1850 1.1 dholland *tocp++ = '.';
1851 1.1 dholland hash += ((u_char)'.');
1852 1.1 dholland *tocp++ = '.';
1853 1.1 dholland hash += ((u_char)'.');
1854 1.1 dholland outlen = 2;
1855 1.1 dholland } else {
1856 1.1 dholland /*
1857 1.1 dholland * First, get the name length.
1858 1.1 dholland */
1859 1.1 dholland NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED);
1860 1.1 dholland len = fxdr_unsigned(int, *tl);
1861 1.1 dholland if (len > NFS_MAXNAMLEN) {
1862 1.1 dholland nd->nd_repstat = NFSERR_NAMETOL;
1863 1.1 dholland error = 0;
1864 1.1 dholland goto nfsmout;
1865 1.1 dholland } else if (len <= 0) {
1866 1.1 dholland nd->nd_repstat = NFSERR_INVAL;
1867 1.1 dholland error = 0;
1868 1.1 dholland goto nfsmout;
1869 1.1 dholland }
1870 1.1 dholland
1871 1.1 dholland /*
1872 1.1 dholland * Now, copy the component name into the buffer.
1873 1.1 dholland */
1874 1.1 dholland fromcp = nd->nd_dpos;
1875 1.1 dholland md = nd->nd_md;
1876 1.1 dholland rem = NFSMTOD(md, caddr_t) + mbuf_len(md) - fromcp;
1877 1.1 dholland for (i = 0; i < len; i++) {
1878 1.1 dholland while (rem == 0) {
1879 1.1 dholland md = mbuf_next(md);
1880 1.1 dholland if (md == NULL) {
1881 1.1 dholland error = EBADRPC;
1882 1.1 dholland goto nfsmout;
1883 1.1 dholland }
1884 1.1 dholland fromcp = NFSMTOD(md, caddr_t);
1885 1.1 dholland rem = mbuf_len(md);
1886 1.1 dholland }
1887 1.1 dholland if (*fromcp == '\0') {
1888 1.1 dholland nd->nd_repstat = EACCES;
1889 1.1 dholland error = 0;
1890 1.1 dholland goto nfsmout;
1891 1.1 dholland }
1892 1.1 dholland /*
1893 1.1 dholland * For lookups on the public filehandle, do some special
1894 1.1 dholland * processing on the name. (The public file handle is the
1895 1.1 dholland * root of the public file system for this server.)
1896 1.1 dholland */
1897 1.1 dholland if (nd->nd_flag & ND_PUBLOOKUP) {
1898 1.1 dholland /*
1899 1.1 dholland * If the first char is ASCII, it is a canonical
1900 1.1 dholland * path, otherwise it is a native path. (RFC2054
1901 1.1 dholland * doesn't actually state what it is if the first
1902 1.1 dholland * char isn't ASCII or 0x80, so I assume native.)
1903 1.1 dholland * pubtype == 1 -> native path
1904 1.1 dholland * pubtype == 2 -> canonical path
1905 1.1 dholland */
1906 1.1 dholland if (i == 0) {
1907 1.1 dholland if (*fromcp & 0x80) {
1908 1.1 dholland /*
1909 1.1 dholland * Since RFC2054 doesn't indicate
1910 1.1 dholland * that a native path of just 0x80
1911 1.1 dholland * isn't allowed, I'll replace the
1912 1.1 dholland * 0x80 with '/' instead of just
1913 1.1 dholland * throwing it away.
1914 1.1 dholland */
1915 1.1 dholland *fromcp = '/';
1916 1.1 dholland pubtype = 1;
1917 1.1 dholland } else {
1918 1.1 dholland pubtype = 2;
1919 1.1 dholland }
1920 1.1 dholland }
1921 1.1 dholland /*
1922 1.1 dholland * '/' only allowed in a native path
1923 1.1 dholland */
1924 1.1 dholland if (*fromcp == '/' && pubtype != 1) {
1925 1.1 dholland nd->nd_repstat = EACCES;
1926 1.1 dholland error = 0;
1927 1.1 dholland goto nfsmout;
1928 1.1 dholland }
1929 1.1 dholland
1930 1.1 dholland /*
1931 1.1 dholland * For the special case of 2 hex digits after a
1932 1.1 dholland * '%' in an absolute path, calculate the value.
1933 1.1 dholland * percent == 1 -> indicates "get first hex digit"
1934 1.1 dholland * percent == 2 -> indicates "get second hex digit"
1935 1.1 dholland */
1936 1.1 dholland if (percent > 0) {
1937 1.1 dholland digit = nfsrv_hexdigit(*fromcp, &error);
1938 1.1 dholland if (error) {
1939 1.1 dholland nd->nd_repstat = EACCES;
1940 1.1 dholland error = 0;
1941 1.1 dholland goto nfsmout;
1942 1.1 dholland }
1943 1.1 dholland if (percent == 1) {
1944 1.1 dholland val = (digit << 4);
1945 1.1 dholland percent = 2;
1946 1.1 dholland } else {
1947 1.1 dholland val += digit;
1948 1.1 dholland percent = 0;
1949 1.1 dholland *tocp++ = val;
1950 1.1 dholland hash += ((u_char)val);
1951 1.1 dholland outlen++;
1952 1.1 dholland }
1953 1.1 dholland } else {
1954 1.1 dholland if (*fromcp == '%' && pubtype == 2) {
1955 1.1 dholland /*
1956 1.1 dholland * Must be followed by 2 hex digits
1957 1.1 dholland */
1958 1.1 dholland if ((len - i) < 3) {
1959 1.1 dholland nd->nd_repstat = EACCES;
1960 1.1 dholland error = 0;
1961 1.1 dholland goto nfsmout;
1962 1.1 dholland }
1963 1.1 dholland percent = 1;
1964 1.1 dholland } else {
1965 1.1 dholland *tocp++ = *fromcp;
1966 1.1 dholland hash += ((u_char)*fromcp);
1967 1.1 dholland outlen++;
1968 1.1 dholland }
1969 1.1 dholland }
1970 1.1 dholland } else {
1971 1.1 dholland /*
1972 1.1 dholland * Normal, non lookup on public, name.
1973 1.1 dholland */
1974 1.1 dholland if (*fromcp == '/') {
1975 1.1 dholland if (nd->nd_flag & ND_NFSV4)
1976 1.1 dholland nd->nd_repstat = NFSERR_BADNAME;
1977 1.1 dholland else
1978 1.1 dholland nd->nd_repstat = EACCES;
1979 1.1 dholland error = 0;
1980 1.1 dholland goto nfsmout;
1981 1.1 dholland }
1982 1.1 dholland hash += ((u_char)*fromcp);
1983 1.1 dholland *tocp++ = *fromcp;
1984 1.1 dholland outlen++;
1985 1.1 dholland }
1986 1.1 dholland fromcp++;
1987 1.1 dholland rem--;
1988 1.1 dholland }
1989 1.1 dholland nd->nd_md = md;
1990 1.1 dholland nd->nd_dpos = fromcp;
1991 1.1 dholland i = NFSM_RNDUP(len) - len;
1992 1.1 dholland if (i > 0) {
1993 1.1 dholland if (rem >= i) {
1994 1.1 dholland nd->nd_dpos += i;
1995 1.1 dholland } else {
1996 1.1 dholland error = nfsm_advance(nd, i, rem);
1997 1.1 dholland if (error)
1998 1.1 dholland goto nfsmout;
1999 1.1 dholland }
2000 1.1 dholland }
2001 1.1 dholland
2002 1.1 dholland /*
2003 1.1 dholland * For v4, don't allow lookups of '.' or '..' and
2004 1.1 dholland * also check for non-utf8 strings.
2005 1.1 dholland */
2006 1.1 dholland if (nd->nd_flag & ND_NFSV4) {
2007 1.1 dholland if ((outlen == 1 && bufp[0] == '.') ||
2008 1.1 dholland (outlen == 2 && bufp[0] == '.' &&
2009 1.1 dholland bufp[1] == '.')) {
2010 1.1 dholland nd->nd_repstat = NFSERR_BADNAME;
2011 1.1 dholland error = 0;
2012 1.1 dholland goto nfsmout;
2013 1.1 dholland }
2014 1.3 pgoyette if (enable_checkutf8 == 1 &&
2015 1.1 dholland nfsrv_checkutf8((u_int8_t *)bufp, outlen)) {
2016 1.1 dholland nd->nd_repstat = NFSERR_INVAL;
2017 1.1 dholland error = 0;
2018 1.1 dholland goto nfsmout;
2019 1.1 dholland }
2020 1.1 dholland }
2021 1.1 dholland }
2022 1.1 dholland *tocp = '\0';
2023 1.1 dholland *outlenp = (size_t)outlen;
2024 1.1 dholland if (hashp != NULL)
2025 1.1 dholland *hashp = hash;
2026 1.1 dholland nfsmout:
2027 1.1 dholland NFSEXITCODE2(error, nd);
2028 1.1 dholland return (error);
2029 1.1 dholland }
2030 1.1 dholland
2031 1.1 dholland void
2032 1.1 dholland nfsd_init(void)
2033 1.1 dholland {
2034 1.1 dholland int i;
2035 1.1 dholland static int inited = 0;
2036 1.1 dholland
2037 1.1 dholland if (inited)
2038 1.1 dholland return;
2039 1.1 dholland inited = 1;
2040 1.1 dholland
2041 1.1 dholland /*
2042 1.1 dholland * Initialize client queues. Don't free/reinitialize
2043 1.1 dholland * them when nfsds are restarted.
2044 1.1 dholland */
2045 1.3 pgoyette nfsclienthash = malloc(sizeof(struct nfsclienthashhead) *
2046 1.3 pgoyette nfsrv_clienthashsize, M_NFSDCLIENT, M_WAITOK | M_ZERO);
2047 1.3 pgoyette for (i = 0; i < nfsrv_clienthashsize; i++)
2048 1.1 dholland LIST_INIT(&nfsclienthash[i]);
2049 1.3 pgoyette nfslockhash = malloc(sizeof(struct nfslockhashhead) *
2050 1.3 pgoyette nfsrv_lockhashsize, M_NFSDLOCKFILE, M_WAITOK | M_ZERO);
2051 1.3 pgoyette for (i = 0; i < nfsrv_lockhashsize; i++)
2052 1.1 dholland LIST_INIT(&nfslockhash[i]);
2053 1.3 pgoyette nfssessionhash = malloc(sizeof(struct nfssessionhash) *
2054 1.3 pgoyette nfsrv_sessionhashsize, M_NFSDSESSION, M_WAITOK | M_ZERO);
2055 1.3 pgoyette for (i = 0; i < nfsrv_sessionhashsize; i++) {
2056 1.3 pgoyette mtx_init(&nfssessionhash[i].mtx, "nfssm", NULL, MTX_DEF);
2057 1.3 pgoyette LIST_INIT(&nfssessionhash[i].list);
2058 1.3 pgoyette }
2059 1.1 dholland
2060 1.1 dholland /* and the v2 pubfh should be all zeros */
2061 1.1 dholland NFSBZERO(nfs_v2pubfh, NFSX_V2FH);
2062 1.1 dholland }
2063 1.1 dholland
2064 1.1 dholland /*
2065 1.1 dholland * Check the v4 root exports.
2066 1.1 dholland * Return 0 if ok, 1 otherwise.
2067 1.1 dholland */
2068 1.1 dholland int
2069 1.1 dholland nfsd_checkrootexp(struct nfsrv_descript *nd)
2070 1.1 dholland {
2071 1.1 dholland
2072 1.1 dholland if ((nd->nd_flag & (ND_GSS | ND_EXAUTHSYS)) == ND_EXAUTHSYS)
2073 1.1 dholland return (0);
2074 1.1 dholland if ((nd->nd_flag & (ND_GSSINTEGRITY | ND_EXGSSINTEGRITY)) ==
2075 1.1 dholland (ND_GSSINTEGRITY | ND_EXGSSINTEGRITY))
2076 1.1 dholland return (0);
2077 1.1 dholland if ((nd->nd_flag & (ND_GSSPRIVACY | ND_EXGSSPRIVACY)) ==
2078 1.1 dholland (ND_GSSPRIVACY | ND_EXGSSPRIVACY))
2079 1.1 dholland return (0);
2080 1.1 dholland if ((nd->nd_flag & (ND_GSS | ND_GSSINTEGRITY | ND_GSSPRIVACY |
2081 1.1 dholland ND_EXGSS)) == (ND_GSS | ND_EXGSS))
2082 1.1 dholland return (0);
2083 1.1 dholland return (1);
2084 1.1 dholland }
2085 1.1 dholland
2086 1.3 pgoyette /*
2087 1.3 pgoyette * Parse the first part of an NFSv4 compound to find out what the minor
2088 1.3 pgoyette * version# is.
2089 1.3 pgoyette */
2090 1.3 pgoyette void
2091 1.3 pgoyette nfsd_getminorvers(struct nfsrv_descript *nd, u_char *tag, u_char **tagstrp,
2092 1.3 pgoyette int *taglenp, u_int32_t *minversp)
2093 1.3 pgoyette {
2094 1.3 pgoyette uint32_t *tl;
2095 1.3 pgoyette int error = 0, taglen = -1;
2096 1.3 pgoyette u_char *tagstr = NULL;
2097 1.3 pgoyette
2098 1.3 pgoyette NFSM_DISSECT(tl, uint32_t *, NFSX_UNSIGNED);
2099 1.3 pgoyette taglen = fxdr_unsigned(int, *tl);
2100 1.3 pgoyette if (taglen < 0 || taglen > NFSV4_OPAQUELIMIT) {
2101 1.3 pgoyette error = EBADRPC;
2102 1.3 pgoyette goto nfsmout;
2103 1.3 pgoyette }
2104 1.3 pgoyette if (taglen <= NFSV4_SMALLSTR)
2105 1.3 pgoyette tagstr = tag;
2106 1.3 pgoyette else
2107 1.3 pgoyette tagstr = malloc(taglen + 1, M_TEMP, M_WAITOK);
2108 1.3 pgoyette error = nfsrv_mtostr(nd, tagstr, taglen);
2109 1.3 pgoyette if (error != 0)
2110 1.3 pgoyette goto nfsmout;
2111 1.3 pgoyette NFSM_DISSECT(tl, uint32_t *, NFSX_UNSIGNED);
2112 1.3 pgoyette *minversp = fxdr_unsigned(u_int32_t, *tl);
2113 1.3 pgoyette *tagstrp = tagstr;
2114 1.3 pgoyette if (*minversp == NFSV41_MINORVERSION)
2115 1.3 pgoyette nd->nd_flag |= ND_NFSV41;
2116 1.3 pgoyette nfsmout:
2117 1.3 pgoyette if (error != 0) {
2118 1.3 pgoyette if (tagstr != NULL && taglen > NFSV4_SMALLSTR)
2119 1.3 pgoyette free(tagstr, M_TEMP);
2120 1.3 pgoyette taglen = -1;
2121 1.3 pgoyette }
2122 1.3 pgoyette *taglenp = taglen;
2123 1.3 pgoyette }
2124 1.3 pgoyette
2125