From aeaa9a8f721affda5dac751f7a54575538e81e4e Mon Sep 17 00:00:00 2001 From: Douglas Bagnall Date: Thu, 26 Jun 2025 12:46:14 +1200 Subject: [PATCH] samba_kcc: use dsdb_dn_guess() We also remove a bit of .decode()ing, which now happens automatically. Signed-off-by: Douglas Bagnall Reviewed-by: Gary Lockyer --- python/samba/kcc/kcc_utils.py | 18 +++++++++--------- python/samba/kcc/ldif_import_export.py | 6 +++--- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/python/samba/kcc/kcc_utils.py b/python/samba/kcc/kcc_utils.py index 326889d8488..f0165344c5a 100644 --- a/python/samba/kcc/kcc_utils.py +++ b/python/samba/kcc/kcc_utils.py @@ -29,7 +29,7 @@ from samba.dcerpc import ( drsuapi, misc, ) -from samba.samdb import dsdb_Dn +from samba.samdb import dsdb_dn_guess from samba.ndr import ndr_unpack, ndr_pack from collections import Counter @@ -743,9 +743,9 @@ class DirectoryServiceAgent(object): # listed. For instance DCs normally have 3 hasMasterNCs # listed. for value in res[0][k]: - # Turn dn into a dsdb_Dn so we can use - # its methods to parse a binary DN - dsdn = dsdb_Dn(samdb, value.decode('utf8')) + # msDS-HasInstantiatedNCs is a BinaryDN, but the + # others are plain DNs. + dsdn = dsdb_dn_guess(samdb, value) flags = dsdn.get_binary_integer() dnstr = str(dsdn.dn) @@ -991,7 +991,7 @@ class NTDSConnection(object): "for (%s)" % (self.dnstr)) if "transportType" in msg: - dsdn = dsdb_Dn(samdb, msg["transportType"][0].decode('utf8')) + dsdn = dsdb_dn_guess(samdb, msg["transportType"][0]) self.load_connection_transport(samdb, str(dsdn.dn)) if "schedule" in msg: @@ -1001,7 +1001,7 @@ class NTDSConnection(object): self.whenCreated = ldb.string_to_time(str(msg["whenCreated"][0])) if "fromServer" in msg: - dsdn = dsdb_Dn(samdb, msg["fromServer"][0].decode('utf8')) + dsdn = dsdb_dn_guess(samdb, msg["fromServer"][0]) self.from_dnstr = str(dsdn.dn) assert self.from_dnstr is not None @@ -1368,7 +1368,7 @@ class Partition(NamingContext): continue for value in msg[k]: - dsdn = dsdb_Dn(samdb, value.decode('utf8')) + dsdn = dsdb_dn_guess(samdb, value) dnstr = str(dsdn.dn) if k == "nCName": @@ -1928,7 +1928,7 @@ class Transport(object): if "bridgeheadServerListBL" in msg: for value in msg["bridgeheadServerListBL"]: - dsdn = dsdb_Dn(samdb, value.decode('utf8')) + dsdn = dsdb_dn_guess(samdb, value) dnstr = str(dsdn.dn) if dnstr not in self.bridgehead_list: self.bridgehead_list.append(dnstr) @@ -2188,7 +2188,7 @@ class SiteLink(object): if "siteList" in msg: for value in msg["siteList"]: - dsdn = dsdb_Dn(samdb, value.decode('utf8')) + dsdn = dsdb_dn_guess(samdb, value) guid = misc.GUID(dsdn.dn.get_extended_component('GUID')) dnstr = str(dsdn.dn) if (guid, dnstr) not in self.site_list: diff --git a/python/samba/kcc/ldif_import_export.py b/python/samba/kcc/ldif_import_export.py index 41f0fd75778..ad584355151 100644 --- a/python/samba/kcc/ldif_import_export.py +++ b/python/samba/kcc/ldif_import_export.py @@ -23,7 +23,7 @@ import os from samba import Ldb, ldb, read_and_sub_file from samba.auth import system_session -from samba.samdb import SamDB, dsdb_Dn +from samba.samdb import SamDB, dsdb_dn_guess class LdifError(Exception): @@ -231,8 +231,8 @@ def samdb_to_ldif_file(samdb, dburl, lp, creds, ldif_file): if k in ncattrs: for value in res_msg[k]: # Some of these have binary DNs so - # use dsdb_Dn to split out relevant parts - dsdn = dsdb_Dn(samdb, value.decode('utf8')) + # use dsdb_dn_guess to split out relevant parts. + dsdn = dsdb_dn_guess(samdb, value) dnstr = str(dsdn.dn) if dnstr not in nclist: nclist.append(dnstr) -- 2.47.2