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