From 046c5824e4f28d07c96e5ad21bef415cfdcf090e Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 15 Apr 2010 17:14:46 +1000 Subject: 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 --- source4/scripting/python/samba/netcmd/newuser.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'source4/scripting/python/samba/netcmd/newuser.py') diff --git a/source4/scripting/python/samba/netcmd/newuser.py b/source4/scripting/python/samba/netcmd/newuser.py index 3815219460f..f3babfe780c 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) + -- cgit