/// <summary> Encode an array of LdapModifications to ASN.1. /// /// </summary> /// <param name="mods">an array of LdapModification objects /// /// </param> /// <returns> an Asn1SequenceOf object containing the modifications. /// </returns> static private Asn1SequenceOf encodeModifications(LdapModification[] mods) { // Convert Java-API LdapModification[] to RFC2251 SEQUENCE OF SEQUENCE Asn1SequenceOf rfcMods = new Asn1SequenceOf(mods.Length); for (int i = 0; i < mods.Length; i++) { LdapAttribute attr = mods[i].Attribute; // place modification attribute values in Asn1SetOf Asn1SetOf vals = new Asn1SetOf(attr.size()); if (attr.size() > 0) { System.Collections.IEnumerator attrEnum = attr.ByteValues; while (attrEnum.MoveNext()) { vals.add(new RfcAttributeValue((sbyte[])attrEnum.Current)); } } // create SEQUENCE containing mod operation and attr type and vals Asn1Sequence rfcMod = new Asn1Sequence(2); rfcMod.add(new Asn1Enumerated(mods[i].Op)); rfcMod.add(new RfcAttributeTypeAndValues(new RfcAttributeDescription(attr.Name), vals)); // place SEQUENCE into SEQUENCE OF rfcMods.add(rfcMod); } return(rfcMods); }
/// <summary> Build the attribuite list from an LdapEntry. /// /// </summary> /// <param name="entry">The LdapEntry associated with this add request. /// </param> private static RfcAttributeList makeRfcAttrList(LdapEntry entry) { // convert Java-API LdapEntry to RFC2251 AttributeList LdapAttributeSet attrSet = entry.getAttributeSet(); RfcAttributeList attrList = new RfcAttributeList(attrSet.Count); IEnumerator itr = attrSet.GetEnumerator(); while (itr.MoveNext()) { LdapAttribute attr = (LdapAttribute)itr.Current; Asn1SetOf vals = new Asn1SetOf(attr.size()); IEnumerator attrEnum = attr.ByteValues; while (attrEnum.MoveNext()) { vals.add(new RfcAttributeValue((sbyte[])attrEnum.Current)); } attrList.add(new RfcAttributeTypeAndValues(new RfcAttributeDescription(attr.Name), vals)); } return(attrList); }
/// <summary> Asynchronously compares an attribute value with one in the directory, /// using the specified queue and contraints. /// /// Please note that a successful completion of this command results in /// one of two status codes: LdapException.COMPARE_TRUE if the entry /// has the value, and LdapException.COMPARE_FALSE if the entry /// does not have the value or the attribute. /// /// </summary> /// <param name="dn"> The distinguished name of the entry containing an /// attribute to compare. /// /// </param> /// <param name="attr"> An attribute to compare. /// /// </param> /// <param name="queue"> Handler for messages returned from a server in /// response to this request. If it is null, a /// queue object is created internally. /// /// </param> /// <param name="cons"> Constraints specific to the operation. /// /// </param> /// <exception> LdapException A general exception which includes an error /// message and an Ldap error code. /// /// </exception> /// <seealso cref="LdapException.COMPARE_TRUE"> /// </seealso> /// <seealso cref="LdapException.COMPARE_FALSE"> /// </seealso> public virtual LdapResponseQueue Compare(System.String dn, LdapAttribute attr, LdapResponseQueue queue, LdapConstraints cons) { if (attr.size() != 1) { throw new System.ArgumentException("compare: Exactly one value " + "must be present in the LdapAttribute"); } if ((System.Object) dn == null) { // Invalid parameter throw new System.ArgumentException("compare: DN cannot be null"); } if (cons == null) cons = defSearchCons; LdapMessage msg = new LdapCompareRequest(dn, attr.Name, attr.ByteValue, cons.getControls()); return SendRequestToServer(msg, cons.TimeLimit, queue, null); }
static bool IsAttributeEmpty(LdapAttribute attribute) { if (attribute == null) return true; if (attribute.size() == 0) return true; if (attribute.StringValue == null || attribute.StringValue == "") return true; return false; }