Пример #1
0
        private ADSessionCache.CacheEntry FindEntryInServerList(string key, ADSessionInfo info, out int index)
        {
            List <ADSessionCache.CacheEntry> cacheEntries = null;

            ADSessionCache.CacheEntry item = null;
            int num;

            index = -1;
            if (ADSessionCache._sessionMap.TryGetValue(key, out cacheEntries))
            {
                if (DebugLogger.Level >= DebugLogLevel.Info)
                {
                    object[] count = new object[4];
                    count[0] = "FindEntryInServerList: Found ";
                    count[1] = cacheEntries.Count;
                    count[2] = " session(s) in cache with key: ";
                    count[3] = key;
                    DebugLogger.LogInfo(ADSessionCache._debugCategory, string.Concat(count));
                }
                bool            flag    = this.AreCredentialsExplicit(info);
                WindowsIdentity current = null;
                if (!flag)
                {
                    current = WindowsIdentity.GetCurrent(true);
                }
                int  i     = 0;
                bool flag1 = false;
                for (i = 0; i < cacheEntries.Count; i++)
                {
                    item = cacheEntries[i];
                    if (item.Session.MatchConnectionOptions(info))
                    {
                        bool flag2 = ADPasswordUtils.AreCredentialsExplicit(item.Credential);
                        if (!flag || !flag2)
                        {
                            if (!flag && !flag2)
                            {
                                if (current != null || !(null == item.ImpersonatedOwnerSid))
                                {
                                    if (current.Owner == item.ImpersonatedOwnerSid)
                                    {
                                        flag1 = true;
                                        break;
                                    }
                                }
                                else
                                {
                                    flag1 = true;
                                    break;
                                }
                            }
                        }
                        else
                        {
                            if (ADPasswordUtils.MatchCredentials(item.Credential, info.Credential))
                            {
                                flag1 = true;
                                break;
                            }
                        }
                    }
                    else
                    {
                        if (DebugLogger.Level >= DebugLogLevel.Info)
                        {
                            DebugLogger.LogInfo(ADSessionCache._debugCategory, string.Concat("FindEntryInServerList: Connection options did NOT match with session ", item.Session.SessionInfo.Server));
                        }
                    }
                }
                if (!flag1)
                {
                    if (DebugLogger.Level >= DebugLogLevel.Info)
                    {
                        DebugLogger.LogInfo(ADSessionCache._debugCategory, "FindEntryInServerList. Could NOT find a matching cached session entry");
                    }
                }
                else
                {
                    if (DebugLogger.Level >= DebugLogLevel.Info)
                    {
                        DebugLogger.LogInfo(ADSessionCache._debugCategory, string.Concat("FindEntryInServerList. Found a cached session entry: ", item.Session.SessionInfo.Server));
                    }
                }
                int numPointer = index;
                if (flag1)
                {
                    num = i;
                }
                else
                {
                    num = -1;
                }
                numPointer = num;
                if (flag1)
                {
                    return(item);
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                if (DebugLogger.Level >= DebugLogLevel.Info)
                {
                    DebugLogger.LogInfo(ADSessionCache._debugCategory, string.Concat("FindEntryInServerList: Could NOT find a session in cache with key: ", key));
                }
                return(null);
            }
        }
Пример #2
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");
            }
        }
Пример #3
0
 private static string DetailedLogMessage(string category, DebugLogLevel type, string format, object[] args)
 {
     return(DebugLogger.DetailedLogMessage(category, type, string.Format(CultureInfo.InvariantCulture, format, args)));
 }
Пример #4
0
 protected virtual void OnSet(object key, object oldValue, object newValue)
 {
     DebugLogger.LogWarning("ADPropertyCollection", "OnSet: not supported");
     throw new NotSupportedException();
 }
Пример #5
0
        public object[] ConvertToRaw(string propertyName, IList valueList)
        {
            string[] item;
            byte[][] securityDescriptorBinaryForm;
            object[] objArray;
            string   str;

            if (valueList == null || valueList.Count == 0)
            {
                return(null);
            }
            else
            {
                Type     type     = valueList[0].GetType();
                TypeCode typeCode = Type.GetTypeCode(type);
                switch (typeCode)
                {
                case TypeCode.Object:
                {
                    if (type != typeof(byte[]))
                    {
                        if (type != typeof(Guid))
                        {
                            if (type != typeof(SecurityIdentifier))
                            {
                                if (type != typeof(ActiveDirectorySecurity))
                                {
                                    if (!typeof(X509Certificate).IsAssignableFrom(type))
                                    {
                                        DebugLogger.LogWarning("ADTypeConverter", string.Concat("ConvertToRaw: invalid value type ", type.ToString(), " for ", propertyName));
                                        object[] objArray1 = new object[1];
                                        objArray1[0] = type;
                                        throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.InvalidType, objArray1), propertyName);
                                    }
                                    else
                                    {
                                        return(this.FormatCertificateValue(propertyName, valueList));
                                    }
                                }
                                else
                                {
                                    securityDescriptorBinaryForm = new byte[valueList.Count][];
                                    for (int i = 0; i < valueList.Count; i++)
                                    {
                                        securityDescriptorBinaryForm[i] = ((ActiveDirectorySecurity)valueList[i]).GetSecurityDescriptorBinaryForm();
                                    }
                                    return(securityDescriptorBinaryForm);
                                }
                            }
                            else
                            {
                                securityDescriptorBinaryForm = new byte[valueList.Count][];
                                for (int j = 0; j < valueList.Count; j++)
                                {
                                    SecurityIdentifier securityIdentifier = (SecurityIdentifier)valueList[j];
                                    byte[]             numArray           = new byte[securityIdentifier.BinaryLength];
                                    securityIdentifier.GetBinaryForm(numArray, 0);
                                    securityDescriptorBinaryForm[j] = numArray;
                                }
                                return(securityDescriptorBinaryForm);
                            }
                        }
                        else
                        {
                            return(this.FormatGuidValue(propertyName, valueList));
                        }
                    }
                    else
                    {
                        securityDescriptorBinaryForm = new byte[valueList.Count][];
                        for (int k = 0; k < valueList.Count; k++)
                        {
                            securityDescriptorBinaryForm[k] = (byte[])valueList[k];
                        }
                        return(securityDescriptorBinaryForm);
                    }
                }

                case TypeCode.DBNull:
                case TypeCode.Object | TypeCode.DateTime:
                {
                    DebugLogger.LogWarning("ADTypeConverter", string.Concat("ConvertToRaw: invalid value type ", type.ToString(), " for ", propertyName));
                    objArray    = new object[1];
                    objArray[0] = type;
                    throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.InvalidType, objArray), propertyName);
                }

                case TypeCode.Boolean:
                {
                    item = new string[valueList.Count];
                    for (int l = 0; l < valueList.Count; l++)
                    {
                        if (!(bool)valueList[l])
                        {
                            item[l] = "FALSE";
                        }
                        else
                        {
                            item[l] = "TRUE";
                        }
                    }
                    return(item);
                }

                case TypeCode.Char:
                case TypeCode.SByte:
                case TypeCode.Byte:
                case TypeCode.Int16:
                case TypeCode.UInt16:
                case TypeCode.Int32:
                case TypeCode.UInt32:
                case TypeCode.Int64:
                case TypeCode.UInt64:
                case TypeCode.Single:
                case TypeCode.Double:
                case TypeCode.Decimal:
                {
                    item = new string[valueList.Count];
                    for (int m = 0; m < valueList.Count; m++)
                    {
                        IFormattable formattable = valueList[m] as IFormattable;
                        string[]     strArrays   = item;
                        int          num         = m;
                        if (formattable != null)
                        {
                            str = formattable.ToString(string.Empty, NumberFormatInfo.InvariantInfo);
                        }
                        else
                        {
                            str = valueList[m].ToString();
                        }
                        strArrays[num] = str;
                    }
                    return(item);
                }

                case TypeCode.DateTime:
                {
                    return(this.FormatDateTimeValue(propertyName, valueList));
                }

                case TypeCode.String:
                {
                    item = new string[valueList.Count];
                    for (int n = 0; n < valueList.Count; n++)
                    {
                        item[n] = (string)valueList[n];
                    }
                    return(item);
                }

                default:
                {
                    DebugLogger.LogWarning("ADTypeConverter", string.Concat("ConvertToRaw: invalid value type ", type.ToString(), " for ", propertyName));
                    objArray    = new object[1];
                    objArray[0] = type;
                    throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.InvalidType, objArray), propertyName);
                }
                }
            }
        }
Пример #6
0
        private string[] FormatDateTimeValue(string propertyName, IList valueList)
        {
            DateTime item;

            object[]          objArray;
            string[]          str               = null;
            ADAttributeSyntax propertyType      = this.GetPropertyType(propertyName, ADAttributeSyntax.GeneralizedTime);
            ADAttributeSyntax aDAttributeSyntax = propertyType;

            if (aDAttributeSyntax == ADAttributeSyntax.Int64)
            {
                str = new string[valueList.Count];
                for (int i = 0; i < valueList.Count; i++)
                {
                    item = (DateTime)valueList[i];
                    long fileTimeUtc = item.ToFileTimeUtc();
                    str[i] = fileTimeUtc.ToString();
                }
            }
            else if (aDAttributeSyntax == ADAttributeSyntax.Bool || aDAttributeSyntax == ADAttributeSyntax.Oid)
            {
                DebugLogger.LogWarning("ADTypeConverter", string.Concat("FormatDateTimeValue: DateTime value for ", propertyName, " of syntax ", (object)propertyType.ToString()));
                objArray    = new object[1];
                objArray[0] = typeof(DateTime);
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.InvalidType, objArray), propertyName);
            }
            else if (aDAttributeSyntax == ADAttributeSyntax.GeneralizedTime)
            {
                str = new string[valueList.Count];
                int num = 0;
                while (num < valueList.Count)
                {
                    item = (DateTime)valueList[num];
                    if (item.Year >= 0x3e8)
                    {
                        item     = item.ToUniversalTime();
                        str[num] = item.ToString("yyyyMMddHHmmss.0Z");
                        num++;
                    }
                    else
                    {
                        int year = item.Year;
                        DebugLogger.LogWarning("ADTypeConverter", string.Concat("FormatDateTimeValue: Invalid year ", year.ToString(), " for ", propertyName));
                        throw new ArgumentOutOfRangeException(propertyName, (object)item, StringResources.InvalidYear);
                    }
                }
            }
            else if (aDAttributeSyntax == ADAttributeSyntax.UtcTime)
            {
                str = new string[valueList.Count];
                for (int j = 0; j < valueList.Count; j++)
                {
                    item   = (DateTime)valueList[j];
                    item   = item.ToUniversalTime();
                    str[j] = item.ToString("yyMMddHHmmssZ");
                }
            }
            else
            {
                DebugLogger.LogWarning("ADTypeConverter", string.Concat("FormatDateTimeValue: DateTime value for ", propertyName, " of syntax ", (object)propertyType.ToString()));
                objArray    = new object[1];
                objArray[0] = typeof(DateTime);
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.InvalidType, objArray), propertyName);
            }
            return(str);

            DebugLogger.LogWarning("ADTypeConverter", string.Concat("FormatDateTimeValue: DateTime value for ", propertyName, " of syntax ", propertyType.ToString()));
            objArray    = new object[1];
            objArray[0] = typeof(DateTime);
            throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.InvalidType, objArray), propertyName);
        }
Пример #7
0
        public object ConvertToRaw(string propertyName, object propertyValue)
        {
            object[] objArray;
            if (propertyValue != null)
            {
                Type     type     = propertyValue.GetType();
                TypeCode typeCode = Type.GetTypeCode(type);
                switch (typeCode)
                {
                case TypeCode.Object:
                {
                    if (type != typeof(byte[]))
                    {
                        if (type != typeof(Guid))
                        {
                            if (type != typeof(SecurityIdentifier))
                            {
                                if (type != typeof(ActiveDirectorySecurity))
                                {
                                    if (!typeof(X509Certificate).IsAssignableFrom(type))
                                    {
                                        DebugLogger.LogWarning("ADTypeConverter", string.Concat("ConvertToRaw: invalid value type ", type.ToString(), " for ", propertyName));
                                        object[] objArray1 = new object[1];
                                        objArray1[0] = type;
                                        throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.InvalidType, objArray1), propertyName);
                                    }
                                    else
                                    {
                                        return(this.FormatCertificateValue(propertyName, (X509Certificate)propertyValue));
                                    }
                                }
                                else
                                {
                                    return(((ActiveDirectorySecurity)propertyValue).GetSecurityDescriptorBinaryForm());
                                }
                            }
                            else
                            {
                                SecurityIdentifier securityIdentifier = (SecurityIdentifier)propertyValue;
                                byte[]             numArray           = new byte[securityIdentifier.BinaryLength];
                                securityIdentifier.GetBinaryForm(numArray, 0);
                                return(numArray);
                            }
                        }
                        else
                        {
                            return(this.FormatGuidValue(propertyName, (Guid)propertyValue));
                        }
                    }
                    else
                    {
                        return(propertyValue);
                    }
                }

                case TypeCode.DBNull:
                case TypeCode.Single:
                case TypeCode.Double:
                case TypeCode.Decimal:
                case TypeCode.Object | TypeCode.DateTime:
                {
                    DebugLogger.LogWarning("ADTypeConverter", string.Concat("ConvertToRaw: invalid value type ", type.ToString(), " for ", propertyName));
                    objArray    = new object[1];
                    objArray[0] = type;
                    throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.InvalidType, objArray), propertyName);
                }

                case TypeCode.Boolean:
                {
                    if (!(bool)propertyValue)
                    {
                        return("FALSE");
                    }
                    else
                    {
                        return("TRUE");
                    }
                }

                case TypeCode.Char:
                case TypeCode.SByte:
                case TypeCode.Byte:
                case TypeCode.Int16:
                case TypeCode.UInt16:
                case TypeCode.Int32:
                case TypeCode.UInt32:
                case TypeCode.Int64:
                case TypeCode.UInt64:
                {
                    IFormattable formattable = propertyValue as IFormattable;
                    if (formattable != null)
                    {
                        return(formattable.ToString(string.Empty, NumberFormatInfo.InvariantInfo));
                    }
                    else
                    {
                        return(propertyValue.ToString());
                    }
                }

                case TypeCode.DateTime:
                {
                    return(this.FormatDateTimeValue(propertyName, (DateTime)propertyValue));
                }

                case TypeCode.String:
                {
                    return(propertyValue);
                }

                default:
                {
                    DebugLogger.LogWarning("ADTypeConverter", string.Concat("ConvertToRaw: invalid value type ", type.ToString(), " for ", propertyName));
                    objArray    = new object[1];
                    objArray[0] = type;
                    throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.InvalidType, objArray), propertyName);
                }
                }
            }
            else
            {
                return(null);
            }
        }
Пример #8
0
 private int AddRef()
 {
     Interlocked.Increment(ref this._referenceCount);
     DebugLogger.LogInfo(ADSession._debugCategory, string.Concat("AddRef: new count = ", this._referenceCount));
     return(this._referenceCount);
 }
Пример #9
0
 private int Release()
 {
     Interlocked.Decrement(ref this._referenceCount);
     DebugLogger.LogInfo(ADSession._debugCategory, string.Concat("Release: Releasing object new count = ", this._referenceCount));
     return(this._referenceCount);
 }
Пример #10
0
        public void Update()
        {
            ADPropertyValueCollection value;

            this.Init();
            DebugLogger.WriteLine("ADActiveObject", string.Concat("Update called for ", this._adObject.DistinguishedName));
            DirectoryAttributeModificationCollection directoryAttributeModificationCollection = new DirectoryAttributeModificationCollection();

            if (!this._adObject.TrackChanges)
            {
                bool flag = false;
                foreach (KeyValuePair <string, ADPropertyValueCollection> keyValuePair in this._adObject)
                {
                    string key = keyValuePair.Key;
                    if (flag || string.Compare(key, "distinguishedName", StringComparison.OrdinalIgnoreCase) != 0)
                    {
                        value = keyValuePair.Value;
                        this.UpdateValueCollectionChanges(key, value, directoryAttributeModificationCollection);
                    }
                    else
                    {
                        flag = true;
                    }
                }
            }
            else
            {
                foreach (string addedProperty in this._adObject.AddedProperties)
                {
                    value = this._adObject[addedProperty];
                    this.UpdateValueCollectionChanges(addedProperty, value, directoryAttributeModificationCollection);
                }
                foreach (string removedProperty in this._adObject.RemovedProperties)
                {
                    DirectoryAttributeModification directoryAttributeModification = new DirectoryAttributeModification();
                    directoryAttributeModification.Name      = removedProperty;
                    directoryAttributeModification.Operation = DirectoryAttributeOperation.Delete;
                    directoryAttributeModificationCollection.Add(directoryAttributeModification);
                }
                foreach (string modifiedProperty in this._adObject.ModifiedProperties)
                {
                    value = this._adObject[modifiedProperty];
                    this.UpdateValueCollectionChanges(modifiedProperty, value, directoryAttributeModificationCollection);
                }
            }
            if (directoryAttributeModificationCollection.Count != 0)
            {
                DirectoryAttributeModification[] directoryAttributeModificationArray = new DirectoryAttributeModification[directoryAttributeModificationCollection.Count];
                directoryAttributeModificationCollection.CopyTo(directoryAttributeModificationArray, 0);
                ADModifyRequest         aDModifyRequest         = new ADModifyRequest(this._adObject.DistinguishedName, directoryAttributeModificationArray);
                PermissiveModifyControl permissiveModifyControl = new PermissiveModifyControl();
                aDModifyRequest.Controls.Add(permissiveModifyControl);
                if (this._sdFlags != SecurityMasks.None)
                {
                    aDModifyRequest.Controls.Add(new SecurityDescriptorFlagControl(this._sdFlags));
                }
                this._syncOps.Modify(this._sessionHandle, aDModifyRequest);
                DebugLogger.WriteLine("ADActiveObject", string.Concat("Update succeeded for ", this._adObject.DistinguishedName));
                return;
            }
            else
            {
                return;
            }
        }
        bool System.Collections.IEnumerator.MoveNext()
        {
            bool flag = false;
            ADObjectSearchResultEnumerator aDObjectSearchResultEnumerator = this;

            aDObjectSearchResultEnumerator._positionInCurrentPage = aDObjectSearchResultEnumerator._positionInCurrentPage + 1;
            ADObjectSearchResultEnumerator aDObjectSearchResultEnumerator1 = this;

            aDObjectSearchResultEnumerator1._positionInResultSet = aDObjectSearchResultEnumerator1._positionInResultSet + 1;
            if (this._currentPage == null || this._positionInCurrentPage >= this._currentPage.Count)
            {
                if (this._currentPage == null || this._pageCookie != null)
                {
                    DebugLogger.LogInfo("ADObjectSearchResultEnumerator", "Fetching next page.. and resetting current page position to 0");
                    int num = this._searchPageSize;
                    if (this._searchSizeLimit > 0)
                    {
                        int num1 = this._searchSizeLimit - this._positionInResultSet;
                        if (num1 < this._searchPageSize)
                        {
                            num = num1 + 1;
                        }
                    }
                    this._currentPage = this._searcher.PagedSearch(ref this._pageCookie, out this._hasSizeLimitExceedInLastSearch, num, 0);
                    if (this._currentPage == null || this._currentPage.Count == 0)
                    {
                        flag = false;
                    }
                    else
                    {
                        this._positionInCurrentPage = 0;
                        flag = true;
                    }
                }
                else
                {
                    DebugLogger.LogInfo("ADObjectSearchResultEnumerator", "pageCookie is null.. end of search results.");
                    flag = false;
                }
            }
            else
            {
                flag = true;
            }
            if (!flag)
            {
                if (this._searchSizeLimit <= 0 || this._positionInResultSet < this._searchSizeLimit || !this._hasSizeLimitExceedInLastSearch)
                {
                    return(false);
                }
                else
                {
                    throw new ADException(StringResources.SearchSizeLimitExceeded);
                }
            }
            else
            {
                if (this._searchSizeLimit <= 0 || this._positionInResultSet < this._searchSizeLimit)
                {
                    return(true);
                }
                else
                {
                    throw new ADException(StringResources.SearchSizeLimitExceeded);
                }
            }
        }