diff options
author | Alexey Shchepin <alexey@process-one.net> | 2006-04-07 00:39:24 +0000 |
---|---|---|
committer | Alexey Shchepin <alexey@process-one.net> | 2006-04-07 00:39:24 +0000 |
commit | 9a44fdffab463adb4cc5d9463d23a35a78867b10 (patch) | |
tree | 6a278f4255a9df42210a5a5509cc88e326e72df9 /src/ejabberd_auth.erl | |
parent | * src/expat_erl.c: Use binaries for CDATA (diff) |
* src/ejabberd_sm.erl: SASL Anonymous + Anonymous login support
(thanks to Mickael Remond and Magnus Henoch)
* src/ejabberd_c2s.erl: Likewise
* src/ejabberd_auth.erl: Likewise
* src/ejabberd_auth_anonymous.erl: Likewise
* src/cyrsasl.erl: Likewise
* src/cyrsasl_anonymous.erl: Likewise
* src/ejabberd.cfg.example: Likewise
SVN Revision: 527
Diffstat (limited to 'src/ejabberd_auth.erl')
-rw-r--r-- | src/ejabberd_auth.erl | 98 |
1 files changed, 79 insertions, 19 deletions
diff --git a/src/ejabberd_auth.erl b/src/ejabberd_auth.erl index 045bf272..ea4518b9 100644 --- a/src/ejabberd_auth.erl +++ b/src/ejabberd_auth.erl @@ -3,9 +3,13 @@ %%% Author : Alexey Shchepin <alexey@sevcom.net> %%% Purpose : Authentification %%% Created : 23 Nov 2002 by Alexey Shchepin <alexey@sevcom.net> +%%% Updated : 23 Feb 2006 by Mickael Remond <mremond@process-one.net> +%%% for anonymous login support %%% Id : $Id$ %%%---------------------------------------------------------------------- +%% TODO: Use the functions in ejabberd auth to add and remove users. + -module(ejabberd_auth). -author('alexey@sevcom.net'). -vsn('$Revision$ '). @@ -27,6 +31,8 @@ ctl_process_get_registered/3 ]). +-export([auth_modules/1]). + -include("ejabberd.hrl"). -include("ejabberd_ctl.hrl"). @@ -34,50 +40,102 @@ %%% API %%%---------------------------------------------------------------------- start() -> - lists:foreach(fun(Host) -> - (auth_module(Host)):start(Host) - end, ?MYHOSTS). + lists:foreach( + fun(Host) -> + lists:foreach( + fun(M) -> + M:start(Host) + end, auth_modules(Host)) + end, ?MYHOSTS). plain_password_required(Server) -> - (auth_module(Server)):plain_password_required(). + lists:any( + fun(M) -> + M:plain_password_required() + end, auth_modules(Server)). check_password(User, Server, Password) -> - (auth_module(Server)):check_password(User, Server, Password). + lists:any( + fun(M) -> + M:check_password(User, Server, Password) + end, auth_modules(Server)). check_password(User, Server, Password, StreamID, Digest) -> - (auth_module(Server)):check_password(User, Server, Password, StreamID, Digest). + lists:any( + fun(M) -> + M:check_password(User, Server, Password, StreamID, Digest) + end, auth_modules(Server)). set_password(User, Server, Password) -> - (auth_module(Server)):set_password(User, Server, Password). + lists:foldl( + fun(M, {error, _}) -> + M:set_password(User, Server, Password); + (_M, Res) -> + Res + end, {error, not_allowed}, auth_modules(Server)). try_register(User, Server, Password) -> case lists:member(jlib:nameprep(Server), ?MYHOSTS) of true -> - (auth_module(Server)):try_register(User, Server, Password); + lists:foldl( + fun(_M, {atomic, ok} = Res) -> + Res; + (M, _) -> + M:try_register(User, Server, Password) + end, {error, not_allowed}, auth_modules(Server)); false -> {error, not_allowed} end. +%% Registered users list do not include anonymous users logged dirty_get_registered_users() -> - (auth_module(?MYNAME)):dirty_get_registered_users(). + lists:flatmap( + fun(M) -> + M:dirty_get_registered_users() + end, auth_modules(?MYNAME)). +%% Registered users list do not include anonymous users logged get_vh_registered_users(Server) -> - (auth_module(Server)):get_vh_registered_users(Server). + lists:flatmap( + fun(M) -> + M:get_vh_registered_users(Server) + end, auth_modules(Server)). get_password(User, Server) -> - (auth_module(Server)):get_password(User, Server). + lists:foldl( + fun(M, false) -> + M:get_password(User, Server); + (_M, Password) -> + Password + end, false, auth_modules(Server)). get_password_s(User, Server) -> - (auth_module(Server)):get_password_s(User, Server). + case get_password(User, Server) of + false -> + ""; + Password -> + Password + end. +%% Returns true if the user exists in the DB or if an anonymous user is logged +%% under the given name is_user_exists(User, Server) -> - (auth_module(Server)):is_user_exists(User, Server). + lists:any( + fun(M) -> + M:is_user_exists(User, Server) + end, auth_modules(Server)). remove_user(User, Server) -> - (auth_module(Server)):remove_user(User, Server). + lists:foreach( + fun(M) -> + M:remove_user(User, Server) + end, auth_modules(Server)). remove_user(User, Server, Password) -> - (auth_module(Server)):remove_user(User, Server, Password). + lists:foreach( + fun(M) -> + M:remove_user(User, Server, Password) + end, auth_modules(Server)). ctl_process_get_registered(_Val, Host, ["registered-users"]) -> @@ -93,9 +151,11 @@ ctl_process_get_registered(Val, _Host, _Args) -> %%%---------------------------------------------------------------------- %%% Internal functions %%%---------------------------------------------------------------------- - -auth_module(Server) -> +auth_modules(Server) -> LServer = jlib:nameprep(Server), Method = ejabberd_config:get_local_option({auth_method, LServer}), - list_to_atom("ejabberd_auth_" ++ atom_to_list(Method)). - + Methods = if + is_list(Method) -> Method; + is_atom(Method) -> [Method] + end, + [list_to_atom("ejabberd_auth_" ++ atom_to_list(M)) || M <- Methods]. |