summaryrefslogtreecommitdiffstats
path: root/ipa_server
diff options
context:
space:
mode:
Diffstat (limited to 'ipa_server')
-rw-r--r--ipa_server/plugins/b_ldap.py18
-rw-r--r--ipa_server/servercore.py13
-rwxr-xr-xipa_server/test_client12
3 files changed, 27 insertions, 16 deletions
diff --git a/ipa_server/plugins/b_ldap.py b/ipa_server/plugins/b_ldap.py
index 69c2aeb58..600f1c86f 100644
--- a/ipa_server/plugins/b_ldap.py
+++ b/ipa_server/plugins/b_ldap.py
@@ -25,7 +25,11 @@ This wraps the python-ldap bindings.
import ldap as _ldap
from ipalib import api
+from ipalib import errors
from ipalib.crud import CrudBackend
+from ipa_server import servercore
+from ipa_server import ipaldap
+import ldap
class ldap(CrudBackend):
@@ -46,6 +50,18 @@ class ldap(CrudBackend):
)
def create(self, **kw):
- return kw
+ if servercore.entry_exists(kw['dn']):
+ raise errors.DuplicateEntry("entry already exists")
+
+ entry = ipaldap.Entry(kw['dn'])
+
+ # dn isn't allowed to be in the entry itself
+ del kw['dn']
+
+ # Fill in our new entry
+ for k in kw:
+ entry.setValues(k, kw[k])
+
+ return servercore.add_entry(entry)
api.register(ldap)
diff --git a/ipa_server/servercore.py b/ipa_server/servercore.py
index 3e98e6f61..7310104df 100644
--- a/ipa_server/servercore.py
+++ b/ipa_server/servercore.py
@@ -184,18 +184,13 @@ def get_user_by_uid(uid, sattrs):
# User support
-def user_exists(uid):
- """Return True if the exists, False otherwise."""
- # FIXME: fix the filter
- # FIXME: should accept a container to look in
-# uid = self.__safe_filter(uid)
- searchfilter = "(&(uid=%s)(objectclass=posixAccount))" % uid
-
+def entry_exists(dn):
+ """Return True if the entry exists, False otherwise."""
try:
- get_sub_entry("cn=accounts," + basedn, searchfilter, ['dn','uid'])
+ get_base_entry(dn, "objectclass=*", ['dn','objectclass'])
return True
except errors.NotFound:
- return True
+ return False
def get_user_by_uid (uid, sattrs):
"""Get a specific user's entry. Return as a dict of values.
diff --git a/ipa_server/test_client b/ipa_server/test_client
index 364fd3b81..3b4794d95 100755
--- a/ipa_server/test_client
+++ b/ipa_server/test_client
@@ -13,16 +13,16 @@ def user_find(uid):
# main
server = xmlrpclib.ServerProxy("http://localhost:8888/")
-print server.system.listMethods()
-print server.system.methodHelp("user_add")
+#print server.system.listMethods()
+#print server.system.methodHelp("user_add")
try:
- args="admin"
+ args="jsmith1"
kw = {'givenname':'Joe', 'sn':'Smith'}
- result = server.user_add(args, kw)
+ result = server.user_add(kw, args)
print "returned %s" % result
except xmlrpclib.Fault, e:
print e.faultString
-user_find("admin")
-user_find("notfound")
+#user_find("admin")
+#user_find("notfound")