correctly use lua script in dovecot
This commit is contained in:
parent
9b014c4a7a
commit
2169802a9f
@ -22,6 +22,9 @@ function auth_passdb_lookup(req)
|
|||||||
user_count = user_count + 1
|
user_count = user_count + 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local return_code = dovecot.auth.PASSDB_RESULT_NEXT
|
||||||
|
local return_text = ""
|
||||||
|
|
||||||
local user_exists = user_count == 1
|
local user_exists = user_count == 1
|
||||||
if user_exists then
|
if user_exists then
|
||||||
local app_base_dn = "{{ getenv "LDAP_APP_PASSWORDS_BASE_DN" }}"
|
local app_base_dn = "{{ getenv "LDAP_APP_PASSWORDS_BASE_DN" }}"
|
||||||
@ -32,20 +35,22 @@ function auth_passdb_lookup(req)
|
|||||||
local user_password = req.password
|
local user_password = req.password
|
||||||
|
|
||||||
for dn, attribs in ld:search { base = app_base_dn_formatted, scope = "subtree", filter = app_pass_filter } do
|
for dn, attribs in ld:search { base = app_base_dn_formatted, scope = "subtree", filter = app_pass_filter } do
|
||||||
|
req:log_info(string.format("trying %s...", dn))
|
||||||
|
|
||||||
local test_conn = lualdap.open_simple(
|
local test_conn = lualdap.open_simple(
|
||||||
ldap_host,
|
ldap_host,
|
||||||
dn,
|
dn,
|
||||||
user_password,
|
user_password,
|
||||||
ldap_use_tls)
|
ldap_use_tls)
|
||||||
if test_conn ~= nil then
|
if test_conn ~= nil then
|
||||||
return dovecot.auth.PASSDB_RESULT_OK, string.format("%s=user", ldap_user_attribute)
|
return dovecot.auth.PASSDB_RESULT_OK, string.format("password=%s user=%s", user_password, username)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
return dovecot.auth.PASSDB_RESULT_USER_UNKNOWN, "no such user"
|
return dovecot.auth.PASSDB_RESULT_USER_UNKNOWN, "no such user"
|
||||||
end
|
end
|
||||||
|
|
||||||
return dovecot.auth.PASSDB_RESULT_NEXT, ""
|
return return_code, return_text
|
||||||
end
|
end
|
||||||
|
|
||||||
function script_init()
|
function script_init()
|
||||||
|
Loading…
Reference in New Issue
Block a user