Beispiel #1
0
 internal static extern int LsaCallAuthenticationPackage(
     [In] LsaLogonProcessSafeHandle lsaHandle,
     [In] int authenticationPackage,
     [In] NegotiateCallerNameRequest protocolSubmitBuffer,
     [In] int submitBufferLength,
     [Out] out IntPtr protocolReturnBuffer,
     [Out] out int returnBufferLength,
     [Out] out int protocolStatus);
Beispiel #2
0
 internal static extern int LsaConnectUntrusted(
     [Out] out LsaLogonProcessSafeHandle lsaHandle);
Beispiel #3
0
 internal static partial uint LsaCallAuthenticationPackage(
     LsaLogonProcessSafeHandle lsaHandle,
     int authenticationPackage,
     in NegotiateCallerNameRequest protocolSubmitBuffer,
Beispiel #4
0
 internal static partial uint LsaConnectUntrusted(
     out LsaLogonProcessSafeHandle lsaHandle);
Beispiel #5
0
        internal static string GetLoggedOnDomain()
        {
            int num  = 0;
            int num1 = 0;
            LsaLogonProcessSafeHandle lsaLogonProcessSafeHandle = null;
            int    num2;
            string dnsDomainName = null;
            NegotiateCallerNameRequest negotiateCallerNameRequest = new NegotiateCallerNameRequest();
            int    num3 = Marshal.SizeOf(negotiateCallerNameRequest);
            IntPtr zero = IntPtr.Zero;
            NegotiateCallerNameResponse negotiateCallerNameResponse = new NegotiateCallerNameResponse();
            int num4 = NativeMethods.LsaConnectUntrusted(out lsaLogonProcessSafeHandle);

            if (num4 != 0)
            {
                if (num4 != -1073741756)
                {
                    throw ExceptionHelper.GetExceptionFromErrorCode(UnsafeNativeMethods.LsaNtStatusToWinError(num4));
                }
                else
                {
                    throw new OutOfMemoryException();
                }
            }
            else
            {
                negotiateCallerNameRequest.messageType = 1;
                num4 = NativeMethods.LsaCallAuthenticationPackage(lsaLogonProcessSafeHandle, 0, negotiateCallerNameRequest, num3, out zero, out num, out num1);
                try
                {
                    if (num4 != 0 || num1 != 0)
                    {
                        if (num4 != -1073741756)
                        {
                            if (num4 != 0 || UnsafeNativeMethods.LsaNtStatusToWinError(num1) != 0x520)
                            {
                                if (num4 != 0)
                                {
                                    num2 = num4;
                                }
                                else
                                {
                                    num2 = num1;
                                }
                                throw ExceptionHelper.GetExceptionFromErrorCode(UnsafeNativeMethods.LsaNtStatusToWinError(num2));
                            }
                            else
                            {
                                if (!Utils.IsSamUser())
                                {
                                    WindowsIdentity current = WindowsIdentity.GetCurrent();
                                    int             num5    = current.Name.IndexOf('\\');
                                    dnsDomainName = current.Name.Substring(0, num5);
                                }
                            }
                        }
                        else
                        {
                            throw new OutOfMemoryException();
                        }
                    }
                    else
                    {
                        Marshal.PtrToStructure(zero, negotiateCallerNameResponse);
                        int num6 = negotiateCallerNameResponse.callerName.IndexOf('\\');
                        dnsDomainName = negotiateCallerNameResponse.callerName.Substring(0, num6);
                    }
                }
                finally
                {
                    if (zero != IntPtr.Zero)
                    {
                        NativeMethods.LsaFreeReturnBuffer(zero);
                    }
                }
                dnsDomainName = DirectoryContext.GetDnsDomainName(dnsDomainName);
                if (dnsDomainName != null)
                {
                    return(dnsDomainName);
                }
                else
                {
                    throw new ActiveDirectoryOperationException(Res.GetString("ContextNotAssociatedWithDomain"));
                }
            }
        }
 internal static extern int LsaConnectUntrusted(out LsaLogonProcessSafeHandle lsaHandle);