mirror of
https://github.com/samba-team/samba.git
synced 2025-01-11 05:18:09 +03:00
s4-join: fixed exception handling in join command
This commit is contained in:
parent
abe9ac53f0
commit
8c59bbd757
@ -120,14 +120,14 @@ class dc_join:
|
|||||||
if recursive:
|
if recursive:
|
||||||
try:
|
try:
|
||||||
res = ctx.samdb.search(base=dn, scope=ldb.SCOPE_ONELEVEL, attrs=["dn"])
|
res = ctx.samdb.search(base=dn, scope=ldb.SCOPE_ONELEVEL, attrs=["dn"])
|
||||||
except:
|
except Exception:
|
||||||
return
|
return
|
||||||
for r in res:
|
for r in res:
|
||||||
ctx.del_noerror(r.dn, recursive=True)
|
ctx.del_noerror(r.dn, recursive=True)
|
||||||
try:
|
try:
|
||||||
ctx.samdb.delete(dn)
|
ctx.samdb.delete(dn)
|
||||||
print "Deleted %s" % dn
|
print "Deleted %s" % dn
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def cleanup_old_join(ctx):
|
def cleanup_old_join(ctx):
|
||||||
@ -151,16 +151,15 @@ class dc_join:
|
|||||||
if res:
|
if res:
|
||||||
ctx.new_krbtgt_dn = res[0]["msDS-Krbtgtlink"][0]
|
ctx.new_krbtgt_dn = res[0]["msDS-Krbtgtlink"][0]
|
||||||
ctx.del_noerror(ctx.new_krbtgt_dn)
|
ctx.del_noerror(ctx.new_krbtgt_dn)
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def find_dc(ctx, domain):
|
def find_dc(ctx, domain):
|
||||||
'''find a writeable DC for the given domain'''
|
'''find a writeable DC for the given domain'''
|
||||||
try:
|
try:
|
||||||
ctx.cldap_ret = ctx.net.finddc(domain, nbt.NBT_SERVER_LDAP | nbt.NBT_SERVER_DS | nbt.NBT_SERVER_WRITABLE)
|
ctx.cldap_ret = ctx.net.finddc(domain, nbt.NBT_SERVER_LDAP | nbt.NBT_SERVER_DS | nbt.NBT_SERVER_WRITABLE)
|
||||||
except Exception, reason:
|
except Exception:
|
||||||
print("Failed to find a writeable DC for domain '%s': %s" % (domain, reason))
|
raise Exception("Failed to find a writeable DC for domain '%s'" % domain)
|
||||||
sys.exit(1)
|
|
||||||
if ctx.cldap_ret.client_site is not None and ctx.cldap_ret.client_site != "":
|
if ctx.cldap_ret.client_site is not None and ctx.cldap_ret.client_site != "":
|
||||||
ctx.site = ctx.cldap_ret.client_site
|
ctx.site = ctx.cldap_ret.client_site
|
||||||
return ctx.cldap_ret.pdc_dns_name
|
return ctx.cldap_ret.pdc_dns_name
|
||||||
@ -199,8 +198,10 @@ class dc_join:
|
|||||||
'''check if a DN exists'''
|
'''check if a DN exists'''
|
||||||
try:
|
try:
|
||||||
res = ctx.samdb.search(base=dn, scope=ldb.SCOPE_BASE, attrs=[])
|
res = ctx.samdb.search(base=dn, scope=ldb.SCOPE_BASE, attrs=[])
|
||||||
except ldb.LdbError, (ERR_NO_SUCH_OBJECT, _):
|
except ldb.LdbError, (enum, estr):
|
||||||
return False
|
if enum == ldb.ERR_NO_SUCH_OBJECT:
|
||||||
|
return False
|
||||||
|
raise
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def add_krbtgt_account(ctx):
|
def add_krbtgt_account(ctx):
|
||||||
@ -506,7 +507,7 @@ class dc_join:
|
|||||||
ctx.join_provision()
|
ctx.join_provision()
|
||||||
ctx.join_replicate()
|
ctx.join_replicate()
|
||||||
ctx.join_finalise()
|
ctx.join_finalise()
|
||||||
except:
|
except Exception:
|
||||||
print "Join failed - cleaning up"
|
print "Join failed - cleaning up"
|
||||||
ctx.cleanup_old_join()
|
ctx.cleanup_old_join()
|
||||||
raise
|
raise
|
||||||
|
Loading…
Reference in New Issue
Block a user