Software /
code /
prosody
Comparison
plugins/mod_legacyauth.lua @ 1836:f4c88dd32724
Merge with 0.5
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sun, 27 Sep 2009 12:26:51 +0100 |
parent | 1690:b675ae5b4c91 |
parent | 1833:5408d5100bd0 |
child | 1912:126401a7159f |
comparison
equal
deleted
inserted
replaced
1823:7c3ec7ac6316 | 1836:f4c88dd32724 |
---|---|
13 | 13 |
14 local secure_auth_only = module:get_option("require_encryption"); | 14 local secure_auth_only = module:get_option("require_encryption"); |
15 | 15 |
16 local sessionmanager = require "core.sessionmanager"; | 16 local sessionmanager = require "core.sessionmanager"; |
17 local usermanager = require "core.usermanager"; | 17 local usermanager = require "core.usermanager"; |
18 local nodeprep = require "util.encodings".stringprep.nodeprep; | |
19 local resourceprep = require "util.encodings".stringprep.resourceprep; | |
18 | 20 |
19 module:add_feature("jabber:iq:auth"); | 21 module:add_feature("jabber:iq:auth"); |
20 module:add_event_hook("stream-features", function (session, features) | 22 module:add_event_hook("stream-features", function (session, features) |
21 if secure_auth_only and not session.secure then | 23 if secure_auth_only and not session.secure then |
22 -- Sorry, not offering to insecure streams! | 24 -- Sorry, not offering to insecure streams! |
42 :tag("username"):up() | 44 :tag("username"):up() |
43 :tag("password"):up() | 45 :tag("password"):up() |
44 :tag("resource"):up()); | 46 :tag("resource"):up()); |
45 else | 47 else |
46 username, password, resource = t_concat(username), t_concat(password), t_concat(resource); | 48 username, password, resource = t_concat(username), t_concat(password), t_concat(resource); |
49 username = nodeprep(username); | |
50 resource = resourceprep(resource) | |
47 local reply = st.reply(stanza); | 51 local reply = st.reply(stanza); |
48 if usermanager.validate_credentials(session.host, username, password) then | 52 if usermanager.validate_credentials(session.host, username, password) then |
49 -- Authentication successful! | 53 -- Authentication successful! |
50 local success, err = sessionmanager.make_authenticated(session, username); | 54 local success, err = sessionmanager.make_authenticated(session, username); |
51 if success then | 55 if success then |
52 local err_type, err_msg; | 56 local err_type, err_msg; |
53 success, err_type, err, err_msg = sessionmanager.bind_resource(session, resource); | 57 success, err_type, err, err_msg = sessionmanager.bind_resource(session, resource); |
54 if not success then | 58 if not success then |
55 session.send(st.error_reply(stanza, err_type, err, err_msg)); | 59 session.send(st.error_reply(stanza, err_type, err, err_msg)); |
56 return true; -- FIXME need to unauthenticate here | 60 session.username, session.type = nil, "c2s_unauthed"; -- FIXME should this be placed in sessionmanager? |
61 return true; | |
62 elseif resource ~= session.resource then -- server changed resource, not supported by legacy auth | |
63 session.send(st.error_reply(stanza, "cancel", "conflict", "The requested resource could not be assigned to this session.")); | |
64 session:close(); -- FIXME undo resource bind and auth instead of closing the session? | |
65 return true; | |
57 end | 66 end |
58 end | 67 end |
59 session.send(st.reply(stanza)); | 68 session.send(st.reply(stanza)); |
60 else | 69 else |
61 session.send(st.error_reply(stanza, "auth", "not-authorized")); | 70 session.send(st.error_reply(stanza, "auth", "not-authorized")); |