Ejemplo n.º 1
0
 public static string GetDomainForestNameFromServer(string serverFqdn)
 {
     if (string.IsNullOrEmpty(serverFqdn))
     {
         throw new ArgumentNullException("serverFqdn");
     }
     NativeMethods.InteropDsRolePrimaryDomainInfoBasic primaryDomainInformation = NativeHelpers.GetPrimaryDomainInformation(serverFqdn);
     return(primaryDomainInformation.domainForestName);
 }
Ejemplo n.º 2
0
        private static NativeMethods.InteropDsRolePrimaryDomainInfoBasic GetPrimaryDomainInformation(string serverFqdn = null)
        {
            SafeDsRolePrimaryDomainInfoLevelHandle safeDsRolePrimaryDomainInfoLevelHandle = null;
            int num = 0;

            NativeMethods.InteropDsRolePrimaryDomainInfoBasic result;
            try
            {
                int num2;
                for (;;)
                {
                    num2 = NativeMethods.DsRoleGetPrimaryDomainInformation(serverFqdn, NativeMethods.DsRolePrimaryDomainInfoBasic, out safeDsRolePrimaryDomainInfoLevelHandle);
                    if (num2 == 0)
                    {
                        goto IL_8A;
                    }
                    if (num2 != 1723)
                    {
                        goto IL_73;
                    }
                    if (num >= NativeHelpers.MaxCallRetry)
                    {
                        break;
                    }
                    num++;
                    Thread.Sleep(num * NativeHelpers.CallRetryBaseSleepTime);
                }
                Globals.LogEvent(DirectoryEventLogConstants.Tuple_DSC_EVENT_RPC_SERVER_TOO_BUSY, "DsRoleGetPrimaryDomainInformation", new object[]
                {
                    "DsRoleGetPrimaryDomainInformation",
                    1723
                });
                throw new ADTransientException(DirectoryStrings.ExceptionDomainInfoRpcTooBusy);
IL_73:
                throw new CannotGetDomainInfoException(DirectoryStrings.CannotGetDomainInfo(num2.ToString("X")));
IL_8A:
                NativeMethods.InteropDsRolePrimaryDomainInfoBasic interopDsRolePrimaryDomainInfoBasic = new NativeMethods.InteropDsRolePrimaryDomainInfoBasic();
                Marshal.PtrToStructure(safeDsRolePrimaryDomainInfoLevelHandle.DangerousGetHandle(), interopDsRolePrimaryDomainInfoBasic);
                if (string.IsNullOrEmpty(interopDsRolePrimaryDomainInfoBasic.domainNameDns))
                {
                    throw new CannotGetDomainInfoException(DirectoryStrings.CannotGetUsefulDomainInfo);
                }
                result = interopDsRolePrimaryDomainInfoBasic;
            }
            finally
            {
                if (safeDsRolePrimaryDomainInfoLevelHandle != null)
                {
                    safeDsRolePrimaryDomainInfoLevelHandle.Dispose();
                }
            }
            return(result);
        }
Ejemplo n.º 3
0
 public static bool LocalMachineRoleIsDomainController()
 {
     NativeMethods.InteropDsRolePrimaryDomainInfoBasic primaryDomainInformation = NativeHelpers.GetPrimaryDomainInformation(null);
     return(primaryDomainInformation.machineRole == NativeMethods.MachineRole.PrimaryDomainController || primaryDomainInformation.machineRole == NativeMethods.MachineRole.BackupDomainController);
 }
Ejemplo n.º 4
0
 public string GetForestNameHookable()
 {
     NativeMethods.InteropDsRolePrimaryDomainInfoBasic primaryDomainInformation = NativeHelpers.GetPrimaryDomainInformation(null);
     return(primaryDomainInformation.domainForestName);
 }