Skip to content

Expose ResultCode and DiagnosticMessage on SearchResult - #626

Open
Pujathacker2210 wants to merge 1 commit into
go-ldap:masterfrom
Pujathacker2210:search-result-diagnostic
Open

Pujathacker2210 wants to merge 1 commit into
go-ldap:masterfrom
Pujathacker2210:search-result-diagnostic

Conversation

@Pujathacker2210

@Pujathacker2210 Pujathacker2210 commented Sep 7, 2026

Copy link
Copy Markdown

Problem

GetLDAPError returns nil when resultCode is 0 (success), discarding
the diagnosticMessage from SearchResultDone. Per RFC 4511 §4.1.9, servers
may set diagnosticMessage even on a successful operation to communicate
additional information such as degraded state.

For example, Red Hat IPA sets diagnosticMessage when the directory is
reinitializing but still returns resultCode 0 with an empty entry list.
Callers of Search() currently have no way to see that message — they only
see zero entries and no error, which is indistinguishable from a genuine
empty result.

Solution

  • Add ResultCode and DiagnosticMessage fields to SearchResult.
  • In Search(), populate them from the SearchResultDone packet (case 5) before calling GetLDAPError, so they are preserved even whenGetLDAPError returns nil on success.
  • Add ParseLDAPResult helper that extracts resultCode, matchedDN, and diagnosticMessage from an LDAPResult BER packet without the early return on success that GetLDAPError has.
  • Copy the new fields in appendTo so paged searches preserve them.

Backward compatibility

  • GetLDAPError is unchanged.
  • SearchResult is a struct; adding fields is backward compatible in Go.
  • Existing callers are unaffected — they never read the new fields.
  • Callers who need the diagnostic on success can now read result.DiagnosticMessage after Search() returns.

References

Prior art

Python's python-ldap library already exposes the diagnostic message after successful operations by calling get_option(OPT_DIAGNOSTIC_MESSAGE) on the LDAP handle (source). This PR brings the same capability to go-ldap by surfacing diagnosticMessage on the SearchResult struct regardless of resultCode.

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.
@Pujathacker2210

Copy link
Copy Markdown
Author

@t2y @cpuschma @johnweldon - Request you to review the PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant