mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
Completely remove attributes when delattr argument in ipa-groupmod
This commit is contained in:
@@ -67,9 +67,18 @@ def parse_options():
|
|||||||
|
|
||||||
return options, args
|
return options, args
|
||||||
|
|
||||||
def get_group(client, group_cn):
|
def get_group(client, options, group_cn):
|
||||||
try:
|
try:
|
||||||
group = client.get_entry_by_cn(group_cn)
|
attrs = ['*']
|
||||||
|
|
||||||
|
# in case any attributes being modified are operational such as
|
||||||
|
# nsaccountlock. Any attribute to be deleted needs to be included
|
||||||
|
# in the original record so it can be seen as being removed.
|
||||||
|
if options.delattr:
|
||||||
|
for d in options.delattr:
|
||||||
|
attrs.append(d)
|
||||||
|
group = client.get_entry_by_cn(group_cn, sattrs=attrs)
|
||||||
|
|
||||||
except ipa.ipaerror.IPAError, e:
|
except ipa.ipaerror.IPAError, e:
|
||||||
print "%s" % e.message
|
print "%s" % e.message
|
||||||
return None
|
return None
|
||||||
@@ -88,7 +97,7 @@ def main():
|
|||||||
try:
|
try:
|
||||||
client = ipaclient.IPAClient()
|
client = ipaclient.IPAClient()
|
||||||
if options.add:
|
if options.add:
|
||||||
group = get_group(client, args[2])
|
group = get_group(client, options, args[2])
|
||||||
if group is None:
|
if group is None:
|
||||||
return 1
|
return 1
|
||||||
users = args[1].split(',')
|
users = args[1].split(',')
|
||||||
@@ -96,7 +105,7 @@ def main():
|
|||||||
client.add_user_to_group(user, group.dn)
|
client.add_user_to_group(user, group.dn)
|
||||||
print user + " successfully added to " + args[2]
|
print user + " successfully added to " + args[2]
|
||||||
elif options.remove:
|
elif options.remove:
|
||||||
group = get_group(client, args[2])
|
group = get_group(client, options, args[2])
|
||||||
if group is None:
|
if group is None:
|
||||||
return 1
|
return 1
|
||||||
users = args[1].split(',')
|
users = args[1].split(',')
|
||||||
@@ -104,7 +113,7 @@ def main():
|
|||||||
client.remove_user_from_group(user, group.dn)
|
client.remove_user_from_group(user, group.dn)
|
||||||
print user + " successfully removed"
|
print user + " successfully removed"
|
||||||
else:
|
else:
|
||||||
group = get_group(client, args[1])
|
group = get_group(client, options, args[1])
|
||||||
if group is None:
|
if group is None:
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
@@ -113,8 +122,7 @@ def main():
|
|||||||
|
|
||||||
if options.delattr:
|
if options.delattr:
|
||||||
for d in options.delattr:
|
for d in options.delattr:
|
||||||
# doesn't truly delete the attribute but does null out the value
|
group.delValue(d)
|
||||||
group.setValue(d, '')
|
|
||||||
|
|
||||||
if options.setattr:
|
if options.setattr:
|
||||||
for s in options.setattr:
|
for s in options.setattr:
|
||||||
|
|||||||
Reference in New Issue
Block a user