Repository navigation
add Error::code and Error::is_credential_rejected - #5
Merged
Merged
Conversation
Callers must stop retrying a credential the domain rejected, or every retry moves the account closer to lockout. Error::Windows(code) already keeps the status, but each caller had to know which codes mean "credential rejected". is_credential_rejected() is true for invalid password, logon failure, account restriction, password expired, account disabled, account expired, password must change and account locked out. code() exposes the status of Error::Windows. Both are additive, so this is 0.2.1. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
A production deployment (still on sambrs 0.1.2) logged 732
Connection failed: Unknown error.lines over three days. The real statuses only appeared at DEBUG: 1909 (account locked out), 1219 (session credential conflict), 53 (bad net path), 1326 (logon failure), and 2250 (not connected, on disconnect). The consuming application kept retrying credentials the domain had already rejected, which is how an account ends up locked out.0.2.0 already fixed most of the original complaint:
Error::Windows(code)keeps every status, andDisplayshows the code and the OS message.#[non_exhaustive].debug!only and never at ERROR.What's still missing is a supported way to tell "the domain rejected this credential" apart from transient failures. Without it, every caller has to keep its own list of Win32 codes.
What changed
Error::code(&self) -> Option<u32>returns the status ofError::WindowsandNonefor every other variant. Provider-specific codes stay onError::ExtendedError.Error::is_credential_rejected(&self) -> boolis true forERROR_INVALID_PASSWORD(86),ERROR_LOGON_FAILURE(1326),ERROR_ACCOUNT_RESTRICTION(1327),ERROR_PASSWORD_EXPIRED(1330),ERROR_ACCOUNT_DISABLED(1331),ERROR_ACCOUNT_EXPIRED(1793),ERROR_PASSWORD_MUST_CHANGE(1907) andERROR_ACCOUNT_LOCKED_OUT(1909). Its doc comment says callers must not retry these, because each retry counts toward lockout.check_wnet, the status mapping shared by connect, disconnect, query and enumerate. It covers the rejected codes plus 53, 1219, 2250 and an unlisted code.Breaking change
None. Both methods are additive. I deliberately did not bring back per-code variants: 0.2.0 replaced them with
Error::Windows(code), and adding them again would change what existing matches onWindows(1909)see.How tested
On Linux, cross-compiled for
x86_64-pc-windows-msvc, with unit tests run under Wine:cargo fmt --checkcargo xwin test --target x86_64-pc-windows-msvc: 13 unit tests and 8 doctests passcargo xwin clippy --target x86_64-pc-windows-msvc --all-targets -- -Dwarnings: clean (pedantic)RUSTDOCFLAGS="-D warnings" cargo xwin doc --target x86_64-pc-windows-msvc --no-deps: cleanI did not run the integration tests, which need a real share; CI runs them on Windows.
🤖 Generated with Claude Code