From ca3f3041106dbaa8462aeb78c35b640b169d694a Mon Sep 17 00:00:00 2001 From: Jan Cholasta Date: Mon, 23 Jan 2012 09:50:41 -0500 Subject: Base64-decode unicode values in Bytes parameters. Fix wrong handling of strings in --setattr/--addattr/--delattr. These changes make it possible to use Bytes in --setattr/--addattr/ --delattr without errors. Fixes managing SSH keys on command-line https://fedorahosted.org/freeipa/ticket/754 --- ipalib/plugins/baseldap.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'ipalib/plugins/baseldap.py') diff --git a/ipalib/plugins/baseldap.py b/ipalib/plugins/baseldap.py index 66339cca..d619f14e 100644 --- a/ipalib/plugins/baseldap.py +++ b/ipalib/plugins/baseldap.py @@ -24,6 +24,7 @@ import re import json import time from copy import deepcopy +import base64 from ipalib import api, crud, errors from ipalib import Method, Object, Command @@ -862,6 +863,9 @@ last, after all sets and adds."""), try: entry_attrs[attr].remove(delval) except ValueError: + if isinstance(delval, str): + # This is a Binary value, base64 encode it + delval = unicode(base64.b64encode(delval)) raise errors.AttrValueNotFound(attr=attr, value=delval) # normalize all values @@ -871,8 +875,8 @@ last, after all sets and adds."""), entry_attrs[attr] = list(set([val for val in entry_attrs[attr] if val])) if not entry_attrs[attr]: entry_attrs[attr] = None - elif len(entry_attrs[attr]) == 1: - entry_attrs[attr] = entry_attrs[attr][0] + elif isinstance(entry_attrs[attr], (tuple, list)) and len(entry_attrs[attr]) == 1: + entry_attrs[attr] = entry_attrs[attr][0] class LDAPCreate(BaseLDAPCommand, crud.Create): """ -- cgit