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
|
|
|
%%%
|
|
|
|
%%%
|
2009-01-19 15:47:33 +01:00
|
|
|
%%% ejabberd, Copyright (C) 2002-2009 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-19 15:47:33 +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
|
|
|
|
%%%
|
2007-10-01 12:49:42 +02:00
|
|
|
%%%-------------------------------------------------------------------
|
|
|
|
-module(ejabberd_auth_pam).
|
|
|
|
-author('xram@jabber.ru').
|
|
|
|
|
|
|
|
%% External exports
|
|
|
|
-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_password/2,
|
|
|
|
get_password_s/2,
|
|
|
|
is_user_exists/2,
|
|
|
|
remove_user/2,
|
|
|
|
remove_user/3,
|
|
|
|
plain_password_required/0
|
|
|
|
]).
|
|
|
|
|
|
|
|
%%====================================================================
|
|
|
|
%% API
|
|
|
|
%%====================================================================
|
2009-02-05 12:13:01 +01:00
|
|
|
|
|
|
|
%% @spec (Host) -> ok | term()
|
|
|
|
%% Host = string()
|
|
|
|
|
2007-10-01 12:49:42 +02:00
|
|
|
start(_Host) ->
|
|
|
|
case epam:start() of
|
|
|
|
{ok, _} -> ok;
|
|
|
|
{error,{already_started, _}} -> ok;
|
|
|
|
Err -> Err
|
|
|
|
end.
|
|
|
|
|
2009-02-05 12:13:01 +01:00
|
|
|
%% @spec (User, Server, Password) -> {error, not_allowed}
|
|
|
|
%% User = string()
|
|
|
|
%% Server = string()
|
|
|
|
%% Password = string()
|
|
|
|
|
2007-10-01 12:49:42 +02:00
|
|
|
set_password(_User, _Server, _Password) ->
|
|
|
|
{error, not_allowed}.
|
|
|
|
|
2009-04-22 13:44:03 +02:00
|
|
|
%% @spec (User, Server, Password, Digest, DigestGen) -> bool()
|
2009-02-05 12:13:01 +01:00
|
|
|
%% User = string()
|
|
|
|
%% Server = string()
|
|
|
|
%% Password = string()
|
|
|
|
%% Digest = string()
|
2009-04-22 13:44:03 +02:00
|
|
|
%% DigestGen = function()
|
2009-02-05 12:13:01 +01:00
|
|
|
|
2007-10-01 12:49:42 +02:00
|
|
|
check_password(User, Server, Password, _StreamID, _Digest) ->
|
|
|
|
check_password(User, Server, Password).
|
|
|
|
|
2009-02-05 12:13:01 +01:00
|
|
|
%% @spec (User, Server, Password) -> bool()
|
|
|
|
%% User = string()
|
|
|
|
%% Server = string()
|
|
|
|
%% Password = string()
|
|
|
|
|
|
|
|
check_password(User, Server, Password) ->
|
|
|
|
Service = get_pam_service(Server),
|
2007-10-01 12:49:42 +02:00
|
|
|
case catch epam:authenticate(Service, User, Password) of
|
|
|
|
true -> true;
|
|
|
|
_ -> false
|
|
|
|
end.
|
|
|
|
|
2009-02-05 12:13:01 +01:00
|
|
|
%% @spec (User, Server, Password) -> {error, not_allowed}
|
|
|
|
%% User = string()
|
|
|
|
%% Server = string()
|
|
|
|
%% Password = string()
|
|
|
|
|
2007-10-01 12:49:42 +02:00
|
|
|
try_register(_User, _Server, _Password) ->
|
|
|
|
{error, not_allowed}.
|
|
|
|
|
2009-02-05 12:13:01 +01:00
|
|
|
%% @spec () -> [{LUser, LServer}]
|
|
|
|
%% LUser = string()
|
|
|
|
%% LServer = string()
|
|
|
|
|
2007-10-01 12:49:42 +02:00
|
|
|
dirty_get_registered_users() ->
|
|
|
|
[].
|
|
|
|
|
2009-02-05 12:13:01 +01:00
|
|
|
%% @spec (Server) -> [{LUser, LServer}]
|
|
|
|
%% Server = string()
|
|
|
|
%% LUser = string()
|
|
|
|
%% LServer = string()
|
|
|
|
|
|
|
|
get_vh_registered_users(_Server) ->
|
2007-10-01 12:49:42 +02:00
|
|
|
[].
|
|
|
|
|
2009-02-05 12:13:01 +01:00
|
|
|
%% @spec (User, Server) -> Password | false
|
|
|
|
%% User = string()
|
|
|
|
%% Server = string()
|
|
|
|
%% Password = string()
|
|
|
|
|
2007-10-01 12:49:42 +02:00
|
|
|
get_password(_User, _Server) ->
|
|
|
|
false.
|
|
|
|
|
2009-02-05 12:13:01 +01:00
|
|
|
%% @spec (User, Server) -> Password | nil()
|
|
|
|
%% User = string()
|
|
|
|
%% Server = string()
|
|
|
|
%% Password = string()
|
|
|
|
|
2007-10-01 12:49:42 +02:00
|
|
|
get_password_s(_User, _Server) ->
|
|
|
|
"".
|
|
|
|
|
2009-03-04 19:34:02 +01:00
|
|
|
%% @spec (User, Server) -> true | false | {error, Error}
|
2009-02-05 12:13:01 +01:00
|
|
|
%% User = string()
|
|
|
|
%% Server = string()
|
2009-03-04 19:34:02 +01:00
|
|
|
%% TODO: Improve this function to return an error instead of 'false' when
|
|
|
|
%% connection to PAM failed
|
2009-02-05 12:13:01 +01:00
|
|
|
|
|
|
|
is_user_exists(User, Server) ->
|
|
|
|
Service = get_pam_service(Server),
|
2007-10-01 12:49:42 +02:00
|
|
|
case catch epam:acct_mgmt(Service, User) of
|
|
|
|
true -> true;
|
|
|
|
_ -> false
|
|
|
|
end.
|
|
|
|
|
2009-02-05 12:13:01 +01:00
|
|
|
%% @spec (User, Server) -> {error, not_allowed}
|
|
|
|
%% User = string()
|
|
|
|
%% Server = string()
|
|
|
|
|
2007-10-01 12:49:42 +02:00
|
|
|
remove_user(_User, _Server) ->
|
|
|
|
{error, not_allowed}.
|
|
|
|
|
2009-02-05 12:13:01 +01:00
|
|
|
%% @spec (User, Server, Password) -> not_allowed
|
|
|
|
%% User = string()
|
|
|
|
%% Server = string()
|
|
|
|
%% Password = string()
|
|
|
|
|
2007-10-01 12:49:42 +02:00
|
|
|
remove_user(_User, _Server, _Password) ->
|
2009-01-19 11:14:04 +01:00
|
|
|
not_allowed.
|
2007-10-01 12:49:42 +02:00
|
|
|
|
2009-02-05 12:13:01 +01:00
|
|
|
%% @spec () -> bool()
|
|
|
|
|
2007-10-01 12:49:42 +02:00
|
|
|
plain_password_required() ->
|
|
|
|
true.
|
|
|
|
|
|
|
|
%%====================================================================
|
|
|
|
%% Internal functions
|
|
|
|
%%====================================================================
|
2009-02-05 12:13:01 +01:00
|
|
|
|
|
|
|
%% @spec (Server) -> string()
|
|
|
|
%% Server = string()
|
|
|
|
|
|
|
|
get_pam_service(Server) ->
|
|
|
|
case ejabberd_config:get_local_option({pam_service, Server}) of
|
2007-10-01 12:49:42 +02:00
|
|
|
undefined -> "ejabberd";
|
|
|
|
Service -> Service
|
|
|
|
end.
|