From 707aa4fb8c6f6da8f8c1639acdc8c10b28f83227 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20R=C3=A9mond?= Date: Sun, 28 Dec 2008 12:15:51 +0000 Subject: [PATCH] * src/ejabberd_c2s.erl: We should allow use of bare resource in from by the client (partially revert r1727) (EJAB-812) SVN Revision: 1759 --- ChangeLog | 5 +++++ src/ejabberd_c2s.erl | 39 ++++++++++++++++++++++++++------------- 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/ChangeLog b/ChangeLog index d60614fea..baee8cf50 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2008-12-28 Mickael Remond + + * src/ejabberd_c2s.erl: We should allow use of bare resource in from by + the client (partially revert r1727) (EJAB-812). + 2008-12-26 Badlop * src/web/ejabberd_web_admin.erl: Show in ejabberd Web Admin the diff --git a/src/ejabberd_c2s.erl b/src/ejabberd_c2s.erl index 7fcff5b41..c8ae3f188 100644 --- a/src/ejabberd_c2s.erl +++ b/src/ejabberd_c2s.erl @@ -1983,20 +1983,33 @@ is_ip_blacklisted({IP,_Port}) -> check_from(El, FromJID) -> case xml:get_tag_attr("from", El) of false -> - El; - {value, SJID} -> - JID = jlib:string_to_jid(SJID), - case JID of - error -> - 'invalid-from'; - #jid{} -> - if - (JID#jid.luser == FromJID#jid.luser) and - (JID#jid.lserver == FromJID#jid.lserver) and - (JID#jid.lresource == FromJID#jid.lresource) -> - El; - true -> + jlib:replace_from(FromJID, El); + {value, JIDElString} -> + JIDEl = jlib:string_to_jid(JIDElString), + case JIDEl#jid.lresource of + "" -> + %% Matching JID: The stanza is ok + if JIDEl#jid.luser == FromJID#jid.luser andalso + JIDEl#jid.lserver == FromJID#jid.lserver -> + %% We force the resource on the from attribute in the packet. + %% This is strictly needed only for IQ (to + %% reply to the client), but I do not see + %% any good reason for now not to do it on + %% all packets. + %% Need to be changed to support multiple + %% resource binding per connection. + jlib:replace_from(FromJID, El); + true -> 'invalid-from' + end; + _ -> + %% Matching JID: The stanza is ok + if JIDEl#jid.luser == FromJID#jid.luser andalso + JIDEl#jid.lserver == FromJID#jid.lserver andalso + JIDEl#jid.lresource == FromJID#jid.lresource -> + El; + true -> + 'invalid-from' end end end.