Skip to content

Fix/bind protocol error handling - #83

Merged
Firstyear merged 7 commits into
kanidm:masterfrom
rumba-id:fix/bind-protocol-error-handling
Oct 27, 2026
Merged

Firstyear merged 7 commits into
kanidm:masterfrom
rumba-id:fix/bind-protocol-error-handling

Conversation

@danielsreichenbach

@danielsreichenbach danielsreichenbach commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Hello again,

I found more protocol issues in the crate. This PR fixes them. These changes are based on my reading of the LDAP RFCs. Please correct me if I misread them.

I changed how the parser handles bind requests. RFC 4511 §4.2 says the server must report bind errors. The parser must pass the message through. As it stands, it does not. A server built on this crate cannot be RFC compliant.

Changes made

These changes are breaking.

  • LdapBindRequest stores the protocol version. The server answers protocolError for a version other than 3.
  • Unknown authentication choices decode as LdapBindCred::Unsupported. The server answers authMethodNotSupported.
  • SaslCredentials.credentials is optional. If it is absent, it decodes as empty.
  • The lber parser stops on a malformed child element. It keeps the decoded prefix and reports the error.

I added result codes from RFC 3909, 4528, 4370, and the VLV draft:

  • 76 VirtualListViewError (VLV draft)
  • 118 Canceled (RFC 3909)
  • 119 NoSuchOperation (RFC 3909)
  • 120 TooLate (RFC 3909)
  • 121 CannotCancel (RFC 3909)
  • 122 AssertionFailed (RFC 4528)
  • 123 AuthorizationError (RFC 4370)

I also added the Increment modify operation (value 3, RFC 4525).

I added tests for the new bind behavior.

As suggested in the last PR, I added myself to the contributor list.

Thanks for maintaining this project. It saves me a lot of time. ❤️

RFC 4511 §4.2 assigns bind error handling to the server: unsupported
protocol versions must be answered with protocolError, unsupported
authentication choices with authMethodNotSupported. The parser
previously rejected these PDUs up front — some even hung the lber
parse loop forever — so servers never got the chance to respond.

- LdapBindRequest now stores the protocol version; versions other than
  3 parse successfully.
- LdapBindCred::Unsupported covers AuthenticationChoice tags other
  than simple [0] and sasl [3].
- Absent SaslCredentials.credentials (OPTIONAL per the ASN.1) decodes
  as empty.
- lber: a non-TLV child inside a fully-consumed constructed tag is
  malformed, not truncated; keep the decoded prefix instead of
  reporting Incomplete forever.

BREAKING CHANGE: LdapBindRequest gains a version field and LdapBindCred
gains an Unsupported variant.
- LdapResultCode::AssertionFailed (122) per RFC 4528 §2, including
  the numeric decode mapping.
- LdapModifyType::Increment (3) per RFC 4525 §2, including the
  numeric decode mapping.
canceled (118), noSuchOperation (119), tooLate (120), cannotCancel
(121) per RFC 3909 §2.2, with numeric decode mappings.
RFC 4370 §6 assigns result code 123 for a proxy authorization
request the server does not honor.
The recently added probe tests used unwrap/unwrap_err/unreachable! and
explicit .into_iter() calls, violating the crate-wide deny lints
(clippy::unwrap_used, clippy::unreachable, clippy::panic). Rewritten to
expect/panic-with-message and implicit iteration, matching the crate's
convention (expect_used is allowed).
draft-ietf-ldapext-ldapv3-vlv-09 section 6.2.1 registers result code 76
(virtualListViewError). Needed by LDAP servers implementing the VLV
control.
@Firstyear

Copy link
Copy Markdown
Member

Thanks, I'll review this next week (I'm away this week) :)

@Firstyear

Copy link
Copy Markdown
Member

Thank you so much, the contribution is really appreciated. Glad to know that we help you by maintaining this library :)

@Firstyear
Firstyear merged commit 4324b2c into kanidm:master Oct 27, 2026
1 check passed
@danielsreichenbach

Copy link
Copy Markdown
Contributor Author

Incredibly so, my own projects use this. I am learning a lot.

@Firstyear

Copy link
Copy Markdown
Member

Incredibly so, my own projects use this. I am learning a lot.

If you ever have any questions, please let us know, we're always happy to help out.

@danielsreichenbach
danielsreichenbach deleted the fix/bind-protocol-error-handling branch November 15, 2026 04:15
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.

2 participants