mod_storage_gdbm: Use require directly instead of util.import (which is not available in prosodyctl, breaks adduser etc)
-- PAM authentication for Prosody
-- Copyright (C) 2013 Kim Alvefur
--
-- Requires https://github.com/devurandom/lua-pam
-- and LuaPosix
local have_posix, posix = pcall(require, "posix");
local pam = require "pam";
local new_sasl = require "util.sasl".new;
if have_posix then
function user_exists(username)
return not not posix.getpasswd(username);
end
else
function user_exists()
return true;
end
end
function test_password(username, password)
local h, err = pam.start("xmpp", username, {
function (t)
if #t == 1 and t[1][1] == pam.PROMPT_ECHO_OFF then
return { { password, 0} };
end
end
});
if h and h:authenticate() and h:endx(pam.SUCCESS) then
return user_exists(username);
end
end
function get_sasl_handler()
return new_sasl(module.host, {
plain_test = function(sasl, ...)
return test_password(...), true;
end
});
end
module:provides"auth";