Comparison

mod_auth_pam/mod_auth_pam.lua @ 1165:b8762c9fb270

mod_auth_pam: Initial commit of simple PAM authentication module
author Kim Alvefur <zash@zash.se>
date Thu, 15 Aug 2013 18:38:02 +0200
child 1538:57bb2497fadc
comparison
equal deleted inserted replaced
1164:b6280e8886f4 1165:b8762c9fb270
1 -- PAM authentication for Prosody
2 -- Copyright (C) 2013 Kim Alvefur
3 --
4 -- Requires https://github.com/devurandom/lua-pam
5 -- and LuaPosix
6
7 local posix = require "posix";
8 local pam = require "pam";
9 local new_sasl = require "util.sasl".new;
10
11 function user_exists(username)
12 return not not posix.getpasswd(username);
13 end
14
15 function test_password(username, password)
16 local h, err = pam.start("xmpp", username, {
17 function (t)
18 if #t == 1 and t[1][1] == pam.PAM_PROMPT_ECHO_OFF then
19 return { { password, 0} };
20 end
21 end
22 });
23 if h and h:authenticate() and h:endx(pam.PAM_SUCCESS) then
24 return true, true;
25 end
26 return nil, true;
27 end
28
29 function get_sasl_handler()
30 return new_sasl(module.host, {
31 plain_test = function(sasl, ...)
32 return test_password(...)
33 end
34 });
35 end
36
37 module:provides"auth";