25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-12-22 17:28:25 +01:00

Introduce option 'allow_transports'

This is a boolean option. If set to `true` and some server's JID
is in user's roster, then messages from any user of this server are
accepted even if no subscription present.

The option is enabled by default.
This commit is contained in:
Evgeniy Khramtsov 2017-09-08 23:10:01 +03:00
parent 9e35af54e0
commit dfd2045523

View File

@ -86,20 +86,19 @@ check_message(#message{from = From, to = To} = Msg) ->
case (Msg#message.body == [] andalso case (Msg#message.body == [] andalso
Msg#message.subject == []) Msg#message.subject == [])
orelse ((AllowLocalUsers orelse From#jid.luser == <<"">>) andalso orelse ((AllowLocalUsers orelse From#jid.luser == <<"">>) andalso
ejabberd_router:is_my_route(From#jid.lserver)) of ejabberd_router:is_my_host(From#jid.lserver)) of
false -> false ->
{Sub, _} = ejabberd_hooks:run_fold( case check_subscription(From, To) of
roster_get_jid_info, LServer,
{none, []}, [To#jid.luser, LServer, From]),
case Sub of
none -> none ->
Drop = gen_mod:get_module_opt(LServer, ?MODULE, drop, true), Drop = gen_mod:get_module_opt(LServer, ?MODULE, drop, true),
Log = gen_mod:get_module_opt(LServer, ?MODULE, log, false), Log = gen_mod:get_module_opt(LServer, ?MODULE, log, false),
if if
Log -> Log ->
?INFO_MSG("Dropping message from ~s to ~s: " ?INFO_MSG("~s message from stranger ~s to ~s",
"the sender is not in the roster", [if Drop -> "Dropping";
[jid:encode(From), jid:encode(To)]); true -> "Allow"
end,
jid:encode(From), jid:encode(To)]);
true -> true ->
ok ok
end, end,
@ -109,13 +108,41 @@ check_message(#message{from = From, to = To} = Msg) ->
true -> true ->
allow allow
end; end;
_ -> some ->
allow allow
end; end;
true -> true ->
allow allow
end. end.
-spec check_subscription(jid(), jid()) -> none | some.
check_subscription(From, To) ->
{LocalUser, LocalServer, _} = jid:tolower(To),
{RemoteUser, RemoteServer, _} = jid:tolower(From),
case ejabberd_hooks:run_fold(
roster_get_jid_info, LocalServer,
{none, []}, [LocalUser, LocalServer, From]) of
{none, _} when RemoteUser == <<"">> ->
none;
{none, _} ->
case gen_mod:get_module_opt(LocalServer, ?MODULE,
allow_transports, true) of
true ->
%% Check if the contact's server is in the roster
case ejabberd_hooks:run_fold(
roster_get_jid_info, LocalServer,
{none, []},
[LocalUser, LocalServer, jid:make(RemoteServer)]) of
{none, _} -> none;
_ -> some
end;
false ->
none
end;
_ ->
some
end.
sets_bare_member({U, S, <<"">>} = LBJID, Set) -> sets_bare_member({U, S, <<"">>} = LBJID, Set) ->
case ?SETS:next(sets_iterator_from(LBJID, Set)) of case ?SETS:next(sets_iterator_from(LBJID, Set)) of
{{U, S, _}, _} -> true; {{U, S, _}, _} -> true;
@ -151,4 +178,6 @@ mod_opt_type(log) ->
fun (B) when is_boolean(B) -> B end; fun (B) when is_boolean(B) -> B end;
mod_opt_type(allow_local_users) -> mod_opt_type(allow_local_users) ->
fun (B) when is_boolean(B) -> B end; fun (B) when is_boolean(B) -> B end;
mod_opt_type(_) -> [drop, log, allow_local_users]. mod_opt_type(allow_transports) ->
fun (B) when is_boolean(B) -> B end;
mod_opt_type(_) -> [drop, log, allow_local_users, allow_transports].