Lines 7-26
Link Here
|
7 |
local posix = require "posix"; |
7 |
local posix = require "posix"; |
8 |
local pam = require "pam"; |
8 |
local pam = require "pam"; |
9 |
local new_sasl = require "util.sasl".new; |
9 |
local new_sasl = require "util.sasl".new; |
|
|
10 |
local io = require "io" |
10 |
|
11 |
|
11 |
function user_exists(username) |
12 |
function user_exists(username) |
12 |
return not not posix.getpasswd(username); |
13 |
return not not posix.getpasswd(username); |
13 |
end |
14 |
end |
14 |
|
15 |
|
15 |
function test_password(username, password) |
16 |
function test_password(username, password) |
16 |
local h, err = pam.start("xmpp", username, { |
17 |
local function conversation(messages) |
17 |
function (t) |
18 |
local responses = {} |
18 |
if #t == 1 and t[1][1] == pam.PAM_PROMPT_ECHO_OFF then |
19 |
|
19 |
return { { password, 0} }; |
20 |
for i, message in ipairs(messages) do |
|
|
21 |
local msg_style, msg = message[1], message[2] |
22 |
|
23 |
if msg_style == pam.PROMPT_ECHO_OFF then |
24 |
-- Assume PAM asks us for the password |
25 |
responses[i] = {password, 0} |
26 |
elseif msg_style == pam.PROMPT_ECHO_ON then |
27 |
responses[i] = {username, 0} |
28 |
elseif msg_style == pam.ERROR_MSG then |
29 |
io.write("ERROR: ") |
30 |
io.write(msg) |
31 |
io.write("\n") |
32 |
responses[i] = {"", 0} |
33 |
elseif msg_style == pam.TEXT_INFO then |
34 |
io.write(msg) |
35 |
io.write("\n") |
36 |
responses[i] = {"", 0} |
37 |
else |
38 |
error("Unsupported conversation message style: " .. msg_style) |
20 |
end |
39 |
end |
21 |
end |
40 |
end |
22 |
}); |
41 |
|
23 |
if h and h:authenticate() and h:endx(pam.PAM_SUCCESS) then |
42 |
return responses |
|
|
43 |
end |
44 |
|
45 |
local h, err = pam.start("xmpp", username, {conversation, nil}); |
46 |
if h and h:authenticate() and h:endx(pam.SUCCESS) then |
24 |
return true, true; |
47 |
return true, true; |
25 |
end |
48 |
end |
26 |
return nil, true; |
49 |
return nil, true; |