1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
|
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Unix SMB/CIFS implementation.
# Copyright (C) Catalyst.Net Ltd. 2017
# Copyright (C) Andrew Bartlett <abartlet@samba.org> 2019
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
import drs_base
import ldb
import samba
from samba import sd_utils
from ldb import LdbError
class ReplAclTestCase(drs_base.DrsBaseTestCase):
def setUp(self):
super(ReplAclTestCase, self).setUp()
self.mod = "(A;CIOI;GA;;;SY)"
self.mod_becomes = "(A;OICIIO;GA;;;SY)"
self.mod_inherits_as = "(A;OICIIOID;GA;;;SY)"
self.sd_utils_dc1 = sd_utils.SDUtils(self.ldb_dc1)
self.sd_utils_dc2 = sd_utils.SDUtils(self.ldb_dc2)
self.ou = samba.tests.create_test_ou(self.ldb_dc1,
"test_acl_inherit")
# disable replication for the tests so we can control at what point
# the DCs try to replicate
self._disable_all_repl(self.dnsname_dc1)
self._disable_all_repl(self.dnsname_dc2)
# make sure DCs are synchronized before the test
self._net_drs_replicate(DC=self.dnsname_dc2, fromDC=self.dnsname_dc1, forced=True)
self._net_drs_replicate(DC=self.dnsname_dc1, fromDC=self.dnsname_dc2, forced=True)
def tearDown(self):
self.ldb_dc1.delete(self.ou, ["tree_delete:1"])
# re-enable replication
self._enable_all_repl(self.dnsname_dc1)
self._enable_all_repl(self.dnsname_dc2)
super(ReplAclTestCase, self).tearDown()
def test_acl_inheirt_new_object_1_pass(self):
# Set the inherited ACL on the parent OU
self.sd_utils_dc1.dacl_add_ace(self.ou, self.mod)
# Assert ACL set stuck as expected
self.assertIn(self.mod_becomes,
self.sd_utils_dc1.get_sd_as_sddl(self.ou))
# Make a new object
dn = ldb.Dn(self.ldb_dc1, "OU=l2,%s" % self.ou)
self.ldb_dc1.add({"dn": dn, "objectclass": "organizationalUnit"})
self._net_drs_replicate(DC=self.dnsname_dc2,
fromDC=self.dnsname_dc1,
forced=True)
# Assert ACL replicated as expected
self.assertIn(self.mod_becomes,
self.sd_utils_dc2.get_sd_as_sddl(self.ou))
# Confirm inherited ACLs are identical and were inherited
self.assertIn(self.mod_inherits_as,
self.sd_utils_dc1.get_sd_as_sddl(dn))
self.assertEqual(self.sd_utils_dc1.get_sd_as_sddl(dn),
self.sd_utils_dc2.get_sd_as_sddl(dn))
def test_acl_inheirt_new_object(self):
# Set the inherited ACL on the parent OU
self.sd_utils_dc1.dacl_add_ace(self.ou, self.mod)
# Assert ACL set stuck as expected
self.assertIn(self.mod_becomes,
self.sd_utils_dc1.get_sd_as_sddl(self.ou))
# Replicate to DC2
self._net_drs_replicate(DC=self.dnsname_dc2,
fromDC=self.dnsname_dc1,
forced=True)
# Make a new object
dn = ldb.Dn(self.ldb_dc1, "OU=l2,%s" % self.ou)
self.ldb_dc1.add({"dn": dn, "objectclass": "organizationalUnit"})
self._net_drs_replicate(DC=self.dnsname_dc2,
fromDC=self.dnsname_dc1,
forced=True)
# Assert ACL replicated as expected
self.assertIn(self.mod_becomes,
self.sd_utils_dc2.get_sd_as_sddl(self.ou))
# Confirm inherited ACLs are identical and were inherited
self.assertIn(self.mod_inherits_as,
self.sd_utils_dc1.get_sd_as_sddl(dn))
self.assertEqual(self.sd_utils_dc1.get_sd_as_sddl(dn),
self.sd_utils_dc2.get_sd_as_sddl(dn))
def test_acl_inherit_existing_object(self):
# Make a new object
dn = ldb.Dn(self.ldb_dc1, "OU=l2,%s" % self.ou)
self.ldb_dc1.add({"dn": dn, "objectclass": "organizationalUnit"})
try:
self.ldb_dc2.search(scope=ldb.SCOPE_BASE,
base=dn,
attrs=[])
self.fail()
except LdbError as err:
enum = err.args[0]
self.assertEqual(enum, ldb.ERR_NO_SUCH_OBJECT)
self._net_drs_replicate(DC=self.dnsname_dc2,
fromDC=self.dnsname_dc1,
forced=True)
# Confirm it is now replicated
self.ldb_dc2.search(scope=ldb.SCOPE_BASE,
base=dn,
attrs=[])
# Set the inherited ACL on the parent OU
self.sd_utils_dc1.dacl_add_ace(self.ou, self.mod)
# Assert ACL set stuck as expected
self.assertIn(self.mod_becomes,
self.sd_utils_dc1.get_sd_as_sddl(self.ou))
# Replicate to DC2
self._net_drs_replicate(DC=self.dnsname_dc2,
fromDC=self.dnsname_dc1,
forced=True)
# Confirm inherited ACLs are identical and were inherited
# Assert ACL replicated as expected
self.assertIn(self.mod_becomes,
self.sd_utils_dc2.get_sd_as_sddl(self.ou))
self.assertIn(self.mod_inherits_as,
self.sd_utils_dc1.get_sd_as_sddl(dn))
self.assertEqual(self.sd_utils_dc1.get_sd_as_sddl(dn),
self.sd_utils_dc2.get_sd_as_sddl(dn))
def test_acl_inheirt_existing_object_1_pass(self):
# Make a new object
dn = ldb.Dn(self.ldb_dc1, "OU=l2,%s" % self.ou)
self.ldb_dc1.add({"dn": dn, "objectclass": "organizationalUnit"})
try:
self.ldb_dc2.search(scope=ldb.SCOPE_BASE,
base=dn,
attrs=[])
self.fail()
except LdbError as err:
enum = err.args[0]
self.assertEqual(enum, ldb.ERR_NO_SUCH_OBJECT)
# Set the inherited ACL on the parent OU
self.sd_utils_dc1.dacl_add_ace(self.ou, self.mod)
# Assert ACL set as expected
self.assertIn(self.mod_becomes,
self.sd_utils_dc1.get_sd_as_sddl(self.ou))
# Replicate to DC2
self._net_drs_replicate(DC=self.dnsname_dc2,
fromDC=self.dnsname_dc1,
forced=True)
# Assert ACL replicated as expected
self.assertIn(self.mod_becomes,
self.sd_utils_dc2.get_sd_as_sddl(self.ou))
# Confirm inherited ACLs are identical and were inherited
self.assertIn(self.mod_inherits_as,
self.sd_utils_dc1.get_sd_as_sddl(dn))
self.assertEqual(self.sd_utils_dc1.get_sd_as_sddl(dn),
self.sd_utils_dc2.get_sd_as_sddl(dn))
def test_acl_inheirt_renamed_object(self):
# Make a new object
new_ou = samba.tests.create_test_ou(self.ldb_dc1,
"acl_test_l2")
sub_ou_dn = ldb.Dn(self.ldb_dc1, "OU=l2,%s" % self.ou)
try:
self.ldb_dc2.search(scope=ldb.SCOPE_BASE,
base=new_ou,
attrs=[])
self.fail()
except LdbError as err:
enum = err.args[0]
self.assertEqual(enum, ldb.ERR_NO_SUCH_OBJECT)
self._net_drs_replicate(DC=self.dnsname_dc2,
fromDC=self.dnsname_dc1,
forced=True)
# Confirm it is now replicated
self.ldb_dc2.search(scope=ldb.SCOPE_BASE,
base=new_ou,
attrs=[])
# Set the inherited ACL on the parent OU on DC1
self.sd_utils_dc1.dacl_add_ace(self.ou, self.mod)
# Assert ACL set as expected
self.assertIn(self.mod_becomes,
self.sd_utils_dc1.get_sd_as_sddl(self.ou))
# Replicate to DC2
self._net_drs_replicate(DC=self.dnsname_dc2,
fromDC=self.dnsname_dc1,
forced=True)
# Assert ACL replicated as expected
self.assertIn(self.mod_becomes,
self.sd_utils_dc2.get_sd_as_sddl(self.ou))
# Rename to under self.ou
self.ldb_dc1.rename(new_ou, sub_ou_dn)
# Replicate to DC2
self._net_drs_replicate(DC=self.dnsname_dc2,
fromDC=self.dnsname_dc1,
forced=True)
# Confirm inherited ACLs are identical and were inherited
self.assertIn(self.mod_inherits_as,
self.sd_utils_dc1.get_sd_as_sddl(sub_ou_dn))
self.assertEqual(self.sd_utils_dc1.get_sd_as_sddl(sub_ou_dn),
self.sd_utils_dc2.get_sd_as_sddl(sub_ou_dn))
def test_acl_inheirt_renamed_child_object(self):
# Make a new OU
new_ou = samba.tests.create_test_ou(self.ldb_dc1,
"acl_test_l2")
# Here is where the new OU will end up at the end.
sub2_ou_dn_final = ldb.Dn(self.ldb_dc1, "OU=l2,%s" % self.ou)
sub3_ou_dn = ldb.Dn(self.ldb_dc1, "OU=l3,%s" % new_ou)
sub3_ou_dn_final = ldb.Dn(self.ldb_dc1, "OU=l3,%s" % sub2_ou_dn_final)
self.ldb_dc1.add({"dn": sub3_ou_dn,
"objectclass": "organizationalUnit"})
sub4_ou_dn = ldb.Dn(self.ldb_dc1, "OU=l4,%s" % sub3_ou_dn)
sub4_ou_dn_final = ldb.Dn(self.ldb_dc1, "OU=l4,%s" % sub3_ou_dn_final)
self.ldb_dc1.add({"dn": sub4_ou_dn,
"objectclass": "organizationalUnit"})
try:
self.ldb_dc2.search(scope=ldb.SCOPE_BASE,
base=new_ou,
attrs=[])
self.fail()
except LdbError as err:
enum = err.args[0]
self.assertEqual(enum, ldb.ERR_NO_SUCH_OBJECT)
self._net_drs_replicate(DC=self.dnsname_dc2,
fromDC=self.dnsname_dc1,
forced=True)
# Confirm it is now replicated
self.ldb_dc2.search(scope=ldb.SCOPE_BASE,
base=new_ou,
attrs=[])
#
# Given a tree new_ou -> l3 -> l4
#
# Set the inherited ACL on the grandchild OU (l3) on DC1
self.sd_utils_dc1.dacl_add_ace(sub3_ou_dn, self.mod)
# Assert ACL set stuck as expected
self.assertIn(self.mod_becomes,
self.sd_utils_dc1.get_sd_as_sddl(sub3_ou_dn))
# Rename new_ou (l2) to under self.ou (this must happen second). If the
# inheritance between l3 and l4 is name-based, this could
# break.
# The tree is now self.ou -> l2 -> l3 -> l4
self.ldb_dc1.rename(new_ou, sub2_ou_dn_final)
# Assert ACL set remained as expected
self.assertIn(self.mod_becomes,
self.sd_utils_dc1.get_sd_as_sddl(sub3_ou_dn_final))
# Replicate to DC2
self._net_drs_replicate(DC=self.dnsname_dc2,
fromDC=self.dnsname_dc1,
forced=True)
# Confirm set ACLs (on l3 ) are identical and were inherited
self.assertIn(self.mod_becomes,
self.sd_utils_dc2.get_sd_as_sddl(sub3_ou_dn_final))
self.assertEqual(self.sd_utils_dc1.get_sd_as_sddl(sub3_ou_dn_final),
self.sd_utils_dc2.get_sd_as_sddl(sub3_ou_dn_final))
# Confirm inherited ACLs (from l3 to l4) are identical
# and were inherited
self.assertIn(self.mod_inherits_as,
self.sd_utils_dc1.get_sd_as_sddl(sub4_ou_dn_final))
self.assertEqual(self.sd_utils_dc1.get_sd_as_sddl(sub4_ou_dn_final),
self.sd_utils_dc2.get_sd_as_sddl(sub4_ou_dn_final))
def test_acl_inheirt_renamed_object_in_conflict(self):
# Make a new object to be renamed under self.ou
new_ou = samba.tests.create_test_ou(self.ldb_dc1,
"acl_test_l2")
# Make a new OU under self.ou (on DC2)
sub_ou_dn = ldb.Dn(self.ldb_dc2, "OU=l2,%s" % self.ou)
self.ldb_dc2.add({"dn": sub_ou_dn,
"objectclass": "organizationalUnit"})
# Set the inherited ACL on the parent OU
self.sd_utils_dc1.dacl_add_ace(self.ou, self.mod)
# Assert ACL set stuck as expected
self.assertIn(self.mod_becomes,
self.sd_utils_dc1.get_sd_as_sddl(self.ou))
# Replicate to DC2
self._net_drs_replicate(DC=self.dnsname_dc2,
fromDC=self.dnsname_dc1,
forced=True)
# Rename to under self.ou
self.ldb_dc1.rename(new_ou, sub_ou_dn)
self.assertIn(self.mod_inherits_as,
self.sd_utils_dc1.get_sd_as_sddl(sub_ou_dn))
# Replicate to DC2 (will cause a conflict, DC1 to win, version
# is higher since named twice)
self._net_drs_replicate(DC=self.dnsname_dc2,
fromDC=self.dnsname_dc1,
forced=True)
children = self.ldb_dc2.search(scope=ldb.SCOPE_ONELEVEL,
base=self.ou,
attrs=[])
for child in children:
self.assertIn(self.mod_inherits_as,
self.sd_utils_dc2.get_sd_as_sddl(child.dn))
self.assertEqual(self.sd_utils_dc1.get_sd_as_sddl(sub_ou_dn),
self.sd_utils_dc2.get_sd_as_sddl(child.dn))
# Replicate back
self._net_drs_replicate(DC=self.dnsname_dc1,
fromDC=self.dnsname_dc2,
forced=True)
self.assertIn(self.mod_inherits_as,
self.sd_utils_dc1.get_sd_as_sddl(sub_ou_dn))
for child in children:
self.assertIn(self.mod_inherits_as,
self.sd_utils_dc1.get_sd_as_sddl(child.dn))
self.assertEqual(self.sd_utils_dc1.get_sd_as_sddl(child.dn),
self.sd_utils_dc2.get_sd_as_sddl(child.dn))
|