join: Fix TypeError when handling exception
authorTim Beale <timbeale@catalyst.net.nz>
Wed, 16 Jan 2019 02:17:38 +0000 (15:17 +1300)
committerJeremy Allison <jra@samba.org>
Wed, 16 Jan 2019 17:51:27 +0000 (18:51 +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>
python/samba/join.py
python/samba/netcmd/domain.py

index cf5d1b92b66e963c1959a34e8b23913e22478a01..28b7f0b8300f5f7fd8a980375a22e8c12ec68bac 100644 (file)
@@ -346,7 +346,7 @@ class DCJoinContext(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 9c5ae21fdd744d1cd04cbf4f2f7fc494c04b805c..b7aedc16a918e587ee86044a4db0bf116eeda99a 100644 (file)
@@ -1802,7 +1802,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 = {