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>
|
|
|
|
%%%
|
|
|
|
%%%
|
2013-01-24 15:25:13 +01:00
|
|
|
%%% ejabberd, Copyright (C) 2002-2013 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
|
|
|
%%%
|
2007-12-24 12:41:41 +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., 59 Temple Place, Suite 330, Boston, MA
|
|
|
|
%%% 02111-1307 USA
|
|
|
|
%%%
|
2002-11-23 21:55:05 +01:00
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
|
2006-04-07 02:39:24 +02:00
|
|
|
%% TODO: Use the functions in ejabberd auth to add and remove users.
|
|
|
|
|
2002-11-23 21:55:05 +01:00
|
|
|
-module(ejabberd_auth).
|
2013-03-14 10:33:02 +01:00
|
|
|
|
2007-12-24 12:41:41 +01:00
|
|
|
-author('alexey@process-one.net').
|
2002-11-23 21:55:05 +01:00
|
|
|
|
|
|
|
%% External exports
|
2013-03-14 10:33:02 +01:00
|
|
|
-export([start/0, set_password/3, check_password/3,
|
|
|
|
check_password/5, check_password_with_authmodule/3,
|
|
|
|
check_password_with_authmodule/5, try_register/3,
|
|
|
|
dirty_get_registered_users/0, get_vh_registered_users/1,
|
2013-07-21 12:24:36 +02:00
|
|
|
get_vh_registered_users/2, export/1, import/1,
|
|
|
|
get_vh_registered_users_number/1, import/3,
|
2013-03-14 10:33:02 +01:00
|
|
|
get_vh_registered_users_number/2, get_password/2,
|
|
|
|
get_password_s/2, get_password_with_authmodule/2,
|
|
|
|
is_user_exists/2, is_user_exists_in_other_modules/3,
|
|
|
|
remove_user/2, remove_user/3, plain_password_required/1,
|
|
|
|
store_type/1, entropy/1]).
|
2002-11-23 21:55:05 +01:00
|
|
|
|
2006-04-07 02:39:24 +02:00
|
|
|
-export([auth_modules/1]).
|
|
|
|
|
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
|
|
|
|
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().
|
|
|
|
-callback plain_password_required() -> boolean().
|
|
|
|
-callback store_type() -> plain | external | scram.
|
|
|
|
-callback set_password(binary(), binary(), binary()) -> ok | {error, atom()}.
|
|
|
|
-callback remove_user(binary(), binary()) -> any().
|
|
|
|
-callback remove_user(binary(), binary(), binary()) -> any().
|
|
|
|
-callback is_user_exists(binary(), binary()) -> boolean() | {error, atom()}.
|
|
|
|
-callback check_password(binary(), binary(), binary()) -> boolean().
|
|
|
|
-callback check_password(binary(), binary(), binary(), binary(),
|
|
|
|
fun((binary()) -> binary())) -> boolean().
|
|
|
|
-callback try_register(binary(), binary(), binary()) -> {atomic, atom()} |
|
|
|
|
{error, atom()}.
|
|
|
|
-callback dirty_get_registered_users() -> [{binary(), binary()}].
|
|
|
|
-callback get_vh_registered_users(binary()) -> [{binary(), binary()}].
|
|
|
|
-callback get_vh_registered_users(binary(), opts()) -> [{binary(), binary()}].
|
|
|
|
-callback get_vh_registered_users_number(binary()) -> number().
|
|
|
|
-callback get_vh_registered_users_number(binary(), opts()) -> number().
|
|
|
|
-callback get_password(binary(), binary()) -> false | binary().
|
|
|
|
-callback get_password_s(binary(), binary()) -> binary().
|
2003-11-23 21:11:21 +01:00
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
start() ->
|
2011-08-16 00:26:49 +02:00
|
|
|
%% This is only executed by ejabberd_c2s for non-SASL auth client
|
2013-03-14 10:33:02 +01:00
|
|
|
lists:foreach(fun (Host) ->
|
|
|
|
lists:foreach(fun (M) -> M:start(Host) end,
|
|
|
|
auth_modules(Host))
|
|
|
|
end,
|
|
|
|
?MYHOSTS).
|
|
|
|
|
2005-07-13 05:24:13 +02:00
|
|
|
plain_password_required(Server) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
lists:any(fun (M) -> M:plain_password_required() end,
|
|
|
|
auth_modules(Server)).
|
2003-11-23 21:11:21 +01:00
|
|
|
|
2011-08-16 00:26:49 +02:00
|
|
|
store_type(Server) ->
|
2008-04-22 19:41:30 +02:00
|
|
|
%% @doc Check if the user and password can login in server.
|
|
|
|
%% @spec (User::string(), Server::string(), Password::string()) ->
|
|
|
|
%% true | false
|
2013-03-14 10:33:02 +01:00
|
|
|
lists:foldl(fun (_, external) -> external;
|
|
|
|
(M, scram) ->
|
|
|
|
case M:store_type() of
|
|
|
|
external -> external;
|
|
|
|
_Else -> scram
|
|
|
|
end;
|
|
|
|
(M, plain) -> M:store_type()
|
|
|
|
end,
|
|
|
|
plain, auth_modules(Server)).
|
|
|
|
|
|
|
|
-spec check_password(binary(), binary(), binary()) -> boolean().
|
|
|
|
|
2005-04-17 20:08:34 +02:00
|
|
|
check_password(User, Server, Password) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
case check_password_with_authmodule(User, Server,
|
|
|
|
Password)
|
|
|
|
of
|
|
|
|
{true, _AuthModule} -> true;
|
|
|
|
false -> false
|
2009-03-04 19:34:02 +01:00
|
|
|
end.
|
2002-11-23 21:55:05 +01:00
|
|
|
|
2008-04-22 19:41:30 +02:00
|
|
|
%% @doc Check if the user and password can login in server.
|
2009-08-17 19:16:43 +02:00
|
|
|
%% @spec (User::string(), Server::string(), Password::string(),
|
2009-04-22 13:44:03 +02:00
|
|
|
%% Digest::string(), DigestGen::function()) ->
|
2008-04-22 19:41:30 +02:00
|
|
|
%% true | false
|
2013-03-14 10:33:02 +01:00
|
|
|
-spec check_password(binary(), binary(), binary(), binary(),
|
|
|
|
fun((binary()) -> binary())) -> boolean().
|
|
|
|
|
|
|
|
check_password(User, Server, Password, Digest,
|
|
|
|
DigestGen) ->
|
|
|
|
case check_password_with_authmodule(User, 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
|
|
|
|
2008-04-22 19:41:30 +02:00
|
|
|
%% @doc Check if the user and password can login in server.
|
|
|
|
%% The user can login if at least an authentication method accepts the user
|
|
|
|
%% and the password.
|
|
|
|
%% The first authentication method that accepts the credentials is returned.
|
|
|
|
%% @spec (User::string(), Server::string(), Password::string()) ->
|
|
|
|
%% {true, AuthModule} | false
|
|
|
|
%% where
|
|
|
|
%% AuthModule = ejabberd_auth_anonymous | ejabberd_auth_external
|
|
|
|
%% | ejabberd_auth_internal | ejabberd_auth_ldap
|
|
|
|
%% | ejabberd_auth_odbc | ejabberd_auth_pam
|
2013-03-14 10:33:02 +01:00
|
|
|
-spec check_password_with_authmodule(binary(), binary(), binary()) -> false |
|
|
|
|
{true, atom()}.
|
2008-04-22 19:41:30 +02:00
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
check_password_with_authmodule(User, Server,
|
|
|
|
Password) ->
|
|
|
|
check_password_loop(auth_modules(Server),
|
|
|
|
[User, Server, Password]).
|
2009-03-04 19:34:02 +01:00
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
-spec check_password_with_authmodule(binary(), binary(), binary(), binary(),
|
|
|
|
fun((binary()) -> binary())) -> false |
|
|
|
|
{true, atom()}.
|
|
|
|
|
|
|
|
check_password_with_authmodule(User, Server, Password,
|
|
|
|
Digest, DigestGen) ->
|
|
|
|
check_password_loop(auth_modules(Server),
|
|
|
|
[User, Server, Password, Digest, DigestGen]).
|
|
|
|
|
|
|
|
check_password_loop([], _Args) -> false;
|
2009-03-04 19:34:02 +01:00
|
|
|
check_password_loop([AuthModule | AuthModules], Args) ->
|
|
|
|
case apply(AuthModule, check_password, Args) of
|
2013-03-14 10:33:02 +01:00
|
|
|
true -> {true, AuthModule};
|
|
|
|
false -> check_password_loop(AuthModules, Args)
|
2008-04-22 19:41:30 +02:00
|
|
|
end.
|
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
-spec set_password(binary(), binary(), binary()) -> ok |
|
|
|
|
{error, atom()}.
|
2009-03-04 19:34:02 +01:00
|
|
|
|
2008-08-18 20:21:10 +02:00
|
|
|
%% @spec (User::string(), Server::string(), Password::string()) ->
|
|
|
|
%% ok | {error, ErrorType}
|
|
|
|
%% where ErrorType = empty_password | not_allowed | invalid_jid
|
2013-03-14 10:33:02 +01:00
|
|
|
set_password(_User, _Server, <<"">>) ->
|
2008-08-18 20:21:10 +02:00
|
|
|
{error, empty_password};
|
2005-04-17 20:08:34 +02:00
|
|
|
set_password(User, Server, Password) ->
|
2008-12-23 20:15:33 +01:00
|
|
|
%% @spec (User, Server, Password) -> {atomic, ok} | {atomic, exists} | {error, not_allowed}
|
2013-03-14 10:33:02 +01:00
|
|
|
lists:foldl(fun (M, {error, _}) ->
|
|
|
|
M:set_password(User, Server, Password);
|
|
|
|
(_M, Res) -> Res
|
|
|
|
end,
|
|
|
|
{error, not_allowed}, auth_modules(Server)).
|
|
|
|
|
|
|
|
-spec try_register(binary(), binary(), binary()) -> {atomic, atom()} |
|
|
|
|
{error, atom()}.
|
|
|
|
|
|
|
|
try_register(_User, _Server, <<"">>) ->
|
|
|
|
{error, not_allowed};
|
2005-04-17 20:08:34 +02:00
|
|
|
try_register(User, Server, Password) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
case is_user_exists(User, Server) of
|
|
|
|
true -> {atomic, exists};
|
|
|
|
false ->
|
|
|
|
case lists:member(jlib:nameprep(Server), ?MYHOSTS) of
|
|
|
|
true ->
|
|
|
|
Res = lists:foldl(fun (_M, {atomic, ok} = Res) -> Res;
|
|
|
|
(M, _) ->
|
|
|
|
M:try_register(User, Server, Password)
|
|
|
|
end,
|
|
|
|
{error, not_allowed}, auth_modules(Server)),
|
|
|
|
case Res of
|
|
|
|
{atomic, ok} ->
|
|
|
|
ejabberd_hooks:run(register_user, Server,
|
|
|
|
[User, Server]),
|
|
|
|
{atomic, ok};
|
|
|
|
_ -> Res
|
|
|
|
end;
|
|
|
|
false -> {error, not_allowed}
|
|
|
|
end
|
2005-04-20 01:10:22 +02:00
|
|
|
end.
|
2002-12-14 21:07:26 +01:00
|
|
|
|
2006-04-07 02:39:24 +02:00
|
|
|
%% Registered users list do not include anonymous users logged
|
2013-03-14 10:33:02 +01:00
|
|
|
-spec dirty_get_registered_users() -> [{binary(), binary()}].
|
|
|
|
|
2003-01-01 20:54:44 +01:00
|
|
|
dirty_get_registered_users() ->
|
2013-03-14 10:33:02 +01:00
|
|
|
lists:flatmap(fun (M) -> M:dirty_get_registered_users()
|
|
|
|
end,
|
|
|
|
auth_modules()).
|
|
|
|
|
|
|
|
-spec get_vh_registered_users(binary()) -> [{binary(), binary()}].
|
2003-01-01 20:54:44 +01:00
|
|
|
|
2006-04-07 02:39:24 +02:00
|
|
|
%% Registered users list do not include anonymous users logged
|
2005-04-17 20:08:34 +02:00
|
|
|
get_vh_registered_users(Server) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
lists:flatmap(fun (M) ->
|
|
|
|
M:get_vh_registered_users(Server)
|
|
|
|
end,
|
|
|
|
auth_modules(Server)).
|
|
|
|
|
|
|
|
-spec get_vh_registered_users(binary(), opts()) -> [{binary(), binary()}].
|
2003-03-12 20:48:05 +01:00
|
|
|
|
2007-11-03 18:35:23 +01:00
|
|
|
get_vh_registered_users(Server, Opts) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
lists:flatmap(fun (M) ->
|
|
|
|
case erlang:function_exported(M,
|
|
|
|
get_vh_registered_users,
|
|
|
|
2)
|
|
|
|
of
|
|
|
|
true -> M:get_vh_registered_users(Server, Opts);
|
|
|
|
false -> M:get_vh_registered_users(Server)
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
auth_modules(Server)).
|
2007-11-03 18:35:23 +01:00
|
|
|
|
2007-05-12 20:09:38 +02:00
|
|
|
get_vh_registered_users_number(Server) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
lists:sum(lists:map(fun (M) ->
|
|
|
|
case erlang:function_exported(M,
|
|
|
|
get_vh_registered_users_number,
|
|
|
|
1)
|
|
|
|
of
|
|
|
|
true ->
|
|
|
|
M:get_vh_registered_users_number(Server);
|
|
|
|
false ->
|
|
|
|
length(M:get_vh_registered_users(Server))
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
auth_modules(Server))).
|
|
|
|
|
|
|
|
-spec get_vh_registered_users_number(binary(), opts()) -> number().
|
2007-11-03 18:35:23 +01:00
|
|
|
|
|
|
|
get_vh_registered_users_number(Server, Opts) ->
|
2008-04-22 19:41:30 +02:00
|
|
|
%% @doc Get the password of the user.
|
|
|
|
%% @spec (User::string(), Server::string()) -> Password::string()
|
2013-03-14 10:33:02 +01:00
|
|
|
lists:sum(lists:map(fun (M) ->
|
|
|
|
case erlang:function_exported(M,
|
|
|
|
get_vh_registered_users_number,
|
|
|
|
2)
|
|
|
|
of
|
|
|
|
true ->
|
|
|
|
M:get_vh_registered_users_number(Server,
|
|
|
|
Opts);
|
|
|
|
false ->
|
|
|
|
length(M:get_vh_registered_users(Server))
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
auth_modules(Server))).
|
|
|
|
|
|
|
|
-spec get_password(binary(), binary()) -> false | binary().
|
|
|
|
|
2005-04-17 20:08:34 +02:00
|
|
|
get_password(User, Server) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
lists:foldl(fun (M, false) ->
|
|
|
|
M:get_password(User, Server);
|
|
|
|
(_M, Password) -> Password
|
|
|
|
end,
|
|
|
|
false, auth_modules(Server)).
|
|
|
|
|
|
|
|
-spec get_password_s(binary(), binary()) -> binary().
|
2003-01-21 21:36:55 +01:00
|
|
|
|
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
|
|
|
|
2008-04-22 19:41:30 +02:00
|
|
|
%% @doc Get the password of the user and the auth module.
|
|
|
|
%% @spec (User::string(), Server::string()) ->
|
|
|
|
%% {Password::string(), AuthModule::atom()} | {false, none}
|
2013-03-14 10:33:02 +01:00
|
|
|
-spec get_password_with_authmodule(binary(), binary()) -> {false | binary(), atom()}.
|
2008-04-22 19:41:30 +02:00
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
get_password_with_authmodule(User, Server) ->
|
2006-04-07 02:39:24 +02:00
|
|
|
%% Returns true if the user exists in the DB or if an anonymous user is logged
|
|
|
|
%% under the given name
|
2013-03-14 10:33:02 +01:00
|
|
|
lists:foldl(fun (M, {false, _}) ->
|
|
|
|
{M:get_password(User, Server), M};
|
|
|
|
(_M, {Password, AuthModule}) -> {Password, AuthModule}
|
|
|
|
end,
|
|
|
|
{false, none}, auth_modules(Server)).
|
2003-02-21 20:52:15 +01:00
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
-spec is_user_exists(binary(), binary()) -> boolean().
|
|
|
|
|
|
|
|
is_user_exists(User, Server) ->
|
2006-06-13 18:52:38 +02:00
|
|
|
%% Check if the user exists in all authentications module except the module
|
|
|
|
%% passed as parameter
|
2009-03-04 19:34:02 +01:00
|
|
|
%% @spec (Module::atom(), User, Server) -> true | false | maybe
|
2013-03-14 10:33:02 +01:00
|
|
|
lists:any(fun (M) ->
|
|
|
|
case M:is_user_exists(User, Server) of
|
|
|
|
{error, Error} ->
|
|
|
|
?ERROR_MSG("The authentication module ~p returned "
|
|
|
|
"an error~nwhen checking user ~p in server "
|
|
|
|
"~p~nError message: ~p",
|
|
|
|
[M, User, Server, Error]),
|
|
|
|
false;
|
|
|
|
Else -> Else
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
auth_modules(Server)).
|
|
|
|
|
|
|
|
-spec is_user_exists_in_other_modules(atom(), binary(), binary()) -> boolean() | maybe.
|
|
|
|
|
2006-06-13 18:52:38 +02:00
|
|
|
is_user_exists_in_other_modules(Module, User, Server) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
is_user_exists_in_other_modules_loop(auth_modules(Server)
|
|
|
|
-- [Module],
|
|
|
|
User, Server).
|
|
|
|
|
|
|
|
is_user_exists_in_other_modules_loop([], _User,
|
|
|
|
_Server) ->
|
2009-03-04 19:34:02 +01:00
|
|
|
false;
|
2013-03-14 10:33:02 +01:00
|
|
|
is_user_exists_in_other_modules_loop([AuthModule
|
|
|
|
| AuthModules],
|
|
|
|
User, Server) ->
|
2009-03-04 19:34:02 +01:00
|
|
|
case AuthModule:is_user_exists(User, Server) of
|
2013-03-14 10:33:02 +01:00
|
|
|
true -> true;
|
|
|
|
false ->
|
|
|
|
is_user_exists_in_other_modules_loop(AuthModules, User,
|
|
|
|
Server);
|
|
|
|
{error, Error} ->
|
|
|
|
?DEBUG("The authentication module ~p returned "
|
|
|
|
"an error~nwhen checking user ~p in server "
|
|
|
|
"~p~nError message: ~p",
|
|
|
|
[AuthModule, User, Server, 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.
|
2006-06-13 18:52:38 +02:00
|
|
|
|
2011-09-05 07:39:55 +02:00
|
|
|
%% @spec (User, Server) -> ok
|
2009-01-03 22:29:54 +01:00
|
|
|
%% @doc Remove user.
|
2008-12-23 20:15:33 +01:00
|
|
|
%% Note: it may return ok even if there was some problem removing the user.
|
2005-04-17 20:08:34 +02:00
|
|
|
remove_user(User, Server) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
lists:foreach(fun (M) -> M:remove_user(User, Server)
|
|
|
|
end,
|
|
|
|
auth_modules(Server)),
|
|
|
|
ejabberd_hooks:run(remove_user, jlib:nameprep(Server),
|
|
|
|
[User, Server]),
|
2011-09-05 07:39:55 +02:00
|
|
|
ok.
|
2005-04-17 20:08:34 +02:00
|
|
|
|
2008-12-23 20:15:33 +01:00
|
|
|
%% @spec (User, Server, Password) -> ok | not_exists | not_allowed | bad_request | error
|
2009-01-03 22:29:54 +01:00
|
|
|
%% @doc Try to remove user if the provided password is correct.
|
2008-12-23 20:15:33 +01:00
|
|
|
%% The removal is attempted in each auth method provided:
|
|
|
|
%% when one returns 'ok' the loop stops;
|
|
|
|
%% if no method returns 'ok' then it returns the error message indicated by the last method attempted.
|
2013-03-14 10:33:02 +01:00
|
|
|
-spec remove_user(binary(), binary(), binary()) -> any().
|
|
|
|
|
2005-04-17 20:08:34 +02:00
|
|
|
remove_user(User, Server, Password) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
R = lists:foldl(fun (_M, ok = Res) -> Res;
|
|
|
|
(M, _) -> M:remove_user(User, Server, Password)
|
|
|
|
end,
|
|
|
|
error, auth_modules(Server)),
|
2008-12-23 20:15:33 +01:00
|
|
|
case R of
|
2013-03-14 10:33:02 +01:00
|
|
|
ok ->
|
|
|
|
ejabberd_hooks:run(remove_user, jlib:nameprep(Server),
|
|
|
|
[User, Server]);
|
|
|
|
_ -> none
|
2008-12-23 20:15:33 +01:00
|
|
|
end,
|
|
|
|
R.
|
2004-07-30 23:09:55 +02:00
|
|
|
|
2010-10-24 09:17:30 +02:00
|
|
|
%% @spec (IOList) -> non_negative_float()
|
|
|
|
%% @doc Calculate informational entropy.
|
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
|
|
|
|
2004-12-12 22:00:34 +01:00
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
%%% Internal functions
|
|
|
|
%%%----------------------------------------------------------------------
|
2008-02-19 14:49:29 +01:00
|
|
|
%% Return the lists of all the auth modules actually used in the
|
|
|
|
%% configuration
|
|
|
|
auth_modules() ->
|
2013-03-14 10:33:02 +01:00
|
|
|
lists:usort(lists:flatmap(fun (Server) ->
|
|
|
|
auth_modules(Server)
|
|
|
|
end,
|
|
|
|
?MYHOSTS)).
|
|
|
|
|
|
|
|
-spec auth_modules(binary()) -> [atom()].
|
2008-02-19 14:49:29 +01:00
|
|
|
|
|
|
|
%% Return the list of authenticated modules for a given host
|
2006-04-07 02:39:24 +02:00
|
|
|
auth_modules(Server) ->
|
2005-07-13 05:24:13 +02:00
|
|
|
LServer = jlib:nameprep(Server),
|
2013-08-12 14:25:05 +02:00
|
|
|
Methods = ejabberd_config:get_option(
|
2013-03-14 10:33:02 +01:00
|
|
|
{auth_method, LServer},
|
|
|
|
fun(V) when is_list(V) ->
|
|
|
|
true = lists:all(fun is_atom/1, V),
|
|
|
|
V;
|
|
|
|
(V) when is_atom(V) ->
|
|
|
|
[V]
|
|
|
|
end, []),
|
|
|
|
[jlib:binary_to_atom(<<"ejabberd_auth_",
|
|
|
|
(jlib:atom_to_binary(M))/binary>>)
|
|
|
|
|| M <- Methods].
|
|
|
|
|
|
|
|
export(Server) ->
|
|
|
|
ejabberd_auth_internal:export(Server).
|
2013-07-21 12:24:36 +02:00
|
|
|
|
|
|
|
import(Server) ->
|
|
|
|
ejabberd_auth_internal:import(Server).
|
|
|
|
|
|
|
|
import(Server, mnesia, Passwd) ->
|
|
|
|
ejabberd_auth_internal:import(Server, mnesia, Passwd);
|
|
|
|
import(_, _, _) ->
|
|
|
|
pass.
|