25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-22 16:20:52 +01:00

* src/aclocal.m4: Fixed headers detecting in AM_WITH_OPENSSL

(thanks to Leif Johansson)

* src/ejabberd_auth.erl: Added support for ldap_rootdn and
ldap_password options (thanks to Stefan de Konink)
* src/mod_vcard_ldap.erl: Likewise

* src/ejabberd_router.erl: Now possible to route packet via
function call instead of message sending
* src/ejabberd_sm.erl: Added function route/3, use it in route
table
* src/ejabberd_local.erl: Likewise
* src/ejabberd_s2s.erl: Likewise

* (all): Fixed spelling of word "authentication"

* src/*/Makefile.in: Replaced erlc with @ERLC@

SVN Revision: 285
This commit is contained in:
Alexey Shchepin 2004-11-05 21:14:31 +00:00
parent 7d683b194f
commit 2f7f3d9b00
19 changed files with 194 additions and 106 deletions

View File

@ -1,5 +1,32 @@
2004-11-05 Alexey Shchepin <alexey@sevcom.net>
* src/aclocal.m4: Fixed headers detecting in AM_WITH_OPENSSL
(thanks to Leif Johansson)
* src/ejabberd_auth.erl: Added support for ldap_rootdn and
ldap_password options (thanks to Stefan de Konink)
* src/mod_vcard_ldap.erl: Likewise
* src/ejabberd_router.erl: Now possible to route packet via
function call instead of message sending
* src/ejabberd_sm.erl: Added function route/3, use it in route
table
* src/ejabberd_local.erl: Likewise
* src/ejabberd_s2s.erl: Likewise
2004-10-23 Alexey Shchepin <alexey@sevcom.net>
* (all): Fixed spelling of word "authentication"
* src/*/Makefile.in: Replaced erlc with @ERLC@
2004-10-15 Alexey Shchepin <alexey@sevcom.net>
* src/ejabberd_s2s.erl: Added remove_connection/1
* src/ejabberd_s2s_out.erl: Use ejabberd_s2s:remove_connection/1
* src/ejabberd_s2s_in.erl: Minor cleanup
* examples/transport-configs/: Transport config examples (thanks
to Sander Devrieze)

View File

@ -116,7 +116,7 @@ The main features of \ejabberd{} are:
\item Built-in web-based administration interface
\item Built-in \tjepref{0025}{HTTP Polling} service
\item SSL support
\item Support for LDAP authentification
\item Support for LDAP authentication
\item Ability to interface with external components (JIT, MSN-t, Yahoo-t, etc.)
\item Migration from jabberd14 is possible
\item Mostly XMPP-compliant
@ -128,7 +128,7 @@ The main features of \ejabberd{} are:
The misfeatures of \ejabberd{} are:
\begin{itemize}
\item No support for virtual domains
\item No support for authentification and STARTTLS in S2S connections
\item No support for authentication and STARTTLS in S2S connections
\end{itemize}
@ -655,7 +655,7 @@ with such config:
}.
\end{verbatim}
you should enter URL \verb|http://example.org:5280/admin/|. After
authentification you should see something like in figure~\ref{fig:webadmmain}.
authentication you should see something like in figure~\ref{fig:webadmmain}.
\begin{figure}[htbp]
\centering
\insimg{webadmmain.png}

8
src/aclocal.m4 vendored
View File

@ -205,12 +205,16 @@ if test x"$tls" != x; then
SSL_LIBS="-L$ssl_prefix/lib -lcrypto"
AC_CHECK_LIB(ssl, SSL_new, [ have_openssl=yes ], [ have_openssl=no ], [ $SSL_LIBS $SSL_CFLAGS ])
if test x"$have_openssl" = xyes; then
AC_CHECK_HEADERS($ssl_prefix/include/openssl/ssl.h, have_openssl_h=yes)
save_CPPFLAGS=$CPPFLAGS
CPPFLAGS="-I$ssl_prefix/lib $CPPFLAGS"
AC_CHECK_HEADERS(openssl/ssl.h, have_openssl_h=yes)
CPPFLAGS=$save_CPPFLAGS
if test x"$have_openssl_h" = xyes; then
have_openssl=yes
printf "openssl found in $ssl_prefix\n";
SSL_LIBS="-L$ssl_prefix/lib -lssl -lcrypto"
SSL_CFLAGS="-I$ssl_prefix/include/openssl -DHAVE_SSL"
CPPFLAGS="-I$ssl_prefix/lib $CPPFLAGS"
SSL_CFLAGS="-DHAVE_SSL"
break
fi
fi

View File

@ -79,8 +79,10 @@ init([]) ->
ok;
ldap ->
LDAPServers = ejabberd_config:get_local_option(ldap_servers),
eldap:start_link("ejabberd", LDAPServers, 389, "", ""),
eldap:start_link("ejabberd_bind", LDAPServers, 389, "", "")
RootDN = ejabberd_config:get_local_option(ldap_rootdn),
Password = ejabberd_config:get_local_option(ldap_password),
eldap:start_link("ejabberd", LDAPServers, 389, RootDN, Password),
eldap:start_link("ejabberd_bind", LDAPServers, 389, RootDN, Password)
end,
{ok, #state{}}.

View File

@ -292,7 +292,7 @@ wait_for_auth({xmlstreamelement, El}, StateData) ->
U, P, StateData#state.streamid, D) of
true ->
?INFO_MSG(
"(~w) Accepted legacy authentification for ~s",
"(~w) Accepted legacy authentication for ~s",
[StateData#state.socket,
jlib:jid_to_string(JID)]),
ejabberd_sm:open_session(U, R),
@ -319,7 +319,7 @@ wait_for_auth({xmlstreamelement, El}, StateData) ->
privacy_list = PrivList}};
_ ->
?INFO_MSG(
"(~w) Failed legacy authentification for ~s",
"(~w) Failed legacy authentication for ~s",
[StateData#state.socket,
jlib:jid_to_string(JID)]),
Err = jlib:make_error_reply(
@ -331,7 +331,7 @@ wait_for_auth({xmlstreamelement, El}, StateData) ->
if
JID == error ->
?INFO_MSG(
"(~w) Forbidden legacy authentification for "
"(~w) Forbidden legacy authentication for "
"username '~s' with resource '~s'",
[StateData#state.socket, U, R]),
Err = jlib:make_error_reply(El, ?ERR_JID_MALFORMED),
@ -339,7 +339,7 @@ wait_for_auth({xmlstreamelement, El}, StateData) ->
{next_state, wait_for_auth, StateData};
true ->
?INFO_MSG(
"(~w) Forbidden legacy authentification for ~s",
"(~w) Forbidden legacy authentication for ~s",
[StateData#state.socket,
jlib:jid_to_string(JID)]),
Err = jlib:make_error_reply(El, ?ERR_NOT_ALLOWED),
@ -393,7 +393,7 @@ wait_for_feature_request({xmlstreamelement, El}, StateData) ->
{xmlelement, "success",
[{"xmlns", ?NS_SASL}], []}),
U = xml:get_attr_s(username, Props),
?INFO_MSG("(~w) Accepted authentification for ~s",
?INFO_MSG("(~w) Accepted authentication for ~s",
[StateData#state.socket, U]),
{next_state, wait_for_stream,
StateData#state{authentificated = true,
@ -469,7 +469,7 @@ wait_for_sasl_response({xmlstreamelement, El}, StateData) ->
{xmlelement, "success",
[{"xmlns", ?NS_SASL}], []}),
U = xml:get_attr_s(username, Props),
?INFO_MSG("(~w) Accepted authentification for ~s",
?INFO_MSG("(~w) Accepted authentication for ~s",
[StateData#state.socket, U]),
{next_state, wait_for_stream,
StateData#state{authentificated = true,

View File

@ -1,7 +1,7 @@
%%%----------------------------------------------------------------------
%%% File : ejabberd_local.erl
%%% Author : Alexey Shchepin <alexey@sevcom.net>
%%% Purpose :
%%% Purpose : Route local packets
%%% Created : 30 Nov 2002 by Alexey Shchepin <alexey@sevcom.net>
%%% Id : $Id$
%%%----------------------------------------------------------------------
@ -12,7 +12,8 @@
-export([start_link/0, init/0]).
-export([register_iq_handler/3,
-export([route/3,
register_iq_handler/3,
register_iq_handler/4,
unregister_iq_handler/1,
refresh_iq_handlers/0,
@ -22,7 +23,7 @@
-include("ejabberd.hrl").
-include("jlib.hrl").
-record(state, {mydomain, iqtable}).
-define(IQTABLE, local_iqtable).
start_link() ->
register(ejabberd_local,
@ -30,43 +31,41 @@ start_link() ->
{ok, Pid}.
init() ->
MyDomain = ?MYNAME,
ejabberd_router:register_route(MyDomain),
catch ets:new(local_iqtable, [named_table, public]),
ejabberd_router:register_route(?MYNAME, {apply, ?MODULE, route}),
catch ets:new(?IQTABLE, [named_table, public]),
ejabberd_hooks:add(local_send_to_resource_hook,
?MODULE, bounce_resource_packet, 100),
loop(#state{mydomain = MyDomain,
iqtable = local_iqtable}).
loop().
loop(State) ->
loop() ->
receive
{route, From, To, Packet} ->
case catch do_route(State, From, To, Packet) of
case catch do_route(From, To, Packet) of
{'EXIT', Reason} ->
?ERROR_MSG("~p~nwhen processing: ~p",
[Reason, {From, To, Packet}]);
_ ->
ok
end,
loop(State);
loop();
{register_iq_handler, XMLNS, Module, Function} ->
ets:insert(State#state.iqtable, {XMLNS, Module, Function}),
ets:insert(?IQTABLE, {XMLNS, Module, Function}),
catch mod_disco:register_feature(XMLNS),
loop(State);
loop();
{register_iq_handler, XMLNS, Module, Function, Opts} ->
ets:insert(State#state.iqtable, {XMLNS, Module, Function, Opts}),
ets:insert(?IQTABLE, {XMLNS, Module, Function, Opts}),
catch mod_disco:register_feature(XMLNS),
loop(State);
loop();
{unregister_iq_handler, XMLNS} ->
case ets:lookup(State#state.iqtable, XMLNS) of
case ets:lookup(?IQTABLE, XMLNS) of
[{_, Module, Function, Opts}] ->
gen_iq_handler:stop_iq_handler(Module, Function, Opts);
_ ->
ok
end,
ets:delete(State#state.iqtable, XMLNS),
ets:delete(?IQTABLE, XMLNS),
catch mod_disco:unregister_feature(XMLNS),
loop(State);
loop();
refresh_iq_handlers ->
lists:foreach(
fun(T) ->
@ -78,22 +77,24 @@ loop(State) ->
_ ->
ok
end
end, ets:tab2list(State#state.iqtable)),
loop(State);
end, ets:tab2list(?IQTABLE)),
loop();
_ ->
loop(State)
loop()
end.
do_route(State, From, To, Packet) ->
do_route(From, To, Packet) ->
?DEBUG("local route~n\tfrom ~p~n\tto ~p~n\tpacket ~P~n",
[From, To, Packet, 8]),
case To of
#jid{luser = "", lresource = ""} ->
if
To#jid.luser /= "" ->
ejabberd_sm:route(From, To, Packet);
To#jid.lresource == "" ->
{xmlelement, Name, Attrs, _Els} = Packet,
case Name of
"iq" ->
process_iq(State, From, To, Packet);
process_iq(From, To, Packet);
"message" ->
ok;
"presence" ->
@ -101,7 +102,7 @@ do_route(State, From, To, Packet) ->
_ ->
ok
end;
#jid{luser = "", lresource = Res} ->
true ->
{xmlelement, Name, Attrs, _Els} = Packet,
case xml:get_attr_s("type", Attrs) of
"error" -> ok;
@ -109,16 +110,14 @@ do_route(State, From, To, Packet) ->
_ ->
ejabberd_hooks:run(local_send_to_resource_hook,
[From, To, Packet])
end;
_ ->
ejabberd_sm ! {route, From, To, Packet}
end.
end
end.
process_iq(State, From, To, Packet) ->
process_iq(From, To, Packet) ->
IQ = jlib:iq_query_info(Packet),
case IQ of
#iq{xmlns = XMLNS} ->
case ets:lookup(State#state.iqtable, XMLNS) of
case ets:lookup(?IQTABLE, XMLNS) of
[{_, Module, Function}] ->
ResIQ = Module:Function(From, To, IQ),
if
@ -144,6 +143,15 @@ process_iq(State, From, To, Packet) ->
ok
end.
route(From, To, Packet) ->
case catch do_route(From, To, Packet) of
{'EXIT', Reason} ->
?ERROR_MSG("~p~nwhen processing: ~p",
[Reason, {From, To, Packet}]);
_ ->
ok
end.
register_iq_handler(XMLNS, Module, Fun) ->
ejabberd_local ! {register_iq_handler, XMLNS, Module, Fun}.

View File

@ -12,6 +12,7 @@
-export([route/3,
register_route/1,
register_route/2,
unregister_route/1,
dirty_get_all_routes/0,
dirty_get_all_domains/0
@ -22,15 +23,10 @@
-include("ejabberd.hrl").
-include("jlib.hrl").
-record(route, {domain, pid}).
-record(route, {domain, pid, local_hint}).
start_link() ->
Pid = proc_lib:spawn_link(ejabberd_router, init, []),
register(ejabberd_router, Pid),
{ok, Pid}.
init() ->
update_tables(),
mnesia:create_table(route,
[{ram_copies, [node()]},
@ -38,6 +34,11 @@ init() ->
{attributes,
record_info(fields, route)}]),
mnesia:add_table_copy(route, node(), ram_copies),
Pid = proc_lib:spawn_link(ejabberd_router, init, []),
register(ejabberd_router, Pid),
{ok, Pid}.
init() ->
mnesia:subscribe({table, route, simple}),
loop().
@ -52,20 +53,6 @@ loop() ->
ok
end,
loop();
{register_route, Domain, Pid} ->
F = fun() ->
mnesia:write(#route{domain = Domain,
pid = Pid})
end,
mnesia:transaction(F),
loop();
{unregister_route, Domain, Pid} ->
F = fun() ->
mnesia:delete_object(#route{domain = Domain,
pid = Pid})
end,
mnesia:transaction(F),
loop();
{mnesia_table_event, {write, #route{pid = Pid}, _ActivityId}} ->
erlang:monitor(process, Pid),
loop();
@ -91,31 +78,76 @@ do_route(From, To, Packet) ->
LDstDomain = To#jid.lserver,
case mnesia:dirty_read(route, LDstDomain) of
[] ->
ejabberd_s2s ! {route, From, To, Packet};
ejabberd_s2s:route(From, To, Packet);
[R] ->
Pid = R#route.pid,
?DEBUG("routed to process ~p~n", [Pid]),
Pid ! {route, From, To, Packet};
if
node(Pid) == node() ->
case R#route.local_hint of
{apply, Module, Function} ->
Module:Function(From, To, Packet);
_ ->
Pid ! {route, From, To, Packet}
end;
true ->
Pid ! {route, From, To, Packet}
end;
Rs ->
Rs1 = case [R || R <- Rs, node(R#route.pid) == node()] of
[] -> Rs;
LRs -> LRs
end,
R = lists:nth(erlang:phash(now(), length(Rs1)), Rs1),
Pid = R#route.pid,
?DEBUG("routed to process ~p~n", [Pid]),
Pid ! {route, From, To, Packet}
case [R || R <- Rs, node(R#route.pid) == node()] of
[] ->
R = lists:nth(erlang:phash(now(), length(Rs)), Rs),
Pid = R#route.pid,
Pid ! {route, From, To, Packet};
LRs ->
LRs,
R = lists:nth(erlang:phash(now(), length(LRs)), LRs),
Pid = R#route.pid,
case R#route.local_hint of
{apply, Module, Function} ->
Module:Function(From, To, Packet);
_ ->
Pid ! {route, From, To, Packet}
end
end
end.
%route(From, To, Packet) ->
% ejabberd_router ! {route, From, To, Packet}.
route(From, To, Packet) ->
ejabberd_router ! {route, From, To, Packet}.
case catch do_route(From, To, Packet) of
{'EXIT', Reason} ->
?ERROR_MSG("~p~nwhen processing: ~p",
[Reason, {From, To, Packet}]);
_ ->
ok
end.
register_route(Domain) ->
ejabberd_router ! {register_route, Domain, self()}.
Pid = self(),
F = fun() ->
mnesia:write(#route{domain = Domain,
pid = Pid})
end,
mnesia:transaction(F).
register_route(Domain, LocalHint) ->
Pid = self(),
F = fun() ->
mnesia:write(#route{domain = Domain,
pid = Pid,
local_hint = LocalHint})
end,
mnesia:transaction(F).
unregister_route(Domain) ->
ejabberd_router ! {unregister_route, Domain, self()}.
Pid = self(),
F = fun() ->
mnesia:delete_object(#route{domain = Domain,
pid = Pid})
end,
mnesia:transaction(F).
dirty_get_all_routes() ->
@ -131,6 +163,8 @@ update_tables() ->
[domain, node, pid] ->
mnesia:delete_table(route);
[domain, pid] ->
mnesia:delete_table(route);
[domain, pid, local_hint] ->
ok;
{'EXIT', _} ->
ok

View File

@ -11,9 +11,11 @@
-vsn('$Revision$ ').
-export([start_link/0, init/0,
route/3,
have_connection/1,
get_key/1,
try_register/1,
remove_connection/1,
dirty_get_connections/0]).
-include("ejabberd.hrl").
@ -29,17 +31,14 @@ start_link() ->
init() ->
update_tables(),
mnesia:create_table(s2s,[{ram_copies, [node()]},
{attributes, record_info(fields, s2s)}]),
mnesia:create_table(s2s, [{ram_copies, [node()]},
{attributes, record_info(fields, s2s)}]),
mnesia:add_table_copy(s2s, node(), ram_copies),
mnesia:subscribe(system),
loop().
loop() ->
receive
{closed_conection, FromTo} ->
remove_connection(FromTo),
loop();
{mnesia_system_event, {mnesia_down, Node}} ->
clean_table_from_bad_node(Node),
loop();
@ -57,6 +56,15 @@ loop() ->
end.
route(From, To, Packet) ->
case catch do_route(From, To, Packet) of
{'EXIT', Reason} ->
?ERROR_MSG("~p~nwhen processing: ~p",
[Reason, {From, To, Packet}]);
_ ->
ok
end.
remove_connection(FromTo) ->
F = fun() ->

View File

@ -311,14 +311,6 @@ handle_info(_, StateName, StateData) ->
%% Returns: any
%%----------------------------------------------------------------------
terminate(Reason, _StateName, StateData) ->
% case StateData#state.user of
% "" ->
% ok;
% _ ->
% %ejabberd_sm:close_session(StateData#state.user,
% % StateData#state.resource)
% end,
%ejabberd_s2s ! {closed_conection, StateData#state.server},
?INFO_MSG("terminated: ~p", [Reason]),
gen_tcp:close(StateData#state.socket),
ok.

View File

@ -397,8 +397,8 @@ terminate(Reason, StateName, StateData) ->
false ->
ok;
Key ->
ejabberd_s2s ! {closed_conection, {StateData#state.myname,
StateData#state.server}}
ejabberd_s2s:remove_connection({StateData#state.myname,
StateData#state.server})
end,
case StateData#state.socket of
undefined ->

View File

@ -10,7 +10,9 @@
-author('alexey@sevcom.net').
-vsn('$Revision$ ').
-export([start_link/0, init/0, open_session/2, close_session/2,
-export([start_link/0, init/0,
route/3,
open_session/2, close_session/2,
bounce_offline_message/3,
get_user_resources/1,
set_presence/3,
@ -89,11 +91,20 @@ loop() ->
end.
route(From, To, Packet) ->
case catch do_route(From, To, Packet) of
{'EXIT', Reason} ->
?ERROR_MSG("~p~nwhen processing: ~p",
[Reason, {From, To, Packet}]);
_ ->
ok
end.
open_session(User, Resource) ->
ejabberd_sm ! {open_session, User, Resource, self()}.
register_connection(User, Resource, self()).
close_session(User, Resource) ->
ejabberd_sm ! {close_session, User, Resource}.
remove_connection(User, Resource).
register_connection(User, Resource, Pid) ->

View File

@ -17,10 +17,10 @@ OBJS = \
all: $(OBJS)
ELDAPv3.erl: ELDAPv3.asn
erlc -bber_bin -W $(EFLAGS) $<
@ERLC@ -bber_bin -W $(EFLAGS) $<
$(OUTDIR)/%.beam: %.erl ELDAPv3.erl
erlc -W $(EFLAGS) -o $(OUTDIR) $<
@ERLC@ -W $(EFLAGS) -o $(OUTDIR) $<
clean:

View File

@ -20,7 +20,7 @@ OBJS = \
all: $(OBJS) $(ERLSHLIBS)
$(OUTDIR)/%.beam: %.erl
erlc -W $(EFLAGS) -o $(OUTDIR) $<
@ERLC@ -W $(EFLAGS) -o $(OUTDIR) $<
#all: $(ERLSHLIBS)
# erl -s make all report "{outdir, \"..\"}" -noinput -s erlang halt

View File

@ -17,7 +17,7 @@ OBJS = \
all: $(OBJS)
$(OUTDIR)/%.beam: %.erl
erlc -W $(EFLAGS) -o $(OUTDIR) $<
@ERLC@ -W $(EFLAGS) -o $(OUTDIR) $<
clean:
rm -f $(OBJS)

View File

@ -16,7 +16,7 @@ OBJS = \
all: $(OBJS)
$(OUTDIR)/%.beam: %.erl
erlc -W $(EFLAGS) -o $(OUTDIR) $<
@ERLC@ -W $(EFLAGS) -o $(OUTDIR) $<
clean:
rm -f $(OBJS)

View File

@ -29,7 +29,9 @@ start(Opts) ->
gen_iq_handler:add_iq_handler(ejabberd_sm, ?NS_VCARD,
?MODULE, process_sm_iq, IQDisc),
LDAPServers = ejabberd_config:get_local_option(ldap_servers),
eldap:start_link("mod_vcard_ldap", LDAPServers, 389, "", ""),
RootDN = ejabberd_config:get_local_option(ldap_rootdn),
Password = ejabberd_config:get_local_option(ldap_password),
eldap:start_link("mod_vcard_ldap", LDAPServers, 389, RootDN, Password),
Host = gen_mod:get_opt(host, Opts, "vjud." ++ ?MYNAME),
Search = gen_mod:get_opt(search, Opts, true),
register(ejabberd_mod_vcard_ldap, spawn(?MODULE, init, [Host, Search])).

View File

@ -18,7 +18,7 @@ OBJS = \
all: $(OBJS) $(ERLSHLIBS)
$(OUTDIR)/%.beam: %.erl
erlc -W $(EFLAGS) -o $(OUTDIR) $<
@ERLC@ -W $(EFLAGS) -o $(OUTDIR) $<
#all: $(ERLSHLIBS)
# erl -s make all report "{outdir, \"..\"}" -noinput -s erlang halt

View File

@ -18,7 +18,7 @@ OBJS = \
all: $(OBJS) $(ERLSHLIBS)
$(OUTDIR)/%.beam: %.erl
erlc -W $(EFLAGS) -o $(OUTDIR) $<
@ERLC@ -W $(EFLAGS) -o $(OUTDIR) $<
#all: $(ERLSHLIBS)
# erl -s make all report "{outdir, \"..\"}" -noinput -s erlang halt

View File

@ -20,7 +20,7 @@ OBJS = \
all: $(OBJS)
$(OUTDIR)/%.beam: %.erl
erlc -W $(EFLAGS) -o $(OUTDIR) $<
@ERLC@ -W $(EFLAGS) -o $(OUTDIR) $<
clean: