diff options
author | Evgeniy Khramtsov <ekhramtsov@process-one.net> | 2017-01-09 17:02:17 +0300 |
---|---|---|
committer | Evgeniy Khramtsov <ekhramtsov@process-one.net> | 2017-01-09 17:02:17 +0300 |
commit | 1e55e018e534aa82541c5f460063a237192b768c (patch) | |
tree | 9584ed46fe2b18770343399254b0ba15ff591e51 /src/cyrsasl.erl | |
parent | Get rid of "jlib.hrl" header in some files (diff) |
Adopt remaining code to support new hooks
Diffstat (limited to 'src/cyrsasl.erl')
-rw-r--r-- | src/cyrsasl.erl | 73 |
1 files changed, 17 insertions, 56 deletions
diff --git a/src/cyrsasl.erl b/src/cyrsasl.erl index 1edf4467..5c7eb7ed 100644 --- a/src/cyrsasl.erl +++ b/src/cyrsasl.erl @@ -25,13 +25,11 @@ -module(cyrsasl). --behaviour(ejabberd_config). - -author('alexey@process-one.net'). -export([start/0, register_mechanism/3, listmech/1, server_new/7, server_start/3, server_step/2, - get_mech/1, format_error/2, opt_type/1]). + get_mech/1, format_error/2]). -include("ejabberd.hrl"). -include("logger.hrl"). @@ -113,15 +111,9 @@ format_error(Mech, Reason) -> PasswordType :: password_type()) -> any(). register_mechanism(Mechanism, Module, PasswordType) -> - case is_disabled(Mechanism) of - false -> - ets:insert(sasl_mechanism, - #sasl_mechanism{mechanism = Mechanism, module = Module, - password_type = PasswordType}); - true -> - ?DEBUG("SASL mechanism ~p is disabled", [Mechanism]), - true - end. + ets:insert(sasl_mechanism, + #sasl_mechanism{mechanism = Mechanism, module = Module, + password_type = PasswordType}). check_credentials(_State, Props) -> User = proplists:get_value(authzid, Props, <<>>), @@ -134,20 +126,19 @@ check_credentials(_State, Props) -> -spec listmech(Host ::binary()) -> Mechanisms::mechanisms(). listmech(Host) -> - Mechs = ets:select(sasl_mechanism, - [{#sasl_mechanism{mechanism = '$1', - password_type = '$2', _ = '_'}, - case catch ejabberd_auth:store_type(Host) of - external -> [{'==', '$2', plain}]; - scram -> [{'/=', '$2', digest}]; - {'EXIT', {undef, [{Module, store_type, []} | _]}} -> - ?WARNING_MSG("~p doesn't implement the function store_type/0", - [Module]), - []; - _Else -> [] - end, - ['$1']}]), - filter_anonymous(Host, Mechs). + ets:select(sasl_mechanism, + [{#sasl_mechanism{mechanism = '$1', + password_type = '$2', _ = '_'}, + case catch ejabberd_auth:store_type(Host) of + external -> [{'==', '$2', plain}]; + scram -> [{'/=', '$2', digest}]; + {'EXIT', {undef, [{Module, store_type, []} | _]}} -> + ?WARNING_MSG("~p doesn't implement the function store_type/0", + [Module]), + []; + _Else -> [] + end, + ['$1']}]). -spec server_new(binary(), binary(), binary(), term(), fun(), fun(), fun()) -> sasl_state(). @@ -206,33 +197,3 @@ server_step(State, ClientIn) -> -spec get_mech(sasl_state()) -> binary(). get_mech(#sasl_state{mech_name = Mech}) -> Mech. - -%% Remove the anonymous mechanism from the list if not enabled for the given -%% host -%% --spec filter_anonymous(Host :: binary(), Mechs :: mechanisms()) -> mechanisms(). - -filter_anonymous(Host, Mechs) -> - case ejabberd_auth_anonymous:is_sasl_anonymous_enabled(Host) of - true -> Mechs; - false -> Mechs -- [<<"ANONYMOUS">>] - end. - --spec is_disabled(Mechanism :: mechanism()) -> boolean(). - -is_disabled(Mechanism) -> - Disabled = ejabberd_config:get_option( - disable_sasl_mechanisms, - fun(V) when is_list(V) -> - lists:map(fun(M) -> str:to_upper(M) end, V); - (V) -> - [str:to_upper(V)] - end, []), - lists:member(Mechanism, Disabled). - -opt_type(disable_sasl_mechanisms) -> - fun (V) when is_list(V) -> - lists:map(fun (M) -> str:to_upper(M) end, V); - (V) -> [str:to_upper(V)] - end; -opt_type(_) -> [disable_sasl_mechanisms]. |