xref: /titanic_41/usr/src/lib/libsmbfs/smb/acl_print.c (revision fcf3ce441efd61da9bb2884968af01cb7c1452cc)
1 /*
2  * CDDL HEADER START
3  *
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.
7  *
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.
12  *
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]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 /*
30  * Print an NT Security Descriptor (SD) and its sub-components.
31  */
32 
33 #include <sys/types.h>
34 #include <sys/errno.h>
35 #include <sys/cred.h>
36 #include <sys/cmn_err.h>
37 #include <sys/kmem.h>
38 #include <sys/sunddi.h>
39 #include <sys/acl.h>
40 #include <sys/vnode.h>
41 #include <sys/vfs.h>
42 #include <sys/byteorder.h>
43 
44 #include <errno.h>
45 #include <stdio.h>
46 #include <string.h>
47 #include <strings.h>
48 #include <unistd.h>
49 
50 #include <umem.h>
51 #include <idmap.h>
52 
53 #include <sys/fs/smbfs_ioctl.h>
54 
55 #include <netsmb/smb_lib.h>
56 #include <netsmb/smbfs_acl.h>
57 #include <netsmb/smbfs_isec.h>
58 
59 static void
60 fprint_sid(FILE *fp, i_ntsid_t *sid)
61 {
62 	static char sidbuf[256];
63 
64 	if (sid == NULL) {
65 		fprintf(fp, "(null)\n");
66 		return;
67 	}
68 
69 	if (smbfs_sid2str(sid, sidbuf, sizeof (sidbuf), NULL) < 0)
70 		fprintf(fp, "(error)\n");
71 	else
72 		fprintf(fp, "%s\n", sidbuf);
73 }
74 
75 static void
76 fprint_ntace(FILE *fp, i_ntace_t *ace)
77 {
78 	if (ace == NULL) {
79 		fprintf(fp, "  (null)\n");
80 		return;
81 	}
82 
83 	/* ACEs are always printed in a list, so indent by 2. */
84 	fprintf(fp, "  ace_type=%d ace_flags=0x%x ace_rights=0x%x\n",
85 	    ace->ace_type, ace->ace_flags, ace->ace_rights);
86 	/* Show the SID as a "continuation" line. */
87 	fprintf(fp, "    ace_sid: ");
88 	fprint_sid(fp, ace->ace_sid);
89 }
90 
91 static void
92 fprint_ntacl(FILE *fp, i_ntacl_t *acl)
93 {
94 	int i;
95 
96 	if (acl == NULL) {
97 		fprintf(fp, "(null)\n");
98 		return;
99 	}
100 
101 	fprintf(fp, "acl_rev=%d acl_acecount=%d\n",
102 	    acl->acl_revision, acl->acl_acecount);
103 	for (i = 0; i < acl->acl_acecount; i++)
104 		fprint_ntace(fp, acl->acl_acevec[i]);
105 }
106 
107 void
108 smbfs_acl_print_sd(FILE *fp, i_ntsd_t *sd)
109 {
110 
111 	fprintf(fp, "sd_rev=%d, flags=0x%x\n",
112 	    sd->sd_revision, sd->sd_flags);
113 	fprintf(fp, "owner: ");
114 	fprint_sid(fp, sd->sd_owner);
115 	fprintf(fp, "group: ");
116 	fprint_sid(fp, sd->sd_group);
117 	fprintf(fp, "sacl: ");
118 	fprint_ntacl(fp, sd->sd_sacl);
119 	fprintf(fp, "dacl: ");
120 	fprint_ntacl(fp, sd->sd_dacl);
121 }
122