mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-28 16:34:13 +01:00
Fix external authentication
This commit is contained in:
parent
167f02ab72
commit
aab70fc066
@ -70,28 +70,28 @@ get_process_name(Host, Integer) ->
|
||||
eauth).
|
||||
|
||||
check_password(User, Server, Password) ->
|
||||
call_port(Server, ["auth", User, Server, Password]).
|
||||
call_port(Server, [<<"auth">>, User, Server, Password]).
|
||||
|
||||
is_user_exists(User, Server) ->
|
||||
call_port(Server, ["isuser", User, Server]).
|
||||
call_port(Server, [<<"isuser">>, User, Server]).
|
||||
|
||||
set_password(User, Server, Password) ->
|
||||
call_port(Server, ["setpass", User, Server, Password]).
|
||||
call_port(Server, [<<"setpass">>, User, Server, Password]).
|
||||
|
||||
try_register(User, Server, Password) ->
|
||||
case call_port(Server,
|
||||
["tryregister", User, Server, Password])
|
||||
[<<"tryregister">>, User, Server, Password])
|
||||
of
|
||||
true -> {atomic, ok};
|
||||
false -> {error, not_allowed}
|
||||
end.
|
||||
|
||||
remove_user(User, Server) ->
|
||||
call_port(Server, ["removeuser", User, Server]).
|
||||
call_port(Server, [<<"removeuser">>, User, Server]).
|
||||
|
||||
remove_user(User, Server, Password) ->
|
||||
call_port(Server,
|
||||
["removeuser3", User, Server, Password]).
|
||||
[<<"removeuser3">>, User, Server, Password]).
|
||||
|
||||
call_port(Server, Msg) ->
|
||||
LServer = jlib:nameprep(Server),
|
||||
@ -154,13 +154,7 @@ flush_buffer_and_forward_messages(Pid) ->
|
||||
after 0 -> true
|
||||
end.
|
||||
|
||||
join(List, Sep) ->
|
||||
lists:foldl(fun (A, "") -> A;
|
||||
(A, Acc) -> Acc ++ Sep ++ A
|
||||
end,
|
||||
"", List).
|
||||
|
||||
encode(L) -> join(L, ":").
|
||||
encode(L) -> str:join(L, <<":">>).
|
||||
|
||||
decode([0, 0]) -> false;
|
||||
decode([0, 1]) -> true.
|
||||
|
@ -70,6 +70,7 @@
|
||||
-define(MYSQL_VHOST, <<"mysql.localhost">>).
|
||||
-define(PGSQL_VHOST, <<"pgsql.localhost">>).
|
||||
-define(LDAP_VHOST, <<"ldap.localhost">>).
|
||||
-define(EXTAUTH_VHOST, <<"extauth.localhost">>).
|
||||
|
||||
suite() ->
|
||||
[{timetrap, {seconds,10}}].
|
||||
@ -85,8 +86,10 @@ init_per_suite(Config) ->
|
||||
MnesiaDir = filename:join([PrivDir, "mnesia"]),
|
||||
CertFile = filename:join([DataDir, "cert.pem"]),
|
||||
LDIFFile = filename:join([DataDir, "ejabberd.ldif"]),
|
||||
ExtAuthScript = filename:join([DataDir, "extauth.py"]),
|
||||
{ok, CWD} = file:get_cwd(),
|
||||
{ok, _} = file:copy(CertFile, filename:join([CWD, "cert.pem"])),
|
||||
{ok, _} = file:copy(ExtAuthScript, filename:join([CWD, "extauth.py"])),
|
||||
application:set_env(ejabberd, config, ConfigPath),
|
||||
application:set_env(ejabberd, log_path, LogPath),
|
||||
application:set_env(sasl, sasl_error_logger, {file, SASLPath}),
|
||||
@ -136,6 +139,8 @@ init_per_group(pgsql, Config) ->
|
||||
end;
|
||||
init_per_group(ldap, Config) ->
|
||||
set_opt(server, ?LDAP_VHOST, Config);
|
||||
init_per_group(extauth, Config) ->
|
||||
set_opt(server, ?EXTAUTH_VHOST, Config);
|
||||
init_per_group(_GroupName, Config) ->
|
||||
Pid = start_event_relay(),
|
||||
set_opt(event_relay, Pid, Config).
|
||||
@ -150,6 +155,8 @@ end_per_group(no_db, _Config) ->
|
||||
ok;
|
||||
end_per_group(ldap, _Config) ->
|
||||
ok;
|
||||
end_per_group(extauth, _Config) ->
|
||||
ok;
|
||||
end_per_group(_GroupName, Config) ->
|
||||
stop_event_relay(Config),
|
||||
ok.
|
||||
@ -252,8 +259,14 @@ ldap_tests() ->
|
||||
[test_auth,
|
||||
vcard_get]}].
|
||||
|
||||
extauth_tests() ->
|
||||
[{extauth_tests, [sequence],
|
||||
[test_auth,
|
||||
test_unregister]}].
|
||||
|
||||
groups() ->
|
||||
[{ldap, [sequence], ldap_tests()},
|
||||
{extauth, [sequence], extauth_tests()},
|
||||
{no_db, [sequence], no_db_tests()},
|
||||
{mnesia, [sequence], db_tests()},
|
||||
{mysql, [sequence], db_tests()},
|
||||
@ -268,6 +281,7 @@ all() ->
|
||||
{group, mnesia},
|
||||
{group, mysql},
|
||||
{group, pgsql},
|
||||
{group, extauth},
|
||||
stop_ejabberd].
|
||||
|
||||
stop_ejabberd(Config) ->
|
||||
|
@ -3,6 +3,7 @@
|
||||
"mnesia.localhost",
|
||||
"mysql.localhost",
|
||||
"pgsql.localhost",
|
||||
"extauth.localhost",
|
||||
"ldap.localhost"]}.
|
||||
{define_macro, 'CERTFILE', "cert.pem"}.
|
||||
{listen,
|
||||
@ -59,6 +60,9 @@
|
||||
{mod_version, []}
|
||||
]}.
|
||||
{host_config, "localhost", [{auth_method, internal}]}.
|
||||
{host_config, "extauth.localhost",
|
||||
[{auth_method, external},
|
||||
{extauth_program, "python extauth.py"}]}.
|
||||
{host_config, "mnesia.localhost",
|
||||
[{auth_method, internal},
|
||||
{{add, modules}, [{mod_announce, [{db_type, internal}]},
|
||||
|
36
test/ejabberd_SUITE_data/extauth.py
Executable file
36
test/ejabberd_SUITE_data/extauth.py
Executable file
@ -0,0 +1,36 @@
|
||||
import sys
|
||||
import struct
|
||||
|
||||
def read():
|
||||
(pkt_size,) = struct.unpack('>H', sys.stdin.read(2))
|
||||
pkt = sys.stdin.read(pkt_size).split(':')
|
||||
cmd = pkt[0]
|
||||
args_num = len(pkt) - 1
|
||||
if cmd == 'auth' and args_num == 3:
|
||||
write(True)
|
||||
elif cmd == 'isuser' and args_num == 2:
|
||||
write(True)
|
||||
elif cmd == 'setpass' and args_num == 3:
|
||||
write(True)
|
||||
elif cmd == 'tryregister' and args_num == 3:
|
||||
write(True)
|
||||
elif cmd == 'removeuser' and args_num == 2:
|
||||
write(True)
|
||||
elif cmd == 'removeuser3' and args_num == 3:
|
||||
write(True)
|
||||
else:
|
||||
write(False)
|
||||
read()
|
||||
|
||||
def write(result):
|
||||
if result:
|
||||
sys.stdout.write('\x00\x02\x00\x01')
|
||||
else:
|
||||
sys.stdout.write('\x00\x02\x00\x00')
|
||||
sys.stdout.flush()
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
read()
|
||||
except struct.error:
|
||||
pass
|
Loading…
Reference in New Issue
Block a user