Mercurial > prosody-modules
comparison mod_auth_dovecot/auth_dovecot/mod_auth_dovecot.lua @ 700:0c130c45b7c1
mod_auth_dovecot: Old forgotten changes. Testing appreciated.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Thu, 07 Jun 2012 23:41:25 +0200 |
parents | 942738953ff3 |
children | 881ec9919144 |
comparison
equal
deleted
inserted
replaced
699:7c88e09a07e7 | 700:0c130c45b7c1 |
---|---|
12 local socket_port = module:get_option_string("dovecot_auth_port"); | 12 local socket_port = module:get_option_string("dovecot_auth_port"); |
13 | 13 |
14 local service_realm = module:get_option("realm"); | 14 local service_realm = module:get_option("realm"); |
15 local service_name = module:get_option("service_name"); | 15 local service_name = module:get_option("service_name"); |
16 local append_host = module:get_option_boolean("auth_append_host"); | 16 local append_host = module:get_option_boolean("auth_append_host"); |
17 --assert(not append_host, "auth_append_host does not work"); | |
17 local validate_domain = module:get_option_boolean("validate_append_host"); | 18 local validate_domain = module:get_option_boolean("validate_append_host"); |
18 local handle_appended = module:get_option_string("handle_appended"); | 19 local handle_appended = module:get_option_string("handle_appended"); |
19 local util_sasl_new = require "util.sasl".new; | 20 local util_sasl_new = require "util.sasl".new; |
20 | 21 |
21 local new_dovecot_sasl = module:require "sasl_dovecot".new; | 22 local new_dovecot_sasl = module:require "sasl_dovecot".new; |
23 local new_sasl = function(realm) | 24 local new_sasl = function(realm) |
24 return new_dovecot_sasl( | 25 return new_dovecot_sasl( |
25 service_realm or realm, | 26 service_realm or realm, |
26 service_name or "xmpp", | 27 service_name or "xmpp", |
27 | 28 |
28 socket_port and { socket_path, socket_port } or socket_path, | 29 socket_port and { socket_host, socket_port } or socket_path, |
29 | 30 |
30 { --config | 31 { --config |
31 handle_domain = handle_appended or | 32 handle_domain = handle_appended or |
32 (append_host and "split" or "escape"), | 33 (append_host and "split" or "escape"), |
33 validate_domain = validate_domain, | 34 validate_domain = validate_domain, |
53 | 54 |
54 function provider.test_password(username, password) | 55 function provider.test_password(username, password) |
55 return new_sasl(module.host):plain_test(username, password); | 56 return new_sasl(module.host):plain_test(username, password); |
56 end | 57 end |
57 | 58 |
58 if append_host then | |
59 new_sasl = function(realm) | |
60 return util_sasl_new(realm, { | |
61 plain_test = function(sasl, username, password, realm) | |
62 local prepped_username = nodeprep(username); | |
63 if not prepped_username then | |
64 log("debug", "NODEprep failed on username: %s", username); | |
65 return "", nil; | |
66 end | |
67 prepped_username = prepped_username .. "@" .. module.host; | |
68 return provider.test_password(prepped_username, password), true; | |
69 end, | |
70 }); | |
71 end | |
72 end | |
73 | |
74 function provider.get_password(username) | 59 function provider.get_password(username) |
75 return nil, "Passwords unavailable for "..name; | 60 return nil, "Passwords unavailable for "..name; |
76 end | 61 end |
77 | 62 |
78 function provider.set_password(username, password) | 63 function provider.set_password(username, password) |
79 return nil, "Passwords unavailable for "..name; | 64 return nil, "Passwords unavailable for "..name; |
80 end | 65 end |
81 | 66 |
82 function provider.user_exists(username) | 67 function provider.user_exists(username) |
68 return true -- FIXME | |
69 --[[ This, sadly, doesn't work. | |
83 local user_test = new_sasl(module.host); | 70 local user_test = new_sasl(module.host); |
84 user_test:select("PLAIN"); | 71 user_test:select("PLAIN"); |
85 user_test:process(("\0%s\0"):format(username)); | 72 user_test:process(("\0%s\0"):format(username)); |
86 return user_test.username == username; | 73 return user_test.username == username; |
74 --]] | |
87 end | 75 end |
88 | 76 |
89 function provider.create_user(username, password) | 77 function provider.create_user(username, password) |
90 return nil, "Account creation/modification not available with "..name; | 78 return nil, "Account creation/modification not available with "..name; |
91 end | 79 end |
92 | 80 |
93 function provider.get_sasl_handler() | 81 function provider.get_sasl_handler() |
94 return new_sasl(module.host); | 82 return new_sasl(module.host); |
95 end | 83 end |
96 | 84 |
85 if append_host then | |
86 function provider.test_password(username, password) | |
87 return new_sasl(module.host):plain_test(username .. "@".. (service_realm or module.host), password); | |
88 end | |
89 | |
90 provider.get_sasl_handler = nil | |
91 end | |
92 | |
97 module:add_item("auth-provider", provider); | 93 module:add_item("auth-provider", provider); |
98 | 94 |