drop net-snmp dep
[unleashed.git] / kernel / fs / nfs / nfs_acl_xdr.c
blob5044c86b22295f80aeab2b4bf0be6b334f416530
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
22 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #pragma ident "%Z%%M% %I% %E% SMI"
29 #include <sys/param.h>
30 #include <sys/types.h>
31 #include <sys/systm.h>
32 #include <sys/user.h>
33 #include <sys/vnode.h>
34 #include <sys/file.h>
35 #include <sys/dirent.h>
36 #include <sys/vfs.h>
37 #include <sys/stream.h>
38 #include <sys/strsubr.h>
39 #include <sys/debug.h>
40 #include <sys/t_lock.h>
41 #include <sys/acl.h>
43 #include <rpc/types.h>
44 #include <rpc/xdr.h>
46 #include <nfs/nfs.h>
47 #include <nfs/nfs_clnt.h>
48 #include <nfs/nfs_acl.h>
51 * These are the XDR routines used to serialize and deserialize
52 * the various structures passed as parameters accross the network
53 * between ACL clients and servers.
56 bool_t
57 xdr_uid(XDR *xdrs, uid32_t *objp)
59 if (!xdr_u_int(xdrs, objp))
60 return (FALSE);
61 return (TRUE);
64 bool_t
65 xdr_o_mode(XDR *xdrs, o_mode *objp)
68 if (!xdr_u_short(xdrs, (ushort_t *)objp))
69 return (FALSE);
70 return (TRUE);
73 bool_t
74 xdr_aclent(XDR *xdrs, aclent_t *objp)
77 if (!xdr_int(xdrs, &objp->a_type))
78 return (FALSE);
79 if (!xdr_uid(xdrs, &objp->a_id))
80 return (FALSE);
81 if (!xdr_o_mode(xdrs, &objp->a_perm))
82 return (FALSE);
83 return (TRUE);
86 bool_t
87 xdr_secattr(XDR *xdrs, vsecattr_t *objp)
89 uint_t count;
91 if (!xdr_u_int(xdrs, &objp->vsa_mask))
92 return (FALSE);
93 if (!xdr_int(xdrs, &objp->vsa_aclcnt))
94 return (FALSE);
95 if (objp->vsa_aclentp != NULL)
96 count = (uint_t)objp->vsa_aclcnt;
97 else
98 count = 0;
99 if (!xdr_array(xdrs, (char **)&objp->vsa_aclentp, &count,
100 NFS_ACL_MAX_ENTRIES, sizeof (aclent_t), (xdrproc_t)xdr_aclent))
101 return (FALSE);
102 if (count != 0 && count != (uint_t)objp->vsa_aclcnt) {
104 * Assign the actual array size to vsa_aclcnt before
105 * aborting on error
107 objp->vsa_aclcnt = (int)count;
108 return (FALSE);
110 if (!xdr_int(xdrs, &objp->vsa_dfaclcnt))
111 return (FALSE);
112 if (objp->vsa_dfaclentp != NULL)
113 count = (uint_t)objp->vsa_dfaclcnt;
114 else
115 count = 0;
116 if (!xdr_array(xdrs, (char **)&objp->vsa_dfaclentp, &count,
117 NFS_ACL_MAX_ENTRIES, sizeof (aclent_t), (xdrproc_t)xdr_aclent))
118 return (FALSE);
119 if (count != 0 && count != (uint_t)objp->vsa_dfaclcnt) {
121 * Assign the actual array size to vsa_dfaclcnt before
122 * aborting on error
124 objp->vsa_dfaclcnt = (int)count;
125 return (FALSE);
127 return (TRUE);
130 bool_t
131 xdr_GETACL2args(XDR *xdrs, GETACL2args *objp)
134 if (!xdr_fhandle(xdrs, &objp->fh))
135 return (FALSE);
136 if (!xdr_u_int(xdrs, &objp->mask))
137 return (FALSE);
138 return (TRUE);
140 bool_t
141 xdr_fastGETACL2args(XDR *xdrs, GETACL2args **objpp)
143 int32_t *ptr;
144 #ifdef _LITTLE_ENDIAN
145 GETACL2args *objp;
146 #endif
148 if (xdrs->x_op != XDR_DECODE)
149 return (FALSE);
151 ptr = XDR_INLINE(xdrs, RNDUP(sizeof (GETACL2args)));
152 if (ptr != NULL) {
153 *objpp = (GETACL2args *)ptr;
154 #ifdef _LITTLE_ENDIAN
155 objp = (GETACL2args *)ptr;
156 objp->mask = ntohl(objp->mask);
157 #endif
158 return (TRUE);
161 return (FALSE);
164 bool_t
165 xdr_GETACL2resok(XDR *xdrs, GETACL2resok *objp)
168 if (!xdr_fattr(xdrs, &objp->attr))
169 return (FALSE);
170 if (!xdr_secattr(xdrs, &objp->acl))
171 return (FALSE);
172 return (TRUE);
175 bool_t
176 xdr_GETACL2res(XDR *xdrs, GETACL2res *objp)
179 if (!xdr_enum(xdrs, (enum_t *)&objp->status))
180 return (FALSE);
181 switch (objp->status) {
182 case NFS_OK:
183 if (!xdr_GETACL2resok(xdrs, &objp->resok))
184 return (FALSE);
185 break;
187 return (TRUE);
190 bool_t
191 xdr_SETACL2args(XDR *xdrs, SETACL2args *objp)
194 if (!xdr_fhandle(xdrs, &objp->fh))
195 return (FALSE);
196 if (!xdr_secattr(xdrs, &objp->acl))
197 return (FALSE);
198 return (TRUE);
201 bool_t
202 xdr_SETACL2resok(XDR *xdrs, SETACL2resok *objp)
205 if (!xdr_fattr(xdrs, &objp->attr))
206 return (FALSE);
207 return (TRUE);
209 #ifdef _LITTLE_ENDIAN
210 bool_t
211 xdr_fastSETACL2resok(XDR *xdrs, SETACL2resok *objp)
214 if (!xdr_fastfattr(xdrs, &objp->attr))
215 return (FALSE);
216 return (TRUE);
218 #endif
220 bool_t
221 xdr_SETACL2res(XDR *xdrs, SETACL2res *objp)
224 if (!xdr_enum(xdrs, (enum_t *)&objp->status))
225 return (FALSE);
226 switch (objp->status) {
227 case NFS_OK:
228 if (!xdr_SETACL2resok(xdrs, &objp->resok))
229 return (FALSE);
230 break;
232 return (TRUE);
234 #ifdef _LITTLE_ENDIAN
235 bool_t
236 xdr_fastSETACL2res(XDR *xdrs, SETACL2res *objp)
239 if (!xdr_fastenum(xdrs, (enum_t *)&objp->status))
240 return (FALSE);
241 switch (objp->status) {
242 case NFS_OK:
243 if (!xdr_fastSETACL2resok(xdrs, &objp->resok))
244 return (FALSE);
245 break;
247 return (TRUE);
249 #endif
251 bool_t
252 xdr_GETATTR2args(XDR *xdrs, GETATTR2args *objp)
255 if (!xdr_fhandle(xdrs, &objp->fh))
256 return (FALSE);
257 return (TRUE);
259 bool_t
260 xdr_fastGETATTR2args(XDR *xdrs, GETATTR2args **objpp)
262 int32_t *ptr;
264 if (xdrs->x_op != XDR_DECODE)
265 return (FALSE);
267 ptr = XDR_INLINE(xdrs, RNDUP(sizeof (GETATTR2args)));
268 if (ptr != NULL) {
269 *objpp = (GETATTR2args *)ptr;
270 return (TRUE);
273 return (FALSE);
276 bool_t
277 xdr_GETATTR2resok(XDR *xdrs, GETATTR2resok *objp)
280 if (!xdr_fattr(xdrs, &objp->attr))
281 return (FALSE);
282 return (TRUE);
284 #ifdef _LITTLE_ENDIAN
285 bool_t
286 xdr_fastGETATTR2resok(XDR *xdrs, GETATTR2resok *objp)
289 if (!xdr_fastfattr(xdrs, &objp->attr))
290 return (FALSE);
291 return (TRUE);
293 #endif
295 bool_t
296 xdr_GETATTR2res(XDR *xdrs, GETATTR2res *objp)
299 if (!xdr_enum(xdrs, (enum_t *)&objp->status))
300 return (FALSE);
301 switch (objp->status) {
302 case NFS_OK:
303 if (!xdr_GETATTR2resok(xdrs, &objp->resok))
304 return (FALSE);
305 break;
307 return (TRUE);
309 #ifdef _LITTLE_ENDIAN
310 bool_t
311 xdr_fastGETATTR2res(XDR *xdrs, GETATTR2res *objp)
314 if (!xdr_fastenum(xdrs, (enum_t *)&objp->status))
315 return (FALSE);
316 switch (objp->status) {
317 case NFS_OK:
318 if (!xdr_fastGETATTR2resok(xdrs, &objp->resok))
319 return (FALSE);
320 break;
322 return (TRUE);
324 #endif
326 bool_t
327 xdr_ACCESS2args(XDR *xdrs, ACCESS2args *objp)
330 if (!xdr_fhandle(xdrs, &objp->fh))
331 return (FALSE);
332 if (!xdr_uint32(xdrs, &objp->access))
333 return (FALSE);
334 return (TRUE);
336 bool_t
337 xdr_fastACCESS2args(XDR *xdrs, ACCESS2args **objpp)
339 int32_t *ptr;
340 #ifdef _LITTLE_ENDIAN
341 ACCESS2args *objp;
342 #endif
344 if (xdrs->x_op != XDR_DECODE)
345 return (FALSE);
347 ptr = XDR_INLINE(xdrs, RNDUP(sizeof (ACCESS2args)));
348 if (ptr != NULL) {
349 *objpp = (ACCESS2args *)ptr;
350 #ifdef _LITTLE_ENDIAN
351 objp = (ACCESS2args *)ptr;
352 objp->access = ntohl(objp->access);
353 #endif
354 return (TRUE);
357 return (FALSE);
360 bool_t
361 xdr_ACCESS2resok(XDR *xdrs, ACCESS2resok *objp)
364 if (!xdr_fattr(xdrs, &objp->attr))
365 return (FALSE);
366 if (!xdr_uint32(xdrs, &objp->access))
367 return (FALSE);
368 return (TRUE);
370 #ifdef _LITTLE_ENDIAN
371 bool_t
372 xdr_fastACCESS2resok(XDR *xdrs, ACCESS2resok *objp)
375 if (!xdr_fastfattr(xdrs, &objp->attr))
376 return (FALSE);
377 objp->access = ntohl(objp->access);
378 return (TRUE);
380 #endif
382 bool_t
383 xdr_ACCESS2res(XDR *xdrs, ACCESS2res *objp)
386 if (!xdr_enum(xdrs, (enum_t *)&objp->status))
387 return (FALSE);
388 switch (objp->status) {
389 case NFS_OK:
390 if (!xdr_ACCESS2resok(xdrs, &objp->resok))
391 return (FALSE);
392 break;
394 return (TRUE);
396 #ifdef _LITTLE_ENDIAN
397 bool_t
398 xdr_fastACCESS2res(XDR *xdrs, ACCESS2res *objp)
401 if (!xdr_fastenum(xdrs, (enum_t *)&objp->status))
402 return (FALSE);
403 switch (objp->status) {
404 case NFS_OK:
405 if (!xdr_fastACCESS2resok(xdrs, &objp->resok))
406 return (FALSE);
407 break;
409 return (TRUE);
411 #endif
413 bool_t
414 xdr_GETXATTRDIR2args(XDR *xdrs, GETXATTRDIR2args *objp)
416 if (!xdr_fhandle(xdrs, &objp->fh))
417 return (FALSE);
418 if (!xdr_bool(xdrs, &objp->create))
419 return (FALSE);
420 return (TRUE);
423 bool_t
424 xdr_GETXATTRDIR2resok(XDR *xdrs, GETXATTRDIR2resok *objp)
426 if (!xdr_fhandle(xdrs, &objp->fh))
427 return (FALSE);
428 if (!xdr_fattr(xdrs, &objp->attr))
429 return (FALSE);
430 return (TRUE);
433 bool_t
434 xdr_GETXATTRDIR2res(XDR *xdrs, GETXATTRDIR2res *objp)
436 if (!xdr_enum(xdrs, (enum_t *)&objp->status))
437 return (FALSE);
438 switch (objp->status) {
439 case NFS_OK:
440 if (!xdr_GETXATTRDIR2resok(xdrs, &objp->resok))
441 return (FALSE);
442 break;
444 return (TRUE);
447 bool_t
448 xdr_GETACL3args(XDR *xdrs, GETACL3args *objp)
451 switch (xdrs->x_op) {
452 case XDR_FREE:
453 case XDR_ENCODE:
454 if (!xdr_nfs_fh3(xdrs, &objp->fh))
455 return (FALSE);
456 break;
457 case XDR_DECODE:
458 if (!xdr_nfs_fh3_server(xdrs, &objp->fh))
459 return (FALSE);
460 break;
462 if (!xdr_u_int(xdrs, &objp->mask))
463 return (FALSE);
464 return (TRUE);
467 bool_t
468 xdr_GETACL3resok(XDR *xdrs, GETACL3resok *objp)
471 if (!xdr_post_op_attr(xdrs, &objp->attr))
472 return (FALSE);
473 if (!xdr_secattr(xdrs, &objp->acl))
474 return (FALSE);
475 return (TRUE);
478 bool_t
479 xdr_GETACL3resfail(XDR *xdrs, GETACL3resfail *objp)
482 if (!xdr_post_op_attr(xdrs, &objp->attr))
483 return (FALSE);
484 return (TRUE);
487 bool_t
488 xdr_GETACL3res(XDR *xdrs, GETACL3res *objp)
491 if (!xdr_enum(xdrs, (enum_t *)&objp->status))
492 return (FALSE);
493 switch (objp->status) {
494 case NFS3_OK:
495 if (!xdr_GETACL3resok(xdrs, &objp->resok))
496 return (FALSE);
497 break;
498 default:
499 if (!xdr_GETACL3resfail(xdrs, &objp->resfail))
500 return (FALSE);
501 break;
503 return (TRUE);
506 bool_t
507 xdr_SETACL3args(XDR *xdrs, SETACL3args *objp)
510 switch (xdrs->x_op) {
511 case XDR_FREE:
512 case XDR_ENCODE:
513 if (!xdr_nfs_fh3(xdrs, &objp->fh))
514 return (FALSE);
515 break;
516 case XDR_DECODE:
517 if (!xdr_nfs_fh3_server(xdrs, &objp->fh))
518 return (FALSE);
519 break;
521 if (!xdr_secattr(xdrs, &objp->acl))
522 return (FALSE);
523 return (TRUE);
526 bool_t
527 xdr_SETACL3resok(XDR *xdrs, SETACL3resok *objp)
530 if (!xdr_post_op_attr(xdrs, &objp->attr))
531 return (FALSE);
532 return (TRUE);
535 bool_t
536 xdr_SETACL3resfail(XDR *xdrs, SETACL3resfail *objp)
539 if (!xdr_post_op_attr(xdrs, &objp->attr))
540 return (FALSE);
541 return (TRUE);
544 bool_t
545 xdr_SETACL3res(XDR *xdrs, SETACL3res *objp)
548 if (!xdr_enum(xdrs, (enum_t *)&objp->status))
549 return (FALSE);
550 switch (objp->status) {
551 case NFS3_OK:
552 if (!xdr_SETACL3resok(xdrs, &objp->resok))
553 return (FALSE);
554 break;
555 default:
556 if (!xdr_SETACL3resfail(xdrs, &objp->resfail))
557 return (FALSE);
558 break;
560 return (TRUE);
563 bool_t
564 xdr_GETXATTRDIR3args(XDR *xdrs, GETXATTRDIR3args *objp)
566 switch (xdrs->x_op) {
567 case XDR_FREE:
568 case XDR_ENCODE:
569 if (!xdr_nfs_fh3(xdrs, &objp->fh))
570 return (FALSE);
571 break;
572 case XDR_DECODE:
573 if (!xdr_nfs_fh3_server(xdrs, &objp->fh))
574 return (FALSE);
575 break;
577 if (!xdr_bool(xdrs, &objp->create))
578 return (FALSE);
579 return (TRUE);
582 bool_t
583 xdr_GETXATTRDIR3resok(XDR *xdrs, GETXATTRDIR3resok *objp)
585 switch (xdrs->x_op) {
586 case XDR_ENCODE:
587 if (!xdr_nfs_fh3_server(xdrs, &objp->fh))
588 return (FALSE);
589 break;
590 case XDR_FREE:
591 case XDR_DECODE:
592 if (!xdr_nfs_fh3(xdrs, &objp->fh))
593 return (FALSE);
594 break;
596 if (!xdr_post_op_attr(xdrs, &objp->attr))
597 return (FALSE);
598 return (TRUE);
601 bool_t
602 xdr_GETXATTRDIR3res(XDR *xdrs, GETXATTRDIR3res *objp)
604 if (!xdr_enum(xdrs, (enum_t *)&objp->status))
605 return (FALSE);
606 switch (objp->status) {
607 case NFS_OK:
608 if (!xdr_GETXATTRDIR3resok(xdrs, &objp->resok))
609 return (FALSE);
610 break;
612 return (TRUE);