diff options
author | Alexey Shchepin <alexey@process-one.net> | 2004-07-30 21:09:55 +0000 |
---|---|---|
committer | Alexey Shchepin <alexey@process-one.net> | 2004-07-30 21:09:55 +0000 |
commit | 6cd02b971457219aa239d5f76dfb98c8e7fa397f (patch) | |
tree | c41fd747d55b8825d8e88f10aba0afa7a4723d98 /src/extauth.erl | |
parent | * src/tls/tls_drv.c: Added freeing of SSL stuff (diff) |
* examples/extauth/check_pass_null.pl: A reference "null"
implementation of external authentification script (thanks to Leif
Johansson)
* src/extauth.erl: Support for external authentification
(thanks to Leif Johansson)
* src/ejabberd_auth.erl: Likewise
* src/mod_vcard_ldap.erl: A drop-in replacement for mod_vcard.erl
which uses ldap for JUD and vCard (thanks to Leif Johansson)
SVN Revision: 251
Diffstat (limited to '')
-rw-r--r-- | src/extauth.erl | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/src/extauth.erl b/src/extauth.erl new file mode 100644 index 000000000..a7ac59fae --- /dev/null +++ b/src/extauth.erl @@ -0,0 +1,76 @@ +%%%---------------------------------------------------------------------- +%%% File : extauth.erl +%%% Author : Leif Johansson <leifj@it.su.se> +%%% Purpose : External authentication using a simple port-driver +%%% Created : 30 Jul 2004 by Leif Johansson <leifj@it.su.se> +%%% Id : $Id$ +%%%---------------------------------------------------------------------- + +-module(extauth). +-author('leifj@it.su.se'). + +-export([start/1, stop/0, init/1, + check_password/2, set_password/2, is_user_exists/1 ]). + + +start(ExtPrg) -> + spawn(?MODULE, init, [ExtPrg]). + +init(ExtPrg) -> + register(eauth,self()), + process_flag(trap_exit,true), + Port = open_port({spawn, ExtPrg}, [{packet,2}]), + loop(Port). + +stop() -> + eauth ! stop. + +check_password(User,Password) -> + call_port(["auth",User,Password]). + +is_user_exists(User) -> + call_port(["isuser",User]). + +set_password(User,Password) -> + call_port(["setpass",User,Password]). + +call_port(Msg) -> + eauth ! {call, self(), Msg}, + receive + {eauth,Result}-> + Result + end. + +loop(Port) -> + receive + {call, Caller, Msg} -> + Port ! {self(), {command, encode(Msg)}}, + receive + {Port, {data, Data}} -> + Caller ! {eauth, decode(Data)} + end, + loop(Port); + stop -> + Port ! {self(), close}, + receive + {Port, closed} -> + exit(normal) + end; + {'EXIT', Port, Reason} -> + io:format("~p ~n", [Reason]), + exit(port_terminated) + end. + +join(List, Sep) -> + lists:foldl(fun(A, "") -> A; + (A, Acc) -> Acc ++ Sep ++ A + end, "", List). + +encode(L) -> + join(L,":"). + +decode([0,0]) -> + false; +decode([0,1]) -> + true. + |