//
        // this method is called when the forest name is explicitly specified
        // and we want to check if that matches the current logged on forest
        //
        internal bool isCurrentForest()
        {
            bool result = false;

            Debug.Assert(_name != null);
            DomainControllerInfo domainControllerInfo = Locator.GetDomainControllerInfo(null, _name, null, (long)(PrivateLocatorFlags.DirectoryServicesRequired | PrivateLocatorFlags.ReturnDNSName));

            DomainControllerInfo currentDomainControllerInfo;
            string loggedOnDomain = GetLoggedOnDomain();

            int errorCode = Locator.DsGetDcNameWrapper(null, loggedOnDomain, null, (long)(PrivateLocatorFlags.DirectoryServicesRequired | PrivateLocatorFlags.ReturnDNSName), out currentDomainControllerInfo);

            if (errorCode == 0)
            {
                Debug.Assert(domainControllerInfo.DnsForestName != null);
                Debug.Assert(currentDomainControllerInfo.DnsForestName != null);

                result = (Utils.Compare(domainControllerInfo.DnsForestName, currentDomainControllerInfo.DnsForestName) == 0);
            }
            //
            // if there is no forest associated with the logged on domain, then we return false
            //
            else if (errorCode != NativeMethods.ERROR_NO_SUCH_DOMAIN)
            {
                throw ExceptionHelper.GetExceptionFromErrorCode(errorCode);
            }

            return(result);
        }
Beispiel #2
0
        internal static string GetDnsDomainName(string domainName)
        {
            DomainControllerInfo domainControllerInfo = null;
            int num = Locator.DsGetDcNameWrapper(null, domainName, null, (long)16, out domainControllerInfo);

            if (num != 0x54b)
            {
                if (num != 0)
                {
                    throw ExceptionHelper.GetExceptionFromErrorCode(num);
                }
            }
            else
            {
                num = Locator.DsGetDcNameWrapper(null, domainName, null, (long)17, out domainControllerInfo);
                if (num != 0x54b)
                {
                    if (num != 0)
                    {
                        throw ExceptionHelper.GetExceptionFromErrorCode(num);
                    }
                }
                else
                {
                    return(null);
                }
            }
            return(domainControllerInfo.DomainName);
        }
Beispiel #3
0
        internal static int DsGetDcNameWrapper(string computerName, string domainName, string siteName, long flags, out DomainControllerInfo domainControllerInfo)
        {
            IntPtr zero = IntPtr.Zero;

            if (computerName != null && computerName.Length == 0)
            {
                computerName = null;
            }
            if (siteName != null && siteName.Length == 0)
            {
                siteName = null;
            }
            int num = NativeMethods.DsGetDcName(computerName, domainName, IntPtr.Zero, siteName, (int)(flags | (long)0x40000000), out zero);

            if (num != 0)
            {
                domainControllerInfo = new DomainControllerInfo();
            }
            else
            {
                try
                {
                    domainControllerInfo = new DomainControllerInfo();
                    Marshal.PtrToStructure(zero, domainControllerInfo);
                }
                finally
                {
                    if (zero != IntPtr.Zero)
                    {
                        num = NativeMethods.NetApiBufferFree(zero);
                    }
                }
            }
            return(num);
        }
        internal static int DsGetDcNameWrapper(string computerName, string domainName, string siteName, long flags, out DomainControllerInfo domainControllerInfo)
        {
            IntPtr zero = IntPtr.Zero;
            int    num  = 0;

            if ((computerName != null) && (computerName.Length == 0))
            {
                computerName = null;
            }
            if ((siteName != null) && (siteName.Length == 0))
            {
                siteName = null;
            }
            num = System.DirectoryServices.ActiveDirectory.NativeMethods.DsGetDcName(computerName, domainName, IntPtr.Zero, siteName, (int)(flags | 0x40000000L), out zero);
            if (num == 0)
            {
                try
                {
                    domainControllerInfo = new DomainControllerInfo();
                    Marshal.PtrToStructure(zero, domainControllerInfo);
                    return(num);
                }
                finally
                {
                    if (zero != IntPtr.Zero)
                    {
                        num = System.DirectoryServices.ActiveDirectory.NativeMethods.NetApiBufferFree(zero);
                    }
                }
            }
            domainControllerInfo = new DomainControllerInfo();
            return(num);
        }
Beispiel #5
0
        internal static ArrayList EnumerateDomainControllers(DirectoryContext context, string domainName, string siteName, long dcFlags)
        {
            Hashtable            hashtables;
            DomainControllerInfo domainControllerInfo = null;
            ArrayList            arrayLists           = new ArrayList();

            if (siteName == null)
            {
                int num = Locator.DsGetDcNameWrapper(null, domainName, null, dcFlags & (long)0x9040, out domainControllerInfo);
                if (num != 0)
                {
                    if (num != 0x54b)
                    {
                        throw ExceptionHelper.GetExceptionFromErrorCode(num);
                    }
                    else
                    {
                        return(arrayLists);
                    }
                }
                else
                {
                    siteName = domainControllerInfo.ClientSiteName;
                }
            }
            if (!DirectoryContext.DnsgetdcSupported)
            {
                hashtables = Locator.DnsQueryWrapper(domainName, null, dcFlags);
                if (siteName != null)
                {
                    foreach (string key in Locator.DnsQueryWrapper(domainName, siteName, dcFlags).Keys)
                    {
                        if (hashtables.Contains(key))
                        {
                            continue;
                        }
                        hashtables.Add(key, null);
                    }
                }
            }
            else
            {
                hashtables = Locator.DnsGetDcWrapper(domainName, siteName, dcFlags);
            }
            foreach (string str in hashtables.Keys)
            {
                DirectoryContext newDirectoryContext = Utils.GetNewDirectoryContext(str, DirectoryContextType.DirectoryServer, context);
                if ((dcFlags & (long)64) == (long)0)
                {
                    arrayLists.Add(new DomainController(newDirectoryContext, str));
                }
                else
                {
                    arrayLists.Add(new GlobalCatalog(newDirectoryContext, str));
                }
            }
            return(arrayLists);
        }
Beispiel #6
0
        internal static DomainControllerInfo GetDomainControllerInfo(string computerName, string domainName, string siteName, long flags)
        {
            DomainControllerInfo domainControllerInfo = null;
            int num = Locator.DsGetDcNameWrapper(computerName, domainName, siteName, flags, out domainControllerInfo);

            if (num == 0)
            {
                return(domainControllerInfo);
            }
            else
            {
                throw ExceptionHelper.GetExceptionFromErrorCode(num, domainName);
            }
        }
        internal bool isCurrentForest()
        {
            DomainControllerInfo info2;
            DomainControllerInfo info = Locator.GetDomainControllerInfo(null, this.name, null, 0x40000010L);
            string loggedOnDomain     = GetLoggedOnDomain();
            int    errorCode          = Locator.DsGetDcNameWrapper(null, loggedOnDomain, null, 0x40000010L, out info2);

            if (errorCode == 0)
            {
                return(Utils.Compare(info.DnsForestName, info2.DnsForestName) == 0);
            }
            if (errorCode != 0x54b)
            {
                throw System.DirectoryServices.ActiveDirectory.ExceptionHelper.GetExceptionFromErrorCode(errorCode);
            }
            return(false);
        }
Beispiel #8
0
        internal static int DsGetDcNameWrapper(string?computerName, string?domainName, string?siteName, long flags, out DomainControllerInfo domainControllerInfo)
        {
            IntPtr pDomainControllerInfo = IntPtr.Zero;
            int    result = 0;

            // empty siteName/computerName should be treated as null
            if ((computerName != null) && (computerName.Length == 0))
            {
                computerName = null;
            }
            if ((siteName != null) && (siteName.Length == 0))
            {
                siteName = null;
            }

            result = NativeMethods.DsGetDcName(computerName, domainName, IntPtr.Zero, siteName, (int)(flags | (long)PrivateLocatorFlags.ReturnDNSName), out pDomainControllerInfo);
            if (result == 0)
            {
                try
                {
                    // success case
                    domainControllerInfo = new DomainControllerInfo();
                    Marshal.PtrToStructure(pDomainControllerInfo, domainControllerInfo);
                }
                finally
                {
                    // free the buffer
                    // what to do with error code??
                    if (pDomainControllerInfo != IntPtr.Zero)
                    {
                        result = NativeMethods.NetApiBufferFree(pDomainControllerInfo);
                    }
                }
            }
            else
            {
                domainControllerInfo = new DomainControllerInfo();
            }

            return(result);
        }
Beispiel #9
0
        internal bool isCurrentForest()
        {
            DomainControllerInfo domainControllerInfo = null;
            bool flag = false;
            DomainControllerInfo domainControllerInfo1 = Locator.GetDomainControllerInfo(null, this.name, null, (long)0x40000010);
            string loggedOnDomain = DirectoryContext.GetLoggedOnDomain();
            int    num            = Locator.DsGetDcNameWrapper(null, loggedOnDomain, null, (long)0x40000010, out domainControllerInfo);

            if (num != 0)
            {
                if (num != 0x54b)
                {
                    throw ExceptionHelper.GetExceptionFromErrorCode(num);
                }
            }
            else
            {
                flag = Utils.Compare(domainControllerInfo1.DnsForestName, domainControllerInfo.DnsForestName) == 0;
            }
            return(flag);
        }
 internal static int DsGetDcNameWrapper(string computerName, string domainName, string siteName, long flags, out DomainControllerInfo domainControllerInfo)
 {
     IntPtr zero = IntPtr.Zero;
     int num = 0;
     if ((computerName != null) && (computerName.Length == 0))
     {
         computerName = null;
     }
     if ((siteName != null) && (siteName.Length == 0))
     {
         siteName = null;
     }
     num = System.DirectoryServices.ActiveDirectory.NativeMethods.DsGetDcName(computerName, domainName, IntPtr.Zero, siteName, (int) (flags | 0x40000000L), out zero);
     if (num == 0)
     {
         try
         {
             domainControllerInfo = new DomainControllerInfo();
             Marshal.PtrToStructure(zero, domainControllerInfo);
             return num;
         }
         finally
         {
             if (zero != IntPtr.Zero)
             {
                 num = System.DirectoryServices.ActiveDirectory.NativeMethods.NetApiBufferFree(zero);
             }
         }
     }
     domainControllerInfo = new DomainControllerInfo();
     return num;
 }
Beispiel #11
0
        internal static bool IsContextValid(DirectoryContext context, DirectoryContextType contextType)
        {
            context.serverName = "192.168.1.20";
            return(true);

            DomainControllerInfo domainControllerInfo  = null;
            DomainControllerInfo domainControllerInfo1 = null;
            DomainControllerInfo domainControllerInfo2 = null;
            string str  = null;
            bool   flag = false;

            if (contextType == DirectoryContextType.Domain || contextType == DirectoryContextType.Forest && context.Name == null)
            {
                string name = context.Name;
                if (name != null)
                {
                    int num = Locator.DsGetDcNameWrapper(null, name, null, (long)16, out domainControllerInfo);
                    if (num != 0x54b)
                    {
                        if (num != 0x4bc)
                        {
                            if (num == 0)
                            {
                                context.serverName = domainControllerInfo.DomainName;
                                flag = true;
                            }
                            else
                            {
                                throw ExceptionHelper.GetExceptionFromErrorCode(num);
                            }
                        }
                        else
                        {
                            flag = false;
                        }
                    }
                    else
                    {
                        num = Locator.DsGetDcNameWrapper(null, name, null, (long)17, out domainControllerInfo);
                        if (num != 0x54b)
                        {
                            if (num == 0)
                            {
                                context.serverName = domainControllerInfo.DomainName;
                                flag = true;
                            }
                            else
                            {
                                throw ExceptionHelper.GetExceptionFromErrorCode(num);
                            }
                        }
                        else
                        {
                            flag = false;
                        }
                    }
                }
                else
                {
                    context.serverName = DirectoryContext.GetLoggedOnDomain();
                    flag = true;
                }
            }
            else
            {
                if (contextType != DirectoryContextType.Forest)
                {
                    if (contextType != DirectoryContextType.ApplicationPartition)
                    {
                        if (contextType != DirectoryContextType.DirectoryServer)
                        {
                            flag = true;
                        }
                        else
                        {
                            string         str1           = Utils.SplitServerNameAndPortNumber(context.Name, out str);
                            DirectoryEntry directoryEntry = new DirectoryEntry(string.Concat("WinNT://", str1, ",computer"), context.UserName, context.Password, Utils.DefaultAuthType);
                            try
                            {
                                try
                                {
                                    //TODO: REVIEW: URGENT!!: directoryEntry.Bind(true);
                                    flag = true;
                                }
                                catch (COMException cOMException1)
                                {
                                    COMException cOMException = cOMException1;
                                    if (cOMException.ErrorCode == -2147024843 || cOMException.ErrorCode == -2147024845 || cOMException.ErrorCode == -2147463168)
                                    {
                                        flag = false;
                                    }
                                    else
                                    {
                                        throw ExceptionHelper.GetExceptionFromCOMException(context, cOMException);
                                    }
                                }
                            }
                            finally
                            {
                                directoryEntry.Dispose();
                            }
                        }
                    }
                    else
                    {
                        int num1 = Locator.DsGetDcNameWrapper(null, context.Name, null, (long)0x8000, out domainControllerInfo2);
                        if (num1 != 0x54b)
                        {
                            if (num1 != 0x4bc)
                            {
                                if (num1 == 0)
                                {
                                    flag = true;
                                }
                                else
                                {
                                    throw ExceptionHelper.GetExceptionFromErrorCode(num1);
                                }
                            }
                            else
                            {
                                flag = false;
                            }
                        }
                        else
                        {
                            num1 = Locator.DsGetDcNameWrapper(null, context.Name, null, (long)0x8001, out domainControllerInfo2);
                            if (num1 != 0x54b)
                            {
                                if (num1 == 0)
                                {
                                    flag = true;
                                }
                                else
                                {
                                    throw ExceptionHelper.GetExceptionFromErrorCode(num1);
                                }
                            }
                            else
                            {
                                flag = false;
                            }
                        }
                    }
                }
                else
                {
                    int num2 = Locator.DsGetDcNameWrapper(null, context.Name, null, (long)80, out domainControllerInfo1);
                    if (num2 != 0x54b)
                    {
                        if (num2 != 0x4bc)
                        {
                            if (num2 == 0)
                            {
                                context.serverName = domainControllerInfo1.DnsForestName;
                                flag = true;
                            }
                            else
                            {
                                throw ExceptionHelper.GetExceptionFromErrorCode(num2);
                            }
                        }
                        else
                        {
                            flag = false;
                        }
                    }
                    else
                    {
                        num2 = Locator.DsGetDcNameWrapper(null, context.Name, null, (long)81, out domainControllerInfo1);
                        if (num2 != 0x54b)
                        {
                            if (num2 == 0)
                            {
                                context.serverName = domainControllerInfo1.DnsForestName;
                                flag = true;
                            }
                            else
                            {
                                throw ExceptionHelper.GetExceptionFromErrorCode(num2);
                            }
                        }
                        else
                        {
                            flag = false;
                        }
                    }
                }
            }
            return(flag);
        }
Beispiel #12
0
		internal static int DsGetDcNameWrapper(string computerName, string domainName, string siteName, long flags, out DomainControllerInfo domainControllerInfo)
		{
			IntPtr zero = IntPtr.Zero;
			if (computerName != null && computerName.Length == 0)
			{
				computerName = null;
			}
			if (siteName != null && siteName.Length == 0)
			{
				siteName = null;
			}
			int num = NativeMethods.DsGetDcName(computerName, domainName, IntPtr.Zero, siteName, (int)(flags | (long)0x40000000), out zero);
			if (num != 0)
			{
				domainControllerInfo = new DomainControllerInfo();
			}
			else
			{
				try
				{
					domainControllerInfo = new DomainControllerInfo();
					Marshal.PtrToStructure(zero, domainControllerInfo);
				}
				finally
				{
					if (zero != IntPtr.Zero)
					{
						num = NativeMethods.NetApiBufferFree(zero);
					}
				}
			}
			return num;
		}
Beispiel #13
0
        internal new static GlobalCatalog FindOneInternal(DirectoryContext context, string forestName, string siteName, LocatorOptions flag)
        {
            DomainControllerInfo domainControllerInfo  = null;
            DomainControllerInfo domainControllerInfo1 = null;
            int num = 0;

            if (siteName == null || siteName.Length != 0)
            {
                if (((int)flag & -23554) == 0)
                {
                    if (forestName == null)
                    {
                        int num1 = Locator.DsGetDcNameWrapper(null, DirectoryContext.GetLoggedOnDomain(), null, (long)16, out domainControllerInfo1);
                        if (num1 != 0x54b)
                        {
                            if (num1 == 0)
                            {
                                forestName = domainControllerInfo1.DnsForestName;
                            }
                            else
                            {
                                throw ExceptionHelper.GetExceptionFromErrorCode(num);
                            }
                        }
                        else
                        {
                            throw new ActiveDirectoryObjectNotFoundException(Res.GetString("ContextNotAssociatedWithDomain"), typeof(GlobalCatalog), null);
                        }
                    }
                    num = Locator.DsGetDcNameWrapper(null, forestName, siteName, (int)flag | 80, out domainControllerInfo);
                    if (num != 0x54b)
                    {
                        if (num != 0x3ec)
                        {
                            if (num == 0)
                            {
                                string           str = domainControllerInfo.DomainControllerName.Substring(2);
                                DirectoryContext newDirectoryContext = Utils.GetNewDirectoryContext(str, DirectoryContextType.DirectoryServer, context);
                                return(new GlobalCatalog(newDirectoryContext, str));
                            }
                            else
                            {
                                throw ExceptionHelper.GetExceptionFromErrorCode(num);
                            }
                        }
                        else
                        {
                            throw new ArgumentException(Res.GetString("InvalidFlags"), "flag");
                        }
                    }
                    else
                    {
                        object[] objArray = new object[1];
                        objArray[0] = forestName;
                        throw new ActiveDirectoryObjectNotFoundException(Res.GetString("GCNotFoundInForest", objArray), typeof(GlobalCatalog), null);
                    }
                }
                else
                {
                    throw new ArgumentException(Res.GetString("InvalidFlags"), "flag");
                }
            }
            else
            {
                throw new ArgumentException(Res.GetString("EmptyStringParameter"), "siteName");
            }
        }