Inheritance: Asn1Structured
		/// <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);
			}
		}
Esempio n. 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);
      }

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

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

	Asn1Set asnSet = new Asn1Set();
	bool bFiltered = false;
	for (int nIndex = 0; nIndex < specifiers.Length; nIndex++)
	{
	  Asn1Sequence 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);
      }

      setValue(SupportClass.ToSByteArray(encodedData.ToArray()));
    } // end of the constructor MonitorEventRequest
        /// <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>
        private static 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> A copy constructor which creates an Asn1SequenceOf from an
		/// instance of Asn1Sequence.
		/// 
		/// Since SEQUENCE and SEQUENCE_OF have the same identifier, the decoder
		/// will always return a SEQUENCE object when it detects that identifier.
		/// In order to take advantage of the Asn1SequenceOf type, we need to be
		/// able to construct this object when knowingly receiving an
		/// Asn1Sequence.
		/// </summary>
		public Asn1SequenceOf(Asn1Sequence sequence):base(ID, sequence.toArray(), sequence.size())
		{
			return ;
		}
Esempio n. 5
0
		/// <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 ((System.Object) m_context != null)
				m_vlvRequest.add(new Asn1OctetString(m_context));
			
			return ;
		}
Esempio n. 6
0
		/// <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.
			*/
			Asn1Sequence 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 ((System.Object) m_context != null)
				m_vlvRequest.add(new Asn1OctetString(m_context));
			
			return ;
		}
Esempio n. 7
0
 /// <summary> Create an RfcLdapMessage using the specified Ldap Response.</summary>
 public RfcLdapMessage(Asn1Sequence op)
     : this(op, null)
 {
     return ;
 }
Esempio n. 8
0
        /// <summary> Create an RfcLdapMessage response from input parameters.</summary>
        public RfcLdapMessage(Asn1Sequence op, RfcControls controls)
            : base(3)
        {
            this.op = op;
            this.controls = controls;

            add(new RfcMessageID()); // MessageID has static counter
            add(op);
            if (controls != null)
            {
                add(controls);
            }
            return ;
        }
Esempio n. 9
0
 public DSETimeStamp(Asn1Sequence dseObject)
 {
   nSeconds = ((Asn1Integer)dseObject.get_Renamed(0)).intValue();
   replica_number = ((Asn1Integer) dseObject.get_Renamed(1)).intValue();
   nEvent = ((Asn1Integer) dseObject.get_Renamed(2)).intValue();
 }
Esempio n. 10
0
		/// <summary> Constructs a Control object by decoding from an Asn1Sequence</summary>
		public RfcControl(Asn1Sequence seqObj):base(3)
		{
			int len = seqObj.size();
			for (int i = 0; i < len; i++)
				add(seqObj.get_Renamed(i));
		}
Esempio n. 11
0
 /// <summary> 
 /// Returns a string representation of the object.
 /// </summary>
 public ReferralAddress(Asn1Sequence dseObject)
 {
   address_type = ((Asn1Integer) dseObject.get_Renamed(0)).intValue();
   strAddress = ((Asn1OctetString) dseObject.get_Renamed(1)).stringValue();
 }
Esempio n. 12
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)
		{
			
			Asn1SequenceOf sortKeyList = new Asn1SequenceOf();
			
			for (int i = 0; i < keys.Length; i++)
			{
				
				Asn1Sequence key = new Asn1Sequence();
				
				key.add(new Asn1OctetString(keys[i].Key));
				
				if ((System.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 == true)
				{
					// 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()));
			return ;
		}
        /// <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 ;
        }
Esempio n. 14
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);
            }
        }
        /// <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(System.String dn, System.String trusteeDN, System.String[] attrName)
            : base(ReplicationConstants.GET_EFFECTIVE_LIST_PRIVILEGES_REQ, null)
        {
            try
            {
                if ( ((System.Object)dn == null) )
                    throw new System.ArgumentException(ExceptionMessages.PARAM_ERROR);

                System.IO.MemoryStream encodedData = new System.IO.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(System.IO.IOException ioe)
            {
                throw new LdapException(ExceptionMessages.ENCODING_ERROR, LdapException.ENCODING_ERROR, (System.String) null);
            }
        }