diff options
author | Jelmer Vernooij <jelmer@samba.org> | 2012-06-19 12:43:08 +0200 |
---|---|---|
committer | Jelmer Vernooij <jelmer@samba.org> | 2012-06-21 18:05:33 +0200 |
commit | cbd660d01381465a35dc696b6a135de22f7682e6 (patch) | |
tree | 9ab54901865002a4c36735accb0e04def259af2e /source4/scripting/python | |
parent | 3c74117e2eb6616b8f539807ae8824d963f7987c (diff) | |
download | samba-cbd660d01381465a35dc696b6a135de22f7682e6.tar.gz samba-cbd660d01381465a35dc696b6a135de22f7682e6.tar.bz2 samba-cbd660d01381465a35dc696b6a135de22f7682e6.zip |
samdb: Accept a list of member variables rather than a comma-separated string.
Diffstat (limited to 'source4/scripting/python')
-rw-r--r-- | source4/scripting/python/samba/netcmd/group.py | 7 | ||||
-rw-r--r-- | source4/scripting/python/samba/samdb.py | 7 |
2 files changed, 8 insertions, 6 deletions
diff --git a/source4/scripting/python/samba/netcmd/group.py b/source4/scripting/python/samba/netcmd/group.py index 0f4a744acc..42c236bc95 100644 --- a/source4/scripting/python/samba/netcmd/group.py +++ b/source4/scripting/python/samba/netcmd/group.py @@ -206,7 +206,9 @@ Example2 shows how to add a single user account, User2, to the supergroup AD gro try: samdb = SamDB(url=H, session_info=system_session(), credentials=creds, lp=lp) - samdb.add_remove_group_members(groupname, listofmembers, add_members_operation=True) + groupmembers = listofmembers.split(',') + samdb.add_remove_group_members(groupname, groupmembers, + add_members_operation=True) except Exception, e: # FIXME: catch more specific exception raise CommandError('Failed to add members "%s" to group "%s"' % ( @@ -256,7 +258,8 @@ Example2 shows how to remove a single user account, User2, from the supergroup A try: samdb = SamDB(url=H, session_info=system_session(), credentials=creds, lp=lp) - samdb.add_remove_group_members(groupname, listofmembers, add_members_operation=False) + samdb.add_remove_group_members(groupname, listofmembers.split(","), + add_members_operation=False) except Exception, e: # FIXME: Catch more specific exception raise CommandError('Failed to remove members "%s" from group "%s"' % (listofmembers, groupname), e) diff --git a/source4/scripting/python/samba/samdb.py b/source4/scripting/python/samba/samdb.py index b37854b3e4..2d746de00f 100644 --- a/source4/scripting/python/samba/samdb.py +++ b/source4/scripting/python/samba/samdb.py @@ -226,19 +226,18 @@ pwdLastSet: 0 else: self.transaction_commit() - def add_remove_group_members(self, groupname, listofmembers, + def add_remove_group_members(self, groupname, members, add_members_operation=True): """Adds or removes group members :param groupname: Name of the target group - :param listofmembers: Comma-separated list of group members + :param members: list of group members :param add_members_operation: Defines if its an add or remove operation """ groupfilter = "(&(sAMAccountName=%s)(objectCategory=%s,%s))" % ( ldb.binary_encode(groupname), "CN=Group,CN=Schema,CN=Configuration", self.domain_dn()) - groupmembers = listofmembers.split(',') self.transaction_start() try: @@ -255,7 +254,7 @@ dn: %s changetype: modify """ % (str(targetgroup[0].dn)) - for member in groupmembers: + for member in members: targetmember = self.search(base=self.domain_dn(), scope=ldb.SCOPE_SUBTREE, expression="(|(sAMAccountName=%s)(CN=%s))" % ( ldb.binary_encode(member), ldb.binary_encode(member)), attrs=[]) |