mirror of
https://github.com/samba-team/samba.git
synced 2025-03-09 08:58:35 +03:00
samba-tool drs replicate: make pseudo-method a real method
This function can't function without a cmd_drs_replicate class, so it might as well be inside Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
This commit is contained in:
parent
7f7e690231
commit
23001c2835
@ -306,64 +306,6 @@ class cmd_drs_kcc(Command):
|
||||
self.message("Consistency check on %s successful." % DC)
|
||||
|
||||
|
||||
|
||||
def drs_local_replicate(self, SOURCE_DC, NC, full_sync=False, single_object=False,
|
||||
sync_forced=False):
|
||||
'''replicate from a source DC to the local SAM'''
|
||||
|
||||
self.server = SOURCE_DC
|
||||
drsuapi_connect(self)
|
||||
|
||||
self.local_samdb = SamDB(session_info=system_session(), url=None,
|
||||
credentials=self.creds, lp=self.lp)
|
||||
|
||||
self.samdb = SamDB(url="ldap://%s" % self.server,
|
||||
session_info=system_session(),
|
||||
credentials=self.creds, lp=self.lp)
|
||||
|
||||
# work out the source and destination GUIDs
|
||||
res = self.local_samdb.search(base="", scope=ldb.SCOPE_BASE,
|
||||
attrs=["dsServiceName"])
|
||||
self.ntds_dn = res[0]["dsServiceName"][0]
|
||||
|
||||
res = self.local_samdb.search(base=self.ntds_dn, scope=ldb.SCOPE_BASE,
|
||||
attrs=["objectGUID"])
|
||||
self.ntds_guid = misc.GUID(self.samdb.schema_format_value("objectGUID", res[0]["objectGUID"][0]))
|
||||
|
||||
source_dsa_invocation_id = misc.GUID(self.samdb.get_invocation_id())
|
||||
dest_dsa_invocation_id = misc.GUID(self.local_samdb.get_invocation_id())
|
||||
destination_dsa_guid = self.ntds_guid
|
||||
|
||||
exop = drsuapi.DRSUAPI_EXOP_NONE
|
||||
|
||||
if single_object:
|
||||
exop = drsuapi.DRSUAPI_EXOP_REPL_OBJ
|
||||
full_sync = True
|
||||
|
||||
self.samdb.transaction_start()
|
||||
repl = drs_utils.drs_Replicate("ncacn_ip_tcp:%s[seal]" % self.server, self.lp,
|
||||
self.creds, self.local_samdb, dest_dsa_invocation_id)
|
||||
|
||||
# Work out if we are an RODC, so that a forced local replicate
|
||||
# with the admin pw does not sync passwords
|
||||
rodc = self.local_samdb.am_rodc()
|
||||
try:
|
||||
(num_objects, num_links) = repl.replicate(NC,
|
||||
source_dsa_invocation_id, destination_dsa_guid,
|
||||
rodc=rodc, full_sync=full_sync,
|
||||
exop=exop, sync_forced=sync_forced)
|
||||
except Exception as e:
|
||||
raise CommandError("Error replicating DN %s" % NC, e)
|
||||
self.samdb.transaction_commit()
|
||||
|
||||
if full_sync:
|
||||
self.message("Full Replication of all %d objects and %d links from %s to %s was successful."
|
||||
% (num_objects, num_links, SOURCE_DC, self.local_samdb.url))
|
||||
else:
|
||||
self.message("Incremental replication of %d objects and %d links from %s to %s was successful."
|
||||
% (num_objects, num_links, SOURCE_DC, self.local_samdb.url))
|
||||
|
||||
|
||||
class cmd_drs_replicate(Command):
|
||||
"""Replicate a naming context between two DCs."""
|
||||
|
||||
@ -388,6 +330,62 @@ class cmd_drs_replicate(Command):
|
||||
Option("--single-object", help="Replicate only the object specified, instead of the whole Naming Context (only with --local)", action="store_true"),
|
||||
]
|
||||
|
||||
def drs_local_replicate(self, SOURCE_DC, NC, full_sync=False, single_object=False,
|
||||
sync_forced=False):
|
||||
'''replicate from a source DC to the local SAM'''
|
||||
|
||||
self.server = SOURCE_DC
|
||||
drsuapi_connect(self)
|
||||
|
||||
self.local_samdb = SamDB(session_info=system_session(), url=None,
|
||||
credentials=self.creds, lp=self.lp)
|
||||
|
||||
self.samdb = SamDB(url="ldap://%s" % self.server,
|
||||
session_info=system_session(),
|
||||
credentials=self.creds, lp=self.lp)
|
||||
|
||||
# work out the source and destination GUIDs
|
||||
res = self.local_samdb.search(base="", scope=ldb.SCOPE_BASE,
|
||||
attrs=["dsServiceName"])
|
||||
self.ntds_dn = res[0]["dsServiceName"][0]
|
||||
|
||||
res = self.local_samdb.search(base=self.ntds_dn, scope=ldb.SCOPE_BASE,
|
||||
attrs=["objectGUID"])
|
||||
self.ntds_guid = misc.GUID(self.samdb.schema_format_value("objectGUID", res[0]["objectGUID"][0]))
|
||||
|
||||
source_dsa_invocation_id = misc.GUID(self.samdb.get_invocation_id())
|
||||
dest_dsa_invocation_id = misc.GUID(self.local_samdb.get_invocation_id())
|
||||
destination_dsa_guid = self.ntds_guid
|
||||
|
||||
exop = drsuapi.DRSUAPI_EXOP_NONE
|
||||
|
||||
if single_object:
|
||||
exop = drsuapi.DRSUAPI_EXOP_REPL_OBJ
|
||||
full_sync = True
|
||||
|
||||
self.samdb.transaction_start()
|
||||
repl = drs_utils.drs_Replicate("ncacn_ip_tcp:%s[seal]" % self.server, self.lp,
|
||||
self.creds, self.local_samdb, dest_dsa_invocation_id)
|
||||
|
||||
# Work out if we are an RODC, so that a forced local replicate
|
||||
# with the admin pw does not sync passwords
|
||||
rodc = self.local_samdb.am_rodc()
|
||||
try:
|
||||
(num_objects, num_links) = repl.replicate(NC,
|
||||
source_dsa_invocation_id, destination_dsa_guid,
|
||||
rodc=rodc, full_sync=full_sync,
|
||||
exop=exop, sync_forced=sync_forced)
|
||||
except Exception as e:
|
||||
raise CommandError("Error replicating DN %s" % NC, e)
|
||||
self.samdb.transaction_commit()
|
||||
|
||||
if full_sync:
|
||||
self.message("Full Replication of all %d objects and %d links from %s to %s was successful."
|
||||
% (num_objects, num_links, SOURCE_DC, self.local_samdb.url))
|
||||
else:
|
||||
self.message("Incremental replication of %d objects and %d links from %s to %s was successful."
|
||||
% (num_objects, num_links, SOURCE_DC, self.local_samdb.url))
|
||||
|
||||
def run(self, DEST_DC, SOURCE_DC, NC,
|
||||
add_ref=False, sync_forced=False, sync_all=False, full_sync=False,
|
||||
local=False, local_online=False, async_op=False, single_object=False,
|
||||
@ -399,9 +397,9 @@ class cmd_drs_replicate(Command):
|
||||
self.creds = credopts.get_credentials(self.lp, fallback_machine=True)
|
||||
|
||||
if local:
|
||||
drs_local_replicate(self, SOURCE_DC, NC, full_sync=full_sync,
|
||||
single_object=single_object,
|
||||
sync_forced=sync_forced)
|
||||
self.drs_local_replicate(SOURCE_DC, NC, full_sync=full_sync,
|
||||
single_object=single_object,
|
||||
sync_forced=sync_forced)
|
||||
return
|
||||
|
||||
if local_online:
|
||||
|
Loading…
x
Reference in New Issue
Block a user