From 48f0d9c15ec5a77f5b1800c241ad2a54ee127794 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Chmielowski?= Date: Wed, 22 Nov 2023 18:34:18 +0100 Subject: [PATCH] Update xmpp to make us present both sasl1 and sasl2 with from in initial stanza --- mix.exs | 2 +- rebar.config | 2 +- src/ejabberd_c2s.erl | 2 +- src/ejabberd_sm.erl | 25 ++++++++++++++----------- 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/mix.exs b/mix.exs index 0f6b059f6..135f6778e 100644 --- a/mix.exs +++ b/mix.exs @@ -114,7 +114,7 @@ defmodule Ejabberd.MixProject do {:p1_utils, "~> 1.0"}, {:pkix, "~> 1.0"}, {:stringprep, ">= 1.0.26"}, - {:xmpp, git: "https://github.com/processone/xmpp.git", ref: "dcb701e6800d827f8806c0d049aaf103cd724e2b", override: true}, + {:xmpp, git: "https://github.com/processone/xmpp.git", ref: "2b0c95c807fc8f5862bc4301e0b7451a0617348e", override: true}, {:yconf, "~> 1.0"}] ++ cond_deps() end diff --git a/rebar.config b/rebar.config index cbbf1d927..594abece8 100644 --- a/rebar.config +++ b/rebar.config @@ -77,7 +77,7 @@ {stringprep, ".*", {git, "https://github.com/processone/stringprep", {tag, "1.0.29"}}}, {if_var_true, stun, {stun, ".*", {git, "https://github.com/processone/stun", {tag, "1.2.10"}}}}, - {xmpp, ".*", {git, "https://github.com/processone/xmpp", "dcb701e6800d827f8806c0d049aaf103cd724e2b"}}, + {xmpp, ".*", {git, "https://github.com/processone/xmpp", "2b0c95c807fc8f5862bc4301e0b7451a0617348e"}}, {yconf, ".*", {git, "https://github.com/processone/yconf", {tag, "1.0.15"}}} ]}. diff --git a/src/ejabberd_c2s.erl b/src/ejabberd_c2s.erl index 32ac79305..de246cbae 100644 --- a/src/ejabberd_c2s.erl +++ b/src/ejabberd_c2s.erl @@ -216,7 +216,7 @@ open_session(#{user := U, server := S, resource := R, end, Info = [{ip, IP}, {conn, Conn}, {auth_module, AuthModule}], case State of - #{bind2_tag := Tag} -> + #{bind2_session_id := Tag} -> ejabberd_sm:open_session(SID, U, S, R, Prio, Info, Tag); _ -> ejabberd_sm:open_session(SID, U, S, R, Prio, Info) diff --git a/src/ejabberd_sm.erl b/src/ejabberd_sm.erl index 7222a91f5..37ef9094b 100644 --- a/src/ejabberd_sm.erl +++ b/src/ejabberd_sm.erl @@ -149,8 +149,8 @@ route(Packet) -> end. --spec open_session(sid(), binary(), binary(), binary(), prio(), info(), binary() | undefined) -> ok. - +-spec open_session(sid(), binary(), binary(), binary(), prio(), info(), + {binary(), binary()} | undefined) -> ok. open_session(SID, User, Server, Resource, Priority, Info, Bind2Tag) -> set_session(SID, User, Server, Resource, Priority, Info), check_for_sessions_to_replace(User, Server, Resource, Bind2Tag), @@ -459,7 +459,7 @@ c2s_handle_info(#{lang := Lang} = State, replaced) -> State1 = State#{replaced => true}, Err = xmpp:serr_conflict(?T("Replaced by new connection"), Lang), {stop, ejabberd_c2s:send(State1, Err)}; -c2s_handle_info(#{lang := Lang, bind2_tag := Tag} = State, +c2s_handle_info(#{lang := Lang, bind2_session_id := {Tag, _}} = State, {replaced_with_bind_tag, Bind2Tag}) when Tag == Bind2Tag -> State1 = State#{replaced => true}, Err = xmpp:serr_conflict(?T("Replaced by new connection"), Lang), @@ -840,8 +840,8 @@ clean_session_list([S1, S2 | Rest], Res) -> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% On new session, check if some existing connections need to be replace --spec check_for_sessions_to_replace(binary(), binary(), binary(), binary() | undefined) - -> ok | replaced. +-spec check_for_sessions_to_replace(binary(), binary(), binary(), + {binary(), binary()} | undefined) -> ok | replaced. check_for_sessions_to_replace(User, Server, Resource, Bind2Tag) -> LUser = jid:nodeprep(User), LServer = jid:nameprep(Server), @@ -849,7 +849,8 @@ check_for_sessions_to_replace(User, Server, Resource, Bind2Tag) -> check_existing_resources(LUser, LServer, LResource, Bind2Tag), check_max_sessions(LUser, LServer). --spec check_existing_resources(binary(), binary(), binary(), binary() | undefined) -> ok. +-spec check_existing_resources(binary(), binary(), binary(), + {binary(), binary()} | undefined) -> ok. check_existing_resources(LUser, LServer, LResource, undefined) -> Mod = get_sm_backend(LServer), Ss = get_sessions(Mod, LUser, LServer, LResource), @@ -863,14 +864,16 @@ check_existing_resources(LUser, LServer, LResource, undefined) -> end, SIDs) end; -check_existing_resources(LUser, LServer, _LResource, Bind2Tag) -> +check_existing_resources(LUser, LServer, LResource, {Tag, Hash}) -> Mod = get_sm_backend(LServer), Ss = get_sessions(Mod, LUser, LServer), - Len = size(Bind2Tag), lists:foreach( - fun(#session{sid = {_, Pid}, usr = {_, _, <>}}) - when Pid /= self(), Tag == Bind2Tag -> - ejabberd_c2s:route(Pid, {replaced_with_bind_tag, Bind2Tag}); + fun(#session{sid = {_, Pid}, usr = {_, _, Res}}) + when Pid /= self(), Res == LResource -> + ejabberd_c2s:route(Pid, replaced); + (#session{sid = {_, Pid}, usr = {_, _, Res}}) + when Pid /= self(), binary_part(Res, size(Res), -size(Hash)) == Hash -> + ejabberd_c2s:route(Pid, {replaced_with_bind_tag, Tag}); (_) -> ok end, Ss).