1
0
mirror of https://github.com/samba-team/samba.git synced 2025-12-16 00:23:52 +03:00

samba-tool: avoid traceback for options errors

What option? None yet, but see the next two commits.

We use a local reference to optparse.OptionValueError, to save typing
and make the eventual switch to argparse easier.

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
This commit is contained in:
Douglas Bagnall
2022-09-01 15:32:07 +12:00
committed by Douglas Bagnall
parent 62fe118e99
commit ca7535912b
2 changed files with 10 additions and 2 deletions

View File

@@ -31,6 +31,9 @@ from samba.credentials import (
import sys
OptionError = optparse.OptionValueError
class SambaOptions(optparse.OptionGroup):
"""General Samba-related command line options."""

View File

@@ -19,7 +19,7 @@
import optparse
import samba
from samba import colour
from samba.getopt import SambaOption
from samba.getopt import SambaOption, OptionError
from samba.logger import get_samba_logger
from ldb import LdbError, ERR_INVALID_CREDENTIALS
import sys
@@ -110,7 +110,12 @@ class Command(object):
message = "uncaught exception"
force_traceback = True
if isinstance(inner_exception, LdbError):
if isinstance(e, OptionError):
print(evalue, file=self.errf)
self.usage()
force_traceback = False
elif isinstance(inner_exception, LdbError):
(ldb_ecode, ldb_emsg) = inner_exception.args
if ldb_ecode == ERR_INVALID_CREDENTIALS:
print("Invalid username or password", file=self.errf)