liquid_feedback_frontend
diff 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 diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/env/ldap/bind.lua Fri Jul 18 21:42:59 2014 +0200 1.3 @@ -0,0 +1,55 @@ 1.4 +-- binds to configured LDAP server 1.5 +-- -------------------------------------------------------------------------- 1.6 +-- omit arguments for anonymous bind 1.7 +-- 1.8 +-- arguments: 1.9 +-- dn: the distinguished name to be used fo binding (string) 1.10 +-- password: password credentials (string) 1.11 +-- 1.12 +-- returns: 1.13 +-- ldap: in case of success, an LDAP connection handle 1.14 +-- err: in case of an error, an error code (string) 1.15 +-- err2: error dependent extra error information 1.16 + 1.17 +function ldap.bind(dn, password) 1.18 + 1.19 + local libldap = require("mldap") 1.20 + 1.21 + local hostlist = ldap.get_hosts() 1.22 + 1.23 + -- try binding to LDAP server until success of no host entry left 1.24 + local ldap 1.25 + while not ldap do 1.26 + 1.27 + if #hostlist < 1 then 1.28 + break 1.29 + end 1.30 + 1.31 + local host = table.remove(hostlist, 1) 1.32 + 1.33 + local err 1.34 + ldap, err, errno = libldap.bind{ 1.35 + uri = host.uri, 1.36 + timeout = host.timeout, 1.37 + who = dn, 1.38 + password = password 1.39 + } 1.40 + 1.41 + if not err and ldap then 1.42 + return ldap, nil 1.43 + end 1.44 + 1.45 + local errno_string 1.46 + 1.47 + if errno then 1.48 + errno_string = libldap.errorcodes[errno] 1.49 + end 1.50 + 1.51 + if errno == libldap.errorcodes.invalid_credentials then 1.52 + return nil, "invalid_credentials", errno_string 1.53 + end 1.54 + end 1.55 + 1.56 + return nil, "cant_contact_ldap_server" 1.57 + 1.58 +end