def sendDsReplicaSync(drsuapiBind, drsuapi_handle, source_dsa_guid, naming_context, req_option): """Send DS replica sync request. :param drsuapiBind: a drsuapi Bind object :param drsuapi_handle: a drsuapi hanle on the drsuapi connection :param source_dsa_guid: the guid of the source dsa for the replication :param naming_context: the DN of the naming context to replicate :param req_options: replication options for the DsReplicaSync call :raise drsException: if any error occur while sending and receiving the reply for the dsReplicaSync """ nc = drsuapi.DsReplicaObjectIdentifier() nc.dn = naming_context req1 = drsuapi.DsReplicaSyncRequest1() req1.naming_context = nc req1.options = req_option req1.source_dsa_guid = misc.GUID(source_dsa_guid) try: drsuapiBind.DsReplicaSync(drsuapi_handle, 1, req1) except Exception, estr: raise drsException("DsReplicaSync failed %s" % estr)
def run(self, DEST_DC, SOURCE_DC, NC, add_ref=False, sync_forced=False, sambaopts=None, credopts=None, versionopts=None, server=None): self.server = DEST_DC self.lp = sambaopts.get_loadparm() self.creds = credopts.get_credentials(self.lp, fallback_machine=True) drsuapi_connect(self) samdb_connect(self) # we need to find the NTDS GUID of the source DC msg = self.samdb.search(base=self.samdb.get_config_basedn(), expression="(&(objectCategory=server)(|(name=%s)(dNSHostName=%s)))" % (SOURCE_DC, SOURCE_DC), attrs=[]) if len(msg) == 0: raise CommandError("Failed to find source DC %s" % SOURCE_DC) server_dn = msg[0]['dn'] msg = self.samdb.search(base=server_dn, scope=ldb.SCOPE_ONELEVEL, expression="(|(objectCategory=nTDSDSA)(objectCategory=nTDSDSARO))", attrs=['objectGUID', 'options']) if len(msg) == 0: raise CommandError("Failed to find source NTDS DN %s" % SOURCE_DC) source_dsa_guid = msg[0]['objectGUID'][0] options = int(attr_default(msg, 'options', 0)) nc = drsuapi.DsReplicaObjectIdentifier() nc.dn = NC req1 = drsuapi.DsReplicaSyncRequest1() req1.naming_context = nc; req1.options = 0 if not (options & dsdb.DS_NTDSDSA_OPT_DISABLE_OUTBOUND_REPL): req1.options |= drsuapi.DRSUAPI_DRS_WRIT_REP if add_ref: req1.options |= drsuapi.DRSUAPI_DRS_ADD_REF if sync_forced: req1.options |= drsuapi.DRSUAPI_DRS_SYNC_FORCED req1.source_dsa_guid = misc.GUID(source_dsa_guid) try: self.drsuapi.DsReplicaSync(self.drsuapi_handle, 1, req1) except Exception, estr: raise CommandError("DsReplicaSync failed", estr)