2002-11-23 21:55:05 +01:00
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
%%% File : ejabberd_auth.erl
|
2007-12-24 12:41:41 +01:00
|
|
|
%%% Author : Alexey Shchepin <alexey@process-one.net>
|
2004-12-12 22:00:34 +01:00
|
|
|
%%% Purpose : Authentification
|
2007-12-24 12:41:41 +01:00
|
|
|
%%% Created : 23 Nov 2002 by Alexey Shchepin <alexey@process-one.net>
|
|
|
|
%%%
|
|
|
|
%%%
|
2017-01-02 21:41:53 +01:00
|
|
|
%%% ejabberd, Copyright (C) 2002-2017 ProcessOne
|
2007-12-24 12:41:41 +01:00
|
|
|
%%%
|
|
|
|
%%% This program is free software; you can redistribute it and/or
|
|
|
|
%%% modify it under the terms of the GNU General Public License as
|
|
|
|
%%% published by the Free Software Foundation; either version 2 of the
|
|
|
|
%%% License, or (at your option) any later version.
|
|
|
|
%%%
|
|
|
|
%%% This program is distributed in the hope that it will be useful,
|
|
|
|
%%% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
%%% General Public License for more details.
|
2009-01-12 15:44:42 +01:00
|
|
|
%%%
|
2014-02-22 11:27:40 +01:00
|
|
|
%%% You should have received a copy of the GNU General Public License along
|
|
|
|
%%% with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
%%% 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2007-12-24 12:41:41 +01:00
|
|
|
%%%
|
2002-11-23 21:55:05 +01:00
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
-module(ejabberd_auth).
|
2013-03-14 10:33:02 +01:00
|
|
|
|
2017-02-24 10:05:47 +01:00
|
|
|
-behaviour(gen_server).
|
2015-06-01 14:38:27 +02:00
|
|
|
-behaviour(ejabberd_config).
|
|
|
|
|
2007-12-24 12:41:41 +01:00
|
|
|
-author('alexey@process-one.net').
|
2002-11-23 21:55:05 +01:00
|
|
|
|
|
|
|
%% External exports
|
2017-02-24 12:06:47 +01:00
|
|
|
-export([start_link/0, host_up/1, host_down/1, config_reloaded/0,
|
|
|
|
set_password/3, check_password/4,
|
2015-04-09 03:21:09 +02:00
|
|
|
check_password/6, check_password_with_authmodule/4,
|
|
|
|
check_password_with_authmodule/6, try_register/3,
|
2017-05-11 13:37:21 +02:00
|
|
|
get_users/0, get_users/1, password_to_scram/1,
|
|
|
|
get_users/2, export/1, import_info/0,
|
|
|
|
count_users/1, import/5, import_start/2,
|
|
|
|
count_users/2, get_password/2,
|
2013-03-14 10:33:02 +01:00
|
|
|
get_password_s/2, get_password_with_authmodule/2,
|
2017-05-11 14:49:06 +02:00
|
|
|
user_exists/2, user_exists_in_other_modules/3,
|
2013-03-14 10:33:02 +01:00
|
|
|
remove_user/2, remove_user/3, plain_password_required/1,
|
2017-04-28 12:23:32 +02:00
|
|
|
store_type/1, entropy/1, backend_type/1, password_format/1]).
|
2017-02-24 10:05:47 +01:00
|
|
|
%% gen_server callbacks
|
|
|
|
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
|
|
|
|
terminate/2, code_change/3]).
|
2002-11-23 21:55:05 +01:00
|
|
|
|
2015-06-01 14:38:27 +02:00
|
|
|
-export([auth_modules/1, opt_type/1]).
|
2006-04-07 02:39:24 +02:00
|
|
|
|
2005-04-20 01:10:22 +02:00
|
|
|
-include("ejabberd.hrl").
|
2013-04-08 11:12:54 +02:00
|
|
|
-include("logger.hrl").
|
2005-04-20 01:10:22 +02:00
|
|
|
|
2017-05-11 13:37:21 +02:00
|
|
|
-define(AUTH_CACHE, auth_cache).
|
|
|
|
-define(SALT_LENGTH, 16).
|
|
|
|
|
2017-02-24 12:06:47 +01:00
|
|
|
-record(state, {host_modules = #{} :: map()}).
|
2017-02-24 10:05:47 +01:00
|
|
|
|
2017-05-11 13:37:21 +02:00
|
|
|
-type password() :: binary() | #scram{}.
|
|
|
|
-type digest_fun() :: fun((binary()) -> binary()).
|
2017-02-18 07:36:27 +01:00
|
|
|
-export_type([password/0]).
|
|
|
|
|
2002-11-23 21:55:05 +01:00
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
%%% API
|
|
|
|
%%%----------------------------------------------------------------------
|
2013-03-14 10:33:02 +01:00
|
|
|
-type opts() :: [{prefix, binary()} | {from, integer()} |
|
|
|
|
{to, integer()} | {limit, integer()} |
|
|
|
|
{offset, integer()}].
|
|
|
|
|
|
|
|
-callback start(binary()) -> any().
|
2017-02-23 14:19:22 +01:00
|
|
|
-callback stop(binary()) -> any().
|
2017-05-11 13:37:21 +02:00
|
|
|
-callback plain_password_required(binary()) -> boolean().
|
|
|
|
-callback store_type(binary()) -> plain | external | scram.
|
2013-03-14 10:33:02 +01:00
|
|
|
-callback set_password(binary(), binary(), binary()) -> ok | {error, atom()}.
|
2017-05-11 13:37:21 +02:00
|
|
|
-callback remove_user(binary(), binary()) -> ok | {error, any()}.
|
2017-05-11 14:49:06 +02:00
|
|
|
-callback user_exists(binary(), binary()) -> boolean() | {error, atom()}.
|
2015-04-09 03:21:09 +02:00
|
|
|
-callback check_password(binary(), binary(), binary(), binary()) -> boolean().
|
2017-05-11 13:37:21 +02:00
|
|
|
-callback try_register(binary(), binary(), password()) -> ok | {error, atom()}.
|
|
|
|
-callback get_users(binary(), opts()) -> [{binary(), binary()}].
|
|
|
|
-callback count_users(binary(), opts()) -> number().
|
|
|
|
-callback get_password(binary(), binary()) -> {ok, password()} | error.
|
|
|
|
-callback use_cache(binary()) -> boolean().
|
|
|
|
-callback cache_nodes(binary()) -> boolean().
|
|
|
|
|
|
|
|
-optional_callbacks([set_password/3,
|
|
|
|
remove_user/2,
|
2017-05-11 14:49:06 +02:00
|
|
|
user_exists/2,
|
2017-05-11 13:37:21 +02:00
|
|
|
check_password/4,
|
|
|
|
try_register/3,
|
|
|
|
get_users/2,
|
|
|
|
count_users/2,
|
|
|
|
get_password/2,
|
|
|
|
use_cache/1,
|
|
|
|
cache_nodes/1]).
|
2003-11-23 21:11:21 +01:00
|
|
|
|
2017-02-24 10:05:47 +01:00
|
|
|
-spec start_link() -> {ok, pid()} | {error, any()}.
|
|
|
|
start_link() ->
|
|
|
|
gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
|
|
|
|
|
|
|
|
init([]) ->
|
2017-02-24 12:06:47 +01:00
|
|
|
ejabberd_hooks:add(host_up, ?MODULE, host_up, 30),
|
|
|
|
ejabberd_hooks:add(host_down, ?MODULE, host_down, 80),
|
|
|
|
ejabberd_hooks:add(config_reloaded, ?MODULE, config_reloaded, 40),
|
|
|
|
HostModules = lists:foldl(
|
|
|
|
fun(Host, Acc) ->
|
|
|
|
Modules = auth_modules(Host),
|
2017-02-27 20:38:59 +01:00
|
|
|
maps:put(Host, Modules, Acc)
|
2017-02-24 12:06:47 +01:00
|
|
|
end, #{}, ?MYHOSTS),
|
2017-05-11 13:37:21 +02:00
|
|
|
lists:foreach(
|
|
|
|
fun({Host, Modules}) ->
|
|
|
|
start(Host, Modules)
|
|
|
|
end, maps:to_list(HostModules)),
|
|
|
|
init_cache(HostModules),
|
2017-02-24 12:06:47 +01:00
|
|
|
{ok, #state{host_modules = HostModules}}.
|
2017-02-24 10:05:47 +01:00
|
|
|
|
|
|
|
handle_call(_Request, _From, State) ->
|
|
|
|
Reply = ok,
|
|
|
|
{reply, Reply, State}.
|
|
|
|
|
2017-02-24 12:06:47 +01:00
|
|
|
handle_cast({host_up, Host}, #state{host_modules = HostModules} = State) ->
|
|
|
|
Modules = auth_modules(Host),
|
|
|
|
start(Host, Modules),
|
2017-02-27 20:38:59 +01:00
|
|
|
NewHostModules = maps:put(Host, Modules, HostModules),
|
2017-05-11 13:37:21 +02:00
|
|
|
init_cache(NewHostModules),
|
2017-02-24 12:06:47 +01:00
|
|
|
{noreply, State#state{host_modules = NewHostModules}};
|
|
|
|
handle_cast({host_down, Host}, #state{host_modules = HostModules} = State) ->
|
|
|
|
Modules = maps:get(Host, HostModules, []),
|
|
|
|
stop(Host, Modules),
|
|
|
|
NewHostModules = maps:remove(Host, HostModules),
|
2017-05-11 13:37:21 +02:00
|
|
|
init_cache(NewHostModules),
|
2017-02-24 12:06:47 +01:00
|
|
|
{noreply, State#state{host_modules = NewHostModules}};
|
|
|
|
handle_cast(config_reloaded, #state{host_modules = HostModules} = State) ->
|
|
|
|
NewHostModules = lists:foldl(
|
|
|
|
fun(Host, Acc) ->
|
|
|
|
OldModules = maps:get(Host, HostModules, []),
|
|
|
|
NewModules = auth_modules(Host),
|
|
|
|
start(Host, NewModules -- OldModules),
|
|
|
|
stop(Host, OldModules -- NewModules),
|
2017-02-27 20:38:59 +01:00
|
|
|
maps:put(Host, NewModules, Acc)
|
2017-02-24 12:06:47 +01:00
|
|
|
end, HostModules, ?MYHOSTS),
|
2017-05-11 13:37:21 +02:00
|
|
|
init_cache(NewHostModules),
|
2017-02-24 12:06:47 +01:00
|
|
|
{noreply, State#state{host_modules = NewHostModules}};
|
|
|
|
handle_cast(Msg, State) ->
|
|
|
|
?WARNING_MSG("unexpected cast: ~p", [Msg]),
|
2017-02-24 10:05:47 +01:00
|
|
|
{noreply, State}.
|
|
|
|
|
|
|
|
handle_info(_Info, State) ->
|
|
|
|
{noreply, State}.
|
|
|
|
|
2017-02-24 12:06:47 +01:00
|
|
|
terminate(_Reason, State) ->
|
2017-02-24 10:05:47 +01:00
|
|
|
ejabberd_hooks:delete(host_up, ?MODULE, start, 30),
|
|
|
|
ejabberd_hooks:delete(host_down, ?MODULE, stop, 80),
|
2017-02-24 12:06:47 +01:00
|
|
|
ejabberd_hooks:delete(config_reloaded, ?MODULE, config_reloaded, 40),
|
|
|
|
lists:foreach(
|
|
|
|
fun({Host, Modules}) ->
|
|
|
|
stop(Host, Modules)
|
|
|
|
end, maps:to_list(State#state.host_modules)).
|
2017-02-24 10:05:47 +01:00
|
|
|
|
|
|
|
code_change(_OldVsn, State, _Extra) ->
|
|
|
|
{ok, State}.
|
2017-02-23 14:19:22 +01:00
|
|
|
|
2017-02-24 12:06:47 +01:00
|
|
|
start(Host, Modules) ->
|
2017-02-23 14:19:22 +01:00
|
|
|
lists:foreach(fun(M) -> M:start(Host) end, Modules).
|
|
|
|
|
2017-02-24 12:06:47 +01:00
|
|
|
stop(Host, Modules) ->
|
|
|
|
lists:foreach(fun(M) -> M:stop(Host) end, Modules).
|
|
|
|
|
|
|
|
host_up(Host) ->
|
|
|
|
gen_server:cast(?MODULE, {host_up, Host}).
|
|
|
|
|
|
|
|
host_down(Host) ->
|
|
|
|
gen_server:cast(?MODULE, {host_down, Host}).
|
|
|
|
|
|
|
|
config_reloaded() ->
|
|
|
|
gen_server:cast(?MODULE, config_reloaded).
|
2013-03-14 10:33:02 +01:00
|
|
|
|
2017-05-11 13:37:21 +02:00
|
|
|
-spec plain_password_required(binary()) -> boolean().
|
2005-07-13 05:24:13 +02:00
|
|
|
plain_password_required(Server) ->
|
2017-05-11 13:37:21 +02:00
|
|
|
lists:any(fun (M) -> M:plain_password_required(Server) end,
|
2013-03-14 10:33:02 +01:00
|
|
|
auth_modules(Server)).
|
2003-11-23 21:11:21 +01:00
|
|
|
|
2017-05-11 13:37:21 +02:00
|
|
|
-spec store_type(binary()) -> plain | scram | external.
|
2011-08-16 00:26:49 +02:00
|
|
|
store_type(Server) ->
|
2017-05-11 13:37:21 +02:00
|
|
|
lists:foldl(
|
|
|
|
fun(_, external) -> external;
|
|
|
|
(M, scram) ->
|
|
|
|
case M:store_type(Server) of
|
|
|
|
external -> external;
|
|
|
|
_ -> scram
|
|
|
|
end;
|
|
|
|
(M, plain) ->
|
|
|
|
M:store_type(Server)
|
|
|
|
end, plain, auth_modules(Server)).
|
2013-03-14 10:33:02 +01:00
|
|
|
|
2015-04-09 03:21:09 +02:00
|
|
|
-spec check_password(binary(), binary(), binary(), binary()) -> boolean().
|
|
|
|
check_password(User, AuthzId, Server, Password) ->
|
2017-05-11 13:37:21 +02:00
|
|
|
check_password(User, AuthzId, Server, Password, <<"">>, undefined).
|
2002-11-23 21:55:05 +01:00
|
|
|
|
2015-04-09 03:21:09 +02:00
|
|
|
-spec check_password(binary(), binary(), binary(), binary(), binary(),
|
2017-05-11 13:37:21 +02:00
|
|
|
digest_fun() | undefined) -> boolean().
|
|
|
|
check_password(User, AuthzId, Server, Password, Digest, DigestGen) ->
|
|
|
|
case check_password_with_authmodule(
|
|
|
|
User, AuthzId, Server, Password, Digest, DigestGen) of
|
|
|
|
{true, _AuthModule} -> true;
|
|
|
|
false -> false
|
2009-03-04 19:34:02 +01:00
|
|
|
end.
|
2002-12-20 21:42:08 +01:00
|
|
|
|
2017-05-11 13:37:21 +02:00
|
|
|
-spec check_password_with_authmodule(binary(), binary(),
|
|
|
|
binary(), binary()) -> false | {true, atom()}.
|
|
|
|
check_password_with_authmodule(User, AuthzId, Server, Password) ->
|
|
|
|
check_password_with_authmodule(
|
|
|
|
User, AuthzId, Server, Password, <<"">>, undefined).
|
|
|
|
|
|
|
|
-spec check_password_with_authmodule(
|
|
|
|
binary(), binary(), binary(), binary(), binary(),
|
|
|
|
digest_fun() | undefined) -> false | {true, atom()}.
|
|
|
|
check_password_with_authmodule(User, AuthzId, Server, Password, Digest, DigestGen) ->
|
|
|
|
case validate_credentials(User, Server) of
|
|
|
|
{ok, LUser, LServer} ->
|
|
|
|
lists:foldl(
|
|
|
|
fun(Mod, false) ->
|
|
|
|
case db_check_password(
|
|
|
|
LUser, AuthzId, LServer, Password,
|
|
|
|
Digest, DigestGen, Mod) of
|
|
|
|
true -> {true, Mod};
|
|
|
|
false -> false
|
|
|
|
end;
|
|
|
|
(_, Acc) ->
|
|
|
|
Acc
|
|
|
|
end, false, auth_modules(LServer));
|
|
|
|
_ ->
|
|
|
|
false
|
2008-04-22 19:41:30 +02:00
|
|
|
end.
|
|
|
|
|
2017-05-11 13:37:21 +02:00
|
|
|
-spec set_password(binary(), binary(), password()) -> ok | {error, atom()}.
|
2005-04-17 20:08:34 +02:00
|
|
|
set_password(User, Server, Password) ->
|
2017-05-11 13:37:21 +02:00
|
|
|
case validate_credentials(User, Server, Password) of
|
|
|
|
{ok, LUser, LServer} ->
|
|
|
|
lists:foldl(
|
|
|
|
fun(M, {error, _}) ->
|
|
|
|
db_set_password(LUser, LServer, Password, M);
|
|
|
|
(_, ok) ->
|
|
|
|
ok
|
|
|
|
end, {error, not_allowed}, auth_modules(LServer));
|
|
|
|
Err ->
|
|
|
|
Err
|
|
|
|
end.
|
|
|
|
|
|
|
|
-spec try_register(binary(), binary(), password()) -> ok | {error, atom()}.
|
2005-04-17 20:08:34 +02:00
|
|
|
try_register(User, Server, Password) ->
|
2017-05-11 13:37:21 +02:00
|
|
|
case validate_credentials(User, Server, Password) of
|
|
|
|
{ok, LUser, LServer} ->
|
2017-05-11 14:49:06 +02:00
|
|
|
case user_exists(LUser, LServer) of
|
2017-05-11 13:37:21 +02:00
|
|
|
true ->
|
|
|
|
{error, exists};
|
|
|
|
false ->
|
|
|
|
case ejabberd_router:is_my_host(LServer) of
|
|
|
|
true ->
|
|
|
|
case lists:foldl(
|
|
|
|
fun(_, ok) ->
|
|
|
|
ok;
|
|
|
|
(Mod, _) ->
|
|
|
|
db_try_register(
|
2017-08-04 11:53:32 +02:00
|
|
|
LUser, LServer, Password, Mod)
|
2017-05-11 13:37:21 +02:00
|
|
|
end, {error, not_allowed},
|
|
|
|
auth_modules(LServer)) of
|
|
|
|
ok ->
|
|
|
|
ejabberd_hooks:run(
|
2017-08-04 11:53:32 +02:00
|
|
|
register_user, LServer, [LUser, LServer]);
|
2017-05-11 13:37:21 +02:00
|
|
|
{error, _} = Err ->
|
|
|
|
Err
|
|
|
|
end;
|
|
|
|
false ->
|
|
|
|
{error, not_allowed}
|
|
|
|
end
|
|
|
|
end;
|
|
|
|
Err ->
|
|
|
|
Err
|
2005-04-20 01:10:22 +02:00
|
|
|
end.
|
2002-12-14 21:07:26 +01:00
|
|
|
|
2017-05-11 13:37:21 +02:00
|
|
|
-spec get_users() -> [{binary(), binary()}].
|
|
|
|
get_users() ->
|
|
|
|
lists:flatmap(
|
|
|
|
fun({Host, Mod}) ->
|
|
|
|
db_get_users(Host, [], Mod)
|
|
|
|
end, auth_modules()).
|
|
|
|
|
|
|
|
-spec get_users(binary()) -> [{binary(), binary()}].
|
|
|
|
get_users(Server) ->
|
|
|
|
get_users(Server, []).
|
|
|
|
|
|
|
|
-spec get_users(binary(), opts()) -> [{binary(), binary()}].
|
|
|
|
get_users(Server, Opts) ->
|
|
|
|
case jid:nameprep(Server) of
|
|
|
|
error -> [];
|
|
|
|
LServer ->
|
|
|
|
lists:flatmap(
|
|
|
|
fun(M) -> db_get_users(LServer, Opts, M) end,
|
|
|
|
auth_modules(LServer))
|
|
|
|
end.
|
2013-03-14 10:33:02 +01:00
|
|
|
|
2017-05-11 13:37:21 +02:00
|
|
|
-spec count_users(binary()) -> non_neg_integer().
|
|
|
|
count_users(Server) ->
|
|
|
|
count_users(Server, []).
|
|
|
|
|
|
|
|
-spec count_users(binary(), opts()) -> non_neg_integer().
|
|
|
|
count_users(Server, Opts) ->
|
|
|
|
case jid:nameprep(Server) of
|
|
|
|
error -> 0;
|
|
|
|
LServer ->
|
|
|
|
lists:sum(
|
|
|
|
lists:map(
|
|
|
|
fun(M) -> db_count_users(LServer, Opts, M) end,
|
|
|
|
auth_modules(LServer)))
|
|
|
|
end.
|
2013-03-14 10:33:02 +01:00
|
|
|
|
2017-05-11 13:37:21 +02:00
|
|
|
-spec get_password(binary(), binary()) -> false | password().
|
2005-04-17 20:08:34 +02:00
|
|
|
get_password(User, Server) ->
|
2017-05-11 13:37:21 +02:00
|
|
|
case validate_credentials(User, Server) of
|
|
|
|
{ok, LUser, LServer} ->
|
|
|
|
case lists:foldl(
|
|
|
|
fun(M, error) -> db_get_password(LUser, LServer, M);
|
|
|
|
(_M, Acc) -> Acc
|
|
|
|
end, error, auth_modules(LServer)) of
|
|
|
|
{ok, Password} ->
|
|
|
|
Password;
|
|
|
|
error ->
|
|
|
|
false
|
|
|
|
end;
|
|
|
|
_ ->
|
|
|
|
false
|
|
|
|
end.
|
2013-03-14 10:33:02 +01:00
|
|
|
|
2017-02-18 07:36:27 +01:00
|
|
|
-spec get_password_s(binary(), binary()) -> password().
|
2005-04-17 20:08:34 +02:00
|
|
|
get_password_s(User, Server) ->
|
2006-04-07 02:39:24 +02:00
|
|
|
case get_password(User, Server) of
|
2013-03-14 10:33:02 +01:00
|
|
|
false -> <<"">>;
|
|
|
|
Password -> Password
|
2006-04-07 02:39:24 +02:00
|
|
|
end.
|
2003-01-26 21:16:53 +01:00
|
|
|
|
2017-02-18 07:36:27 +01:00
|
|
|
-spec get_password_with_authmodule(binary(), binary()) -> {false | password(), module()}.
|
2013-03-14 10:33:02 +01:00
|
|
|
get_password_with_authmodule(User, Server) ->
|
2017-05-11 13:37:21 +02:00
|
|
|
case validate_credentials(User, Server) of
|
|
|
|
{ok, LUser, LServer} ->
|
|
|
|
case lists:foldl(
|
|
|
|
fun(M, {error, _}) ->
|
|
|
|
{db_get_password(LUser, LServer, M), M};
|
|
|
|
(_M, Acc) ->
|
|
|
|
Acc
|
|
|
|
end, {error, undefined}, auth_modules(LServer)) of
|
|
|
|
{{ok, Password}, Module} ->
|
|
|
|
{Password, Module};
|
|
|
|
{error, Module} ->
|
|
|
|
{false, Module}
|
|
|
|
end;
|
|
|
|
_ ->
|
|
|
|
{false, undefined}
|
|
|
|
end.
|
2003-02-21 20:52:15 +01:00
|
|
|
|
2017-05-11 14:49:06 +02:00
|
|
|
-spec user_exists(binary(), binary()) -> boolean().
|
|
|
|
user_exists(_User, <<"">>) ->
|
2014-04-30 17:20:58 +02:00
|
|
|
false;
|
2017-05-11 14:49:06 +02:00
|
|
|
user_exists(User, Server) ->
|
2017-05-11 13:37:21 +02:00
|
|
|
case validate_credentials(User, Server) of
|
|
|
|
{ok, LUser, LServer} ->
|
|
|
|
lists:any(
|
|
|
|
fun(M) ->
|
2017-05-11 14:49:06 +02:00
|
|
|
case db_user_exists(LUser, LServer, M) of
|
2017-05-11 13:37:21 +02:00
|
|
|
{error, _} ->
|
|
|
|
false;
|
|
|
|
Else ->
|
|
|
|
Else
|
2013-03-14 10:33:02 +01:00
|
|
|
end
|
2017-05-11 13:37:21 +02:00
|
|
|
end, auth_modules(LServer));
|
|
|
|
_ ->
|
|
|
|
false
|
|
|
|
end.
|
2013-03-14 10:33:02 +01:00
|
|
|
|
2017-05-11 14:49:06 +02:00
|
|
|
-spec user_exists_in_other_modules(atom(), binary(), binary()) -> boolean() | maybe.
|
|
|
|
user_exists_in_other_modules(Module, User, Server) ->
|
|
|
|
user_exists_in_other_modules_loop(
|
2017-05-11 13:37:21 +02:00
|
|
|
auth_modules(Server) -- [Module], User, Server).
|
2013-03-14 10:33:02 +01:00
|
|
|
|
2017-05-11 14:49:06 +02:00
|
|
|
user_exists_in_other_modules_loop([], _User, _Server) ->
|
2009-03-04 19:34:02 +01:00
|
|
|
false;
|
2017-05-11 14:49:06 +02:00
|
|
|
user_exists_in_other_modules_loop([AuthModule | AuthModules], User, Server) ->
|
|
|
|
case db_user_exists(User, Server, AuthModule) of
|
2017-05-11 13:37:21 +02:00
|
|
|
true ->
|
|
|
|
true;
|
|
|
|
false ->
|
2017-05-11 14:49:06 +02:00
|
|
|
user_exists_in_other_modules_loop(AuthModules, User, Server);
|
2017-05-11 13:37:21 +02:00
|
|
|
{error, _} ->
|
|
|
|
maybe
|
2009-03-04 19:34:02 +01:00
|
|
|
end.
|
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
-spec remove_user(binary(), binary()) -> ok.
|
2005-04-17 20:08:34 +02:00
|
|
|
remove_user(User, Server) ->
|
2017-05-11 13:37:21 +02:00
|
|
|
case validate_credentials(User, Server) of
|
|
|
|
{ok, LUser, LServer} ->
|
|
|
|
lists:foreach(
|
|
|
|
fun(Mod) -> db_remove_user(LUser, LServer, Mod) end,
|
|
|
|
auth_modules(LServer)),
|
|
|
|
ejabberd_hooks:run(remove_user, LServer, [LUser, LServer]);
|
|
|
|
_Err ->
|
|
|
|
ok
|
|
|
|
end.
|
2013-03-14 10:33:02 +01:00
|
|
|
|
2017-05-11 13:37:21 +02:00
|
|
|
-spec remove_user(binary(), binary(), password()) -> ok | {error, atom()}.
|
2005-04-17 20:08:34 +02:00
|
|
|
remove_user(User, Server, Password) ->
|
2017-05-11 13:37:21 +02:00
|
|
|
case validate_credentials(User, Server, Password) of
|
|
|
|
{ok, LUser, LServer} ->
|
|
|
|
case lists:foldl(
|
|
|
|
fun (_, ok) ->
|
|
|
|
ok;
|
|
|
|
(Mod, _) ->
|
|
|
|
case db_check_password(
|
|
|
|
LUser, <<"">>, LServer, Password,
|
|
|
|
<<"">>, undefined, Mod) of
|
|
|
|
true ->
|
|
|
|
db_remove_user(LUser, LServer, Mod);
|
|
|
|
false ->
|
|
|
|
{error, not_allowed}
|
|
|
|
end
|
|
|
|
end, {error, not_allowed}, auth_modules(Server)) of
|
|
|
|
ok ->
|
|
|
|
ejabberd_hooks:run(
|
|
|
|
remove_user, LServer, [LUser, LServer]);
|
|
|
|
Err ->
|
|
|
|
Err
|
|
|
|
end;
|
|
|
|
Err ->
|
|
|
|
Err
|
|
|
|
end.
|
|
|
|
|
2010-10-24 09:17:30 +02:00
|
|
|
%% @doc Calculate informational entropy.
|
2017-05-11 13:37:21 +02:00
|
|
|
-spec entropy(iodata()) -> float().
|
2013-03-14 10:33:02 +01:00
|
|
|
entropy(B) ->
|
|
|
|
case binary_to_list(B) of
|
|
|
|
"" -> 0.0;
|
|
|
|
S ->
|
|
|
|
Set = lists:foldl(fun (C,
|
|
|
|
[Digit, Printable, LowLetter, HiLetter,
|
|
|
|
Other]) ->
|
|
|
|
if C >= $a, C =< $z ->
|
|
|
|
[Digit, Printable, 26, HiLetter,
|
|
|
|
Other];
|
|
|
|
C >= $0, C =< $9 ->
|
|
|
|
[9, Printable, LowLetter, HiLetter,
|
|
|
|
Other];
|
|
|
|
C >= $A, C =< $Z ->
|
|
|
|
[Digit, Printable, LowLetter, 26,
|
|
|
|
Other];
|
|
|
|
C >= 33, C =< 126 ->
|
|
|
|
[Digit, 33, LowLetter, HiLetter,
|
|
|
|
Other];
|
|
|
|
true ->
|
|
|
|
[Digit, Printable, LowLetter,
|
|
|
|
HiLetter, 128]
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
[0, 0, 0, 0, 0], S),
|
|
|
|
length(S) * math:log(lists:sum(Set)) / math:log(2)
|
2010-10-24 09:17:30 +02:00
|
|
|
end.
|
2006-02-20 05:07:42 +01:00
|
|
|
|
2016-12-28 07:47:11 +01:00
|
|
|
-spec backend_type(atom()) -> atom().
|
|
|
|
backend_type(Mod) ->
|
|
|
|
case atom_to_list(Mod) of
|
|
|
|
"ejabberd_auth_" ++ T -> list_to_atom(T);
|
|
|
|
_ -> Mod
|
|
|
|
end.
|
|
|
|
|
2017-05-11 13:37:21 +02:00
|
|
|
-spec password_format(binary() | global) -> plain | scram.
|
2017-04-28 12:23:32 +02:00
|
|
|
password_format(LServer) ->
|
2017-04-29 10:39:40 +02:00
|
|
|
ejabberd_config:get_option({auth_password_format, LServer}, plain).
|
2017-04-28 12:23:32 +02:00
|
|
|
|
2017-05-11 13:37:21 +02:00
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
%%% Backend calls
|
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
db_try_register(User, Server, Password, Mod) ->
|
|
|
|
case erlang:function_exported(Mod, try_register, 3) of
|
|
|
|
true ->
|
|
|
|
Password1 = case Mod:store_type(Server) of
|
|
|
|
scram -> password_to_scram(Password);
|
|
|
|
_ -> Password
|
|
|
|
end,
|
|
|
|
case use_cache(Mod, Server) of
|
|
|
|
true ->
|
|
|
|
case ets_cache:update(
|
|
|
|
?AUTH_CACHE, {User, Server}, {ok, Password},
|
|
|
|
fun() -> Mod:try_register(User, Server, Password1) end,
|
|
|
|
cache_nodes(Mod, Server)) of
|
|
|
|
{ok, _} -> ok;
|
|
|
|
{error, _} = Err -> Err
|
|
|
|
end;
|
|
|
|
false ->
|
|
|
|
Mod:try_register(User, Server, Password1)
|
|
|
|
end;
|
|
|
|
false ->
|
|
|
|
{error, not_allowed}
|
|
|
|
end.
|
|
|
|
|
|
|
|
db_set_password(User, Server, Password, Mod) ->
|
|
|
|
case erlang:function_exported(Mod, set_password, 3) of
|
|
|
|
true ->
|
|
|
|
Password1 = case Mod:store_type(Server) of
|
|
|
|
scram -> password_to_scram(Password);
|
|
|
|
_ -> Password
|
|
|
|
end,
|
|
|
|
case use_cache(Mod, Server) of
|
|
|
|
true ->
|
|
|
|
case ets_cache:update(
|
|
|
|
?AUTH_CACHE, {User, Server}, {ok, Password},
|
|
|
|
fun() -> Mod:set_password(User, Server, Password1) end,
|
|
|
|
cache_nodes(Mod, Server)) of
|
|
|
|
{ok, _} -> ok;
|
|
|
|
{error, _} = Err -> Err
|
|
|
|
end;
|
|
|
|
false ->
|
|
|
|
Mod:set_password(User, Server, Password1)
|
|
|
|
end;
|
|
|
|
false ->
|
|
|
|
{error, not_allowed}
|
|
|
|
end.
|
|
|
|
|
|
|
|
db_get_password(User, Server, Mod) ->
|
|
|
|
UseCache = use_cache(Mod, Server),
|
|
|
|
case erlang:function_exported(Mod, get_password, 2) of
|
|
|
|
false when UseCache ->
|
|
|
|
ets_cache:lookup(?AUTH_CACHE, {User, Server});
|
|
|
|
false ->
|
|
|
|
error;
|
|
|
|
true when UseCache ->
|
|
|
|
ets_cache:lookup(
|
|
|
|
?AUTH_CACHE, {User, Server},
|
|
|
|
fun() -> Mod:get_password(User, Server) end);
|
|
|
|
true ->
|
|
|
|
Mod:get_password(User, Server)
|
|
|
|
end.
|
|
|
|
|
2017-05-11 14:49:06 +02:00
|
|
|
db_user_exists(User, Server, Mod) ->
|
2017-05-11 13:37:21 +02:00
|
|
|
case db_get_password(User, Server, Mod) of
|
|
|
|
{ok, _} ->
|
|
|
|
true;
|
|
|
|
error ->
|
|
|
|
case Mod:store_type(Server) of
|
|
|
|
external ->
|
2017-05-11 14:49:06 +02:00
|
|
|
Mod:user_exists(User, Server);
|
2017-05-11 13:37:21 +02:00
|
|
|
_ ->
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end.
|
|
|
|
|
|
|
|
db_check_password(User, AuthzId, Server, ProvidedPassword,
|
|
|
|
Digest, DigestFun, Mod) ->
|
|
|
|
case db_get_password(User, Server, Mod) of
|
|
|
|
{ok, ValidPassword} ->
|
|
|
|
match_passwords(ProvidedPassword, ValidPassword, Digest, DigestFun);
|
|
|
|
error ->
|
|
|
|
case {Mod:store_type(Server), use_cache(Mod, Server)} of
|
|
|
|
{external, true} ->
|
|
|
|
case ets_cache:update(
|
|
|
|
?AUTH_CACHE, {User, Server}, {ok, ProvidedPassword},
|
|
|
|
fun() ->
|
|
|
|
case Mod:check_password(
|
|
|
|
User, AuthzId, Server, ProvidedPassword) of
|
|
|
|
true ->
|
|
|
|
{ok, ProvidedPassword};
|
|
|
|
false ->
|
|
|
|
error
|
|
|
|
end
|
|
|
|
end, cache_nodes(Mod, Server)) of
|
|
|
|
{ok, _} ->
|
|
|
|
true;
|
|
|
|
error ->
|
|
|
|
false
|
|
|
|
end;
|
|
|
|
{external, false} ->
|
|
|
|
Mod:check_password(User, AuthzId, Server, ProvidedPassword);
|
|
|
|
_ ->
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end.
|
|
|
|
|
|
|
|
db_remove_user(User, Server, Mod) ->
|
|
|
|
case erlang:function_exported(Mod, remove_user, 2) of
|
|
|
|
true ->
|
|
|
|
case Mod:remove_user(User, Server) of
|
|
|
|
ok ->
|
|
|
|
case use_cache(Mod, Server) of
|
|
|
|
true ->
|
|
|
|
ets_cache:delete(?AUTH_CACHE, {User, Server},
|
|
|
|
cache_nodes(Mod, Server));
|
|
|
|
false ->
|
|
|
|
ok
|
|
|
|
end;
|
|
|
|
{error, _} = Err ->
|
|
|
|
Err
|
|
|
|
end;
|
|
|
|
false ->
|
|
|
|
{error, not_allowed}
|
|
|
|
end.
|
|
|
|
|
|
|
|
db_get_users(Server, Opts, Mod) ->
|
|
|
|
case erlang:function_exported(Mod, get_users, 2) of
|
|
|
|
true ->
|
|
|
|
Mod:get_users(Server, Opts);
|
|
|
|
false ->
|
|
|
|
case use_cache(Mod, Server) of
|
|
|
|
true ->
|
|
|
|
ets_cache:fold(
|
|
|
|
fun({User, S}, {ok, _}, Users) when S == Server ->
|
|
|
|
[{User, Server}|Users];
|
|
|
|
(_, _, Users) ->
|
|
|
|
Users
|
|
|
|
end, [], ?AUTH_CACHE);
|
|
|
|
false ->
|
|
|
|
[]
|
|
|
|
end
|
|
|
|
end.
|
|
|
|
|
|
|
|
db_count_users(Server, Opts, Mod) ->
|
|
|
|
case erlang:function_exported(Mod, count_users, 2) of
|
|
|
|
true ->
|
|
|
|
Mod:count_users(Server, Opts);
|
|
|
|
false ->
|
|
|
|
case use_cache(Mod, Server) of
|
|
|
|
true ->
|
|
|
|
ets_cache:fold(
|
|
|
|
fun({_, S}, {ok, _}, Num) when S == Server ->
|
|
|
|
Num + 1;
|
|
|
|
(_, _, Num) ->
|
|
|
|
Num
|
|
|
|
end, 0, ?AUTH_CACHE);
|
|
|
|
false ->
|
|
|
|
0
|
|
|
|
end
|
|
|
|
end.
|
|
|
|
|
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
%%% SCRAM stuff
|
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
is_password_scram_valid(Password, Scram) ->
|
|
|
|
case jid:resourceprep(Password) of
|
|
|
|
error ->
|
|
|
|
false;
|
|
|
|
_ ->
|
|
|
|
IterationCount = Scram#scram.iterationcount,
|
2017-05-23 09:43:26 +02:00
|
|
|
Salt = base64:decode(Scram#scram.salt),
|
2017-05-11 13:37:21 +02:00
|
|
|
SaltedPassword = scram:salted_password(Password, Salt, IterationCount),
|
|
|
|
StoredKey = scram:stored_key(scram:client_key(SaltedPassword)),
|
2017-05-23 09:43:26 +02:00
|
|
|
base64:decode(Scram#scram.storedkey) == StoredKey
|
2017-05-11 13:37:21 +02:00
|
|
|
end.
|
|
|
|
|
|
|
|
password_to_scram(Password) ->
|
|
|
|
password_to_scram(Password, ?SCRAM_DEFAULT_ITERATION_COUNT).
|
|
|
|
|
|
|
|
password_to_scram(#scram{} = Password, _IterationCount) ->
|
|
|
|
Password;
|
|
|
|
password_to_scram(Password, IterationCount) ->
|
|
|
|
Salt = randoms:bytes(?SALT_LENGTH),
|
|
|
|
SaltedPassword = scram:salted_password(Password, Salt, IterationCount),
|
|
|
|
StoredKey = scram:stored_key(scram:client_key(SaltedPassword)),
|
|
|
|
ServerKey = scram:server_key(SaltedPassword),
|
2017-05-23 09:43:26 +02:00
|
|
|
#scram{storedkey = base64:encode(StoredKey),
|
|
|
|
serverkey = base64:encode(ServerKey),
|
|
|
|
salt = base64:encode(Salt),
|
2017-05-11 13:37:21 +02:00
|
|
|
iterationcount = IterationCount}.
|
|
|
|
|
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
%%% Cache stuff
|
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
-spec init_cache(map()) -> ok.
|
|
|
|
init_cache(HostModules) ->
|
|
|
|
case use_cache(HostModules) of
|
|
|
|
true ->
|
|
|
|
ets_cache:new(?AUTH_CACHE, cache_opts());
|
|
|
|
false ->
|
|
|
|
ets_cache:delete(?AUTH_CACHE)
|
|
|
|
end.
|
|
|
|
|
|
|
|
-spec cache_opts() -> [proplists:property()].
|
|
|
|
cache_opts() ->
|
|
|
|
MaxSize = ejabberd_config:get_option(
|
|
|
|
auth_cache_size,
|
|
|
|
ejabberd_config:cache_size(global)),
|
|
|
|
CacheMissed = ejabberd_config:get_option(
|
|
|
|
auth_cache_missed,
|
|
|
|
ejabberd_config:cache_missed(global)),
|
|
|
|
LifeTime = case ejabberd_config:get_option(
|
|
|
|
auth_cache_life_time,
|
|
|
|
ejabberd_config:cache_life_time(global)) of
|
|
|
|
infinity -> infinity;
|
|
|
|
I -> timer:seconds(I)
|
|
|
|
end,
|
|
|
|
[{max_size, MaxSize}, {cache_missed, CacheMissed}, {life_time, LifeTime}].
|
|
|
|
|
|
|
|
-spec use_cache(map()) -> boolean().
|
|
|
|
use_cache(HostModules) ->
|
|
|
|
lists:any(
|
|
|
|
fun({Host, Modules}) ->
|
|
|
|
lists:any(fun(Module) ->
|
|
|
|
use_cache(Module, Host)
|
|
|
|
end, Modules)
|
|
|
|
end, maps:to_list(HostModules)).
|
|
|
|
|
|
|
|
-spec use_cache(module(), binary()) -> boolean().
|
|
|
|
use_cache(Mod, LServer) ->
|
|
|
|
case erlang:function_exported(Mod, use_cache, 1) of
|
|
|
|
true -> Mod:use_cache(LServer);
|
|
|
|
false ->
|
|
|
|
ejabberd_config:get_option(
|
|
|
|
{auth_use_cache, LServer},
|
|
|
|
ejabberd_config:use_cache(LServer))
|
|
|
|
end.
|
|
|
|
|
|
|
|
-spec cache_nodes(module(), binary()) -> [node()].
|
|
|
|
cache_nodes(Mod, LServer) ->
|
|
|
|
case erlang:function_exported(Mod, cache_nodes, 1) of
|
|
|
|
true -> Mod:cache_nodes(LServer);
|
|
|
|
false -> ejabberd_cluster:get_nodes()
|
|
|
|
end.
|
|
|
|
|
2004-12-12 22:00:34 +01:00
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
%%% Internal functions
|
|
|
|
%%%----------------------------------------------------------------------
|
2017-05-11 13:37:21 +02:00
|
|
|
-spec auth_modules() -> [{binary(), module()}].
|
2008-02-19 14:49:29 +01:00
|
|
|
auth_modules() ->
|
2017-05-11 13:37:21 +02:00
|
|
|
lists:flatmap(
|
|
|
|
fun(Host) ->
|
|
|
|
[{Host, Mod} || Mod <- auth_modules(Host)]
|
|
|
|
end, ?MYHOSTS).
|
2013-03-14 10:33:02 +01:00
|
|
|
|
2017-02-24 12:06:47 +01:00
|
|
|
-spec auth_modules(binary()) -> [module()].
|
2006-04-07 02:39:24 +02:00
|
|
|
auth_modules(Server) ->
|
2015-11-24 16:44:13 +01:00
|
|
|
LServer = jid:nameprep(Server),
|
2016-04-27 16:10:50 +02:00
|
|
|
Default = ejabberd_config:default_db(LServer, ?MODULE),
|
2017-04-29 10:39:40 +02:00
|
|
|
Methods = ejabberd_config:get_option({auth_method, LServer}, [Default]),
|
2017-04-11 12:13:58 +02:00
|
|
|
[misc:binary_to_atom(<<"ejabberd_auth_",
|
|
|
|
(misc:atom_to_binary(M))/binary>>)
|
2013-03-14 10:33:02 +01:00
|
|
|
|| M <- Methods].
|
|
|
|
|
2017-05-11 13:37:21 +02:00
|
|
|
-spec match_passwords(password(), password(),
|
|
|
|
binary(), digest_fun() | undefined) -> boolean().
|
|
|
|
match_passwords(Password, #scram{} = Scram, <<"">>, undefined) ->
|
|
|
|
is_password_scram_valid(Password, Scram);
|
|
|
|
match_passwords(Password, #scram{} = Scram, Digest, DigestFun) ->
|
2017-05-23 09:43:26 +02:00
|
|
|
StoredKey = base64:decode(Scram#scram.storedkey),
|
2017-05-11 13:37:21 +02:00
|
|
|
DigRes = if Digest /= <<"">> ->
|
|
|
|
Digest == DigestFun(StoredKey);
|
|
|
|
true -> false
|
|
|
|
end,
|
|
|
|
if DigRes ->
|
|
|
|
true;
|
|
|
|
true ->
|
|
|
|
StoredKey == Password andalso Password /= <<"">>
|
|
|
|
end;
|
|
|
|
match_passwords(ProvidedPassword, ValidPassword, <<"">>, undefined) ->
|
|
|
|
ProvidedPassword == ValidPassword andalso ProvidedPassword /= <<"">>;
|
|
|
|
match_passwords(ProvidedPassword, ValidPassword, Digest, DigestFun) ->
|
|
|
|
DigRes = if Digest /= <<"">> ->
|
|
|
|
Digest == DigestFun(ValidPassword);
|
|
|
|
true -> false
|
|
|
|
end,
|
|
|
|
if DigRes ->
|
|
|
|
true;
|
|
|
|
true ->
|
|
|
|
ValidPassword == ProvidedPassword andalso ProvidedPassword /= <<"">>
|
|
|
|
end.
|
|
|
|
|
|
|
|
-spec validate_credentials(binary(), binary()) ->
|
|
|
|
{ok, binary(), binary()} | {error, invalid_jid}.
|
|
|
|
validate_credentials(User, Server) ->
|
|
|
|
validate_credentials(User, Server, #scram{}).
|
|
|
|
|
|
|
|
-spec validate_credentials(binary(), binary(), password()) ->
|
|
|
|
{ok, binary(), binary()} | {error, invalid_jid | invalid_password}.
|
|
|
|
validate_credentials(_User, _Server, <<"">>) ->
|
|
|
|
{error, invalid_password};
|
|
|
|
validate_credentials(User, Server, Password) ->
|
|
|
|
case jid:nodeprep(User) of
|
|
|
|
error ->
|
|
|
|
{error, invalid_jid};
|
|
|
|
LUser ->
|
|
|
|
case jid:nameprep(Server) of
|
|
|
|
error ->
|
|
|
|
{error, invalid_jid};
|
|
|
|
LServer ->
|
|
|
|
if is_record(Password, scram) ->
|
|
|
|
{ok, LUser, LServer};
|
|
|
|
true ->
|
|
|
|
case jid:resourceprep(Password) of
|
|
|
|
error ->
|
|
|
|
{error, invalid_password};
|
|
|
|
_ ->
|
|
|
|
{ok, LUser, LServer}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end.
|
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
export(Server) ->
|
2016-04-27 08:44:32 +02:00
|
|
|
ejabberd_auth_mnesia:export(Server).
|
2013-07-21 12:24:36 +02:00
|
|
|
|
2016-11-22 14:48:01 +01:00
|
|
|
import_info() ->
|
|
|
|
[{<<"users">>, 3}].
|
2013-07-21 12:24:36 +02:00
|
|
|
|
2016-11-22 14:48:01 +01:00
|
|
|
import_start(_LServer, mnesia) ->
|
|
|
|
ejabberd_auth_mnesia:init_db();
|
|
|
|
import_start(_LServer, _) ->
|
|
|
|
ok.
|
|
|
|
|
|
|
|
import(Server, {sql, _}, mnesia, <<"users">>, Fields) ->
|
|
|
|
ejabberd_auth_mnesia:import(Server, Fields);
|
|
|
|
import(Server, {sql, _}, riak, <<"users">>, Fields) ->
|
|
|
|
ejabberd_auth_riak:import(Server, Fields);
|
|
|
|
import(_LServer, {sql, _}, sql, <<"users">>, _) ->
|
|
|
|
ok.
|
2015-06-01 14:38:27 +02:00
|
|
|
|
2017-05-08 11:59:28 +02:00
|
|
|
-spec opt_type(auth_method) -> fun((atom() | [atom()]) -> [atom()]);
|
|
|
|
(auth_password_format) -> fun((plain | scram) -> plain | scram);
|
2017-05-11 13:37:21 +02:00
|
|
|
(auth_use_cache) -> fun((boolean()) -> boolean());
|
|
|
|
(auth_cache_missed) -> fun((boolean()) -> boolean());
|
|
|
|
(auth_cache_life_time) -> fun((timeout()) -> timeout());
|
|
|
|
(auth_cache_size) -> fun((timeout()) -> timeout());
|
2017-05-08 11:59:28 +02:00
|
|
|
(atom()) -> [atom()].
|
2015-06-01 14:38:27 +02:00
|
|
|
opt_type(auth_method) ->
|
|
|
|
fun (V) when is_list(V) ->
|
2016-04-27 16:10:50 +02:00
|
|
|
lists:map(fun(M) -> ejabberd_config:v_db(?MODULE, M) end, V);
|
|
|
|
(V) -> [ejabberd_config:v_db(?MODULE, V)]
|
2015-06-01 14:38:27 +02:00
|
|
|
end;
|
2017-04-28 12:23:32 +02:00
|
|
|
opt_type(auth_password_format) ->
|
|
|
|
fun (plain) -> plain;
|
|
|
|
(scram) -> scram
|
|
|
|
end;
|
2017-05-11 13:37:21 +02:00
|
|
|
opt_type(auth_use_cache) ->
|
|
|
|
fun(B) when is_boolean(B) -> B end;
|
|
|
|
opt_type(auth_cache_missed) ->
|
|
|
|
fun(B) when is_boolean(B) -> B end;
|
|
|
|
opt_type(auth_cache_life_time) ->
|
|
|
|
fun(I) when is_integer(I), I>0 -> I;
|
|
|
|
(unlimited) -> infinity;
|
|
|
|
(infinity) -> infinity
|
|
|
|
end;
|
|
|
|
opt_type(auth_cache_size) ->
|
|
|
|
fun(I) when is_integer(I), I>0 -> I;
|
|
|
|
(unlimited) -> infinity;
|
|
|
|
(infinity) -> infinity
|
|
|
|
end;
|
|
|
|
opt_type(_) ->
|
|
|
|
[auth_method, auth_password_format, auth_use_cache,
|
|
|
|
auth_cache_missed, auth_cache_life_time, auth_cache_size].
|