summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ipa_server/ipaldap.py9
-rw-r--r--ipa_server/servercore.py33
-rw-r--r--ipalib/plugins/f_user.py21
3 files changed, 55 insertions, 8 deletions
diff --git a/ipa_server/ipaldap.py b/ipa_server/ipaldap.py
index 07b207dc5..4ab0d759c 100644
--- a/ipa_server/ipaldap.py
+++ b/ipa_server/ipaldap.py
@@ -115,6 +115,15 @@ class Entry:
r.append((i[0], n))
return r
+ def toDict(self):
+ """Convert the attrs and values to a dict. The dict is keyed on the
+ attribute name. The value is either single value or a list of values."""
+ result = ipautil.CIDict(self.data)
+ for i in result.keys():
+ result[i] = ipautil.utf8_encode_values(result[i])
+ result['dn'] = self.dn
+ return result
+
def __str__(self):
"""Convert the Entry to its LDIF representation"""
return self.__repr__()
diff --git a/ipa_server/servercore.py b/ipa_server/servercore.py
index 551c84e9a..76c358ef6 100644
--- a/ipa_server/servercore.py
+++ b/ipa_server/servercore.py
@@ -121,6 +121,22 @@ def is_user_unique(uid):
except Exception:
return True
+def get_user_by_uid (uid, sattrs):
+ """Get a specific user's entry. Return as a dict of values.
+ Multi-valued fields are represented as lists.
+ """
+
+ if not isinstance(uid,basestring) or len(uid) == 0:
+ raise SyntaxError("uid is not a string")
+# raise ipaerror.gen_exception(ipaerror.INPUT_INVALID_PARAMETER)
+ if sattrs is not None and not isinstance(sattrs,list):
+ raise SyntaxError("sattrs is not a list")
+# raise ipaerror.gen_exception(ipaerror.INPUT_INVALID_PARAMETER)
+# logging.info("IPA: get_user_by_uid '%s'" % uid)
+# uid = self.__safe_filter(uid)
+ searchfilter = "(uid=" + uid + ")"
+ return get_sub_entry("cn=accounts," + basedn, searchfilter, sattrs)
+
def uid_too_long(uid):
"""Verify that the new uid is within the limits we set. This is a
very narrow test.
@@ -143,14 +159,18 @@ def uid_too_long(uid):
return False
-def update_entry (oldentry, newentry):
+def update_entry (entry):
"""Update an LDAP entry
- oldentry is a dict
- newentry is a dict
+ entry is a dict
+
+ This refreshes the record from LDAP in order to obtain the list of
+ attributes that has changed.
"""
- oldentry = convert_scalar_values(oldentry)
- newentry = convert_scalar_values(newentry)
+ attrs = entry.keys()
+ o = get_base_entry(entry['dn'], "objectclass=*", attrs)
+ oldentry = convert_scalar_values(o)
+ newentry = convert_scalar_values(entry)
# Should be able to get this from either the old or new entry
# but just in case someone has decided to try changing it, use the
@@ -161,8 +181,7 @@ def update_entry (oldentry, newentry):
# FIXME: return a missing DN error message
raise e
- res = context.conn.getConn().updateEntry(moddn, oldentry, newentry)
- return res
+ return context.conn.getConn().updateEntry(moddn, oldentry, newentry)
def add_entry(entry):
"""Add a new entry"""
diff --git a/ipalib/plugins/f_user.py b/ipalib/plugins/f_user.py
index 49b6a3704..0b424d351 100644
--- a/ipalib/plugins/f_user.py
+++ b/ipalib/plugins/f_user.py
@@ -170,7 +170,7 @@ class user_add(crud.Add):
def forward(self, *args, **kw):
result = super(crud.Add, self).forward(*args, **kw)
if result != False:
- print result
+ print "User %s added" % args[0]
api.register(user_add)
@@ -182,6 +182,25 @@ api.register(user_del)
class user_mod(crud.Mod):
'Edit an existing user.'
+ def execute(self, *args, **kw):
+ uid=args[0]
+ result = servercore.get_sub_entry(servercore.basedn, "uid=%s" % uid, ["*"])
+
+ user = kw
+ dn = result.get('dn')
+ del result['dn']
+ entry = ipaldap.Entry((dn, servercore.convert_scalar_values(result)))
+
+ for u in user:
+ entry.setValues(u, user[u])
+
+ result = servercore.update_entry(entry.toDict())
+
+ return result
+ def forward(self, *args, **kw):
+ result = super(crud.Mod, self).forward(*args, **kw)
+ if result != False:
+ print "User %s modified" % args[0]
api.register(user_mod)