Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ jobs:
with:
packages: libexpat1-dev libgd-dev libpam0g-dev
libsqlite3-dev libwebp-dev libyaml-dev
unixodbc-dev

- name: Cache rebar3
uses: actions/cache@v5
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/runtime.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ jobs:
run: |
apt-get -qq update
apt-get -q -y install libexpat1-dev libgd-dev libpam0g-dev \
libsqlite3-dev libwebp-dev libyaml-dev
libsqlite3-dev libwebp-dev libyaml-dev \
unixodbc-dev

- name: Cache rebar3
if: matrix.rebar == 'rebar3'
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/weekly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ jobs:
with:
packages: libexpat1-dev libgd-dev libpam0g-dev
libsqlite3-dev libwebp-dev libyaml-dev
unixodbc-dev

- name: Get recent compatible Rebar binaries
if: matrix.otp < 26
Expand Down
123 changes: 123 additions & 0 deletions include/ejabberd_catch.hrl
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
%%%----------------------------------------------------------------------
%%%
%%% ejabberd, Copyright (C) 2002-2026 ProcessOne
%%%
%%% 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.
%%%
%%% 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.
%%%
%%%----------------------------------------------------------------------

%% This uses Macros Overloading, see
%% https://www.erlang.org/doc/system/macros.html#macros-overloading

%% @format-begin

-define(CATCH_MFA(Module, Function, Arguments),
try apply(Module, Function, Arguments)
catch
TCX:TCY ->
?WARNING_MSG("Catched exception~n in: ~p:~p/~p (line ~p)~n"
" calling: ~p:~p~p~n catched: ~p:~p",
[?MODULE, ?FUNCTION_NAME, ?FUNCTION_ARITY, ?LINE,
Module, Function, Arguments, TCX, TCY]),
{TCX, TCY}
end).

-define(CATCH_TRY(Function, A1),
try Function(A1)
catch
TCX:TCY ->
?WARNING_MSG("Catched exception~n in: ~p:~p/~p (line ~p)~n"
" calling: ~p(~p)~n catched: ~p:~p",
[?MODULE, ?FUNCTION_NAME, ?FUNCTION_ARITY, ?LINE,
Function, A1, TCX, TCY]),
{TCX, TCY}
end).

-define(CATCH_TRY(Function, A1, A2),
try Function(A1, A2)
catch
TCX:TCY ->
?WARNING_MSG("Catched exception~n in: ~p:~p/~p (line ~p)~n"
" calling: ~p(~p, ~p)~n catched: ~p:~p",
[?MODULE, ?FUNCTION_NAME, ?FUNCTION_ARITY, ?LINE,
Function, A1, A2, TCX, TCY]),
{TCX, TCY}
end).

-define(CATCH_TRY(Function, A1, A2, A3),
try Function(A1, A2, A3)
catch
TCX:TCY ->
?WARNING_MSG("Catched exception~n in: ~p:~p/~p (line ~p)~n"
" calling: ~p(~p, ~p, ~p)~n catched: ~p:~p",
[?MODULE, ?FUNCTION_NAME, ?FUNCTION_ARITY, ?LINE,
Function, A1, A2, A3, TCX, TCY]),
{TCX, TCY}
end).

-define(CATCH_TRY(Function, A1, A2, A3, A4),
try Function(A1, A2, A3, A4)
catch
TCX:TCY ->
?WARNING_MSG("Catched exception~n in: ~p:~p/~p (line ~p)~n"
" calling: ~p(~p, ~p, ~p, ~p)~n catched: ~p:~p",
[?MODULE, ?FUNCTION_NAME, ?FUNCTION_ARITY, ?LINE,
Function, A1, A2, A3, A4, TCX, TCY]),
{TCX, TCY}
end).

-define(CATCH_TRY(Function, A1, A2, A3, A4, A5),
try Function(A1, A2, A3, A4, A5)
catch
TCX:TCY ->
?WARNING_MSG("Catched exception~n in: ~p:~p/~p (line ~p)~n"
" calling: ~p(~p, ~p, ~p, ~p, ~p)~n catched: ~p:~p",
[?MODULE, ?FUNCTION_NAME, ?FUNCTION_ARITY, ?LINE,
Function, A1, A2, A3, A4, A5, TCX, TCY]),
{TCX, TCY}
end).

-define(CATCH_TRY(Function, A1, A2, A3, A4, A5, A6),
try Function(A1, A2, A3, A4, A5, A6)
catch
TCX:TCY ->
?WARNING_MSG("Catched exception~n in: ~p:~p/~p (line ~p)~n"
" calling: ~p(~p, ~p, ~p, ~p, ~p, ~p)~n catched: ~p:~p",
[?MODULE, ?FUNCTION_NAME, ?FUNCTION_ARITY, ?LINE,
Function, A1, A2, A3, A4, A5, A6, TCX, TCY]),
{TCX, TCY}
end).

-define(CATCH_TRY(Function, A1, A2, A3, A4, A5, A6, A7),
try Function(A1, A2, A3, A4, A5, A6, A7)
catch
TCX:TCY ->
?WARNING_MSG("Catched exception~n in: ~p:~p/~p (line ~p)~n"
" calling: ~p(~p, ~p, ~p, ~p, ~p, ~p, ~p)~n catched: ~p:~p",
[?MODULE, ?FUNCTION_NAME, ?FUNCTION_ARITY, ?LINE,
Function, A1, A2, A3, A4, A5, A6, A7, TCX, TCY]),
{TCX, TCY}
end).

-define(CATCH_TRY(Function, A1, A2, A3, A4, A5, A6, A7, A8),
try Function(A1, A2, A3, A4, A5, A6, A7, A8)
catch
TCX:TCY ->
?WARNING_MSG("Catched exception~n in: ~p:~p/~p (line ~p)~n"
" calling: ~p(~p, ~p, ~p, ~p, ~p, ~p, ~p, ~p)~n catched: ~p:~p",
[?MODULE, ?FUNCTION_NAME, ?FUNCTION_ARITY, ?LINE,
Function, A1, A2, A3, A4, A5, A6, A7, A8, TCX, TCY]),
{TCX, TCY}
end).
15 changes: 13 additions & 2 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,23 @@ defmodule Ejabberd.MixProject do
if :erlang.system_info(:otp_release) > ver do
okResult
else
[]
if :erlang.is_boolean(okResult) do
not okResult
else
[]
end
end
end

defp if_version_below(ver, okResult) do
if :erlang.system_info(:otp_release) < ver do
okResult
else
[]
if :erlang.is_boolean(okResult) do
not okResult
else
[]
end
end
end

Expand Down Expand Up @@ -151,6 +159,9 @@ defmodule Ejabberd.MixProject do
{if_version_above(~c"25", true), {:jose, "~> 1.11.12"}},
{config(:lua), {:luerl, "~> 1.2.0"}},
{config(:mysql), {:p1_mysql, ">= 1.0.28"}},
{if_version_above(~c"28", true) and config(:odbc),
{:odbc, "~> 2.17.1", hex: :erlang_otp_odbc}
},
{config(:pgsql), {:p1_pgsql, ">= 1.1.38"}},
{config(:sqlite), {:sqlite3, "~> 1.1"}},
{config(:stun), {:stun, "~> 1.0"}}], do:
Expand Down
6 changes: 5 additions & 1 deletion rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@
{luerl, "~> 1.2.0", {git, "https://github.com/rvirding/luerl", {tag, "1.2"}}}
},
{mqtree, "~> 1.0.19", {git, "https://github.com/processone/mqtree", {tag, "1.0.20"}}},
{if_version_above, "28",
{if_var_true, odbc,
{if_rebar3,
{odbc, {package, erlang_otp_odbc, "~> 2.17.1"}, {git, "https://github.com/rnowak/erlang-otp-odbc", {tag, "v2.17.1"}}}
}}},
{p1_acme, "~> 1.0.30", {git, "https://github.com/processone/p1_acme", {tag, "1.0.31"}}},
{if_var_true, mysql,
{p1_mysql, "~> 1.0.28", {git, "https://github.com/processone/p1_mysql", {tag, "1.0.28"}}}},
Expand Down Expand Up @@ -119,7 +124,6 @@
{if_version_below, "27", {d, 'OTP_BELOW_27'}},
{if_version_below, "27", {feature, maybe_expr, enable}},
{if_version_below, "28", {d, 'OTP_BELOW_28'}},
{if_version_above, "28", nowarn_deprecated_catch},
{if_var_false, debug, no_debug_info},
{if_var_true, debug, debug_info},
{if_var_true, elixir, {d, 'ELIXIR_ENABLED'}},
Expand Down
22 changes: 15 additions & 7 deletions rebar.config.script
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ AppendList2 = fun(Append) ->
% https://github.com/rebar/rebar/wiki/Dependency-management
Rebar2DepsFilter =
fun(DepsList, GitOnlyDeps) ->
lists:map(fun({DepName, _HexVersion, Source}) ->
lists:map(fun({DepName, _HexPackage, Source}) ->
{DepName, ".*", Source}
end, DepsList)
end,
Expand All @@ -233,14 +233,22 @@ end,
% https://hexdocs.pm/elixir/Version.html
Rebar3DepsFilter =
fun(DepsList, GitOnlyDeps) ->
lists:map(fun({DepName, HexVersion, {git, _, {tag, GitVersion}} = Source}) ->
case {lists:member(DepName, GitOnlyDeps), HexVersion == ".*"} of
{true, _} ->
lists:map(fun({DepName, HexPackageVersion, {git, _, {tag, GitVersion}} = Source}) ->
{HexPackage, HexVersion} = case HexPackageVersion of
HV when is_list(HV) -> {false, HV};
{package, HP, HV} -> {HP, HV}
end,
case {lists:member(DepName, GitOnlyDeps),
HexPackage,
HexVersion == ".*"} of
{true, _, _} ->
{DepName, ".*", Source};
{false, true} ->
{false, _, true} ->
{DepName, GitVersion};
{false, false} ->
{DepName, HexVersion}
{false, false, false} ->
{DepName, HexVersion};
{false, PkgName, false} ->
{DepName, HexVersion, {pkg, PkgName}}
end;
({DepName, _HexVersion, Source}) ->
{DepName, ".*", Source}
Expand Down
22 changes: 12 additions & 10 deletions src/ELDAPv3.erl
Original file line number Diff line number Diff line change
Expand Up @@ -129,25 +129,27 @@ encoding_rule() -> ber.
bit_string_format() -> bitstring.

encode(Type,Data) ->
case catch encode_disp(Type,Data) of
{'EXIT',{error,Reason}} ->
{error,Reason};
{'EXIT',Reason} ->
{error,{asn1,Reason}};
try encode_disp(Type,Data) of
{Bytes,_Len} ->
{ok,iolist_to_binary(Bytes)};
Bytes ->
{ok,iolist_to_binary(Bytes)}
catch
_:{error,Reason} ->
{error,Reason};
_:Reason ->
{error,{asn1,Reason}}
end.

decode(Type,Data) ->
case catch decode_disp(Type,element(1, ber_decode_nif(Data))) of
{'EXIT',{error,Reason}} ->
{error,Reason};
{'EXIT',Reason} ->
{error,{asn1,Reason}};
try decode_disp(Type,element(1, ber_decode_nif(Data))) of
Result ->
{ok,Result}
catch
_:{error,Reason} ->
{error,Reason};
_:Reason ->
{error,{asn1,Reason}}
end.

encode_disp('LDAPMessage',Data) -> 'enc_LDAPMessage'(Data);
Expand Down
3 changes: 2 additions & 1 deletion src/ejabberd_admin.erl
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
web_menu_node/3, web_page_node/3]).

-include_lib("xmpp/include/xmpp.hrl").
-include("ejabberd_catch.hrl").
-include("ejabberd_commands.hrl").
-include("ejabberd_http.hrl").
-include("ejabberd_web_admin.hrl").
Expand Down Expand Up @@ -839,7 +840,7 @@ perform_kindly(DelaySeconds, AnnouncementTextString, Action) ->
io:format("~s[~p/~p ~ps]~s ~ts...~s ",
[?CLEAD ++ ?CINFO, NumberThis, NumberLast, SecondsDiff,
?CMID ++ ?CINFO, Desc, ?CCLEAN]),
Result = (catch apply(Mod, Func, Args)),
Result = ?CATCH_TRY(apply, Mod, Func, Args),
io:format("~p~n", [Result]),
NumberThis + 1
end,
Expand Down
4 changes: 3 additions & 1 deletion src/ejabberd_app.erl
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,11 @@ print_distribution_listening() ->
end,
{Addr, Port} = lists:foldl(
fun(Link, Acc) ->
case catch inet:sockname(Link) of
try inet:sockname(Link) of
{ok, {A1, P1}} -> {misc:ip_to_list(A1), P1};
_ -> Acc
catch
_:_ -> Acc
end
end, {"UnknownAddress", "UnknownPort"}, Links),
?INFO_MSG("Start accepting TCP connections at ~ts:~p for erlang distribution", [Addr, Port]).
16 changes: 9 additions & 7 deletions src/ejabberd_auth_ldap.erl
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,10 @@ check_password(User, AuthzId, Server, Password) ->
Password == <<"">> ->
{nocache, false};
true ->
case catch check_password_ldap(User, Server, Password) of
{'EXIT', _} -> {nocache, false};
try check_password_ldap(User, Server, Password) of
Result -> {cache, Result}
catch
_:_ -> {nocache, false}
end
end.

Expand All @@ -143,18 +144,19 @@ set_password(User, Server, Password) ->
end.

get_users(Server, []) ->
case catch get_users_ldap(Server) of
{'EXIT', _} -> [];
Result -> Result
try get_users_ldap(Server)
catch
_:_ -> []
end.

count_users(Server, Opts) ->
length(get_users(Server, Opts)).

user_exists(User, Server) ->
case catch user_exists_ldap(User, Server) of
{'EXIT', _Error} -> {nocache, {error, db_failure}};
try user_exists_ldap(User, Server) of
Result -> {cache, Result}
catch
_:_Error -> {nocache, {error, db_failure}}
end.

%%%----------------------------------------------------------------------
Expand Down
14 changes: 8 additions & 6 deletions src/ejabberd_auth_pam.erl
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,11 @@ check_password(User, AuthzId, Host, Password) ->
username -> User;
jid -> <<User/binary, "@", Host/binary>>
end,
case catch epam:authenticate(Service, UserInfo, Password) of
try epam:authenticate(Service, UserInfo, Password) of
true -> {cache, true};
false -> {cache, false};
_ -> {nocache, false}
false -> {cache, false}
catch
_:_ -> {nocache, false}
end
end.

Expand All @@ -59,10 +60,11 @@ user_exists(User, Host) ->
username -> User;
jid -> <<User/binary, "@", Host/binary>>
end,
case catch epam:acct_mgmt(Service, UserInfo) of
try epam:acct_mgmt(Service, UserInfo) of
true -> {cache, true};
false -> {cache, false};
_Err -> {nocache, {error, db_failure}}
false -> {cache, false}
catch
_:_Err -> {nocache, {error, db_failure}}
end.

plain_password_required(_) -> true.
Expand Down
Loading
Loading