diff options
author | Andrew Tridgell <tridge@samba.org> | 2010-04-15 17:14:46 +1000 |
---|---|---|
committer | Andrew Tridgell <tridge@samba.org> | 2010-04-16 14:12:44 +1000 |
commit | 046c5824e4f28d07c96e5ad21bef415cfdcf090e (patch) | |
tree | 04d8023da1d6a8c5aa80bbc91d1aec706f0b3e3e | |
parent | 22d7a06522088e86eb19b104f24cdf19e576a668 (diff) | |
download | samba-046c5824e4f28d07c96e5ad21bef415cfdcf090e.tar.gz samba-046c5824e4f28d07c96e5ad21bef415cfdcf090e.tar.bz2 samba-046c5824e4f28d07c96e5ad21bef415cfdcf090e.zip |
s4-net: nicer error message (and no exception)
in net newuser and net setpasswd we shouldn't be throwing python
exceptions on normal user errors like unknown user
Pair-Programmed-With: Andrew Bartlett <abartlet@samba.org>
-rw-r--r-- | source4/scripting/python/samba/netcmd/newuser.py | 10 | ||||
-rw-r--r-- | source4/scripting/python/samba/netcmd/setpassword.py | 12 |
2 files changed, 17 insertions, 5 deletions
diff --git a/source4/scripting/python/samba/netcmd/newuser.py b/source4/scripting/python/samba/netcmd/newuser.py index 3815219460..f3babfe780 100644 --- a/source4/scripting/python/samba/netcmd/newuser.py +++ b/source4/scripting/python/samba/netcmd/newuser.py @@ -21,6 +21,7 @@ import samba.getopt as options from samba.netcmd import Command, Option +import sys, ldb from getpass import getpass from samba.auth import system_session @@ -61,5 +62,10 @@ class cmd_newuser(Command): samdb = SamDB(url=H, session_info=system_session(), credentials=creds, lp=lp) - samdb.newuser(username, unixname, password, - force_password_change_at_next_login_req=must_change_at_next_login) + try: + samdb.newuser(username, unixname, password, + force_password_change_at_next_login_req=must_change_at_next_login) + except ldb.LdbError, (num, msg): + print('Failed to create user "%s" : %s' % (username, msg)) + sys.exit(1) + diff --git a/source4/scripting/python/samba/netcmd/setpassword.py b/source4/scripting/python/samba/netcmd/setpassword.py index c4a9b00698..a1fe75c029 100644 --- a/source4/scripting/python/samba/netcmd/setpassword.py +++ b/source4/scripting/python/samba/netcmd/setpassword.py @@ -22,7 +22,7 @@ import samba.getopt as options from samba.netcmd import Command, CommandError, Option - +import sys from getpass import getpass from samba.auth import system_session from samba.samdb import SamDB @@ -68,5 +68,11 @@ class cmd_setpassword(Command): samdb = SamDB(url=H, session_info=system_session(), credentials=creds, lp=lp) - samdb.setpassword(filter, password, - force_change_at_next_login=must_change_at_next_login) + try: + samdb.setpassword(filter, password, + force_change_at_next_login=must_change_at_next_login, + username=username) + except: + print('Failed to set password for user "%s"' % username) + sys.exit(1) + |