mirror of
https://github.com/samba-team/samba.git
synced 2025-07-27 07:42:04 +03:00
python: Move partial replication logic into drs_utils.py
This allows us to use this easily from join.py soon Signed-off-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Garming Sam <garming@catalyst.net.nz>
This commit is contained in:
@ -17,8 +17,10 @@
|
|||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#
|
#
|
||||||
|
|
||||||
from samba.dcerpc import drsuapi, misc
|
from samba.dcerpc import drsuapi, misc, drsblobs
|
||||||
from samba.net import Net
|
from samba.net import Net
|
||||||
|
from samba.ndr import ndr_unpack
|
||||||
|
from samba import dsdb
|
||||||
import samba, ldb
|
import samba, ldb
|
||||||
|
|
||||||
|
|
||||||
@ -198,7 +200,7 @@ class drs_Replicate(object):
|
|||||||
|
|
||||||
def replicate(self, dn, source_dsa_invocation_id, destination_dsa_guid,
|
def replicate(self, dn, source_dsa_invocation_id, destination_dsa_guid,
|
||||||
schema=False, exop=drsuapi.DRSUAPI_EXOP_NONE, rodc=False,
|
schema=False, exop=drsuapi.DRSUAPI_EXOP_NONE, rodc=False,
|
||||||
replica_flags=None, highwatermark=None, udv=None):
|
replica_flags=None, full_sync=True):
|
||||||
'''replicate a single DN'''
|
'''replicate a single DN'''
|
||||||
|
|
||||||
# setup for a GetNCChanges call
|
# setup for a GetNCChanges call
|
||||||
@ -209,14 +211,40 @@ class drs_Replicate(object):
|
|||||||
req8.naming_context = drsuapi.DsReplicaObjectIdentifier()
|
req8.naming_context = drsuapi.DsReplicaObjectIdentifier()
|
||||||
req8.naming_context.dn = dn
|
req8.naming_context.dn = dn
|
||||||
|
|
||||||
if highwatermark is not None:
|
udv = None
|
||||||
req8.highwatermark = highwatermark
|
if not full_sync:
|
||||||
else:
|
res = self.samdb.search(base=dn, scope=ldb.SCOPE_BASE,
|
||||||
req8.highwatermark = drsuapi.DsReplicaHighWaterMark()
|
attrs=["repsFrom"])
|
||||||
req8.highwatermark.tmp_highest_usn = 0
|
if "repsFrom" in res[0]:
|
||||||
req8.highwatermark.reserved_usn = 0
|
for reps_from_packed in res[0]["repsFrom"]:
|
||||||
req8.highwatermark.highest_usn = 0
|
reps_from_obj = ndr_unpack(drsblobs.repsFromToBlob, reps_from_packed)
|
||||||
|
if reps_from_obj.ctr.source_dsa_invocation_id == source_dsa_invocation_id:
|
||||||
|
hwm = reps_from_obj.ctr.highwatermark
|
||||||
|
|
||||||
|
udv = drsuapi.DsReplicaCursorCtrEx()
|
||||||
|
udv.version = 1
|
||||||
|
udv.reserved1 = 0
|
||||||
|
udv.reserved2 = 0
|
||||||
|
|
||||||
|
cursors_v1 = []
|
||||||
|
cursors_v2 = dsdb._dsdb_load_udv_v2(self.samdb,
|
||||||
|
self.samdb.get_default_basedn())
|
||||||
|
for cursor_v2 in cursors_v2:
|
||||||
|
cursor_v1 = drsuapi.DsReplicaCursor()
|
||||||
|
cursor_v1.source_dsa_invocation_id = cursor_v2.source_dsa_invocation_id
|
||||||
|
cursor_v1.highest_usn = cursor_v2.highest_usn
|
||||||
|
cursors_v1.append(cursor_v1)
|
||||||
|
|
||||||
|
udv.cursors = cursors_v1
|
||||||
|
udv.count = len(cursors_v1)
|
||||||
|
|
||||||
|
# If we can't find an upToDateVector, or where told not to, replicate fully
|
||||||
|
hwm = drsuapi.DsReplicaHighWaterMark()
|
||||||
|
hwm.tmp_highest_usn = 0
|
||||||
|
hwm.reserved_usn = 0
|
||||||
|
hwm.highest_usn = 0
|
||||||
|
|
||||||
|
req8.highwatermark = hwm
|
||||||
req8.uptodateness_vector = udv
|
req8.uptodateness_vector = udv
|
||||||
|
|
||||||
if replica_flags is not None:
|
if replica_flags is not None:
|
||||||
|
@ -267,39 +267,6 @@ def drs_local_replicate(self, SOURCE_DC, NC, full_sync=False):
|
|||||||
dest_dsa_invocation_id = misc.GUID(self.local_samdb.get_invocation_id())
|
dest_dsa_invocation_id = misc.GUID(self.local_samdb.get_invocation_id())
|
||||||
destination_dsa_guid = self.ntds_guid
|
destination_dsa_guid = self.ntds_guid
|
||||||
|
|
||||||
# If we can't find an upToDateVector, replicate fully
|
|
||||||
hwm = drsuapi.DsReplicaHighWaterMark()
|
|
||||||
hwm.tmp_highest_usn = 0
|
|
||||||
hwm.reserved_usn = 0
|
|
||||||
hwm.highest_usn = 0
|
|
||||||
|
|
||||||
udv = None
|
|
||||||
if not full_sync:
|
|
||||||
res = self.local_samdb.search(base=NC, scope=ldb.SCOPE_BASE,
|
|
||||||
attrs=["repsFrom"])
|
|
||||||
if "repsFrom" in res[0]:
|
|
||||||
for reps_from_packed in res[0]["repsFrom"]:
|
|
||||||
reps_from_obj = ndr_unpack(drsblobs.repsFromToBlob, reps_from_packed)
|
|
||||||
if reps_from_obj.ctr.source_dsa_invocation_id == source_dsa_invocation_id:
|
|
||||||
hwm = reps_from_obj.ctr.highwatermark
|
|
||||||
|
|
||||||
udv = drsuapi.DsReplicaCursorCtrEx()
|
|
||||||
udv.version = 1
|
|
||||||
udv.reserved1 = 0
|
|
||||||
udv.reserved2 = 0
|
|
||||||
|
|
||||||
cursors_v1 = []
|
|
||||||
cursors_v2 = dsdb._dsdb_load_udv_v2(self.local_samdb,
|
|
||||||
self.local_samdb.get_default_basedn())
|
|
||||||
for cursor_v2 in cursors_v2:
|
|
||||||
cursor_v1 = drsuapi.DsReplicaCursor()
|
|
||||||
cursor_v1.source_dsa_invocation_id = cursor_v2.source_dsa_invocation_id
|
|
||||||
cursor_v1.highest_usn = cursor_v2.highest_usn
|
|
||||||
cursors_v1.append(cursor_v1)
|
|
||||||
|
|
||||||
udv.cursors = cursors_v1
|
|
||||||
udv.count = len(cursors_v1)
|
|
||||||
|
|
||||||
self.samdb.transaction_start()
|
self.samdb.transaction_start()
|
||||||
repl = drs_utils.drs_Replicate("ncacn_ip_tcp:%s[seal]" % self.server, self.lp,
|
repl = drs_utils.drs_Replicate("ncacn_ip_tcp:%s[seal]" % self.server, self.lp,
|
||||||
self.creds, self.local_samdb, dest_dsa_invocation_id)
|
self.creds, self.local_samdb, dest_dsa_invocation_id)
|
||||||
@ -310,7 +277,7 @@ def drs_local_replicate(self, SOURCE_DC, NC, full_sync=False):
|
|||||||
try:
|
try:
|
||||||
(num_objects, num_links) = repl.replicate(NC,
|
(num_objects, num_links) = repl.replicate(NC,
|
||||||
source_dsa_invocation_id, destination_dsa_guid,
|
source_dsa_invocation_id, destination_dsa_guid,
|
||||||
rodc=rodc, highwatermark=hwm, udv=udv)
|
rodc=rodc, full_sync=full_sync)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
raise CommandError("Error replicating DN %s" % NC, e)
|
raise CommandError("Error replicating DN %s" % NC, e)
|
||||||
self.samdb.transaction_commit()
|
self.samdb.transaction_commit()
|
||||||
|
Reference in New Issue
Block a user