xref: /illumos-gate/usr/src/lib/libsmbfs/smb/acl_print.c (revision e6f8def1ace27f327240a0b4b090911007f71137)
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 2010 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 "smbfs_ntacl.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_hdr.ace_type, ace->ace_hdr.ace_flags,
85 	    ace->ace_v2.ace_rights);
86 	/* Show the SID as a "continuation" line. */
87 	fprintf(fp, "    ace_sid: ");
88 	fprint_sid(fp, ace->ace_v2.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