Fix SafeLsaMemoryHandle.InvalidHandle #32786
Conversation
src/System.Security.Principal.Windows/src/Microsoft/Win32/SafeHandles/SafeSecurityHandles.cs
Outdated
Show resolved
Hide resolved
src/System.Security.Principal.Windows/src/System/Security/Principal/NTAccount.cs
Show resolved
Hide resolved
src/System.Security.Principal.Windows/src/System/Security/Principal/NTAccount.cs
Outdated
Show resolved
Hide resolved
{ | ||
public class NTAccountTest | ||
{ | ||
[Fact(Skip = "This test needs a machine in a domain but off line.")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you let it always run, and check that it either does not throw or throws IdentityNotMappedException or Win32EXception? That would prove it does not throw ObjectDisposedException any more and occasionally it would likely get run on a machine in such a state. Eg. we often work on laptops with machines that are joined to the domain and do not have connectivity.
Or the test could somehow check for the state (in domain but offline)
[Fact(Skip = "This test needs a machine in a domain but off line.")] | ||
public void Translate_Fail_Domain_Offline() | ||
{ | ||
var nta = new NTAccount("foobar"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Somewhere someone has a domain or user named foobar. Best to use something like Guid.NewGuid().ToString("N")
@@ -7,6 +7,7 @@ | |||
<Compile Include="WindowsIdentityTests.cs" /> | |||
<Compile Include="WindowsPrincipalTests.cs" /> | |||
<Compile Include="WellKnownSidTypeTests.cs" /> | |||
<Compile Include="NTAccount.cs" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please sort. This helps avoid merge conflicts. It's how VS adds entries.
if (exception is Win32Exception win32Exception) | ||
{ | ||
// ERROR_TRUSTED_RELATIONSHIP_FAILURE: The trust relationship between this workstation and the primary domain failed. | ||
Assert.Equal(1789, win32Exception.NativeErrorCode); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@danmosemsft @jkotas i don't know if this makes sense, maybe is extras.
@dotnet-bot test Linux arm64 Release Build please |
I wonder if converting SafeLsaMemoryHandle / SafeLsaPolicyHandle / SafeLsaReturnBufferHandle to use the SafeHandleCache, like SafeX509ChainHandle does, is better. Lines 19 to 35 in a10890f
|
As I get more caught up on email I see that it looks like my comment was already given and disrecommended, but it wasn't visible here. Personally, I prefer the SafeHandleCache because it keeps writing new code easy (no "am I supposed to not call Dispose() here if IsInvalid?"). The interlocked calls are more expensive, but they are keeping the expense in the calls, not on the finalizer thread/finalizer queue/GC sweep. Though, restructuring code to not allocate the invalid handle redundantly is also a viable path, and then get rid of the static property altogether. |
Sorry @bartonjs i don't understand what are you proposing...now |
Instead of |
@bartonjs PTAL! |
src/System.Security.Principal.Windows/src/System/Security/Principal/NTAccount.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks
* fix SafeLsaMemoryHandle.InvalidHandle * address PR feedback * update tests * address PR feedback * update test * sort csproj * update test * update test * address PR feedback * address PR feedback Commit migrated from dotnet/corefx@fc2d6ff
fixes https://github.com/dotnet/corefx/issues/32636
/cc @bartonjs @GrabYourPitchforks @jkotas