]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
samba-tool group listmembers: handle group-does-not-exist error
authorBjörn Baumbach <bb@sernet.de>
Wed, 26 Feb 2020 12:08:43 +0000 (13:08 +0100)
committerAndrew Bartlett <abartlet@samba.org>
Fri, 28 Feb 2020 03:08:45 +0000 (03:08 +0000)
Return a error with a proper message instead of just do nothing when
the target group does not exist.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14296

Signed-off-by: Björn Baumbach <bb@sernet.de>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
python/samba/netcmd/group.py

index 46000e7f9dec8da5f7b2658d62c69283576f1746..7f51c8e0d271334e86fff22f20acb9571776c907 100644 (file)
@@ -517,15 +517,14 @@ samba-tool group listmembers \"Domain Users\" -H ldap://samba.samdom.example.com
                           credentials=creds, lp=lp)
 
             search_filter = "(&(objectClass=group)(samaccountname=%s))" % groupname
-            res = samdb.search(samdb.domain_dn(), scope=ldb.SCOPE_SUBTREE,
-                               expression=(search_filter),
-                               attrs=["objectSid"])
-
-            if (len(res) != 1):
-                return
-
-            group_dn = res[0].get('dn', idx=0)
-            object_sid = res[0].get('objectSid', idx=0)
+            try:
+                res = samdb.search(samdb.domain_dn(), scope=ldb.SCOPE_SUBTREE,
+                                   expression=(search_filter),
+                                   attrs=["objectSid"])
+                group_dn = res[0].get('dn', idx=0)
+                object_sid = res[0].get('objectSid', idx=0)
+            except IndexError:
+                raise CommandError('Unable to find group "%s"' % (groupname))
 
             object_sid = ndr_unpack(security.dom_sid, object_sid)
             (group_dom_sid, rid) = object_sid.split()