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

* src/ejabberd_c2s.erl: Enforce privacy rules also for

subscription requests (EJAB-300)
* src/ejabberd_sm.erl: Likewise

SVN Revision: 1976
This commit is contained in:
Badlop 2009-03-07 08:59:26 +00:00
parent d6820f2c2d
commit 56c33e994d
3 changed files with 51 additions and 29 deletions

View File

@ -1,5 +1,9 @@
2009-03-07 Badlop <badlop@process-one.net>
* src/ejabberd_c2s.erl: Enforce privacy rules also for
subscription requests (EJAB-300)
* src/ejabberd_sm.erl: Likewise
* src/mod_privacy.erl: Temporary workaround to inconsistency
* src/mod_privacy_odbc.erl: Likewise

View File

@ -1039,13 +1039,22 @@ handle_info({route, From, To, Packet}, StateName, StateData) ->
'unavailable'),
{true, Attrs1, StateData};
'subscribe' ->
{true, Attrs, StateData};
Reason = exmpp_presence:get_status(Packet),
SRes = check_privacy_subs(in, subscribe, From, To,
Packet, Reason, StateData),
{SRes, Attrs, StateData};
'subscribed' ->
{true, Attrs, StateData};
SRes = check_privacy_subs(in, subscribed, From, To,
Packet, <<>>, StateData),
{SRes, Attrs, StateData};
'unsubscribe' ->
{true, Attrs, StateData};
SRes = check_privacy_subs(in, unsubscribe, From, To,
Packet, <<>>, StateData),
{SRes, Attrs, StateData};
'unsubscribed' ->
{true, Attrs, StateData};
SRes = check_privacy_subs(in, unsubscribed, From, To,
Packet, <<>>, StateData),
{SRes, Attrs, StateData};
_ ->
case ejabberd_hooks:run_fold(
privacy_check_packet, StateData#state.server,
@ -1571,6 +1580,36 @@ check_privacy_route(From, StateData, FromRoute, To, Packet) ->
ejabberd_router:route(FromRoute, To, Packet)
end.
%% Check privacy rules for subscription requests and call the roster storage
check_privacy_subs(Dir, Type, From, To, Packet, Reason, StateData) ->
case is_privacy_allow(From, To, Dir, Packet, StateData) of
true ->
ejabberd_hooks:run_fold(
roster_in_subscription,
exmpp_jid:ldomain(To),
false,
[exmpp_jid:lnode(To), exmpp_jid:ldomain(To), From, Type, Reason]),
true;
false ->
false
end.
%% Check if privacy rules allow this delivery, then push to roster
is_privacy_allow(From, To, Dir, Packet, StateData) ->
case ejabberd_hooks:run_fold(
privacy_check_packet, StateData#state.server,
allow,
[StateData#state.user,
StateData#state.server,
StateData#state.privacy_list,
{From, To, Packet},
Dir]) of
deny ->
false;
allow ->
true
end.
presence_broadcast(StateData, From, JIDSet, Packet) ->
lists:foreach(fun({U, S, R}) ->
FJID = exmpp_jid:make_jid(U, S, R),

View File

@ -422,34 +422,13 @@ do_route(From, To, Packet) ->
{Pass, _Subsc} =
case exmpp_presence:get_type(Packet) of
'subscribe' ->
Reason = exmpp_presence:get_status(Packet),
{ejabberd_hooks:run_fold(
roster_in_subscription,
exmpp_jid:ldomain(To),
false,
[exmpp_jid:lnode(To), exmpp_jid:ldomain(To), From, subscribe, Reason]),
true};
{true, true};
'subscribed' ->
{ejabberd_hooks:run_fold(
roster_in_subscription,
exmpp_jid:ldomain(To),
false,
[exmpp_jid:lnode(To), exmpp_jid:ldomain(To), From, subscribed, <<>>]),
true};
{true, true};
'unsubscribe' ->
{ejabberd_hooks:run_fold(
roster_in_subscription,
exmpp_jid:ldomain(To),
false,
[exmpp_jid:lnode(To), exmpp_jid:ldomain(To), From, unsubscribe, <<>>]),
true};
{true, true};
'unsubscribed' ->
{ejabberd_hooks:run_fold(
roster_in_subscription,
exmpp_jid:ldomain(To),
false,
[exmpp_jid:lnode(To), exmpp_jid:ldomain(To), From, unsubscribed, <<>>]),
true};
{true, true};
_ ->
{true, false}
end,