Example #1
0
        public ADRootDSE GetRootDSE(ICollection <string> propertyList, bool propertyNamesOnly)
        {
            this.Init();
            ADRootDSE aDRootDSE = null;

            string[] strArrays = null;
            if (propertyList != null)
            {
                strArrays = new string[propertyList.Count];
                propertyList.CopyTo(strArrays, 0);
            }
            ADSearchRequest aDSearchRequest = new ADSearchRequest("", ADObjectSearcher.DefaultSearchFilter.GetLdapFilterString(), SearchScope.Base, strArrays);

            aDSearchRequest.TypesOnly = propertyNamesOnly;
            aDSearchRequest.TimeLimit = this._timeLimit;
            ADSearchResponse aDSearchResponse = this._syncOps.Search(this._sessionHandle, aDSearchRequest);

            if (aDSearchResponse.Entries.Count > 0)
            {
                aDRootDSE = new ADRootDSE();
                ADObject item = aDSearchResponse.Entries[0];
                foreach (string propertyName in item.PropertyNames)
                {
                    aDRootDSE.Add(propertyName, item[propertyName]);
                }
            }
            return(aDRootDSE);
        }
Example #2
0
        public ADRootDSE GetRootDSE()
        {
            this.Init();
            ADRootDSE rootDSE = this._adSession.RootDSE;

            if (rootDSE == null)
            {
                string[] strArrays = new string[2];
                strArrays[0] = "*";
                strArrays[1] = "msDS-PortLDAP";
                ADSearchRequest aDSearchRequest = new ADSearchRequest("", ADObjectSearcher.DefaultSearchFilter.GetLdapFilterString(), SearchScope.Base, strArrays);
                aDSearchRequest.TimeLimit = this._timeLimit;
                ADSearchResponse aDSearchResponse = this._syncOps.Search(this._sessionHandle, aDSearchRequest);
                if (aDSearchResponse.Entries.Count > 0)
                {
                    rootDSE = new ADRootDSE();
                    ADObject item = aDSearchResponse.Entries[0];
                    foreach (string propertyName in item.PropertyNames)
                    {
                        rootDSE.Add(propertyName, item[propertyName]);
                    }
                    this._adSession.RootDSE = rootDSE;
                }
                return(rootDSE);
            }
            else
            {
                return(rootDSE);
            }
        }
Example #3
0
 private void ProcessResponseControls(ADSearchResponse response)
 {
     if (response.Controls != null)
     {
         this.ProcessAsqResponse(response);
         return;
     }
     else
     {
         return;
     }
 }
        ADSearchResponse Microsoft.ActiveDirectory.Management.IADSyncOperations.Search(ADSessionHandle handle, ADSearchRequest request)
        {
            ADSearchResponse             aDSearchResponse = null;
            ADDirectoryServiceConnection internalHandle   = this.GetInternalHandle(handle);

            if (internalHandle != null)
            {
                aDSearchResponse = internalHandle.Search(request);
                this.CheckAndThrowReferralException(aDSearchResponse);
                ADStoreAccess.ThrowExceptionForResultCodeError(aDSearchResponse.ResultCode, aDSearchResponse.ErrorMessage, null);
            }
            return(aDSearchResponse);
        }
Example #5
0
 private void ProcessAsqResponse(ADSearchResponse response)
 {
     if (!string.IsNullOrEmpty(this._attributeScopedQuery))
     {
         DirectoryControl[] controls = response.Controls;
         int num = 0;
         while (num < (int)controls.Length)
         {
             ADAsqResponseControl aDAsqResponseControl = controls[num] as ADAsqResponseControl;
             if (aDAsqResponseControl == null)
             {
                 num++;
             }
             else
             {
                 if (aDAsqResponseControl.Result == ResultCode.Success)
                 {
                     break;
                 }
                 int            errorCode      = ADStoreAccess.MapResultCodeToErrorCode(aDAsqResponseControl.Result);
                 Win32Exception win32Exception = new Win32Exception(errorCode);
                 object[]       message        = new object[3];
                 message[0] = this._searchRoot;
                 message[1] = this._attributeScopedQuery;
                 message[2] = win32Exception.Message;
                 string str = string.Format(CultureInfo.CurrentCulture, StringResources.AsqResponseError, message);
                 throw ExceptionHelper.GetExceptionFromErrorCode(errorCode, str, null);
             }
         }
         return;
     }
     else
     {
         return;
     }
 }
Example #6
0
        public List <ADObject> PagedSearch(ref object pageCookie, out bool hasSizeLimitExceeded, int pageSize, int sizeLimit)
        {
            hasSizeLimitExceeded = false;
            Dictionary <string, ADObject> strs = null;
            HashSet <string> strs1             = null;
            HashSet <string> strs2             = null;
            int num = -2147483648;

            this.Init();
            if (this._searchRoot != null)
            {
                ADPageResultRequestControl aDPageResultRequestControl = new ADPageResultRequestControl(pageSize);
                if (pageCookie != null)
                {
                    aDPageResultRequestControl.Cookie = pageCookie;
                }
                ADSearchRequest aDSearchRequest = this.CreateSearchRequest(aDPageResultRequestControl);
                aDSearchRequest.SizeLimit = sizeLimit;
                ADSearchResponse aDSearchResponse = this._syncOps.Search(this._sessionHandle, aDSearchRequest);
                this.ProcessResponseControls(aDSearchResponse);
                if (aDSearchResponse.ResultCode == ResultCode.SizeLimitExceeded)
                {
                    hasSizeLimitExceeded = true;
                }
                List <ADObject> aDObjects = new List <ADObject>(aDSearchResponse.Entries.Count);
                if (this._autoRangeRetrieve)
                {
                    strs  = new Dictionary <string, ADObject>(StringComparer.OrdinalIgnoreCase);
                    strs1 = new HashSet <string>(StringComparer.OrdinalIgnoreCase);
                    strs2 = new HashSet <string>(StringComparer.OrdinalIgnoreCase);
                }
                foreach (ADObject entry in aDSearchResponse.Entries)
                {
                    ADObject aDObject = this.CreateRichADObject(entry);
                    aDObjects.Add(aDObject);
                    if (!this._autoRangeRetrieve)
                    {
                        continue;
                    }
                    if (!string.IsNullOrEmpty(aDObject.DistinguishedName))
                    {
                        strs.Add(aDObject.DistinguishedName, aDObject);
                        ADObjectSearcher.ExtractRangeRetrievalDataFromAttributes(aDObject, aDObject, strs1, strs2, ref num);
                    }
                }
                while (this._autoRangeRetrieve && strs2.Count > 0 && strs1.Count > 0 && num != -2147483648)
                {
                    using (ADObjectSearcher aDObjectSearcher = new ADObjectSearcher(this._adSession.SessionInfo))
                    {
                        IEnumerable <ADObject> aDObjects1 = ADObjectSearcher.FetchRemainingRangeRetrievalAttributeValues(aDObjectSearcher, this, strs1, strs2, num);
                        strs1.Clear();
                        strs2.Clear();
                        num = -2147483648;
                        foreach (ADObject aDObject1 in aDObjects1)
                        {
                            ADObjectSearcher.ExtractRangeRetrievalDataFromAttributes(aDObject1, strs[aDObject1.DistinguishedName], strs1, strs2, ref num);
                        }
                    }
                }
                pageCookie = null;
                DirectoryControl[] controls = aDSearchResponse.Controls;
                int num1 = 0;
                while (num1 < (int)controls.Length)
                {
                    if (controls[num1] as ADPageResultResponseControl == null)
                    {
                        num1++;
                    }
                    else
                    {
                        pageCookie = ((ADPageResultResponseControl)controls[num1]).Cookie;
                        break;
                    }
                }
                return(aDObjects);
            }
            else
            {
                DebugLogger.LogWarning("ADObjectSearcher", "PagedSearch: SearchRoot is null");
                throw new ArgumentNullException("SearchRoot");
            }
        }
Example #7
0
		private void ProcessResponseControls(ADSearchResponse response)
		{
			if (response.Controls != null)
			{
				this.ProcessAsqResponse(response);
				return;
			}
			else
			{
				return;
			}
		}
Example #8
0
		private void ProcessAsqResponse(ADSearchResponse response)
		{
			if (!string.IsNullOrEmpty(this._attributeScopedQuery))
			{
				DirectoryControl[] controls = response.Controls;
				int num = 0;
				while (num < (int)controls.Length)
				{
					ADAsqResponseControl aDAsqResponseControl = controls[num] as ADAsqResponseControl;
					if (aDAsqResponseControl == null)
					{
						num++;
					}
					else
					{
						if (aDAsqResponseControl.Result == ResultCode.Success)
						{
							break;
						}
						int errorCode = ADStoreAccess.MapResultCodeToErrorCode(aDAsqResponseControl.Result);
						Win32Exception win32Exception = new Win32Exception(errorCode);
						object[] message = new object[3];
						message[0] = this._searchRoot;
						message[1] = this._attributeScopedQuery;
						message[2] = win32Exception.Message;
						string str = string.Format(CultureInfo.CurrentCulture, StringResources.AsqResponseError, message);
						throw ExceptionHelper.GetExceptionFromErrorCode(errorCode, str, null);
					}
				}
				return;
			}
			else
			{
				return;
			}
		}