示例#1
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);
            }
        }
示例#2
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
示例#3
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);
            }
        }