Skip to content

Commit 9df993f

Browse files
committed
Ensure server is converted to unicode charlist
1 parent c25f38f commit 9df993f

File tree

2 files changed

+75
-54
lines changed

2 files changed

+75
-54
lines changed

deps/rabbitmq_auth_backend_ldap_management/src/rabbit_auth_backend_ldap_mgmt.erl

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,15 @@ accept_content(ReqData0, Context) ->
4949
Port = safe_parse_int(maps:get(port, BodyMap, 389), "port"),
5050
UseSsl = safe_parse_bool(maps:get(use_ssl, BodyMap, false), "use_ssl"),
5151
UseStartTls = safe_parse_bool(maps:get(use_starttls, BodyMap, false), "use_starttls"),
52-
Servers = maps:get(servers, BodyMap, []),
52+
Servers = safe_parse_servers(BodyMap),
5353
UserDN = maps:get(user_dn, BodyMap, <<"">>),
5454
Password = maps:get(password, BodyMap, <<"">>),
5555
Options0 = [
5656
{port, Port},
5757
{timeout, 5000}
5858
],
5959
{ok, Options1} = maybe_add_ssl_options(Options0, UseSsl, BodyMap),
60+
ct:pal("@@@@ SERVES: ~tp",[Servers]),
6061
case eldap:open(Servers, Options1) of
6162
{ok, LDAP} ->
6263
Result = case maybe_starttls(LDAP, UseStartTls, BodyMap) of
@@ -178,8 +179,8 @@ tls_options(BodyMap) when is_map_key(ssl_options, BodyMap) ->
178179
TlsOpts2;
179180
Verify ->
180181
try
181-
VerifyStr = unicode:characters_to_list(Verify),
182-
[{verify, list_to_existing_atom(VerifyStr)} | TlsOpts2]
182+
VerifyStr = to_unicode(Verify),
183+
[{verify, binary_to_existing_atom(VerifyStr)} | TlsOpts2]
183184
catch
184185
error:badarg ->
185186
throw({bad_request, "invalid verify option passed to "
@@ -211,9 +212,10 @@ tls_options(BodyMap) when is_map_key(ssl_options, BodyMap) ->
211212
undefined ->
212213
TlsOpts5;
213214
VersionStrs when is_list(VersionStrs) ->
214-
F1 = fun (VStr) ->
215+
F1 = fun (VStr0) ->
215216
try
216-
{true, list_to_existing_atom(VStr)}
217+
VStr1 = to_unicode(VStr0),
218+
{true, binary_to_existing_atom(VStr1)}
217219
catch error:badarg ->
218220
throw({bad_request, "invalid TLS version passed to "
219221
"/ldap/validate/simple-bind ssl_options.versions"})
@@ -222,10 +224,10 @@ tls_options(BodyMap) when is_map_key(ssl_options, BodyMap) ->
222224
Versions = lists:filtermap(F1, VersionStrs),
223225
[{versions, Versions} | TlsOpts5]
224226
end,
225-
TlsOpts7 = case maps:get(<<"ssl_hostname_verification">>, SslOptionsMap, undefined) of
227+
TlsOpts7 = case to_unicode(maps:get(<<"ssl_hostname_verification">>, SslOptionsMap, undefined)) of
226228
undefined ->
227229
TlsOpts6;
228-
"wildcard" ->
230+
<<"wildcard">> ->
229231
[{customize_hostname_check, [{match_fun, public_key:pkix_verify_hostname_match_fun(https)}]} | TlsOpts6];
230232
_ ->
231233
throw({bad_request, "invalid value passed to "
@@ -235,6 +237,9 @@ tls_options(BodyMap) when is_map_key(ssl_options, BodyMap) ->
235237
tls_options(_BodyMap) ->
236238
{ok, []}.
237239

240+
to_unicode(Arg) ->
241+
rabbit_data_coercion:to_utf8_binary(Arg).
242+
238243
unicode_format(Arg) ->
239244
rabbit_data_coercion:to_utf8_binary(io_lib:format("~tp", [Arg])).
240245

@@ -246,6 +251,13 @@ format_password_for_logging(<<>>) ->
246251
format_password_for_logging(Password) ->
247252
io_lib:format("[~p characters]", [string:length(Password)]).
248253

254+
safe_parse_servers(BodyMap) when is_map(BodyMap) ->
255+
safe_parse_servers(maps:get(servers, BodyMap, []));
256+
safe_parse_servers(Servers) when is_list(Servers) ->
257+
[rabbit_data_coercion:to_unicode_charlist(S) || S <- Servers];
258+
safe_parse_servers(_) ->
259+
[].
260+
249261
safe_parse_int(Value, FieldName) ->
250262
try
251263
rabbit_mgmt_util:parse_int(Value)

0 commit comments

Comments
 (0)