internal partial class Interop
{
- internal partial class SspiCli
+ internal partial class Advapi32
{
[StructLayout(LayoutKind.Sequential)]
internal struct LSA_STRING
SafeLsaPolicyHandle handle,
int flags,
int count,
- UNICODE_STRING[] names,
+ MARSHALLED_UNICODE_STRING[] names,
out SafeLsaMemoryHandle referencedDomains,
out SafeLsaMemoryHandle sids
- );
+ );
+
+ [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
+ internal struct MARSHALLED_UNICODE_STRING
+ {
+ internal ushort Length;
+ internal ushort MaximumLength;
+ [MarshalAs(UnmanagedType.LPWStr)]
+ internal string Buffer;
+ }
}
}
IntPtr[] sids,
out SafeLsaMemoryHandle referencedDomains,
out SafeLsaMemoryHandle names
- );
+ );
}
}
internal static partial class Advapi32
{
[DllImport(Interop.Libraries.Advapi32, EntryPoint = "LsaOpenPolicy", SetLastError = true, CharSet = CharSet.Unicode)]
- internal static extern uint LsaOpenPolicy(string systemName, ref LSA_OBJECT_ATTRIBUTES attributes, int accessMask, out SafeLsaPolicyHandle handle);
+ private static extern uint LsaOpenPolicy(
+ ref UNICODE_STRING SystemName,
+ ref OBJECT_ATTRIBUTES ObjectAttributes,
+ int AccessMask,
+ out SafeLsaPolicyHandle PolicyHandle
+ );
+
+ internal static unsafe uint LsaOpenPolicy(
+ string SystemName,
+ ref OBJECT_ATTRIBUTES Attributes,
+ int AccessMask,
+ out SafeLsaPolicyHandle PolicyHandle)
+ {
+ var systemNameUnicode = new UNICODE_STRING();
+ if (SystemName != null)
+ {
+ fixed (char* c = SystemName)
+ {
+ systemNameUnicode.Length = checked((ushort)(SystemName.Length * sizeof(char)));
+ systemNameUnicode.MaximumLength = checked((ushort)(SystemName.Length * sizeof(char)));
+ systemNameUnicode.Buffer = (IntPtr)c;
+ return LsaOpenPolicy(ref systemNameUnicode, ref Attributes, AccessMask, out PolicyHandle);
+ }
+ }
+ else
+ {
+ return LsaOpenPolicy(ref systemNameUnicode, ref Attributes, AccessMask, out PolicyHandle);
+ }
+ }
}
}
--- /dev/null
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Runtime.InteropServices;
+
+internal static partial class Interop
+{
+ /// <summary>
+ /// <a href="https://msdn.microsoft.com/en-us/library/windows/hardware/ff557749.aspx">OBJECT_ATTRIBUTES</a> structure.
+ /// The OBJECT_ATTRIBUTES structure specifies attributes that can be applied to objects or object handles by routines
+ /// that create objects and/or return handles to objects.
+ /// </summary>
+ internal unsafe struct OBJECT_ATTRIBUTES
+ {
+ public uint Length;
+
+ /// <summary>
+ /// Optional handle to root object directory for the given ObjectName.
+ /// Can be a file system directory or object manager directory.
+ /// </summary>
+ public IntPtr RootDirectory;
+
+ /// <summary>
+ /// Name of the object. Must be fully qualified if RootDirectory isn't set.
+ /// Otherwise is relative to RootDirectory.
+ /// </summary>
+ public UNICODE_STRING* ObjectName;
+
+ public ObjectAttributes Attributes;
+
+ /// <summary>
+ /// If null, object will receive default security settings.
+ /// </summary>
+ public void* SecurityDescriptor;
+
+ /// <summary>
+ /// Optional quality of service to be applied to the object. Used to indicate
+ /// security impersonation level and context tracking mode (dynamic or static).
+ /// </summary>
+ public void* SecurityQualityOfService;
+
+ /// <summary>
+ /// Equivalent of InitializeObjectAttributes macro with the exception that you can directly set SQOS.
+ /// </summary>
+ public unsafe OBJECT_ATTRIBUTES(UNICODE_STRING* objectName, ObjectAttributes attributes, IntPtr rootDirectory)
+ {
+ Length = (uint)sizeof(OBJECT_ATTRIBUTES);
+ RootDirectory = rootDirectory;
+ ObjectName = objectName;
+ Attributes = attributes;
+ SecurityDescriptor = null;
+ SecurityQualityOfService = null;
+ }
+ }
+
+ [Flags]
+ public enum ObjectAttributes : uint
+ {
+ // https://msdn.microsoft.com/en-us/library/windows/hardware/ff564586.aspx
+ // https://msdn.microsoft.com/en-us/library/windows/hardware/ff547804.aspx
+
+ /// <summary>
+ /// This handle can be inherited by child processes of the current process.
+ /// </summary>
+ OBJ_INHERIT = 0x00000002,
+
+ /// <summary>
+ /// This flag only applies to objects that are named within the object manager.
+ /// By default, such objects are deleted when all open handles to them are closed.
+ /// If this flag is specified, the object is not deleted when all open handles are closed.
+ /// </summary>
+ OBJ_PERMANENT = 0x00000010,
+
+ /// <summary>
+ /// Only a single handle can be open for this object.
+ /// </summary>
+ OBJ_EXCLUSIVE = 0x00000020,
+
+ /// <summary>
+ /// Lookups for this object should be case insensitive.
+ /// </summary>
+ OBJ_CASE_INSENSITIVE = 0x00000040,
+
+ /// <summary>
+ /// Create on existing object should open, not fail with STATUS_OBJECT_NAME_COLLISION.
+ /// </summary>
+ OBJ_OPENIF = 0x00000080,
+
+ /// <summary>
+ /// Open the symbolic link, not its target.
+ /// </summary>
+ OBJ_OPENLINK = 0x00000100,
+
+ // Only accessible from kernel mode
+ // OBJ_KERNEL_HANDLE
+
+ // Access checks enforced, even in kernel mode
+ // OBJ_FORCE_ACCESS_CHECK
+ // OBJ_VALID_ATTRIBUTES = 0x000001F2
+ }
+}
}
/// <summary>
- /// <a href="https://msdn.microsoft.com/en-us/library/windows/hardware/ff557749.aspx">OBJECT_ATTRIBUTES</a> structure.
- /// The OBJECT_ATTRIBUTES structure specifies attributes that can be applied to objects or object handles by routines
- /// that create objects and/or return handles to objects.
- /// </summary>
- internal unsafe struct OBJECT_ATTRIBUTES
- {
- public uint Length;
-
- /// <summary>
- /// Optional handle to root object directory for the given ObjectName.
- /// Can be a file system directory or object manager directory.
- /// </summary>
- public IntPtr RootDirectory;
-
- /// <summary>
- /// Name of the object. Must be fully qualified if RootDirectory isn't set.
- /// Otherwise is relative to RootDirectory.
- /// </summary>
- public UNICODE_STRING* ObjectName;
-
- public ObjectAttributes Attributes;
-
- /// <summary>
- /// If null, object will receive default security settings.
- /// </summary>
- public void* SecurityDescriptor;
-
- /// <summary>
- /// Optional quality of service to be applied to the object. Used to indicate
- /// security impersonation level and context tracking mode (dynamic or static).
- /// </summary>
- public void* SecurityQualityOfService;
-
- /// <summary>
- /// Equivalent of InitializeObjectAttributes macro with the exception that you can directly set SQOS.
- /// </summary>
- public unsafe OBJECT_ATTRIBUTES(UNICODE_STRING* objectName, ObjectAttributes attributes, IntPtr rootDirectory)
- {
- Length = (uint)sizeof(OBJECT_ATTRIBUTES);
- RootDirectory = rootDirectory;
- ObjectName = objectName;
- Attributes = attributes;
- SecurityDescriptor = null;
- SecurityQualityOfService = null;
- }
- }
-
- [Flags]
- public enum ObjectAttributes : uint
- {
- // https://msdn.microsoft.com/en-us/library/windows/hardware/ff564586.aspx
- // https://msdn.microsoft.com/en-us/library/windows/hardware/ff547804.aspx
-
- /// <summary>
- /// This handle can be inherited by child processes of the current process.
- /// </summary>
- OBJ_INHERIT = 0x00000002,
-
- /// <summary>
- /// This flag only applies to objects that are named within the object manager.
- /// By default, such objects are deleted when all open handles to them are closed.
- /// If this flag is specified, the object is not deleted when all open handles are closed.
- /// </summary>
- OBJ_PERMANENT = 0x00000010,
-
- /// <summary>
- /// Only a single handle can be open for this object.
- /// </summary>
- OBJ_EXCLUSIVE = 0x00000020,
-
- /// <summary>
- /// Lookups for this object should be case insensitive.
- /// </summary>
- OBJ_CASE_INSENSITIVE = 0x00000040,
-
- /// <summary>
- /// Create on existing object should open, not fail with STATUS_OBJECT_NAME_COLLISION.
- /// </summary>
- OBJ_OPENIF = 0x00000080,
-
- /// <summary>
- /// Open the symbolic link, not its target.
- /// </summary>
- OBJ_OPENLINK = 0x00000100,
-
- // Only accessible from kernel mode
- // OBJ_KERNEL_HANDLE
-
- // Access checks enforced, even in kernel mode
- // OBJ_FORCE_ACCESS_CHECK
- // OBJ_VALID_ATTRIBUTES = 0x000001F2
- }
-
- /// <summary>
/// File creation disposition when calling directly to NT APIs.
/// </summary>
public enum CreateDisposition : uint
{
internal KERB_LOGON_SUBMIT_TYPE MessageType;
internal KerbS4uLogonFlags Flags;
- internal LSA_UNICODE_STRING ClientUpn;
- internal LSA_UNICODE_STRING ClientRealm;
+ internal UNICODE_STRING ClientUpn;
+ internal UNICODE_STRING ClientRealm;
}
[Flags]
}
[StructLayout(LayoutKind.Sequential)]
- internal struct LSA_OBJECT_ATTRIBUTES
- {
- internal int Length;
- internal IntPtr RootDirectory;
- internal IntPtr ObjectName;
- internal int Attributes;
- internal IntPtr SecurityDescriptor;
- internal IntPtr SecurityQualityOfService;
- }
-
- [StructLayout(LayoutKind.Sequential)]
internal struct LSA_TRANSLATED_SID2
{
internal int Use;
[DllImport(Libraries.SspiCli)]
internal static extern int LsaLogonUser(
[In] SafeLsaHandle LsaHandle,
- [In] ref LSA_STRING OriginName,
+ [In] ref Advapi32.LSA_STRING OriginName,
[In] SECURITY_LOGON_TYPE LogonType,
[In] int AuthenticationPackage,
[In] IntPtr AuthenticationInformation,
using System;
using System.Runtime.InteropServices;
-
using Microsoft.Win32.SafeHandles;
internal partial class Interop
internal partial class SspiCli
{
[DllImport(Libraries.SspiCli)]
- internal static extern int LsaLookupAuthenticationPackage(SafeLsaHandle LsaHandle, [In] ref LSA_STRING PackageName, out int AuthenticationPackage);
+ internal static extern int LsaLookupAuthenticationPackage(
+ SafeLsaHandle LsaHandle,
+ [In] ref Advapi32.LSA_STRING PackageName,
+ out int AuthenticationPackage
+ );
}
}
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-using System;
-using System.Runtime.InteropServices;
-
-internal partial class Interop
-{
- internal partial class SspiCli
- {
- [StructLayout(LayoutKind.Sequential)]
- internal struct LSA_UNICODE_STRING
- {
- internal LSA_UNICODE_STRING(IntPtr pBuffer, ushort length)
- {
- Length = length;
- MaximumLength = length;
- Buffer = pBuffer;
- }
-
- /// <summary>
- /// Specifies the length, in bytes, of the string in Buffer. This value does not include the terminating null character, if any.
- /// </summary>
- internal ushort Length;
-
- /// <summary>
- /// Specifies the total size, in bytes, of Buffer. Up to MaximumLength bytes may be written into the buffer without trampling memory.
- /// </summary>
- internal ushort MaximumLength;
-
- /// <summary>
- /// Pointer to a wide character string. Note that strings returned by the LSA may not be null-terminated.
- /// </summary>
- internal IntPtr Buffer;
- }
- }
-}
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-using System;
-using System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
- internal struct UNICODE_STRING
- {
- internal ushort Length;
- internal ushort MaximumLength;
- [MarshalAs(UnmanagedType.LPWStr)]
- internal string Buffer;
- }
-}
--- /dev/null
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Runtime.InteropServices;
+
+namespace Microsoft.Win32.SafeHandles
+{
+ internal sealed class SafeLsaMemoryHandle : SafeBuffer
+ {
+ private SafeLsaMemoryHandle() : base(true) { }
+
+ // 0 is an Invalid Handle
+ internal SafeLsaMemoryHandle(IntPtr handle) : base(true)
+ {
+ SetHandle(handle);
+ }
+
+ override protected bool ReleaseHandle()
+ {
+ return Interop.Advapi32.LsaFreeMemory(handle) == 0;
+ }
+ }
+}
--- /dev/null
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+
+namespace Microsoft.Win32.SafeHandles
+{
+ internal sealed class SafeLsaPolicyHandle : SafeHandleZeroOrMinusOneIsInvalid
+ {
+ private SafeLsaPolicyHandle() : base(true) { }
+
+ // 0 is an Invalid Handle
+ internal SafeLsaPolicyHandle(IntPtr handle) : base(true)
+ {
+ SetHandle(handle);
+ }
+
+ override protected bool ReleaseHandle()
+ {
+ return Interop.Advapi32.LsaClose(handle) == 0;
+ }
+ }
+}
--- /dev/null
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Runtime.InteropServices;
+using System.Security;
+
+namespace Microsoft.Win32.SafeHandles
+{
+ internal sealed class SafeLsaReturnBufferHandle : SafeBuffer
+ {
+ private SafeLsaReturnBufferHandle() : base(true) { }
+
+ // 0 is an Invalid Handle
+ internal SafeLsaReturnBufferHandle(IntPtr handle) : base(true)
+ {
+ SetHandle(handle);
+ }
+
+ override protected bool ReleaseHandle()
+ {
+ // LsaFreeReturnBuffer returns an NTSTATUS
+ return Interop.SspiCli.LsaFreeReturnBuffer(handle) >= 0;
+ }
+ }
+}
<Compile Include="$(CommonPath)\Interop\Windows\Interop.UNICODE_STRING.cs">
<Link>Common\Interop\Windows\Interop.UNICODE_STRING.cs</Link>
</Compile>
+ <Compile Include="$(CommonPath)\Interop\Windows\Interop.OBJECT_ATTRIBUTES.cs">
+ <Link>Common\Interop\Windows\Interop.OBJECT_ATTRIBUTES.cs</Link>
+ </Compile>
<Compile Include="$(CommonPath)\CoreLib\Interop\Windows\Interop.BOOLEAN.cs">
<Link>Common\Interop\Windows\Interop.BOOLEAN.cs</Link>
</Compile>
<Compile Include="$(CommonPath)\Interop\Windows\Interop.UNICODE_STRING.cs">
<Link>Common\Interop\Windows\Interop.UNICODE_STRING.cs</Link>
</Compile>
+ <Compile Include="$(CommonPath)\Interop\Windows\Interop.OBJECT_ATTRIBUTES.cs">
+ <Link>Common\Interop\Windows\Interop.OBJECT_ATTRIBUTES.cs</Link>
+ </Compile>
<Compile Include="$(CommonPath)\Interop\Windows\Kernel32\Interop.IoControlCodeAccess.cs">
<Link>Common\Interop\Windows\Kernel32\Interop.IoControlCodeAccess.cs</Link>
</Compile>
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-/*============================================================
-**
-** Class: SafeTokenHandle
-**
-** A wrapper for a process handle
-**
-**
-===========================================================*/
-
-using System;
-using System.Diagnostics;
-using System.Runtime.InteropServices;
-using System.Security;
-
-namespace Microsoft.Win32.SafeHandles
-{
- internal sealed class SafeTokenHandle : SafeHandle
- {
- private const int DefaultInvalidHandleValue = 0;
-
- internal static readonly SafeTokenHandle InvalidHandle = new SafeTokenHandle(new IntPtr(DefaultInvalidHandleValue));
-
- internal SafeTokenHandle() : base(new IntPtr(DefaultInvalidHandleValue), true) { }
-
- internal SafeTokenHandle(IntPtr handle)
- : base(new IntPtr(DefaultInvalidHandleValue), true)
- {
- SetHandle(handle);
- }
-
- public override bool IsInvalid
- {
- get { return handle == IntPtr.Zero || handle == new IntPtr(-1); }
- }
-
- protected override bool ReleaseHandle()
- {
- return Interop.Kernel32.CloseHandle(handle);
- }
- }
-}
</Compile>
</ItemGroup>
<ItemGroup Condition=" '$(TargetsWindows)' == 'true'">
+ <Compile Include="$(CommonPath)\Microsoft\Win32\SafeHandles\SafeTokenHandle.cs">
+ <Link>Microsoft\Win32\SafeHandles\SafeTokenHandle.cs</Link>
+ </Compile>
<Compile Include="$(CommonPath)\Interop\Windows\Interop.Libraries.cs">
<Link>Common\Interop\Windows\Interop.Libraries.cs</Link>
</Compile>
</Compile>
<Compile Include="Microsoft\Win32\SafeHandles\SafeProcessHandle.Windows.cs" />
<Compile Include="Microsoft\Win32\SafeHandles\SafeThreadHandle.cs" />
- <Compile Include="Microsoft\Win32\SafeHandles\SafeTokenHandle.cs" />
<Compile Include="System\Diagnostics\PerformanceCounterLib.cs" />
<Compile Include="System\Diagnostics\Process.Windows.cs" />
<Compile Include="System\Diagnostics\ProcessManager.Windows.cs" />
<Compile Include="$(CommonPath)\Interop\Windows\Interop.UNICODE_STRING.cs">
<Link>Common\Interop\Windows\Interop.UNICODE_STRING.cs</Link>
</Compile>
+ <Compile Include="$(CommonPath)\Interop\Windows\Interop.OBJECT_ATTRIBUTES.cs">
+ <Link>Common\Interop\Windows\Interop.OBJECT_ATTRIBUTES.cs</Link>
+ </Compile>
<Compile Include="$(CommonPath)\CoreLib\Interop\Windows\Interop.BOOLEAN.cs">
<Link>Common\Interop\Windows\Interop.BOOLEAN.cs</Link>
</Compile>
<Compile Include="System\Security\AccessControl\Rules.cs" />
<Compile Include="System\Security\AccessControl\Win32.cs" />
<Compile Include="System\Security\Principal\Win32.cs" />
- <Compile Include="System\Security\SafeSecurityHandles.cs" />
<!-- PInvoke sources -->
<Compile Include="$(CommonPath)\System\NotImplemented.cs">
<Link>Common\System\NotImplemented.cs</Link>
</Compile>
+ <Compile Include="$(CommonPath)\Microsoft\Win32\SafeHandles\SafeTokenHandle.cs">
+ <Link>Microsoft\Win32\SafeHandles\SafeTokenHandle.cs</Link>
+ </Compile>
<Compile Include="$(CommonPath)\Interop\Windows\Interop.Libraries.cs">
<Link>Common\Interop\Interop.Libraries.cs</Link>
</Compile>
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-using System;
-using System.Runtime.InteropServices;
-using System.Security;
-
-namespace Microsoft.Win32.SafeHandles
-{
- internal sealed class SafeLsaMemoryHandle : SafeBuffer
- {
- private SafeLsaMemoryHandle() : base(true) { }
-
- // 0 is an Invalid Handle
- internal SafeLsaMemoryHandle(IntPtr handle) : base(true)
- {
- SetHandle(handle);
- }
-
- override protected bool ReleaseHandle()
- {
- return Interop.Advapi32.LsaFreeMemory(handle) == 0;
- }
- }
-
- internal sealed class SafeLsaPolicyHandle : SafeHandleZeroOrMinusOneIsInvalid
- {
- private SafeLsaPolicyHandle() : base(true) { }
-
- // 0 is an Invalid Handle
- internal SafeLsaPolicyHandle(IntPtr handle) : base(true)
- {
- SetHandle(handle);
- }
-
- override protected bool ReleaseHandle()
- {
- return Interop.Advapi32.LsaClose(handle) == 0;
- }
- }
-
- internal sealed class SafeLsaReturnBufferHandle : SafeBuffer
- {
- private SafeLsaReturnBufferHandle() : base(true) { }
-
- // 0 is an Invalid Handle
- internal SafeLsaReturnBufferHandle(IntPtr handle) : base(true)
- {
- SetHandle(handle);
- }
-
- override protected bool ReleaseHandle()
- {
- // LsaFreeReturnBuffer returns an NTSTATUS
- return Interop.SspiCli.LsaFreeReturnBuffer(handle) >= 0;
- }
- }
-}
</PropertyGroup>
<ItemGroup Condition="($(TargetGroup.StartsWith('netcoreapp')) or '$(TargetGroup)' == 'uap') AND '$(TargetsWindows)' == 'true'">
<Compile Include="Microsoft\Win32\SafeHandles\SafeAccessTokenHandle.cs" />
- <Compile Include="Microsoft\Win32\SafeHandles\SafeSecurityHandles.cs" />
<Compile Include="System\Security\Principal\IdentityNotMappedException.cs" />
<Compile Include="System\Security\Principal\IdentityReference.cs" />
<Compile Include="System\Security\Principal\IRCollection.cs" />
<Compile Include="$(CommonPath)\Interop\Windows\Interop.Libraries.cs">
<Link>Common\Interop\Interop.Libraries.cs</Link>
</Compile>
+ <Compile Include="$(CommonPath)\Interop\Windows\Interop.UNICODE_STRING.cs">
+ <Link>Common\Interop\Windows\Advapi32\Interop.UNICODE_STRING.cs</Link>
+ </Compile>
+ <Compile Include="$(CommonPath)\Interop\Windows\Interop.OBJECT_ATTRIBUTES.cs">
+ <Link>Common\Interop\Windows\Advapi32\Interop.OBJECT_ATTRIBUTES.cs</Link>
+ </Compile>
<Compile Include="$(CommonPath)\Interop\Windows\SspiCli\Interop.TOKENS.cs">
<Link>Common\Interop\Interop.TOKENS.cs</Link>
</Compile>
<Compile Include="$(CommonPath)\Interop\Windows\SspiCli\Interop.SECURITY_LOGON_SESSION_DATA.cs">
<Link>Common\Interop\Interop.SECURITY_LOGON_SESSION_DATA.cs</Link>
</Compile>
- <Compile Include="$(CommonPath)\Interop\Windows\SspiCli\Interop.UNICODE_STRING.cs">
- <Link>Common\Interop\Interop.UNICODE_STRING.cs</Link>
- </Compile>
<Compile Include="$(CommonPath)\CoreLib\Interop\Windows\Kernel32\Interop.GetCurrentProcess_IntPtr.cs">
<Link>Common\Interop\Interop.GetCurrentProcess.cs</Link>
</Compile>
<Compile Include="$(CommonPath)\Interop\Windows\Advapi32\Interop.LsaNtStatusToWinError.cs">
<Link>Common\Interop\Interop.LsaNtStatusToWinError.cs</Link>
</Compile>
+ <Compile Include="$(CommonPath)\Interop\Windows\Advapi32\Interop.LSA_STRING.cs">
+ <Link>Common\Interop\Windows\Advapi32\Interop.LSA_STRING.cs</Link>
+ </Compile>
<Compile Include="$(CommonPath)\Interop\Windows\Kernel32\Interop.LocalFree.cs">
<Link>Common\Interop\Interop.LocalFree.cs</Link>
</Compile>
<Compile Include="$(CommonPath)\Interop\Windows\SspiCli\Interop.LsaLookupAuthenticationPackage.cs">
<Link>Common\Interop\Windows\SspiCli\Interop.LsaLookupAuthenticationPackage.cs</Link>
</Compile>
- <Compile Include="$(CommonPath)\Interop\Windows\SspiCli\Interop.LsaString.cs">
- <Link>Common\Interop\Windows\SspiCli\Interop.LsaString.cs</Link>
- </Compile>
- <Compile Include="$(CommonPath)\Interop\Windows\SspiCli\Interop.LsaUnicodeString.cs">
- <Link>Common\Interop\Windows\SspiCli\Interop.LsaUnicodeString.cs</Link>
- </Compile>
<Compile Include="$(CommonPath)\Interop\Windows\SspiCli\Interop.QuotaLimits.cs">
<Link>Common\Interop\Windows\SspiCli\Interop.QuotaLimits.cs</Link>
</Compile>
<Compile Include="$(CommonPath)\Microsoft\Win32\SafeHandles\SafeLsaHandle.cs">
<Link>Common\Microsoft\Win32\SafeHandles\SafeLsaHandle.cs</Link>
</Compile>
+ <Compile Include="$(CommonPath)\Microsoft\Win32\SafeHandles\SafeLsaMemoryHandle.cs">
+ <Link>Common\Microsoft\Win32\SafeHandles\SafeLsaMemoryHandle.cs</Link>
+ </Compile>
+ <Compile Include="$(CommonPath)\Microsoft\Win32\SafeHandles\SafeLsaPolicyHandle.cs">
+ <Link>Common\Microsoft\Win32\SafeHandles\SafeLsaPolicyHandle.cs</Link>
+ </Compile>
+ <Compile Include="$(CommonPath)\Microsoft\Win32\SafeHandles\SafeLsaReturnBufferHandle.cs">
+ <Link>Common\Microsoft\Win32\SafeHandles\SafeLsaReturnBufferHandle.cs</Link>
+ </Compile>
</ItemGroup>
<ItemGroup Condition="$(TargetGroup.StartsWith('netcoreapp')) AND '$(TargetsWindows)' == 'true'">
<Compile Include="$(CommonPath)\Interop\Windows\Advapi32\Interop.CheckTokenMembership.cs">
// Construct an array of unicode strings
//
- Interop.UNICODE_STRING[] Names = new Interop.UNICODE_STRING[sourceAccounts.Count];
+ Interop.Advapi32.MARSHALLED_UNICODE_STRING[] Names = new Interop.Advapi32.MARSHALLED_UNICODE_STRING[sourceAccounts.Count];
int currentName = 0;
foreach (IdentityReference id in sourceAccounts)
string systemName,
PolicyRights rights)
{
- uint ReturnCode;
- SafeLsaPolicyHandle Result;
- Interop.LSA_OBJECT_ATTRIBUTES Loa;
-
- Loa.Length = Marshal.SizeOf<Interop.LSA_OBJECT_ATTRIBUTES>();
- Loa.RootDirectory = IntPtr.Zero;
- Loa.ObjectName = IntPtr.Zero;
- Loa.Attributes = 0;
- Loa.SecurityDescriptor = IntPtr.Zero;
- Loa.SecurityQualityOfService = IntPtr.Zero;
-
- if (0 == (ReturnCode = Interop.Advapi32.LsaOpenPolicy(systemName, ref Loa, (int)rights, out Result)))
+ SafeLsaPolicyHandle policyHandle;
+
+ var attributes = new Interop.OBJECT_ATTRIBUTES();
+ uint error = Interop.Advapi32.LsaOpenPolicy(systemName, ref attributes, (int)rights, out policyHandle);
+ if (error == 0)
{
- return Result;
+ return policyHandle;
}
- else if (ReturnCode == Interop.StatusOptions.STATUS_ACCESS_DENIED)
+ else if (error == Interop.StatusOptions.STATUS_ACCESS_DENIED)
{
throw new UnauthorizedAccessException();
}
- else if (ReturnCode == Interop.StatusOptions.STATUS_INSUFFICIENT_RESOURCES ||
- ReturnCode == Interop.StatusOptions.STATUS_NO_MEMORY)
+ else if (error == Interop.StatusOptions.STATUS_INSUFFICIENT_RESOURCES ||
+ error == Interop.StatusOptions.STATUS_NO_MEMORY)
{
throw new OutOfMemoryException();
}
else
{
- uint win32ErrorCode = Interop.Advapi32.LsaNtStatusToWinError(ReturnCode);
+ uint win32ErrorCode = Interop.Advapi32.LsaNtStatusToWinError(error);
throw new Win32Exception(unchecked((int)win32ErrorCode));
}
using KERB_S4U_LOGON = Interop.SspiCli.KERB_S4U_LOGON;
using KerbS4uLogonFlags = Interop.SspiCli.KerbS4uLogonFlags;
using LUID = Interop.LUID;
-using LSA_STRING = Interop.SspiCli.LSA_STRING;
+using LSA_STRING = Interop.Advapi32.LSA_STRING;
using QUOTA_LIMITS = Interop.SspiCli.QUOTA_LIMITS;
using SECURITY_LOGON_TYPE = Interop.SspiCli.SECURITY_LOGON_TYPE;
using TOKEN_SOURCE = Interop.SspiCli.TOKEN_SOURCE;