Skip to content

add Error::code and Error::is_credential_rejected - #5

Merged
samvdst merged 1 commit into
mainfrom
error-codes
Nov 9, 2026
Merged

samvdst merged 1 commit into
mainfrom
error-codes

Conversation

@samvdst

@samvdst samvdst commented Oct 29, 2026

Copy link
Copy Markdown
Owner

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, and Display shows the code and the OS message.
  • The enum is #[non_exhaustive].
  • sambrs logs WNet statuses at 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 of Error::Windows and None for every other variant. Provider-specific codes stay on Error::ExtendedError.
  • Error::is_credential_rejected(&self) -> bool is true for ERROR_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) and ERROR_ACCOUNT_LOCKED_OUT (1909). Its doc comment says callers must not retry these, because each retry counts toward lockout.
  • A table test goes through 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.
  • Version bumped to 0.2.1, with a CHANGELOG entry.

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 on Windows(1909) see.

How tested

On Linux, cross-compiled for x86_64-pc-windows-msvc, with unit tests run under Wine:

  • cargo fmt --check
  • cargo xwin test --target x86_64-pc-windows-msvc: 13 unit tests and 8 doctests pass
  • cargo 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: clean

I did not run the integration tests, which need a real share; CI runs them on Windows.

🤖 Generated with Claude Code

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>
@samvdst
samvdst merged commit fa0a719 into main Nov 9, 2026
2 checks passed
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