2007-10-01 12:49:42 +02:00
|
|
|
%%%-------------------------------------------------------------------
|
|
|
|
%%% File : ejabberd_auth_pam.erl
|
|
|
|
%%% Author : Evgeniy Khramtsov <xram@jabber.ru>
|
|
|
|
%%% Purpose : PAM authentication
|
|
|
|
%%% Created : 5 Jul 2007 by Evgeniy Khramtsov <xram@jabber.ru>
|
2007-12-24 12:41:41 +01:00
|
|
|
%%%
|
|
|
|
%%%
|
2015-01-08 17:34:43 +01:00
|
|
|
%%% ejabberd, Copyright (C) 2002-2015 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
|
|
|
%%%
|
2007-10-01 12:49:42 +02:00
|
|
|
%%%-------------------------------------------------------------------
|
|
|
|
-module(ejabberd_auth_pam).
|
2013-03-14 10:33:02 +01:00
|
|
|
|
2007-10-01 12:49:42 +02:00
|
|
|
-author('xram@jabber.ru').
|
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
-behaviour(ejabberd_auth).
|
2007-10-01 12:49:42 +02:00
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
%% External exports
|
2007-10-01 12:49:42 +02:00
|
|
|
%%====================================================================
|
|
|
|
%% API
|
|
|
|
%%====================================================================
|
2013-03-14 10:33:02 +01:00
|
|
|
-export([start/1, set_password/3, check_password/3,
|
|
|
|
check_password/5, try_register/3,
|
|
|
|
dirty_get_registered_users/0, get_vh_registered_users/1,
|
|
|
|
get_vh_registered_users/2, get_vh_registered_users_number/1,
|
|
|
|
get_vh_registered_users_number/2,
|
|
|
|
get_password/2, get_password_s/2, is_user_exists/2,
|
|
|
|
remove_user/2, remove_user/3, store_type/0,
|
|
|
|
plain_password_required/0]).
|
|
|
|
|
2007-10-01 12:49:42 +02:00
|
|
|
start(_Host) ->
|
2013-04-08 11:12:54 +02:00
|
|
|
ejabberd:start_app(p1_pam).
|
2007-10-01 12:49:42 +02:00
|
|
|
|
|
|
|
set_password(_User, _Server, _Password) ->
|
|
|
|
{error, not_allowed}.
|
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
check_password(User, Server, Password, _Digest,
|
|
|
|
_DigestGen) ->
|
2007-10-01 12:49:42 +02:00
|
|
|
check_password(User, Server, Password).
|
|
|
|
|
|
|
|
check_password(User, Host, Password) ->
|
|
|
|
Service = get_pam_service(Host),
|
2010-05-07 22:34:59 +02:00
|
|
|
UserInfo = case get_pam_userinfotype(Host) of
|
2013-03-14 10:33:02 +01:00
|
|
|
username -> User;
|
|
|
|
jid -> <<User/binary, "@", Host/binary>>
|
|
|
|
end,
|
|
|
|
case catch epam:authenticate(Service, UserInfo,
|
|
|
|
Password)
|
|
|
|
of
|
|
|
|
true -> true;
|
|
|
|
_ -> false
|
2007-10-01 12:49:42 +02:00
|
|
|
end.
|
|
|
|
|
|
|
|
try_register(_User, _Server, _Password) ->
|
|
|
|
{error, not_allowed}.
|
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
dirty_get_registered_users() -> [].
|
|
|
|
|
|
|
|
get_vh_registered_users(_Host) -> [].
|
|
|
|
|
|
|
|
get_vh_registered_users(_Host, _) -> [].
|
2007-10-01 12:49:42 +02:00
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
get_vh_registered_users_number(_Host) -> 0.
|
2007-10-01 12:49:42 +02:00
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
get_vh_registered_users_number(_Host, _) -> 0.
|
2007-10-01 12:49:42 +02:00
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
get_password(_User, _Server) -> false.
|
|
|
|
|
|
|
|
get_password_s(_User, _Server) -> <<"">>.
|
2007-10-01 12:49:42 +02:00
|
|
|
|
2009-03-04 19:34:02 +01:00
|
|
|
%% @spec (User, Server) -> true | false | {error, Error}
|
|
|
|
%% TODO: Improve this function to return an error instead of 'false' when connection to PAM failed
|
2007-10-01 12:49:42 +02:00
|
|
|
is_user_exists(User, Host) ->
|
|
|
|
Service = get_pam_service(Host),
|
2010-05-07 22:34:59 +02:00
|
|
|
UserInfo = case get_pam_userinfotype(Host) of
|
2013-03-14 10:33:02 +01:00
|
|
|
username -> User;
|
|
|
|
jid -> <<User/binary, "@", Host/binary>>
|
|
|
|
end,
|
2010-05-07 22:34:59 +02:00
|
|
|
case catch epam:acct_mgmt(Service, UserInfo) of
|
2013-03-14 10:33:02 +01:00
|
|
|
true -> true;
|
|
|
|
_ -> false
|
2007-10-01 12:49:42 +02:00
|
|
|
end.
|
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
remove_user(_User, _Server) -> {error, not_allowed}.
|
2007-10-01 12:49:42 +02:00
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
remove_user(_User, _Server, _Password) -> not_allowed.
|
2007-10-01 12:49:42 +02:00
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
plain_password_required() -> true.
|
2007-10-01 12:49:42 +02:00
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
store_type() -> external.
|
2011-08-16 00:25:03 +02:00
|
|
|
|
2007-10-01 12:49:42 +02:00
|
|
|
%%====================================================================
|
|
|
|
%% Internal functions
|
|
|
|
%%====================================================================
|
|
|
|
get_pam_service(Host) ->
|
2013-08-12 14:25:05 +02:00
|
|
|
ejabberd_config:get_option(
|
2013-03-14 10:33:02 +01:00
|
|
|
{pam_service, Host},
|
|
|
|
fun iolist_to_binary/1,
|
|
|
|
<<"ejabberd">>).
|
|
|
|
|
2010-05-07 22:34:59 +02:00
|
|
|
get_pam_userinfotype(Host) ->
|
2013-08-12 14:25:05 +02:00
|
|
|
ejabberd_config:get_option(
|
2013-03-14 10:33:02 +01:00
|
|
|
{pam_userinfotype, Host},
|
|
|
|
fun(username) -> username;
|
|
|
|
(jid) -> jid
|
|
|
|
end,
|
|
|
|
username).
|