From 0151a2a4c4cea64b0d931aa0e227b187abf28280 Mon Sep 17 00:00:00 2001
From: Andrew Bartlett <abartlet@samba.org>
Date: Fri, 3 Mar 2023 16:49:00 +1300
Subject: [PATCH 31/34] CVE-2023-0614 dsdb: Add pre-cleanup and
 self.addCleanup() of OU created in match_rules tests

BUG: https://bugzilla.samba.org/show_bug.cgi?id=15270

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Joseph Sutton <josephsutton@catalyst.net.nz>

Conflict: NA
Reference: https://attachments.samba.org/attachment.cgi?id=17821
---
 lib/ldb-samba/tests/match_rules.py | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/lib/ldb-samba/tests/match_rules.py b/lib/ldb-samba/tests/match_rules.py
index abf485c9eab..2af1dd6a070 100755
--- a/lib/ldb-samba/tests/match_rules.py
+++ b/lib/ldb-samba/tests/match_rules.py
@@ -31,11 +31,19 @@ class MatchRulesTests(samba.tests.TestCase):
         self.ou_groups = "OU=groups,%s" % self.ou
         self.ou_computers = "OU=computers,%s" % self.ou
 
+        try:
+            self.ldb.delete(self.ou, ["tree_delete:1"])
+        except LdbError as e:
+            pass
+
         # Add a organizational unit to create objects
         self.ldb.add({
             "dn": self.ou,
             "objectclass": "organizationalUnit"})
 
+        self.addCleanup(self.ldb.delete, self.ou, controls=['tree_delete:0'])
+
+
         # Add the following OU hierarchy and set otherWellKnownObjects,
         # which has BinaryDN syntax:
         #
-- 
2.25.1