samba-tool: improved user enable error handling
authorAndrew Tridgell <tridge@samba.org>
Wed, 1 Jun 2011 04:41:51 +0000 (14:41 +1000)
committerAndrew Tridgell <tridge@samba.org>
Wed, 1 Jun 2011 07:24:36 +0000 (17:24 +1000)
source4/scripting/python/samba/netcmd/user.py
source4/scripting/python/samba/samdb.py

index 696c8892cfe0d20854847904ffffa1f15cddd1b8..15be4bb87fa8c0e2bbd8d162bba76031a1658c27 100644 (file)
@@ -108,7 +108,12 @@ class cmd_user_enable(Command):
 
         samdb = SamDB(url=H, session_info=system_session(),
             credentials=creds, lp=lp)
-        samdb.enable_account(filter)
+        try:
+            samdb.enable_account(filter)
+        except Exception, msg:
+            raise CommandError("Failed to enable user %s: %s" % (username or filter, msg))
+        print("Enabled user %s" % (username or filter))
+
 
 class cmd_user_setexpiry(Command):
     """Sets the expiration of a user account"""
index 99f141e664233d24f231f5e70f9a5c354290e64a..2cea198e6bfb7b0022174631c52e15ac9c38b506 100644 (file)
@@ -79,6 +79,8 @@ class SamDB(samba.Ldb):
         """
         res = self.search(base=self.domain_dn(), scope=ldb.SCOPE_SUBTREE,
                           expression=search_filter, attrs=["userAccountControl"])
+        if len(res) == 0:
+                raise Exception('Unable to find user "%s"' % search_filter)
         assert(len(res) == 1)
         user_dn = res[0].dn