summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2010-12-15 16:40:59 +0100
committerJelmer Vernooij <jelmer@samba.org>2010-12-15 16:40:59 +0100
commit186c3474c4cdeb366c056a40608abe6e69176145 (patch)
tree1cd63e292741e228076da825289a4e608a65da5d
parentf98d9e06cfc9615834585864ed2348c63fb66adc (diff)
downloadsamba-186c3474c4cdeb366c056a40608abe6e69176145.tar.gz
samba-186c3474c4cdeb366c056a40608abe6e69176145.tar.bz2
samba-186c3474c4cdeb366c056a40608abe6e69176145.zip
join: Properly cancel transaction on exceptions.
-rw-r--r--source4/scripting/python/samba/join.py79
1 files changed, 44 insertions, 35 deletions
diff --git a/source4/scripting/python/samba/join.py b/source4/scripting/python/samba/join.py
index 60f3ac305b..09adf7393b 100644
--- a/source4/scripting/python/samba/join.py
+++ b/source4/scripting/python/samba/join.py
@@ -39,8 +39,8 @@ talloc.enable_null_tracking()
class dc_join:
'''perform a DC join'''
- def __init__(ctx, server=None, creds=None, lp=None, site=None, netbios_name=None,
- targetdir=None, domain=None):
+ def __init__(ctx, server=None, creds=None, lp=None, site=None,
+ netbios_name=None, targetdir=None, domain=None):
ctx.creds = creds
ctx.lp = lp
ctx.site = site
@@ -443,40 +443,49 @@ class dc_join:
print "Starting replication"
ctx.local_samdb.transaction_start()
-
- source_dsa_invocation_id = misc.GUID(ctx.samdb.get_invocation_id())
- destination_dsa_guid = ctx.ntds_guid
-
- if ctx.RODC:
- repl_creds = Credentials()
- repl_creds.guess(ctx.lp)
- repl_creds.set_kerberos_state(DONT_USE_KERBEROS)
- repl_creds.set_username(ctx.samname)
- repl_creds.set_password(ctx.acct_pass)
+ try:
+ source_dsa_invocation_id = misc.GUID(ctx.samdb.get_invocation_id())
+ destination_dsa_guid = ctx.ntds_guid
+
+ if ctx.RODC:
+ repl_creds = Credentials()
+ repl_creds.guess(ctx.lp)
+ repl_creds.set_kerberos_state(DONT_USE_KERBEROS)
+ repl_creds.set_username(ctx.samname)
+ repl_creds.set_password(ctx.acct_pass)
+ else:
+ repl_creds = ctx.creds
+
+ binding_options = "seal"
+ if ctx.lp.get("debug level") >= 5:
+ binding_options += ",print"
+ repl = drs_utils.drs_Replicate(
+ "ncacn_ip_tcp:%s[%s]" % (ctx.server, binding_options),
+ ctx.lp, repl_creds, ctx.local_samdb)
+
+ repl.replicate(ctx.schema_dn, source_dsa_invocation_id,
+ destination_dsa_guid, schema=True, rodc=ctx.RODC,
+ replica_flags=ctx.replica_flags)
+ repl.replicate(ctx.config_dn, source_dsa_invocation_id,
+ destination_dsa_guid, rodc=ctx.RODC,
+ replica_flags=ctx.replica_flags)
+ repl.replicate(ctx.base_dn, source_dsa_invocation_id,
+ destination_dsa_guid, rodc=ctx.RODC,
+ replica_flags=ctx.replica_flags)
+ if ctx.RODC:
+ repl.replicate(ctx.acct_dn, source_dsa_invocation_id,
+ destination_dsa_guid,
+ exop=drsuapi.DRSUAPI_EXOP_REPL_SECRET, rodc=True)
+ repl.replicate(ctx.new_krbtgt_dn, source_dsa_invocation_id,
+ destination_dsa_guid,
+ exop=drsuapi.DRSUAPI_EXOP_REPL_SECRET, rodc=True)
+
+ print "Committing SAM database"
+ except:
+ ctx.local_samdb.transaction_cancel()
+ raise
else:
- repl_creds = ctx.creds
-
- binding_options = "seal"
- if ctx.lp.get("debug level") >= 5:
- binding_options += ",print"
- repl = drs_utils.drs_Replicate("ncacn_ip_tcp:%s[%s]" % (ctx.server, binding_options),
- ctx.lp, repl_creds, ctx.local_samdb)
-
- repl.replicate(ctx.schema_dn, source_dsa_invocation_id, destination_dsa_guid,
- schema=True, rodc=ctx.RODC,
- replica_flags=ctx.replica_flags)
- repl.replicate(ctx.config_dn, source_dsa_invocation_id, destination_dsa_guid,
- rodc=ctx.RODC, replica_flags=ctx.replica_flags)
- repl.replicate(ctx.base_dn, source_dsa_invocation_id, destination_dsa_guid,
- rodc=ctx.RODC, replica_flags=ctx.replica_flags)
- if ctx.RODC:
- repl.replicate(ctx.acct_dn, source_dsa_invocation_id, destination_dsa_guid,
- exop=drsuapi.DRSUAPI_EXOP_REPL_SECRET, rodc=True)
- repl.replicate(ctx.new_krbtgt_dn, source_dsa_invocation_id, destination_dsa_guid,
- exop=drsuapi.DRSUAPI_EXOP_REPL_SECRET, rodc=True)
-
- print "Committing SAM database"
- ctx.local_samdb.transaction_commit()
+ ctx.local_samdb.transaction_commit()
def join_finalise(ctx):