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
|
|
|
%%%
|
|
|
|
%%%
|
2019-01-08 22:53:27 +01:00
|
|
|
%%% ejabberd, Copyright (C) 2002-2019 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
|
|
|
|
2017-05-11 13:37:21 +02:00
|
|
|
-export([start/1, stop/1, check_password/4,
|
2019-06-14 11:33:26 +02:00
|
|
|
user_exists/2, store_type/1, plain_password_required/1]).
|
2013-03-14 10:33:02 +01:00
|
|
|
|
2007-10-01 12:49:42 +02:00
|
|
|
start(_Host) ->
|
2017-01-29 14:35:22 +01:00
|
|
|
ejabberd:start_app(epam).
|
2007-10-01 12:49:42 +02:00
|
|
|
|
2017-02-23 14:19:22 +01:00
|
|
|
stop(_Host) ->
|
|
|
|
ok.
|
|
|
|
|
2015-04-09 03:21:09 +02:00
|
|
|
check_password(User, AuthzId, Host, Password) ->
|
|
|
|
if AuthzId /= <<>> andalso AuthzId /= User ->
|
2019-06-30 16:15:43 +02:00
|
|
|
false;
|
|
|
|
true ->
|
|
|
|
Service = get_pam_service(Host),
|
|
|
|
UserInfo = case get_pam_userinfotype(Host) of
|
|
|
|
username -> User;
|
|
|
|
jid -> <<User/binary, "@", Host/binary>>
|
|
|
|
end,
|
|
|
|
case catch epam:authenticate(Service, UserInfo, Password) of
|
|
|
|
true -> {cache, true};
|
|
|
|
false -> {cache, false};
|
|
|
|
_ -> {nocache, false}
|
|
|
|
end
|
2007-10-01 12:49:42 +02:00
|
|
|
end.
|
|
|
|
|
2017-05-11 14:49:06 +02:00
|
|
|
user_exists(User, Host) ->
|
2007-10-01 12:49:42 +02:00
|
|
|
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
|
2019-06-30 16:15:43 +02:00
|
|
|
true -> {cache, true};
|
|
|
|
false -> {cache, false};
|
|
|
|
_Err -> {nocache, {error, db_failure}}
|
2007-10-01 12:49:42 +02:00
|
|
|
end.
|
|
|
|
|
2017-05-11 13:37:21 +02:00
|
|
|
plain_password_required(_) -> true.
|
2007-10-01 12:49:42 +02:00
|
|
|
|
2017-05-11 13:37:21 +02: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) ->
|
2019-06-14 11:33:26 +02:00
|
|
|
ejabberd_option:pam_service(Host).
|
2013-03-14 10:33:02 +01:00
|
|
|
|
2010-05-07 22:34:59 +02:00
|
|
|
get_pam_userinfotype(Host) ->
|
2019-06-14 11:33:26 +02:00
|
|
|
ejabberd_option:pam_userinfotype(Host).
|