mirror of
https://github.com/processone/ejabberd.git
synced 2024-12-02 16:37:52 +01:00
fix owners cache and fix unsubscribe permissions (EJAB-840)
SVN Revision: 1798
This commit is contained in:
parent
6e04bcbbf8
commit
da893f4293
@ -1,3 +1,9 @@
|
|||||||
|
2009-01-11 Christophe Romain <christophe.romain@process-one.net>
|
||||||
|
|
||||||
|
* src/mod_pubsub/mod_pubsub.erl: fix owners cache and fix unsubscribe
|
||||||
|
permissions (thanks to Andy Skelton)(EJAB-840)
|
||||||
|
* src/mod_pubsub/node_default.erl: Likewise
|
||||||
|
|
||||||
2009-01-10 Christophe Romain <christophe.romain@process-one.net>
|
2009-01-10 Christophe Romain <christophe.romain@process-one.net>
|
||||||
|
|
||||||
* src/mod_pubsub/node_default.erl: fix unsubscription of full jid
|
* src/mod_pubsub/node_default.erl: fix unsubscription of full jid
|
||||||
|
@ -1875,19 +1875,34 @@ set_affiliations(Host, Node, From, EntitiesEls) ->
|
|||||||
error ->
|
error ->
|
||||||
{error, ?ERR_BAD_REQUEST};
|
{error, ?ERR_BAD_REQUEST};
|
||||||
_ ->
|
_ ->
|
||||||
Action = fun(#pubsub_node{type = Type, owners = Owners}) ->
|
Action = fun(#pubsub_node{type = Type, owners = Owners}=N) ->
|
||||||
case lists:member(Owner, Owners) of
|
case lists:member(Owner, Owners) of
|
||||||
true ->
|
true ->
|
||||||
lists:foreach(
|
lists:foreach(
|
||||||
fun({JID, Affiliation}) ->
|
fun({JID, Affiliation}) ->
|
||||||
node_call(
|
node_call(Type, set_affiliation, [Host, Node, JID, Affiliation]),
|
||||||
Type, set_affiliation,
|
case Affiliation of
|
||||||
[Host, Node, JID, Affiliation])
|
owner ->
|
||||||
end, Entities),
|
NewOwner = jlib:jid_tolower(jlib:jid_remove_resource(JID)),
|
||||||
{result, []};
|
NewOwners = [NewOwner|Owners],
|
||||||
_ ->
|
tree_call(Host, set_node, [N#pubsub_node{owners = NewOwners}]);
|
||||||
{error, ?ERR_FORBIDDEN}
|
none ->
|
||||||
end
|
OldOwner = jlib:jid_tolower(jlib:jid_remove_resource(JID)),
|
||||||
|
case lists:member(OldOwner, Owners) of
|
||||||
|
true ->
|
||||||
|
NewOwners = Owners--[OldOwner],
|
||||||
|
tree_call(Host, set_node, [N#pubsub_node{owners = NewOwners}]);
|
||||||
|
_ ->
|
||||||
|
ok
|
||||||
|
end;
|
||||||
|
_ ->
|
||||||
|
ok
|
||||||
|
end
|
||||||
|
end, Entities),
|
||||||
|
{result, []};
|
||||||
|
_ ->
|
||||||
|
{error, ?ERR_FORBIDDEN}
|
||||||
|
end
|
||||||
end,
|
end,
|
||||||
transaction(Host, Node, Action, sync_dirty)
|
transaction(Host, Node, Action, sync_dirty)
|
||||||
end.
|
end.
|
||||||
|
@ -275,22 +275,27 @@ subscribe_node(Host, Node, Sender, Subscriber, AccessModel,
|
|||||||
SendLast, PresenceSubscription, RosterGroup) ->
|
SendLast, PresenceSubscription, RosterGroup) ->
|
||||||
SubKey = jlib:jid_tolower(Subscriber),
|
SubKey = jlib:jid_tolower(Subscriber),
|
||||||
GenKey = jlib:jid_remove_resource(SubKey),
|
GenKey = jlib:jid_remove_resource(SubKey),
|
||||||
Authorized = (jlib:jid_tolower(jlib:jid_remove_resource(Sender)) == GenKey),
|
SenderKey = jlib:jid_tolower(jlib:jid_remove_resource(Sender)),
|
||||||
GenState = get_state(Host, Node, GenKey),
|
GenState = get_state(Host, Node, GenKey),
|
||||||
SubState = case SubKey of
|
SubState = case SubKey of
|
||||||
GenKey -> GenState;
|
GenKey -> GenState;
|
||||||
_ -> get_state(Host, Node, SubKey)
|
_ -> get_state(Host, Node, SubKey)
|
||||||
end,
|
end,
|
||||||
Affiliation = GenState#pubsub_state.affiliation,
|
Authorized = case SenderKey of
|
||||||
Subscription = SubState#pubsub_state.subscription,
|
GenKey ->
|
||||||
|
true;
|
||||||
|
_ ->
|
||||||
|
SenderState = get_state(Host, Node, SenderKey),
|
||||||
|
SenderState#pubsub_state.affiliation == owner
|
||||||
|
end,
|
||||||
if
|
if
|
||||||
not Authorized ->
|
not Authorized ->
|
||||||
%% JIDs do not match
|
%% JIDs do not match
|
||||||
{error, ?ERR_EXTENDED(?ERR_BAD_REQUEST, "invalid-jid")};
|
{error, ?ERR_EXTENDED(?ERR_BAD_REQUEST, "invalid-jid")};
|
||||||
Affiliation == outcast ->
|
GenState#pubsub_state.affiliation == outcast ->
|
||||||
%% Requesting entity is blocked
|
%% Requesting entity is blocked
|
||||||
{error, ?ERR_FORBIDDEN};
|
{error, ?ERR_FORBIDDEN};
|
||||||
Subscription == pending ->
|
SubState#pubsub_state.subscription == pending ->
|
||||||
%% Requesting entity has pending subscription
|
%% Requesting entity has pending subscription
|
||||||
{error, ?ERR_EXTENDED(?ERR_NOT_AUTHORIZED, "pending-subscription")};
|
{error, ?ERR_EXTENDED(?ERR_NOT_AUTHORIZED, "pending-subscription")};
|
||||||
(AccessModel == presence) and (not PresenceSubscription) ->
|
(AccessModel == presence) and (not PresenceSubscription) ->
|
||||||
@ -345,14 +350,19 @@ subscribe_node(Host, Node, Sender, Subscriber, AccessModel,
|
|||||||
unsubscribe_node(Host, Node, Sender, Subscriber, _SubId) ->
|
unsubscribe_node(Host, Node, Sender, Subscriber, _SubId) ->
|
||||||
SubKey = jlib:jid_tolower(Subscriber),
|
SubKey = jlib:jid_tolower(Subscriber),
|
||||||
GenKey = jlib:jid_remove_resource(SubKey),
|
GenKey = jlib:jid_remove_resource(SubKey),
|
||||||
Authorized = (jlib:jid_tolower(jlib:jid_remove_resource(Sender)) == GenKey),
|
SenderKey = jlib:jid_tolower(jlib:jid_remove_resource(Sender)),
|
||||||
GenState = get_state(Host, Node, GenKey),
|
GenState = get_state(Host, Node, GenKey),
|
||||||
SubState = case SubKey of
|
SubState = case SubKey of
|
||||||
GenKey -> GenState;
|
GenKey -> GenState;
|
||||||
_ -> get_state(Host, Node, SubKey)
|
_ -> get_state(Host, Node, SubKey)
|
||||||
end,
|
end,
|
||||||
Affiliation = GenState#pubsub_state.affiliation,
|
Authorized = case SenderKey of
|
||||||
Subscription = SubState#pubsub_state.subscription,
|
GenKey ->
|
||||||
|
true;
|
||||||
|
_ ->
|
||||||
|
SenderState = get_state(Host, Node, SenderKey),
|
||||||
|
SenderState#pubsub_state.affiliation == owner
|
||||||
|
end,
|
||||||
if
|
if
|
||||||
%% Entity did not specify SubID
|
%% Entity did not specify SubID
|
||||||
%%SubID == "", ?? ->
|
%%SubID == "", ?? ->
|
||||||
@ -361,10 +371,10 @@ unsubscribe_node(Host, Node, Sender, Subscriber, _SubId) ->
|
|||||||
%%InvalidSubID ->
|
%%InvalidSubID ->
|
||||||
%% {error, ?ERR_EXTENDED(?ERR_NOT_ACCEPTABLE, "invalid-subid")};
|
%% {error, ?ERR_EXTENDED(?ERR_NOT_ACCEPTABLE, "invalid-subid")};
|
||||||
%% Requesting entity is not a subscriber
|
%% Requesting entity is not a subscriber
|
||||||
Subscription == none ->
|
SubState#pubsub_state.subscription == none ->
|
||||||
{error, ?ERR_EXTENDED(?ERR_UNEXPECTED_REQUEST, "not-subscribed")};
|
{error, ?ERR_EXTENDED(?ERR_UNEXPECTED_REQUEST, "not-subscribed")};
|
||||||
%% Requesting entity is prohibited from unsubscribing entity
|
%% Requesting entity is prohibited from unsubscribing entity
|
||||||
(not Authorized) and (Affiliation =/= owner) ->
|
not Authorized ->
|
||||||
{error, ?ERR_FORBIDDEN};
|
{error, ?ERR_FORBIDDEN};
|
||||||
%% Was just subscriber, remove the record
|
%% Was just subscriber, remove the record
|
||||||
SubState#pubsub_state.affiliation == none ->
|
SubState#pubsub_state.affiliation == none ->
|
||||||
@ -576,7 +586,12 @@ set_affiliation(Host, Node, Owner, Affiliation) ->
|
|||||||
SubKey = jlib:jid_tolower(Owner),
|
SubKey = jlib:jid_tolower(Owner),
|
||||||
GenKey = jlib:jid_remove_resource(SubKey),
|
GenKey = jlib:jid_remove_resource(SubKey),
|
||||||
GenState = get_state(Host, Node, GenKey),
|
GenState = get_state(Host, Node, GenKey),
|
||||||
set_state(GenState#pubsub_state{affiliation = Affiliation}),
|
case {Affiliation, GenState#pubsub_state.subscription} of
|
||||||
|
{none, none} ->
|
||||||
|
del_state(GenState#pubsub_state.stateid);
|
||||||
|
_ ->
|
||||||
|
set_state(GenState#pubsub_state{affiliation = Affiliation})
|
||||||
|
end,
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
%% @spec (Host, Ownner) -> [{Node,Subscription}]
|
%% @spec (Host, Ownner) -> [{Node,Subscription}]
|
||||||
@ -619,7 +634,12 @@ get_subscription(Host, Node, Owner) ->
|
|||||||
set_subscription(Host, Node, Owner, Subscription) ->
|
set_subscription(Host, Node, Owner, Subscription) ->
|
||||||
SubKey = jlib:jid_tolower(Owner),
|
SubKey = jlib:jid_tolower(Owner),
|
||||||
SubState = get_state(Host, Node, SubKey),
|
SubState = get_state(Host, Node, SubKey),
|
||||||
set_state(SubState#pubsub_state{subscription = Subscription}),
|
case {Subscription, SubState#pubsub_state.affiliation} of
|
||||||
|
{none, none} ->
|
||||||
|
del_state(SubState#pubsub_state.stateid);
|
||||||
|
_ ->
|
||||||
|
set_state(SubState#pubsub_state{subscription = Subscription})
|
||||||
|
end,
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
%% @spec (Host, Node) -> [States] | []
|
%% @spec (Host, Node) -> [States] | []
|
||||||
@ -690,7 +710,6 @@ get_items(Host, Node, JID, AccessModel, PresenceSubscription, RosterGroup, _SubI
|
|||||||
SubKey = jlib:jid_tolower(JID),
|
SubKey = jlib:jid_tolower(JID),
|
||||||
GenKey = jlib:jid_remove_resource(SubKey),
|
GenKey = jlib:jid_remove_resource(SubKey),
|
||||||
GenState = get_state(Host, Node, GenKey),
|
GenState = get_state(Host, Node, GenKey),
|
||||||
Affiliation = GenState#pubsub_state.affiliation,
|
|
||||||
if
|
if
|
||||||
%%SubID == "", ?? ->
|
%%SubID == "", ?? ->
|
||||||
%% Entity has multiple subscriptions to the node but does not specify a subscription ID
|
%% Entity has multiple subscriptions to the node but does not specify a subscription ID
|
||||||
@ -698,7 +717,7 @@ get_items(Host, Node, JID, AccessModel, PresenceSubscription, RosterGroup, _SubI
|
|||||||
%%InvalidSubID ->
|
%%InvalidSubID ->
|
||||||
%% Entity is subscribed but specifies an invalid subscription ID
|
%% Entity is subscribed but specifies an invalid subscription ID
|
||||||
%{error, ?ERR_EXTENDED(?ERR_NOT_ACCEPTABLE, "invalid-subid")};
|
%{error, ?ERR_EXTENDED(?ERR_NOT_ACCEPTABLE, "invalid-subid")};
|
||||||
Affiliation == outcast ->
|
GenState#pubsub_state.affiliation == outcast ->
|
||||||
%% Requesting entity is blocked
|
%% Requesting entity is blocked
|
||||||
{error, ?ERR_FORBIDDEN};
|
{error, ?ERR_FORBIDDEN};
|
||||||
(AccessModel == presence) and (not PresenceSubscription) ->
|
(AccessModel == presence) and (not PresenceSubscription) ->
|
||||||
@ -737,7 +756,6 @@ get_item(Host, Node, ItemId, JID, AccessModel, PresenceSubscription, RosterGroup
|
|||||||
SubKey = jlib:jid_tolower(JID),
|
SubKey = jlib:jid_tolower(JID),
|
||||||
GenKey = jlib:jid_remove_resource(SubKey),
|
GenKey = jlib:jid_remove_resource(SubKey),
|
||||||
GenState = get_state(Host, Node, GenKey),
|
GenState = get_state(Host, Node, GenKey),
|
||||||
Affiliation = GenState#pubsub_state.affiliation,
|
|
||||||
if
|
if
|
||||||
%%SubID == "", ?? ->
|
%%SubID == "", ?? ->
|
||||||
%% Entity has multiple subscriptions to the node but does not specify a subscription ID
|
%% Entity has multiple subscriptions to the node but does not specify a subscription ID
|
||||||
@ -745,7 +763,7 @@ get_item(Host, Node, ItemId, JID, AccessModel, PresenceSubscription, RosterGroup
|
|||||||
%%InvalidSubID ->
|
%%InvalidSubID ->
|
||||||
%% Entity is subscribed but specifies an invalid subscription ID
|
%% Entity is subscribed but specifies an invalid subscription ID
|
||||||
%{error, ?ERR_EXTENDED(?ERR_NOT_ACCEPTABLE, "invalid-subid")};
|
%{error, ?ERR_EXTENDED(?ERR_NOT_ACCEPTABLE, "invalid-subid")};
|
||||||
Affiliation == outcast ->
|
GenState#pubsub_state.affiliation == outcast ->
|
||||||
%% Requesting entity is blocked
|
%% Requesting entity is blocked
|
||||||
{error, ?ERR_FORBIDDEN};
|
{error, ?ERR_FORBIDDEN};
|
||||||
(AccessModel == presence) and (not PresenceSubscription) ->
|
(AccessModel == presence) and (not PresenceSubscription) ->
|
||||||
|
Loading…
Reference in New Issue
Block a user