From d5839133377d481a4ec362e58b185b65c8a9353d Mon Sep 17 00:00:00 2001 From: Garming Sam Date: Tue, 24 Feb 2015 14:13:52 +1300 Subject: [PATCH] kcc: Remove DN translation for Site GUID Signed-off-by: Garming Sam Signed-off-by: Douglas Bagnall Reviewed-by: Andrew Bartlett --- python/samba/kcc_utils.py | 14 ++++++++------ source4/scripting/bin/samba_kcc | 20 +++++--------------- 2 files changed, 13 insertions(+), 21 deletions(-) diff --git a/python/samba/kcc_utils.py b/python/samba/kcc_utils.py index 5b612ccce54..192b274cbdf 100644 --- a/python/samba/kcc_utils.py +++ b/python/samba/kcc_utils.py @@ -1439,11 +1439,12 @@ class Site(object): ssdn = "CN=NTDS Site Settings,%s" % self.site_dnstr attrs = ["options", "interSiteTopologyFailover", - "interSiteTopologyGenerator", - "objectGUID"] + "interSiteTopologyGenerator"] try: res = samdb.search(base=ssdn, scope=ldb.SCOPE_BASE, attrs=attrs) + self_res = samdb.search(base=self.site_dnstr, scope=ldb.SCOPE_BASE, + attrs=['objectGUID']) except ldb.LdbError, (enum, estr): raise Exception("Unable to find site settings for (%s) - (%s)" % (ssdn, estr)) @@ -1458,6 +1459,7 @@ class Site(object): if "interSiteTopologyFailover" in msg: self.site_topo_failover = int(msg["interSiteTopologyFailover"][0]) + msg = self_res[0] if "objectGUID" in msg: self.site_guid = misc.GUID(samdb.schema_format_value("objectGUID", msg["objectGUID"][0])) @@ -2131,7 +2133,7 @@ class SiteLink(object): "siteList" ] try: res = samdb.search(base=self.dnstr, scope=ldb.SCOPE_BASE, - attrs=attrs) + attrs=attrs, controls=['extended_dn:0']) except ldb.LdbError, (enum, estr): raise Exception("Unable to find SiteLink for (%s) - (%s)" % @@ -2154,9 +2156,9 @@ class SiteLink(object): if "siteList" in msg: for value in msg["siteList"]: dsdn = dsdb_Dn(samdb, value) - dnstr = str(dsdn.dn) - if dnstr not in self.site_list: - self.site_list.append(dnstr) + guid = misc.GUID(dsdn.dn.get_extended_component('GUID')) + if guid not in self.site_list: + self.site_list.append(guid) def is_sitelink(self, site1_dnstr, site2_dnstr): """Given a siteLink object, determine if it is a link diff --git a/source4/scripting/bin/samba_kcc b/source4/scripting/bin/samba_kcc index 0c346f09cc7..8189e6c70bd 100755 --- a/source4/scripting/bin/samba_kcc +++ b/source4/scripting/bin/samba_kcc @@ -75,8 +75,6 @@ class KCC(object): self.kcc_failed_links = {} self.kcc_failed_connections = set() - self.site_dn_to_guid = {} - # Used in inter-site topology computation. A list # of connections (by NTDSConnection object) that are # to be kept when pruning un-needed NTDS Connections @@ -163,8 +161,6 @@ class KCC(object): self.my_site_guid = site.site_guid self.my_site = site - self.site_dn_to_guid[self.my_site_dnstr.lower()] = str(self.my_site_guid) - def load_all_sites(self): """Discover all sites and instantiate and load each NTDS Site settings. @@ -191,8 +187,6 @@ class KCC(object): self.site_table[str(site.site_guid)] = site - self.site_dn_to_guid[sitestr.lower()] = str(site.site_guid) - def load_my_dsa(self): """Discover my nTDSDSA dn thru the rootDSE entry @@ -1029,8 +1023,7 @@ class KCC(object): for transport_guid, transport in self.transport_table.items(): # Currently only ever "IP" for site_link_dn, site_link in self.sitelink_table.items(): - new_edge = create_edge(transport_guid, site_link, guid_to_vertex, - self.site_dn_to_guid) + new_edge = create_edge(transport_guid, site_link, guid_to_vertex) connected_vertices.update(new_edge.vertices) g.edges.add(new_edge) @@ -2617,16 +2610,13 @@ def write_search_result(samdb, f, res): lstr = samdb.write_ldif(msg, ldb.CHANGETYPE_NONE) f.write("%s" % lstr) -def create_edge(con_type, site_link, guid_to_vertex, site_dn_to_guid): +def create_edge(con_type, site_link, guid_to_vertex): e = MultiEdge() e.site_link = site_link e.vertices = [] - for site_dn in site_link.site_list: - site_guid = site_dn_to_guid.get(site_dn.lower()) - if site_guid is None: - continue - if site_guid in guid_to_vertex: - e.vertices.extend(guid_to_vertex.get(site_guid)) + for site_guid in site_link.site_list: + if str(site_guid) in guid_to_vertex: + e.vertices.extend(guid_to_vertex.get(str(site_guid))) e.repl_info.cost = site_link.cost e.repl_info.options = site_link.options e.repl_info.interval = site_link.interval