Mercurial > prosody-hg
comparison plugins/mod_saslauth.lua @ 3062:892c49869293
mod_saslauth: Add return value and error message to the Cyrus SASL handle_status callback
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Thu, 20 May 2010 11:08:51 +0100 |
| parents | c9f9b3964bb9 |
| children | 596303990c7c |
comparison
equal
deleted
inserted
replaced
| 3061:c9f9b3964bb9 | 3062:892c49869293 |
|---|---|
| 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 |
