liquid_feedback_frontend

diff env/ldap/get_member_entry.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/get_member_entry.lua	Fri Jul 18 21:42:59 2014 +0200
     1.3 @@ -0,0 +1,52 @@
     1.4 +-- gets the corresponding ldap entry for a given member login
     1.5 +-- --------------------------------------------------------------------------
     1.6 +--
     1.7 +-- arguments:
     1.8 +--   filter: the LDAP filter for searching the member (required)
     1.9 +--   use_ldap_conn: an already existing LDAP connection to be used (optional)
    1.10 +--
    1.11 +-- returns:
    1.12 +--   ldap_entry: in case of success, the LDAP entry (object)
    1.13 +--   err: in case of an error, an error message (string)
    1.14 +--   err2: error dependent extra error information
    1.15 +
    1.16 +function ldap.get_member_entry(filter, use_ldap_conn)
    1.17 +  
    1.18 +  local ldap_conn, err
    1.19 +  
    1.20 +  if use_ldap_conn then
    1.21 +    ldap_conn = use_ldap_conn
    1.22 +  else
    1.23 +    ldap_conn, bind_err = ldap.bind_as_app()
    1.24 +  end
    1.25 +  
    1.26 +  if not ldap_conn then
    1.27 +    return nil, "ldap_bind_error", bind_err
    1.28 +  end
    1.29 +
    1.30 +  local entries, search_err = ldap_conn:search{
    1.31 +    base = config.ldap.base,
    1.32 +    scope = config.ldap.member.scope,
    1.33 +    filter = filter,
    1.34 +    attr = config.ldap.member.fetch_attr,
    1.35 +  }
    1.36 +  
    1.37 +  if not use_ldap_conn then
    1.38 +    ldap_conn:unbind()
    1.39 +  end
    1.40 +  
    1.41 +  if not entries then
    1.42 +    return nil, "ldap_search_error", search_err
    1.43 +  end
    1.44 +  
    1.45 +  if #entries > 1 then
    1.46 +    return nil, "too_many_ldap_entries_found"
    1.47 +  end
    1.48 +  
    1.49 +  if #entries < 0 then
    1.50 +    return nil, "no_ldap_entry_found"
    1.51 +  end
    1.52 +  
    1.53 +  return entries[1]
    1.54 +  
    1.55 +end

Impressum / About Us