Skip to content

Commit

Permalink
Handle user and 'all' sources which overlap
Browse files Browse the repository at this point in the history
  • Loading branch information
Vagabond committed Jan 2, 2014
1 parent 699324c commit 8be51c2
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/riak_core_security.erl
Expand Up @@ -860,8 +860,21 @@ group_sources(Sources) ->
end, dict:new(), Sources), end, dict:new(), Sources),
R1 = [{Users, CIDR, Source, Options} || {{CIDR, Source, Options}, Users} <- R1 = [{Users, CIDR, Source, Options} || {{CIDR, Source, Options}, Users} <-
dict:to_list(D)], dict:to_list(D)],
%% Split any entries where the user list contains 'all' so that 'all' has
%% its own entry. We could actually elide any user sources that overlap
%% with an 'all' source, but that may be more confusing because deleting
%% the all source would then 'ressurrect' the user sources.
R2 = lists:foldl(fun({Users, CIDR, Source, Options}=E, Acc) ->
case lists:member(all, Users) of
true ->
[{[all], CIDR, Source, Options},
{Users -- [all], CIDR, Source, Options}|Acc];
false ->
[E|Acc]
end
end, [], R1),
%% sort the result by the same criteria that sort_sources uses %% sort the result by the same criteria that sort_sources uses
R2 = lists:sort(fun({UserA, _, _, _}, {UserB, _, _, _}) -> R3 = lists:sort(fun({UserA, _, _, _}, {UserB, _, _, _}) ->
case {UserA, UserB} of case {UserA, UserB} of
{[all], [all]} -> {[all], [all]} ->
true; true;
Expand All @@ -873,10 +886,10 @@ group_sources(Sources) ->
{_, _} -> {_, _} ->
true true
end end
end, R1), end, R2),
lists:sort(fun({_, {_, MaskA}, _, _}, {_, {_, MaskB}, _, _}) -> lists:sort(fun({_, {_, MaskA}, _, _}, {_, {_, MaskB}, _, _}) ->
MaskA > MaskB MaskA > MaskB
end, R2). end, R3).


group_grants(Grants) -> group_grants(Grants) ->
D = lists:foldl(fun({{_User, Bucket}, G}, Acc) -> D = lists:foldl(fun({{_User, Bucket}, G}, Acc) ->
Expand Down

0 comments on commit 8be51c2

Please sign in to comment.