From: Jo Sutton Date: Mon, 15 Apr 2024 01:23:15 +0000 (+1200) Subject: python: Move get_admin_sid() to SamDB X-Git-Tag: tdb-1.4.11~924 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1889e0aea389662a1e4111d7537f3c4e1c93d492;p=thirdparty%2Fsamba.git python: Move get_admin_sid() to SamDB Signed-off-by: Jo Sutton Reviewed-by: Andrew Bartlett --- diff --git a/python/samba/samdb.py b/python/samba/samdb.py index b831cf56250..eced40a6541 100644 --- a/python/samba/samdb.py +++ b/python/samba/samdb.py @@ -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""" diff --git a/source4/dsdb/tests/python/unicodepwd_encrypted.py b/source4/dsdb/tests/python/unicodepwd_encrypted.py index c48f0aa624a..e6ec54650a1 100644 --- a/source4/dsdb/tests/python/unicodepwd_encrypted.py +++ b/source4/dsdb/tests/python/unicodepwd_encrypted.py @@ -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)