microsoft / microsoft/sqlmanagementobjects
Login.ChangePassword() leaves MustChangePassword and IsLocked stale - the property bag is never updated or invalidated
まだ誰も着手していません。
- 主要言語
- C#
- スター
- 143
- フォーク
- 28
- PR マージ指標
- 30日以内にマージされた PR はありません
説明
After a successful Login.ChangePassword(newPassword, unlock: true, mustChange: true), reading login.MustChangePassword on the same object still returns the old value (typically False) until Refresh() is called. The same applies to the other properties the ALTER changes: IsLocked after an unlock, IsPasswordExpired, PasswordLastSetTime, IsMustChange.
This is the same object-cache pattern as #40 (Database.SetOwner() not updating .Owner): a method executes DDL immediately but neither updates nor invalidates the cached properties it just changed on the server.
Repro
$login = $server.Logins["testlogin"] # SQL login, MustChangePassword currently False
$login.ChangePassword("N3wP@ssw0rd!", $true, $true)
$login.MustChangePassword # False - stale; the server says otherwise:
# SELECT LOGINPROPERTY('testlogin', 'IsMustChange') --> 1
$login.Refresh()
$login.MustChangePassword # True
dbatools carries the workaround with the comment "We need to refresh login after ChangePassword. Otherwise, MustChangePassword will appear as False" (New-DbaLogin.ps1#L610-L611), and its Set-DbaLogin re-reads the login after unlocking for the same reason.
Mechanism
All ChangePassword overloads (LoginBase.cs#L142-L282) end in ExecuteLoginPasswordOptions (LoginBase.cs#L533-L555), which builds ALTER LOGIN ... WITH PASSWORD=... [UNLOCK] [MUST_CHANGE] and runs ExecutionManager.ExecuteNonQuery — and returns. Nothing touches the property bag.
A helper that does update the bag exists — SetMustChangePassword (LoginBase.cs#L334-L347) — but it early-returns unless the object is in design mode, and is only called from Create().
Suggested fix
After a successful non-recording execution, invalidate the affected cached properties so the next read fetches current values from the server — the approach proposed for #40 in PR #231. For ChangePassword that covers at least MustChangePassword, IsLocked, IsPasswordExpired, IsMustChange, PasswordLastSetTime, PasswordHash.
Happy to submit a PR along those lines if that helps.
This was created by Claude and reviewed by Andreas Jordan.
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
src/Microsoft/SqlServer/Management/Smo/LoginBase.cs から始め、ChangePassword のオーバーロードと ExecuteLoginPasswordOptions を読み、次にそれらの動作を SetMustChangePassword と比較します。記録を伴わない実行が成功した後、影響を受けるキャッシュ済みプロパティを無効化し、同じオブジェクトからの読み取りが、MustChangePassword、IsLocked、IsPasswordExpired、IsMustChange、PasswordLastSetTime、PasswordHash について ALTER LOGIN の結果を反映するようにします。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- csharp, sql
- 領域
- backend-api-design, databases
- issue の種類
- バグ
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 活発
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 72/100