/// <summary> Constructs an object from the responseValue which contains the effective /// privileges. /// /// The constructor parses the responseValue which has the following /// format: /// responseValue ::= /// privileges INTEGER /// /// </summary> /// <exception> IOException The responseValue could not be decoded. /// </exception> public GetEffectivePrivilegesResponse(RfcLdapMessage rfcMessage) : base(rfcMessage) { if (ResultCode == LdapException.SUCCESS) { // parse the contents of the reply sbyte[] returnedValue = this.Value; if (returnedValue == null) throw new System.IO.IOException("No returned value"); // Create a decoder object LBERDecoder decoder = new LBERDecoder(); if (decoder == null) throw new System.IO.IOException("Decoding error"); Asn1Integer asn1_privileges = (Asn1Integer) decoder.decode(returnedValue); if (asn1_privileges == null) throw new System.IO.IOException("Decoding error"); privileges = asn1_privileges.intValue(); } else { privileges = 0; } }
/// <summary> Constructs an object from the responseValue which contains the bind dn. /// /// The constructor parses the responseValue which has the following /// format: /// responseValue ::= /// identity OCTET STRING /// /// </summary> /// <exception> IOException The return value could not be decoded. /// </exception> public GetBindDNResponse(RfcLdapMessage rfcMessage):base(rfcMessage) { if (ResultCode == LdapException.SUCCESS) { // parse the contents of the reply sbyte[] returnedValue = this.Value; if (returnedValue == null) throw new System.IO.IOException("No returned value"); // Create a decoder object LBERDecoder decoder = new LBERDecoder(); if (decoder == null) throw new System.IO.IOException("Decoding error"); // The only parameter returned should be an octet string Asn1OctetString asn1_identity = (Asn1OctetString) decoder.decode(returnedValue); if (asn1_identity == null) throw new System.IO.IOException("Decoding error"); // Convert to normal string object identity = asn1_identity.stringValue(); if ((System.Object) identity == null) throw new System.IO.IOException("Decoding error"); } else { identity = ""; } }
public MonitorEventResponse(RfcLdapMessage message) : base(message) { sbyte[] returnedValue = Value; if (null == returnedValue) { throw new LdapException(LdapException.resultCodeToString(ResultCode), ResultCode, null); } LBERDecoder decoder = new LBERDecoder(); Asn1Sequence sequence = (Asn1Sequence) decoder.decode(returnedValue); int length = ((Asn1Integer) sequence.get_Renamed(0)).intValue(); Asn1Set sequenceSet = (Asn1Set) sequence.get_Renamed(1); specifier_list = new EdirEventSpecifier[length]; for (int i = 0; i < length; i++) { Asn1Sequence eventspecifiersequence = (Asn1Sequence) sequenceSet.get_Renamed(i); int classfication = ((Asn1Integer) eventspecifiersequence.get_Renamed(0)).intValue(); int enumtype = ((Asn1Enumerated) eventspecifiersequence.get_Renamed(1)).intValue(); specifier_list[i] = new EdirEventSpecifier((EdirEventType)classfication, (EdirEventResultType)enumtype); } }
/// <summary> Constructs an object from the responseValue which contains the /// entry count. /// /// The constructor parses the responseValue which has the following /// format: /// responseValue ::= /// count INTEGER /// /// </summary> /// <exception> IOException The response value could not be decoded. /// </exception> public PartitionEntryCountResponse(RfcLdapMessage rfcMessage):base(rfcMessage) { if (ResultCode == LdapException.SUCCESS) { // parse the contents of the reply sbyte[] returnedValue = this.Value; if (returnedValue == null) throw new System.IO.IOException("No returned value"); // Create a decoder object LBERDecoder decoder = new LBERDecoder(); if (decoder == null) throw new System.IO.IOException("Decoding error"); Asn1Integer asn1_count = (Asn1Integer) decoder.decode(returnedValue); if (asn1_count == null) throw new System.IO.IOException("Decoding error"); count = asn1_count.intValue(); } else { count = - 1; } }
/// <summary> Used to Convert an RfcLdapMessage object to the appropriate /// LdapExtendedResponse object depending on the operation being performed. /// /// </summary> /// <param name="inResponse"> The LdapExtendedReponse object as returned by the /// extendedOperation method in the LdapConnection object. /// </param> /// <returns> An object of base class LdapExtendedResponse. The actual child /// class of this returned object depends on the operation being /// performed. /// </returns> static public LdapExtendedResponse convertToExtendedResponse(RfcLdapMessage inResponse) { LdapExtendedResponse tempResponse = new LdapExtendedResponse(inResponse); // Get the oid stored in the Extended response System.String inOID = tempResponse.ID; RespExtensionSet regExtResponses = LdapExtendedResponse.RegisteredResponses; try { System.Type extRespClass = regExtResponses.findResponseExtension(inOID); if (extRespClass == null) { return tempResponse; } System.Type[] argsClass = new System.Type[]{typeof(RfcLdapMessage)}; System.Object[] args = new System.Object[]{inResponse}; System.Exception ex; try { System.Reflection.ConstructorInfo extConstructor = extRespClass.GetConstructor(argsClass); try { System.Object resp = null; resp = extConstructor.Invoke(args); return (LdapExtendedResponse) resp; } catch (System.UnauthorizedAccessException e) { ex = e; } catch (System.Reflection.TargetInvocationException e) { ex = e; } catch (System.Exception e) { // Could not create the ResponseControl object // All possible exceptions are ignored. We fall through // and create a default LdapControl object ex = e; } } catch (System.MethodAccessException e) { // bad class was specified, fall through and return a // default LdapExtendedResponse object ex = e; } } catch (System.FieldAccessException e) { } // If we get here we did not have a registered extendedresponse // for this oid. Return a default LdapExtendedResponse object. return tempResponse; }
/// <summary> /// Duplicate this message, replacing base dn, filter, and scope if supplied. /// </summary> /// <param name="dn"> /// the base dn. /// </param> /// <param name="filter"> /// the filter. /// </param> /// <param name="reference"> /// true if a search reference. /// </param> /// <returns> /// the object representing the new message. /// </returns> public object DupMessage(string dn, string filter, bool reference) { if (_op == null) { throw new LdapException("DUP_ERROR", LdapException.LocalError, null); } var newMsg = new RfcLdapMessage(ToArray(), (IRfcRequest)get_Renamed(1), dn, filter, reference); return(newMsg); }
/// <summary> Duplicate this message, replacing base dn, filter, and scope if supplied /// /// </summary> /// <param name="dn">the base dn /// /// </param> /// <param name="filter">the filter /// /// </param> /// <param name="reference">true if a search reference /// /// </param> /// <returns> the object representing the new message /// </returns> public System.Object dupMessage(System.String dn, System.String filter, bool reference) { if ((op == null)) { throw new LdapException("DUP_ERROR", LdapException.LOCAL_ERROR, (System.String)null); } RfcLdapMessage newMsg = new RfcLdapMessage(toArray(), (RfcRequest)get_Renamed(1), dn, filter, reference); return(newMsg); }
public GetEffectivePrivilegesListResponse(RfcLdapMessage rfcMessage) : base(rfcMessage) { /// <summary> Constructs an object from the responseValue which contains the effective /// privileges. /// /// The constructor parses the responseValue which has the following /// format: /// responseValue ::=<br> /// <p>SEQUENCE numberofresponses ::= INTEGER <br> /// SET of [<br> /// SEQUENCES of {privileges INTEGER}]<br> /// /// </summary> /// <exception> IOException The responseValue could not be decoded. /// </exception> if (ResultCode == LdapException.SUCCESS) { // parse the contents of the reply sbyte [] returnedValue = this.Value; if (returnedValue == null) throw new System.IO.IOException("No returned value"); //Create a decoder object LBERDecoder decoder = new LBERDecoder(); if (decoder == null) throw new System.IO.IOException("Decoding error"); Asn1Sequence asn1_seq1 = (Asn1Sequence)decoder.decode(returnedValue); if (asn1_seq1 == null) throw new System.IO.IOException("Decoding error"); Asn1Sequence asn1_seq2 = (Asn1Sequence)asn1_seq1.get_Renamed(0); no_privileges = ((Asn1Integer)asn1_seq2.get_Renamed(0)).intValue(); Asn1Set set_privileg_response = null; set_privileg_response = ((Asn1Set)asn1_seq1.get_Renamed(1)); Asn1Sequence seq2 = null; privileges = new int[no_privileges]; for(int index=0; index < no_privileges; index++) { seq2 = (Asn1Sequence)set_privileg_response.get_Renamed(index); privileges[index]=((Asn1Integer)seq2.get_Renamed(0)).intValue(); } } }
/** * Used to Convert an RfcLDAPMessage object to the appropriate * LDAPIntermediateResponse object depending on the operation being performed. * * @param inResponse The LDAPIntermediateResponse object as returned by the * extendedOperation method in the LDAPConnection object. * <br><br> * @return An object of base class LDAPIntermediateResponse. The actual child * class of this returned object depends on the operation being * performed. * * @exception LDAPException A general exception which includes an error message * and an LDAP error code. */ static public LdapIntermediateResponse convertToIntermediateResponse(RfcLdapMessage inResponse) // throws LDAPException { LdapIntermediateResponse tempResponse = new LdapIntermediateResponse(inResponse); // Get the oid stored in the Extended response String inOID = tempResponse.getID(); RespExtensionSet regExtResponses = LdapIntermediateResponse.getRegisteredResponses(); try{ Type extRespClass = regExtResponses.findResponseExtension(inOID); if ( extRespClass == null ){ return tempResponse; } Type[] argsClass = new Type[]{typeof(RfcLdapMessage)}; Object[] args = { inResponse }; Exception ex; try{ ConstructorInfo extConstructor = extRespClass.GetConstructor(argsClass); try{ Object resp = null; resp = extConstructor.Invoke(args); return (LdapIntermediateResponse) resp; } catch (UnauthorizedAccessException e) { ex = e; } catch (TargetInvocationException e) { ex = e; } } catch (MissingMethodException e) { // bad class was specified, fall through and return a // default LDAPIntermediateResponse object ex = e; } } catch (MissingFieldException e) { // No match with the OID // Do nothing. Fall through and construct a default LDAPControl object. } // If we get here we did not have a registered extendedresponse // for this oid. Return a default LDAPIntermediateResponse object. return tempResponse; }
/// <summary> Constructs an object from the responseValue which contains the list /// of replicas. /// /// The constructor parses the responseValue which has the following /// format: /// responseValue ::= /// replicaList /// SEQUENCE OF OCTET STRINGS /// /// </summary> /// <exception> IOException The responseValue could not be decoded. /// </exception> public ListReplicasResponse(RfcLdapMessage rfcMessage):base(rfcMessage) { if (ResultCode != LdapException.SUCCESS) { replicaList = new System.String[0]; } else { // parse the contents of the reply sbyte[] returnedValue = this.Value; if (returnedValue == null) throw new System.IO.IOException("No returned value"); // Create a decoder object LBERDecoder decoder = new LBERDecoder(); if (decoder == null) throw new System.IO.IOException("Decoding error"); // We should get back a sequence Asn1Sequence returnedSequence = (Asn1Sequence) decoder.decode(returnedValue); if (returnedSequence == null) throw new System.IO.IOException("Decoding error"); // How many replicas were returned int len = returnedSequence.size(); replicaList = new System.String[len]; // Copy each one into our String array for (int i = 0; i < len; i++) { // Get the next Asn1Octet String in the sequence Asn1OctetString asn1_nextReplica = (Asn1OctetString) returnedSequence.get_Renamed(i); if (asn1_nextReplica == null) throw new System.IO.IOException("Decoding error"); // Convert to a string replicaList[i] = asn1_nextReplica.stringValue(); if ((System.Object) replicaList[i] == null) throw new System.IO.IOException("Decoding error"); } } }
/// <summary> Creates a response LdapMessage when receiving an asynchronous /// response from a server. /// /// </summary> /// <param name="message"> The RfcLdapMessage from a server. /// </param> /*package*/ internal LdapResponse(RfcLdapMessage message) : base(message) { return ; }
/// <summary> Creates an LdapMessage when sending a protocol operation and sends /// some optional controls with the message. /// /// </summary> /// <param name="op">The operation type of message. /// /// </param> /// <param name="controls">The controls to use with the operation. /// /// </param> /// <seealso cref="Type"> /// </seealso> /*package*/ internal LdapMessage(int type, RfcRequest op, LdapControl[] controls) { // Get a unique number for this request message messageType = type; RfcControls asn1Ctrls = null; if (controls != null) { // Move LdapControls into an RFC 2251 Controls object. asn1Ctrls = new RfcControls(); for (int i = 0; i < controls.Length; i++) { // asn1Ctrls.add(null); asn1Ctrls.add(controls[i].Asn1Object); } } // create RFC 2251 LdapMessage message = new RfcLdapMessage(op, asn1Ctrls); return ; }
/** * Creates an LdapIntermediateResponse object which encapsulates * a server response to an asynchronous extended operation request. * * @param message The RfcLdapMessage to convert to an * LdapIntermediateResponse object. */ public LdapIntermediateResponse(RfcLdapMessage message) : base(message) { }
internal virtual void putReply(RfcLdapMessage message) { if (!acceptReplies) { return ; } lock(replies) { replies.Add(message); } message.RequestingMessage = msg; // Save request message info switch (message.Type) { case LdapMessage.SEARCH_RESPONSE: case LdapMessage.SEARCH_RESULT_REFERENCE: case LdapMessage.INTERMEDIATE_RESPONSE: break; default: int res; stopTimer(); // Accept no more results for this message // Leave on connection queue so we can abandon if necessary acceptReplies = false; complete = true; if (bindprops != null) { res = ((RfcResponse) message.Response).getResultCode().intValue(); if (res == LdapException.SASL_BIND_IN_PROGRESS) { } else { // We either have success or failure on the bind if (res == LdapException.SUCCESS) { // Set bind properties into connection object conn.BindProperties = bindprops; } else { } // If not a sasl bind in-progress, release the bind // semaphore and wake up all waiting threads int id; if (conn.BindSemIdClear) { // Semaphore id for normal operations id = msgId; } else { // Semaphore id for sasl bind id = conn.BindSemId; conn.clearBindSemId(); } conn.freeWriteSemaphore(id); } } break; } // wake up waiting threads sleepersAwake(); return ; }
private void notifyAllUnsolicitedListeners(RfcLdapMessage message) { // MISSING: If this is a shutdown notification from the server // set a flag in the Connection class so that we can throw an // appropriate LdapException to the application LdapMessage extendedLdapMessage = new LdapExtendedResponse(message); System.String notificationOID = ((LdapExtendedResponse) extendedLdapMessage).ID; if (notificationOID.Equals(LdapConnection.SERVER_SHUTDOWN_OID)) { unsolSvrShutDnNotification = true; } int numOfListeners = unsolicitedListeners.Count; // Cycle through all the listeners for (int i = 0; i < numOfListeners; i++) { // Get next listener LdapUnsolicitedNotificationListener listener = (LdapUnsolicitedNotificationListener) unsolicitedListeners[i]; // Create a new ExtendedResponse each time as we do not want each listener // to have its own copy of the message LdapExtendedResponse tempLdapMessage = new LdapExtendedResponse(message); // Spawn a new thread for each listener to go process the message // The reason we create a new thread rather than just call the // the messageReceived method directly is beacuse we do not know // what kind of processing the notification listener class will // do. We do not want our deamon thread to block waiting for // the notification listener method to return. UnsolicitedListenerThread u = new UnsolicitedListenerThread(this, listener, tempLdapMessage); u.Start(); } return ; }
private String stateInfo; //Represent the state Information of data #endregion Fields #region Constructors /** * Constructs an object from the responseValue which contains the backup data. * <p>The constructor parses the responseValue which has the following * format:<br> * responseValue ::=<br> * <p>databufferLength ::= INTEGER <br> * mts(modification time stamp) ::= INTEGER<br> * revision ::= INTEGER<br> * returnedBuffer ::= OCTET STRING<br> * dataChunkSizes ::= <br> * SEQUENCE{<br> * noOfChunks INTEGER<br> * SET of [<br> * SEQUENCE of {eachChunksize INTEGER}]<br> * }</p> * * @exception IOException The responseValue could not be decoded. */ public LdapBackupResponse(RfcLdapMessage rfcMessage) : base(rfcMessage) { int modificationTime = 0; // Modifaction timestamp of the Object int revision = 0; // Revision number of the Object int chunksSize = 0; int[] chunks = null; //Holds size of each chunks returned from server //Verify if returned ID is not proper if (ID == null || !(ID.Equals(BackupRestoreConstants.NLDAP_LDAP_BACKUP_RESPONSE))) throw new IOException("LDAP Extended Operation not supported"); if (ResultCode == LdapException.SUCCESS) { // Get the contents of the reply byte[] returnedValue = SupportClass.ToByteArray(this.Value); if (returnedValue == null) throw new Exception("LDAP Operations error. No returned value."); // Create a decoder object LBERDecoder decoder = new LBERDecoder(); if (decoder == null) throw new Exception("Decoding error"); // Parse the parameters in the order MemoryStream currentPtr = new MemoryStream(returnedValue); // Parse bufferLength Asn1Integer asn1_bufferLength = (Asn1Integer) decoder .decode(currentPtr); if (asn1_bufferLength == null) throw new IOException("Decoding error"); bufferLength = asn1_bufferLength.intValue(); // Parse modificationTime Asn1Integer asn1_modificationTime = (Asn1Integer) decoder .decode(currentPtr); if (asn1_modificationTime == null) throw new IOException("Decoding error"); modificationTime = asn1_modificationTime.intValue(); // Parse revision Asn1Integer asn1_revision = (Asn1Integer) decoder .decode(currentPtr); if (asn1_revision == null) throw new IOException("Decoding error"); revision = asn1_revision.intValue(); //Format stateInfo to contain both modificationTime and revision this.stateInfo = modificationTime + "+" + revision; // Parse returnedBuffer Asn1OctetString asn1_returnedBuffer = (Asn1OctetString) decoder.decode(currentPtr); if (asn1_returnedBuffer == null) throw new IOException("Decoding error"); returnedBuffer = SupportClass.ToByteArray(asn1_returnedBuffer.byteValue()); /* * Parse chunks array * Chunks returned from server is encoded as shown below:: * SEQUENCE{ * chunksSize INTEGER * SET of [ * SEQUENCE of {eacChunksize INTEGER}] * } */ Asn1Sequence asn1_chunksSeq = (Asn1Sequence) decoder .decode(currentPtr); if (asn1_chunksSeq == null) throw new IOException("Decoding error"); //Get number of chunks returned from server chunksSize = ((Asn1Integer)asn1_chunksSeq.get_Renamed(0)).intValue(); //Construct chunks array chunks = new int[chunksSize]; Asn1Set asn1_chunksSet = (Asn1Set)asn1_chunksSeq.get_Renamed(1); //Iterate through asn1_chunksSet and put each size into chunks array for (int index = 0; index < chunksSize; index++) { Asn1Sequence asn1_eachSeq = (Asn1Sequence)asn1_chunksSet.get_Renamed(index); chunks[index] = ((Asn1Integer)asn1_eachSeq.get_Renamed(0)).intValue(); } //Construct a temporary StringBuffer and append chunksSize, each size //element in chunks array and actual data of eDirectoty Object System.Text.StringBuilder tempBuffer = new System.Text.StringBuilder(); tempBuffer.Append(chunksSize); tempBuffer.Append(";"); int i = 0; for (; i < (chunksSize - 1); i++) { tempBuffer.Append(chunks[i]); tempBuffer.Append(";"); } tempBuffer.Append(chunks[i]); //Assign tempBuffer to parsedString to be returned to Application this.chunkSizesString = tempBuffer.ToString(); } else { //Intialize all these if getResultCode() != LdapException.SUCCESS this.bufferLength = 0; this.stateInfo = null; this.chunkSizesString = null; this.returnedBuffer = null; } }
/// <summary> Creates an LdapExtendedResponse object which encapsulates /// a server response to an asynchronous extended operation request. /// /// </summary> /// <param name="message"> The RfcLdapMessage to convert to an /// LdapExtendedResponse object. /// </param> public LdapExtendedResponse(RfcLdapMessage message) : base(message) { }
/// <summary> This thread decodes and processes RfcLdapMessage's from the server. /// /// Note: This thread needs a graceful shutdown implementation. /// </summary> public virtual void Run() { System.String reason = "reader: thread stopping"; InterThreadException notify = null; Message info = null; System.IO.IOException ioex = null; this.enclosingInstance.reader = SupportClass.ThreadClass.Current(); // Enclosing_Instance.reader = SupportClass.ThreadClass.Current(); // Console.WriteLine("Inside run:" + this.enclosingInstance.reader.Name); try { for (; ; ) { // ------------------------------------------------------- // Decode an RfcLdapMessage directly from the socket. // ------------------------------------------------------- Asn1Identifier asn1ID; System.IO.Stream myIn; /* get current value of in, keep value consistant * though the loop, i.e. even during shutdown */ myIn = this.enclosingInstance.in_Renamed; if (myIn == null) { break; } asn1ID = new Asn1Identifier(myIn); int tag = asn1ID.Tag; if (asn1ID.Tag != Asn1Sequence.TAG) { continue; // loop looking for an RfcLdapMessage identifier } // Turn the message into an RfcMessage class Asn1Length asn1Len = new Asn1Length(myIn); RfcLdapMessage msg = new RfcLdapMessage(this.enclosingInstance.decoder, myIn, asn1Len.Length); // ------------------------------------------------------------ // Process the decoded RfcLdapMessage. // ------------------------------------------------------------ int msgId = msg.MessageID; // Find the message which requested this response. // It is possible to receive a response for a request which // has been abandoned. If abandoned, throw it away try { info = this.enclosingInstance.messages.findMessageById(msgId); info.putReply(msg); // queue & wake up waiting thread } catch (System.FieldAccessException ex) { /* * We get the NoSuchFieldException when we could not find * a matching message id. First check to see if this is * an unsolicited notification (msgID == 0). If it is not * we throw it away. If it is we call any unsolicited * listeners that might have been registered to listen for these * messages. */ /* Note the location of this code. We could have required * that message ID 0 be just like other message ID's but * since message ID 0 has to be treated specially we have * a separate check for message ID 0. Also note that * this test is after the regular message list has been * checked for. We could have always checked the list * of messages after checking if this is an unsolicited * notification but that would have inefficient as * message ID 0 is a rare event (as of this time). */ if (msgId == 0) { // Notify any listeners that might have been registered this.enclosingInstance.notifyAllUnsolicitedListeners(msg); /* * Was this a server shutdown unsolicited notification. * IF so we quit. Actually calling the return will * first transfer control to the finally clause which * will do the necessary clean up. */ if (this.enclosingInstance.unsolSvrShutDnNotification) { notify = new InterThreadException(ExceptionMessages.SERVER_SHUTDOWN_REQ, new System.Object[]{this.enclosingInstance.host, this.enclosingInstance.port}, LdapException.CONNECT_ERROR, null, null); return ; } } else { } } if ((this.enclosingInstance.stopReaderMessageID == msgId) || (this.enclosingInstance.stopReaderMessageID == Novell.Directory.Ldap.Connection.STOP_READING)) { // Stop the reader Thread. return ; } } } catch (System.IO.IOException ioe) { ioex = ioe; if ((this.enclosingInstance.stopReaderMessageID != Novell.Directory.Ldap.Connection.STOP_READING) && this.enclosingInstance.clientActive) { // Connection lost waiting for results from host:port notify = new InterThreadException(ExceptionMessages.CONNECTION_WAIT, new System.Object[]{this.enclosingInstance.host, this.enclosingInstance.port}, LdapException.CONNECT_ERROR, ioe, info); } // The connection is no good, don't use it any more this.enclosingInstance.in_Renamed = null; this.enclosingInstance.out_Renamed = null; } finally { /* * There can be four states that the reader can be in at this point: * 1) We are starting TLS and will be restarting the reader * after we have negotiated TLS. * - Indicated by whether stopReaderMessageID does not * equal CONTINUE_READING. * - Don't call Shutdown. * 2) We are stoping TLS and will be restarting after TLS is * stopped. * - Indicated by an IOException AND stopReaderMessageID equals * STOP_READING - in which case notify will be null. * - Don't call Shutdown * 3) We receive a Server Shutdown notification. * - Indicated by messageID equal to 0. * - call Shutdown. * 4) Another error occured * - Indicated by an IOException AND notify is not NULL * - call Shutdown. */ if ((!this.enclosingInstance.clientActive) || (notify != null)) { //#3 & 4 this.enclosingInstance.shutdown(reason, 0, notify); } else { this.enclosingInstance.stopReaderMessageID = Novell.Directory.Ldap.Connection.CONTINUE_READING; } } this.enclosingInstance.deadReaderException = ioex; this.enclosingInstance.deadReader = this.enclosingInstance.reader; this.enclosingInstance.reader = null; return ; }
public static async ValueTask <RfcLdapMessage> Decode(IAsn1Decoder dec, Stream inRenamed, int len, CancellationToken cancellationToken) { var message = new RfcLdapMessage(await DecodeStructured(dec, inRenamed, len, cancellationToken).ConfigureAwait(false)); // Decode implicitly tagged protocol operation from an Asn1Tagged type // to its appropriate application type. var protocolOp = (Asn1Tagged)message.get_Renamed(1); var protocolOpId = protocolOp.GetIdentifier(); var content = ((Asn1OctetString)protocolOp.TaggedValue).ByteValue(); var bais = new MemoryStream(content); switch (protocolOpId.Tag) { case LdapMessage.SearchResponse: message.set_Renamed(1, new RfcSearchResultEntry(await DecodeStructured(dec, bais, content.Length, cancellationToken).ConfigureAwait(false))); break; case LdapMessage.SearchResult: message.set_Renamed(1, await RfcLdapResult.Decode(dec, bais, content.Length, cancellationToken, newContent => new RfcSearchResultDone(newContent)).ConfigureAwait(false)); break; case LdapMessage.SearchResultReference: message.set_Renamed(1, new RfcSearchResultReference(await DecodeStructured(dec, bais, content.Length, cancellationToken).ConfigureAwait(false))); break; case LdapMessage.AddResponse: message.set_Renamed(1, await RfcLdapResult.Decode(dec, bais, content.Length, cancellationToken, newContent => new RfcAddResponse(newContent)).ConfigureAwait(false)); break; case LdapMessage.BindResponse: message.set_Renamed(1, await RfcBindResponse.Decode(dec, bais, content.Length, cancellationToken).ConfigureAwait(false)); break; case LdapMessage.CompareResponse: message.set_Renamed(1, await RfcLdapResult.Decode(dec, bais, content.Length, cancellationToken, newContent => new RfcCompareResponse(newContent)).ConfigureAwait(false)); break; case LdapMessage.DelResponse: message.set_Renamed(1, await RfcLdapResult.Decode(dec, bais, content.Length, cancellationToken, newContent => new RfcDelResponse(newContent)).ConfigureAwait(false)); break; case LdapMessage.ExtendedResponse: message.set_Renamed(1, new RfcExtendedResponse(await DecodeStructured(dec, bais, content.Length, cancellationToken).ConfigureAwait(false))); break; case LdapMessage.IntermediateResponse: message.set_Renamed(1, new RfcIntermediateResponse(await DecodeStructured(dec, bais, content.Length, cancellationToken).ConfigureAwait(false))); break; case LdapMessage.ModifyResponse: message.set_Renamed(1, await RfcLdapResult.Decode(dec, bais, content.Length, cancellationToken, newContent => new RfcModifyResponse(newContent)).ConfigureAwait(false)); break; case LdapMessage.ModifyRdnResponse: message.set_Renamed(1, await RfcLdapResult.Decode(dec, bais, content.Length, cancellationToken, newContent => new RfcModifyDnResponse(newContent)).ConfigureAwait(false)); break; default: throw new Exception("RfcLdapMessage: Invalid tag: " + protocolOpId.Tag); } // decode optional implicitly tagged controls from Asn1Tagged type to // to RFC 2251 types. if (message.Size() > 2) { var controls = (Asn1Tagged)message.get_Renamed(2); // Asn1Identifier controlsId = protocolOp.getIdentifier(); // we could check to make sure we have controls here.... content = ((Asn1OctetString)controls.TaggedValue).ByteValue(); bais = new MemoryStream(content); message.set_Renamed(2, await RfcControls.Decode(dec, bais, content.Length, cancellationToken).ConfigureAwait(false)); } return(message); }
/// <summary> Constructs an object from the responseValue which contains the /// replica information. /// /// The constructor parses the responseValue which has the following /// format: /// responseValue ::= /// partitionID INTEGER /// replicaState INTEGER /// modificationTime INTEGER /// purgeTime INTEGER /// localPartitionID INTEGER /// partitionDN OCTET STRING /// replicaType INTEGER /// flags INTEGER /// /// </summary> /// <exception> IOException The response value could not be decoded. /// </exception> public GetReplicaInfoResponse(RfcLdapMessage rfcMessage):base(rfcMessage) { if (ResultCode == LdapException.SUCCESS) { // parse the contents of the reply sbyte[] returnedValue = this.Value; if (returnedValue == null) throw new System.IO.IOException("No returned value"); // Create a decoder object LBERDecoder decoder = new LBERDecoder(); if (decoder == null) throw new System.IO.IOException("Decoding error"); // Parse the parameters in the order System.IO.MemoryStream currentPtr = new System.IO.MemoryStream(SupportClass.ToByteArray(returnedValue)); // Parse partitionID Asn1Integer asn1_partitionID = (Asn1Integer) decoder.decode(currentPtr); if (asn1_partitionID == null) throw new System.IO.IOException("Decoding error"); partitionID = asn1_partitionID.intValue(); // Parse replicaState Asn1Integer asn1_replicaState = (Asn1Integer) decoder.decode(currentPtr); if (asn1_replicaState == null) throw new System.IO.IOException("Decoding error"); replicaState = asn1_replicaState.intValue(); // Parse modificationTime Asn1Integer asn1_modificationTime = (Asn1Integer) decoder.decode(currentPtr); if (asn1_modificationTime == null) throw new System.IO.IOException("Decoding error"); modificationTime = asn1_modificationTime.intValue(); // Parse purgeTime Asn1Integer asn1_purgeTime = (Asn1Integer) decoder.decode(currentPtr); if (asn1_purgeTime == null) throw new System.IO.IOException("Decoding error"); purgeTime = asn1_purgeTime.intValue(); // Parse localPartitionID Asn1Integer asn1_localPartitionID = (Asn1Integer) decoder.decode(currentPtr); if (asn1_localPartitionID == null) throw new System.IO.IOException("Decoding error"); localPartitionID = asn1_localPartitionID.intValue(); // Parse partitionDN Asn1OctetString asn1_partitionDN = (Asn1OctetString) decoder.decode(currentPtr); if (asn1_partitionDN == null) throw new System.IO.IOException("Decoding error"); partitionDN = asn1_partitionDN.stringValue(); if ((System.Object) partitionDN == null) throw new System.IO.IOException("Decoding error"); // Parse replicaType Asn1Integer asn1_replicaType = (Asn1Integer) decoder.decode(currentPtr); if (asn1_replicaType == null) throw new System.IO.IOException("Decoding error"); replicaType = asn1_replicaType.intValue(); // Parse flags Asn1Integer asn1_flags = (Asn1Integer) decoder.decode(currentPtr); if (asn1_flags == null) throw new System.IO.IOException("Decoding error"); flags = asn1_flags.intValue(); } else { partitionID = 0; replicaState = 0; modificationTime = 0; purgeTime = 0; localPartitionID = 0; partitionDN = ""; replicaType = 0; flags = 0; } }
/// <summary> Creates an Rfc 2251 LdapMessage when the libraries receive a response /// from a command. /// /// </summary> /// <param name="message">A response message. /// </param> protected internal LdapMessage(RfcLdapMessage message) { this.message = message; return ; }
/// <summary> Duplicate this message, replacing base dn, filter, and scope if supplied /// /// </summary> /// <param name="dn">the base dn /// /// </param> /// <param name="filter">the filter /// /// </param> /// <param name="reference">true if a search reference /// /// </param> /// <returns> the object representing the new message /// </returns> public System.Object dupMessage(System.String dn, System.String filter, bool reference) { if ((op == null)) { throw new LdapException("DUP_ERROR", LdapException.LOCAL_ERROR, (System.String) null); } RfcLdapMessage newMsg = new RfcLdapMessage(toArray(), (RfcRequest) get_Renamed(1), dn, filter, reference); return newMsg; }
public EdirEventIntermediateResponse(RfcLdapMessage message) : base(message) { ProcessMessage(getValue()); }
/// <summary> Constructs an LdapSearchResult object. /// /// </summary> /// <param name="message">The RfcLdapMessage with a search result. /// </param> /*package*/ internal LdapSearchResult(RfcLdapMessage message):base(message) { return ; }
/// <summary> Constructs an object from the responseValue which contains the replication /// filter. /// /// The constructor parses the responseValue which has the following /// format: /// responseValue ::= /// SEQUENCE of SEQUENCE { /// classname OCTET STRING /// SEQUENCE of ATTRIBUTES /// } /// where /// ATTRIBUTES:: OCTET STRING /// /// </summary> /// <exception> IOException The responseValue could not be decoded. /// </exception> public GetReplicationFilterResponse(RfcLdapMessage rfcMessage) : base(rfcMessage) { if (ResultCode != LdapException.SUCCESS) { returnedFilter = new System.String[0][]; for (int i = 0; i < 0; i++) { returnedFilter[i] = new System.String[0]; } } else { // parse the contents of the reply sbyte[] returnedValue = this.Value; if (returnedValue == null) throw new System.IO.IOException("No returned value"); // Create a decoder object LBERDecoder decoder = new LBERDecoder(); if (decoder == null) throw new System.IO.IOException("Decoding error"); // We should get back a sequence Asn1Sequence returnedSequence = (Asn1Sequence) decoder.decode(returnedValue); if (returnedSequence == null) throw new System.IO.IOException("Decoding error"); // How many sequences in this list int numberOfSequences = returnedSequence.size(); returnedFilter = new System.String[numberOfSequences][]; // Parse each returned sequence object for (int classNumber = 0; classNumber < numberOfSequences; classNumber++) { // Get the next Asn1Sequence Asn1Sequence asn1_innerSequence = (Asn1Sequence) returnedSequence.get_Renamed(classNumber); if (asn1_innerSequence == null) throw new System.IO.IOException("Decoding error"); // Get the asn1 encoded classname Asn1OctetString asn1_className = (Asn1OctetString) asn1_innerSequence.get_Renamed(0); if (asn1_className == null) return ; // Get the attribute List Asn1Sequence asn1_attributeList = (Asn1Sequence) asn1_innerSequence.get_Renamed(1); if (asn1_attributeList == null) throw new System.IO.IOException("Decoding error"); int numberOfAttributes = asn1_attributeList.size(); returnedFilter[classNumber] = new System.String[numberOfAttributes + 1]; // Get the classname returnedFilter[classNumber][0] = asn1_className.stringValue(); if ((System.Object) returnedFilter[classNumber][0] == null) throw new System.IO.IOException("Decoding error"); for (int attributeNumber = 0; attributeNumber < numberOfAttributes; attributeNumber++) { // Get the asn1 encoded attribute name Asn1OctetString asn1_attributeName = (Asn1OctetString) asn1_attributeList.get_Renamed(attributeNumber); if (asn1_attributeName == null) throw new System.IO.IOException("Decoding error"); // Get attributename string returnedFilter[classNumber][attributeNumber + 1] = asn1_attributeName.stringValue(); if ((System.Object) returnedFilter[classNumber][attributeNumber + 1] == null) throw new System.IO.IOException("Decoding error"); } } } }