2 # Unix SMB/CIFS implementation.
3 # backend code for provisioning a Samba4 server
5 # Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007-2010
6 # Copyright (C) Andrew Bartlett <abartlet@samba.org> 2008-2009
7 # Copyright (C) Oliver Liebel <oliver@itc.li> 2008-2009
8 # Copyright (C) Amitay Isaacs <amitay@samba.org> 2011
10 # Based on the original in EJS:
11 # Copyright (C) Andrew Tridgell <tridge@samba.org> 2005
13 # This program is free software; you can redistribute it and/or modify
14 # it under the terms of the GNU General Public License as published by
15 # the Free Software Foundation; either version 3 of the License, or
16 # (at your option) any later version.
18 # This program is distributed in the hope that it will be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 # GNU General Public License for more details.
23 # You should have received a copy of the GNU General Public License
24 # along with this program. If not, see <http://www.gnu.org/licenses/>.
27 """Functions for setting up a Samba configuration (security descriptors)."""
29 from samba
.dcerpc
import security
30 from samba
.ndr
import ndr_pack
31 from samba
.schema
import get_schema_descriptor
35 # Descriptors of naming contexts and other important objects
38 def sddl2binary(sddl_in
, domain_sid
, name_map
):
41 for [name
, sid
] in name_map
.items():
42 sddl
= sddl
.replace(name
, sid
)
44 sec
= security
.descriptor
.from_sddl(sddl
, domain_sid
)
48 def get_empty_descriptor(domain_sid
, name_map
=None):
53 return sddl2binary(sddl
, domain_sid
, name_map
)
55 # "get_schema_descriptor" is located in "schema.py"
58 def get_config_descriptor(domain_sid
, name_map
=None):
62 sddl
= "O:EAG:EAD:(OA;;CR;1131f6aa-9c07-11d1-f79f-00c04fc2dcd2;;ED)" \
63 "(OA;;CR;1131f6ab-9c07-11d1-f79f-00c04fc2dcd2;;ED)" \
64 "(OA;;CR;1131f6ac-9c07-11d1-f79f-00c04fc2dcd2;;ED)" \
65 "(OA;;CR;1131f6aa-9c07-11d1-f79f-00c04fc2dcd2;;BA)" \
66 "(OA;;CR;1131f6ab-9c07-11d1-f79f-00c04fc2dcd2;;BA)" \
67 "(OA;;CR;1131f6ac-9c07-11d1-f79f-00c04fc2dcd2;;BA)" \
68 "(A;;RPLCLORC;;;AU)(A;CI;RPWPCRCCDCLCLORCWOWDSDDTSW;;;EA)" \
69 "(A;;RPWPCRCCDCLCLORCWOWDSDDTSW;;;SY)(A;CIIO;RPWPCRCCLCLORCWOWDSDSW;;;DA)" \
70 "(OA;;CR;1131f6ad-9c07-11d1-f79f-00c04fc2dcd2;;ED)" \
71 "(OA;;CR;89e95b76-444d-4c62-991a-0facbeda640c;;ED)" \
72 "(OA;;CR;1131f6ad-9c07-11d1-f79f-00c04fc2dcd2;;BA)" \
73 "(OA;;CR;89e95b76-444d-4c62-991a-0facbeda640c;;BA)" \
74 "(OA;;CR;1131f6aa-9c07-11d1-f79f-00c04fc2dcd2;;RO)" \
75 "S:(AU;SA;WPWOWD;;;WD)(AU;SA;CR;;;BA)(AU;SA;CR;;;DU)" \
76 "(OU;SA;CR;45ec5156-db7e-47bb-b53f-dbeb2d03c40f;;WD)"
77 return sddl2binary(sddl
, domain_sid
, name_map
)
80 def get_config_partitions_descriptor(domain_sid
, name_map
=None):
86 "(OA;;RP;e48d0154-bcf8-11d1-8702-00c04fb96050;;AU)" \
87 "(OA;;RP;d31a8757-2447-4545-8081-3bb610cacbf2;;AU)" \
88 "(OA;;RP;66171887-8f3c-11d0-afda-00c04fd930c9;;AU)" \
89 "(OA;;RP;032160bf-9824-11d1-aec0-0000f80367c1;;AU)" \
90 "(OA;;RP;789ee1eb-8c8e-4e4c-8cec-79b31b7617b5;;AU)" \
91 "(OA;;RP;5706aeaf-b940-4fb2-bcfc-5268683ad9fe;;AU)" \
92 "(A;;RPWPCRCCLCLORCWOWDSW;;;EA)" \
93 "(A;;RPWPCRCCDCLCLORCWOWDSDDTSW;;;SY)" \
95 "(OA;CIIO;WP;3df793df-9858-4417-a701-735a1ecebf74;bf967a8d-0de6-11d0-a285-00aa003049e2;BA)" \
97 "(AU;CISA;WPCRCCDCWOWDSDDT;;;WD)"
98 return sddl2binary(sddl
, domain_sid
, name_map
)
101 def get_config_sites_descriptor(domain_sid
, name_map
=None):
106 "(A;;RPLCLORC;;;AU)" \
107 "(OA;CIIO;SW;d31a8757-2447-4545-8081-3bb610cacbf2;f0f8ffab-1191-11d0-a060-00aa006c33ed;RO)" \
108 "(A;;RPWPCRCCLCLORCWOWDSW;;;EA)" \
109 "(A;;RPWPCRCCDCLCLORCWOWDSDDTSW;;;SY)" \
111 "(AU;CISA;CCDCSDDT;;;WD)" \
112 "(OU;CIIOSA;CR;;f0f8ffab-1191-11d0-a060-00aa006c33ed;WD)" \
113 "(OU;CIIOSA;WP;f30e3bbe-9ff0-11d1-b603-0000f80367c1;bf967ab3-0de6-11d0-a285-00aa003049e2;WD)" \
114 "(OU;CIIOSA;WP;f30e3bbf-9ff0-11d1-b603-0000f80367c1;bf967ab3-0de6-11d0-a285-00aa003049e2;WD)" \
115 "(OU;CIIOSA;WP;3e10944c-c354-11d0-aff8-0000f80367c1;b7b13124-b82e-11d0-afee-0000f80367c1;WD)"
116 return sddl2binary(sddl
, domain_sid
, name_map
)
119 def get_config_ntds_quotas_descriptor(domain_sid
, name_map
=None):
124 "(A;;RPWPCRCCDCLCLORCWOWDSDDTSW;;;EA)" \
125 "(A;;RPLCLORC;;;BA)" \
126 "(OA;;CR;4ecc03fe-ffc0-4947-b630-eb672a8a9dbc;;WD)"
127 return sddl2binary(sddl
, domain_sid
, name_map
)
130 def get_config_delete_protected1_descriptor(domain_sid
, name_map
=None):
135 "(A;;RPLCLORC;;;AU)" \
136 "(A;;RPWPCRCCLCLORCWOWDSW;;;EA)" \
137 "(A;;RPWPCRCCDCLCLORCWOWDSDDTSW;;;SY)"
138 return sddl2binary(sddl
, domain_sid
, name_map
)
141 def get_config_delete_protected1wd_descriptor(domain_sid
, name_map
=None):
146 "(A;;RPLCLORC;;;WD)" \
147 "(A;;RPWPCRCCLCLORCWOWDSW;;;EA)" \
148 "(A;;RPWPCRCCDCLCLORCWOWDSDDTSW;;;SY)"
149 return sddl2binary(sddl
, domain_sid
, name_map
)
152 def get_config_delete_protected2_descriptor(domain_sid
, name_map
=None):
157 "(A;;RPLCLORC;;;AU)" \
158 "(A;;RPWPCRCCDCLCLORCWOWDSW;;;EA)" \
159 "(A;;RPWPCRCCDCLCLORCWOWDSDDTSW;;;SY)"
160 return sddl2binary(sddl
, domain_sid
, name_map
)
163 def get_domain_descriptor(domain_sid
, name_map
=None):
167 sddl
= "O:BAG:BAD:AI(OA;CIIO;RP;4c164200-20c0-11d0-a768-00aa006e0529;4828cc14-1437-45bc-9b07-ad6f015e5f28;RU)" \
168 "(OA;CIIO;RP;4c164200-20c0-11d0-a768-00aa006e0529;bf967aba-0de6-11d0-a285-00aa003049e2;RU)" \
169 "(OA;CIIO;RP;5f202010-79a5-11d0-9020-00c04fc2d4cf;4828cc14-1437-45bc-9b07-ad6f015e5f28;RU)" \
170 "(OA;CIIO;RP;5f202010-79a5-11d0-9020-00c04fc2d4cf;bf967aba-0de6-11d0-a285-00aa003049e2;RU)" \
171 "(OA;CIIO;RP;bc0ac240-79a9-11d0-9020-00c04fc2d4cf;4828cc14-1437-45bc-9b07-ad6f015e5f28;RU)" \
172 "(OA;CIIO;RP;bc0ac240-79a9-11d0-9020-00c04fc2d4cf;bf967aba-0de6-11d0-a285-00aa003049e2;RU)" \
173 "(OA;CIIO;RP;59ba2f42-79a2-11d0-9020-00c04fc2d3cf;4828cc14-1437-45bc-9b07-ad6f015e5f28;RU)" \
174 "(OA;CIIO;RP;59ba2f42-79a2-11d0-9020-00c04fc2d3cf;bf967aba-0de6-11d0-a285-00aa003049e2;RU)" \
175 "(OA;CIIO;RP;037088f8-0ae1-11d2-b422-00a0c968f939;4828cc14-1437-45bc-9b07-ad6f015e5f28;RU)" \
176 "(OA;CIIO;RP;037088f8-0ae1-11d2-b422-00a0c968f939;bf967aba-0de6-11d0-a285-00aa003049e2;RU)" \
177 "(OA;;CR;1131f6aa-9c07-11d1-f79f-00c04fc2dcd2;;RO)" \
178 "(OA;;CR;1131f6ad-9c07-11d1-f79f-00c04fc2dcd2;;DD)" \
179 "(OA;CIIO;RP;b7c69e6d-2cc7-11d2-854e-00a0c983f608;bf967a86-0de6-11d0-a285-00aa003049e2;ED)" \
180 "(OA;CIIO;RP;b7c69e6d-2cc7-11d2-854e-00a0c983f608;bf967a9c-0de6-11d0-a285-00aa003049e2;ED)" \
181 "(OA;CIIO;RP;b7c69e6d-2cc7-11d2-854e-00a0c983f608;bf967aba-0de6-11d0-a285-00aa003049e2;ED)" \
182 "(OA;;CR;89e95b76-444d-4c62-991a-0facbeda640c;;BA)" \
183 "(OA;;CR;1131f6aa-9c07-11d1-f79f-00c04fc2dcd2;;BA)" \
184 "(OA;;CR;1131f6ab-9c07-11d1-f79f-00c04fc2dcd2;;BA)" \
185 "(OA;;CR;1131f6ac-9c07-11d1-f79f-00c04fc2dcd2;;BA)" \
186 "(OA;;CR;1131f6ad-9c07-11d1-f79f-00c04fc2dcd2;;BA)" \
187 "(OA;;CR;1131f6ae-9c07-11d1-f79f-00c04fc2dcd2;;BA)" \
188 "(OA;;CR;e2a36dc9-ae17-47c3-b58b-be34c55ba633;;S-1-5-32-557)" \
189 "(OA;;RP;c7407360-20bf-11d0-a768-00aa006e0529;;RU)" \
190 "(OA;;RP;b8119fd0-04f6-4762-ab7a-4986c76b3f9a;;RU)" \
191 "(OA;CIIO;RPLCLORC;;4828cc14-1437-45bc-9b07-ad6f015e5f28;RU)" \
192 "(OA;CIIO;RPLCLORC;;bf967a9c-0de6-11d0-a285-00aa003049e2;RU)" \
193 "(OA;CIIO;RPLCLORC;;bf967aba-0de6-11d0-a285-00aa003049e2;RU)" \
194 "(OA;;CR;05c74c5e-4deb-43b4-bd9f-86664c2a7fd5;;AU)" \
195 "(OA;;CR;89e95b76-444d-4c62-991a-0facbeda640c;;ED)" \
196 "(OA;;CR;ccc2dc7d-a6ad-4a7a-8846-c04e3cc53501;;AU)" \
197 "(OA;;CR;280f369c-67c7-438e-ae98-1d46f3c6f541;;AU)" \
198 "(OA;;CR;1131f6aa-9c07-11d1-f79f-00c04fc2dcd2;;ED)" \
199 "(OA;;CR;1131f6ab-9c07-11d1-f79f-00c04fc2dcd2;;ED)" \
200 "(OA;;CR;1131f6ac-9c07-11d1-f79f-00c04fc2dcd2;;ED)" \
201 "(OA;;CR;1131f6ae-9c07-11d1-f79f-00c04fc2dcd2;;ED)" \
202 "(OA;;RP;b8119fd0-04f6-4762-ab7a-4986c76b3f9a;;AU)" \
203 "(OA;CIIO;RPWPCR;91e647de-d96f-4b70-9557-d63ff4f3ccd8;;PS)" \
204 "(OA;CIIO;WP;ea1b7b93-5e48-46d5-bc6c-4df4fda78a35;bf967a86-0de6-11d0-a285-00aa003049e2;PS)" \
205 "(OA;;CR;3e0f7e18-2c7a-4c10-ba82-4d926db99a3e;;CN)" \
206 "(OA;OICI;RPWP;3f78c3e5-f79a-46bd-a0b8-9d18116ddc79;;PS)" \
207 "(OA;CI;RPWP;5b47d60f-6090-40b2-9f37-2a4de88f3063;;KA)" \
208 "(OA;CI;RPWP;5b47d60f-6090-40b2-9f37-2a4de88f3063;;EK)" \
209 "(OA;CIIO;SW;9b026da6-0d3c-465c-8bee-5199d7165cba;bf967a86-0de6-11d0-a285-00aa003049e2;PS)" \
210 "(OA;CIIO;SW;9b026da6-0d3c-465c-8bee-5199d7165cba;bf967a86-0de6-11d0-a285-00aa003049e2;CO)" \
211 "(A;;RPWPCRCCLCLORCWOWDSW;;;DA)" \
212 "(A;CI;RPWPCRCCDCLCLORCWOWDSDDTSW;;;EA)" \
215 "(A;CI;RPWPCRCCLCLORCWOWDSDSW;;;BA)" \
217 "(A;;RPLCLORC;;;ED)" \
218 "(A;;RPLCLORC;;;AU)" \
219 "(A;;RPWPCRCCDCLCLORCWOWDSDDTSW;;;SY)" \
220 "S:AI(OU;CISA;WP;f30e3bbe-9ff0-11d1-b603-0000f80367c1;bf967aa5-0de6-11d0-a285-00aa003049e2;WD)" \
221 "(OU;CISA;WP;f30e3bbf-9ff0-11d1-b603-0000f80367c1;bf967aa5-0de6-11d0-a285-00aa003049e2;WD)" \
222 "(AU;SA;CR;;;DU)(AU;SA;CR;;;BA)(AU;SA;WPWOWD;;;WD)"
223 return sddl2binary(sddl
, domain_sid
, name_map
)
226 def get_domain_infrastructure_descriptor(domain_sid
, name_map
=None):
231 "(A;;RPLCLORC;;;AU)" \
232 "(A;;RPWPCRCCLCLORCWOWDSW;;;DA)" \
233 "(A;;RPWPCRCCDCLCLORCWOWDSDDTSW;;;SY)" \
236 return sddl2binary(sddl
, domain_sid
, name_map
)
239 def get_domain_builtin_descriptor(domain_sid
, name_map
=None):
244 "(OA;CIIO;RP;4c164200-20c0-11d0-a768-00aa006e0529;4828cc14-1437-45bc-9b07-ad6f015e5f28;RU)" \
245 "(OA;CIIO;RP;4c164200-20c0-11d0-a768-00aa006e0529;bf967aba-0de6-11d0-a285-00aa003049e2;RU)" \
246 "(OA;CIIO;RP;5f202010-79a5-11d0-9020-00c04fc2d4cf;4828cc14-1437-45bc-9b07-ad6f015e5f28;RU)" \
247 "(OA;CIIO;RP;5f202010-79a5-11d0-9020-00c04fc2d4cf;bf967aba-0de6-11d0-a285-00aa003049e2;RU)" \
248 "(OA;CIIO;RP;bc0ac240-79a9-11d0-9020-00c04fc2d4cf;4828cc14-1437-45bc-9b07-ad6f015e5f28;RU)" \
249 "(OA;CIIO;RP;bc0ac240-79a9-11d0-9020-00c04fc2d4cf;bf967aba-0de6-11d0-a285-00aa003049e2;RU)" \
250 "(OA;CIIO;RP;59ba2f42-79a2-11d0-9020-00c04fc2d3cf;4828cc14-1437-45bc-9b07-ad6f015e5f28;RU)" \
251 "(OA;CIIO;RP;59ba2f42-79a2-11d0-9020-00c04fc2d3cf;bf967aba-0de6-11d0-a285-00aa003049e2;RU)" \
252 "(OA;CIIO;RP;037088f8-0ae1-11d2-b422-00a0c968f939;4828cc14-1437-45bc-9b07-ad6f015e5f28;RU)" \
253 "(OA;CIIO;RP;037088f8-0ae1-11d2-b422-00a0c968f939;bf967aba-0de6-11d0-a285-00aa003049e2;RU)" \
254 "(OA;;CR;1131f6aa-9c07-11d1-f79f-00c04fc2dcd2;;RO)" \
255 "(OA;;CR;1131f6ad-9c07-11d1-f79f-00c04fc2dcd2;;DD)" \
256 "(OA;CIIO;RP;b7c69e6d-2cc7-11d2-854e-00a0c983f608;bf967a86-0de6-11d0-a285-00aa003049e2;ED)" \
257 "(OA;CIIO;RP;b7c69e6d-2cc7-11d2-854e-00a0c983f608;bf967a9c-0de6-11d0-a285-00aa003049e2;ED)" \
258 "(OA;CIIO;RP;b7c69e6d-2cc7-11d2-854e-00a0c983f608;bf967aba-0de6-11d0-a285-00aa003049e2;ED)" \
259 "(OA;;CR;89e95b76-444d-4c62-991a-0facbeda640c;;BA)" \
260 "(OA;;CR;1131f6aa-9c07-11d1-f79f-00c04fc2dcd2;;BA)" \
261 "(OA;;CR;1131f6ab-9c07-11d1-f79f-00c04fc2dcd2;;BA)" \
262 "(OA;;CR;1131f6ac-9c07-11d1-f79f-00c04fc2dcd2;;BA)" \
263 "(OA;;CR;1131f6ad-9c07-11d1-f79f-00c04fc2dcd2;;BA)" \
264 "(OA;;CR;1131f6ae-9c07-11d1-f79f-00c04fc2dcd2;;BA)" \
265 "(OA;;CR;e2a36dc9-ae17-47c3-b58b-be34c55ba633;;S-1-5-32-557)" \
266 "(OA;;RP;c7407360-20bf-11d0-a768-00aa006e0529;;RU)" \
267 "(OA;;RP;b8119fd0-04f6-4762-ab7a-4986c76b3f9a;;RU)" \
268 "(OA;CIIO;RPLCLORC;;4828cc14-1437-45bc-9b07-ad6f015e5f28;RU)" \
269 "(OA;CIIO;RPLCLORC;;bf967a9c-0de6-11d0-a285-00aa003049e2;RU)" \
270 "(OA;CIIO;RPLCLORC;;bf967aba-0de6-11d0-a285-00aa003049e2;RU)" \
271 "(OA;;CR;05c74c5e-4deb-43b4-bd9f-86664c2a7fd5;;AU)" \
272 "(OA;;CR;89e95b76-444d-4c62-991a-0facbeda640c;;ED)" \
273 "(OA;;CR;ccc2dc7d-a6ad-4a7a-8846-c04e3cc53501;;AU)" \
274 "(OA;;CR;280f369c-67c7-438e-ae98-1d46f3c6f541;;AU)" \
275 "(OA;;CR;1131f6aa-9c07-11d1-f79f-00c04fc2dcd2;;ED)" \
276 "(OA;;CR;1131f6ab-9c07-11d1-f79f-00c04fc2dcd2;;ED)" \
277 "(OA;;CR;1131f6ac-9c07-11d1-f79f-00c04fc2dcd2;;ED)" \
278 "(OA;;CR;1131f6ae-9c07-11d1-f79f-00c04fc2dcd2;;ED)" \
279 "(OA;;RP;b8119fd0-04f6-4762-ab7a-4986c76b3f9a;;AU)" \
280 "(OA;CIIO;RPWPCR;91e647de-d96f-4b70-9557-d63ff4f3ccd8;;PS)" \
281 "(OA;CIIO;SW;9b026da6-0d3c-465c-8bee-5199d7165cba;bf967a86-0de6-11d0-a285-00aa003049e2;CO)" \
282 "(OA;OICI;RPWP;3f78c3e5-f79a-46bd-a0b8-9d18116ddc79;;PS)" \
283 "(OA;CIIO;SW;9b026da6-0d3c-465c-8bee-5199d7165cba;bf967a86-0de6-11d0-a285-00aa003049e2;PS)" \
284 "(OA;CIIO;WP;ea1b7b93-5e48-46d5-bc6c-4df4fda78a35;bf967a86-0de6-11d0-a285-00aa003049e2;PS)" \
285 "(A;;RPWPCRCCLCLORCWOWDSW;;;DA)" \
286 "(A;CI;RPWPCRCCDCLCLORCWOWDSDDTSW;;;EA)" \
289 "(A;CI;RPWPCRCCLCLORCWOWDSDSW;;;BA)" \
291 "(A;;RPLCLORC;;;ED)" \
292 "(A;;RPLCLORC;;;AU)" \
293 "(A;;RPWPCRCCDCLCLORCWOWDSDDTSW;;;SY)" \
295 "(OU;CISA;WP;f30e3bbe-9ff0-11d1-b603-0000f80367c1;bf967aa5-0de6-11d0-a285-00aa003049e2;WD)" \
296 "(OU;CISA;WP;f30e3bbf-9ff0-11d1-b603-0000f80367c1;bf967aa5-0de6-11d0-a285-00aa003049e2;WD)" \
299 "(AU;SA;WPWOWD;;;WD)"
300 return sddl2binary(sddl
, domain_sid
, name_map
)
303 def get_domain_computers_descriptor(domain_sid
, name_map
=None):
308 "(A;;RPWPCRCCDCLCLORCWOWDSDDTSW;;;SY)" \
309 "(A;;RPWPCRCCDCLCLORCWOWDSW;;;DA)" \
310 "(OA;;CCDC;bf967a86-0de6-11d0-a285-00aa003049e2;;AO)" \
311 "(OA;;CCDC;bf967aba-0de6-11d0-a285-00aa003049e2;;AO)" \
312 "(OA;;CCDC;bf967a9c-0de6-11d0-a285-00aa003049e2;;AO)" \
313 "(OA;;CCDC;bf967aa8-0de6-11d0-a285-00aa003049e2;;PO)" \
314 "(A;;RPLCLORC;;;AU)" \
315 "(OA;;CCDC;4828cc14-1437-45bc-9b07-ad6f015e5f28;;AO)" \
317 return sddl2binary(sddl
, domain_sid
, name_map
)
320 def get_domain_users_descriptor(domain_sid
, name_map
=None):
325 "(A;;RPWPCRCCDCLCLORCWOWDSDDTSW;;;SY)" \
326 "(A;;RPWPCRCCDCLCLORCWOWDSW;;;DA)" \
327 "(OA;;CCDC;bf967aba-0de6-11d0-a285-00aa003049e2;;AO)" \
328 "(OA;;CCDC;bf967a9c-0de6-11d0-a285-00aa003049e2;;AO)" \
329 "(OA;;CCDC;bf967aa8-0de6-11d0-a285-00aa003049e2;;PO)" \
330 "(A;;RPLCLORC;;;AU)" \
331 "(OA;;CCDC;4828cc14-1437-45bc-9b07-ad6f015e5f28;;AO)" \
333 return sddl2binary(sddl
, domain_sid
, name_map
)
336 def get_managed_service_accounts_descriptor(domain_sid
, name_map
=None):
341 "(A;;RPWPCRCCDCLCLORCWOWDSDDTSW;;;SY)" \
342 "(A;;RPWPCRCCDCLCLORCWOWDSW;;;DA)" \
343 "(OA;;CCDC;ce206244-5827-4a86-ba1c-1c0c386c1b64;;AO)" \
344 "(OA;;CCDC;bf967aba-0de6-11d0-a285-00aa003049e2;;AO)" \
345 "(OA;;CCDC;bf967a9c-0de6-11d0-a285-00aa003049e2;;AO)" \
346 "(A;;RPLCLORC;;;AU)" \
348 return sddl2binary(sddl
, domain_sid
, name_map
)
351 def get_domain_controllers_descriptor(domain_sid
, name_map
=None):
356 "(A;;RPLCLORC;;;AU)" \
357 "(A;;RPWPCRCCLCLORCWOWDSW;;;DA)" \
358 "(A;;RPWPCRCCDCLCLORCWOWDSDDTSW;;;SY)" \
359 "(A;;RPLCLORC;;;ED)" \
361 "(AU;SA;CCDCWOWDSDDT;;;WD)" \
363 return sddl2binary(sddl
, domain_sid
, name_map
)
366 def get_domain_delete_protected1_descriptor(domain_sid
, name_map
=None):
371 "(A;;RPLCLORC;;;AU)" \
372 "(A;;RPWPCRCCLCLORCWOWDSW;;;DA)" \
373 "(A;;RPWPCRCCDCLCLORCWOWDSDDTSW;;;SY)"
374 return sddl2binary(sddl
, domain_sid
, name_map
)
377 def get_domain_delete_protected2_descriptor(domain_sid
, name_map
=None):
382 "(A;;RPLCLORC;;;AU)" \
383 "(A;;RPWPCRCCDCLCLORCWOWDSW;;;DA)" \
384 "(A;;RPWPCRCCDCLCLORCWOWDSDDTSW;;;SY)"
385 return sddl2binary(sddl
, domain_sid
, name_map
)
388 def get_dns_partition_descriptor(domain_sid
, name_map
=None):
392 sddl
= "O:SYG:BAD:AI" \
393 "(OA;CIIO;RP;4c164200-20c0-11d0-a768-00aa006e0529;4828cc14-1437-45bc-9b07-ad6f015e5f28;RU)" \
394 "(OA;CIIO;RP;4c164200-20c0-11d0-a768-00aa006e0529;bf967aba-0de6-11d0-a285-00aa003049e2;RU)" \
395 "(OA;CIIO;RP;5f202010-79a5-11d0-9020-00c04fc2d4cf;4828cc14-1437-45bc-9b07-ad6f015e5f28;RU)" \
396 "(OA;CIIO;RP;5f202010-79a5-11d0-9020-00c04fc2d4cf;bf967aba-0de6-11d0-a285-00aa003049e2;RU)" \
397 "(OA;CIIO;RP;bc0ac240-79a9-11d0-9020-00c04fc2d4cf;4828cc14-1437-45bc-9b07-ad6f015e5f28;RU)" \
398 "(OA;CIIO;RP;bc0ac240-79a9-11d0-9020-00c04fc2d4cf;bf967aba-0de6-11d0-a285-00aa003049e2;RU)" \
399 "(OA;CIIO;RP;59ba2f42-79a2-11d0-9020-00c04fc2d3cf;4828cc14-1437-45bc-9b07-ad6f015e5f28;RU)" \
400 "(OA;CIIO;RP;59ba2f42-79a2-11d0-9020-00c04fc2d3cf;bf967aba-0de6-11d0-a285-00aa003049e2;RU)" \
401 "(OA;CIIO;RP;037088f8-0ae1-11d2-b422-00a0c968f939;4828cc14-1437-45bc-9b07-ad6f015e5f28;RU)" \
402 "(OA;CIIO;RP;037088f8-0ae1-11d2-b422-00a0c968f939;bf967aba-0de6-11d0-a285-00aa003049e2;RU)" \
403 "(OA;;CR;1131f6aa-9c07-11d1-f79f-00c04fc2dcd2;;RO)" \
404 "(OA;CIIO;RP;b7c69e6d-2cc7-11d2-854e-00a0c983f608;bf967a86-0de6-11d0-a285-00aa003049e2;ED)" \
405 "(OA;CIIO;RP;b7c69e6d-2cc7-11d2-854e-00a0c983f608;bf967a9c-0de6-11d0-a285-00aa003049e2;ED)" \
406 "(OA;CIIO;RP;b7c69e6d-2cc7-11d2-854e-00a0c983f608;bf967aba-0de6-11d0-a285-00aa003049e2;ED)" \
407 "(OA;;CR;89e95b76-444d-4c62-991a-0facbeda640c;;BA)" \
408 "(OA;;CR;1131f6aa-9c07-11d1-f79f-00c04fc2dcd2;;BA)" \
409 "(OA;;CR;1131f6ab-9c07-11d1-f79f-00c04fc2dcd2;;BA)" \
410 "(OA;;CR;1131f6ac-9c07-11d1-f79f-00c04fc2dcd2;;BA)" \
411 "(OA;;CR;1131f6ad-9c07-11d1-f79f-00c04fc2dcd2;;BA)" \
412 "(OA;;CR;1131f6ae-9c07-11d1-f79f-00c04fc2dcd2;;BA)" \
413 "(OA;;CR;e2a36dc9-ae17-47c3-b58b-be34c55ba633;;S-1-5-32-557)" \
414 "(OA;;RP;c7407360-20bf-11d0-a768-00aa006e0529;;RU)" \
415 "(OA;;RP;b8119fd0-04f6-4762-ab7a-4986c76b3f9a;;RU)" \
416 "(OA;CIIO;RPLCLORC;;4828cc14-1437-45bc-9b07-ad6f015e5f28;RU)" \
417 "(OA;CIIO;RPLCLORC;;bf967a9c-0de6-11d0-a285-00aa003049e2;RU)" \
418 "(OA;CIIO;RPLCLORC;;bf967aba-0de6-11d0-a285-00aa003049e2;RU)" \
419 "(OA;;CR;05c74c5e-4deb-43b4-bd9f-86664c2a7fd5;;AU)" \
420 "(OA;;CR;89e95b76-444d-4c62-991a-0facbeda640c;;ED)" \
421 "(OA;;CR;ccc2dc7d-a6ad-4a7a-8846-c04e3cc53501;;AU)" \
422 "(OA;;CR;280f369c-67c7-438e-ae98-1d46f3c6f541;;AU)" \
423 "(OA;;CR;1131f6aa-9c07-11d1-f79f-00c04fc2dcd2;;ED)" \
424 "(OA;;CR;1131f6ab-9c07-11d1-f79f-00c04fc2dcd2;;ED)" \
425 "(OA;;CR;1131f6ac-9c07-11d1-f79f-00c04fc2dcd2;;ED)" \
426 "(OA;;CR;1131f6ad-9c07-11d1-f79f-00c04fc2dcd2;;ED)" \
427 "(OA;;CR;1131f6ae-9c07-11d1-f79f-00c04fc2dcd2;;ED)" \
428 "(OA;;RP;b8119fd0-04f6-4762-ab7a-4986c76b3f9a;;AU)" \
429 "(OA;CIIO;RPWPCR;91e647de-d96f-4b70-9557-d63ff4f3ccd8;;PS)" \
430 "(OA;CIIO;SW;9b026da6-0d3c-465c-8bee-5199d7165cba;bf967a86-0de6-11d0-a285-00aa003049e2;CO)" \
431 "(OA;OICI;RPWP;3f78c3e5-f79a-46bd-a0b8-9d18116ddc79;;PS)" \
432 "(OA;CIIO;SW;9b026da6-0d3c-465c-8bee-5199d7165cba;bf967a86-0de6-11d0-a285-00aa003049e2;PS)" \
433 "(OA;CIIO;WP;ea1b7b93-5e48-46d5-bc6c-4df4fda78a35;bf967a86-0de6-11d0-a285-00aa003049e2;PS)" \
434 "(A;;RPWPCRCCLCLORCWOWDSW;;;DA)" \
435 "(A;CI;RPWPCRCCDCLCLORCWOWDSDDTSW;;;EA)" \
438 "(A;CI;RPWPCRCCLCLORCWOWDSDSW;;;BA)" \
440 "(A;;RPLCLORC;;;ED)" \
441 "(A;;RPLCLORC;;;AU)" \
442 "(A;;RPWPCRCCDCLCLORCWOWDSDDTSW;;;SY)" \
444 "(OU;CISA;WP;f30e3bbe-9ff0-11d1-b603-0000f80367c1;bf967aa5-0de6-11d0-a285-00aa003049e2;WD)" \
445 "(OU;CISA;WP;f30e3bbf-9ff0-11d1-b603-0000f80367c1;bf967aa5-0de6-11d0-a285-00aa003049e2;WD)" \
446 "(AU;SA;CR;;;DU)(AU;SA;CR;;;BA)(AU;SA;WPWOWD;;;WD)"
447 return sddl2binary(sddl
, domain_sid
, name_map
)
450 def get_dns_forest_microsoft_dns_descriptor(domain_sid
, name_map
=None):
454 sddl
= "O:SYG:SYD:AI" \
455 "(A;;RPWPCRCCDCLCLORCWOWDSDDTSW;;;SY)" \
456 "(A;CI;RPWPCRCCDCLCRCWOWDSDDTSW;;;ED)"
457 return sddl2binary(sddl
, domain_sid
, name_map
)
460 def get_dns_domain_microsoft_dns_descriptor(domain_sid
, name_map
=None):
464 sddl
= "O:SYG:SYD:AI" \
465 "(A;;RPWPCRCCDCLCLORCWOWDSDDTSW;;;DA)" \
466 "(A;CI;RPWPCRCCDCLCRCWOWDSDDTSW;;;DnsAdmins)" \
467 "(A;;RPWPCRCCDCLCLORCWOWDSDDTSW;;;SY)" \
468 "(A;CI;RPWPCRCCDCLCRCWOWDSDDTSW;;;ED)"
469 return sddl2binary(sddl
, domain_sid
, name_map
)
472 def get_paritions_crossref_subdomain_descriptor(domain_sid
, name_map
=None):
476 sddl
= "O:SubdomainAdminsG:SubdomainAdminsD:AI" \
477 "(A;;RPWPCRCCLCLORCWOWDSW;;;SubdomainAdmins)" \
478 "(A;;RPLCLORC;;;AU)" \
479 "(A;;RPWPCRCCDCLCLORCWOWDSDDTSW;;;SY)"
480 return sddl2binary(sddl
, domain_sid
, name_map
)
483 def get_wellknown_sds(samdb
):
487 (ldb
.Dn(samdb
, "%s" % str(samdb
.domain_dn())), get_domain_descriptor
),
488 (ldb
.Dn(samdb
, "CN=LostAndFound,%s" % str(samdb
.domain_dn())), get_domain_delete_protected2_descriptor
),
489 (ldb
.Dn(samdb
, "CN=System,%s" % str(samdb
.domain_dn())), get_domain_delete_protected1_descriptor
),
490 (ldb
.Dn(samdb
, "CN=Infrastructure,%s" % str(samdb
.domain_dn())), get_domain_infrastructure_descriptor
),
491 (ldb
.Dn(samdb
, "CN=Builtin,%s" % str(samdb
.domain_dn())), get_domain_builtin_descriptor
),
492 (ldb
.Dn(samdb
, "CN=Computers,%s" % str(samdb
.domain_dn())), get_domain_computers_descriptor
),
493 (ldb
.Dn(samdb
, "CN=Users,%s" % str(samdb
.domain_dn())), get_domain_users_descriptor
),
494 (ldb
.Dn(samdb
, "OU=Domain Controllers,%s" % str(samdb
.domain_dn())), get_domain_controllers_descriptor
),
495 (ldb
.Dn(samdb
, "CN=MicrosoftDNS,CN=System,%s" % str(samdb
.domain_dn())), get_dns_domain_microsoft_dns_descriptor
),
497 (ldb
.Dn(samdb
, "%s" % str(samdb
.get_config_basedn())), get_config_descriptor
),
498 (ldb
.Dn(samdb
, "CN=NTDS Quotas,%s" % str(samdb
.get_config_basedn())), get_config_ntds_quotas_descriptor
),
499 (ldb
.Dn(samdb
, "CN=LostAndFoundConfig,%s" % str(samdb
.get_config_basedn())), get_config_delete_protected1wd_descriptor
),
500 (ldb
.Dn(samdb
, "CN=Services,%s" % str(samdb
.get_config_basedn())), get_config_delete_protected1_descriptor
),
501 (ldb
.Dn(samdb
, "CN=Physical Locations,%s" % str(samdb
.get_config_basedn())), get_config_delete_protected1wd_descriptor
),
502 (ldb
.Dn(samdb
, "CN=WellKnown Security Principals,%s" % str(samdb
.get_config_basedn())), get_config_delete_protected1wd_descriptor
),
503 (ldb
.Dn(samdb
, "CN=ForestUpdates,%s" % str(samdb
.get_config_basedn())), get_config_delete_protected1wd_descriptor
),
504 (ldb
.Dn(samdb
, "CN=DisplaySpecifiers,%s" % str(samdb
.get_config_basedn())), get_config_delete_protected2_descriptor
),
505 (ldb
.Dn(samdb
, "CN=Extended-Rights,%s" % str(samdb
.get_config_basedn())), get_config_delete_protected2_descriptor
),
506 (ldb
.Dn(samdb
, "CN=Partitions,%s" % str(samdb
.get_config_basedn())), get_config_partitions_descriptor
),
507 (ldb
.Dn(samdb
, "CN=Sites,%s" % str(samdb
.get_config_basedn())), get_config_sites_descriptor
),
509 (ldb
.Dn(samdb
, "%s" % str(samdb
.get_schema_basedn())), get_schema_descriptor
),
512 current
= samdb
.search(expression
="(objectClass=*)",
513 base
="", scope
=ldb
.SCOPE_BASE
,
514 attrs
=["namingContexts"])
516 for nc
in current
[0]["namingContexts"]:
518 dnsforestdn
= ldb
.Dn(samdb
, "DC=ForestDnsZones,%s" % (str(samdb
.get_root_basedn())))
519 if ldb
.Dn(samdb
, nc
.decode('utf8')) == dnsforestdn
:
520 c
= (ldb
.Dn(samdb
, "%s" % str(dnsforestdn
)), get_dns_partition_descriptor
)
521 subcontainers
.append(c
)
522 c
= (ldb
.Dn(samdb
, "CN=Infrastructure,%s" % str(dnsforestdn
)),
523 get_domain_delete_protected1_descriptor
)
524 subcontainers
.append(c
)
525 c
= (ldb
.Dn(samdb
, "CN=LostAndFound,%s" % str(dnsforestdn
)),
526 get_domain_delete_protected2_descriptor
)
527 subcontainers
.append(c
)
528 c
= (ldb
.Dn(samdb
, "CN=MicrosoftDNS,%s" % str(dnsforestdn
)),
529 get_dns_forest_microsoft_dns_descriptor
)
530 subcontainers
.append(c
)
533 dnsdomaindn
= ldb
.Dn(samdb
, "DC=DomainDnsZones,%s" % (str(samdb
.domain_dn())))
534 if ldb
.Dn(samdb
, nc
.decode('utf8')) == dnsdomaindn
:
535 c
= (ldb
.Dn(samdb
, "%s" % str(dnsdomaindn
)), get_dns_partition_descriptor
)
536 subcontainers
.append(c
)
537 c
= (ldb
.Dn(samdb
, "CN=Infrastructure,%s" % str(dnsdomaindn
)),
538 get_domain_delete_protected1_descriptor
)
539 subcontainers
.append(c
)
540 c
= (ldb
.Dn(samdb
, "CN=LostAndFound,%s" % str(dnsdomaindn
)),
541 get_domain_delete_protected2_descriptor
)
542 subcontainers
.append(c
)
543 c
= (ldb
.Dn(samdb
, "CN=MicrosoftDNS,%s" % str(dnsdomaindn
)),
544 get_dns_domain_microsoft_dns_descriptor
)
545 subcontainers
.append(c
)
551 """Return separate ACE of an ACL
553 :param acl: A string representing the ACL
554 :return: A hash with different parts
557 p
= re
.compile(r
'(\w+)?(\(.*?\))')
565 hash["aces"].append(e
[1])
570 def chunck_sddl(sddl
):
571 """ Return separate parts of the SDDL (owner, group, ...)
573 :param sddl: An string containing the SDDL to chunk
574 :return: A hash with the different chunk
577 p
= re
.compile(r
'([OGDS]:)(.*?)(?=(?:[GDS]:|$))')
578 tab
= p
.findall(sddl
)
594 def get_clean_sd(sd
):
595 """Get the SD without any inherited ACEs
597 :param sd: SD to strip
598 :return: An SD with inherited ACEs stripped
601 sd_clean
= security
.descriptor()
602 sd_clean
.owner_sid
= sd
.owner_sid
603 sd_clean
.group_sid
= sd
.group_sid
604 sd_clean
.type = sd
.type
605 sd_clean
.revision
= sd
.revision
608 if sd
.sacl
is not None:
610 for i
in range(0, len(aces
)):
613 if not ace
.flags
& security
.SEC_ACE_FLAG_INHERITED_ACE
:
614 sd_clean
.sacl_add(ace
)
618 if sd
.dacl
is not None:
620 for i
in range(0, len(aces
)):
623 if not ace
.flags
& security
.SEC_ACE_FLAG_INHERITED_ACE
:
624 sd_clean
.dacl_add(ace
)
629 def get_diff_sds(refsd
, cursd
, domainsid
, checkSacl
=True):
630 """Get the difference between 2 sd
632 This function split the textual representation of ACL into smaller
633 chunck in order to not to report a simple permutation as a difference
635 :param refsddl: First sddl to compare
636 :param cursddl: Second sddl to compare
637 :param checkSacl: If false we skip the sacl checks
638 :return: A string that explain difference between sddls
641 cursddl
= get_clean_sd(cursd
).as_sddl(domainsid
)
642 refsddl
= get_clean_sd(refsd
).as_sddl(domainsid
)
645 hash_cur
= chunck_sddl(cursddl
)
646 hash_ref
= chunck_sddl(refsddl
)
648 if "owner" not in hash_cur
:
649 txt
= "\tNo owner in current SD"
650 elif "owner" in hash_ref
and hash_cur
["owner"] != hash_ref
["owner"]:
651 txt
= "\tOwner mismatch: %s (in ref) %s" \
652 "(in current)\n" % (hash_ref
["owner"], hash_cur
["owner"])
654 if "group" not in hash_cur
:
655 txt
= "%s\tNo group in current SD" % txt
656 elif "group" in hash_ref
and hash_cur
["group"] != hash_ref
["group"]:
657 txt
= "%s\tGroup mismatch: %s (in ref) %s" \
658 "(in current)\n" % (txt
, hash_ref
["group"], hash_cur
["group"])
664 if part
in hash_cur
and part
in hash_ref
:
666 # both are present, check if they contain the same ACE
669 c_cur
= chunck_acl(hash_cur
[part
])
670 c_ref
= chunck_acl(hash_ref
[part
])
672 for elem
in c_cur
["aces"]:
675 for elem
in c_ref
["aces"]:
683 if len(h_cur
) + len(h_ref
) > 0:
684 txt
= "%s\tPart %s is different between reference" \
685 " and current here is the detail:\n" % (txt
, part
)
688 txt
= "%s\t\t%s ACE is not present in the" \
689 " reference\n" % (txt
, item
)
692 txt
= "%s\t\t%s ACE is not present in the" \
693 " current\n" % (txt
, item
)
695 elif part
in hash_cur
and part
not in hash_ref
:
696 txt
= "%s\tReference ACL hasn't a %s part\n" % (txt
, part
)
697 elif part
not in hash_cur
and part
in hash_ref
:
698 txt
= "%s\tCurrent ACL hasn't a %s part\n" % (txt
, part
)