liquid_feedback_frontend
view env/ldap/bind.lua @ 1323:9cf8b4161fa0
Do not count manual verification requests as other reasons part 2
| author | bsw | 
|---|---|
| date | Thu Aug 02 15:34:08 2018 +0200 (2018-08-02) | 
| parents | 58f48a8a202a | 
| 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
