python: Move get_admin_sid() to SamDB
authorJo Sutton <josutton@catalyst.net.nz>
Mon, 15 Apr 2024 01:23:15 +0000 (13:23 +1200)
committerAndrew Bartlett <abartlet@samba.org>
Wed, 24 Apr 2024 05:16:29 +0000 (05:16 +0000)
Signed-off-by: Jo Sutton <josutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
python/samba/samdb.py
source4/dsdb/tests/python/unicodepwd_encrypted.py

index b831cf562506e86cd0f527d466215f01c9765634..eced40a6541bd3b56eaedb1b8b3959f5ec2eba76 100644 (file)
@@ -1557,6 +1557,13 @@ schemaUpdateNow: 1
         dn = dsdb._dsdb_create_gkdi_root_key(self, *args, **kwargs)
         return dn
 
+    def get_admin_sid(self):
+        res = self.search(
+            base="", expression="", scope=ldb.SCOPE_BASE, attrs=["tokenGroups"])
+
+        return self.schema_format_value(
+            "tokenGroups", res[0]["tokenGroups"][0]).decode("utf8")
+
 
 class dsdb_Dn(object):
     """a class for binary DN"""
index c48f0aa624a16bd32636215c3f2294be25ec4733..e6ec54650a1359ee3870fa4b498eab5e76d61ece 100644 (file)
@@ -6,7 +6,7 @@ import optparse
 sys.path.insert(0, "bin/python")
 import samba.getopt as options
 from ldb import Message, MessageElement, Dn
-from ldb import LdbError, FLAG_MOD_REPLACE, ERR_UNWILLING_TO_PERFORM, SCOPE_BASE
+from ldb import LdbError, FLAG_MOD_REPLACE, ERR_UNWILLING_TO_PERFORM
 from samba import gensec
 from samba.auth import system_session
 from samba.samdb import SamDB
@@ -75,13 +75,6 @@ class UnicodePwdEncryptedConnectionTests(PasswordTestCase):
         )
         ldb.modify(m)
 
-    def get_admin_sid(self, ldb):
-        res = ldb.search(
-            base="", expression="", scope=SCOPE_BASE, attrs=["tokenGroups"])
-
-        return ldb.schema_format_value(
-            "tokenGroups", res[0]["tokenGroups"][0]).decode("utf8")
-
     def test_with_seal(self):
         """Test unicodePwd on connection with seal.
 
@@ -123,7 +116,7 @@ class UnicodePwdEncryptedConnectionTests(PasswordTestCase):
 
     def test_simple_bind_plain(self):
         """Test unicodePwd using simple bind without encryption."""
-        admin_sid = self.get_admin_sid(self.ldb)
+        admin_sid = self.ldb.get_admin_sid()
 
         self.creds.set_bind_dn(admin_sid)
         ldb = SamDB(url=host_ldap, credentials=self.creds, lp=lp)
@@ -140,7 +133,7 @@ class UnicodePwdEncryptedConnectionTests(PasswordTestCase):
 
     def test_simple_bind_tls(self):
         """Test unicodePwd using simple bind with encryption."""
-        admin_sid = self.get_admin_sid(self.ldb)
+        admin_sid = self.ldb.get_admin_sid()
 
         self.creds.set_bind_dn(admin_sid)
         ldb = SamDB(url=host_ldaps, credentials=self.creds, lp=lp)