summaryrefslogtreecommitdiff
path: root/mod_auth_custom/mod_auth_custom.lua
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2015-09-30 16:26:53 +0200
committerGregor Kleen <gkleen@yggdrasil.li>2015-09-30 16:26:53 +0200
commiteb68d998a10b436194cc81f9a64620606b1bd216 (patch)
tree9dd538d2f0827a296ed9b78c73aed1898be1b33e /mod_auth_custom/mod_auth_custom.lua
downloadprosody_auth-eb68d998a10b436194cc81f9a64620606b1bd216.tar
prosody_auth-eb68d998a10b436194cc81f9a64620606b1bd216.tar.gz
prosody_auth-eb68d998a10b436194cc81f9a64620606b1bd216.tar.bz2
prosody_auth-eb68d998a10b436194cc81f9a64620606b1bd216.tar.xz
prosody_auth-eb68d998a10b436194cc81f9a64620606b1bd216.zip
First attempt at custom auth module
Diffstat (limited to 'mod_auth_custom/mod_auth_custom.lua')
-rw-r--r--mod_auth_custom/mod_auth_custom.lua36
1 files changed, 36 insertions, 0 deletions
diff --git a/mod_auth_custom/mod_auth_custom.lua b/mod_auth_custom/mod_auth_custom.lua
new file mode 100644
index 0000000..e917b6a
--- /dev/null
+++ b/mod_auth_custom/mod_auth_custom.lua
@@ -0,0 +1,36 @@
1local posix = require "posix.grp";
2local pam = require "pam";
3local new_sasl = require "util.sasl".new;
4
5function user_exists(username)
6 for i,v in ipairs(posix.getgroup("xmpp")) do
7 if username == v then
8 return true;
9 end
10 end
11 return false;
12end
13
14function test_password(username, password)
15 local h, err = pam.start("xmpp", username, {
16 function (t)
17 if #t == 1 and t[1][1] == pam.PAM_PROMPT_ECHO_OFF then
18 return { { password, 0} };
19 end
20 end
21 });
22 if h and h:authenticate() and h:endx(pam.PAM_SUCCESS) then
23 return true, true;
24 end
25 return nil, true;
26end
27
28function get_sasl_handler()
29 return new_sasl(module.host, {
30 plain_test = function(sasl, ...)
31 return test_password(...)
32 end
33 });
34end
35
36module:provides"auth";