Exemplo n.º 1
0
        private string GetUserPrincipalName(int nameFormat)
        {
            // TODO: there is discrepancy between the implementation of this method on net45 - throws if upn not found - and uap and
            // the rest of the platforms - returns ""

            uint userNameSize = 0;

            WindowsNativeMethods.GetUserNameEx(nameFormat, null, ref userNameSize);
            if (userNameSize == 0)
            {
                throw new MsalClientException(
                          MsalError.GetUserNameFailed,
                          MsalErrorMessage.GetUserNameFailed,
                          new Win32Exception(Marshal.GetLastWin32Error()));
            }

            var sb = new StringBuilder((int)userNameSize);

            if (!WindowsNativeMethods.GetUserNameEx(nameFormat, sb, ref userNameSize))
            {
                throw new MsalClientException(
                          MsalError.GetUserNameFailed,
                          MsalErrorMessage.GetUserNameFailed,
                          new Win32Exception(Marshal.GetLastWin32Error()));
            }

            return(sb.ToString());
        }
Exemplo n.º 2
0
        public override bool IsDomainJoined()
        {
            if (!IsWindows)
            {
                return(false);
            }

            bool returnValue = false;

            try
            {
                int result = WindowsNativeMethods.NetGetJoinInformation(null, out var pDomain, out var status);
                if (pDomain != IntPtr.Zero)
                {
                    WindowsNativeMethods.NetApiBufferFree(pDomain);
                }

                returnValue = result == WindowsNativeMethods.ErrorSuccess &&
                              status == WindowsNativeMethods.NetJoinStatus.NetSetupDomainName;
            }
            catch (Exception ex)
            {
                Logger.WarningPii(ex);
                // ignore the exception as the result is already set to false;
            }

            return(returnValue);
        }
Exemplo n.º 3
0
 /// <inheritdoc />
 protected override string InternalGetProcessorArchitecture()
 {
     return(IsWindows ? WindowsNativeMethods.GetProcessorArchitecture() : null);
 }