Software /
code /
prosody-modules
Comparison
mod_auth_imap/auth_imap/mod_auth_imap.lua @ 1196:f45ca6edc159
mod_auth_imap: Authentication module that works by passing through SASL to a IMAP connection
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Thu, 26 Sep 2013 13:43:27 +0200 |
child | 1198:b21bd39c8a12 |
comparison
equal
deleted
inserted
replaced
1195:f502cbffbdd4 | 1196:f45ca6edc159 |
---|---|
1 -- IMAP authentication backend for Prosody | |
2 -- | |
3 -- Copyright (C) 2011 FIMXE from hg annotate -u | |
4 | |
5 local name = "IMAP SASL"; | |
6 local log = require "util.logger".init("auth_imap"); | |
7 | |
8 local imap_host = module:get_option_string("imap_auth_host", "localhost"); | |
9 local imap_port = module:get_option_number("imap_auth_port", 143); | |
10 | |
11 | |
12 local imap_service_realm = module:get_option("imap_service_realm"); | |
13 local imap_service_name = module:get_option("imap_service_name"); | |
14 | |
15 | |
16 local new_imap_sasl = module:require "sasl_imap".new; | |
17 | |
18 local new_sasl = function(realm) | |
19 return new_imap_sasl( | |
20 imap_service_realm or realm, | |
21 imap_service_name or "xmpp", | |
22 imap_host, imap_port | |
23 ); | |
24 end | |
25 | |
26 do | |
27 local s = new_sasl(module.host) | |
28 assert(s, "Could not create a new SASL object"); | |
29 assert(s.mechanisms, "SASL object has no mechanims method"); | |
30 local m = {}; | |
31 for k in pairs(s:mechanisms()) do | |
32 table.insert(m, k); | |
33 end | |
34 log("debug", "Mechanims found: %s", table.concat(m, ", ")); | |
35 end | |
36 | |
37 provider = { | |
38 name = module.name:gsub("^auth_",""); | |
39 }; | |
40 | |
41 function provider.test_password(username, password) | |
42 return nil, "Legacy auth not supported with "..name; | |
43 end | |
44 | |
45 function provider.get_password(username) | |
46 return nil, "Passwords unavailable for "..name; | |
47 end | |
48 | |
49 function provider.set_password(username, password) | |
50 return nil, "Passwords unavailable for "..name; | |
51 end | |
52 | |
53 function provider.user_exists(username) | |
54 -- FIXME | |
55 return true | |
56 end | |
57 | |
58 function provider.create_user(username, password) | |
59 return nil, "Account creation/modification not available with "..name; | |
60 end | |
61 | |
62 function provider.get_sasl_handler() | |
63 return new_sasl(module.host); | |
64 end | |
65 | |
66 module:add_item("auth-provider", provider); | |
67 |