samba-tool: tidy up uncaught insufficient rights LdbError
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Sun, 3 Mar 2024 21:43:17 +0000 (10:43 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Mon, 4 Mar 2024 02:16:33 +0000 (02:16 +0000)
It is likely that many sub-commands will produce a traceback when people
go `-H ldap://server -Ubob` when they needed to go `-UAdministrator`.

We can catch these and show only the core message.

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
python/samba/netcmd/__init__.py

index 3e1f1c45aef4de035c750740afd62579a7525eac..7d74352620715f721ec7560fe6a3471b6fcc8b20 100644 (file)
@@ -23,7 +23,7 @@ import textwrap
 import traceback
 
 import samba
-from ldb import ERR_INVALID_CREDENTIALS, LdbError
+from ldb import ERR_INVALID_CREDENTIALS, ERR_INSUFFICIENT_ACCESS_RIGHTS, LdbError
 from samba import colour
 from samba.auth import system_session
 from samba.getopt import Option, OptionParser
@@ -242,6 +242,9 @@ class Command(object):
             elif ldb_emsg.startswith("Unable to open tdb "):
                 self._print_error(message, ldb_emsg, 'ldb')
                 force_traceback = False
+            elif ldb_ecode == ERR_INSUFFICIENT_ACCESS_RIGHTS:
+                self._print_error("User has insufficient access rights")
+                force_traceback = False
             else:
                 self._print_error(message, ldb_emsg, 'ldb')