diff options
Diffstat (limited to 'mod_auth_custom')
| -rw-r--r-- | mod_auth_custom/mod_auth_custom.lua | 36 |
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 @@ | |||
| 1 | local posix = require "posix.grp"; | ||
| 2 | local pam = require "pam"; | ||
| 3 | local new_sasl = require "util.sasl".new; | ||
| 4 | |||
| 5 | function 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; | ||
| 12 | end | ||
| 13 | |||
| 14 | function 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; | ||
| 26 | end | ||
| 27 | |||
| 28 | function get_sasl_handler() | ||
| 29 | return new_sasl(module.host, { | ||
| 30 | plain_test = function(sasl, ...) | ||
| 31 | return test_password(...) | ||
| 32 | end | ||
| 33 | }); | ||
| 34 | end | ||
| 35 | |||
| 36 | module:provides"auth"; | ||
