_generated\0\LibraryImports.g.cs (44)
329internal static partial int LsaGetLogonSessionData(ref global::Interop.LUID LogonId, out global::Microsoft.Win32.SafeHandles.SafeLsaReturnBufferHandle ppLogonSessionData)
341fixed (global::Interop.LUID* __LogonId_native = &LogonId)
367static extern unsafe int __PInvoke(global::Interop.LUID* __LogonId_native, nint* __ppLogonSessionData_native);
399internal static partial uint LsaLookupNames2(global::Microsoft.Win32.SafeHandles.SafeLsaPolicyHandle handle, int flags, int count, global::Interop.Advapi32.MARSHALLED_UNICODE_STRING[] names, out global::Microsoft.Win32.SafeHandles.SafeLsaMemoryHandle referencedDomains, out global::Microsoft.Win32.SafeHandles.SafeLsaMemoryHandle sids)
406global::Interop.Advapi32.MARSHALLED_UNICODE_STRING.Marshaller.Native* __names_native = default;
413scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller<global::Interop.Advapi32.MARSHALLED_UNICODE_STRING, global::Interop.Advapi32.MARSHALLED_UNICODE_STRING.Marshaller.Native>.ManagedToUnmanagedIn __names_native__marshaller = new();
419__names_native__marshaller.FromManaged(names, stackalloc global::Interop.Advapi32.MARSHALLED_UNICODE_STRING.Marshaller.Native[global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller<global::Interop.Advapi32.MARSHALLED_UNICODE_STRING, global::Interop.Advapi32.MARSHALLED_UNICODE_STRING.Marshaller.Native>.ManagedToUnmanagedIn.BufferSize]);
421global::System.ReadOnlySpan<global::Interop.Advapi32.MARSHALLED_UNICODE_STRING> __names_native__managedSpan = __names_native__marshaller.GetManagedValuesSource();
422global::System.Span<global::Interop.Advapi32.MARSHALLED_UNICODE_STRING.Marshaller.Native> __names_native__nativeSpan = __names_native__marshaller.GetUnmanagedValuesDestination();
425__names_native__nativeSpan[__i0] = global::Interop.Advapi32.MARSHALLED_UNICODE_STRING.Marshaller.ConvertToUnmanaged(__names_native__managedSpan[__i0]);
461global::System.ReadOnlySpan<global::Interop.Advapi32.MARSHALLED_UNICODE_STRING.Marshaller.Native> __names_native__nativeSpan = __names_native__marshaller.GetUnmanagedValuesDestination();
464global::Interop.Advapi32.MARSHALLED_UNICODE_STRING.Marshaller.Free(__names_native__nativeSpan[__i0]);
476static extern unsafe uint __PInvoke(nint __handle_native, int __flags_native, int __count_native, global::Interop.Advapi32.MARSHALLED_UNICODE_STRING.Marshaller.Native* __names_native, nint* __referencedDomains_native, nint* __sids_native);
593private static partial uint LsaOpenPolicy(ref global::Interop.UNICODE_STRING SystemName, ref global::Interop.OBJECT_ATTRIBUTES ObjectAttributes, int AccessMask, out global::Microsoft.Win32.SafeHandles.SafeLsaPolicyHandle PolicyHandle)
605fixed (global::Interop.OBJECT_ATTRIBUTES* __ObjectAttributes_native = &ObjectAttributes)
606fixed (global::Interop.UNICODE_STRING* __SystemName_native = &SystemName)
632static extern unsafe uint __PInvoke(global::Interop.UNICODE_STRING* __SystemName_native, global::Interop.OBJECT_ATTRIBUTES* __ObjectAttributes_native, int __AccessMask_native, nint* __PolicyHandle_native);
641internal static unsafe partial global::Interop.BOOL ConvertStringSidToSid(string StringSid, out void* Sid)
645global::Interop.BOOL __retVal;
659static extern unsafe global::Interop.BOOL __PInvoke(ushort* __StringSid_native, void** __Sid_native);
980internal static partial int LsaLogonUser(global::Microsoft.Win32.SafeHandles.SafeLsaHandle LsaHandle, in global::Interop.Advapi32.LSA_STRING OriginName, global::Interop.SspiCli.SECURITY_LOGON_TYPE LogonType, int AuthenticationPackage, nint AuthenticationInformation, int AuthenticationInformationLength, nint LocalGroups, in global::Interop.SspiCli.TOKEN_SOURCE SourceContext, out global::Microsoft.Win32.SafeHandles.SafeLsaReturnBufferHandle ProfileBuffer, out int ProfileBufferLength, out global::Interop.LUID LogonId, out global::Microsoft.Win32.SafeHandles.SafeAccessTokenHandle Token, out global::Interop.SspiCli.QUOTA_LIMITS Quotas, out int SubStatus)
1003fixed (global::Interop.SspiCli.QUOTA_LIMITS* __Quotas_native = &Quotas)
1004fixed (global::Interop.LUID* __LogonId_native = &LogonId)
1006fixed (global::Interop.SspiCli.TOKEN_SOURCE* __SourceContext_native = &SourceContext)
1007fixed (global::Interop.Advapi32.LSA_STRING* __OriginName_native = &OriginName)
1038static extern unsafe int __PInvoke(nint __LsaHandle_native, global::Interop.Advapi32.LSA_STRING* __OriginName_native, global::Interop.SspiCli.SECURITY_LOGON_TYPE __LogonType_native, int __AuthenticationPackage_native, nint __AuthenticationInformation_native, int __AuthenticationInformationLength_native, nint __LocalGroups_native, global::Interop.SspiCli.TOKEN_SOURCE* __SourceContext_native, nint* __ProfileBuffer_native, int* __ProfileBufferLength_native, global::Interop.LUID* __LogonId_native, nint* __Token_native, global::Interop.SspiCli.QUOTA_LIMITS* __Quotas_native, int* __SubStatus_native);
1047internal static partial int LsaLookupAuthenticationPackage(global::Microsoft.Win32.SafeHandles.SafeLsaHandle LsaHandle, ref global::Interop.Advapi32.LSA_STRING PackageName, out int AuthenticationPackage)
1060fixed (global::Interop.Advapi32.LSA_STRING* __PackageName_native = &PackageName)
1076static extern unsafe int __PInvoke(nint __LsaHandle_native, global::Interop.Advapi32.LSA_STRING* __PackageName_native, int* __AuthenticationPackage_native);
1085internal static unsafe partial bool AllocateLocallyUniqueId(global::Interop.LUID* Luid)
1098static extern unsafe int __PInvoke(global::Interop.LUID* __Luid_native);
System\Security\Principal\Win32.cs (16)
22Interop.Advapi32.PolicyRights rights)
25Interop.OBJECT_ATTRIBUTES attributes = default;
26uint error = Interop.Advapi32.LsaOpenPolicy(systemName, ref attributes, (int)rights, out SafeLsaPolicyHandle policyHandle);
34if (error == Interop.StatusOptions.STATUS_ACCESS_DENIED)
38else if (error == Interop.StatusOptions.STATUS_INSUFFICIENT_RESOURCES ||
39error == Interop.StatusOptions.STATUS_NO_MEMORY)
45uint win32ErrorCode = Interop.Advapi32.LsaNtStatusToWinError(error);
110if (Interop.BOOL.FALSE == Interop.Advapi32.ConvertStringSidToSid(stringSid, out pSid))
131return Interop.Errors.ERROR_SUCCESS;
158if (FALSE != Interop.Advapi32.CreateWellKnownSid((int)sidType, domainSid?.BinaryForm, resultSid, ref length))
160return Interop.Errors.ERROR_SUCCESS;
189return (Interop.Advapi32.IsEqualDomainSid(BinaryForm1, BinaryForm2, out bool result) == FALSE ? false : result);
211if (FALSE != Interop.Advapi32.GetWindowsAccountDomainSid(BinaryForm, resultSidBinary, ref sidLength))
215return Interop.Errors.ERROR_SUCCESS;
238if (FALSE == Interop.Advapi32.IsWellKnownSid(BinaryForm, (int)type))
System\Security\Principal\WindowsIdentity.cs (91)
16using KERB_LOGON_SUBMIT_TYPE = Interop.SspiCli.KERB_LOGON_SUBMIT_TYPE;
17using KERB_S4U_LOGON = Interop.SspiCli.KERB_S4U_LOGON;
18using KerbS4uLogonFlags = Interop.SspiCli.KerbS4uLogonFlags;
19using LSA_STRING = Interop.Advapi32.LSA_STRING;
20using LUID = Interop.LUID;
21using QUOTA_LIMITS = Interop.SspiCli.QUOTA_LIMITS;
22using SECURITY_LOGON_TYPE = Interop.SspiCli.SECURITY_LOGON_TYPE;
23using TOKEN_SOURCE = Interop.SspiCli.TOKEN_SOURCE;
137int packageId = LookupAuthenticationPackage(lsaHandle, Interop.SspiCli.AuthenticationPackageNames.MICROSOFT_KERBEROS_NAME_A);
146if (!Interop.Advapi32.AllocateLocallyUniqueId(&sourceContext.SourceIdentifier))
191int ntStatus = Interop.SspiCli.LsaLogonUser(
209if (ntStatus == unchecked((int)Interop.StatusOptions.STATUS_ACCOUNT_RESTRICTION) && subStatus < 0)
234int ntStatus = Interop.SspiCli.LsaConnectUntrusted(out SafeLsaHandle lsaHandle);
250int ntStatus = Interop.SspiCli.LsaLookupAuthenticationPackage(lsaHandle, ref lsaPackageName, out packageId);
266if (!Interop.Advapi32.GetTokenInformation(
272Marshal.GetLastPInvokeError() == Interop.Errors.ERROR_INVALID_HANDLE)
278IntPtr currentProcessHandle = Interop.Kernel32.GetCurrentProcess();
279if (!Interop.Kernel32.DuplicateHandle(
286Interop.DuplicateHandleOptions.DUPLICATE_SAME_ACCESS))
387Interop.LUID authId = GetLogonAuthId(_safeTokenHandle);
388if (authId.LowPart == Interop.LuidOptions.ANONYMOUS_LOGON_LUID)
394int status = Interop.SspiCli.LsaGetLogonSessionData(ref authId, out pLogonSessionData);
398pLogonSessionData.Initialize((uint)sizeof(Interop.SECURITY_LOGON_SESSION_DATA));
400Interop.SECURITY_LOGON_SESSION_DATA logonSessionData = pLogonSessionData.Read<Interop.SECURITY_LOGON_SESSION_DATA>(0);
458new int[] { Interop.SecurityIdentifier.SECURITY_AUTHENTICATED_USER_RID }
484!Interop.Advapi32.DuplicateTokenEx(_safeTokenHandle,
495if (!Interop.Advapi32.CheckTokenMembership((til != TokenImpersonationLevel.None ? _safeTokenHandle : token),
526new int[] { Interop.SecurityIdentifier.SECURITY_BUILTIN_DOMAIN_RID, (int)WindowsBuiltInRole.Guest }
543new int[] { Interop.SecurityIdentifier.SECURITY_LOCAL_SYSTEM_RID }
560new int[] { Interop.SecurityIdentifier.SECURITY_ANONYMOUS_LOGON_RID }
648Interop.TOKEN_GROUPS tokenGroups = pGroups!.Read<Interop.TOKEN_GROUPS>(0);
649Interop.SID_AND_ATTRIBUTES[] groupDetails = new Interop.SID_AND_ATTRIBUTES[tokenGroups.GroupCount];
655foreach (Interop.SID_AND_ATTRIBUTES group in groupDetails)
658uint mask = Interop.SecurityGroups.SE_GROUP_ENABLED | Interop.SecurityGroups.SE_GROUP_LOGON_ID | Interop.SecurityGroups.SE_GROUP_USE_FOR_DENY_ONLY;
659if ((group.Attributes & mask) == Interop.SecurityGroups.SE_GROUP_ENABLED)
779if (!Interop.Advapi32.RevertToSelf())
784if (!token.IsInvalid && !Interop.Advapi32.ImpersonateLoggedOnUser(token))
799if (!Interop.Advapi32.RevertToSelf())
804if (!Interop.Advapi32.ImpersonateLoggedOnUser(args.CurrentValue))
842if ((uint)status == Interop.StatusOptions.STATUS_ACCESS_DENIED)
845if ((uint)status == Interop.StatusOptions.STATUS_INSUFFICIENT_RESOURCES || (uint)status == Interop.StatusOptions.STATUS_NO_MEMORY)
848uint win32ErrorCode = Interop.Advapi32.LsaNtStatusToWinError((uint)status);
856bool success = Interop.Advapi32.OpenThreadToken(desiredAccess, WinSecurityContext.Both, out SafeAccessTokenHandle safeTokenHandle);
860if (hr == GetHRForWin32Error(Interop.Errors.ERROR_NO_TOKEN))
878if (!Interop.Advapi32.OpenProcessToken(Interop.Kernel32.GetCurrentProcess(), desiredAccess, out SafeAccessTokenHandle safeTokenHandle))
900private static Interop.LUID GetLogonAuthId(SafeAccessTokenHandle safeTokenHandle)
904Interop.TOKEN_STATISTICS statistics = pStatistics!.Read<Interop.TOKEN_STATISTICS>(0);
914Interop.Advapi32.GetTokenInformation(tokenHandle,
922case Interop.Errors.ERROR_BAD_LENGTH: // special case for TokenSessionId. Falling through
923case Interop.Errors.ERROR_INSUFFICIENT_BUFFER:
927bool result = Interop.Advapi32.GetTokenInformation(tokenHandle,
938case Interop.Errors.ERROR_INVALID_HANDLE:
941case Interop.Errors.ERROR_INVALID_PARAMETER:
1095Interop.TOKEN_PRIMARY_GROUP primaryGroup = *(Interop.TOKEN_PRIMARY_GROUP*)(safeAllocHandlePrimaryGroup!.DangerousGetHandle());
1104Interop.SID_AND_ATTRIBUTES* pSidAndAttributes = (Interop.SID_AND_ATTRIBUTES*)
1109Interop.SID_AND_ATTRIBUTES group = pSidAndAttributes[i];
1110uint mask = Interop.SecurityGroups.SE_GROUP_ENABLED | Interop.SecurityGroups.SE_GROUP_LOGON_ID | Interop.SecurityGroups.SE_GROUP_USE_FOR_DENY_ONLY;
1113if ((group.Attributes & mask) == Interop.SecurityGroups.SE_GROUP_ENABLED)
1127else if ((group.Attributes & mask) == Interop.SecurityGroups.SE_GROUP_USE_FOR_DENY_ONLY)
1163Interop.SID_AND_ATTRIBUTES user = *(Interop.SID_AND_ATTRIBUTES*)(safeAllocHandle!.DangerousGetHandle());
1164uint mask = Interop.SecurityGroups.SE_GROUP_USE_FOR_DENY_ONLY;
1174else if ((user.Attributes & mask) == Interop.SecurityGroups.SE_GROUP_USE_FOR_DENY_ONLY)
1207Interop.SID_AND_ATTRIBUTES* pSidAndAttributes = (Interop.SID_AND_ATTRIBUTES*)
1211Interop.SID_AND_ATTRIBUTES group = pSidAndAttributes[i];
1212uint mask = Interop.SecurityGroups.SE_GROUP_ENABLED | Interop.SecurityGroups.SE_GROUP_LOGON_ID | Interop.SecurityGroups.SE_GROUP_USE_FOR_DENY_ONLY;
1215if ((group.Attributes & mask) == Interop.SecurityGroups.SE_GROUP_ENABLED)
1223else if ((group.Attributes & mask) == Interop.SecurityGroups.SE_GROUP_USE_FOR_DENY_ONLY)
1251Interop.CLAIM_SECURITY_ATTRIBUTES_INFORMATION claimAttributes = *(Interop.CLAIM_SECURITY_ATTRIBUTES_INFORMATION*)(safeAllocHandle!.DangerousGetHandle());
1257Interop.CLAIM_SECURITY_ATTRIBUTE_V1 windowsClaim = ((Interop.CLAIM_SECURITY_ATTRIBUTE_V1*)claimAttributes.Attribute.pAttributeV1)[attribute];
1264case Interop.ClaimSecurityAttributeType.CLAIM_SECURITY_ATTRIBUTE_TYPE_STRING:
1276case Interop.ClaimSecurityAttributeType.CLAIM_SECURITY_ATTRIBUTE_TYPE_INT64:
1289case Interop.ClaimSecurityAttributeType.CLAIM_SECURITY_ATTRIBUTE_TYPE_UINT64:
1301case Interop.ClaimSecurityAttributeType.CLAIM_SECURITY_ATTRIBUTE_TYPE_BOOLEAN: