-
Notifications
You must be signed in to change notification settings - Fork 3k
Add support for paged search results to LDAP #5538
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand it as only a spontaneous paged result return on a normal search request is covered.
Is it possible to send a search request asking for a paged result or asking for further pages?
Maybe a few lines in the manual or at least a comment section with an example in the code would help. (I am aware of that the manual is far from complete in its present state.)
| -- LDAP Control Extension for Simple Paged Results Manipulation | ||
| -- https://www.rfc-editor.org/rfc/rfc2696.txt | ||
| -- controlType 1.2.840.113556.1.4.319 | ||
|
|
||
| PagedResultsControl ::= SEQUENCE { | ||
| size INTEGER (0..maxInt), | ||
| -- requested page size from client | ||
| -- result set size estimate from server | ||
| cookie OCTET STRING | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In RFC 2696 this record is called realSearchControlValue and PagedResultsControl is different.
Why rename it? Changing the naming could make future updates impossible without breaking compatibility.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A simple test case would be good to, if possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In RFC 2696 this record is called
realSearchControlValueandPagedResultsControlis different.
Why rename it
Good question. I think because the original name realSearchControlValue didn't make much sense to me - no mention of paging and the weird "real" prefix...
I'll revert to the original name if you think it has maintainability advantages.
A simple test case would be good to, if possible.
Sure
As far as I know, no spontaneous paged result are ever returned if not asked for. To ask to a paged result the The flow is to start a search request with the pageControl control and the empty cookie. Then get the cookie from the pagedResultsControl, check if equals zero (no more pages), continue to perform the very same search by just updating the cookie (the cookie is a sort of an opaque cursor), until is zero. Just to make it clearer, here's some pseudo (elixir, sorry!) code to understand the flow: defmodule LdapClient do
@pageControl '1.2.840.113556.1.4.319'
def run do
{:ok, handle} = :eldap.open(['192.168.56.10'], [])
search_opts = [
base: 'dc=192,dc=168,dc=56,dc=10,dc=base',
filter: :eldap.present('uid'),
scope: :eldap.wholeSubtree()
]
{:done, pages} = do_search(handle, search_opts, [])
end
defp do_search(handle, search_opts, pages) do
{:ok, results} = :eldap.search(handle, search_opts, build_controls())
{:eldap_search_result, _results, _ref, controls} = results # not ideal, just for quick data extraction from record
next_cookie = decode_cookie(controls)
do_search(handle, search_opts, [results | pages], next_cookie)
end
defp do_search(_handle, _search_opts, pages, cookie) when cookie == "" or is_nil(cookie) do
{:done, pages}
end
defp do_search(handle, search_opts, pages, cookie) do
{:ok, results} = :eldap.search(handle, search_opts, build_controls(cookie))
{:eldap_search_result, _results, _ref, controls} = results
next_cookie = decode_cookie(controls)
do_search(handle, search_opts, [results | pages], next_cookie)
end
defp decode_cookie(controls) do
# skipping this fun for clarity, but basically returns a string or nil if no control are present
# or cookie is set to empty by the server, which means we reached the end of pages
...
end
def build_controls(cookie \\ '') do
{:ok, value} = :ELDAPv3.encode(:PagedResultsControl, {:PagedResultsControl, 1, cookie})
[{:control, @pageControl, true, value}]
end
end--- updated comment to reuse PagedResultsControl istead of my local encoder --- |
|
additional note about the asn1 definition: while I'm with @magnetised for the weird naming and suggest to use just Example: |
|
I've added a test case and as a result included a few helper functions in the eldap module to make usage much easier. The usage is now something like: PageSize = 10,
Control1 = eldap:paged_result_control(PageSize),
{ok, SearchResult1} = eldap:search(H, #eldap_search{...}, [Control1]),
{ok, Cookie1} = eldap:paged_result_cookie(SearchResult1),
Control2 = eldap:paged_result_control(PageSize, Cookie1),
{ok, SearchResult2} = eldap:search(H, #eldap_search{...}, [Control2]),
%% etcHappy to rename the control - With the functions wrapping the encoding-decoding of the actual control it isn't particularly user-facing anymore so being true-ish to the spec is maybe the best way to go. Regarding the |
Happy to add to the manual once the api is approved/agreed |
Btw, for what it's worth I like those helpers and is exactly the same thing I was doing before discovering this PR. Also exposing resultControls to the caller make it easier to add stuff without necessarily extending :eldap, like the above mentioned sort Control. |
|
@HansN I see the move to "stalled" but don't know what's holding this back. Are you waiting for docs, or a rename? I was waiting on some feedback before moving ahead (i.e. are you happy with the name of the control value? is the "extended" api ok?) |
|
@magnetised what is missing is simply my time. Today is first working day after my christmas vacation and there are other tasks with higher priority. |
|
Hi @magnetised, |
5916c8e to
8436ff4
Compare
CT Test ResultsNo tests were run for this PR. This is either because the build failed, or the PR is based on a branch without GH actions tests configured. Results for commit 3b7f350 To speed up review, make sure that you have read Contributing to Erlang/OTP and that all checks pass. See the TESTING and DEVELOPMENT HowTo guides for details about how to run test locally. Artifacts
// Erlang/OTP Github Action Bot |
|
@HansN documentation added - had to make assumptions about when this would be released which are probably wrong. Feedback on docs appreciated obvs. My types were a bit ad-hoc... |
|
Thanks for the documentation. I'll check it! |
In erlang/otp#5538, the eldap_search_result record structure has changed: https://github.com/erlang/otp/pull/5538/files#diff-30e064e89b115da7e974f229ed5c92f28e489da679ef42f17e70b9e7cf874179R24 It does have a default but for code compiled on, say, Erlang 23.0, which is the case for current RabbitMQ releases, it would still be a breaking change resulting in case expression matching failures (a case_clause). Closes #4284.
An additional field was added by Erlang to the #eldap_search_result record to support paged search results. This caused a bad match, which was difficult to find because the bad match was not being logged because the error was being caught. erlang/otp#5538 Signed-off-by: Lincoln Baker <[email protected]>
An additional field was added by Erlang to the #eldap_search_result record to support paged search results. This caused a bad match, which was difficult to find because the bad match was not being logged because the error was being caught. erlang/otp#5538 Signed-off-by: Lincoln Baker <[email protected]>
An additional field was added by Erlang to the #eldap_search_result record to support paged search results. This caused a bad match, which was difficult to find because the bad match exception was being caught. erlang/otp#5538 Signed-off-by: Lincoln Baker <[email protected]>
An additional field was added by Erlang to the #eldap_search_result record to support paged search results. This caused a bad match, which was difficult to find because the bad match exception was being caught. erlang/otp#5538 Signed-off-by: Lincoln Baker <[email protected]>
An additional field was added by Erlang to the #eldap_search_result record to support paged search results. This caused a bad match, which was difficult to find because the bad match exception was being caught. erlang/otp#5538 Signed-off-by: Lincoln Baker <[email protected]>
An additional field was added by Erlang to the #eldap_search_result record to support paged search results. This caused a bad match, which was difficult to find because the bad match exception was being caught. erlang/otp#5538 Signed-off-by: Lincoln Baker <[email protected]>
An additional field was added by Erlang to the #eldap_search_result record to support paged search results. This caused a bad match, which was difficult to find because the bad match exception was being caught. erlang/otp#5538 Signed-off-by: Lincoln Baker <[email protected]>
An additional field was added by Erlang to the #eldap_search_result record to support paged search results. This caused a bad match, which was difficult to find because the bad match exception was being caught. erlang/otp#5538 Signed-off-by: Lincoln Baker <[email protected]>
An additional field was added by Erlang to the #eldap_search_result record to support paged search results. This caused a bad match, which was difficult to find because the bad match exception was being caught. erlang/otp#5538 Signed-off-by: Lincoln Baker <[email protected]>
An additional field was added by Erlang to the #eldap_search_result record to support paged search results. This caused a bad match, which was difficult to find because the bad match exception was being caught. erlang/otp#5538 Signed-off-by: Lincoln Baker <[email protected]>
An additional field was added by Erlang to the #eldap_search_result record to support paged search results. This caused a bad match, which was difficult to find because the bad match exception was being caught. erlang/otp#5538 Signed-off-by: Lincoln Baker <[email protected]>
An additional field was added by Erlang to the #eldap_search_result record to support paged search results. This caused a bad match, which was difficult to find because the bad match exception was being caught. erlang/otp#5538 Signed-off-by: Lincoln Baker <[email protected]>
An additional field was added by Erlang to the #eldap_search_result record to support paged search results. This caused a bad match, which was difficult to find because the bad match exception was being caught. erlang/otp#5538 Signed-off-by: Lincoln Baker <[email protected]>
An additional field was added by Erlang to the #eldap_search_result record to support paged search results. This caused a bad match, which was difficult to find because the bad match exception was being caught. erlang/otp#5538 Signed-off-by: Lincoln Baker <[email protected]>
An additional field was added by Erlang to the #eldap_search_result record to support paged search results. This caused a bad match, which was difficult to find because the bad match exception was being caught. erlang/otp#5538 Signed-off-by: Lincoln Baker <[email protected]>
An additional field was added by Erlang to the #eldap_search_result record to support paged search results. This caused a bad match, which was difficult to find because the bad match exception was being caught. erlang/otp#5538 Signed-off-by: Lincoln Baker <[email protected]>
An additional field was added by Erlang to the #eldap_search_result record to support paged search results. This caused a bad match, which was difficult to find because the bad match exception was being caught. erlang/otp#5538 Signed-off-by: Lincoln Baker <[email protected]>
An additional field was added by Erlang to the #eldap_search_result record to support paged search results. This caused a bad match, which was difficult to find because the bad match exception was being caught. erlang/otp#5538 Signed-off-by: Lincoln Baker <[email protected]>
- Upgrade to Erlang 24.3.2 - Install/build with correct version of Erlang - Fix deprecations, incompatibilities, etc. Note: rebar3 could not be upgraded as of yet, because it causes various failures. An issue has been created for it. Below are a few of the many issues addressed while doing this work: - Jiffy update for Erlang 24+ (erl_interface compilation errors) ld: library not found for -lerl_interface clang: error: linker command failed with exit code 1 (use -v to see invocation) sh(c++ c_src/decoder.o c_src/encoder.o c_src/jiffy.o c_src/utf8.o c_src/util.o c_src/doubles.o c_src/objects.o c_src/double-conversion/bignum-dtoa.o c_src/double-conversion/bignum.o c_src/double-conversion/cached-powers.o c_src/double-conversion/diy-fp.o c_src/double-conversion/double-conversion.o c_src/double-conversion/fast-dtoa.o c_src/double-conversion/fixed-dtoa.o c_src/double-conversion/strtod.o -lstdc++ -bundle -flat_namespace -undefined suppress -L"/usr/local/Cellar/erlang@24/24.3.4.1/lib/erlang/lib/erl_interface-5.2.2/lib" -lerl_interface -lei -o priv/jiffy.so) failed with return code 1 and the following output: ld: library not found for -lerl_interface clang: error: linker command failed with exit code 1 (use -v to see invocation) ===> Hook for compile failed! - Fix bcrypt - Fix depsolver jiffy issues - Fix LDAP failures after Erlang changes to #eldap_search_result record. An additional field was added by Erlang to the #eldap_search_result record to support paged search results. This caused a bad match, which was difficult to find because the bad match exception was being caught. erlang/otp#5538 - Fix unused type failure. encountered the following minor compilation error below, but if the type is removed, we get an error that the type is needed. the best way is to not spend hours on this, and just add the compilation flag (that's why it's there) and move on. ===> Compiling bookshelf ===> Compiling src/bksw_sql.erl failed src/bksw_sql.erl:22:2: type dict() is unused - Fix verify pipeline errors in oc_bifrost. the way jiffy throws errors was changed, due to erlang changes. - Fix http_uri:encode/decode deprecations. ===> Compiling src/bksw_io_names.erl failed src/bksw_io_names.erl:34:5: http_uri:encode/1 is deprecated and will be removed in OTP 25; use uri_string functions instead src/bksw_io_names.erl:39:5: http_uri:decode/1 is deprecated and will be removed in OTP 25; use uri_string functions instead - Fix bookshelf verify pipeline errors. https://buildkite.com/chef-oss/chef-chef-server-main-verify/builds/468#0181ffdf-75e7-4942-9bae-7c02fde88a4a Signed-off-by: Lincoln Baker <[email protected]>
- Upgrade to Erlang 24.3.2 - Install/build with correct version of Erlang - Fix deprecations, incompatibilities, etc. Note: rebar3 could not be upgraded as of yet, because it causes various failures. An issue has been created for it. Below are a few of the many issues addressed while doing this work: - Jiffy update for Erlang 24+ (erl_interface compilation errors) ld: library not found for -lerl_interface clang: error: linker command failed with exit code 1 (use -v to see invocation) sh(c++ c_src/decoder.o c_src/encoder.o c_src/jiffy.o c_src/utf8.o c_src/util.o c_src/doubles.o c_src/objects.o c_src/double-conversion/bignum-dtoa.o c_src/double-conversion/bignum.o c_src/double-conversion/cached-powers.o c_src/double-conversion/diy-fp.o c_src/double-conversion/double-conversion.o c_src/double-conversion/fast-dtoa.o c_src/double-conversion/fixed-dtoa.o c_src/double-conversion/strtod.o -lstdc++ -bundle -flat_namespace -undefined suppress -L"/usr/local/Cellar/erlang@24/24.3.4.1/lib/erlang/lib/erl_interface-5.2.2/lib" -lerl_interface -lei -o priv/jiffy.so) failed with return code 1 and the following output: ld: library not found for -lerl_interface clang: error: linker command failed with exit code 1 (use -v to see invocation) ===> Hook for compile failed! - Fix bcrypt - Fix depsolver jiffy issues - Fix LDAP failures after Erlang changes to #eldap_search_result record. An additional field was added by Erlang to the #eldap_search_result record to support paged search results. This caused a bad match, which was difficult to find because the bad match exception was being caught. erlang/otp#5538 - Fix unused type failure. encountered the following minor compilation error below, but if the type is removed, we get an error that the type is needed. the best way is to not spend hours on this, and just add the compilation flag (that's why it's there) and move on. ===> Compiling bookshelf ===> Compiling src/bksw_sql.erl failed src/bksw_sql.erl:22:2: type dict() is unused - Fix verify pipeline errors in oc_bifrost. the way jiffy throws errors was changed, due to erlang changes. - Fix http_uri:encode/decode deprecations. ===> Compiling src/bksw_io_names.erl failed src/bksw_io_names.erl:34:5: http_uri:encode/1 is deprecated and will be removed in OTP 25; use uri_string functions instead src/bksw_io_names.erl:39:5: http_uri:decode/1 is deprecated and will be removed in OTP 25; use uri_string functions instead - Fix bookshelf verify pipeline errors. https://buildkite.com/chef-oss/chef-chef-server-main-verify/builds/468#0181ffdf-75e7-4942-9bae-7c02fde88a4a Signed-off-by: Lincoln Baker <[email protected]>
- Upgrade to Erlang 24.3.2 - Install/build with correct version of Erlang - Fix deprecations, incompatibilities, etc. Note: rebar3 could not be upgraded as of yet, because it causes various failures. An issue has been created for it. Below are a few of the many issues addressed while doing this work: - Jiffy update for Erlang 24+ (erl_interface compilation errors) ld: library not found for -lerl_interface clang: error: linker command failed with exit code 1 (use -v to see invocation) sh(c++ c_src/decoder.o c_src/encoder.o c_src/jiffy.o c_src/utf8.o c_src/util.o c_src/doubles.o c_src/objects.o c_src/double-conversion/bignum-dtoa.o c_src/double-conversion/bignum.o c_src/double-conversion/cached-powers.o c_src/double-conversion/diy-fp.o c_src/double-conversion/double-conversion.o c_src/double-conversion/fast-dtoa.o c_src/double-conversion/fixed-dtoa.o c_src/double-conversion/strtod.o -lstdc++ -bundle -flat_namespace -undefined suppress -L"/usr/local/Cellar/erlang@24/24.3.4.1/lib/erlang/lib/erl_interface-5.2.2/lib" -lerl_interface -lei -o priv/jiffy.so) failed with return code 1 and the following output: ld: library not found for -lerl_interface clang: error: linker command failed with exit code 1 (use -v to see invocation) ===> Hook for compile failed! - Fix bcrypt - Fix depsolver jiffy issues - Fix LDAP failures after Erlang changes to #eldap_search_result record. An additional field was added by Erlang to the #eldap_search_result record to support paged search results. This caused a bad match, which was difficult to find because the bad match exception was being caught. erlang/otp#5538 - Fix unused type failure. encountered the following minor compilation error below, but if the type is removed, we get an error that the type is needed. the best way is to not spend hours on this, and just add the compilation flag (that's why it's there) and move on. ===> Compiling bookshelf ===> Compiling src/bksw_sql.erl failed src/bksw_sql.erl:22:2: type dict() is unused - Fix verify pipeline errors in oc_bifrost. the way jiffy throws errors was changed, due to erlang changes. - Fix http_uri:encode/decode deprecations. ===> Compiling src/bksw_io_names.erl failed src/bksw_io_names.erl:34:5: http_uri:encode/1 is deprecated and will be removed in OTP 25; use uri_string functions instead src/bksw_io_names.erl:39:5: http_uri:decode/1 is deprecated and will be removed in OTP 25; use uri_string functions instead - Fix bookshelf verify pipeline errors. https://buildkite.com/chef-oss/chef-chef-server-main-verify/builds/468#0181ffdf-75e7-4942-9bae-7c02fde88a4a Signed-off-by: Lincoln Baker <[email protected]> Signed-off-by: Lincoln Baker <[email protected]>
The search results record change was done in OTP-25, which is no longer supported. So we can use the modern search results record and drop the compatibility clauses. For more context: * 8d8847e * erlang/otp#5538
The search results record change was done in OTP-25, which is no longer supported. So we can use the modern search results record and drop the compatibility clauses. For more context: * 8d8847e * erlang/otp#5538
The search results record change was done in OTP-25, which is no longer supported. So we can use the modern search results record and drop the compatibility clauses. For more context: * 8d8847e * erlang/otp#5538
The search results record change was done in OTP-25, which is no longer supported. So we can use the modern search results record and drop the compatibility clauses. For more context: * 8d8847e * erlang/otp#5538
The search results record change was done in OTP-25, which is no longer supported. So we can use the modern search results record and drop the compatibility clauses. For more context: * 8d8847e * erlang/otp#5538
The search results record change was done in OTP-25, which is no longer supported. So we can use the modern search results record and drop the compatibility clauses. For more context: * 8d8847e * erlang/otp#5538
The search results record change was done in OTP-25, which is no longer supported. So we can use the modern search results record and drop the compatibility clauses. For more context: * 8d8847e * erlang/otp#5538
The search results record change was done in OTP-25, which is no longer supported. So we can use the modern search results record and drop the compatibility clauses. For more context: * 8d8847e * erlang/otp#5538
Returns the controls from an LDAP search and includes the
PagedResultsControl ASN so that user code can perform paged searches
according to https://www.rfc-editor.org/rfc/rfc2696.txt