92 module:log("error", "Unknown sasl status: %s", status); |
92 module:log("error", "Unknown sasl status: %s", status); |
93 end |
93 end |
94 return reply; |
94 return reply; |
95 end |
95 end |
96 |
96 |
97 local function handle_status(session, status) |
97 local function handle_status(session, status, ret, err_msg) |
98 if status == "failure" then |
98 if status == "failure" then |
99 session.sasl_handler = session.sasl_handler:clean_clone(); |
99 session.sasl_handler = session.sasl_handler:clean_clone(); |
100 elseif status == "success" then |
100 elseif status == "success" then |
101 local username = nodeprep(session.sasl_handler.username); |
101 local username = nodeprep(session.sasl_handler.username); |
102 if not username then -- TODO move this to sessionmanager |
102 if not username then -- TODO move this to sessionmanager |
103 module:log("warn", "SASL succeeded but we didn't get a username!"); |
103 module:log("warn", "SASL succeeded but we didn't get a username!"); |
104 session.sasl_handler = nil; |
104 session.sasl_handler = nil; |
105 session:reset_stream(); |
105 session:reset_stream(); |
106 return; |
106 return status, ret, err_msg; |
107 end |
107 end |
108 sm_make_authenticated(session, session.sasl_handler.username); |
108 sm_make_authenticated(session, session.sasl_handler.username); |
109 session.sasl_handler = nil; |
109 session.sasl_handler = nil; |
110 session:reset_stream(); |
110 session:reset_stream(); |
111 end |
111 end |
|
112 return status, ret, err_msg; |
112 end |
113 end |
113 |
114 |
114 local function sasl_handler(session, stanza) |
115 local function sasl_handler(session, stanza) |
115 if stanza.name == "auth" then |
116 if stanza.name == "auth" then |
116 -- FIXME ignoring duplicates because ejabberd does |
117 -- FIXME ignoring duplicates because ejabberd does |
140 session.send(build_reply("failure", "incorrect-encoding")); |
141 session.send(build_reply("failure", "incorrect-encoding")); |
141 return; |
142 return; |
142 end |
143 end |
143 end |
144 end |
144 local status, ret, err_msg = session.sasl_handler:process(text); |
145 local status, ret, err_msg = session.sasl_handler:process(text); |
145 handle_status(session, status); |
146 status, ret, err_msg = handle_status(session, status, ret, err_msg); |
146 local s = build_reply(status, ret, err_msg); |
147 local s = build_reply(status, ret, err_msg); |
147 log("debug", "sasl reply: %s", tostring(s)); |
148 log("debug", "sasl reply: %s", tostring(s)); |
148 session.send(s); |
149 session.send(s); |
149 end |
150 end |
150 |
151 |