2016-12-28 07:47:11 +01:00
|
|
|
%%%-------------------------------------------------------------------
|
|
|
|
%%% Created : 12 Dec 2016 by Evgeny Khramtsov <ekhramtsov@process-one.net>
|
2007-12-24 12:41:41 +01:00
|
|
|
%%%
|
|
|
|
%%%
|
2020-01-28 13:34:02 +01:00
|
|
|
%%% ejabberd, Copyright (C) 2002-2020 ProcessOne
|
2007-12-24 12:41:41 +01:00
|
|
|
%%%
|
|
|
|
%%% This program is free software; you can redistribute it and/or
|
|
|
|
%%% modify it under the terms of the GNU General Public License as
|
|
|
|
%%% published by the Free Software Foundation; either version 2 of the
|
|
|
|
%%% License, or (at your option) any later version.
|
|
|
|
%%%
|
|
|
|
%%% This program is distributed in the hope that it will be useful,
|
|
|
|
%%% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
%%% General Public License for more details.
|
2009-01-12 15:44:42 +01:00
|
|
|
%%%
|
2014-02-22 11:27:40 +01:00
|
|
|
%%% You should have received a copy of the GNU General Public License along
|
|
|
|
%%% with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
%%% 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2007-12-24 12:41:41 +01:00
|
|
|
%%%
|
2016-12-28 07:47:11 +01:00
|
|
|
%%%-------------------------------------------------------------------
|
2002-12-06 21:59:19 +01:00
|
|
|
-module(ejabberd_s2s_in).
|
2016-12-28 07:47:11 +01:00
|
|
|
-behaviour(xmpp_stream_in).
|
2018-09-17 10:21:02 +02:00
|
|
|
-behaviour(ejabberd_listener).
|
2015-06-01 14:38:27 +02:00
|
|
|
|
2017-05-08 11:59:28 +02:00
|
|
|
%% ejabberd_listener callbacks
|
2019-06-14 11:33:26 +02:00
|
|
|
-export([start/3, start_link/3, accept/1, listen_options/0]).
|
2016-12-28 07:47:11 +01:00
|
|
|
%% xmpp_stream_in callbacks
|
|
|
|
-export([init/1, handle_call/3, handle_cast/2,
|
|
|
|
handle_info/2, terminate/2, code_change/3]).
|
2018-07-10 09:14:08 +02:00
|
|
|
-export([tls_options/1, tls_required/1, tls_enabled/1, compress_methods/1,
|
2016-12-28 07:47:11 +01:00
|
|
|
unauthenticated_stream_features/1, authenticated_stream_features/1,
|
2016-12-29 22:00:36 +01:00
|
|
|
handle_stream_start/2, handle_stream_end/2,
|
2016-12-28 07:47:11 +01:00
|
|
|
handle_stream_established/1, handle_auth_success/4,
|
|
|
|
handle_auth_failure/4, handle_send/3, handle_recv/3, handle_cdata/2,
|
|
|
|
handle_unauthenticated_packet/2, handle_authenticated_packet/2]).
|
|
|
|
%% Hooks
|
|
|
|
-export([handle_unexpected_info/2, handle_unexpected_cast/2,
|
|
|
|
reject_unauthenticated_packet/2, process_closed/2]).
|
|
|
|
%% API
|
2020-04-01 14:35:49 +02:00
|
|
|
-export([stop_async/1, close/1, close/2, send/2, update_state/2, establish/1,
|
2017-02-23 08:12:19 +01:00
|
|
|
host_up/1, host_down/1]).
|
2002-12-06 21:59:19 +01:00
|
|
|
|
2016-07-27 09:45:08 +02:00
|
|
|
-include("xmpp.hrl").
|
2016-12-28 07:47:11 +01:00
|
|
|
-include("logger.hrl").
|
2013-03-14 10:33:02 +01:00
|
|
|
|
2019-06-22 09:19:17 +02:00
|
|
|
-type state() :: xmpp_stream_in:state().
|
2016-12-28 07:47:11 +01:00
|
|
|
-export_type([state/0]).
|
2011-12-02 19:30:20 +01:00
|
|
|
|
2016-12-28 07:47:11 +01:00
|
|
|
%%%===================================================================
|
|
|
|
%%% API
|
|
|
|
%%%===================================================================
|
2019-04-01 15:53:28 +02:00
|
|
|
start(SockMod, Socket, Opts) ->
|
|
|
|
xmpp_stream_in:start(?MODULE, [{SockMod, Socket}, Opts],
|
2018-09-17 10:21:02 +02:00
|
|
|
ejabberd_config:fsm_limit_opts(Opts)).
|
2003-07-20 22:35:35 +02:00
|
|
|
|
2019-04-01 15:53:28 +02:00
|
|
|
start_link(SockMod, Socket, Opts) ->
|
|
|
|
xmpp_stream_in:start_link(?MODULE, [{SockMod, Socket}, Opts],
|
2016-12-28 07:47:11 +01:00
|
|
|
ejabberd_config:fsm_limit_opts(Opts)).
|
|
|
|
|
|
|
|
close(Ref) ->
|
|
|
|
xmpp_stream_in:close(Ref).
|
|
|
|
|
2017-04-15 07:30:41 +02:00
|
|
|
close(Ref, Reason) ->
|
|
|
|
xmpp_stream_in:close(Ref, Reason).
|
|
|
|
|
2020-04-01 14:35:49 +02:00
|
|
|
-spec stop_async(pid()) -> ok.
|
|
|
|
stop_async(Pid) ->
|
|
|
|
xmpp_stream_in:stop_async(Pid).
|
2016-12-28 07:47:11 +01:00
|
|
|
|
2018-09-17 10:21:02 +02:00
|
|
|
accept(Ref) ->
|
|
|
|
xmpp_stream_in:accept(Ref).
|
2016-12-28 07:47:11 +01:00
|
|
|
|
|
|
|
-spec send(pid(), xmpp_element()) -> ok;
|
|
|
|
(state(), xmpp_element()) -> state().
|
|
|
|
send(Stream, Pkt) ->
|
|
|
|
xmpp_stream_in:send(Stream, Pkt).
|
|
|
|
|
|
|
|
-spec establish(state()) -> state().
|
|
|
|
establish(State) ->
|
|
|
|
xmpp_stream_in:establish(State).
|
|
|
|
|
|
|
|
-spec update_state(pid(), fun((state()) -> state()) |
|
|
|
|
{module(), atom(), list()}) -> ok.
|
|
|
|
update_state(Ref, Callback) ->
|
|
|
|
xmpp_stream_in:cast(Ref, {update_state, Callback}).
|
|
|
|
|
2017-02-23 08:12:19 +01:00
|
|
|
-spec host_up(binary()) -> ok.
|
|
|
|
host_up(Host) ->
|
|
|
|
ejabberd_hooks:add(s2s_in_closed, Host, ?MODULE,
|
|
|
|
process_closed, 100),
|
|
|
|
ejabberd_hooks:add(s2s_in_unauthenticated_packet, Host, ?MODULE,
|
|
|
|
reject_unauthenticated_packet, 100),
|
|
|
|
ejabberd_hooks:add(s2s_in_handle_info, Host, ?MODULE,
|
|
|
|
handle_unexpected_info, 100),
|
|
|
|
ejabberd_hooks:add(s2s_in_handle_cast, Host, ?MODULE,
|
|
|
|
handle_unexpected_cast, 100).
|
|
|
|
|
|
|
|
-spec host_down(binary()) -> ok.
|
|
|
|
host_down(Host) ->
|
|
|
|
ejabberd_hooks:delete(s2s_in_closed, Host, ?MODULE,
|
|
|
|
process_closed, 100),
|
|
|
|
ejabberd_hooks:delete(s2s_in_unauthenticated_packet, Host, ?MODULE,
|
|
|
|
reject_unauthenticated_packet, 100),
|
|
|
|
ejabberd_hooks:delete(s2s_in_handle_info, Host, ?MODULE,
|
|
|
|
handle_unexpected_info, 100),
|
|
|
|
ejabberd_hooks:delete(s2s_in_handle_cast, Host, ?MODULE,
|
|
|
|
handle_unexpected_cast, 100).
|
2016-12-28 07:47:11 +01:00
|
|
|
|
|
|
|
%%%===================================================================
|
|
|
|
%%% Hooks
|
|
|
|
%%%===================================================================
|
|
|
|
handle_unexpected_info(State, Info) ->
|
2019-06-24 19:32:34 +02:00
|
|
|
?WARNING_MSG("Unexpected info: ~p", [Info]),
|
2016-12-28 07:47:11 +01:00
|
|
|
State.
|
|
|
|
|
|
|
|
handle_unexpected_cast(State, Msg) ->
|
2019-06-24 19:32:34 +02:00
|
|
|
?WARNING_MSG("Unexpected cast: ~p", [Msg]),
|
2016-12-28 07:47:11 +01:00
|
|
|
State.
|
|
|
|
|
2017-01-13 09:35:47 +01:00
|
|
|
reject_unauthenticated_packet(State, _Pkt) ->
|
|
|
|
Err = xmpp:serr_not_authorized(),
|
|
|
|
send(State, Err).
|
2016-12-28 07:47:11 +01:00
|
|
|
|
2018-08-29 16:23:56 +02:00
|
|
|
process_closed(#{server := LServer} = State, Reason) ->
|
|
|
|
RServer = case State of
|
|
|
|
#{remote_server := Name} ->
|
|
|
|
Name;
|
|
|
|
#{ip := IP} ->
|
|
|
|
ejabberd_config:may_hide_data(misc:ip_to_list(IP))
|
|
|
|
end,
|
2019-09-23 14:17:20 +02:00
|
|
|
?INFO_MSG("Closing inbound s2s connection ~ts -> ~ts: ~ts",
|
2018-08-29 16:23:56 +02:00
|
|
|
[RServer, LServer, xmpp_stream_out:format_error(Reason)]),
|
2020-04-01 14:35:49 +02:00
|
|
|
stop_async(self()),
|
|
|
|
State.
|
2016-12-28 07:47:11 +01:00
|
|
|
|
|
|
|
%%%===================================================================
|
|
|
|
%%% xmpp_stream_in callbacks
|
|
|
|
%%%===================================================================
|
2019-09-06 21:20:07 +02:00
|
|
|
tls_options(#{tls_options := TLSOpts, lserver := LServer, server_host := ServerHost}) ->
|
|
|
|
ejabberd_s2s:tls_options(LServer, ServerHost, TLSOpts).
|
2016-12-28 07:47:11 +01:00
|
|
|
|
2019-06-23 18:37:54 +02:00
|
|
|
tls_required(#{server_host := ServerHost}) ->
|
|
|
|
ejabberd_s2s:tls_required(ServerHost).
|
2002-12-06 21:59:19 +01:00
|
|
|
|
2019-06-23 18:37:54 +02:00
|
|
|
tls_enabled(#{server_host := ServerHost}) ->
|
|
|
|
ejabberd_s2s:tls_enabled(ServerHost).
|
2002-12-06 21:59:19 +01:00
|
|
|
|
2019-06-23 18:37:54 +02:00
|
|
|
compress_methods(#{server_host := ServerHost}) ->
|
|
|
|
case ejabberd_s2s:zlib_enabled(ServerHost) of
|
2016-12-28 07:47:11 +01:00
|
|
|
true -> [<<"zlib">>];
|
|
|
|
false -> []
|
|
|
|
end.
|
|
|
|
|
|
|
|
unauthenticated_stream_features(#{server_host := LServer}) ->
|
|
|
|
ejabberd_hooks:run_fold(s2s_in_pre_auth_features, LServer, [], [LServer]).
|
|
|
|
|
|
|
|
authenticated_stream_features(#{server_host := LServer}) ->
|
|
|
|
ejabberd_hooks:run_fold(s2s_in_post_auth_features, LServer, [], [LServer]).
|
|
|
|
|
|
|
|
handle_stream_start(_StreamStart, #{lserver := LServer} = State) ->
|
|
|
|
case check_to(jid:make(LServer), State) of
|
|
|
|
false ->
|
|
|
|
send(State, xmpp:serr_host_unknown());
|
2017-05-24 17:16:16 +02:00
|
|
|
true ->
|
2016-12-28 07:47:11 +01:00
|
|
|
ServerHost = ejabberd_router:host_of_route(LServer),
|
2019-06-21 20:06:32 +02:00
|
|
|
Opts = ejabberd_config:codec_options(),
|
2018-02-09 16:12:50 +01:00
|
|
|
State#{server_host => ServerHost, codec_options => Opts}
|
2016-12-28 07:47:11 +01:00
|
|
|
end.
|
|
|
|
|
2019-06-23 18:37:54 +02:00
|
|
|
handle_stream_end(Reason, #{server_host := ServerHost} = State) ->
|
2017-03-07 16:46:02 +01:00
|
|
|
State1 = State#{stop_reason => Reason},
|
2019-06-23 18:37:54 +02:00
|
|
|
ejabberd_hooks:run_fold(s2s_in_closed, ServerHost, State1, [Reason]).
|
2016-12-28 07:47:11 +01:00
|
|
|
|
|
|
|
handle_stream_established(State) ->
|
|
|
|
set_idle_timeout(State#{established => true}).
|
|
|
|
|
|
|
|
handle_auth_success(RServer, Mech, _AuthModule,
|
2017-12-26 16:55:57 +01:00
|
|
|
#{socket := Socket, ip := IP,
|
2016-12-28 07:47:11 +01:00
|
|
|
auth_domains := AuthDomains,
|
|
|
|
server_host := ServerHost,
|
|
|
|
lserver := LServer} = State) ->
|
2019-09-23 14:17:20 +02:00
|
|
|
?INFO_MSG("(~ts) Accepted inbound s2s ~ts authentication ~ts -> ~ts (~ts)",
|
2017-12-26 16:55:57 +01:00
|
|
|
[xmpp_socket:pp(Socket), Mech, RServer, LServer,
|
2017-04-11 12:13:58 +02:00
|
|
|
ejabberd_config:may_hide_data(misc:ip_to_list(IP))]),
|
2019-06-24 20:18:57 +02:00
|
|
|
State1 = case ejabberd_s2s:allow_host(ServerHost, RServer) of
|
2017-05-24 17:16:16 +02:00
|
|
|
true ->
|
2016-12-28 07:47:11 +01:00
|
|
|
AuthDomains1 = sets:add_element(RServer, AuthDomains),
|
2017-12-26 16:55:57 +01:00
|
|
|
State0 = change_shaper(State, RServer),
|
|
|
|
State0#{auth_domains => AuthDomains1};
|
2016-12-28 07:47:11 +01:00
|
|
|
false ->
|
|
|
|
State
|
2018-10-15 23:03:53 +02:00
|
|
|
end,
|
2016-12-28 07:47:11 +01:00
|
|
|
ejabberd_hooks:run_fold(s2s_in_auth_result, ServerHost, State1, [true, RServer]).
|
|
|
|
|
|
|
|
handle_auth_failure(RServer, Mech, Reason,
|
2017-12-26 16:55:57 +01:00
|
|
|
#{socket := Socket, ip := IP,
|
2016-12-28 07:47:11 +01:00
|
|
|
server_host := ServerHost,
|
|
|
|
lserver := LServer} = State) ->
|
2019-09-23 14:17:20 +02:00
|
|
|
?WARNING_MSG("(~ts) Failed inbound s2s ~ts authentication ~ts -> ~ts (~ts): ~ts",
|
2018-09-19 22:12:14 +02:00
|
|
|
[xmpp_socket:pp(Socket), Mech, RServer, LServer,
|
|
|
|
ejabberd_config:may_hide_data(misc:ip_to_list(IP)), Reason]),
|
2016-12-28 07:47:11 +01:00
|
|
|
ejabberd_hooks:run_fold(s2s_in_auth_result,
|
|
|
|
ServerHost, State, [false, RServer]).
|
|
|
|
|
2019-06-23 18:37:54 +02:00
|
|
|
handle_unauthenticated_packet(Pkt, #{server_host := ServerHost} = State) ->
|
2016-12-28 07:47:11 +01:00
|
|
|
ejabberd_hooks:run_fold(s2s_in_unauthenticated_packet,
|
2019-06-23 18:37:54 +02:00
|
|
|
ServerHost, State, [Pkt]).
|
2016-12-28 07:47:11 +01:00
|
|
|
|
2019-06-23 18:37:54 +02:00
|
|
|
handle_authenticated_packet(Pkt, #{server_host := ServerHost} = State) when not ?is_stanza(Pkt) ->
|
|
|
|
ejabberd_hooks:run_fold(s2s_in_authenticated_packet, ServerHost, State, [Pkt]);
|
2017-02-14 15:09:25 +01:00
|
|
|
handle_authenticated_packet(Pkt0, #{ip := {IP, _}} = State) ->
|
|
|
|
Pkt = xmpp:put_meta(Pkt0, ip, IP),
|
2016-07-27 09:45:08 +02:00
|
|
|
From = xmpp:get_from(Pkt),
|
|
|
|
To = xmpp:get_to(Pkt),
|
2016-12-28 07:47:11 +01:00
|
|
|
case check_from_to(From, To, State) of
|
|
|
|
ok ->
|
|
|
|
LServer = ejabberd_router:host_of_route(To#jid.lserver),
|
|
|
|
State1 = ejabberd_hooks:run_fold(s2s_in_authenticated_packet,
|
|
|
|
LServer, State, [Pkt]),
|
2017-01-09 15:02:17 +01:00
|
|
|
{Pkt1, State2} = ejabberd_hooks:run_fold(s2s_receive_packet, LServer,
|
|
|
|
{Pkt, State1}, []),
|
|
|
|
case Pkt1 of
|
|
|
|
drop -> ok;
|
2017-02-16 09:00:26 +01:00
|
|
|
_ -> ejabberd_router:route(Pkt1)
|
2018-10-15 23:03:53 +02:00
|
|
|
end,
|
2017-01-09 15:02:17 +01:00
|
|
|
State2;
|
2016-12-28 07:47:11 +01:00
|
|
|
{error, Err} ->
|
|
|
|
send(State, Err)
|
2011-12-02 19:30:20 +01:00
|
|
|
end.
|
|
|
|
|
2019-06-23 18:37:54 +02:00
|
|
|
handle_cdata(Data, #{server_host := ServerHost} = State) ->
|
|
|
|
ejabberd_hooks:run_fold(s2s_in_handle_cdata, ServerHost, State, [Data]).
|
2016-12-28 07:47:11 +01:00
|
|
|
|
2019-06-23 18:37:54 +02:00
|
|
|
handle_recv(El, Pkt, #{server_host := ServerHost} = State) ->
|
2016-12-28 07:47:11 +01:00
|
|
|
State1 = set_idle_timeout(State),
|
2019-06-23 18:37:54 +02:00
|
|
|
ejabberd_hooks:run_fold(s2s_in_handle_recv, ServerHost, State1, [El, Pkt]).
|
2016-12-28 07:47:11 +01:00
|
|
|
|
2019-06-23 18:37:54 +02:00
|
|
|
handle_send(Pkt, Result, #{server_host := ServerHost} = State) ->
|
|
|
|
ejabberd_hooks:run_fold(s2s_in_handle_send, ServerHost,
|
2016-12-28 07:47:11 +01:00
|
|
|
State, [Pkt, Result]).
|
|
|
|
|
|
|
|
init([State, Opts]) ->
|
2017-05-08 13:34:35 +02:00
|
|
|
Shaper = proplists:get_value(shaper, Opts, none),
|
2017-01-09 15:02:17 +01:00
|
|
|
TLSOpts1 = lists:filter(
|
|
|
|
fun({certfile, _}) -> true;
|
|
|
|
({ciphers, _}) -> true;
|
|
|
|
({dhfile, _}) -> true;
|
|
|
|
({cafile, _}) -> true;
|
2017-04-30 18:01:47 +02:00
|
|
|
({protocol_options, _}) -> true;
|
2017-01-09 15:02:17 +01:00
|
|
|
(_) -> false
|
|
|
|
end, Opts),
|
2017-04-30 18:01:47 +02:00
|
|
|
TLSOpts2 = case proplists:get_bool(tls_compression, Opts) of
|
2018-10-15 23:03:53 +02:00
|
|
|
false -> [compression_none | TLSOpts1];
|
|
|
|
true -> TLSOpts1
|
|
|
|
end,
|
2019-06-14 11:33:26 +02:00
|
|
|
Timeout = ejabberd_option:negotiation_timeout(),
|
2017-04-30 18:01:47 +02:00
|
|
|
State1 = State#{tls_options => TLSOpts2,
|
2016-12-28 07:47:11 +01:00
|
|
|
auth_domains => sets:new(),
|
|
|
|
xmlns => ?NS_SERVER,
|
2019-06-14 11:33:26 +02:00
|
|
|
lang => ejabberd_option:language(),
|
2018-06-14 13:00:47 +02:00
|
|
|
server => ejabberd_config:get_myname(),
|
|
|
|
lserver => ejabberd_config:get_myname(),
|
|
|
|
server_host => ejabberd_config:get_myname(),
|
2016-12-28 07:47:11 +01:00
|
|
|
established => false,
|
|
|
|
shaper => Shaper},
|
2018-02-20 09:38:00 +01:00
|
|
|
State2 = xmpp_stream_in:set_timeout(State1, Timeout),
|
|
|
|
ejabberd_hooks:run_fold(s2s_in_init, {ok, State2}, [Opts]).
|
2016-12-28 07:47:11 +01:00
|
|
|
|
2019-06-23 18:37:54 +02:00
|
|
|
handle_call(Request, From, #{server_host := ServerHost} = State) ->
|
|
|
|
ejabberd_hooks:run_fold(s2s_in_handle_call, ServerHost, State, [Request, From]).
|
2016-12-28 07:47:11 +01:00
|
|
|
|
|
|
|
handle_cast({update_state, Fun}, State) ->
|
|
|
|
case Fun of
|
|
|
|
{M, F, A} -> erlang:apply(M, F, [State|A]);
|
|
|
|
_ when is_function(Fun) -> Fun(State)
|
|
|
|
end;
|
2019-06-23 18:37:54 +02:00
|
|
|
handle_cast(Msg, #{server_host := ServerHost} = State) ->
|
|
|
|
ejabberd_hooks:run_fold(s2s_in_handle_cast, ServerHost, State, [Msg]).
|
2002-12-07 21:27:26 +01:00
|
|
|
|
2019-06-23 18:37:54 +02:00
|
|
|
handle_info(Info, #{server_host := ServerHost} = State) ->
|
|
|
|
ejabberd_hooks:run_fold(s2s_in_handle_info, ServerHost, State, [Info]).
|
2016-12-28 07:47:11 +01:00
|
|
|
|
2017-03-07 16:46:02 +01:00
|
|
|
terminate(Reason, #{auth_domains := AuthDomains,
|
2017-12-26 16:55:57 +01:00
|
|
|
socket := Socket} = State) ->
|
2017-03-07 16:46:02 +01:00
|
|
|
case maps:get(stop_reason, State, undefined) of
|
2017-03-08 06:27:54 +01:00
|
|
|
{tls, _} = Err ->
|
2019-09-23 14:17:20 +02:00
|
|
|
?WARNING_MSG("(~ts) Failed to secure inbound s2s connection: ~ts",
|
2017-12-26 16:55:57 +01:00
|
|
|
[xmpp_socket:pp(Socket), xmpp_stream_in:format_error(Err)]);
|
2017-03-07 16:46:02 +01:00
|
|
|
_ ->
|
|
|
|
ok
|
|
|
|
end,
|
2011-12-02 19:30:20 +01:00
|
|
|
case Reason of
|
2013-03-14 10:33:02 +01:00
|
|
|
{process_limit, _} ->
|
2017-01-09 15:02:17 +01:00
|
|
|
sets:fold(
|
|
|
|
fun(Host, _) ->
|
|
|
|
ejabberd_s2s:external_host_overloaded(Host)
|
|
|
|
end, ok, AuthDomains);
|
|
|
|
_ ->
|
|
|
|
ok
|
2011-12-02 19:30:20 +01:00
|
|
|
end.
|
|
|
|
|
2016-12-28 07:47:11 +01:00
|
|
|
code_change(_OldVsn, State, _Extra) ->
|
|
|
|
{ok, State}.
|
2011-12-02 19:30:20 +01:00
|
|
|
|
2016-12-28 07:47:11 +01:00
|
|
|
%%%===================================================================
|
2002-12-06 21:59:19 +01:00
|
|
|
%%% Internal functions
|
2016-12-28 07:47:11 +01:00
|
|
|
%%%===================================================================
|
|
|
|
-spec check_from_to(jid(), jid(), state()) -> ok | {error, stream_error()}.
|
|
|
|
check_from_to(From, To, State) ->
|
|
|
|
case check_from(From, State) of
|
2017-05-24 17:16:16 +02:00
|
|
|
true ->
|
2016-12-28 07:47:11 +01:00
|
|
|
case check_to(To, State) of
|
2017-05-24 17:16:16 +02:00
|
|
|
true ->
|
2016-12-28 07:47:11 +01:00
|
|
|
ok;
|
2017-05-24 17:16:16 +02:00
|
|
|
false ->
|
2017-01-13 09:35:47 +01:00
|
|
|
{error, xmpp:serr_host_unknown()}
|
2017-05-24 17:16:16 +02:00
|
|
|
end;
|
2016-12-28 07:47:11 +01:00
|
|
|
false ->
|
|
|
|
{error, xmpp:serr_invalid_from()}
|
2016-07-27 09:45:08 +02:00
|
|
|
end.
|
|
|
|
|
2016-12-28 07:47:11 +01:00
|
|
|
-spec check_from(jid(), state()) -> boolean().
|
|
|
|
check_from(#jid{lserver = S1}, #{auth_domains := AuthDomains}) ->
|
|
|
|
sets:is_element(S1, AuthDomains).
|
|
|
|
|
|
|
|
-spec check_to(jid(), state()) -> boolean().
|
|
|
|
check_to(#jid{lserver = LServer}, _State) ->
|
|
|
|
ejabberd_router:is_my_route(LServer).
|
|
|
|
|
|
|
|
-spec set_idle_timeout(state()) -> state().
|
2019-06-23 18:37:54 +02:00
|
|
|
set_idle_timeout(#{server_host := ServerHost,
|
2016-12-28 07:47:11 +01:00
|
|
|
established := true} = State) ->
|
2019-06-23 18:37:54 +02:00
|
|
|
Timeout = ejabberd_s2s:get_idle_timeout(ServerHost),
|
2016-12-28 07:47:11 +01:00
|
|
|
xmpp_stream_in:set_timeout(State, Timeout);
|
|
|
|
set_idle_timeout(State) ->
|
|
|
|
State.
|
2015-06-01 14:38:27 +02:00
|
|
|
|
2017-12-26 16:55:57 +01:00
|
|
|
-spec change_shaper(state(), binary()) -> state().
|
2017-01-09 15:02:17 +01:00
|
|
|
change_shaper(#{shaper := ShaperName, server_host := ServerHost} = State,
|
|
|
|
RServer) ->
|
2019-06-14 11:33:26 +02:00
|
|
|
Shaper = ejabberd_shaper:match(ServerHost, ShaperName, jid:make(RServer)),
|
2018-07-06 00:07:36 +02:00
|
|
|
xmpp_stream_in:change_shaper(State, ejabberd_shaper:new(Shaper)).
|
2017-01-09 15:02:17 +01:00
|
|
|
|
2018-09-18 11:53:36 +02:00
|
|
|
listen_options() ->
|
|
|
|
[{shaper, none},
|
|
|
|
{ciphers, undefined},
|
|
|
|
{dhfile, undefined},
|
|
|
|
{cafile, undefined},
|
|
|
|
{protocol_options, undefined},
|
|
|
|
{tls, false},
|
|
|
|
{tls_compression, false},
|
|
|
|
{max_stanza_size, infinity},
|
2020-05-05 01:34:12 +02:00
|
|
|
{max_fsm_queue, 10000}].
|