liquid_feedback_frontend

view env/ldap/bind.lua @ 1071:58f48a8a202a

Imported and merged LDAP patch
author bsw
date Fri Jul 18 21:42:59 2014 +0200 (2014-07-18)
parents
children 35e605322b41
line source
1 -- binds to configured LDAP server
2 -- --------------------------------------------------------------------------
3 -- omit arguments for anonymous bind
4 --
5 -- arguments:
6 -- dn: the distinguished name to be used fo binding (string)
7 -- password: password credentials (string)
8 --
9 -- returns:
10 -- ldap: in case of success, an LDAP connection handle
11 -- err: in case of an error, an error code (string)
12 -- err2: error dependent extra error information
14 function ldap.bind(dn, password)
16 local libldap = require("mldap")
18 local hostlist = ldap.get_hosts()
20 -- try binding to LDAP server until success of no host entry left
21 local ldap
22 while not ldap do
24 if #hostlist < 1 then
25 break
26 end
28 local host = table.remove(hostlist, 1)
30 local err
31 ldap, err, errno = libldap.bind{
32 uri = host.uri,
33 timeout = host.timeout,
34 who = dn,
35 password = password
36 }
38 if not err and ldap then
39 return ldap, nil
40 end
42 local errno_string
44 if errno then
45 errno_string = libldap.errorcodes[errno]
46 end
48 if errno == libldap.errorcodes.invalid_credentials then
49 return nil, "invalid_credentials", errno_string
50 end
51 end
53 return nil, "cant_contact_ldap_server"
55 end

Impressum / About Us