コード例 #1
0
        /// <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>
        ///     Private method used to construct the ber encoded control
        ///     Used only when using the typed mode of VLV Control.
        /// </summary>
        private void BuildTypedVLVRequest()
        {
            /* Create a new Asn1Sequence object */
            m_vlvRequest = new Asn1Sequence(4);

            /* Add the beforeCount and afterCount fields to the sequence */
            m_vlvRequest.add(new Asn1Integer(m_beforeCount));
            m_vlvRequest.add(new Asn1Integer(m_afterCount));

            /* The next field is dependent on the type of indexing being used.
             * A "typed" VLV request uses a ASN.1 OCTET STRING to index to the
             * correct object in the list.  Encode the ASN.1 CHOICE corresponding
             * to this option (as indicated by the greaterthanOrEqual field)
             * in the ASN.1.
             */
            m_vlvRequest.add(new Asn1Tagged(new Asn1Identifier(Asn1Identifier.CONTEXT, false, GREATERTHANOREQUAL),
                                            new Asn1OctetString(m_jumpTo), false));

            /* Add the optional context string if one is available.
             */
            if ((object)m_context != null)
            {
                m_vlvRequest.add(new Asn1OctetString(m_context));
            }
        }
        /// <summary>
        ///     Private method used to construct the ber encoded control
        ///     Used only when using the Indexed mode of VLV Control
        /// </summary>
        private void BuildIndexedVLVRequest()
        {
            /* Create a new Asn1Sequence object */
            m_vlvRequest = new Asn1Sequence(4);

            /* Add the beforeCount and afterCount fields to the sequence */
            m_vlvRequest.add(new Asn1Integer(m_beforeCount));
            m_vlvRequest.add(new Asn1Integer(m_afterCount));

            /* The next field is dependent on the type of indexing being used.
             * An "indexed" VLV request uses a ASN.1 SEQUENCE to index to the
             * correct object in the list.  Encode the ASN.1 CHOICE corresponding
             * to this option (as indicated by the byoffset fieldin the ASN.1.
             */
            var byoffset = new Asn1Sequence(2);

            byoffset.add(new Asn1Integer(m_startIndex));
            byoffset.add(new Asn1Integer(m_contentCount));
            ;

            /* Add the ASN.1 sequence to the encoded data
             */
            m_vlvRequest.add(new Asn1Tagged(new Asn1Identifier(Asn1Identifier.CONTEXT, true, BYOFFSET), byoffset, false));

            /* Add the optional context string if one is available.
             */
            if ((object)m_context != null)
            {
                m_vlvRequest.add(new Asn1OctetString(m_context));
            }
        }
コード例 #4
0
        /// <summary>
        ///     Constructs a sort control with multiple sort keys.
        /// </summary>
        /// <param name="keys		An">
        ///     array of sort key objects, to be processed in
        ///     order.
        /// </param>
        /// <param name="critical	True">
        ///     if the search operation is to fail if the
        ///     server does not support this control.
        /// </param>
        public LdapSortControl(LdapSortKey[] keys, bool critical) : base(requestOID, critical, null)
        {
            var sortKeyList = new Asn1SequenceOf();

            for (var i = 0; i < keys.Length; i++)
            {
                var key = new Asn1Sequence();

                key.add(new Asn1OctetString(keys[i].Key));

                if ((object)keys[i].MatchRule != null)
                {
                    key.add(new Asn1Tagged(new Asn1Identifier(Asn1Identifier.CONTEXT, false, ORDERING_RULE),
                                           new Asn1OctetString(keys[i].MatchRule), false));
                }

                if (keys[i].Reverse)
                {
                    // only add if true
                    key.add(new Asn1Tagged(new Asn1Identifier(Asn1Identifier.CONTEXT, false, REVERSE_ORDER),
                                           new Asn1Boolean(true), false));
                }

                sortKeyList.add(key);
            }

            setValue(sortKeyList.getEncoding(new LBEREncoder()));
        }
コード例 #5
0
        /// <summary>Private method used to construct the ber encoded control
        /// </summary>
        private void BuildPagedSearchRequest()
        {
            /* Create a new Asn1Sequence object */
            m_pagedSearchRequest = new Asn1Sequence(2);

            /* Add the pageSize and cookie to the sequence */
            m_pagedSearchRequest.add(new Asn1Integer(m_pageSize));
            m_pagedSearchRequest.add(new Asn1OctetString(m_cookie));
        }
コード例 #6
0
        /// <summary>  Constructs an LdapPersistSearchControl object according to the
        /// supplied parameters. The resulting control is used to specify a
        /// persistent search.
        ///
        /// </summary>
        /// <param name="changeTypes"> the change types to monitor. The bitwise OR of any
        /// of the following values:
        /// <li>                           LdapPersistSearchControl.ADD</li>
        /// <li>                           LdapPersistSearchControl.DELETE</li>
        /// <li>                           LdapPersistSearchControl.MODIFY</li>
        /// <li>                           LdapPersistSearchControl.MODDN</li>
        /// To track all changes the value can be set to:
        /// <li>                           LdapPersistSearchControl.ANY</li>
        ///
        /// </param>
        /// <param name="changesOnly"> true if you do not want the server to return
        /// all existing entries in the directory that match the search
        /// criteria. (Use this if you just want the changed entries to be
        /// returned.)
        ///
        /// </param>
        /// <param name="returnControls"> true if you want the server to return entry
        /// change controls with each entry in the search results. You need to
        /// return entry change controls to discover what type of change
        /// and other additional information about the change.
        ///
        /// </param>
        /// <param name="isCritical"> true if this control is critical to the search
        /// operation. If true and the server does not support this control,
        /// the server will not perform the search at all.
        /// </param>
        public LdapPersistSearchControl(int changeTypes, bool changesOnly, bool returnControls, bool isCritical) : base(requestOID, isCritical, null)
        {
            m_changeTypes    = changeTypes;
            m_changesOnly    = changesOnly;
            m_returnControls = returnControls;

            m_sequence = new Asn1Sequence(SEQUENCE_SIZE);

            m_sequence.add(new Asn1Integer(m_changeTypes));
            m_sequence.add(new Asn1Boolean(m_changesOnly));
            m_sequence.add(new Asn1Boolean(m_returnControls));

            setValue();
            return;
        }
コード例 #7
0
        /// <summary> Constructs an extended operation object for checking effective rights.
        ///
        /// </summary>
        /// <param name="dn">       The distinguished name of the entry whose attribute is
        /// being checked.
        ///
        /// </param>
        /// <param name="trusteeDN">The distinguished name of the entry whose trustee rights
        /// are being returned
        ///
        /// </param>
        /// <param name={"attr1","attr2",...,null}> The Ldap attribute names list.
        ///
        /// </param>
        /// <exception> LdapException A general exception which includes an error
        /// message and an Ldap error code.
        /// </exception>

        public GetEffectivePrivilegesListRequest(String dn, String trusteeDN, String[] attrName) : base(ReplicationConstants.GET_EFFECTIVE_LIST_PRIVILEGES_REQ, null)
        {
            try
            {
                if (((object)dn == null))
                {
                    throw new ArgumentException(ExceptionMessages.PARAM_ERROR);
                }

                MemoryStream encodedData = new MemoryStream();
                LBEREncoder  encoder     = new LBEREncoder();

                Asn1OctetString asn1_trusteeDN = new Asn1OctetString(trusteeDN);
                Asn1OctetString asn1_dn        = new Asn1OctetString(dn);
                asn1_trusteeDN.encode(encoder, encodedData);
                asn1_dn.encode(encoder, encodedData);

                Asn1Sequence asn1_seqattr = new Asn1Sequence();
                for (int i = 0; attrName[i] != null; i++)
                {
                    Asn1OctetString asn1_attrName = new Asn1OctetString(attrName[i]);
                    asn1_seqattr.add(asn1_attrName);
                }
                asn1_seqattr.encode(encoder, encodedData);
                setValue(SupportClass.ToSByteArray(encodedData.ToArray()));
            }
            catch (IOException ioe)
            {
                throw new LdapException(ExceptionMessages.ENCODING_ERROR, LdapException.ENCODING_ERROR, (String)null);
            }
        }
コード例 #8
0
        } // end of static constructor

        public MonitorEventRequest(EdirEventSpecifier[] specifiers) :
            base(EventOids.NLDAP_MONITOR_EVENTS_REQUEST, null)
        {
            if (specifiers == null)
            {
                throw new ArgumentException(ExceptionMessages.PARAM_ERROR);
            }

            var encodedData = new MemoryStream();
            var encoder     = new LBEREncoder();

            var asnSequence = new Asn1Sequence();

            try
            {
                asnSequence.add(new Asn1Integer(specifiers.Length));

                var asnSet    = new Asn1Set();
                var bFiltered = false;
                for (var nIndex = 0; nIndex < specifiers.Length; nIndex++)
                {
                    var specifierSequence = new Asn1Sequence();
                    specifierSequence.add(new Asn1Integer((int)specifiers[nIndex].EventType));
                    specifierSequence.add(new Asn1Enumerated((int)specifiers[nIndex].EventResultType));
                    if (0 == nIndex)
                    {
                        bFiltered = null != specifiers[nIndex].EventFilter;
                        if (bFiltered)
                        {
                            setID(EventOids.NLDAP_FILTERED_MONITOR_EVENTS_REQUEST);
                        }
                    }

                    if (bFiltered)
                    {
                        // A filter is expected
                        if (null == specifiers[nIndex].EventFilter)
                        {
                            throw new ArgumentException("Filter cannot be null,for Filter events");
                        }

                        specifierSequence.add(new Asn1OctetString(specifiers[nIndex].EventFilter));
                    }
                    else
                    {
                        // No filter is expected
                        if (null != specifiers[nIndex].EventFilter)
                        {
                            throw new ArgumentException("Filter cannot be specified for non Filter events");
                        }
                    }

                    asnSet.add(specifierSequence);
                }

                asnSequence.add(asnSet);
                asnSequence.encode(encoder, encodedData);
            }
            catch (Exception e)
            {
                throw new LdapException(ExceptionMessages.ENCODING_ERROR,
                                        LdapException.ENCODING_ERROR,
                                        null, e);
            }

            setValue(SupportClass.ToSByteArray(encodedData.ToArray()));
        } // end of the constructor MonitorEventRequest
コード例 #9
0
        /**
         *
         * Constructs an extended operations object which contains the ber encoded
         * restore data.
         *
         * @param objectDN The object DN to restore
         * <br>
         * @param passwd        The encrypted password required for the object to
         * be backed up
         * <br>
         * @param bufferLength The length of backed up data
         * <br>
         * @param chunkSizesString The String containing number of chunks and
         * each chunk elements representing chunk sizes
         * <br>
         * @param returnedBuffer The actual data in byte[]
         * <br><br>
         * @exception LdapException A general exception which includes an error
         *                          message and an LDAP error code.
         */

        public LdapRestoreRequest(String objectDN, byte[] passwd,
                                  int bufferLength, String chunkSizesString, byte[] returnedBuffer) :
            base(BackupRestoreConstants.NLDAP_LDAP_RESTORE_REQUEST, null)
        {
            try
            {
                //Verify the validity of arguments
                if (objectDN == null || bufferLength == 0 ||
                    chunkSizesString == null || returnedBuffer == null)
                {
                    throw new ArgumentException("PARAM_ERROR");
                }

                //If encrypted password has null reference make it null String
                if (passwd == null)
                {
                    passwd = System.Text.Encoding.UTF8.GetBytes("");
                }

                /*
                 * From the input argument chunkSizesString get::
                 * chunkSize => Represents the number of chunks of data returned from server
                 * sizeOf each chunk => int represents the size of each chunk
                 */
                int   index;
                int   chunkSize;
                int[] chunks = null;
                index = chunkSizesString.IndexOf(';');
                try
                {
                    chunkSize = int.Parse(chunkSizesString.Substring(0, index));
                }
                catch (FormatException e)
                {
                    throw new LdapLocalException(
                              "Invalid data buffer send in the request",
                              LdapException.ENCODING_ERROR);
                }
                //Return exception if chunkSize == 0
                if (chunkSize == 0)
                {
                    throw new ArgumentException("PARAM_ERROR");
                }

                chunkSizesString = chunkSizesString.Substring(index + 1);

                int chunkIndex;
                //Construct chunks array
                chunks = new int[chunkSize];

                /*
                 * Iterate through each member in buffer and
                 * assign to chunks array elements
                 */
                for (int i = 0; i < chunkSize; i++)
                {
                    chunkIndex = chunkSizesString.IndexOf(';');
                    if (chunkIndex == -1)
                    {
                        chunks[i] = int.Parse(chunkSizesString);
                        break;
                    }
                    chunks[i] = int.Parse(chunkSizesString.Substring(0,
                                                                     chunkIndex));
                    chunkSizesString = chunkSizesString.Substring(chunkIndex + 1);
                }

                MemoryStream encodedData = new MemoryStream();
                LBEREncoder  encoder     = new LBEREncoder();

                //Form objectDN, passwd, bufferLength, data byte[] as ASN1 Objects
                Asn1OctetString asn1_objectDN     = new Asn1OctetString(objectDN);
                Asn1OctetString asn1_passwd       = new Asn1OctetString(SupportClass.ToSByteArray(passwd));
                Asn1Integer     asn1_bufferLength = new Asn1Integer(bufferLength);
                Asn1OctetString asn1_buffer       = new Asn1OctetString(SupportClass.ToSByteArray(returnedBuffer));

                //Form the chunks sequence to be passed to Server
                Asn1Sequence asn1_chunksSeq = new Asn1Sequence();
                asn1_chunksSeq.add(new Asn1Integer(chunkSize));
                Asn1Set asn1_chunksSet = new Asn1Set();
                for (int i = 0; i < chunkSize; i++)
                {
                    Asn1Integer  tmpChunk = new Asn1Integer(chunks[i]);
                    Asn1Sequence tmpSeq   = new Asn1Sequence();
                    tmpSeq.add(tmpChunk);
                    asn1_chunksSet.add(tmpSeq);
                }
                asn1_chunksSeq.add(asn1_chunksSet);

                //Encode data to send to server
                asn1_objectDN.encode(encoder, encodedData);
                asn1_passwd.encode(encoder, encodedData);
                asn1_bufferLength.encode(encoder, encodedData);
                asn1_buffer.encode(encoder, encodedData);
                asn1_chunksSeq.encode(encoder, encodedData);

                // set the value of operation specific data
                setValue(SupportClass.ToSByteArray(encodedData.ToArray()));
            }
            catch (IOException ioe)
            {
                throw new LdapException("ENCODING_ERROR", LdapException.ENCODING_ERROR, (String)null);
            }
        }
コード例 #10
0
        /// <summary>
        /// Constructs an extended operations object which contains the ber encoded
        /// replication filter.
        ///
        /// </summary>
        /// <param name="serverDN">The server on which the replication filter needs to be set
        ///
        /// </param>
        /// <param name="replicationFilter">An array of String Arrays. Each array starting with
        /// a class name followed by the attribute names for that class that should comprise
        /// the replication filter.
        ///
        /// </param>
        /// <exception> LdapException A general exception which includes an error
        /// message and an Ldap error code.
        /// </exception>
        public SetReplicationFilterRequest(System.String serverDN, System.String[][] replicationFilter) : base(ReplicationConstants.SET_REPLICATION_FILTER_REQ, null)
        {
            try
            {
                if ((System.Object)serverDN == null)
                {
                    throw new System.ArgumentException(ExceptionMessages.PARAM_ERROR);
                }

                System.IO.MemoryStream encodedData = new System.IO.MemoryStream();
                LBEREncoder            encoder     = new LBEREncoder();

                Asn1OctetString asn1_serverDN = new Asn1OctetString(serverDN);

                // Add the serverDN to encoded data
                asn1_serverDN.encode(encoder, encodedData);

                // The toplevel sequenceOF
                Asn1SequenceOf asn1_replicationFilter = new Asn1SequenceOf();

                if (replicationFilter == null)
                {
                    asn1_replicationFilter.encode(encoder, encodedData);
                    setValue(SupportClass.ToSByteArray(encodedData.ToArray()));
                    return;
                }

                int i = 0;
                // for every element in the array
                while ((i < replicationFilter.Length) && (replicationFilter[i] != null))
                {
                    // The following additional Sequence is not needed
                    // as defined by the Asn1. But the server and the
                    // C client are encoding it. Remove this when server
                    // and C client are fixed to conform to the published Asn1.
                    Asn1Sequence buginAsn1Representation = new Asn1Sequence();

                    // Add the classname to the sequence -
                    buginAsn1Representation.add(new Asn1OctetString(replicationFilter[i][0]));

                    // Start a sequenceOF for attributes
                    Asn1SequenceOf asn1_attributeList = new Asn1SequenceOf();

                    // For every attribute in the array - remember attributes start after
                    // the first element
                    int j = 1;
                    while ((j < replicationFilter[i].Length) && ((System.Object)replicationFilter[i][j] != null))
                    {
                        // Add the attribute name to the inner SequenceOf
                        asn1_attributeList.add(new Asn1OctetString(replicationFilter[i][j]));
                        j++;
                    }


                    // Add the attributeList to the sequence - extra add due to bug
                    buginAsn1Representation.add(asn1_attributeList);
                    asn1_replicationFilter.add(buginAsn1Representation);
                    i++;
                }

                asn1_replicationFilter.encode(encoder, encodedData);
                setValue(SupportClass.ToSByteArray(encodedData.ToArray()));
            }
            catch (System.IO.IOException ioe)
            {
                throw new LdapException(ExceptionMessages.ENCODING_ERROR, LdapException.ENCODING_ERROR, (System.String)null);
            }
        }