-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Description
Description
Only a single successful call to PrincipalContext.ValidateCredentials against the local SAM store will succeed even when the PrincipalContext is disposed correctly starting with System.DirectoryServices.AccountManagement version 7.0.0. The subsequent calls will all fail with a PrinciaplOperationException. This issue will persist through application restarts and will only cease when the Workstation service is restarted. The issue is not present in System.DirectoryServices.AccountManagement version 6.0.0.
Reproduction Steps
Please see the attached project to reproduce the issue. The project is a simple console application which simply takes 4 arguments: the username and password of a local user followed by the username and password of a second local user. The application simply calls ValidateCredentails on the first user and then on the second user using two PrincipalContext objects with ContextType.Machine that are properly disposed through using statements. The second call to PrincipalContext.ValidateCredentials will fail with the exception mentioned in the description when correct user credentials are passed to the application.
Expected behavior
Both calls to PrincipalManager.ValidateCredentials should succeed without an exception when correct credentials are supplied to the ValidateCredentials calls.
Actual behavior
The second call to PrincipalManager.ValidateCredentials fails with the following exception:
System.DirectoryServices.AccountManagement.PrincipalOperationException
HResult=0x80131501
Message=Multiple connections to a server or shared resource by the same user, using more than one user name, are not allowed. Disconnect all previous connections to the server or shared resource and try again.Source=System.DirectoryServices.AccountManagement
$(String[] args) in C:\Users\bgarfinkel\Desktop\PrincipalContextTestApp\PrincipalContextTestApp\Program.cs:line 12
StackTrace:
at System.DirectoryServices.AccountManagement.CredentialValidator.BindSam(String target, String userName, String password)
at System.DirectoryServices.AccountManagement.CredentialValidator.Validate(String userName, String password)
at System.DirectoryServices.AccountManagement.PrincipalContext.ValidateCredentials(String userName, String password)
at Program.This exception was originally thrown at this call stack:
System.DirectoryServices.AccountManagement.CredentialValidator.BindSam(string, string, string)Inner Exception 1:
COMException: Multiple connections to a server or shared resource by the same user, using more than one user name, are not allowed. Disconnect all previous connections to the server or shared resource and try again.
Regression?
Yes, this is a regression. This issue does not occur in System.DirectoryServices.AccountManagement 6.0.0. This can be verified by downgrading the System.DirectoryServices.AccountManagement nuget package to version 6.0.0. in the attached sample application.
Known Workarounds
Restarting the Windows workstation service fixes the issue until another successful call to PrincipalContext.ValidateCredentials occurs against the local SAM store.
Configuration
The code is running on .NET 7.0 and Windows version 10.0.19044 Build 19044 x64. I am not sure if the issue is specific to this configuration.
Other information
No response