samba-tool group addmembers: add new option --object-types
authorBjörn Baumbach <bb@sernet.de>
Fri, 9 Aug 2019 15:07:07 +0000 (17:07 +0200)
committerStefan Metzmacher <metze@samba.org>
Tue, 21 Jan 2020 14:38:46 +0000 (14:38 +0000)
With this option the admin can specify the object types of the group
members which will be added to the group. The search filter for the objects
will be created according to the types.

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

index 2e1db1371b4a66199d2b4a697bf8bcbfe67b25a9..6a8da402c47c691c33970d5c3ab9578066b0b183 100644 (file)
@@ -229,12 +229,27 @@ Example2 shows how to add a single user account, User2, to the supergroup AD gro
     takes_options = [
         Option("-H", "--URL", help="LDB URL for database or target server", type=str,
                metavar="URL", dest="H"),
+        Option("--object-types",
+               help=("Comma separated list of object types.\n"
+                     "The types are used to filter the search for the "
+                     "specified members.\n"
+                     "Valid values are: user, group, computer, serviceaccount, "
+                     "contact and all.\n"
+                     "Default: user,group,computer"),
+               default="user,group,computer",
+               type=str),
     ]
 
     takes_args = ["groupname", "listofmembers"]
 
-    def run(self, groupname, listofmembers, credopts=None, sambaopts=None,
-            versionopts=None, H=None):
+    def run(self,
+            groupname,
+            listofmembers,
+            credopts=None,
+            sambaopts=None,
+            versionopts=None,
+            H=None,
+            object_types="user,group,computer"):
 
         lp = sambaopts.get_loadparm()
         creds = credopts.get_credentials(lp, fallback_machine=True)
@@ -243,8 +258,10 @@ Example2 shows how to add a single user account, User2, to the supergroup AD gro
             samdb = SamDB(url=H, session_info=system_session(),
                           credentials=creds, lp=lp)
             groupmembers = listofmembers.split(',')
+            group_member_types = object_types.split(',')
             samdb.add_remove_group_members(groupname, groupmembers,
-                                           add_members_operation=True)
+                                           add_members_operation=True,
+                                           member_types=group_member_types)
         except Exception as e:
             # FIXME: catch more specific exception
             raise CommandError('Failed to add members "%s" to group "%s"' % (