diff options
author | Rob Crittenden <rcritten@redhat.com> | 2008-10-14 22:22:01 -0400 |
---|---|---|
committer | Rob Crittenden <rcritten@redhat.com> | 2008-10-14 22:22:01 -0400 |
commit | cfc8450efd92dc0fb6648e97b27416c67625adfb (patch) | |
tree | 8df315efa8690de696c89172a971b9f8dd9f861c /ipa_server | |
parent | 1c3f81852cb8337e2305f968be5bd8165997d27e (diff) | |
download | freeipa-cfc8450efd92dc0fb6648e97b27416c67625adfb.tar.gz freeipa-cfc8450efd92dc0fb6648e97b27416c67625adfb.tar.xz freeipa-cfc8450efd92dc0fb6648e97b27416c67625adfb.zip |
Port user-show to new CrudBackend framework
Diffstat (limited to 'ipa_server')
-rw-r--r-- | ipa_server/plugins/b_ldap.py | 38 |
1 files changed, 36 insertions, 2 deletions
diff --git a/ipa_server/plugins/b_ldap.py b/ipa_server/plugins/b_ldap.py index 600f1c86f..84f25245b 100644 --- a/ipa_server/plugins/b_ldap.py +++ b/ipa_server/plugins/b_ldap.py @@ -29,7 +29,6 @@ from ipalib import errors from ipalib.crud import CrudBackend from ipa_server import servercore from ipa_server import ipaldap -import ldap class ldap(CrudBackend): @@ -39,7 +38,7 @@ class ldap(CrudBackend): dn = _ldap.dn - def get_user_dn(self, uid): + def make_user_dn(self, uid): """ Construct user dn from uid. """ @@ -49,6 +48,35 @@ class ldap(CrudBackend): self.api.env.basedn, ) + def find_entry_dn(self, key_attribute, primary_key, attributes=None, + object_type=None): + """ + Find an existing entry's dn from an attribute + """ + key_attribute = key_attribute.lower() + if not object_type: + if key_attribute == "uid": # User + filter = "posixAccount" + elif key_attribute == "cn": # Group + object_type = "posixGroup" + elif key_attribute == "krbprincipal": # Service + object_type = "krbPrincipal" + + if not object_type: + return None + + filter = "(&(%s=%s)(objectclass=%s))" % ( + key_attribute, + self.dn.escape_dn_chars(primary_key), + object_type + ) + + search_base = "%s, %s" % (self.api.env.container_accounts, self.api.env.basedn) + + entry = servercore.get_sub_entry(search_base, filter, attributes) + + return entry['dn'] + def create(self, **kw): if servercore.entry_exists(kw['dn']): raise errors.DuplicateEntry("entry already exists") @@ -64,4 +92,10 @@ class ldap(CrudBackend): return servercore.add_entry(entry) + def retrieve(self, dn, attributes=None): + return servercore.get_entry_by_dn(dn, attributes) + + def delete(self, dn): + return servercore.delete_entry(dn) + api.register(ldap) |