3f51ca
From efdbea05f716700d8ed659430a6b501b41de0e54 Mon Sep 17 00:00:00 2001
3f51ca
From: Alexander Bokovoy <abokovoy@redhat.com>
3f51ca
Date: Thu, 19 Oct 2017 13:21:05 +0300
3f51ca
Subject: [PATCH] adtrust: filter out subdomains when defining our topology to
3f51ca
 AD
3f51ca
3f51ca
When definining a topology of a forest to be visible over a cross-forest
3f51ca
trust, we set *.<forest name> as all-catch top level name already.
3f51ca
3f51ca
This means that all DNS subdomains of the forest will already be matched
3f51ca
by this top level name (TLN). If we add more TLNs for subdomains, Active
3f51ca
Directory will respond with NT_STATUS_INVALID_PARAMETER.
3f51ca
3f51ca
Filter out all subdomains of the forest root domain. All other realm
3f51ca
domains will be added with explicit TLN records.
3f51ca
3f51ca
Also filter out single label domains. These aren't possible to add as
3f51ca
TLNs to Windows Server 2016 as it considers them incorrect. Given that
3f51ca
we do not allow single lable domains as part of freeIPA installs, this
3f51ca
is another layer of protection here.
3f51ca
3f51ca
Fixes https://pagure.io/freeipa/issue/6666
3f51ca
3f51ca
Reviewed-By: Christian Heimes <cheimes@redhat.com>
3f51ca
---
3f51ca
 ipaserver/dcerpc.py | 16 ++++++++++++++++
3f51ca
 1 file changed, 16 insertions(+)
3f51ca
3f51ca
diff --git a/ipaserver/dcerpc.py b/ipaserver/dcerpc.py
3f51ca
index d684a17cabe43bbbd43d29f75f534b6e50fccd12..aa63cd9db0a1d47b5309cc6bed2ff7584760a39d 100644
3f51ca
--- a/ipaserver/dcerpc.py
3f51ca
+++ b/ipaserver/dcerpc.py
3f51ca
@@ -50,6 +50,7 @@ import samba
3f51ca
 
3f51ca
 import ldap as _ldap
3f51ca
 from ipapython import ipaldap
3f51ca
+from ipapython.dnsutil import DNSName
3f51ca
 from dns import resolver, rdatatype
3f51ca
 from dns.exception import DNSException
3f51ca
 import pysss_nss_idmap
3f51ca
@@ -1589,7 +1590,22 @@ class TrustDomainJoins(object):
3f51ca
                      entry.single_value.get('modifytimestamp').timetuple()
3f51ca
                 )*1e7+116444736000000000)
3f51ca
 
3f51ca
+        forest = DNSName(self.local_domain.info['dns_forest'])
3f51ca
+        # tforest is IPA forest. keep the line below for future checks
3f51ca
+        # tforest = DNSName(self.remote_domain.info['dns_forest'])
3f51ca
         for dom in realm_domains['associateddomain']:
3f51ca
+            d = DNSName(dom)
3f51ca
+
3f51ca
+            # We should skip all DNS subdomains of our forest
3f51ca
+            # because we are going to add *.<forest> TLN anyway
3f51ca
+            if forest.is_superdomain(d) and forest != d:
3f51ca
+                continue
3f51ca
+
3f51ca
+            # We also should skip single label TLDs as they
3f51ca
+            # cannot be added as TLNs
3f51ca
+            if len(d.labels) == 1:
3f51ca
+                continue
3f51ca
+
3f51ca
             ftinfo = dict()
3f51ca
             ftinfo['rec_name'] = dom
3f51ca
             ftinfo['rec_time'] = trust_timestamp
3f51ca
-- 
3f51ca
2.13.6
3f51ca