# HG changeset patch # User Kim Alvefur # Date 1376584682 -7200 # Node ID b8762c9fb2709657c55f12754106fcc018a20766 # Parent b6280e8886f412fa47760b33407b42ab645c957b mod_auth_pam: Initial commit of simple PAM authentication module diff -r b6280e8886f4 -r b8762c9fb270 mod_auth_pam/mod_auth_pam.lua --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mod_auth_pam/mod_auth_pam.lua Thu Aug 15 18:38:02 2013 +0200 @@ -0,0 +1,37 @@ +-- PAM authentication for Prosody +-- Copyright (C) 2013 Kim Alvefur +-- +-- Requires https://github.com/devurandom/lua-pam +-- and LuaPosix + +local posix = require "posix"; +local pam = require "pam"; +local new_sasl = require "util.sasl".new; + +function user_exists(username) + return not not posix.getpasswd(username); +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";