[Freeipa-devel] [PATCH] use cidict for add_user instead of dict
Kevin McCarthy
kmccarth at redhat.com
Fri Aug 17 21:24:56 UTC 2007
Kevin McCarthy wrote:
> Rob Crittenden wrote:
> > Use cidict as the data type instead of dict when adding a user so we avoid
> > case sensitivity in attribute names.
> >
> > John Dennis tracked down a problem we were having with unicode strings too.
> > Basically self.data wasn't getting set in Entry.__init__ for unicode
> > strings so it went insane when you tried to access things.
> >
> > I haven't fully tested unicode strings but they will now be allowed so test
> > away!
>
> > # HG changeset patch
> > # User rcritten at redhat.com
> > # Date 1187382993 14400
> > # Node ID 5c4ee9e04e59ecd0158eae16e810f492325c661f
> > # Parent 242fe060acd4df68ac2ae91f54b37bc4080322dc
> > Use a cidict instead of a dict when adding a new user so we have
> > Allow unicode strings in an Entry
>
> Approved.
there was a merge problem with this. I'm attaching a fixed version that
should merge properly.
-Kevin
-------------- next part --------------
# HG changeset patch
# User Kevin McCarthy <kmccarth at redhat.com>
# Date 1187386074 25200
# Node ID b4b63f510c5f66dce8f91002928009bd8d83c5dd
# Parent 7bfd4001b6b9bd9c7e4c7ff35d678d79297506e2
Manual merge changes in for the cidict/ipaclient add_user()
diff -r 7bfd4001b6b9 -r b4b63f510c5f ipa-admintools/ipa-adduser
--- a/ipa-admintools/ipa-adduser Fri Aug 17 16:36:59 2007 -0400
+++ b/ipa-admintools/ipa-adduser Fri Aug 17 14:27:54 2007 -0700
@@ -26,6 +26,7 @@ import ipa.config
import xmlrpclib
import kerberos
+import ldap
def usage():
print "ipa-adduser [-c|--gecos STRING] [-d|--directory STRING] [-f|--firstname STRING] [-l|--lastname STRING] user"
@@ -55,7 +56,7 @@ def parse_options():
return options, args
def main():
- user={}
+ user=ldap.cidict.cidict()
options, args = parse_options()
if len(args) != 2:
diff -r 7bfd4001b6b9 -r b4b63f510c5f ipa-python/ipaclient.py
--- a/ipa-python/ipaclient.py Fri Aug 17 16:36:59 2007 -0400
+++ b/ipa-python/ipaclient.py Fri Aug 17 14:27:54 2007 -0700
@@ -29,6 +29,14 @@ import ipa
import ipa
import config
+def cidict_to_dict(cid):
+ """Convert a cidict to a standard dict for sending across the wire"""
+ newdict = {}
+ kindex = cid.keys()
+ for dkey in kindex:
+ newdict[dkey] = cid[dkey]
+ return newdict
+
class IPAClient:
def __init__(self,local=None):
@@ -53,7 +61,7 @@ class IPAClient:
return user.User(result)
def add_user(self,user):
- """Add a user. user is a dict of attribute/value pairs"""
+ """Add a user. user is a cidict() of attribute/value pairs"""
realm = config.config.get_realm()
@@ -74,7 +82,9 @@ class IPAClient:
if user.get('gn'):
del user['gn']
- result = self.transport.add_user(user)
+ # convert to a regular dict before sending
+ dict_user = cidict_to_dict(user)
+ result = self.transport.add_user(dict_user)
return result
def get_all_users(self):
diff -r 7bfd4001b6b9 -r b4b63f510c5f ipa-server/ipaserver/ipaldap.py
--- a/ipa-server/ipaserver/ipaldap.py Fri Aug 17 16:36:59 2007 -0400
+++ b/ipa-server/ipaserver/ipaldap.py Fri Aug 17 14:27:54 2007 -0700
@@ -63,7 +63,7 @@ class Entry:
if isinstance(entrydata,tuple):
self.dn = entrydata[0]
self.data = ldap.cidict.cidict(entrydata[1])
- elif isinstance(entrydata,str):
+ elif isinstance(entrydata,str) or isinstance(entrydata,unicode):
self.dn = entrydata
self.data = ldap.cidict.cidict()
else:
diff -r 7bfd4001b6b9 -r b4b63f510c5f ipa-server/xmlrpc-server/funcs.py
--- a/ipa-server/xmlrpc-server/funcs.py Fri Aug 17 16:36:59 2007 -0400
+++ b/ipa-server/xmlrpc-server/funcs.py Fri Aug 17 14:27:54 2007 -0700
@@ -171,14 +171,31 @@ class IPAServer:
return self.convert_entry(ent)
- def add_user (self, user, user_container="ou=users,ou=default",opts=None):
+ def add_user (self, args, user_container="ou=users,ou=default",opts=None):
"""Add a user in LDAP. Takes as input a dict where the key is the
attribute name and the value is either a string or in the case
of a multi-valued field a list of values. user_container sets
where in the tree the user is placed."""
global _LDAPPool
+
+ # The XML-RPC server marshals the arguments into one variable
+ # while the direct caller has them separate. So do a little
+ # bit of gymnastics to figure things out. There has to be a
+ # better way, so FIXME
+ if isinstance(args,tuple):
+ opts = user_container
+ if len(args) == 2:
+ user = args[0]
+ user_container = args[1]
+ else:
+ user = args
+ user_container = "ou=users,ou=default"
+ else:
+ user = args
+
if (isinstance(user, tuple)):
user = user[0]
+
dn="uid=%s,%s,%s" % (user['uid'], user_container,self.basedn)
entry = ipaserver.ipaldap.Entry(str(dn))
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 2228 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/freeipa-devel/attachments/20070817/6e7ccb24/attachment.bin>
More information about the Freeipa-devel
mailing list