]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
join: Fix TypeError when handling exception
authorTim Beale <timbeale@catalyst.net.nz>
Wed, 16 Jan 2019 02:17:38 +0000 (15:17 +1300)
committerKarolin Seeger <kseeger@samba.org>
Tue, 5 Feb 2019 14:33:25 +0000 (15:33 +0100)
When we can't resolve a domain name, we were inadvertently throwing a
TypeError whilst trying to output a helpful message. E.g.

ERROR(<class 'TypeError'>): uncaught exception - 'NTSTATUSError' object
does not support indexing

Instead of indexing the object, we want to index the Exception.args so
that we just display the string portion of the exception error.

The same problem is also present for the domain trust commands.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=13747

Signed-off-by: Tim Beale <timbeale@catalyst.net.nz>
Reviewed-by: Rowland Penny <rpenny@samba.org>
Reviewed-by: Jeremy Allison <rpenny@samba.org>
(cherry picked from commit 3bb7808984c163a7bba66fb983411d1281589722
and modified to work for 4.8 - note that the NTSTATUSError exception
wasn't even imported on 4.8)

python/samba/join.py
python/samba/netcmd/domain.py

index 9782f536dce1f4bf3ca165c2eeb65957a44d9a33..32fac680b1f1ab1d0538d2d8da270e6184fabc41 100644 (file)
@@ -35,7 +35,7 @@ from samba.provision.sambadns import setup_bind9_dns
 from samba import read_and_sub_file
 from samba import werror
 from base64 import b64encode
-from samba import WERRORError
+from samba import WERRORError, NTSTATUSError
 from samba.dnsserver import ARecord, AAAARecord, PTRRecord, CNameRecord, NSRecord, MXRecord, SOARecord, SRVRecord, TXTRecord
 from samba import sd_utils
 import logging
@@ -338,7 +338,7 @@ class dc_join(object):
             ctx.cldap_ret = ctx.net.finddc(domain=domain, flags=nbt.NBT_SERVER_LDAP | nbt.NBT_SERVER_DS | nbt.NBT_SERVER_WRITABLE)
         except NTSTATUSError as error:
             raise Exception("Failed to find a writeable DC for domain '%s': %s" %
-                            (domain, error[1]))
+                            (domain, error.args[1]))
         except Exception:
             raise Exception("Failed to find a writeable DC for domain '%s'" % domain)
         if ctx.cldap_ret.client_site is not None and ctx.cldap_ret.client_site != "":
index 38c800c711b540d18f806437b3699f93b8529634..2901605ce29d403ff92f229e8d931ac6e67bdd27 100644 (file)
@@ -1773,7 +1773,7 @@ class DomainTrustCommand(Command):
             remote_info = remote_net.finddc(flags=remote_flags, domain=domain, address=remote_server)
         except NTSTATUSError as error:
             raise CommandError("Failed to find a writeable DC for domain '%s': %s" %
-                               (domain, error[1]))
+                               (domain, error.args[1]))
         except Exception:
             raise CommandError("Failed to find a writeable DC for domain '%s'" % domain)
         flag_map = {