Пример #1
0
        internal static IADOPathNode ToSearchFlagInInt(int bit, bool isInverted, string extendedAttributeName, string[] directoryAttributes, IADOPathNode filterClause, CmdletSessionInfo cmdletSessionInfo)
        {
            BinaryADOPathNode binaryADOPathNode = filterClause as BinaryADOPathNode;

            if (binaryADOPathNode != null)
            {
                IDataNode rightNode = binaryADOPathNode.RightNode as IDataNode;
                if (rightNode != null)
                {
                    if (rightNode.DataObject is bool)
                    {
                        ADOperator @operator = binaryADOPathNode.Operator;
                        if (@operator == ADOperator.Eq || @operator == ADOperator.Ne)
                        {
                            IADOPathNode aDOPathNode = new BinaryADOPathNode(ADOperator.Bor, new PropertyADOPathNode(directoryAttributes[0]), new ObjectADOPathNode((object)bit));
                            bool         dataObject  = !(bool)rightNode.DataObject;
                            if (@operator == ADOperator.Ne)
                            {
                                dataObject = !dataObject;
                            }
                            if (isInverted)
                            {
                                dataObject = !dataObject;
                            }
                            if (dataObject)
                            {
                                aDOPathNode = ADOPathUtil.CreateNotClause(aDOPathNode);
                            }
                            return(aDOPathNode);
                        }
                        else
                        {
                            object[]     str             = new object[2];
                            ADOperator[] aDOperatorArray = new ADOperator[2];
                            aDOperatorArray[1] = ADOperator.Ne;
                            str[0]             = SearchConverters.ConvertOperatorListToString(aDOperatorArray);
                            str[1]             = extendedAttributeName;
                            throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.SearchConverterSupportedOperatorListErrorMessage, str));
                        }
                    }
                    else
                    {
                        object[] type = new object[2];
                        type[0] = rightNode.DataObject.GetType();
                        type[1] = extendedAttributeName;
                        throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.SearchConverterRHSInvalidType, type));
                    }
                }
                else
                {
                    throw new ArgumentException(StringResources.SearchConverterRHSNotDataNode);
                }
            }
            else
            {
                throw new ArgumentException(StringResources.SearchConverterNotBinaryNode);
            }
        }
Пример #2
0
        public static IADOPathNode ToSearchGroupScope(string extendedAttributeName, string[] directoryAttributes, IADOPathNode filterClause, CmdletSessionInfo cmdletSessionInfo)
        {
            ADGroupScope      aDGroupScope      = ADGroupScope.DomainLocal;
            BinaryADOPathNode binaryADOPathNode = filterClause as BinaryADOPathNode;

            if (binaryADOPathNode == null)
            {
                throw new ArgumentException(StringResources.SearchConverterNotBinaryNode);
            }
            else
            {
                if (binaryADOPathNode.Operator == ADOperator.Eq || binaryADOPathNode.Operator == ADOperator.Ne)
                {
                    IDataNode rightNode = binaryADOPathNode.RightNode as IDataNode;
                    if (rightNode == null)
                    {
                        throw new ArgumentException(StringResources.SearchConverterRHSNotDataNode);
                    }
                    else
                    {
                        if (!Utils.TryParseEnum <ADGroupScope>(rightNode.DataObject.ToString(), out aDGroupScope))
                        {
                            object[] str = new object[2];
                            str[0] = rightNode.DataObject.ToString();
                            str[1] = extendedAttributeName;
                            throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.SearchConverterInvalidValue, str));
                        }
                        else
                        {
                            PropertyADOPathNode propertyADOPathNode = new PropertyADOPathNode(directoryAttributes[0]);
                            ObjectADOPathNode   objectADOPathNode   = new ObjectADOPathNode((object)GroupTypeUtils.GetDirectoryGroupTypeValue(aDGroupScope));
                            IADOPathNode        aDOPathNode         = new BinaryADOPathNode(ADOperator.Band, propertyADOPathNode, objectADOPathNode);
                            if (binaryADOPathNode.Operator != ADOperator.Eq)
                            {
                                return(ADOPathUtil.CreateNotClause(aDOPathNode));
                            }
                            else
                            {
                                return(aDOPathNode);
                            }
                        }
                    }
                }
                else
                {
                    object[]     objArray        = new object[2];
                    ADOperator[] aDOperatorArray = new ADOperator[2];
                    aDOperatorArray[1] = ADOperator.Ne;
                    objArray[0]        = SearchConverters.ConvertOperatorListToString(aDOperatorArray);
                    objArray[1]        = extendedAttributeName;
                    throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, StringResources.SearchConverterSupportedOperatorListErrorMessage, objArray));
                }
            }
        }
Пример #3
0
        internal static IADOPathNode BuildIPFilter(string extendedAttribute, string directoryAttribute, IADOPathNode filterClause, IPUtil.IPVersion ipVersion)
        {
            BinaryADOPathNode binaryADOPathNode = filterClause as BinaryADOPathNode;

            if (binaryADOPathNode != null)
            {
                IDataNode rightNode = binaryADOPathNode.RightNode as IDataNode;
                if (rightNode != null)
                {
                    if (rightNode.DataObject as string != null)
                    {
                        ADOperator @operator = binaryADOPathNode.Operator;
                        if (@operator == ADOperator.Eq || @operator == ADOperator.Ne)
                        {
                            return(IPUtil.BuildHostFilterFromIP(rightNode.DataObject as string, ipVersion, extendedAttribute, directoryAttribute, @operator));
                        }
                        else
                        {
                            object[]     str             = new object[2];
                            ADOperator[] aDOperatorArray = new ADOperator[2];
                            aDOperatorArray[1] = ADOperator.Ne;
                            str[0]             = SearchConverters.ConvertOperatorListToString(aDOperatorArray);
                            str[1]             = extendedAttribute;
                            throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.SearchConverterSupportedOperatorListErrorMessage, str));
                        }
                    }
                    else
                    {
                        object[] type = new object[2];
                        type[0] = rightNode.DataObject.GetType();
                        type[1] = extendedAttribute;
                        throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.SearchConverterRHSInvalidType, type));
                    }
                }
                else
                {
                    throw new ArgumentException(StringResources.SearchConverterRHSNotDataNode);
                }
            }
            else
            {
                throw new ArgumentException(StringResources.SearchConverterNotBinaryNode);
            }
        }
Пример #4
0
        internal static IADOPathNode ToSearchMultivalueCertificate(string extendedAttribute, string[] directoryAttributes, IADOPathNode filterClause, CmdletSessionInfo cmdletSessionInfo)
        {
            BinaryADOPathNode binaryADOPathNode = filterClause as BinaryADOPathNode;

            if (binaryADOPathNode == null)
            {
                throw new ArgumentException(StringResources.SearchConverterNotBinaryNode);
            }
            else
            {
                if (binaryADOPathNode.Operator == ADOperator.Eq || binaryADOPathNode.Operator == ADOperator.Ne)
                {
                    IDataNode rightNode = binaryADOPathNode.RightNode as IDataNode;
                    if (rightNode == null)
                    {
                        throw new ArgumentException(StringResources.SearchConverterRHSNotDataNode);
                    }
                    else
                    {
                        X509Certificate dataObject = rightNode.DataObject as X509Certificate;
                        if (dataObject != null)
                        {
                            IADOPathNode aDOPathNode = ADOPathUtil.CreateFilterClause(binaryADOPathNode.Operator, directoryAttributes[0], dataObject.GetRawCertData());
                            return(aDOPathNode);
                        }
                        else
                        {
                            throw new ArgumentException(StringResources.SearchConverterInvalidValue);
                        }
                    }
                }
                else
                {
                    object[]     str             = new object[2];
                    ADOperator[] aDOperatorArray = new ADOperator[2];
                    aDOperatorArray[1] = ADOperator.Ne;
                    str[0]             = SearchConverters.ConvertOperatorListToString(aDOperatorArray);
                    str[1]             = extendedAttribute;
                    throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, StringResources.SearchConverterSupportedOperatorListErrorMessage, str));
                }
            }
        }
Пример #5
0
        private static IADOPathNode BuildGPLinkFilter(string extendedAttribute, string directoryAttribute, IADOPathNode filterClause)
        {
            BinaryADOPathNode binaryADOPathNode = filterClause as BinaryADOPathNode;

            if (binaryADOPathNode != null)
            {
                IDataNode rightNode = binaryADOPathNode.RightNode as IDataNode;
                if (rightNode != null)
                {
                    string dataObject = rightNode.DataObject as string;
                    if (dataObject != null)
                    {
                        ADOperator @operator = binaryADOPathNode.Operator;
                        if (@operator == ADOperator.Eq || @operator == ADOperator.Ne || @operator == ADOperator.Like || @operator == ADOperator.NotLike)
                        {
                            if (@operator != ADOperator.Eq)
                            {
                                if (@operator == ADOperator.Ne)
                                {
                                    dataObject = ADOPathUtil.LdapSearchEncodeString(dataObject, true);
                                    @operator  = ADOperator.NotLike;
                                }
                            }
                            else
                            {
                                dataObject = ADOPathUtil.LdapSearchEncodeString(dataObject, true);
                                @operator  = ADOperator.Like;
                            }
                            dataObject = string.Concat(GPLinkUtil.GpLinkFilterPrefix, dataObject, GPLinkUtil.GpLinkFilterSuffix);
                            return(ADOPathUtil.CreateFilterClause(@operator, directoryAttribute, dataObject));
                        }
                        else
                        {
                            object[]     str             = new object[2];
                            ADOperator[] aDOperatorArray = new ADOperator[4];
                            aDOperatorArray[1] = ADOperator.Ne;
                            aDOperatorArray[2] = ADOperator.Like;
                            aDOperatorArray[3] = ADOperator.NotLike;
                            str[0]             = SearchConverters.ConvertOperatorListToString(aDOperatorArray);
                            str[1]             = extendedAttribute;
                            throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.SearchConverterSupportedOperatorListErrorMessage, str));
                        }
                    }
                    else
                    {
                        object[] type = new object[2];
                        type[0] = rightNode.DataObject.GetType();
                        type[1] = extendedAttribute;
                        throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.SearchConverterRHSInvalidType, type));
                    }
                }
                else
                {
                    throw new ArgumentException(StringResources.SearchConverterRHSNotDataNode);
                }
            }
            else
            {
                throw new ArgumentException(StringResources.SearchConverterNotBinaryNode);
            }
        }
Пример #6
0
        internal static IADOPathNode ToSearchGuid(string extendedAttributeName, string[] directoryAttributes, IADOPathNode filterClause, CmdletSessionInfo cmdletSessionInfo)
        {
            BinaryADOPathNode binaryADOPathNode = filterClause as BinaryADOPathNode;

            if (binaryADOPathNode != null)
            {
                IDataNode rightNode = binaryADOPathNode.RightNode as IDataNode;
                if (rightNode != null)
                {
                    ADOperator @operator = binaryADOPathNode.Operator;
                    if (@operator == ADOperator.Eq || @operator == ADOperator.Ne)
                    {
                        byte[] byteArray = null;
                        if (!(rightNode.DataObject is Guid))
                        {
                            if (rightNode.DataObject as byte[] == null)
                            {
                                if (rightNode.DataObject as string == null)
                                {
                                    object[] type = new object[2];
                                    type[0] = rightNode.DataObject.GetType();
                                    type[1] = extendedAttributeName;
                                    throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.SearchConverterUnrecognizedObjectType, type));
                                }
                                else
                                {
                                    Guid?nullable = null;
                                    if (!Utils.TryParseGuid((string)rightNode.DataObject, out nullable))
                                    {
                                        return(ADOPathUtil.CreateFilterClause(@operator, directoryAttributes[0], rightNode.DataObject));
                                    }
                                    else
                                    {
                                        Guid value = nullable.Value;
                                        byteArray = value.ToByteArray();
                                    }
                                }
                            }
                            else
                            {
                                byteArray = (byte[])rightNode.DataObject;
                            }
                        }
                        else
                        {
                            Guid dataObject = (Guid)rightNode.DataObject;
                            byteArray = dataObject.ToByteArray();
                        }
                        return(ADOPathUtil.CreateFilterClause(@operator, directoryAttributes[0], byteArray));
                    }
                    else
                    {
                        object[]     str             = new object[2];
                        ADOperator[] aDOperatorArray = new ADOperator[2];
                        aDOperatorArray[1] = ADOperator.Ne;
                        str[0]             = SearchConverters.ConvertOperatorListToString(aDOperatorArray);
                        str[1]             = extendedAttributeName;
                        throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.SearchConverterSupportedOperatorListErrorMessage, str));
                    }
                }
                else
                {
                    throw new ArgumentException(StringResources.SearchConverterRHSNotDataNode);
                }
            }
            else
            {
                throw new ArgumentException(StringResources.SearchConverterNotBinaryNode);
            }
        }
Пример #7
0
        internal static IADOPathNode ToSearchFromADEntityToAttributeValue <F, O>(string searchBase, string attributeName, string extendedAttributeName, string[] directoryAttributes, IADOPathNode filterClause, CmdletSessionInfo cmdletSessionInfo)
            where F : ADFactory <O>, new()
            where O : ADEntity, new()
        {
            ADEntity          extendedObjectFromIdentity;
            IADOPathNode      binaryADOPathNode;
            BinaryADOPathNode binaryADOPathNode1 = filterClause as BinaryADOPathNode;

            if (binaryADOPathNode1 == null)
            {
                throw new ArgumentException(StringResources.SearchConverterNotBinaryNode);
            }
            else
            {
                if (binaryADOPathNode1.Operator == ADOperator.Eq || binaryADOPathNode1.Operator == ADOperator.Ne)
                {
                    IDataNode rightNode = binaryADOPathNode1.RightNode as IDataNode;
                    if (rightNode == null)
                    {
                        throw new ArgumentException(StringResources.SearchConverterRHSNotDataNode);
                    }
                    else
                    {
                        PropertyADOPathNode propertyADOPathNode = new PropertyADOPathNode(directoryAttributes[0]);
                        ObjectADOPathNode   objectADOPathNode   = new ObjectADOPathNode(null);
                        O dataObject = (O)(rightNode.DataObject as O);
                        if (dataObject == null)
                        {
                            string str = rightNode.DataObject as string;
                            if (str != null)
                            {
                                dataObject          = Activator.CreateInstance <O>();
                                dataObject.Identity = str;
                            }
                        }
                        if (dataObject == null)
                        {
                            object[] objArray = new object[2];
                            objArray[0] = rightNode.DataObject.ToString();
                            objArray[1] = extendedAttributeName;
                            throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.SearchConverterInvalidValue, objArray));
                        }
                        else
                        {
                            F f = Activator.CreateInstance <F>();
                            f.SetCmdletSessionInfo(cmdletSessionInfo);
                            try
                            {
                                if (attributeName != null)
                                {
                                    HashSet <string> strs = new HashSet <string>(StringComparer.OrdinalIgnoreCase);
                                    strs.Add(attributeName);
                                    extendedObjectFromIdentity   = f.GetExtendedObjectFromIdentity(dataObject, searchBase, strs, false);
                                    objectADOPathNode.DataObject = (string)extendedObjectFromIdentity[attributeName].Value;
                                }
                                else
                                {
                                    extendedObjectFromIdentity   = f.GetDirectoryObjectFromIdentity(dataObject, searchBase);
                                    objectADOPathNode.DataObject = (string)extendedObjectFromIdentity["DistinguishedName"].Value;
                                }
                                binaryADOPathNode = new BinaryADOPathNode(binaryADOPathNode1.Operator, propertyADOPathNode, objectADOPathNode);
                            }
                            catch (ADIdentityNotFoundException aDIdentityNotFoundException1)
                            {
                                ADIdentityNotFoundException aDIdentityNotFoundException = aDIdentityNotFoundException1;
                                object[] message = new object[2];
                                message[0] = extendedAttributeName;
                                message[1] = aDIdentityNotFoundException.Message;
                                throw new ADIdentityResolutionException(string.Format(CultureInfo.CurrentCulture, StringResources.IdentityInExtendedAttributeCannotBeResolved, message), aDIdentityNotFoundException);
                            }
                            catch (ADIdentityResolutionException aDIdentityResolutionException1)
                            {
                                ADIdentityResolutionException aDIdentityResolutionException = aDIdentityResolutionException1;
                                object[] message1 = new object[2];
                                message1[0] = extendedAttributeName;
                                message1[1] = aDIdentityResolutionException.Message;
                                throw new ADIdentityResolutionException(string.Format(CultureInfo.CurrentCulture, StringResources.IdentityInExtendedAttributeCannotBeResolved, message1), aDIdentityResolutionException);
                            }
                            return(binaryADOPathNode);
                        }
                    }
                }
                else
                {
                    object[]     str1            = new object[2];
                    ADOperator[] aDOperatorArray = new ADOperator[2];
                    aDOperatorArray[1] = ADOperator.Ne;
                    str1[0]            = SearchConverters.ConvertOperatorListToString(aDOperatorArray);
                    str1[1]            = extendedAttributeName;
                    throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, StringResources.SearchConverterSupportedOperatorListErrorMessage, str1));
                }
            }
        }
Пример #8
0
        internal static IADOPathNode ToSearchFlagEnumerationInInt <T>(string extendedAttributeName, string[] directoryAttributes, IADOPathNode filterClause, CmdletSessionInfo cmdletSessionInfo)
        {
            T                 t = default(T);
            object            num;
            IADOPathNode      item;
            BinaryADOPathNode binaryADOPathNode = filterClause as BinaryADOPathNode;

            if (binaryADOPathNode != null)
            {
                IDataNode rightNode = binaryADOPathNode.RightNode as IDataNode;
                if (rightNode != null)
                {
                    ADOperator @operator = binaryADOPathNode.Operator;
                    if (@operator == ADOperator.Eq || @operator == ADOperator.Ne)
                    {
                        char[] chrArray = new char[1];
                        chrArray[0] = ',';
                        string[]            strArrays    = rightNode.DataObject.ToString().Split(chrArray);
                        List <IADOPathNode> aDOPathNodes = new List <IADOPathNode>();
                        string[]            strArrays1   = strArrays;
                        int num1 = 0;
                        while (num1 < (int)strArrays1.Length)
                        {
                            string str = strArrays1[num1];
                            if (!Utils.TryParseEnum <T>(str, out t))
                            {
                                object[] objArray = new object[1];
                                objArray[0] = extendedAttributeName;
                                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.SearchConverterRHSNotMatchEnumValue, objArray));
                            }
                            else
                            {
                                if (Enum.GetUnderlyingType(typeof(T)) != typeof(int))
                                {
                                    num = Convert.ToInt64(t, CultureInfo.InvariantCulture);
                                }
                                else
                                {
                                    num = Convert.ToInt32(t, CultureInfo.InvariantCulture);
                                }
                                IADOPathNode aDOPathNode = new BinaryADOPathNode(ADOperator.Bor, new PropertyADOPathNode(directoryAttributes[0]), new ObjectADOPathNode(num));
                                aDOPathNodes.Add(aDOPathNode);
                                num1++;
                            }
                        }
                        if (aDOPathNodes.Count <= 1)
                        {
                            if (aDOPathNodes.Count != 1)
                            {
                                object[] objArray1 = new object[1];
                                objArray1[0] = extendedAttributeName;
                                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.SearchConverterRHSNotMatchEnumValue, objArray1));
                            }
                            else
                            {
                                item = aDOPathNodes[0];
                            }
                        }
                        else
                        {
                            item = ADOPathUtil.CreateAndClause(aDOPathNodes.ToArray());
                        }
                        if (@operator == ADOperator.Ne)
                        {
                            item = ADOPathUtil.CreateNotClause(item);
                        }
                        return(item);
                    }
                    else
                    {
                        object[]     str1            = new object[2];
                        ADOperator[] aDOperatorArray = new ADOperator[2];
                        aDOperatorArray[1] = ADOperator.Ne;
                        str1[0]            = SearchConverters.ConvertOperatorListToString(aDOperatorArray);
                        str1[1]            = extendedAttributeName;
                        throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.SearchConverterSupportedOperatorListErrorMessage, str1));
                    }
                }
                else
                {
                    throw new ArgumentException(StringResources.SearchConverterRHSNotDataNode);
                }
            }
            else
            {
                throw new ArgumentException(StringResources.SearchConverterNotBinaryNode);
            }
        }