author | Matthew Wild <mwild1@gmail.com> |
Wed, 01 May 2013 13:54:44 +0100 | |
branch | tls |
changeset 5556 | 7407b1160b46 |
parent 45 | 363c0af290bc |
child 154 | 1fee9396ca2f |
permissions | -rw-r--r-- |
30 | 1 |
|
2 |
local st = require "util.stanza"; |
|
3 |
local send = require "core.sessionmanager".send_to_session; |
|
4 |
local t_concat = table.concat; |
|
5 |
||
6 |
add_iq_handler("c2s_unauthed", "jabber:iq:auth", |
|
7 |
function (session, stanza) |
|
8 |
local username = stanza.tags[1]:child_with_name("username"); |
|
9 |
local password = stanza.tags[1]:child_with_name("password"); |
|
10 |
local resource = stanza.tags[1]:child_with_name("resource"); |
|
11 |
if not (username and password and resource) then |
|
12 |
local reply = st.reply(stanza); |
|
13 |
send(session, reply:query("jabber:iq:auth") |
|
14 |
:tag("username"):up() |
|
15 |
:tag("password"):up() |
|
16 |
:tag("resource"):up()); |
|
17 |
return true; |
|
18 |
else |
|
19 |
username, password, resource = t_concat(username), t_concat(password), t_concat(resource); |
|
20 |
local reply = st.reply(stanza); |
|
21 |
require "core.usermanager" |
|
22 |
if usermanager.validate_credentials(session.host, username, password) then |
|
23 |
-- Authentication successful! |
|
38 | 24 |
local success, err = sessionmanager.make_authenticated(session, username); |
25 |
if success then |
|
26 |
success, err = sessionmanager.bind_resource(session, resource); |
|
27 |
--FIXME: Reply with error |
|
28 |
if not success then |
|
29 |
local reply = st.reply(stanza); |
|
30 |
reply.attr.type = "error"; |
|
31 |
if err == "conflict" then |
|
32 |
reply:tag("error", { code = "409", type = "cancel" }) |
|
33 |
:tag("conflict", { xmlns = "urn:ietf:params:xml:ns:xmpp-stanzas" }); |
|
34 |
elseif err == "constraint" then |
|
35 |
reply:tag("error", { code = "409", type = "cancel" }) |
|
36 |
:tag("already-bound", { xmlns = "x-lxmppd:extensions:legacyauth" }); |
|
37 |
elseif err == "auth" then |
|
38 |
reply:tag("error", { code = "401", type = "auth" }) |
|
39 |
:tag("not-authorized", { xmlns = "urn:ietf:params:xml:ns:xmpp-stanzas" }); |
|
40 |
end |
|
45
363c0af290bc
Small fix for sending stanzas in case of resource binding error
Matthew Wild <mwild1@gmail.com>
parents:
38
diff
changeset
|
41 |
send(session, reply); |
38 | 42 |
return true; |
43 |
end |
|
30 | 44 |
end |
45 |
send(session, st.reply(stanza)); |
|
46 |
return true; |
|
47 |
else |
|
48 |
local reply = st.reply(stanza); |
|
49 |
reply.attr.type = "error"; |
|
50 |
reply:tag("error", { code = "401", type = "auth" }) |
|
51 |
:tag("not-authorized", { xmlns = "urn:ietf:params:xml:ns:xmpp-stanzas" }); |
|
52 |
dispatch_stanza(reply); |
|
53 |
return true; |
|
54 |
end |
|
55 |
end |
|
56 |
||
57 |
end); |