Comparison

plugins/mod_saslauth.lua @ 2612:475552b04151

mod_saslauth: Hook stream-features event using new events API.
author Waqas Hussain <waqas20@gmail.com>
date Fri, 12 Feb 2010 04:25:37 +0500
parent 2451:d2f747920eaf
child 2634:e486aca8c5d1
comparison
equal deleted inserted replaced
2611:c3ea4d3f857f 2612:475552b04151
142 module:add_handler("c2s_unauthed", "response", xmlns_sasl, sasl_handler); 142 module:add_handler("c2s_unauthed", "response", xmlns_sasl, sasl_handler);
143 143
144 local mechanisms_attr = { xmlns='urn:ietf:params:xml:ns:xmpp-sasl' }; 144 local mechanisms_attr = { xmlns='urn:ietf:params:xml:ns:xmpp-sasl' };
145 local bind_attr = { xmlns='urn:ietf:params:xml:ns:xmpp-bind' }; 145 local bind_attr = { xmlns='urn:ietf:params:xml:ns:xmpp-bind' };
146 local xmpp_session_attr = { xmlns='urn:ietf:params:xml:ns:xmpp-session' }; 146 local xmpp_session_attr = { xmlns='urn:ietf:params:xml:ns:xmpp-session' };
147 module:add_event_hook("stream-features", function(session, features) 147 module:hook("stream-features", function(event)
148 if not session.username then 148 local origin, features = event.origin, event.features;
149 if secure_auth_only and not session.secure then 149 if not origin.username then
150 if secure_auth_only and not origin.secure then
150 return; 151 return;
151 end 152 end
152 if module:get_option("anonymous_login") then 153 if module:get_option("anonymous_login") then
153 session.sasl_handler = new_sasl(session.host, anonymous_authentication_profile); 154 origin.sasl_handler = new_sasl(origin.host, anonymous_authentication_profile);
154 else 155 else
155 session.sasl_handler = new_sasl(session.host, default_authentication_profile); 156 origin.sasl_handler = new_sasl(origin.host, default_authentication_profile);
156 if not (module:get_option("allow_unencrypted_plain_auth")) and not session.secure then 157 if not (module:get_option("allow_unencrypted_plain_auth")) and not origin.secure then
157 session.sasl_handler:forbidden({"PLAIN"}); 158 origin.sasl_handler:forbidden({"PLAIN"});
158 end 159 end
159 end 160 end
160 features:tag("mechanisms", mechanisms_attr); 161 features:tag("mechanisms", mechanisms_attr);
161 for k, v in pairs(session.sasl_handler:mechanisms()) do 162 for k, v in pairs(origin.sasl_handler:mechanisms()) do
162 features:tag("mechanism"):text(v):up(); 163 features:tag("mechanism"):text(v):up();
163 end 164 end
164 features:up(); 165 features:up();
165 else 166 else
166 features:tag("bind", bind_attr):tag("required"):up():up(); 167 features:tag("bind", bind_attr):tag("required"):up():up();