2 Unix SMB/CIFS implementation.
3 Samba utility functions
4 Copyright (C) Andrew Tridgell 1992-1999
5 Copyright (C) Luke Kenneth Casson Leighton 1996 - 1999
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 /****************************************************************************
24 convert a security permissions into a string
25 ****************************************************************************/
26 char *get_sec_mask_str(uint32 type)
28 static fstring typestr="";
32 if (type & GENERIC_ALL_ACCESS)
33 fstrcat(typestr, "Generic all access ");
34 if (type & GENERIC_EXECUTE_ACCESS)
35 fstrcat(typestr, "Generic execute access ");
36 if (type & GENERIC_WRITE_ACCESS)
37 fstrcat(typestr, "Generic write access ");
38 if (type & GENERIC_READ_ACCESS)
39 fstrcat(typestr, "Generic read access ");
40 if (type & MAXIMUM_ALLOWED_ACCESS)
41 fstrcat(typestr, "MAXIMUM_ALLOWED_ACCESS ");
42 if (type & SYSTEM_SECURITY_ACCESS)
43 fstrcat(typestr, "SYSTEM_SECURITY_ACCESS ");
44 if (type & SYNCHRONIZE_ACCESS)
45 fstrcat(typestr, "SYNCHRONIZE_ACCESS ");
46 if (type & WRITE_OWNER_ACCESS)
47 fstrcat(typestr, "WRITE_OWNER_ACCESS ");
48 if (type & WRITE_DAC_ACCESS)
49 fstrcat(typestr, "WRITE_DAC_ACCESS ");
50 if (type & READ_CONTROL_ACCESS)
51 fstrcat(typestr, "READ_CONTROL_ACCESS ");
52 if (type & DELETE_ACCESS)
53 fstrcat(typestr, "DELETE_ACCESS ");
55 printf("\t\tSpecific bits: 0x%lx\n", (unsigned long)type&SPECIFIC_RIGHTS_MASK);
60 /****************************************************************************
61 display sec_access structure
62 ****************************************************************************/
63 void display_sec_access(SEC_ACCESS *info)
65 printf("\t\tPermissions: 0x%x: %s\n", *info, get_sec_mask_str(*info));
68 /****************************************************************************
69 display sec_ace object
70 ****************************************************************************/
71 static void disp_sec_ace_object(struct security_ace_object *object)
73 if (object->flags & SEC_ACE_OBJECT_PRESENT) {
74 printf("Object type: SEC_ACE_OBJECT_PRESENT\n");
75 printf("Object GUID: %s\n", smb_uuid_string_static(
78 if (object->flags & SEC_ACE_OBJECT_INHERITED_PRESENT) {
79 printf("Object type: SEC_ACE_OBJECT_INHERITED_PRESENT\n");
80 printf("Object GUID: %s\n", smb_uuid_string_static(
81 object->inherited_type.inherited_type));
85 /****************************************************************************
86 display sec_ace structure
87 ****************************************************************************/
88 void display_sec_ace(SEC_ACE *ace)
92 printf("\tACE\n\t\ttype: ");
94 case SEC_ACE_TYPE_ACCESS_ALLOWED:
95 printf("ACCESS ALLOWED");
97 case SEC_ACE_TYPE_ACCESS_DENIED:
98 printf("ACCESS DENIED");
100 case SEC_ACE_TYPE_SYSTEM_AUDIT:
101 printf("SYSTEM AUDIT");
103 case SEC_ACE_TYPE_SYSTEM_ALARM:
104 printf("SYSTEM ALARM");
106 case SEC_ACE_TYPE_ALLOWED_COMPOUND:
107 printf("SEC_ACE_TYPE_ALLOWED_COMPOUND");
109 case SEC_ACE_TYPE_ACCESS_ALLOWED_OBJECT:
110 printf("SEC_ACE_TYPE_ACCESS_ALLOWED_OBJECT");
112 case SEC_ACE_TYPE_ACCESS_DENIED_OBJECT:
113 printf("SEC_ACE_TYPE_ACCESS_DENIED_OBJECT");
115 case SEC_ACE_TYPE_SYSTEM_AUDIT_OBJECT:
116 printf("SEC_ACE_TYPE_SYSTEM_AUDIT_OBJECT");
118 case SEC_ACE_TYPE_SYSTEM_ALARM_OBJECT:
119 printf("SEC_ACE_TYPE_SYSTEM_ALARM_OBJECT");
126 printf(" (%d) flags: %d\n", ace->type, ace->flags);
127 display_sec_access(&ace->access_mask);
128 sid_to_string(sid_str, &ace->trustee);
129 printf("\t\tSID: %s\n\n", sid_str);
131 if (sec_ace_object(ace->type)) {
132 disp_sec_ace_object(&ace->object.object);
137 /****************************************************************************
138 display sec_acl structure
139 ****************************************************************************/
140 void display_sec_acl(SEC_ACL *sec_acl)
144 printf("\tACL\tNum ACEs:\t%d\trevision:\t%x\n",
145 sec_acl->num_aces, sec_acl->revision);
148 if (sec_acl->size != 0 && sec_acl->num_aces != 0)
149 for (i = 0; i < sec_acl->num_aces; i++)
150 display_sec_ace(&sec_acl->aces[i]);
153 void display_acl_type(uint16 type)
155 static fstring typestr="";
159 if (type & SEC_DESC_OWNER_DEFAULTED) /* 0x0001 */
160 fstrcat(typestr, "SEC_DESC_OWNER_DEFAULTED ");
161 if (type & SEC_DESC_GROUP_DEFAULTED) /* 0x0002 */
162 fstrcat(typestr, "SEC_DESC_GROUP_DEFAULTED ");
163 if (type & SEC_DESC_DACL_PRESENT) /* 0x0004 */
164 fstrcat(typestr, "SEC_DESC_DACL_PRESENT ");
165 if (type & SEC_DESC_DACL_DEFAULTED) /* 0x0008 */
166 fstrcat(typestr, "SEC_DESC_DACL_DEFAULTED ");
167 if (type & SEC_DESC_SACL_PRESENT) /* 0x0010 */
168 fstrcat(typestr, "SEC_DESC_SACL_PRESENT ");
169 if (type & SEC_DESC_SACL_DEFAULTED) /* 0x0020 */
170 fstrcat(typestr, "SEC_DESC_SACL_DEFAULTED ");
171 if (type & SEC_DESC_DACL_TRUSTED) /* 0x0040 */
172 fstrcat(typestr, "SEC_DESC_DACL_TRUSTED ");
173 if (type & SEC_DESC_SERVER_SECURITY) /* 0x0080 */
174 fstrcat(typestr, "SEC_DESC_SERVER_SECURITY ");
175 if (type & SEC_DESC_DACL_AUTO_INHERIT_REQ) /* 0x0100 */
176 fstrcat(typestr, "SEC_DESC_DACL_AUTO_INHERIT_REQ ");
177 if (type & SEC_DESC_SACL_AUTO_INHERIT_REQ) /* 0x0200 */
178 fstrcat(typestr, "SEC_DESC_SACL_AUTO_INHERIT_REQ ");
179 if (type & SEC_DESC_DACL_AUTO_INHERITED) /* 0x0400 */
180 fstrcat(typestr, "SEC_DESC_DACL_AUTO_INHERITED ");
181 if (type & SEC_DESC_SACL_AUTO_INHERITED) /* 0x0800 */
182 fstrcat(typestr, "SEC_DESC_SACL_AUTO_INHERITED ");
183 if (type & SEC_DESC_DACL_PROTECTED) /* 0x1000 */
184 fstrcat(typestr, "SEC_DESC_DACL_PROTECTED ");
185 if (type & SEC_DESC_SACL_PROTECTED) /* 0x2000 */
186 fstrcat(typestr, "SEC_DESC_SACL_PROTECTED ");
187 if (type & SEC_DESC_RM_CONTROL_VALID) /* 0x4000 */
188 fstrcat(typestr, "SEC_DESC_RM_CONTROL_VALID ");
189 if (type & SEC_DESC_SELF_RELATIVE) /* 0x8000 */
190 fstrcat(typestr, "SEC_DESC_SELF_RELATIVE ");
192 printf("type: 0x%04x: %s\n", type, typestr);
195 /****************************************************************************
196 display sec_desc structure
197 ****************************************************************************/
198 void display_sec_desc(SEC_DESC *sec)
207 printf("revision: %d\n", sec->revision);
208 display_acl_type(sec->type);
212 display_sec_acl(sec->sacl);
217 display_sec_acl(sec->dacl);
220 if (sec->owner_sid) {
221 sid_to_string(sid_str, sec->owner_sid);
222 printf("\tOwner SID:\t%s\n", sid_str);
225 if (sec->group_sid) {
226 sid_to_string(sid_str, sec->group_sid);
227 printf("\tGroup SID:\t%s\n", sid_str);