mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-24 16:23:40 +01:00
Improve access_commands option backward compatibility
This commit is contained in:
parent
1f2b7e8f20
commit
7c1e7e5b5f
@ -226,6 +226,7 @@
|
|||||||
-include("ejabberd.hrl").
|
-include("ejabberd.hrl").
|
||||||
-include("logger.hrl").
|
-include("logger.hrl").
|
||||||
|
|
||||||
|
-define(POLICY_ACCESS, '$policy').
|
||||||
|
|
||||||
init() ->
|
init() ->
|
||||||
ets:new(ejabberd_commands, [named_table, set, public,
|
ets:new(ejabberd_commands, [named_table, set, public,
|
||||||
@ -483,7 +484,7 @@ check_auth(_Command, {User, Server, Password, _}) when is_binary(Password) ->
|
|||||||
_ -> throw({error, invalid_account_data})
|
_ -> throw({error, invalid_account_data})
|
||||||
end.
|
end.
|
||||||
|
|
||||||
check_access(Command, all, _)
|
check_access(Command, ?POLICY_ACCESS, _)
|
||||||
when Command#ejabberd_commands.policy == open ->
|
when Command#ejabberd_commands.policy == open ->
|
||||||
true;
|
true;
|
||||||
check_access(_Command, _Access, admin) ->
|
check_access(_Command, _Access, admin) ->
|
||||||
@ -491,7 +492,7 @@ check_access(_Command, _Access, admin) ->
|
|||||||
check_access(_Command, _Access, {_User, _Server, _, true}) ->
|
check_access(_Command, _Access, {_User, _Server, _, true}) ->
|
||||||
false;
|
false;
|
||||||
check_access(Command, Access, Auth)
|
check_access(Command, Access, Auth)
|
||||||
when Access =/= all;
|
when Access =/= ?POLICY_ACCESS;
|
||||||
Command#ejabberd_commands.policy == open;
|
Command#ejabberd_commands.policy == open;
|
||||||
Command#ejabberd_commands.policy == user ->
|
Command#ejabberd_commands.policy == user ->
|
||||||
case check_auth(Command, Auth) of
|
case check_auth(Command, Auth) of
|
||||||
@ -503,6 +504,8 @@ check_access(Command, Access, Auth)
|
|||||||
check_access(_Command, _Access, _Auth) ->
|
check_access(_Command, _Access, _Auth) ->
|
||||||
false.
|
false.
|
||||||
|
|
||||||
|
check_access2(?POLICY_ACCESS, _User, _Server) ->
|
||||||
|
true;
|
||||||
check_access2(Access, User, Server) ->
|
check_access2(Access, User, Server) ->
|
||||||
%% Check this user has access permission
|
%% Check this user has access permission
|
||||||
case acl:match_rule(Server, Access, jlib:make_jid(User, Server, <<"">>)) of
|
case acl:match_rule(Server, Access, jlib:make_jid(User, Server, <<"">>)) of
|
||||||
@ -536,9 +539,11 @@ tag_arguments(ArgsDefs, Args) ->
|
|||||||
Args).
|
Args).
|
||||||
|
|
||||||
|
|
||||||
|
get_access_commands(unrestricted) ->
|
||||||
|
[];
|
||||||
get_access_commands(undefined) ->
|
get_access_commands(undefined) ->
|
||||||
Cmds = get_commands(),
|
Cmds = get_commands(),
|
||||||
[{all, Cmds, []}];
|
[{?POLICY_ACCESS, Cmds, []}];
|
||||||
get_access_commands(AccessCommands) ->
|
get_access_commands(AccessCommands) ->
|
||||||
AccessCommands.
|
AccessCommands.
|
||||||
|
|
||||||
|
@ -197,11 +197,14 @@ socket_type() -> raw.
|
|||||||
%% -----------------------------
|
%% -----------------------------
|
||||||
process(_, #request{method = 'POST', data = Data, opts = Opts}) ->
|
process(_, #request{method = 'POST', data = Data, opts = Opts}) ->
|
||||||
AccessCommandsOpts = gen_mod:get_opt(access_commands, Opts,
|
AccessCommandsOpts = gen_mod:get_opt(access_commands, Opts,
|
||||||
fun(L) when is_list(L) -> L end,
|
fun(L) when is_list(L) -> L;
|
||||||
|
(unrestricted) -> unrestricted
|
||||||
|
end,
|
||||||
undefined),
|
undefined),
|
||||||
AccessCommands =
|
AccessCommands =
|
||||||
case AccessCommandsOpts of
|
case AccessCommandsOpts of
|
||||||
undefined -> undefined;
|
undefined -> undefined;
|
||||||
|
unrestricted -> unrestricted;
|
||||||
_ ->
|
_ ->
|
||||||
lists:flatmap(
|
lists:flatmap(
|
||||||
fun({Ac, AcOpts}) ->
|
fun({Ac, AcOpts}) ->
|
||||||
@ -537,6 +540,8 @@ make_status(false) -> 1;
|
|||||||
make_status(error) -> 1;
|
make_status(error) -> 1;
|
||||||
make_status(_) -> 1.
|
make_status(_) -> 1.
|
||||||
|
|
||||||
|
transform_listen_option({access_commands, unrestricted} = Opt, Opts) ->
|
||||||
|
[Opt | Opts];
|
||||||
transform_listen_option({access_commands, ACOpts}, Opts) ->
|
transform_listen_option({access_commands, ACOpts}, Opts) ->
|
||||||
NewACOpts = lists:map(
|
NewACOpts = lists:map(
|
||||||
fun({AName, ACmds, AOpts}) ->
|
fun({AName, ACmds, AOpts}) ->
|
||||||
|
Loading…
Reference in New Issue
Block a user