2 Unix SMB/CIFS implementation.
3 Samba utility functions. ADS stuff
4 Copyright (C) Alexey Kotovich 2002
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "libads/ldap_schema.h"
23 #include "../libcli/security/secace.h"
24 #include "../librpc/ndr/libndr.h"
25 #include "libcli/security/dom_sid.h"
28 #define SEC_RIGHTS_FULL_CTRL 0xf01ff
32 static struct perm_mask_str
{
36 {SEC_RIGHTS_FULL_CTRL
, "[Full Control]"},
38 {SEC_ADS_LIST
, "[List Contents]"},
39 {SEC_ADS_LIST_OBJECT
, "[List Object]"},
41 {SEC_ADS_READ_PROP
, "[Read All Properties]"},
42 {SEC_STD_READ_CONTROL
, "[Read Permissions]"},
44 {SEC_ADS_SELF_WRITE
, "[All validate writes]"},
45 {SEC_ADS_WRITE_PROP
, "[Write All Properties]"},
47 {SEC_STD_WRITE_DAC
, "[Modify Permissions]"},
48 {SEC_STD_WRITE_OWNER
, "[Modify Owner]"},
50 {SEC_ADS_CREATE_CHILD
, "[Create All Child Objects]"},
52 {SEC_STD_DELETE
, "[Delete]"},
53 {SEC_ADS_DELETE_TREE
, "[Delete Subtree]"},
54 {SEC_ADS_DELETE_CHILD
, "[Delete All Child Objects]"},
56 {SEC_ADS_CONTROL_ACCESS
, "[Change Password]"},
57 {SEC_ADS_CONTROL_ACCESS
, "[Reset Password]"},
62 /* convert a security permissions into a string */
63 static void ads_disp_perms(uint32_t type
)
68 printf("Permissions: ");
70 if (type
== SEC_RIGHTS_FULL_CTRL
) {
71 printf("%s\n", perms
[j
].str
);
75 for (i
= 0; i
< 32; i
++) {
76 if (type
& ((uint32_t)1 << i
)) {
77 for (j
= 1; perms
[j
].str
; j
++) {
78 if (perms
[j
].mask
== (((unsigned) 1) << i
)) {
79 printf("\n\t%s (0x%08x)", perms
[j
].str
, perms
[j
].mask
);
86 /* remaining bits get added on as-is */
88 printf("[%08x]", type
);
93 static const char *ads_interprete_guid_from_object(ADS_STRUCT
*ads
,
95 const struct GUID
*guid
)
97 const char *ret
= NULL
;
99 if (!ads
|| !mem_ctx
) {
103 ret
= ads_get_attrname_by_guid(ads
, ads
->config
.schema_path
,
106 return talloc_asprintf(mem_ctx
, "LDAP attribute: \"%s\"", ret
);
109 ret
= ads_get_extended_right_name_by_guid(ads
, ads
->config
.config_path
,
113 return talloc_asprintf(mem_ctx
, "Extended right: \"%s\"", ret
);
119 static void ads_disp_sec_ace_object(ADS_STRUCT
*ads
,
121 struct security_ace_object
*object
)
123 if (object
->flags
& SEC_ACE_OBJECT_TYPE_PRESENT
) {
124 printf("Object type: SEC_ACE_OBJECT_TYPE_PRESENT\n");
125 printf("Object GUID: %s (%s)\n", GUID_string(mem_ctx
,
127 ads_interprete_guid_from_object(ads
, mem_ctx
,
128 &object
->type
.type
));
130 if (object
->flags
& SEC_ACE_INHERITED_OBJECT_TYPE_PRESENT
) {
131 printf("Object type: SEC_ACE_INHERITED_OBJECT_TYPE_PRESENT\n");
132 printf("Object GUID: %s (%s)\n", GUID_string(mem_ctx
,
133 &object
->inherited_type
.inherited_type
),
134 ads_interprete_guid_from_object(ads
, mem_ctx
,
135 &object
->inherited_type
.inherited_type
));
140 static void ads_disp_ace(ADS_STRUCT
*ads
, TALLOC_CTX
*mem_ctx
, struct security_ace
*sec_ace
)
142 const char *access_type
= "UNKNOWN";
143 struct dom_sid_buf sidbuf
;
145 if (!sec_ace_object(sec_ace
->type
)) {
146 printf("------- ACE (type: 0x%02x, flags: 0x%02x, size: 0x%02x, mask: 0x%x)\n",
150 sec_ace
->access_mask
);
152 printf("------- ACE (type: 0x%02x, flags: 0x%02x, size: 0x%02x, mask: 0x%x, object flags: 0x%x)\n",
156 sec_ace
->access_mask
,
157 sec_ace
->object
.object
.flags
);
160 if (sec_ace
->type
== SEC_ACE_TYPE_ACCESS_ALLOWED
) {
161 access_type
= "ALLOWED";
162 } else if (sec_ace
->type
== SEC_ACE_TYPE_ACCESS_DENIED
) {
163 access_type
= "DENIED";
164 } else if (sec_ace
->type
== SEC_ACE_TYPE_SYSTEM_AUDIT
) {
165 access_type
= "SYSTEM AUDIT";
166 } else if (sec_ace
->type
== SEC_ACE_TYPE_ACCESS_ALLOWED_OBJECT
) {
167 access_type
= "ALLOWED OBJECT";
168 } else if (sec_ace
->type
== SEC_ACE_TYPE_ACCESS_DENIED_OBJECT
) {
169 access_type
= "DENIED OBJECT";
170 } else if (sec_ace
->type
== SEC_ACE_TYPE_SYSTEM_AUDIT_OBJECT
) {
171 access_type
= "AUDIT OBJECT";
174 printf("access SID: %s\naccess type: %s\n",
175 dom_sid_str_buf(&sec_ace
->trustee
, &sidbuf
),
178 if (sec_ace_object(sec_ace
->type
)) {
179 ads_disp_sec_ace_object(ads
, mem_ctx
, &sec_ace
->object
.object
);
182 ads_disp_perms(sec_ace
->access_mask
);
186 static void ads_disp_acl(struct security_acl
*sec_acl
, const char *type
)
189 printf("------- (%s) ACL not present\n", type
);
191 printf("------- (%s) ACL (revision: %d, size: %d, number of ACEs: %d)\n",
200 void ads_disp_sd(ADS_STRUCT
*ads
, TALLOC_CTX
*mem_ctx
, struct security_descriptor
*sd
)
203 char *tmp_path
= NULL
;
204 struct dom_sid_buf buf
;
210 if (ads
&& !ads
->config
.schema_path
) {
211 if (ADS_ERR_OK(ads_schema_path(ads
, mem_ctx
, &tmp_path
))) {
212 ads
->config
.schema_path
= talloc_strdup(ads
, tmp_path
);
213 if (ads
->config
.schema_path
== NULL
) {
214 DBG_WARNING("Out of memory\n");
219 if (ads
&& !ads
->config
.config_path
) {
220 if (ADS_ERR_OK(ads_config_path(ads
, mem_ctx
, &tmp_path
))) {
221 ads
->config
.config_path
= talloc_strdup(ads
, tmp_path
);
222 if (ads
->config
.config_path
== NULL
) {
223 DBG_WARNING("Out of memory\n");
228 printf("-------------- Security Descriptor (revision: %d, type: 0x%02x)\n",
232 printf("owner SID: %s\n", sd
->owner_sid
?
233 dom_sid_str_buf(sd
->owner_sid
, &buf
) : "(null)");
234 printf("group SID: %s\n", sd
->group_sid
?
235 dom_sid_str_buf(sd
->group_sid
, &buf
) : "(null)");
237 ads_disp_acl(sd
->sacl
, "system");
239 for (i
= 0; i
< sd
->sacl
->num_aces
; i
++) {
240 ads_disp_ace(ads
, mem_ctx
, &sd
->sacl
->aces
[i
]);
244 ads_disp_acl(sd
->dacl
, "user");
246 for (i
= 0; i
< sd
->dacl
->num_aces
; i
++) {
247 ads_disp_ace(ads
, mem_ctx
, &sd
->dacl
->aces
[i
]);
251 printf("-------------- End Of Security Descriptor\n");