From eb68d998a10b436194cc81f9a64620606b1bd216 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Wed, 30 Sep 2015 16:26:53 +0200 Subject: First attempt at custom auth module --- mod_auth_custom/mod_auth_custom.lua | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 mod_auth_custom/mod_auth_custom.lua (limited to 'mod_auth_custom/mod_auth_custom.lua') 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 @@ +local posix = require "posix.grp"; +local pam = require "pam"; +local new_sasl = require "util.sasl".new; + +function user_exists(username) + for i,v in ipairs(posix.getgroup("xmpp")) do + if username == v then + return true; + end + end + return false; +end + +function test_password(username, password) + local h, err = pam.start("xmpp", username, { + function (t) + if #t == 1 and t[1][1] == pam.PAM_PROMPT_ECHO_OFF then + return { { password, 0} }; + end + end + }); + if h and h:authenticate() and h:endx(pam.PAM_SUCCESS) then + return true, true; + end + return nil, true; +end + +function get_sasl_handler() + return new_sasl(module.host, { + plain_test = function(sasl, ...) + return test_password(...) + end + }); +end + +module:provides"auth"; -- cgit v1.2.3