]> granicus.if.org Git - ejabberd/commitdiff
Make sure that api_permissions always have "console commands" section
authorPaweł Chmielowski <pchmielowski@process-one.net>
Fri, 3 Feb 2017 14:22:35 +0000 (15:22 +0100)
committerPaweł Chmielowski <pchmielowski@process-one.net>
Fri, 3 Feb 2017 14:22:35 +0000 (15:22 +0100)
If user didn't override it in config file, default version which allows
executing all commands will be added

src/ejabberd_access_permissions.erl

index 83defb13ef726a23fece21cb57cb6ede425a1f12..260176130cea93bca3b8da1daaf7e51a37f71f75 100644 (file)
@@ -230,31 +230,34 @@ code_change(_OldVsn, State, _Extra) ->
 %%%===================================================================
 
 -spec get_definitions(#state{}) -> {#state{}, any()}.
-get_definitions(#state{definitions = Defs, fragments_generators = Gens} = State) ->
-    DefaultOptions = [{<<"console commands">>,
-                      {[ejabberd_ctl],
-                       [{acl, all}],
-                       {all, none}}},
-                     {<<"admin access">>,
+get_definitions(#state{definitions = Defs} = State) when Defs /= none ->
+    {State, Defs};
+get_definitions(#state{definitions = none, fragments_generators = Gens} = State) ->
+    DefaultOptions = [{<<"admin access">>,
                       {[],
                        [{acl,{acl,admin}},
                         {oauth,[<<"ejabberd:admin">>],[{acl,{acl,admin}}]}],
                        {all, [start, stop]}}}],
-    NDefs = case Defs of
-               none ->
-                   ApiPerms = ejabberd_config:get_option(api_permissions, fun(A) -> A end, DefaultOptions),
-                   AllCommands = ejabberd_commands:get_commands_definition(),
-                   Frags = lists:foldl(
-                       fun({_Name, Generator}, Acc) ->
-                           Acc ++ Generator()
-                       end, [], Gens),
-                   lists:map(
-                       fun({Name, {From, Who, {Add, Del}}}) ->
-                           Cmds = filter_commands_with_permissions(AllCommands, Add, Del),
-                           {Name, {From, Who, Cmds}}
-                       end, ApiPerms ++ Frags);
-               V ->
-                   V
+    ApiPerms = ejabberd_config:get_option(api_permissions, fun(A) -> A end,
+                                         DefaultOptions),
+    AllCommands = ejabberd_commands:get_commands_definition(),
+    Frags = lists:foldl(
+             fun({_Name, Generator}, Acc) ->
+                     Acc ++ Generator()
+             end, [], Gens),
+    NDefs0 = lists:map(
+              fun({Name, {From, Who, {Add, Del}}}) ->
+                      Cmds = filter_commands_with_permissions(AllCommands, Add, Del),
+                      {Name, {From, Who, Cmds}}
+              end, ApiPerms ++ Frags),
+    NDefs = case lists:keyfind(<<"console commands">>, 1, NDefs0) of
+               false ->
+                   [{<<"console commands">>,
+                     {[ejabberd_ctl],
+                      [{acl, all}],
+                      filter_commands_with_permissions(AllCommands, all, none)}} | NDefs0];
+               _ ->
+                   NDefs0
            end,
     {State#state{definitions = NDefs}, NDefs}.