Exemplo n.º 1
0
        /// <summary>
        /// Verify whether the password is valid.
        /// </summary>
        /// <param name="userLoginName">The user login name.</param>
        /// <param name="password">The user password.</param>
        /// <returns>Whether the password is valid.</returns>
        public bool IsPasswordValid(string userLoginName, string password)
        {
            bool        isPasswordValid = false;
            var         userNameAdpter  = new UseNameAdapter(userLoginName);
            IADOperator adOperator      = new ADOperator(userLoginName, password, userNameAdpter.UserDomainName);

            try
            {
                var userObject = UserObject.FindOneBySAMAccountName(adOperator, userNameAdpter.UserName);
                if (userObject != null)
                {
                    isPasswordValid = true;
                }
            }
            catch (Exception exception)
            {
                if (exception.Message.Contains("Logon failure: unknown user name or bad password.") ||
                    exception.Message.Contains("The user name or password is incorrect."))
                {
                }
                else
                {
                    throw;
                }
            }
            return(isPasswordValid);
        }
Exemplo n.º 2
0
		internal CompositeADOPathNode(ADOperator op, IADOPathNode[] exprList)
		{
			if (exprList != null)
			{
				if ((int)exprList.Length >= 2)
				{
					this._operator = op;
					this._childNodes = new List<IADOPathNode>();
					IADOPathNode[] aDOPathNodeArray = exprList;
					for (int i = 0; i < (int)aDOPathNodeArray.Length; i++)
					{
						IADOPathNode aDOPathNode = aDOPathNodeArray[i];
						this.AddExpressionToChildNodes(aDOPathNode);
					}
					return;
				}
				else
				{
					throw new ArgumentException(StringResources.ADFilterExprListLessThanTwo);
				}
			}
			else
			{
				throw new ArgumentNullException("exprList");
			}
		}
Exemplo n.º 3
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);
			}
		}
Exemplo n.º 4
0
 internal CompositeADOPathNode(ADOperator op, IADOPathNode[] exprList)
 {
     if (exprList != null)
     {
         if ((int)exprList.Length >= 2)
         {
             this._operator   = op;
             this._childNodes = new List <IADOPathNode>();
             IADOPathNode[] aDOPathNodeArray = exprList;
             for (int i = 0; i < (int)aDOPathNodeArray.Length; i++)
             {
                 IADOPathNode aDOPathNode = aDOPathNodeArray[i];
                 this.AddExpressionToChildNodes(aDOPathNode);
             }
             return;
         }
         else
         {
             throw new ArgumentException(StringResources.ADFilterExprListLessThanTwo);
         }
     }
     else
     {
         throw new ArgumentNullException("exprList");
     }
 }
Exemplo n.º 5
0
        public AD()
        {
            string AD_IP = ConfigurationSettings.AppSettings["AD_IP"];
            string AD_User = ConfigurationSettings.AppSettings["AD_User"];
            string AD_Password = ConfigurationSettings.AppSettings["AD_Password"];

            ADOil = new ADOperator(AD_User, AD_Password, AD_IP);
        }
Exemplo n.º 6
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);
            }
        }
Exemplo n.º 7
0
        internal static IADOPathNode ToSearchComputerSamAccountName(string extendedAttribute, string[] directoryAttributes, IADOPathNode filterClause, CmdletSessionInfo cmdletSessionInfo)
        {
            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)
                    {
                        bool       flag      = dataObject.EndsWith("$", StringComparison.OrdinalIgnoreCase);
                        bool       flag1     = dataObject.EndsWith("*", StringComparison.OrdinalIgnoreCase);
                        ADOperator @operator = binaryADOPathNode.Operator;
                        if ((@operator == ADOperator.Eq || @operator == ADOperator.Ne) && !flag)
                        {
                            object[] objArray = new object[3];
                            objArray[0] = extendedAttribute;
                            objArray[1] = "$";
                            objArray[2] = filterClause;
                            cmdletSessionInfo.CmdletMessageWriter.WriteWarningBuffered(string.Format(CultureInfo.CurrentCulture, StringResources.WarningSamAccountNameClauseLacksDollarSign, objArray));
                        }
                        else
                        {
                            if ((@operator == ADOperator.Like || @operator == ADOperator.NotLike) && !flag && !flag1)
                            {
                                object[] objArray1 = new object[3];
                                objArray1[0] = extendedAttribute;
                                objArray1[1] = "$";
                                objArray1[2] = filterClause;
                                cmdletSessionInfo.CmdletMessageWriter.WriteWarningBuffered(string.Format(CultureInfo.CurrentCulture, StringResources.WarningSamAccountNameClauseLacksDollarSign, objArray1));
                            }
                        }
                        return(SearchConverters.ToSearchObject(extendedAttribute, directoryAttributes, filterClause, cmdletSessionInfo));
                    }
                    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);
            }
        }
Exemplo n.º 8
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));
                }
            }
        }
Exemplo n.º 9
0
 internal static bool IsOperatorUnary(ADOperator op)
 {
     if (op != ADOperator.Not)
     {
         return(false);
     }
     else
     {
         return(true);
     }
 }
Exemplo n.º 10
0
 internal UnaryADOPathNode(ADOperator op, IADOPathNode expr)
 {
     if (expr != null)
     {
         this._operator  = op;
         this._childExpr = expr;
         return;
     }
     else
     {
         throw new ArgumentNullException("expr");
     }
 }
Exemplo n.º 11
0
		internal UnaryADOPathNode(ADOperator op, IADOPathNode expr)
		{
			if (expr != null)
			{
				this._operator = op;
				this._childExpr = expr;
				return;
			}
			else
			{
				throw new ArgumentNullException("expr");
			}
		}
Exemplo n.º 12
0
        public static IADOPathNode CreateFilterClause(ADOperator op, string attributeName, object value)
        {
            IADOPathNode objectADOPathNode;
            IADOPathNode propertyADOPathNode = new PropertyADOPathNode(attributeName);
            string       str = value as string;

            if (str == null)
            {
                objectADOPathNode = new ObjectADOPathNode(value);
            }
            else
            {
                objectADOPathNode = new TextDataADOPathNode(str);
            }
            return(ADOPathUtil.CreateRelationalExpressionNode(op, propertyADOPathNode, objectADOPathNode, null));
        }
Exemplo n.º 13
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);
            }
        }
Exemplo n.º 14
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);
			}
		}
Exemplo n.º 15
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));
                }
            }
        }
Exemplo n.º 16
0
		internal static ADObjectSearcher BuildAggregatedSearchFilterIdentityResolver(IdentityResolverDelegate[] identityDelegates, ADOperator op, object identity, string searchRoot, CmdletSessionInfo cmdletSessionInfo, out bool useSearchFilter)
		{
			ADObjectSearcher item;
			List<IADOPathNode> aDOPathNodes = new List<IADOPathNode>((int)identityDelegates.Length);
			IdentityResolverDelegate[] identityResolverDelegateArray = identityDelegates;
			for (int i = 0; i < (int)identityResolverDelegateArray.Length; i++)
			{
				bool V_1;
				IdentityResolverDelegate identityResolverDelegate = identityResolverDelegateArray[i];
				item = identityResolverDelegate(identity, searchRoot, cmdletSessionInfo, out V_1);
				if (item != null)
				{
					aDOPathNodes.Add(item.Filter);
				}
			}
			item = SearchUtility.BuildSearcher(cmdletSessionInfo.ADSessionInfo, searchRoot, ADSearchScope.Subtree);
			if (aDOPathNodes.Count <= 1)
			{
				if (aDOPathNodes.Count != 1)
				{
					item = null;
				}
				else
				{
					item.Filter = aDOPathNodes[0];
				}
			}
			else
			{
				if (ADOperator.Or != op)
				{
					item.Filter = ADOPathUtil.CreateAndClause(aDOPathNodes.ToArray());
				}
				else
				{
					item.Filter = ADOPathUtil.CreateOrClause(aDOPathNodes.ToArray());
				}
			}
			useSearchFilter = true;
			return item;
		}
Exemplo n.º 17
0
        internal static IADOPathNode CreateRelationalExpressionNode(ADOperator op, IADOPathNode leftExpr, IADOPathNode rightExpr, ConvertSearchFilterDelegate searchFilterConverter)
        {
            if (op == ADOperator.Eq || op == ADOperator.Ne)
            {
                VariableADOPathNode variableADOPathNode = rightExpr as VariableADOPathNode;
                if (variableADOPathNode != null)
                {
                    variableADOPathNode.EncodeAsteriskChar = true;
                }
                TextDataADOPathNode textDataADOPathNode = rightExpr as TextDataADOPathNode;
                if (textDataADOPathNode != null)
                {
                    textDataADOPathNode.EncodeAsteriskChar = true;
                }
            }
            IADOPathNode binaryADOPathNode = new BinaryADOPathNode(op, leftExpr, rightExpr);

            if (searchFilterConverter != null)
            {
                binaryADOPathNode = searchFilterConverter(binaryADOPathNode);
            }
            return(binaryADOPathNode);
        }
Exemplo n.º 18
0
		private static IADOPathNode BuildHostFilterFromIP(string ipAddress, IPUtil.IPVersion ipVersion, string extendedAttribute, string directoryAttribute, ADOperator op)
		{
			IPHostEntry hostEntry;
			IPAddress pAddress;
			try
			{
				pAddress = IPAddress.Parse(ipAddress);
			}
			catch (Exception exception)
			{
				object[] objArray = new object[2];
				objArray[0] = ipAddress;
				objArray[1] = extendedAttribute;
				throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.SearchConverterInvalidValue, objArray));
			}
			if (pAddress.AddressFamily == (AddressFamily)ipVersion)
			{
				try
				{
					hostEntry = Dns.GetHostEntry(pAddress);
				}
				catch (SocketException socketException)
				{
					object[] objArray1 = new object[1];
					objArray1[0] = ipAddress;
					throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.CannotResolveIPAddressToHostName, objArray1));
				}
				return ADOPathUtil.CreateFilterClause(op, directoryAttribute, hostEntry.HostName);
			}
			else
			{
				object[] objArray2 = new object[2];
				objArray2[0] = ipAddress;
				objArray2[1] = extendedAttribute;
				throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.SearchConverterInvalidValue, objArray2));
			}
		}
Exemplo n.º 19
0
        private static IADOPathNode BuildHostFilterFromIP(string ipAddress, IPUtil.IPVersion ipVersion, string extendedAttribute, string directoryAttribute, ADOperator op)
        {
            IPHostEntry hostEntry;
            IPAddress   pAddress;

            try
            {
                pAddress = IPAddress.Parse(ipAddress);
            }
            catch (Exception exception)
            {
                object[] objArray = new object[2];
                objArray[0] = ipAddress;
                objArray[1] = extendedAttribute;
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.SearchConverterInvalidValue, objArray));
            }
            if (pAddress.AddressFamily == (AddressFamily)ipVersion)
            {
                try
                {
                    hostEntry = Dns.GetHostEntry(pAddress);
                }
                catch (SocketException socketException)
                {
                    object[] objArray1 = new object[1];
                    objArray1[0] = ipAddress;
                    throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.CannotResolveIPAddressToHostName, objArray1));
                }
                return(ADOPathUtil.CreateFilterClause(op, directoryAttribute, hostEntry.HostName));
            }
            else
            {
                object[] objArray2 = new object[2];
                objArray2[0] = ipAddress;
                objArray2[1] = extendedAttribute;
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.SearchConverterInvalidValue, objArray2));
            }
        }
Exemplo n.º 20
0
 internal BinaryADOPathNode(ADOperator op, IADOPathNode leftExpr, IADOPathNode rightExpr)
 {
     this._operator  = op;
     this._leftExpr  = leftExpr;
     this._rightExpr = rightExpr;
 }
Exemplo n.º 21
0
        string Microsoft.ActiveDirectory.Management.IADOPathNode.GetLdapFilterString()
        {
            ADOperator    aDOperator;
            StringBuilder stringBuilder = new StringBuilder();
            bool          flag          = false;
            bool          flag1         = false;

            if (this._operator == ADOperator.Gt || this._operator == ADOperator.Lt || this._operator == ADOperator.Ne || this._operator == ADOperator.NotLike)
            {
                flag  = true;
                flag1 = true;
                ADOperator aDOperator1 = this._operator;
                if (aDOperator1 == ADOperator.Lt)
                {
                    aDOperator = ADOperator.Ge;
                    stringBuilder.Append("(");
                    if (flag)
                    {
                        stringBuilder.Append("!");
                    }
                    stringBuilder.Append(this._leftExpr.GetLdapFilterString());
                    stringBuilder.Append(ADOPathUtil.GetLdapFilterString(aDOperator));
                    stringBuilder.Append(this._rightExpr.GetLdapFilterString());
                    stringBuilder.Append(")");
                    if (flag1)
                    {
                        stringBuilder.Insert(0, "(&");
                        stringBuilder.Append("(");
                        stringBuilder.Append(this._leftExpr.GetLdapFilterString());
                        stringBuilder.Append("=*))");
                    }
                    return(stringBuilder.ToString());
                }
                else if (aDOperator1 == ADOperator.Gt)
                {
                    aDOperator = ADOperator.Le;
                    stringBuilder.Append("(");
                    if (flag)
                    {
                        stringBuilder.Append("!");
                    }
                    stringBuilder.Append(this._leftExpr.GetLdapFilterString());
                    stringBuilder.Append(ADOPathUtil.GetLdapFilterString(aDOperator));
                    stringBuilder.Append(this._rightExpr.GetLdapFilterString());
                    stringBuilder.Append(")");
                    if (flag1)
                    {
                        stringBuilder.Insert(0, "(&");
                        stringBuilder.Append("(");
                        stringBuilder.Append(this._leftExpr.GetLdapFilterString());
                        stringBuilder.Append("=*))");
                    }
                    return(stringBuilder.ToString());
                }
                else if (aDOperator1 == ADOperator.Approx || aDOperator1 == ADOperator.RecursiveMatch)
                {
                    throw new InvalidOperationException("Code flow should never come here");
                }
                else if (aDOperator1 == ADOperator.Ne)
                {
                    aDOperator = ADOperator.Eq;
                    stringBuilder.Append("(");
                    if (flag)
                    {
                        stringBuilder.Append("!");
                    }
                    stringBuilder.Append(this._leftExpr.GetLdapFilterString());
                    stringBuilder.Append(ADOPathUtil.GetLdapFilterString(aDOperator));
                    stringBuilder.Append(this._rightExpr.GetLdapFilterString());
                    stringBuilder.Append(")");
                    if (flag1)
                    {
                        stringBuilder.Insert(0, "(&");
                        stringBuilder.Append("(");
                        stringBuilder.Append(this._leftExpr.GetLdapFilterString());
                        stringBuilder.Append("=*))");
                    }
                    return(stringBuilder.ToString());
                }
                if (aDOperator1 != ADOperator.NotLike)
                {
                    throw new InvalidOperationException("Code flow should never come here");
                }
                aDOperator = ADOperator.Eq;
                string ldapFilterString = this._rightExpr.GetLdapFilterString();
                if (ADOPathUtil.IsValueAllAsterisk(ldapFilterString))
                {
                    flag1 = false;
                }
            }
            else
            {
                aDOperator = this._operator;
            }
            stringBuilder.Append("(");
            if (flag)
            {
                stringBuilder.Append("!");
            }
            stringBuilder.Append(this._leftExpr.GetLdapFilterString());
            stringBuilder.Append(ADOPathUtil.GetLdapFilterString(aDOperator));
            stringBuilder.Append(this._rightExpr.GetLdapFilterString());
            stringBuilder.Append(")");
            if (flag1)
            {
                stringBuilder.Insert(0, "(&");
                stringBuilder.Append("(");
                stringBuilder.Append(this._leftExpr.GetLdapFilterString());
                stringBuilder.Append("=*))");
            }
            return(stringBuilder.ToString());

            throw new InvalidOperationException("Code flow should never come here");
        }
Exemplo n.º 22
0
        internal static string GetLdapFilterString(ADOperator op)
        {
            ADOperator aDOperator = op;

            switch (aDOperator)
            {
            case ADOperator.Eq:
            {
                return("=");
            }

            case ADOperator.Le:
            {
                return("<=");
            }

            case ADOperator.Ge:
            {
                return(">=");
            }

            case ADOperator.Lt:
            {
                return("NOT_SUPPORTED <");
            }

            case ADOperator.Gt:
            {
                return("NOT_SUPPORTED >");
            }

            case ADOperator.Approx:
            {
                return("~=");
            }

            case ADOperator.RecursiveMatch:
            {
                return(":1.2.840.113556.1.4.1941:=");
            }

            case ADOperator.Ne:
            {
                return("NOT_SUPPORTED !=");
            }

            case ADOperator.Band:
            {
                return(":1.2.840.113556.1.4.803:=");
            }

            case ADOperator.Bor:
            {
                return(":1.2.840.113556.1.4.804:=");
            }

            case ADOperator.Like:
            {
                return("=");
            }

            case ADOperator.NotLike:
            {
                return("NOT_SUPPORTED !=");
            }

            case ADOperator.Not:
            {
                return("!");
            }

            case ADOperator.And:
            {
                return("&");
            }

            case ADOperator.Or:
            {
                return("|");
            }
            }
            object[] str = new object[1];
            str[0] = op.ToString();
            throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, StringResources.ADFilterOperatorNotSupported, str));
        }
Exemplo n.º 23
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));
                }
            }
        }
Exemplo n.º 24
0
        internal static IADOPathNode ToSearchNegativeTimeSpan(string extendedAttributeName, string[] directoryAttributes, IADOPathNode filterClause, CmdletSessionInfo cmdletSessionInfo)
        {
            TimeSpan          timeSpan;
            BinaryADOPathNode binaryADOPathNode = filterClause as BinaryADOPathNode;

            if (binaryADOPathNode != null)
            {
                PropertyADOPathNode propertyADOPathNode = new PropertyADOPathNode(directoryAttributes[0]);
                TextDataADOPathNode textDataADOPathNode = new TextDataADOPathNode("");
                IDataNode           rightNode           = binaryADOPathNode.RightNode as IDataNode;
                if (rightNode != null)
                {
                    if (!(rightNode.DataObject is TimeSpan))
                    {
                        if (!(rightNode.DataObject is long) || !(rightNode.DataObject is int))
                        {
                            long dataObject = (long)rightNode.DataObject;
                            long num        = -Math.Abs(dataObject);
                            textDataADOPathNode.TextValue = num.ToString();
                        }
                        else
                        {
                            if (rightNode.DataObject as string == null)
                            {
                                object[] type = new object[2];
                                type[0] = rightNode.DataObject.GetType();
                                type[1] = directoryAttributes[0];
                                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.SearchConverterUnrecognizedObjectType, type));
                            }
                            else
                            {
                                if (!TimeSpan.TryParse((string)rightNode.DataObject, out timeSpan))
                                {
                                    textDataADOPathNode.TextValue = (string)rightNode.DataObject;
                                }
                                else
                                {
                                    long num1 = -Math.Abs(timeSpan.Ticks);
                                    textDataADOPathNode.TextValue = num1.ToString();
                                }
                            }
                        }
                    }
                    else
                    {
                        TimeSpan dataObject1 = (TimeSpan)rightNode.DataObject;
                        long     num2        = -Math.Abs(dataObject1.Ticks);
                        textDataADOPathNode.TextValue = num2.ToString();
                    }
                    ADOperator @operator  = binaryADOPathNode.Operator;
                    ADOperator aDOperator = @operator;
                    switch (aDOperator)
                    {
                    case ADOperator.Le:
                    {
                        @operator = ADOperator.Ge;
                        break;
                    }

                    case ADOperator.Ge:
                    {
                        @operator = ADOperator.Le;
                        break;
                    }

                    case ADOperator.Lt:
                    {
                        @operator = ADOperator.Gt;
                        break;
                    }

                    case ADOperator.Gt:
                    {
                        @operator = ADOperator.Lt;
                        break;
                    }
                    }
                    return(new BinaryADOPathNode(@operator, propertyADOPathNode, textDataADOPathNode));
                }
                else
                {
                    throw new ArgumentException(StringResources.SearchConverterRHSNotDataNode);
                }
            }
            else
            {
                throw new ArgumentException(StringResources.SearchConverterNotBinaryNode);
            }
        }
Exemplo n.º 25
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);
            }
        }
Exemplo n.º 26
0
		public static IADOPathNode CreateFilterClause(ADOperator op, string attributeName, object value)
		{
			IADOPathNode objectADOPathNode;
			IADOPathNode propertyADOPathNode = new PropertyADOPathNode(attributeName);
			string str = value as string;
			if (str == null)
			{
				objectADOPathNode = new ObjectADOPathNode(value);
			}
			else
			{
				objectADOPathNode = new TextDataADOPathNode(str);
			}
			return ADOPathUtil.CreateRelationalExpressionNode(op, propertyADOPathNode, objectADOPathNode, null);
		}
Exemplo n.º 27
0
		internal BinaryADOPathNode(ADOperator op, IADOPathNode leftExpr, IADOPathNode rightExpr)
		{
			this._operator = op;
			this._leftExpr = leftExpr;
			this._rightExpr = rightExpr;
		}
Exemplo n.º 28
0
		internal static IdentityResolverDelegate GetAggregatedIdentityResolver(ADOperator op, IdentityResolverDelegate[] identityDelegates)
		{
			return (object identityObject, string searchBase, CmdletSessionInfo cmdletSessionInfo, out bool useSearchFilter) => IdentityResolverMethods.BuildAggregatedSearchFilterIdentityResolver(identityDelegates, op, identityObject, searchBase, cmdletSessionInfo, out useSearchFilter);
		}
Exemplo n.º 29
0
		internal static IADOPathNode CreateRelationalExpressionNode(ADOperator op, IADOPathNode leftExpr, IADOPathNode rightExpr, ConvertSearchFilterDelegate searchFilterConverter)
		{
			if (op == ADOperator.Eq || op == ADOperator.Ne)
			{
				VariableADOPathNode variableADOPathNode = rightExpr as VariableADOPathNode;
				if (variableADOPathNode != null)
				{
					variableADOPathNode.EncodeAsteriskChar = true;
				}
				TextDataADOPathNode textDataADOPathNode = rightExpr as TextDataADOPathNode;
				if (textDataADOPathNode != null)
				{
					textDataADOPathNode.EncodeAsteriskChar = true;
				}
			}
			IADOPathNode binaryADOPathNode = new BinaryADOPathNode(op, leftExpr, rightExpr);
			if (searchFilterConverter != null)
			{
				binaryADOPathNode = searchFilterConverter(binaryADOPathNode);
			}
			return binaryADOPathNode;
		}
Exemplo n.º 30
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);
            }
        }
Exemplo n.º 31
0
		internal static string GetLdapFilterString(ADOperator op)
		{
			ADOperator aDOperator = op;
			switch (aDOperator)
			{
				case ADOperator.Eq:
				{
					return "=";
				}
				case ADOperator.Le:
				{
					return "<=";
				}
				case ADOperator.Ge:
				{
					return ">=";
				}
				case ADOperator.Lt:
				{
					return "NOT_SUPPORTED <";
				}
				case ADOperator.Gt:
				{
					return "NOT_SUPPORTED >";
				}
				case ADOperator.Approx:
				{
					return "~=";
				}
				case ADOperator.RecursiveMatch:
				{
					return ":1.2.840.113556.1.4.1941:=";
				}
				case ADOperator.Ne:
				{
					return "NOT_SUPPORTED !=";
				}
				case ADOperator.Band:
				{
					return ":1.2.840.113556.1.4.803:=";
				}
				case ADOperator.Bor:
				{
					return ":1.2.840.113556.1.4.804:=";
				}
				case ADOperator.Like:
				{
					return "=";
				}
				case ADOperator.NotLike:
				{
					return "NOT_SUPPORTED !=";
				}
				case ADOperator.Not:
				{
					return "!";
				}
				case ADOperator.And:
				{
					return "&";
				}
				case ADOperator.Or:
				{
					return "|";
				}
			}
			object[] str = new object[1];
			str[0] = op.ToString();
			throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, StringResources.ADFilterOperatorNotSupported, str));
		}
Exemplo n.º 32
0
		internal static bool IsOperatorUnary(ADOperator op)
		{
			if (op != ADOperator.Not)
			{
				return false;
			}
			else
			{
				return true;
			}
		}
Exemplo n.º 33
0
 internal static IdentityResolverDelegate GetAggregatedIdentityResolver(ADOperator op, IdentityResolverDelegate[] identityDelegates)
 {
     return((object identityObject, string searchBase, CmdletSessionInfo cmdletSessionInfo, out bool useSearchFilter) => IdentityResolverMethods.BuildAggregatedSearchFilterIdentityResolver(identityDelegates, op, identityObject, searchBase, cmdletSessionInfo, out useSearchFilter));
 }
Exemplo n.º 34
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);
            }
        }
Exemplo n.º 35
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));
				}
			}
		}
Exemplo n.º 36
0
        internal static ADObjectSearcher BuildAggregatedSearchFilterIdentityResolver(IdentityResolverDelegate[] identityDelegates, ADOperator op, object identity, string searchRoot, CmdletSessionInfo cmdletSessionInfo, out bool useSearchFilter)
        {
            ADObjectSearcher    item;
            List <IADOPathNode> aDOPathNodes = new List <IADOPathNode>((int)identityDelegates.Length);

            IdentityResolverDelegate[] identityResolverDelegateArray = identityDelegates;
            for (int i = 0; i < (int)identityResolverDelegateArray.Length; i++)
            {
                bool V_1;
                IdentityResolverDelegate identityResolverDelegate = identityResolverDelegateArray[i];
                item = identityResolverDelegate(identity, searchRoot, cmdletSessionInfo, out V_1);
                if (item != null)
                {
                    aDOPathNodes.Add(item.Filter);
                }
            }
            item = SearchUtility.BuildSearcher(cmdletSessionInfo.ADSessionInfo, searchRoot, ADSearchScope.Subtree);
            if (aDOPathNodes.Count <= 1)
            {
                if (aDOPathNodes.Count != 1)
                {
                    item = null;
                }
                else
                {
                    item.Filter = aDOPathNodes[0];
                }
            }
            else
            {
                if (ADOperator.Or != op)
                {
                    item.Filter = ADOPathUtil.CreateAndClause(aDOPathNodes.ToArray());
                }
                else
                {
                    item.Filter = ADOPathUtil.CreateOrClause(aDOPathNodes.ToArray());
                }
            }
            useSearchFilter = true;
            return(item);
        }