1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-22 13:34:15 +03:00

samba python libs: convert 'except X, (tuple)' to 'except X as e'

In addition to converting the except line another line is also added
for each except to extract the tuple contents.

Signed-off-by: Noel Power <noel.power@suse.com>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
This commit is contained in:
Noel Power 2018-02-23 14:29:05 +00:00 committed by Douglas Bagnall
parent efad273122
commit 91a5941f17
10 changed files with 132 additions and 66 deletions

View File

@ -108,7 +108,8 @@ class dbcheck(object):
attrs=["objectSid"])
dnsadmins_sid = ndr_unpack(security.dom_sid, res[0]["objectSid"][0])
self.name_map['DnsAdmins'] = str(dnsadmins_sid)
except ldb.LdbError, (enum, estr):
except ldb.LdbError as e5:
(enum, estr) = e5.args
if enum != ldb.ERR_NO_SUCH_OBJECT:
raise
pass
@ -198,7 +199,8 @@ class dbcheck(object):
self.compatibleFeatures = res[0]["compatibleFeatures"]
if "requiredFeatures" in res[0]:
self.requiredFeatures = res[0]["requiredFeatures"]
except ldb.LdbError as (enum, estr):
except ldb.LdbError as e6:
(enum, estr) = e6.args
if enum != ldb.ERR_NO_SUCH_OBJECT:
raise
pass
@ -253,7 +255,8 @@ class dbcheck(object):
"CN=Deleted Objects\\0ACNF:%s" % str(misc.GUID(guid)))
conflict_dn.add_base(nc)
except ldb.LdbError, (enum, estr):
except ldb.LdbError as e2:
(enum, estr) = e2.args
if enum == ldb.ERR_NO_SUCH_OBJECT:
pass
else:
@ -263,7 +266,8 @@ class dbcheck(object):
if conflict_dn is not None:
try:
self.samdb.rename(dn, conflict_dn, ["show_deleted:1", "relax:0", "show_recycled:1"])
except ldb.LdbError, (enum, estr):
except ldb.LdbError as e1:
(enum, estr) = e1.args
self.report("Couldn't move old Deleted Objects placeholder: %s to %s: %s" % (dn, conflict_dn, estr))
return 1
@ -596,7 +600,8 @@ newSuperior: %s""" % (str(from_dn), str(to_rdn), str(to_base)))
try:
res = self.samdb.search(base=str(dsdb_dn.dn), scope=ldb.SCOPE_BASE,
attrs=[], controls=controls)
except ldb.LdbError, (enum, estr):
except ldb.LdbError as e7:
(enum, estr) = e7.args
self.report("unable to find object for DN %s - (%s)" % (dsdb_dn.dn, estr))
if enum != ldb.ERR_NO_SUCH_OBJECT:
raise
@ -999,7 +1004,8 @@ newSuperior: %s""" % (str(from_dn), str(to_rdn), str(to_base)))
try:
res = self.samdb.search(base=str(dn), scope=ldb.SCOPE_BASE,
attrs=attrs, controls=controls)
except ldb.LdbError, (enum, estr):
except ldb.LdbError as e8:
(enum, estr) = e8.args
if enum != ldb.ERR_NO_SUCH_OBJECT:
raise
@ -1046,7 +1052,8 @@ newSuperior: %s""" % (str(from_dn), str(to_rdn), str(to_base)))
controls=["extended_dn:1:1",
"search_options:1:2",
"paged_results:1:1000"])
except ldb.LdbError, (enum, estr):
except ldb.LdbError as e9:
(enum, estr) = e9.args
raise
for r in res:
@ -1198,7 +1205,8 @@ newSuperior: %s""" % (str(from_dn), str(to_rdn), str(to_base)))
attrs=attrs, controls=["extended_dn:1:1", "show_recycled:1",
"reveal_internals:0"
])
except ldb.LdbError, (enum, estr):
except ldb.LdbError as e3:
(enum, estr) = e3.args
if enum != ldb.ERR_NO_SUCH_OBJECT:
raise
@ -1924,7 +1932,8 @@ newSuperior: %s""" % (str(from_dn), str(to_rdn), str(to_base)))
instancetype |= dsdb.INSTANCE_TYPE_IS_NC_HEAD
try:
self.samdb.search(base=dn.parent(), scope=ldb.SCOPE_BASE, attrs=[], controls=["show_recycled:1"])
except ldb.LdbError, (enum, estr):
except ldb.LdbError as e4:
(enum, estr) = e4.args
if enum != ldb.ERR_NO_SUCH_OBJECT:
raise
else:
@ -1995,7 +2004,8 @@ newSuperior: %s""" % (str(from_dn), str(to_rdn), str(to_base)))
"reveal_internals:0",
],
attrs=attrs)
except ldb.LdbError, (enum, estr):
except ldb.LdbError as e10:
(enum, estr) = e10.args
if enum == ldb.ERR_NO_SUCH_OBJECT:
if self.in_transaction:
self.report("ERROR: Object %s disappeared during check" % dn)
@ -2303,7 +2313,8 @@ newSuperior: %s""" % (str(from_dn), str(to_rdn), str(to_base)))
if dn != self.samdb.get_root_basedn() and str(dn.parent()) not in self.dn_set:
res = self.samdb.search(base=dn.parent(), scope=ldb.SCOPE_BASE,
controls=["show_recycled:1", "show_deleted:1"])
except ldb.LdbError, (enum, estr):
except ldb.LdbError as e11:
(enum, estr) = e11.args
if enum == ldb.ERR_NO_SUCH_OBJECT:
self.err_missing_parent(obj)
error_count += 1
@ -2407,7 +2418,8 @@ newSuperior: %s""" % (str(from_dn), str(to_rdn), str(to_base)))
try:
res = self.samdb.search(base="<SID=%s>" % sid, scope=ldb.SCOPE_BASE,
attrs=[])
except ldb.LdbError, (enum, estr):
except ldb.LdbError as e:
(enum, estr) = e.args
if enum != ldb.ERR_NO_SUCH_OBJECT:
raise
res = None

View File

@ -92,7 +92,8 @@ class dc_join(object):
try:
ctx.samdb.search(scope=ldb.SCOPE_ONELEVEL, attrs=["dn"])
except ldb.LdbError, (enum, estr):
except ldb.LdbError as e4:
(enum, estr) = e4.args
raise DCJoinException(estr)
@ -404,7 +405,8 @@ class dc_join(object):
'''check if a DN exists'''
try:
res = ctx.samdb.search(base=dn, scope=ldb.SCOPE_BASE, attrs=[])
except ldb.LdbError, (enum, estr):
except ldb.LdbError as e5:
(enum, estr) = e5.args
if enum == ldb.ERR_NO_SUCH_OBJECT:
return False
raise
@ -705,7 +707,8 @@ class dc_join(object):
ctx.acct_pass,
force_change_at_next_login=False,
username=ctx.samname)
except ldb.LdbError, (num, _):
except ldb.LdbError as e2:
(num, _) = e2.args
if num != ldb.ERR_UNWILLING_TO_PERFORM:
pass
ctx.net.set_password(account_name=ctx.samname,
@ -754,7 +757,8 @@ class dc_join(object):
samba.dsdb.UF_ACCOUNTDISABLE)
try:
ctx.samdb.add(msg)
except ldb.LdbError, (num, _):
except ldb.LdbError as e:
(num, _) = e.args
if num != ldb.ERR_ENTRY_ALREADY_EXISTS:
raise
@ -770,7 +774,8 @@ class dc_join(object):
ctx.dnspass,
force_change_at_next_login=False,
username=ctx.samname)
except ldb.LdbError, (num, _):
except ldb.LdbError as e3:
(num, _) = e3.args
if num != ldb.ERR_UNWILLING_TO_PERFORM:
raise
ctx.net.set_password(account_name="dns-%s" % ctx.myname,
@ -965,7 +970,8 @@ class dc_join(object):
repl.replicate(ctx.rid_manager_dn, source_dsa_invocation_id,
destination_dsa_guid,
exop=drsuapi.DRSUAPI_EXOP_FSMO_RID_ALLOC)
except samba.DsExtendedError, (enum, estr):
except samba.DsExtendedError as e1:
(enum, estr) = e1.args
if enum == drsuapi.DRSUAPI_EXOP_ERR_FSMO_NOT_OWNER:
print "WARNING: Unable to replicate own RID Set, as server %s (the server we joined) is not the RID Master." % ctx.server
print "NOTE: This is normal and expected, Samba will be able to create users after it contacts the RID Master at first startup."

View File

@ -152,7 +152,8 @@ class KCC(object):
self.samdb.get_config_basedn(),
scope=ldb.SCOPE_SUBTREE,
expression="(objectClass=interSiteTransport)")
except ldb.LdbError, (enum, estr):
except ldb.LdbError as e2:
(enum, estr) = e2.args
raise KCCError("Unable to find inter-site transports - (%s)" %
estr)
@ -186,7 +187,8 @@ class KCC(object):
self.samdb.get_config_basedn(),
scope=ldb.SCOPE_SUBTREE,
expression="(objectClass=siteLink)")
except ldb.LdbError, (enum, estr):
except ldb.LdbError as e3:
(enum, estr) = e3.args
raise KCCError("Unable to find inter-site siteLinks - (%s)" % estr)
for msg in res:
@ -249,7 +251,8 @@ class KCC(object):
self.samdb.get_config_basedn(),
scope=ldb.SCOPE_SUBTREE,
expression="(objectClass=site)")
except ldb.LdbError, (enum, estr):
except ldb.LdbError as e4:
(enum, estr) = e4.args
raise KCCError("Unable to find sites - (%s)" % estr)
for msg in res:
@ -267,7 +270,8 @@ class KCC(object):
try:
res = self.samdb.search(base=dn, scope=ldb.SCOPE_BASE,
attrs=["objectGUID"])
except ldb.LdbError, (enum, estr):
except ldb.LdbError as e5:
(enum, estr) = e5.args
DEBUG_FN("Search for dn '%s' [from %s] failed: %s. "
"This typically happens in --importldif mode due "
"to lack of module support." % (dn, dn_query, estr))
@ -286,7 +290,8 @@ class KCC(object):
res = self.samdb.search(base=dn, scope=ldb.SCOPE_BASE,
attrs=["objectGUID"])
except ldb.LdbError, (enum, estr):
except ldb.LdbError as e:
(enum, estr) = e.args
raise KCCError("Unable to find my nTDSDSA - (%s)" % estr)
if len(res) != 1:
@ -326,7 +331,8 @@ class KCC(object):
self.samdb.get_config_basedn(),
scope=ldb.SCOPE_SUBTREE,
expression="(objectClass=crossRef)")
except ldb.LdbError, (enum, estr):
except ldb.LdbError as e6:
(enum, estr) = e6.args
raise KCCError("Unable to find partitions - (%s)" % estr)
for msg in res:
@ -2479,7 +2485,8 @@ class KCC(object):
self.samdb = SamDB(url=dburl,
session_info=system_session(),
credentials=creds, lp=lp)
except ldb.LdbError, (num, msg):
except ldb.LdbError as e1:
(num, msg) = e1.args
raise KCCError("Unable to open sam database %s : %s" %
(dburl, msg))

View File

@ -83,7 +83,8 @@ class NamingContext(object):
res = samdb.search(base=self.nc_dnstr,
scope=ldb.SCOPE_BASE, attrs=attrs)
except ldb.LdbError, (enum, estr):
except ldb.LdbError as e:
(enum, estr) = e.args
raise KCCError("Unable to find naming context (%s) - (%s)" %
(self.nc_dnstr, estr))
msg = res[0]
@ -301,7 +302,8 @@ class NCReplica(NamingContext):
res = samdb.search(base=self.nc_dnstr, scope=ldb.SCOPE_BASE,
attrs=["repsFrom"])
except ldb.LdbError, (enum, estr):
except ldb.LdbError as e1:
(enum, estr) = e1.args
raise KCCError("Unable to find NC for (%s) - (%s)" %
(self.nc_dnstr, estr))
@ -389,7 +391,8 @@ class NCReplica(NamingContext):
res = samdb.search(base=self.nc_dnstr, scope=ldb.SCOPE_BASE,
attrs=["replUpToDateVector"])
except ldb.LdbError, (enum, estr):
except ldb.LdbError as e2:
(enum, estr) = e2.args
raise KCCError("Unable to find NC for (%s) - (%s)" %
(self.nc_dnstr, estr))
@ -423,7 +426,8 @@ class NCReplica(NamingContext):
res = samdb.search(base=self.nc_dnstr, scope=ldb.SCOPE_BASE,
attrs=["fSMORoleOwner"])
except ldb.LdbError, (enum, estr):
except ldb.LdbError as e3:
(enum, estr) = e3.args
raise KCCError("Unable to find NC for (%s) - (%s)" %
(self.nc_dnstr, estr))
@ -452,7 +456,8 @@ class NCReplica(NamingContext):
res = samdb.search(base=self.nc_dnstr, scope=ldb.SCOPE_BASE,
attrs=["repsTo"])
except ldb.LdbError, (enum, estr):
except ldb.LdbError as e4:
(enum, estr) = e4.args
raise KCCError("Unable to find NC for (%s) - (%s)" %
(self.nc_dnstr, estr))
@ -644,7 +649,8 @@ class DirectoryServiceAgent(object):
res = samdb.search(base=self.dsa_dnstr, scope=ldb.SCOPE_BASE,
attrs=attrs)
except ldb.LdbError, (enum, estr):
except ldb.LdbError as e5:
(enum, estr) = e5.args
raise KCCError("Unable to find nTDSDSA for (%s) - (%s)" %
(self.dsa_dnstr, estr))
@ -705,7 +711,8 @@ class DirectoryServiceAgent(object):
res = samdb.search(base=self.dsa_dnstr, scope=ldb.SCOPE_BASE,
attrs=ncattrs)
except ldb.LdbError, (enum, estr):
except ldb.LdbError as e6:
(enum, estr) = e6.args
raise KCCError("Unable to find nTDSDSA NCs for (%s) - (%s)" %
(self.dsa_dnstr, estr))
@ -773,7 +780,8 @@ class DirectoryServiceAgent(object):
scope=ldb.SCOPE_SUBTREE,
expression="(objectClass=nTDSConnection)")
except ldb.LdbError, (enum, estr):
except ldb.LdbError as e7:
(enum, estr) = e7.args
raise KCCError("Unable to find nTDSConnection for (%s) - (%s)" %
(self.dsa_dnstr, estr))
@ -951,7 +959,8 @@ class NTDSConnection(object):
res = samdb.search(base=self.dnstr, scope=ldb.SCOPE_BASE,
attrs=attrs)
except ldb.LdbError, (enum, estr):
except ldb.LdbError as e8:
(enum, estr) = e8.args
raise KCCError("Unable to find nTDSConnection for (%s) - (%s)" %
(self.dnstr, estr))
@ -1001,7 +1010,8 @@ class NTDSConnection(object):
res = samdb.search(base=tdnstr,
scope=ldb.SCOPE_BASE, attrs=attrs)
except ldb.LdbError, (enum, estr):
except ldb.LdbError as e9:
(enum, estr) = e9.args
raise KCCError("Unable to find transport (%s) - (%s)" %
(tdnstr, estr))
@ -1028,7 +1038,8 @@ class NTDSConnection(object):
try:
samdb.delete(self.dnstr)
except ldb.LdbError, (enum, estr):
except ldb.LdbError as e10:
(enum, estr) = e10.args
raise KCCError("Could not delete nTDSConnection for (%s) - (%s)" %
(self.dnstr, estr))
@ -1052,7 +1063,8 @@ class NTDSConnection(object):
if len(msg) != 0:
found = True
except ldb.LdbError, (enum, estr):
except ldb.LdbError as e11:
(enum, estr) = e11.args
if enum != ldb.ERR_NO_SUCH_OBJECT:
raise KCCError("Unable to search for (%s) - (%s)" %
(self.dnstr, estr))
@ -1097,7 +1109,8 @@ class NTDSConnection(object):
ldb.FLAG_MOD_ADD, "schedule")
try:
samdb.add(m)
except ldb.LdbError, (enum, estr):
except ldb.LdbError as e12:
(enum, estr) = e12.args
raise KCCError("Could not add nTDSConnection for (%s) - (%s)" %
(self.dnstr, estr))
@ -1120,7 +1133,8 @@ class NTDSConnection(object):
# of self.dnstr in the database.
samdb.search(base=self.dnstr, scope=ldb.SCOPE_BASE)
except ldb.LdbError, (enum, estr):
except ldb.LdbError as e13:
(enum, estr) = e13.args
if enum == ldb.ERR_NO_SUCH_OBJECT:
raise KCCError("nTDSConnection for (%s) doesn't exist!" %
self.dnstr)
@ -1166,7 +1180,8 @@ class NTDSConnection(object):
ldb.MessageElement([], ldb.FLAG_MOD_DELETE, "schedule")
try:
samdb.modify(m)
except ldb.LdbError, (enum, estr):
except ldb.LdbError as e14:
(enum, estr) = e14.args
raise KCCError("Could not modify nTDSConnection for (%s) - (%s)" %
(self.dnstr, estr))
@ -1326,7 +1341,8 @@ class Partition(NamingContext):
res = samdb.search(base=self.partstr, scope=ldb.SCOPE_BASE,
attrs=attrs)
except ldb.LdbError, (enum, estr):
except ldb.LdbError as e15:
(enum, estr) = e15.args
raise KCCError("Unable to find partition for (%s) - (%s)" %
(self.partstr, estr))
msg = res[0]
@ -1466,7 +1482,8 @@ class Site(object):
attrs=attrs)
self_res = samdb.search(base=self.site_dnstr, scope=ldb.SCOPE_BASE,
attrs=['objectGUID'])
except ldb.LdbError, (enum, estr):
except ldb.LdbError as e16:
(enum, estr) = e16.args
raise KCCError("Unable to find site settings for (%s) - (%s)" %
(ssdn, estr))
@ -1497,7 +1514,8 @@ class Site(object):
res = samdb.search(self.site_dnstr,
scope=ldb.SCOPE_SUBTREE,
expression="(objectClass=nTDSDSA)")
except ldb.LdbError, (enum, estr):
except ldb.LdbError as e17:
(enum, estr) = e17.args
raise KCCError("Unable to find nTDSDSAs - (%s)" % estr)
for msg in res:
@ -1885,7 +1903,8 @@ class Transport(object):
res = samdb.search(base=self.dnstr, scope=ldb.SCOPE_BASE,
attrs=attrs)
except ldb.LdbError, (enum, estr):
except ldb.LdbError as e18:
(enum, estr) = e18.args
raise KCCError("Unable to find Transport for (%s) - (%s)" %
(self.dnstr, estr))
@ -2145,7 +2164,8 @@ class SiteLink(object):
res = samdb.search(base=self.dnstr, scope=ldb.SCOPE_BASE,
attrs=attrs, controls=['extended_dn:0'])
except ldb.LdbError, (enum, estr):
except ldb.LdbError as e19:
(enum, estr) = e19.args
raise KCCError("Unable to find SiteLink for (%s) - (%s)" %
(self.dnstr, estr))

View File

@ -109,7 +109,8 @@ def samdb_to_ldif_file(samdb, dburl, lp, creds, ldif_file):
samdb = SamDB(url=dburl,
session_info=system_session(),
credentials=creds, lp=lp)
except ldb.LdbError, (enum, estr):
except ldb.LdbError as e:
(enum, estr) = e.args
raise LdifError("Unable to open sam database (%s) : %s" %
(dburl, estr))
@ -396,7 +397,8 @@ def samdb_to_ldif_file(samdb, dburl, lp, creds, ldif_file):
# Write rootdse output
write_search_result(samdb, f, res)
except ldb.LdbError, (enum, estr):
except ldb.LdbError as e1:
(enum, estr) = e1.args
raise LdifError("Error processing (%s) : %s" % (sstr, estr))
f.close()

View File

@ -428,7 +428,8 @@ def get_last_provision_usn(sam):
entry = sam.search(expression="%s=*" % LAST_PROVISION_USN_ATTRIBUTE,
base="@PROVISION", scope=ldb.SCOPE_BASE,
attrs=[LAST_PROVISION_USN_ATTRIBUTE, "provisionnerID"])
except ldb.LdbError, (ecode, emsg):
except ldb.LdbError as e1:
(ecode, emsg) = e1.args
if ecode == ldb.ERR_NO_SUCH_OBJECT:
return None
raise
@ -1274,7 +1275,8 @@ def setup_samdb(path, session_info, provision_backend, lp, names,
# DB
try:
samdb.connect(path)
except ldb.LdbError, (num, string_error):
except ldb.LdbError as e2:
(num, string_error) = e2.args
if (num == ldb.ERR_INSUFFICIENT_ACCESS_RIGHTS):
raise ProvisioningError("Permission denied connecting to %s, are you running as root?" % path)
else:
@ -1902,7 +1904,8 @@ def provision_fill(samdb, secrets_ldb, logger, names, paths,
elements=kerberos_enctypes, flags=ldb.FLAG_MOD_REPLACE,
name="msDS-SupportedEncryptionTypes")
samdb.modify(msg)
except ldb.LdbError, (enum, estr):
except ldb.LdbError as e:
(enum, estr) = e.args
if enum != ldb.ERR_NO_SUCH_ATTRIBUTE:
# It might be that this attribute does not exist in this schema
raise

View File

@ -54,7 +54,8 @@ def remove_sysvol_references(samdb, logger, dc_name):
try:
logger.info("Removing Sysvol reference: %s" % dn)
samdb.delete(dn)
except ldb.LdbError as (enum, estr):
except ldb.LdbError as e:
(enum, estr) = e.args
if enum == ldb.ERR_NO_SUCH_OBJECT:
pass
else:
@ -77,7 +78,8 @@ def remove_sysvol_references(samdb, logger, dc_name):
try:
logger.info("Removing Sysvol reference: %s" % dn)
samdb.delete(dn)
except ldb.LdbError as (enum, estr):
except ldb.LdbError as e1:
(enum, estr) = e1.args
if enum == ldb.ERR_NO_SUCH_OBJECT:
pass
else:
@ -98,7 +100,8 @@ def remove_dns_references(samdb, logger, dnsHostName, ignore_no_name=False):
try:
(dn, primary_recs) = samdb.dns_lookup(dnsHostName)
except RuntimeError as (enum, estr):
except RuntimeError as e4:
(enum, estr) = e4.args
if enum == werror.WERR_DNS_ERROR_NAME_DOES_NOT_EXIST:
if ignore_no_name:
remove_hanging_dns_references(samdb, logger,
@ -145,7 +148,8 @@ def remove_dns_references(samdb, logger, dnsHostName, ignore_no_name=False):
try:
logger.debug("checking for DNS records to remove on %s" % a_name)
(a_rec_dn, a_recs) = samdb.dns_lookup(a_name)
except RuntimeError as (enum, estr):
except RuntimeError as e2:
(enum, estr) = e2.args
if enum == werror.WERR_DNS_ERROR_NAME_DOES_NOT_EXIST:
return
raise DemoteException("lookup of %s failed: %s" % (a_name, estr))
@ -300,7 +304,8 @@ def offline_remove_ntds_dc(samdb,
try:
msgs = samdb.search(base=ntds_dn, expression="objectClass=ntdsDSA",
attrs=["objectGUID"], scope=ldb.SCOPE_BASE)
except LdbError as (enum, estr):
except LdbError as e5:
(enum, estr) = e5.args
if enum == ldb.ERR_NO_SUCH_OBJECT:
raise DemoteException("Given DN %s doesn't exist" % ntds_dn)
else:
@ -349,7 +354,8 @@ def offline_remove_ntds_dc(samdb,
try:
logger.info("Removing nTDSDSA: %s (and any children)" % ntds_dn)
samdb.delete(ntds_dn, ["tree_delete:0"])
except LdbError as (enum, estr):
except LdbError as e6:
(enum, estr) = e6.args
raise DemoteException("Failed to remove the DCs NTDS DSA object: %s"
% estr)
@ -381,7 +387,8 @@ def remove_dc(samdb, logger, dc_name):
expression="(&(objectClass=server)"
"(cn=%s))"
% ldb.binary_encode(dc_name))
except LdbError as (enum, estr):
except LdbError as e3:
(enum, estr) = e3.args
raise DemoteException("Failure checking if %s is an server "
"object in %s: "
% (dc_name, samdb.domain_dns_name()), estr)
@ -399,7 +406,8 @@ def remove_dc(samdb, logger, dc_name):
try:
ntds_msgs = samdb.search(base=ntds_dn, attrs=[], scope=ldb.SCOPE_BASE,
expression="(objectClass=ntdsdsa)")
except LdbError as (enum, estr):
except LdbError as e7:
(enum, estr) = e7.args
if enum == ldb.ERR_NO_SUCH_OBJECT:
ntds_msgs = []
pass

View File

@ -107,7 +107,8 @@ def delete_site(samdb, configDn, siteName):
expression="objectClass=site")
if len(ret) != 1:
raise SiteNotFoundException('Site %s does not exist' % siteName)
except LdbError as (enum, estr):
except LdbError as e:
(enum, estr) = e.args
if enum == ldb.ERR_NO_SUCH_OBJECT:
raise SiteNotFoundException('Site %s does not exist' % siteName)

View File

@ -85,7 +85,8 @@ def create_subnet(samdb, configDn, subnet_name, site_name):
m["siteObject"] = ldb.MessageElement(str(dn_site), FLAG_MOD_ADD,
"siteObject")
samdb.add(m)
except ldb.LdbError as (enum, estr):
except ldb.LdbError as e:
(enum, estr) = e.args
if enum == ldb.ERR_INVALID_DN_SYNTAX:
raise SubnetInvalid("%s is not a valid subnet: %s" % (subnet_name, estr))
elif enum == ldb.ERR_ENTRY_ALREADY_EXISTS:
@ -121,7 +122,8 @@ def delete_subnet(samdb, configDn, subnet_name):
expression="objectClass=subnet")
if len(ret) != 1:
raise SubnetNotFound('Subnet %s does not exist' % subnet_name)
except LdbError as (enum, estr):
except LdbError as e1:
(enum, estr) = e1.args
if enum == ldb.ERR_NO_SUCH_OBJECT:
raise SubnetNotFound('Subnet %s does not exist' % subnet_name)
@ -149,7 +151,8 @@ def rename_subnet(samdb, configDn, subnet_name, new_name):
newdnsubnet.set_component(0, "CN", new_name)
try:
samdb.rename(dnsubnet, newdnsubnet)
except LdbError as (enum, estr):
except LdbError as e2:
(enum, estr) = e2.args
if enum == ldb.ERR_NO_SUCH_OBJECT:
raise SubnetNotFound('Subnet %s does not exist' % subnet)
elif enum == ldb.ERR_ENTRY_ALREADY_EXISTS:
@ -187,7 +190,8 @@ def set_subnet_site(samdb, configDn, subnet_name, site_name):
expression="objectClass=subnet")
if len(ret) != 1:
raise SubnetNotFound('Subnet %s does not exist' % subnet_name)
except LdbError as (enum, estr):
except LdbError as e3:
(enum, estr) = e3.args
if enum == ldb.ERR_NO_SUCH_OBJECT:
raise SubnetNotFound('Subnet %s does not exist' % subnet_name)
@ -206,7 +210,8 @@ def set_subnet_site(samdb, configDn, subnet_name, site_name):
expression="objectClass=site")
if len(ret) != 1:
raise SiteNotFoundException('Site %s does not exist' % site_name)
except LdbError as (enum, estr):
except LdbError as e4:
(enum, estr) = e4.args
if enum == ldb.ERR_NO_SUCH_OBJECT:
raise SiteNotFoundException('Site %s does not exist' % site_name)

View File

@ -255,7 +255,8 @@ def add_group_from_mapping_entry(samdb, groupmap, logger):
msg = samdb.search(
base='<SID=%s>' % str(groupmap.sid), scope=ldb.SCOPE_BASE)
found = True
except ldb.LdbError, (ecode, emsg):
except ldb.LdbError as e1:
(ecode, emsg) = e1.args
if ecode == ldb.ERR_NO_SUCH_OBJECT:
found = False
else:
@ -312,7 +313,8 @@ def add_users_to_group(samdb, group, members, logger):
try:
samdb.modify(m)
except ldb.LdbError, (ecode, emsg):
except ldb.LdbError as e:
(ecode, emsg) = e.args
if ecode == ldb.ERR_ENTRY_ALREADY_EXISTS:
logger.debug("skipped re-adding member '%s' to group '%s': %s", member_sid, group.sid, emsg)
elif ecode == ldb.ERR_NO_SUCH_OBJECT: