public
nobgit
read
NobMail
Based on mailcow: dockerized
Languages
Repository composition by tracked source files.
PHP
49%
JavaScript
35%
HTML
9%
CSS
4%
Shell
2%
Python
1%
Lua
0%
Perl
0%
Ruby
0%
SCSS
0%
Create file
Wiki Documentation
Clone
https://nobgit.com/orgs/nobgit/nobmail.git
ssh://[email protected]:2222/orgs/nobgit/nobmail.git
Trace
data/conf/dovecot/auth/passwd-verify.lua
Trace helps you understand code history line by line. See who changed each line, when it changed, and which commit introduced it.
Author
Date
Commit
Line
Code
1
function auth_password_verify(request, password)
2
if request.domain == nil then
3
return dovecot.auth.PASSDB_RESULT_USER_UNKNOWN, "No such user"
4
end
6
local json = require "cjson"
7
local ltn12 = require "ltn12"
8
local https = require "ssl.https"
9
https.TIMEOUT = 30
11
local req = {
12
username = request.user,
13
password = password,
14
real_rip = request.real_rip,
15
service = request.service
16
}
17
local req_json = json.encode(req)
18
local res = {}
20
local b, c = https.request {
21
method = "POST",
22
url = "https://nginx:9082",
23
source = ltn12.source.string(req_json),
24
headers = {
25
["content-type"] = "application/json",
26
["content-length"] = tostring(#req_json)
27
},
28
sink = ltn12.sink.table(res),
29
insecure = true
30
}
32
-- Returning PASSDB_RESULT_PASSWORD_MISMATCH will reset the user's auth cache entry.
33
-- Returning PASSDB_RESULT_INTERNAL_FAILURE keeps the existing cache entry,
34
-- even if the TTL has expired. Useful to avoid cache eviction during backend issues.
35
if c ~= 200 and c ~= 401 then
36
dovecot.i_info("HTTP request failed with " .. c .. " for user " .. request.user)
37
return dovecot.auth.PASSDB_RESULT_PASSWORD_MISMATCH, "Upstream error"
38
end
40
local response_str = table.concat(res)
41
local is_response_valid, response_json = pcall(json.decode, response_str)
43
if not is_response_valid then
44
dovecot.i_info("Invalid JSON received: " .. response_str)
45
return dovecot.auth.PASSDB_RESULT_PASSWORD_MISMATCH, "Invalid response format"
46
end
48
if response_json.success == true then
49
return dovecot.auth.PASSDB_RESULT_OK, ""
50
end
52
return dovecot.auth.PASSDB_RESULT_PASSWORD_MISMATCH, "Failed to authenticate"
53
end
55
function auth_passdb_lookup(req)
56
return dovecot.auth.PASSDB_RESULT_USER_UNKNOWN, ""
57
end