Skip to content

Commit 7a7bcc3

Browse files
LDAP plugin: handle undefined app env values, pass Dialyzer
(cherry picked from commit 66badb9)
1 parent ee51c41 commit 7a7bcc3

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

deps/rabbitmq_auth_backend_ldap/src/rabbit_auth_backend_ldap.erl

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -706,18 +706,19 @@ eldap_open(Servers, Opts) ->
706706
ssl_conf() ->
707707
%% We must make sure not to add SSL options unless a) we have at least R16A
708708
%% b) we have SSL turned on (or it breaks StartTLS...)
709-
case env(use_ssl) of
709+
case env(use_ssl, false) of
710710
false -> [{ssl, false}];
711711
true -> %% Only the unfixed version can be []
712712
case env(ssl_options) of
713-
[] -> [{ssl, true}];
714-
_ -> [{ssl, true}, {sslopts, ssl_options()}]
713+
[] -> [{ssl, true}];
714+
undefined -> [{ssl, true}];
715+
_ -> [{ssl, true}, {sslopts, ssl_options()}]
715716
end
716717
end.
717718

718719
ssl_options() ->
719720
Opts0 = rabbit_networking:fix_ssl_options(env(ssl_options)),
720-
case env(ssl_hostname_verification) of
721+
case env(ssl_hostname_verification, undefined) of
721722
wildcard ->
722723
rabbit_log_ldap:debug("Enabling wildcard-aware hostname verification for LDAP client connections"),
723724
%% Needed for non-HTTPS connections that connect to servers that use wildcard certificates.
@@ -745,8 +746,13 @@ get_expected_env_str(Key, Default) ->
745746
rabbit_data_coercion:to_list(V).
746747

747748
env(Key) ->
748-
{ok, V} = application:get_env(rabbitmq_auth_backend_ldap, Key),
749-
V.
749+
case application:get_env(rabbitmq_auth_backend_ldap, Key) of
750+
{ok, V} -> V;
751+
undefined -> undefined
752+
end.
753+
754+
env(Key, Default) ->
755+
application:get_env(rabbitmq_auth_backend_ldap, Key, Default).
750756

751757
login_fun(User, UserDN, Password, AuthProps) ->
752758
fun(L) -> case pget(vhost, AuthProps) of
@@ -897,17 +903,12 @@ scrub_rdn([DN|Rem], Acc) ->
897903
scrub_rdn(Rem, [string:join(DN0, "=")|Acc]).
898904

899905
is_dn(S) when is_list(S) ->
900-
case catch string:tokens(to_list(S), "=") of
906+
case catch string:tokens(rabbit_data_coercion:to_list(S), "=") of
901907
L when length(L) > 1 -> true;
902908
_ -> false
903909
end;
904910
is_dn(_S) -> false.
905911

906-
to_list(S) when is_list(S) -> S;
907-
to_list(S) when is_binary(S) -> binary_to_list(S);
908-
to_list(S) when is_atom(S) -> atom_to_list(S);
909-
to_list(S) -> {error, {badarg, S}}.
910-
911912
log(Fmt, Args) -> case env(log) of
912913
false -> ok;
913914
_ -> rabbit_log_ldap:info(Fmt ++ "~n", Args)

0 commit comments

Comments
 (0)