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]
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 * Copyright 2014 Nexenta Systems, Inc. All rights reserved.
29 #include <sys/types.h>
30 #include <sys/errno.h>
31 #include <sys/tiuser.h>
36 #include <rpc/types.h>
40 #include <rpc/rpc_msg.h>
46 extern char *get_sum_line();
47 extern void check_retransmit();
48 extern char *sum_nfsfh();
49 extern int sum_nfsstat();
50 extern int detail_nfsstat();
51 extern void detail_nfsfh();
52 extern void detail_fattr();
53 extern void skip_fattr();
54 extern char *sum_nfsfh3();
55 extern int sum_nfsstat3();
56 extern int detail_nfsstat3();
57 extern void detail_post_op_attr();
58 extern void detail_nfsfh3();
59 extern int sum_nfsstat4();
60 extern int detail_nfsstat4();
62 extern jmp_buf xdr_err
;
64 static void aclcall2();
65 static void aclreply2();
66 static void aclcall3();
67 static void aclreply3();
68 static void aclcall4();
69 static void aclreply4();
70 static void detail_access2();
71 static char *sum_access2();
72 static void detail_mask();
73 static void detail_secattr();
74 static void detail_aclent();
75 static char *detail_uname();
76 static char *detail_gname();
77 static char *detail_perm(ushort_t
);
78 static void interpret_nfs_acl2(int, int, int, int, int, char *, int);
79 static void interpret_nfs_acl3(int, int, int, int, int, char *, int);
80 static void interpret_nfs_acl4(int, int, int, int, int, char *, int);
82 #define ACLPROC2_NULL ((unsigned long)(0))
83 #define ACLPROC2_GETACL ((unsigned long)(1))
84 #define ACLPROC2_SETACL ((unsigned long)(2))
85 #define ACLPROC2_GETATTR ((unsigned long)(3))
86 #define ACLPROC2_ACCESS ((unsigned long)(4))
87 #define ACLPROC2_GETXATTRDIR ((unsigned long)(5))
89 #define ACLPROC3_NULL ((unsigned long)(0))
90 #define ACLPROC3_GETACL ((unsigned long)(1))
91 #define ACLPROC3_SETACL ((unsigned long)(2))
92 #define ACLPROC3_GETXATTRDIR ((unsigned long)(3))
94 #define ACLPROC4_NULL ((unsigned long)(0))
95 #define ACLPROC4_GETACL ((unsigned long)(1))
96 #define ACLPROC4_SETACL ((unsigned long)(2))
98 #define NA_USER_OBJ 0x1
100 #define NA_GROUP_OBJ 0x4
102 #define NA_CLASS_OBJ 0x10
103 #define NA_OTHER_OBJ 0x20
104 #define NA_ACL_DEFAULT 0x1000
106 #define NA_DEF_USER_OBJ (NA_USER_OBJ | NA_ACL_DEFAULT)
107 #define NA_DEF_USER (NA_USER | NA_ACL_DEFAULT)
108 #define NA_DEF_GROUP_OBJ (NA_GROUP_OBJ | NA_ACL_DEFAULT)
109 #define NA_DEF_GROUP (NA_GROUP | NA_ACL_DEFAULT)
110 #define NA_DEF_CLASS_OBJ (NA_CLASS_OBJ | NA_ACL_DEFAULT)
111 #define NA_DEF_OTHER_OBJ (NA_OTHER_OBJ | NA_ACL_DEFAULT)
114 #define NA_ACLCNT 0x2
116 #define NA_DFACLCNT 0x8
118 #define ACCESS2_READ 0x0001
119 #define ACCESS2_LOOKUP 0x0002
120 #define ACCESS2_MODIFY 0x0004
121 #define ACCESS2_EXTEND 0x0008
122 #define ACCESS2_DELETE 0x0010
123 #define ACCESS2_EXECUTE 0x0020
125 static char *procnames_short_v2
[] = {
131 "GETXATTRDIR2", /* 5 */
133 static char *procnames_short_v3
[] = {
137 "GETXATTRDIR3", /* 3 */
139 static char *procnames_short_v4
[] = {
145 static char *procnames_long_v2
[] = {
146 "Null procedure", /* 0 */
147 "Get file access control list", /* 1 */
148 "Set file access control list", /* 2 */
149 "Get file attributes", /* 3 */
150 "Check access permission", /* 4 */
151 "Get extended attribute directory", /* 5 */
153 static char *procnames_long_v3
[] = {
154 "Null procedure", /* 0 */
155 "Get file access control list", /* 1 */
156 "Set file access control list", /* 2 */
157 "Get extended attribute directory", /* 3 */
159 static char *procnames_long_v4
[] = {
160 "Null procedure", /* 0 */
161 "Get file access control list", /* 1 */
162 "Set file access control list", /* 2 */
171 interpret_nfs_acl(flags
, type
, xid
, vers
, proc
, data
, len
)
172 int flags
, type
, xid
, vers
, proc
;
178 interpret_nfs_acl2(flags
, type
, xid
, vers
, proc
, data
, len
);
183 interpret_nfs_acl3(flags
, type
, xid
, vers
, proc
, data
, len
);
188 interpret_nfs_acl4(flags
, type
, xid
, vers
, proc
, data
, len
);
194 interpret_nfs_acl2(int flags
, int type
, int xid
, int vers
, int proc
,
203 if (proc
< 0 || proc
> MAXPROC_V2
)
207 line
= get_sum_line();
210 (void) sprintf(line
, "NFS_ACL C %s",
211 procnames_short_v2
[proc
]);
212 line
+= strlen(line
);
214 case ACLPROC2_GETACL
:
216 mask
= getxdr_u_long();
217 (void) sprintf(line
, "%s mask=0x%lx", fh
, mask
);
219 case ACLPROC2_SETACL
:
220 (void) sprintf(line
, sum_nfsfh());
222 case ACLPROC2_GETATTR
:
223 (void) sprintf(line
, sum_nfsfh());
225 case ACLPROC2_ACCESS
:
227 (void) sprintf(line
, "%s (%s)", fh
,
230 case ACLPROC2_GETXATTRDIR
:
232 (void) sprintf(line
, "%s create=%s", fh
,
233 getxdr_bool() ? "true" : "false");
239 check_retransmit(line
, (ulong_t
)xid
);
241 (void) sprintf(line
, "NFS_ACL R %s ",
242 procnames_short_v2
[proc
]);
243 line
+= strlen(line
);
245 case ACLPROC2_GETACL
:
246 (void) sum_nfsstat(line
);
248 case ACLPROC2_SETACL
:
249 (void) sum_nfsstat(line
);
251 case ACLPROC2_GETATTR
:
252 (void) sum_nfsstat(line
);
254 case ACLPROC2_ACCESS
:
255 if (sum_nfsstat(line
) == 0) {
257 line
+= strlen(line
);
258 (void) sprintf(line
, " (%s)",
262 case ACLPROC2_GETXATTRDIR
:
263 if (sum_nfsstat(line
) == 0) {
264 line
+= strlen(line
);
265 (void) sprintf(line
, sum_nfsfh());
274 if (flags
& F_DTAIL
) {
275 show_header("NFS_ACL: ", "Sun NFS_ACL", len
);
277 (void) sprintf(get_line(0, 0), "Proc = %d (%s)",
278 proc
, procnames_long_v2
[proc
]);
288 interpret_nfs_acl3(int flags
, int type
, int xid
, int vers
, int proc
,
297 if (proc
< 0 || proc
> MAXPROC_V3
)
301 line
= get_sum_line();
304 (void) sprintf(line
, "NFS_ACL C %s",
305 procnames_short_v3
[proc
]);
306 line
+= strlen(line
);
308 case ACLPROC3_GETACL
:
310 mask
= getxdr_u_long();
311 (void) sprintf(line
, "%s mask=0x%lx", fh
, mask
);
313 case ACLPROC3_SETACL
:
314 (void) sprintf(line
, sum_nfsfh3());
316 case ACLPROC3_GETXATTRDIR
:
318 (void) sprintf(line
, "%s create=%s", fh
,
319 getxdr_bool() ? "true" : "false");
325 check_retransmit(line
, (ulong_t
)xid
);
327 (void) sprintf(line
, "NFS_ACL R %s ",
328 procnames_short_v3
[proc
]);
329 line
+= strlen(line
);
331 case ACLPROC3_GETACL
:
332 (void) sum_nfsstat3(line
);
334 case ACLPROC3_SETACL
:
335 (void) sum_nfsstat3(line
);
337 case ACLPROC3_GETXATTRDIR
:
338 if (sum_nfsstat3(line
) == 0) {
339 line
+= strlen(line
);
340 (void) sprintf(line
, sum_nfsfh3());
349 if (flags
& F_DTAIL
) {
350 show_header("NFS_ACL: ", "Sun NFS_ACL", len
);
352 (void) sprintf(get_line(0, 0), "Proc = %d (%s)",
353 proc
, procnames_long_v3
[proc
]);
363 interpret_nfs_acl4(int flags
, int type
, int xid
, int vers
, int proc
,
372 if (proc
< 0 || proc
> MAXPROC_V4
)
376 line
= get_sum_line();
379 (void) sprintf(line
, "NFS_ACL C %s",
380 procnames_short_v4
[proc
]);
381 line
+= strlen(line
);
383 case ACLPROC4_GETACL
:
385 mask
= getxdr_u_long();
386 (void) sprintf(line
, "%s mask=0x%lx", fh
, mask
);
388 case ACLPROC4_SETACL
:
389 (void) sprintf(line
, sum_nfsfh3());
395 check_retransmit(line
, (ulong_t
)xid
);
397 (void) sprintf(line
, "NFS_ACL R %s ",
398 procnames_short_v4
[proc
]);
399 line
+= strlen(line
);
401 case ACLPROC4_GETACL
:
402 (void) sum_nfsstat4(line
);
404 case ACLPROC4_SETACL
:
405 (void) sum_nfsstat4(line
);
413 if (flags
& F_DTAIL
) {
414 show_header("NFS_ACL: ", "Sun NFS_ACL", len
);
416 (void) sprintf(get_line(0, 0), "Proc = %d (%s)",
417 proc
, procnames_long_v4
[proc
]);
427 sum_nfsstat4(char *line
)
430 char *p
, *nfsstat4_to_name(int);
432 status
= getxdr_long();
433 p
= nfsstat4_to_name(status
);
434 (void) strcpy(line
, p
);
446 status
= sum_nfsstat4(buff
);
448 (void) sprintf(get_line(pos
, getxdr_pos()), "Status = %d (%s)",
451 return ((int)status
);
455 * Print out version 2 NFS_ACL call packets
463 case ACLPROC2_GETACL
:
467 case ACLPROC2_SETACL
:
471 case ACLPROC2_GETATTR
:
474 case ACLPROC2_ACCESS
:
484 * Print out version 2 NFS_ACL reply packets
492 case ACLPROC2_GETACL
:
493 if (detail_nfsstat() == 0) {
498 case ACLPROC2_SETACL
:
499 if (detail_nfsstat() == 0)
502 case ACLPROC2_GETATTR
:
503 if (detail_nfsstat() == 0)
506 case ACLPROC2_ACCESS
:
507 if (detail_nfsstat() == 0) {
518 * Print out version 3 NFS_ACL call packets
526 case ACLPROC3_GETACL
:
530 case ACLPROC3_SETACL
:
540 * Print out version 3 NFS_ACL reply packets
548 case ACLPROC3_GETACL
:
549 if (detail_nfsstat3() == 0) {
550 detail_post_op_attr("");
554 case ACLPROC3_SETACL
:
555 if (detail_nfsstat3() == 0)
556 detail_post_op_attr("");
564 * Print out version 4 NFS_ACL call packets
572 case ACLPROC4_GETACL
:
576 case ACLPROC4_SETACL
:
586 * Print out version 4 NFS_ACL reply packets
594 case ACLPROC4_GETACL
:
595 if (detail_nfsstat4() == 0) {
596 detail_post_op_attr("");
600 case ACLPROC4_SETACL
:
601 if (detail_nfsstat4() == 0)
602 detail_post_op_attr("");
614 bits
= showxdr_u_long("Access bits = 0x%08x");
615 (void) sprintf(get_line(0, 0), " %s",
616 getflag(bits
, ACCESS2_READ
, "Read", "(no read)"));
617 (void) sprintf(get_line(0, 0), " %s",
618 getflag(bits
, ACCESS2_LOOKUP
, "Lookup", "(no lookup)"));
619 (void) sprintf(get_line(0, 0), " %s",
620 getflag(bits
, ACCESS2_MODIFY
, "Modify", "(no modify)"));
621 (void) sprintf(get_line(0, 0), " %s",
622 getflag(bits
, ACCESS2_EXTEND
, "Extend", "(no extend)"));
623 (void) sprintf(get_line(0, 0), " %s",
624 getflag(bits
, ACCESS2_DELETE
, "Delete", "(no delete)"));
625 (void) sprintf(get_line(0, 0), " %s",
626 getflag(bits
, ACCESS2_EXECUTE
, "Execute", "(no execute)"));
633 static char buff
[22];
635 bits
= getxdr_u_long();
638 if (bits
& ACCESS2_READ
)
639 (void) strcat(buff
, "read,");
640 if (bits
& ACCESS2_LOOKUP
)
641 (void) strcat(buff
, "lookup,");
642 if (bits
& ACCESS2_MODIFY
)
643 (void) strcat(buff
, "modify,");
644 if (bits
& ACCESS2_EXTEND
)
645 (void) strcat(buff
, "extend,");
646 if (bits
& ACCESS2_DELETE
)
647 (void) strcat(buff
, "delete,");
648 if (bits
& ACCESS2_EXECUTE
)
649 (void) strcat(buff
, "execute,");
651 buff
[strlen(buff
) - 1] = '\0';
661 mask
= showxdr_u_long("Mask = 0x%lx");
662 (void) sprintf(get_line(0, 0), " %s",
663 getflag(mask
, NA_ACL
, "aclent", "(no aclent)"));
664 (void) sprintf(get_line(0, 0), " %s",
665 getflag(mask
, NA_ACLCNT
, "aclcnt", "(no aclcnt)"));
666 (void) sprintf(get_line(0, 0), " %s",
667 getflag(mask
, NA_DFACL
, "dfaclent", "(no dfaclent)"));
668 (void) sprintf(get_line(0, 0), " %s",
669 getflag(mask
, NA_DFACLCNT
, "dfaclcnt", "(no dfaclcnt)"));
677 showxdr_long("Aclcnt = %d");
679 showxdr_long("Dfaclcnt = %d");
691 count
= getxdr_long();
692 while (count
-- > 0) {
693 type
= getxdr_long();
695 perm
= getxdr_u_short();
698 (void) sprintf(get_line(0, 0), "\tuser:%s:%s",
699 detail_uname(id
), detail_perm(perm
));
702 (void) sprintf(get_line(0, 0), "\tuser::%s",
706 (void) sprintf(get_line(0, 0), "\tgroup:%s:%s",
707 detail_gname(id
), detail_perm(perm
));
710 (void) sprintf(get_line(0, 0), "\tgroup::%s",
714 (void) sprintf(get_line(0, 0), "\tmask:%s",
718 (void) sprintf(get_line(0, 0), "\tother:%s",
722 (void) sprintf(get_line(0, 0), "\tdefault:user:%s:%s",
723 detail_uname(id
), detail_perm(perm
));
725 case NA_DEF_USER_OBJ
:
726 (void) sprintf(get_line(0, 0), "\tdefault:user::%s",
730 (void) sprintf(get_line(0, 0), "\tdefault:group:%s:%s",
731 detail_gname(id
), detail_perm(perm
));
733 case NA_DEF_GROUP_OBJ
:
734 (void) sprintf(get_line(0, 0), "\tdefault:group::%s",
737 case NA_DEF_CLASS_OBJ
:
738 (void) sprintf(get_line(0, 0), "\tdefault:mask:%s",
741 case NA_DEF_OTHER_OBJ
:
742 (void) sprintf(get_line(0, 0), "\tdefault:other:%s",
746 (void) sprintf(get_line(0, 0), "\tunrecognized entry");
753 detail_uname(uid_t uid
)
756 static char uidp
[10];
760 sprintf(uidp
, "%d", uid
);
763 return (pwd
->pw_name
);
767 detail_gname(gid_t gid
)
770 static char gidp
[10];
774 sprintf(gidp
, "%d", gid
);
777 return (grp
->gr_name
);
780 static char *perms
[] = {
791 detail_perm(ushort_t perm
)
794 if (perm
>= sizeof (perms
) / sizeof (perms
[0]))
796 return (perms
[perm
]);