예제 #1
0
 /// <summary>
 /// Creates a SearchRequest packet.
 /// </summary>
 /// <param name="context">The user context which contains message ID.</param>
 /// <param name="dn">The DN to be searched.</param>
 /// <param name="sizeLimit">Size limit.</param>
 /// <param name="timeLimit">Time limit, in seconds.</param>
 /// <param name="scope">Search scope. Base, single level, or subtree.</param>
 /// <param name="dereferenceAliases">Dereference aliase options.</param>
 /// <param name="filter">Search filter.</param>
 /// <param name="typesOnly">
 /// Specifies whether the search returns only the attribute names without the attribute values.
 /// </param>
 /// <param name="attributes">The attributes to be retrieved.</param>
 /// <returns>The packet that contains the request.</returns>
 internal abstract AdtsSearchRequestPacket CreateSearchRequest(
     AdtsLdapContext context,
     string dn,
     long sizeLimit,
     long timeLimit,
     SearchScope scope,
     DereferenceAlias dereferenceAliases,
     Asn1Choice filter,
     bool typesOnly,
     params string[] attributes);
예제 #2
0
 /// <summary>
 /// Creates a SearchRequest packet.
 /// </summary>
 /// <param name="dn">The DN to be searched.</param>
 /// <param name="sizeLimit">Size limit for search response.</param>
 /// <param name="timeLimit">
 /// Time limit of search, in seconds, before DC returns an timeLimitExceeded error.
 /// </param>
 /// <param name="scope">Search scope. Base, single level, or subtree.</param>
 /// <param name="dereferenceAliases">Dereference alias options.</param>
 /// <param name="filter">Search filter.</param>
 /// <param name="typesOnly">
 /// Specifies whether the search returns only the attribute names without the attribute values.
 /// </param>
 /// <param name="attributes">The attributes to be retrieved.</param>
 /// <returns>The packet that contains the response.</returns>
 public virtual AdtsSearchRequestPacket CreateSearchRequest(
     string dn,
     long sizeLimit,
     long timeLimit,
     SearchScope scope,
     DereferenceAlias dereferenceAliases,
     Asn1Choice filter,
     bool typesOnly,
     params string[] attributes)
 {
     return(this.encoder.CreateSearchRequest(
                this.context,
                dn,
                sizeLimit,
                timeLimit,
                scope,
                dereferenceAliases,
                filter,
                typesOnly,
                attributes));
 }
예제 #3
0
        public void Aliases_SetInvalid_ThrowsInvalidEnumArgumentException(DereferenceAlias aliases)
        {
            var request = new SearchRequest();

            AssertExtensions.Throws <InvalidEnumArgumentException>("value", () => request.Aliases = aliases);
        }
예제 #4
0
        protected override XmlElement ToXmlNode(XmlDocument doc)
        {
            string       str;
            XmlElement   xmlElement   = base.CreateRequestElement(doc, "searchRequest", true, this.dn);
            XmlAttribute xmlAttribute = doc.CreateAttribute("scope", null);
            SearchScope  searchScope  = this.directoryScope;

            switch (searchScope)
            {
            case SearchScope.Base:
            {
                xmlAttribute.InnerText = "baseObject";
                break;
            }

            case SearchScope.OneLevel:
            {
                xmlAttribute.InnerText = "singleLevel";
                break;
            }

            case SearchScope.Subtree:
            {
                xmlAttribute.InnerText = "wholeSubtree";
                break;
            }
            }
            xmlElement.Attributes.Append(xmlAttribute);
            XmlAttribute     xmlAttribute1   = doc.CreateAttribute("derefAliases", null);
            DereferenceAlias dereferenceAlia = this.directoryRefAlias;

            switch (dereferenceAlia)
            {
            case DereferenceAlias.Never:
            {
                xmlAttribute1.InnerText = "neverDerefAliases";
                break;
            }

            case DereferenceAlias.InSearching:
            {
                xmlAttribute1.InnerText = "derefInSearching";
                break;
            }

            case DereferenceAlias.FindingBaseObject:
            {
                xmlAttribute1.InnerText = "derefFindingBaseObj";
                break;
            }

            case DereferenceAlias.Always:
            {
                xmlAttribute1.InnerText = "derefAlways";
                break;
            }
            }
            xmlElement.Attributes.Append(xmlAttribute1);
            XmlAttribute str1 = doc.CreateAttribute("sizeLimit", null);

            str1.InnerText = this.directorySizeLimit.ToString(CultureInfo.InvariantCulture);
            xmlElement.Attributes.Append(str1);
            XmlAttribute str2  = doc.CreateAttribute("timeLimit", null);
            long         ticks = this.directoryTimeLimit.Ticks / (long)0x989680;

            str2.InnerText = ticks.ToString(CultureInfo.InvariantCulture);
            xmlElement.Attributes.Append(str2);
            XmlAttribute xmlAttribute2 = doc.CreateAttribute("typesOnly", null);
            XmlAttribute xmlAttribute3 = xmlAttribute2;

            if (this.directoryTypesOnly)
            {
                str = "true";
            }
            else
            {
                str = "false";
            }
            xmlAttribute3.InnerText = str;
            xmlElement.Attributes.Append(xmlAttribute2);
            XmlElement outerXml = doc.CreateElement("filter", "urn:oasis:names:tc:DSML:2:0:core");

            if (this.Filter == null)
            {
                outerXml.InnerXml = "<present name='objectClass' xmlns=\"urn:oasis:names:tc:DSML:2:0:core\"/>";
            }
            else
            {
                StringWriter  stringWriter  = new StringWriter(CultureInfo.InvariantCulture);
                XmlTextWriter xmlTextWriter = new XmlTextWriter(stringWriter);
                try
                {
                    if (this.Filter as XmlDocument == null)
                    {
                        if (this.Filter as string != null)
                        {
                            string filter = (string)this.Filter;
                            if (!filter.StartsWith("(", StringComparison.Ordinal) && !filter.EndsWith(")", StringComparison.Ordinal))
                            {
                                filter = filter.Insert(0, "(");
                                filter = string.Concat(filter, ")");
                            }
                            ADFilter aDFilter = FilterParser.ParseFilterString(filter);
                            if (aDFilter != null)
                            {
                                DSMLFilterWriter dSMLFilterWriter = new DSMLFilterWriter();
                                dSMLFilterWriter.WriteFilter(aDFilter, false, xmlTextWriter, "urn:oasis:names:tc:DSML:2:0:core");
                                outerXml.InnerXml = stringWriter.ToString();
                            }
                            else
                            {
                                throw new ArgumentException(Res.GetString("BadSearchLDAPFilter"));
                            }
                        }
                    }
                    else
                    {
                        if (((XmlDocument)this.Filter).NamespaceURI.Length != 0)
                        {
                            outerXml.InnerXml = ((XmlDocument)this.Filter).OuterXml;
                        }
                        else
                        {
                            this.CopyFilter((XmlDocument)this.Filter, xmlTextWriter);
                            outerXml.InnerXml = stringWriter.ToString();
                        }
                    }
                }
                finally
                {
                    xmlTextWriter.Close();
                }
            }
            xmlElement.AppendChild(outerXml);
            if (this.directoryAttributes != null && this.directoryAttributes.Count != 0)
            {
                XmlElement xmlElement1 = doc.CreateElement("attributes", "urn:oasis:names:tc:DSML:2:0:core");
                xmlElement.AppendChild(xmlElement1);
                foreach (string directoryAttribute in this.directoryAttributes)
                {
                    DirectoryAttribute directoryAttribute1 = new DirectoryAttribute();
                    directoryAttribute1.Name = directoryAttribute;
                    XmlElement xmlNode = directoryAttribute1.ToXmlNode(doc, "attribute");
                    xmlElement1.AppendChild(xmlNode);
                }
            }
            return(xmlElement);
        }
 /// <summary>
 /// Creates a SearchRequest packet.
 /// </summary>
 /// <param name="dn">The DN to be searched.</param>
 /// <param name="sizeLimit">Size limit for search response.</param>
 /// <param name="timeLimit">
 /// Time limit of search, in seconds, before DC returns an timeLimitExceeded error.
 /// </param>
 /// <param name="scope">Search scope. Base, single level, or subtree.</param>
 /// <param name="dereferenceAliases">Dereference alias options.</param>
 /// <param name="filter">Search filter.</param>
 /// <param name="typesOnly">
 /// Specifies whether the search returns only the attribute names without the attribute values.
 /// </param>
 /// <param name="attributes">The attributes to be retrieved.</param>
 /// <returns>The packet that contains the response.</returns>
 public virtual AdtsSearchRequestPacket CreateSearchRequest(
     string dn,
     long sizeLimit,
     long timeLimit,
     SearchScope scope,
     DereferenceAlias dereferenceAliases,
     Asn1Choice filter,
     bool typesOnly,
     params string[] attributes)
 {
     return this.encoder.CreateSearchRequest(
         this.context,
         dn,
         sizeLimit,
         timeLimit,
         scope,
         dereferenceAliases,
         filter,
         typesOnly,
         attributes);
 }
 /// <summary>
 /// Creates a SearchRequest packet.
 /// </summary>
 /// <param name="context">The user context which contains message ID.</param>
 /// <param name="dn">The DN to be searched.</param>
 /// <param name="sizeLimit">Size limit.</param>
 /// <param name="timeLimit">Time limit, in seconds.</param>
 /// <param name="scope">Search scope. Base, single level, or subtree.</param>
 /// <param name="dereferenceAliases">Dereference aliase options.</param>
 /// <param name="filter">Search filter.</param>
 /// <param name="typesOnly">
 /// Specifies whether the search returns only the attribute names without the attribute values.
 /// </param>
 /// <param name="attributes">The attributes to be retrieved.</param>
 /// <returns>The packet that contains the request.</returns>
 internal abstract AdtsSearchRequestPacket CreateSearchRequest(
     AdtsLdapContext context,
     string dn,
     long sizeLimit,
     long timeLimit,
     SearchScope scope,
     DereferenceAlias dereferenceAliases,
     Asn1Choice filter,
     bool typesOnly,
     params string[] attributes);