Skip to content

Commit

Permalink
Take other eldap_search_result cases into account
Browse files Browse the repository at this point in the history
Reported here
#4281 (reply in thread)

Fixes #4444

Follow-up to #4285
  • Loading branch information
lukebakken committed Apr 5, 2022
1 parent e73b52e commit 8d8847e
Showing 1 changed file with 28 additions and 8 deletions.
36 changes: 28 additions & 8 deletions deps/rabbitmq_auth_backend_ldap/src/rabbit_auth_backend_ldap.erl
Original file line number Diff line number Diff line change
Expand Up @@ -352,9 +352,15 @@ search_groups(LDAP, Desc, GroupsBase, Scope, DN) ->
[];
{ok, {referral, Referrals}} ->
{error, {referrals_not_supported, Referrals}};
{ok, #eldap_search_result{entries = []}} ->
%% support #eldap_search_result before and after
%% https://github.com/erlang/otp/pull/5538
{ok, {eldap_search_result, [], _Referrals}} ->
[];
{ok, #eldap_search_result{entries = Entries}} ->
{ok, {eldap_search_result, [], _Referrals, _Controls}}->
[];
{ok, {eldap_search_result, Entries, _Referrals}} ->
[ON || #eldap_entry{object_name = ON} <- Entries];
{ok, {eldap_search_result, Entries, _Referrals, _Controls}} ->
[ON || #eldap_entry{object_name = ON} <- Entries]
end.

Expand Down Expand Up @@ -438,7 +444,11 @@ object_exists(DN, Filter, LDAP) ->
{scope, eldap:baseObject()}]) of
{ok, {referral, Referrals}} ->
{error, {referrals_not_supported, Referrals}};
{ok, #eldap_search_result{entries = Entries}} ->
%% support #eldap_search_result before and after
%% https://github.com/erlang/otp/pull/5538
{ok, {eldap_search_result, Entries, _Referrals}} ->
length(Entries) > 0;
{ok, {eldap_search_result, Entries, _Referrals, _Controls}} ->
length(Entries) > 0;
{error, _} = E ->
E
Expand All @@ -451,9 +461,15 @@ attribute(DN, AttributeName, LDAP) ->
{attributes, [AttributeName]}]) of
{ok, {referral, Referrals}} ->
{error, {referrals_not_supported, Referrals}};
{ok, #eldap_search_result{entries = E = [#eldap_entry{}|_]}} ->
%% support #eldap_search_result before and after
%% https://github.com/erlang/otp/pull/5538
{ok, {eldap_search_result, E = [#eldap_entry{}|_], _Referrals}} ->
get_attributes(AttributeName, E);
{ok, #eldap_search_result{entries = _}} ->
{ok, {eldap_search_result, E = [#eldap_entry{}|_], _Referrals, _Controls}} ->
get_attributes(AttributeName, E);
{ok, {eldap_search_result, _Entries, _Referrals}} ->
{error, not_found};
{ok, {eldap_search_result, _Entries, _Referrals, _Controls}} ->
{error, not_found};
{error, _} = E ->
E
Expand Down Expand Up @@ -829,15 +845,19 @@ dn_lookup(Username, LDAP) ->
{attributes, ["distinguishedName"]}]) of
{ok, {referral, Referrals}} ->
{error, {referrals_not_supported, Referrals}};
%% support #eldap_search_result before and after
%% https://github.com/erlang/otp/pull/5538
%% support #eldap_search_result before and after
%% https://github.com/erlang/otp/pull/5538
{ok, {eldap_search_result, [#eldap_entry{object_name = DN}], _Referrals}}->
?L1("DN lookup: ~s -> ~s", [Username, DN]),
DN;
{ok, {eldap_search_result, [#eldap_entry{object_name = DN}], _Referrals, _Controls}}->
?L1("DN lookup: ~s -> ~s", [Username, DN]),
DN;
{ok, #eldap_search_result{entries = Entries}} ->
{ok, {eldap_search_result, Entries, _Referrals}} ->
rabbit_log_ldap:warning("Searching for DN for ~s, got back ~p",
[Filled, Entries]),
Filled;
{ok, {eldap_search_result, Entries, _Referrals, _Controls}} ->
rabbit_log_ldap:warning("Searching for DN for ~s, got back ~p",
[Filled, Entries]),
Filled;
Expand Down

0 comments on commit 8d8847e

Please sign in to comment.