14 internal struct SECURITY_QUALITY_OF_SERVICE
39 internal struct UNICODE_STRING
48 internal struct OBJECT_ATTRIBUTES
195 [DllImport(
"kernel32.dll")]
198 [DllImport(
"kernel32.dll")]
274 internal static class Advapi32
303 [DllImport(
"advapi32.dll", SetLastError =
true)]
306 [DllImport(
"advapi32.dll", SetLastError =
true)]
309 [DllImport(
"advapi32.dll",
CharSet =
CharSet.Unicode, SetLastError =
true)]
312 [DllImport(
"advapi32.dll", SetLastError =
true)]
315 [DllImport(
"advapi32.dll",
CharSet =
CharSet.Unicode, SetLastError =
true)]
318 [DllImport(
"advapi32.dll",
CharSet =
CharSet.Unicode, SetLastError =
true)]
321 [DllImport(
"advapi32.dll", SetLastError =
true)]
324 [DllImport(
"advapi32.dll", SetLastError =
true)]
327 [DllImport(
"advapi32.dll",
CharSet =
CharSet.Unicode, SetLastError =
true)]
335 if (SystemName !=
null)
337 fixed (
char* ptr = SystemName)
339 SystemName2.Length = (ushort)(SystemName.Length * 2);
340 SystemName2.MaximumLength = (ushort)(SystemName.Length * 2);
341 SystemName2.Buffer = (
IntPtr)ptr;
342 return LsaOpenPolicy(ref SystemName2, ref Attributes, AccessMask, out PolicyHandle);
345 return LsaOpenPolicy(ref SystemName2, ref Attributes, AccessMask, out PolicyHandle);
349 [DllImport(
"advapi32.dll",
CharSet =
CharSet.Unicode, EntryPoint =
"ConvertStringSidToSidW", SetLastError =
true)]
352 [DllImport(
"advapi32.dll",
CharSet =
CharSet.Unicode, SetLastError =
true)]
353 internal static extern int CreateWellKnownSid(
int sidType,
byte[] domainSid,
byte[] resultSid, ref uint resultSidLength);
355 [DllImport(
"advapi32.dll",
CharSet =
CharSet.Unicode, SetLastError =
true)]
358 [DllImport(
"advapi32.dll",
CharSet =
CharSet.Unicode, SetLastError =
true)]
361 [DllImport(
"advapi32.dll",
CharSet =
CharSet.Unicode, EntryPoint =
"EqualDomainSid", SetLastError =
true)]
364 [DllImport(
"advapi32.dll", SetLastError =
true)]
369 bool bOpenAsSelf =
true;
389 [DllImport(
"advapi32.dll",
CharSet =
CharSet.Unicode, ExactSpelling =
true, SetLastError =
true)]
392 [DllImport(
"advapi32.dll",
CharSet =
CharSet.Unicode, SetLastError =
true)]
395 [DllImport(
"advapi32.dll")]
398 [DllImport(
"advapi32.dll")]
401 [DllImport(
"advapi32.dll", SetLastError =
true)]
459 [DllImport(
"sspicli.dll", SetLastError =
true)]
462 [DllImport(
"sspicli.dll", SetLastError =
true)]
465 [DllImport(
"sspicli.dll")]
468 [DllImport(
"sspicli.dll")]
471 [DllImport(
"sspicli.dll")]
472 internal static extern int LsaLogonUser([In]
SafeLsaHandle LsaHandle, [In] ref
Advapi32.
LSA_STRING OriginName, [In]
SECURITY_LOGON_TYPE LogonType, [In]
int AuthenticationPackage, [In]
IntPtr AuthenticationInformation, [In]
int AuthenticationInformationLength, [In]
IntPtr LocalGroups, [In] ref
TOKEN_SOURCE SourceContext, out
SafeLsaReturnBufferHandle ProfileBuffer, out
int ProfileBufferLength, out
LUID LogonId, out
SafeAccessTokenHandle Token, out
QUOTA_LIMITS Quotas, out
int SubStatus);
474 [DllImport(
"sspicli.dll")]
static int IsWellKnownSid(byte[] sid, int type)
static int LsaFreeMemory(IntPtr handle)
static int CreateWellKnownSid(int sidType, byte[] domainSid, byte[] resultSid, ref uint resultSidLength)
static int LsaClose(IntPtr handle)
static int IsEqualDomainSid(byte[] sid1, byte[] sid2, out bool result)
static bool OpenProcessToken(IntPtr ProcessToken, TokenAccessLevels DesiredAccess, out SafeAccessTokenHandle TokenHandle)
static uint LsaLookupNames2(SafeLsaPolicyHandle handle, int flags, int count, MARSHALLED_UNICODE_STRING[] names, out SafeLsaMemoryHandle referencedDomains, out SafeLsaMemoryHandle sids)
static bool OpenThreadToken(IntPtr ThreadHandle, TokenAccessLevels dwDesiredAccess, bool bOpenAsSelf, out SafeTokenHandle phThreadToken)
static bool GetTokenInformation(SafeAccessTokenHandle TokenHandle, uint TokenInformationClass, SafeLocalAllocHandle TokenInformation, uint TokenInformationLength, out uint ReturnLength)
static bool DuplicateTokenEx(SafeAccessTokenHandle hExistingToken, uint dwDesiredAccess, IntPtr lpTokenAttributes, uint ImpersonationLevel, uint TokenType, ref SafeAccessTokenHandle phNewToken)
static bool ImpersonateLoggedOnUser(SafeAccessTokenHandle userToken)
static bool OpenThreadToken(IntPtr ThreadHandle, TokenAccessLevels dwDesiredAccess, bool bOpenAsSelf, out SafeAccessTokenHandle phThreadToken)
static bool CheckTokenMembership(SafeAccessTokenHandle TokenHandle, byte[] SidToCheck, ref bool IsMember)
static bool GetTokenInformation(IntPtr TokenHandle, uint TokenInformationClass, IntPtr TokenInformation, uint TokenInformationLength, out uint ReturnLength)
static bool AllocateLocallyUniqueId(out LUID Luid)
static int GetWindowsAccountDomainSid(byte[] sid, byte[] resultSid, ref uint resultSidLength)
static uint LsaLookupSids(SafeLsaPolicyHandle handle, int count, IntPtr[] sids, out SafeLsaMemoryHandle referencedDomains, out SafeLsaMemoryHandle names)
static unsafe uint LsaOpenPolicy(string SystemName, ref OBJECT_ATTRIBUTES Attributes, int AccessMask, out SafeLsaPolicyHandle PolicyHandle)
static uint LsaOpenPolicy(ref UNICODE_STRING SystemName, ref OBJECT_ATTRIBUTES ObjectAttributes, int AccessMask, out SafeLsaPolicyHandle PolicyHandle)
static bool RevertToSelf()
static uint LsaNtStatusToWinError(uint status)
static bool OpenThreadToken(TokenAccessLevels desiredAccess, WinSecurityContext openAs, out SafeAccessTokenHandle tokenHandle)
static int ConvertStringSidToSid(string stringSid, out IntPtr ByteArray)
static void SetLastError(int errorCode)
static IntPtr GetCurrentThread()
static bool CloseHandle(IntPtr handle)
static bool DuplicateHandle(IntPtr hSourceProcessHandle, IntPtr hSourceHandle, IntPtr hTargetProcessHandle, ref SafeAccessTokenHandle lpTargetHandle, uint dwDesiredAccess, bool bInheritHandle, uint dwOptions)
static IntPtr GetCurrentProcess()
static int LsaLookupAuthenticationPackage(SafeLsaHandle LsaHandle, [In] ref Advapi32.LSA_STRING PackageName, out int AuthenticationPackage)
static int LsaGetLogonSessionData(ref LUID LogonId, out SafeLsaReturnBufferHandle ppLogonSessionData)
static int LsaLogonUser([In] SafeLsaHandle LsaHandle, [In] ref Advapi32.LSA_STRING OriginName, [In] SECURITY_LOGON_TYPE LogonType, [In] int AuthenticationPackage, [In] IntPtr AuthenticationInformation, [In] int AuthenticationInformationLength, [In] IntPtr LocalGroups, [In] ref TOKEN_SOURCE SourceContext, out SafeLsaReturnBufferHandle ProfileBuffer, out int ProfileBufferLength, out LUID LogonId, out SafeAccessTokenHandle Token, out QUOTA_LIMITS Quotas, out int SubStatus)
@ KERB_S4U_LOGON_FLAG_IDENTITY
@ KERB_S4U_LOGON_FLAG_CHECK_LOGONHOURS
static int LsaConnectUntrusted(out SafeLsaHandle LsaHandle)
static int LsaFreeReturnBuffer(IntPtr handle)
static int LsaDeregisterLogonProcess(IntPtr LsaHandle)
ClaimSecurityAttributeType
@ CLAIM_SECURITY_ATTRIBUTE_TYPE_UINT64
@ CLAIM_SECURITY_ATTRIBUTE_TYPE_FQBN
@ CLAIM_SECURITY_ATTRIBUTE_TYPE_STRING
@ CLAIM_SECURITY_ATTRIBUTE_TYPE_BOOLEAN
@ CLAIM_SECURITY_ATTRIBUTE_TYPE_SID
@ CLAIM_SECURITY_ATTRIBUTE_TYPE_INT64
@ CLAIM_SECURITY_ATTRIBUTE_TYPE_INVALID
@ CLAIM_SECURITY_ATTRIBUTE_TYPE_OCTET_STRING
LSA_STRING(IntPtr pBuffer, ushort length)
CLAIM_VALUES_ATTRIBUTE_V1 Values
ClaimSecurityAttributeType ValueType
UNICODE_INTPTR_STRING Name
unsafe void * SecurityDescriptor
unsafe SECURITY_QUALITY_OF_SERVICE * SecurityQualityOfService
unsafe UNICODE_STRING * ObjectName
ObjectAttributes Attributes
UNICODE_INTPTR_STRING AuthenticationPackage
UNICODE_INTPTR_STRING UserName
UNICODE_INTPTR_STRING LogonDomain
ImpersonationLevel ImpersonationLevel
ContextTrackingMode ContextTrackingMode
UNICODE_STRING ClientRealm
KERB_LOGON_SUBMIT_TYPE MessageType
IntPtr MinimumWorkingSetSize
IntPtr MaximumWorkingSetSize
SID_AND_ATTRIBUTES Groups