Expose ResultCode and DiagnosticMessage on SearchResult - #626
Conversation
|
@t2y @cpuschma @johnweldon - Request you to review the PR |
|
This is my personal opinion based on the changes. Before we proceed with this PR, I'd like others' opinions on two API changes.
The goal is to parse LDAPResult in one place. |
cpuschma
left a comment
There was a problem hiding this comment.
Please see the comments.
I would prefer not to make this function publicly available yet, until the aforementioned code snippets have been resolved.
For now, please change the function to non-public, so that only the new fields in SearchResult are propagated.
68eebfc to
8ab56ea
Compare
|
@cpuschma Thanks for the review! Pushed the changes: ParseLDAPResult → parseLDAPResult (unexported) Please take another look when you get a chance. Also, @t2y raised two additional suggestions — adding DiagnosticMessage() to the Response interface and a DiagnosticMessage field to ldap.Error. Both would be breaking changes for external consumers. @cpuschma @johnweldon could you share your thoughts on those? Happy to incorporate them into this PR if there's consensus, or we can handle them as a follow-up. |
| result.Entries = append(result.Entries, entry) | ||
| case 5: | ||
| rc, _, diag, parseErr := parseLDAPResult(packet) | ||
| if parseErr == nil { |
There was a problem hiding this comment.
parseErr is not returned, the error is silently dropped here.
Let's not introduce breaking changes in a minor release. Currently we have a abundance of PRs regarding OOB reads for malformed packets we need to address first before new functions or even breaking changes can be introduced (#632) |
johnweldon
left a comment
There was a problem hiding this comment.
Thank you for your contribution!
|
I agree with @cpuschma's direction. Let's not include breaking changes in a minor release. We can revisit changing the interface later if needed. |
GetLDAPError returns nil when resultCode is 0, discarding the diagnosticMessage. Some servers set this field on success to signal degraded state (e.g. directory reinitializing). Add ResultCode and DiagnosticMessage to SearchResult, populated before GetLDAPError. Add ParseLDAPResult to read all LDAPResult fields without the early return on success. GetLDAPError is unchanged. Existing callers are unaffected.
8ab56ea to
b540ec6
Compare
|
@cpuschma @johnweldon Pushed the fixes and replied to each comment. Let me know if anything else needs to be addressed. |
|
Thank you @cpuschma for merging the PR. Please confirm when will this be released. |
|
@t2y @cpuschma @johnweldon Please suggest when will this code be released |
|
Some issues are still to be adressed before a new release is published. If you're eager to use the newest patches, you can use the current commit instead of the tagged release: go get github.com/go-ldap/ldap/v3@05f305f2813dc3d18a886d8f927d9ac9ca18a986 |
Problem
GetLDAPErrorreturnsnilwhenresultCodeis 0 (success), discardingthe
diagnosticMessagefromSearchResultDone. Per RFC 4511 §4.1.9, serversmay set
diagnosticMessageeven on a successful operation to communicateadditional information such as degraded state.
For example, Red Hat IPA sets
diagnosticMessagewhen the directory isreinitializing but still returns
resultCode0 with an empty entry list.Callers of
Search()currently have no way to see that message — they onlysee zero entries and no error, which is indistinguishable from a genuine
empty result.
Solution
ResultCodeandDiagnosticMessagefields toSearchResult.Search(), populate them from theSearchResultDonepacket (case 5) before callingGetLDAPError, so they are preserved even whenGetLDAPErrorreturnsnilon success.parseLDAPResulthelper that extractsresultCode,matchedDN, anddiagnosticMessagefrom anLDAPResultBER packet without the early return on success thatGetLDAPErrorhas.appendToso paged searches preserve them.Backward compatibility
GetLDAPErroris unchanged.SearchResultis a struct; adding fields is backward compatible in Go.result.DiagnosticMessageafterSearch()returns.References
Prior art
Python's
python-ldaplibrary already exposes the diagnostic message after successful operations by callingget_option(OPT_DIAGNOSTIC_MESSAGE)on the LDAP handle (source). This PR brings the same capability togo-ldapby surfacingdiagnosticMessageon theSearchResultstruct regardless ofresultCode.