changeset 864:16b007c7706c

We must search for dn before trying to bind
author Guilhem LETTRON <guilhem.lettron@gmail.com>
date Mon, 10 Dec 2012 21:52:09 +0100
parents 675945ea2ed6
children 236ac7175610
files mod_lib_ldap/ldap.lib.lua
diffstat 1 files changed, 16 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mod_lib_ldap/ldap.lib.lua	Wed Dec 05 18:07:46 2012 +0100
+++ b/mod_lib_ldap/ldap.lib.lua	Mon Dec 10 21:52:09 2012 +0100
@@ -177,7 +177,22 @@
 
 -- XXX consider renaming this...it doesn't bind the current connection
 function _M.bind(username, password)
-    local who = format('%s=%s,%s', params.user.usernamefield, username, params.user.basedn);
+    local conn         = _M.getconnection();
+    local filter       = format('%s=%s', params.user.usernamefield, username);
+    local search_attrs = {
+        attrs     = params.user.usernamefield,
+        base      = params.user.basedn,
+        scope     = 'subtree',
+        sizelimit = 1,
+        filter    = filter,
+    };
+    local who;
+
+    for dn in conn:search(search_attrs) do
+        module:log('debug', '_M.bind - who: %s', dn);
+        who = dn;
+    end
+
     local conn, err = ldap.open_simple(params.hostname, who, password, params.use_tls);
 
     if conn then