s4-net: nicer error message (and no exception)
authorAndrew Tridgell <tridge@samba.org>
Thu, 15 Apr 2010 07:14:46 +0000 (17:14 +1000)
committerAndrew Tridgell <tridge@samba.org>
Fri, 16 Apr 2010 04:12:44 +0000 (14:12 +1000)
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>

source4/scripting/python/samba/netcmd/newuser.py
source4/scripting/python/samba/netcmd/setpassword.py

index 3815219460f558cc4df8ad0ea71de5bd2bff45ff..f3babfe780c0dcf377c378cc307c909dd8f9b39b 100644 (file)
@@ -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)
+
index c4a9b00698cccb05d10f3a749ebbf61599c56ed1..a1fe75c02990e5d7ae07c8459cae394f11895467 100644 (file)
@@ -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)
+