join.py: Add Replica-Locations for DomainDNS and ForestDNS
authorGarming Sam <garming@catalyst.net.nz>
Mon, 18 Jul 2016 01:09:59 +0000 (13:09 +1200)
committerGarming Sam <garming@samba.org>
Thu, 21 Jul 2016 04:37:08 +0000 (06:37 +0200)
BUG: https://bugzilla.samba.org/show_bug.cgi?id=9200

Signed-off-by: Garming Sam <garming@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
python/samba/join.py

index 091efaf31258dafb5f9564a24efa3cfd8fb86afa..d84da6312f894e94a24449d7e96ce4ad3577ffec 100644 (file)
@@ -600,6 +600,32 @@ class dc_join(object):
         if ctx.ntds_dn:
             ctx.join_add_ntdsdsa()
 
+            # Add the Replica-Locations or RO-Replica-Locations attributes
+            # TODO Is this supposed to be for the schema partition too?
+            expr = "(&(objectClass=crossRef)(ncName=%s))" % ldb.binary_encode(ctx.domaindns_zone)
+            domain = ctx.samdb.search(scope=ldb.SCOPE_ONELEVEL,
+                                      attrs=[],
+                                      base=ctx.samdb.get_partitions_dn(),
+                                      expression=expr)
+
+            expr = "(&(objectClass=crossRef)(ncName=%s))" % ldb.binary_encode(ctx.forestdns_zone)
+            forest = ctx.samdb.search(scope=ldb.SCOPE_ONELEVEL,
+                                      attrs=[],
+                                      base=ctx.samdb.get_partitions_dn(),
+                                      expression=expr)
+
+            for part in (domain, forest):
+                if len(part) == 1:
+                    m = ldb.Message()
+                    m.dn = part[0].dn
+                    attr = "msDS-NC-Replica-Locations"
+                    if ctx.RODC:
+                        attr = "msDS-NC-RO-Replica-Locations"
+
+                    m[attr] = ldb.MessageElement(ctx.ntds_dn,
+                                                 ldb.FLAG_MOD_ADD, attr)
+                    ctx.samdb.modify(m)
+
         if ctx.connection_dn is not None:
             print "Adding %s" % ctx.connection_dn
             rec = {
@@ -867,6 +893,11 @@ class dc_join(object):
                                replica_flags=ctx.domain_replica_flags)
             print "Done with always replicated NC (base, config, schema)"
 
+            # At this point we should already have an entry in the ForestDNS
+            # and DomainDNS NC (those under CN=Partions,DC=...) in order to
+            # indicate that we hold a replica for this NC.
+            #
+            # FIXME make this optional based on --dns-backend=
             for nc in (ctx.domaindns_zone, ctx.forestdns_zone):
                 if nc in ctx.nc_list:
                     print "Replicating %s" % (str(nc))
@@ -874,10 +905,6 @@ class dc_join(object):
                                     destination_dsa_guid, rodc=ctx.RODC,
                                     replica_flags=ctx.replica_flags)
 
-            # FIXME At this point we should add an entry in the forestdns and domaindns NC
-            # (those under CN=Partions,DC=...)
-            # in order to indicate that we hold a replica for this NC
-
             if ctx.RODC:
                 repl.replicate(ctx.acct_dn, source_dsa_invocation_id,
                         destination_dsa_guid,