Comparison

mod_lib_ldap/ldap.lib.lua @ 927:a9dfa7232d88

Merge
author Matthew Wild <mwild1@gmail.com>
date Tue, 12 Mar 2013 12:10:25 +0000
parent 877:cd2262969d2e
child 3195:66b3085ecc49
comparison
equal deleted inserted replaced
926:f88381a39c56 927:a9dfa7232d88
175 return params; 175 return params;
176 end 176 end
177 177
178 -- XXX consider renaming this...it doesn't bind the current connection 178 -- XXX consider renaming this...it doesn't bind the current connection
179 function _M.bind(username, password) 179 function _M.bind(username, password)
180 local who = format('%s=%s,%s', params.user.usernamefield, username, params.user.basedn); 180 local conn = _M.getconnection();
181 local filter = format('%s=%s', params.user.usernamefield, username);
182
183 if filter then
184 filter = _M.filter.combine_and(filter, params.user.filter);
185 end
186
187 local who = _M.singlematch {
188 attrs = params.user.usernamefield,
189 base = params.user.basedn,
190 filter = filter,
191 };
192
193 if who then
194 who = who.dn;
195 module:log('debug', '_M.bind - who: %s', who);
196 else
197 module:log('debug', '_M.bind - no DN found for username = %s', username);
198 return nil, format('no DN found for username = %s', username);
199 end
200
181 local conn, err = ldap.open_simple(params.hostname, who, password, params.use_tls); 201 local conn, err = ldap.open_simple(params.hostname, who, password, params.use_tls);
182 202
183 if conn then 203 if conn then
184 conn:close(); 204 conn:close();
185 return true; 205 return true;
190 210
191 function _M.singlematch(query) 211 function _M.singlematch(query)
192 local ld = _M.getconnection(); 212 local ld = _M.getconnection();
193 213
194 query.sizelimit = 1; 214 query.sizelimit = 1;
195 query.scope = 'onelevel'; 215 query.scope = 'subtree';
196 216
197 for dn, attribs in ld:search(query) do 217 for dn, attribs in ld:search(query) do
218 attribs.dn = dn;
198 return attribs; 219 return attribs;
199 end 220 end
200 end 221 end
201 222
202 _M.filter = {}; 223 _M.filter = {};