comparison plugins/mod_saslauth.lua @ 7900:41f783d4e127

Merge 0.10->trunk
author Kim Alvefur <zash@zash.se>
date Wed, 15 Feb 2017 23:05:03 +0100
parents 2b3d0ab67f7d
children e520dc0c3af4
comparison
equal deleted inserted replaced
7892:f00943bbf84f 7900:41f783d4e127
3 -- Copyright (C) 2008-2010 Waqas Hussain 3 -- Copyright (C) 2008-2010 Waqas Hussain
4 -- 4 --
5 -- This project is MIT/X11 licensed. Please see the 5 -- This project is MIT/X11 licensed. Please see the
6 -- COPYING file in the source package for more information. 6 -- COPYING file in the source package for more information.
7 -- 7 --
8 8 -- luacheck: ignore 431/log
9 9
10 10
11 local st = require "util.stanza"; 11 local st = require "util.stanza";
12 local sm_bind_resource = require "core.sessionmanager".bind_resource; 12 local sm_bind_resource = require "core.sessionmanager".bind_resource;
13 local sm_make_authenticated = require "core.sessionmanager".make_authenticated; 13 local sm_make_authenticated = require "core.sessionmanager".make_authenticated;
221 local mechanisms_attr = { xmlns='urn:ietf:params:xml:ns:xmpp-sasl' }; 221 local mechanisms_attr = { xmlns='urn:ietf:params:xml:ns:xmpp-sasl' };
222 local bind_attr = { xmlns='urn:ietf:params:xml:ns:xmpp-bind' }; 222 local bind_attr = { xmlns='urn:ietf:params:xml:ns:xmpp-bind' };
223 local xmpp_session_attr = { xmlns='urn:ietf:params:xml:ns:xmpp-session' }; 223 local xmpp_session_attr = { xmlns='urn:ietf:params:xml:ns:xmpp-session' };
224 module:hook("stream-features", function(event) 224 module:hook("stream-features", function(event)
225 local origin, features = event.origin, event.features; 225 local origin, features = event.origin, event.features;
226 local log = origin.log or log;
226 if not origin.username then 227 if not origin.username then
227 if secure_auth_only and not origin.secure then 228 if secure_auth_only and not origin.secure then
229 log("debug", "Not offering authentication on insecure connection");
228 return; 230 return;
229 end 231 end
230 local sasl_handler = usermanager_get_sasl_handler(module.host, origin) 232 local sasl_handler = usermanager_get_sasl_handler(module.host, origin)
231 origin.sasl_handler = sasl_handler; 233 origin.sasl_handler = sasl_handler;
232 if origin.encrypted then 234 if origin.encrypted then
241 ["tls-unique"] = socket; 243 ["tls-unique"] = socket;
242 }; 244 };
243 end 245 end
244 end 246 end
245 local mechanisms = st.stanza("mechanisms", mechanisms_attr); 247 local mechanisms = st.stanza("mechanisms", mechanisms_attr);
246 for mechanism in pairs(sasl_handler:mechanisms()) do 248 local sasl_mechanisms = sasl_handler:mechanisms()
247 if (not disabled_mechanisms:contains(mechanism)) and (origin.secure or not insecure_mechanisms:contains(mechanism)) then 249 for mechanism in pairs(sasl_mechanisms) do
250 if disabled_mechanisms:contains(mechanism) then
251 log("debug", "Not offering disabled mechanism %s", mechanism);
252 elseif not origin.secure and insecure_mechanisms:contains(mechanism) then
253 log("debug", "Not offering mechanism %s on insecure connection", mechanism);
254 else
248 mechanisms:tag("mechanism"):text(mechanism):up(); 255 mechanisms:tag("mechanism"):text(mechanism):up();
249 end 256 end
250 end 257 end
251 if mechanisms[1] then 258 if mechanisms[1] then
252 features:add_child(mechanisms); 259 features:add_child(mechanisms);
260 elseif not next(sasl_mechanisms) then
261 log("warn", "No available SASL mechanisms, verify that the configured authentication module is working");
253 else 262 else
254 (origin.log or log)("warn", "No SASL mechanisms to offer"); 263 log("warn", "All available authentication mechanisms are either disabled or not suitable for an insecure connection");
255 end 264 end
256 else 265 else
257 features:tag("bind", bind_attr):tag("required"):up():up(); 266 features:tag("bind", bind_attr):tag("required"):up():up();
258 features:tag("session", xmpp_session_attr):tag("optional"):up():up(); 267 features:tag("session", xmpp_session_attr):tag("optional"):up():up();
259 end 268 end