Exemple #1
0
        public LdapPagedResultsControl(string oid, bool critical, byte[] values) : base(oid, critical, values)
        {
            var lberDecoder = new LberDecoder();

            if (lberDecoder == null)
            {
                throw new InvalidOperationException($"Failed to build {nameof(LberDecoder)}");
            }

            var asn1Object = lberDecoder.Decode(values);

            if (!(asn1Object is Asn1Sequence))
            {
                throw new InvalidCastException(DecodedNotSequence);
            }

            var size = ((Asn1Structured)asn1Object).get_Renamed(0);

            if (!(size is Asn1Integer integerSize))
            {
                throw new InvalidOperationException(DecodedNotInteger);
            }
            Size = integerSize.IntValue();

            var cookie = ((Asn1Structured)asn1Object).get_Renamed(1);

            if (!(cookie is Asn1OctetString octetCookie))
            {
                throw new InvalidOperationException(DecodedNotOctetString);
            }
            Cookie = octetCookie.ByteValue();
        }
        //[CLSCompliantAttribute(false)]
        public LdapPagedResultsResponse(String oid, bool critical, byte[] values) : base(oid, critical, values)
        {
            /* Create a decoder object */
            LberDecoder decoder = new LberDecoder();

            if (decoder == null)
            {
                throw new System.IO.IOException("Decoding error");
            }

            /* We should get back an ASN.1 Sequence object */
            Asn1Object asnObj = decoder.Decode(values);

            if ((asnObj == null) || (!(asnObj is Asn1Sequence)))
            {
                throw new System.IO.IOException("Decoding error");
            }

            /*
             * Get the 1st element which should be an integer containing the
             * size (RFC 2696).
             */
            Asn1Object asn1Size = ((Asn1Sequence)asnObj).get_Renamed(0);

            if ((asn1Size != null) && (asn1Size is Asn1Integer))
            {
                m_size = ((Asn1Integer)asn1Size).IntValue();
            }
            else
            {
                throw new System.IO.IOException("Decoding error");
            }

            /*
             * Get the 2nd element which should be an octet string containing the
             * cookie (RFC 2696).
             */
            Asn1Object asn1Cookie = ((Asn1Sequence)asnObj).get_Renamed(1);

            if ((asn1Cookie != null) && (asn1Cookie is Asn1OctetString))
            {
                m_cookie = ((Asn1OctetString)asn1Cookie).StringValue();
            }
            else
            {
                throw new System.IO.IOException("Decoding error");
            }

            return;
        }
Exemple #3
0
        /// <summary>
        ///     This constructor is usually called by the SDK to instantiate an
        ///     a LdapControl corresponding to the Server response to a Ldap
        ///     Sort Control request.  Application programmers should not have
        ///     any reason to call the constructor.  This constructor besides
        ///     constructing a LdapControl object parses the contents of the response
        ///     control.
        ///     RFC 2891 defines this response control as follows:
        ///     The controlValue is an OCTET STRING, whose
        ///     value is the BER encoding of a value of the following SEQUENCE:
        ///     SortResult ::= SEQUENCE {
        ///     sortResult  ENUMERATED {
        ///     success                   (0), -- results are sorted
        ///     operationsError           (1), -- server internal failure
        ///     timeLimitExceeded         (3), -- timelimit reached before
        ///     -- sorting was completed
        ///     strongAuthRequired        (8), -- refused to return sorted
        ///     -- results via insecure
        ///     -- protocol
        ///     adminLimitExceeded       (11), -- too many matching entries
        ///     -- for the server to sort
        ///     noSuchAttribute          (16), -- unrecognized attribute
        ///     -- type in sort key
        ///     inappropriateMatching    (18), -- unrecognized or
        ///     -- inappropriate matching
        ///     -- rule in sort key
        ///     insufficientAccessRights (50), -- refused to return sorted
        ///     -- results to this client
        ///     busy                     (51), -- too busy to process
        ///     unwillingToPerform       (53), -- unable to sort
        ///     other                    (80)
        ///     },
        ///     attributeType [0] AttributeDescription OPTIONAL }.
        /// </summary>
        /// <param name="oid">
        ///     The OID of the control, as a dotted string.
        /// </param>
        /// <param name="critical">
        ///     True if the Ldap operation should be discarded if
        ///     the control is not supported. False if
        ///     the operation can be processed without the control.
        /// </param>
        /// <param name="values">
        ///     The control-specific data.
        /// </param>
        public LdapSortResponse(string oid, bool critical, byte[] values)
            : base(oid, critical, values)
        {
            // Create a decoder object
            var decoder = new LberDecoder();

            if (decoder == null)
            {
                throw new IOException("Decoding error");
            }

            // We should get back an enumerated type
            var asnObj = decoder.Decode(values);

            if (asnObj == null || !(asnObj is Asn1Sequence))
            {
                throw new IOException("Decoding error");
            }

            var asn1Enum = ((Asn1Sequence)asnObj).get_Renamed(0);

            if (asn1Enum != null && asn1Enum is Asn1Enumerated)
            {
                ResultCode = ((Asn1Enumerated)asn1Enum).IntValue();
            }

            // Second element is the attributeType
            if (((Asn1Sequence)asnObj).Size() > 1)
            {
                var asn1String = ((Asn1Sequence)asnObj).get_Renamed(1);
                if (asn1String != null && asn1String is Asn1OctetString)
                {
                    FailedAttribute = ((Asn1OctetString)asn1String).StringValue();
                }
            }
        }
        /// <summary>
        ///     This constructor is called by the SDK to create an
        ///     LdapEntryChangeControl. This constructor should NOT be called by
        ///     application developers. It must be public since it resides in a
        ///     different package than the classes that call it.
        ///     The Entry Change Control is defined as follows:
        ///     EntryChangeNotification ::= SEQUENCE {
        ///     changeType ENUMERATED {
        ///     add             (1),
        ///     delete          (2),
        ///     modify          (4),
        ///     modDN           (8)
        ///     },
        ///     previousDN   LdapDN OPTIONAL,     -- modifyDN ops. only
        ///     changeNumber INTEGER OPTIONAL     -- if supported
        ///     }.
        /// </summary>
        /// <param name="oid">
        ///     The OID of the control, as a dotted string.
        /// </param>
        /// <param name="critical">
        ///     True if the Ldap operation should be discarded if
        ///     the control is not supported. False if
        ///     the operation can be processed without the control.
        /// </param>
        /// <param name="value">
        ///     The control-specific data.
        /// </param>
        public LdapEntryChangeControl(string oid, bool critical, byte[] valueRenamed)
            : base(oid, critical, valueRenamed)
        {
            // Create a decoder objet
            var decoder = new LberDecoder();

            if (decoder == null)
            {
                throw new IOException("Decoding error.");
            }

            // We should get a sequence initially
            var asnObj = decoder.Decode(valueRenamed);

            if (asnObj == null || !(asnObj is Asn1Sequence))
            {
                throw new IOException("Decoding error.");
            }

            var sequence = (Asn1Sequence)asnObj;

            // The first element in the sequence should be an enumerated type
            var asn1Obj = sequence.get_Renamed(0);

            if (asn1Obj == null || !(asn1Obj is Asn1Enumerated))
            {
                throw new IOException("Decoding error.");
            }

            ChangeType = ((Asn1Enumerated)asn1Obj).IntValue();

            // check for optional elements
            if (sequence.Size() > 1 && ChangeType == 8)

            // 8 means modifyDN
            {
                // get the previous DN - it is encoded as an octet string
                asn1Obj = sequence.get_Renamed(1);
                if (asn1Obj == null || !(asn1Obj is Asn1OctetString))
                {
                    throw new IOException("Decoding error get previous DN");
                }

                PreviousDn = ((Asn1OctetString)asn1Obj).StringValue();
            }
            else
            {
                PreviousDn = string.Empty;
            }

            // check for change number
            if (sequence.Size() == 3)
            {
                asn1Obj = sequence.get_Renamed(2);
                if (asn1Obj == null || !(asn1Obj is Asn1Integer))
                {
                    throw new IOException("Decoding error getting change number");
                }

                ChangeNumber    = ((Asn1Integer)asn1Obj).IntValue();
                HasChangeNumber = true;
            }
            else
            {
                HasChangeNumber = false;
            }
        }
        /* The parsed fields are stored in these private variables */

        /* The context field if one was returned by the server */

        /// <summary>
        ///     This constructor is usually called by the SDK to instantiate an
        ///     a LdapControl corresponding to the Server response to a Ldap
        ///     VLV Control request.  Application programmers should not have
        ///     any reason to call the constructor.  This constructor besides
        ///     constructing a LdapVirtualListResponse control object also
        ///     parses the contents of the response into local variables.
        ///     RFC 2891 defines this response control as follows:
        ///     The controlValue is an OCTET STRING, whose value is the BER
        ///     encoding of a value of the following ASN.1:
        ///     VirtualListViewResponse ::= SEQUENCE {
        ///     targetPosition    INTEGER (0 .. maxInt),
        ///     contentCount     INTEGER (0 .. maxInt),
        ///     virtualListViewResult ENUMERATED {
        ///     success (0),
        ///     operationsError (1),
        ///     unwillingToPerform (53),
        ///     insufficientAccessRights (50),
        ///     busy (51),
        ///     timeLimitExceeded (3),
        ///     adminLimitExceeded (11),
        ///     sortControlMissing (60),
        ///     offsetRangeError (61),
        ///     other (80) },
        ///     contextID     OCTET STRING OPTIONAL }.
        /// </summary>
        /// <param name="oid">
        ///     The OID of the control, as a dotted string.
        /// </param>
        /// <param name="critical">
        ///     True if the Ldap operation should be discarded if
        ///     the control is not supported. False if
        ///     the operation can be processed without the control.
        /// </param>
        /// <param name="values">
        ///     The control-specific data.
        /// </param>
        public LdapVirtualListResponse(string oid, bool critical, byte[] values)
            : base(oid, critical, values)
        {
            /* Create a decoder object */
            var decoder = new LberDecoder();

            if (decoder == null)
            {
                throw new IOException("Decoding error");
            }

            /* We should get back an ASN.1 Sequence object */
            var asnObj = decoder.Decode(values);

            if (asnObj == null || !(asnObj is Asn1Sequence))
            {
                throw new IOException("Decoding error");
            }

            /* Else we got back a ASN.1 sequence - print it if running debug code */

            /* Get the 1st element which should be an integer containing the
             * targetPosition (firstPosition)
             */
            var asn1FirstPosition = ((Asn1Sequence)asnObj).get_Renamed(0);

            if (asn1FirstPosition != null && asn1FirstPosition is Asn1Integer)
            {
                FirstPosition = ((Asn1Integer)asn1FirstPosition).IntValue();
            }
            else
            {
                throw new IOException("Decoding error");
            }

            /* Get the 2nd element which should be an integer containing the
             * current estimate of the contentCount
             */
            var asn1ContentCount = ((Asn1Sequence)asnObj).get_Renamed(1);

            if (asn1ContentCount != null && asn1ContentCount is Asn1Integer)
            {
                ContentCount = ((Asn1Integer)asn1ContentCount).IntValue();
            }
            else
            {
                throw new IOException("Decoding error");
            }

            /* The 3rd element is an enum containing the errorcode */
            var asn1Enum = ((Asn1Sequence)asnObj).get_Renamed(2);

            if (asn1Enum != null && asn1Enum is Asn1Enumerated)
            {
                ResultCode = ((Asn1Enumerated)asn1Enum).IntValue();
            }
            else
            {
                throw new IOException("Decoding error");
            }

            /* Optional 4th element could be the context string that the server
             * wants the client to send back with each subsequent VLV request
             */
            if (((Asn1Sequence)asnObj).Size() > 3)
            {
                var asn1String = ((Asn1Sequence)asnObj).get_Renamed(3);
                if (asn1String != null && asn1String is Asn1OctetString)
                {
                    Context = ((Asn1OctetString)asn1String).StringValue();
                }
            }
        }