Encapsulates an Ldap Bind properties
Esempio n. 1
0
        private bool waitForReply_Renamed_Field = true; // true if wait for reply

        #endregion Fields

        #region Constructors

        internal Message(LdapMessage msg, int mslimit, Connection conn, MessageAgent agent, LdapMessageQueue queue, BindProperties bindprops)
        {
            InitBlock();
            this.msg = msg;
            this.conn = conn;
            this.agent = agent;
            this.queue = queue;
            this.mslimit = mslimit;
            this.msgId = msg.MessageID;
            this.bindprops = bindprops;
            return ;
        }
Esempio n. 2
0
 private void cleanup()
 {
     stopTimer(); // Make sure timer stopped
     try
     {
         acceptReplies = false;
         if (conn != null)
         {
             conn.removeMessage(this);
         }
         // Empty out any accumuluated replies
         if (replies != null)
         {
             while (!(replies.Count == 0))
             {
                 System.Object temp_object;
                 temp_object = replies[0];
                 replies.RemoveAt(0);
                 System.Object generatedAux = temp_object;
             }
         }
     }
     catch (System.Exception ex)
     {
         // nothing
     }
     // Let GC clean up this stuff, leave name in case finalized is called
     conn = null;
     msg = null;
     // agent = null;  // leave this reference
     queue = null;
     //replies = null; //leave this since we use it as a semaphore
     bindprops = null;
     return ;
 }
Esempio n. 3
0
		//*************************************************************************
		// helper methods
		//*************************************************************************
		
		/// <summary> Locates the appropriate message agent and sends
		/// the Ldap request to a directory server.
		/// 
		/// </summary>
		/// <param name="msg">the message to send
		/// 
		/// </param>
		/// <param name="timeout">the timeout value
		/// 
		/// </param>
		/// <param name="queue">the response queue or null
		/// 
		/// </param>
		/// <returns> the LdapResponseQueue for this request
		/// 
		/// </returns>
		/// <exception> LdapException A general exception which includes an error
		/// message and an Ldap error code.
		/// </exception>
		private LdapResponseQueue SendRequestToServer(LdapMessage msg, int timeout, LdapResponseQueue queue, BindProperties bindProps)
		{
			MessageAgent agent;
			if (queue == null)
			{
				agent = new MessageAgent();
				queue = new LdapResponseQueue(agent);
			}
			else
			{
				agent = queue.MessageAgent;
			}
			
			agent.sendMessage(conn, msg, timeout, queue, bindProps);
			return queue;
		}
Esempio n. 4
0
		public virtual LdapResponseQueue Bind(int version, System.String dn, sbyte[] passwd, LdapResponseQueue queue, LdapConstraints cons, string mech)
		{
			int msgId;
			BindProperties bindProps;
			if (cons == null)
				cons = defSearchCons;
			
			if ((System.Object) dn == null)
			{
				dn = "";
			}
			else
			{
				dn = dn.Trim();
			}
			
			if (passwd == null)
				passwd = new sbyte[]{};
			
			bool anonymous = false;
			if (passwd.Length == 0)
			{
				anonymous = true; // anonymous, passwd length zero with simple bind
				dn = ""; // set to null if anonymous
			}

			LdapMessage msg;
#if TARGET_JVM
			if (mech != null)
				msg = new LdapBindRequest(version, "", mech, passwd, cons.getControls());
			else
#endif
				msg = new LdapBindRequest(version, dn, passwd, cons.getControls());
			
			msgId = msg.MessageID;
			bindProps = new BindProperties(version, dn, "simple", anonymous, null, null);
			
			// For bind requests, if not connected, attempt to reconnect
			if (!conn.Connected)
			{
				if ((System.Object) conn.Host != null)
				{
					conn.connect(conn.Host, conn.Port);
				}
				else
				{
					throw new LdapException(ExceptionMessages.CONNECTION_IMPOSSIBLE, LdapException.CONNECT_ERROR, null);
				}
			}
			
#if TARGET_JVM
			// stopping reader to enable stream replace after secure binding is complete, see Connection.ReplaceStreams()
			if (mech != null)
			{
				if (conn.BindSemIdClear) {
					// need to acquire a semaphore only if bindSemId is clear
					// because if we receive SASL_BIND_IN_PROGRESS the semaphore is not
					// released when the response is queued
					conn.acquireWriteSemaphore(msgId);
					conn.BindSemId = msgId;
				}
				conn.stopReaderOnReply(msgId);
			}
			else
#endif
			// The semaphore is released when the bind response is queued.
			conn.acquireWriteSemaphore(msgId);
			
			return SendRequestToServer(msg, cons.TimeLimit, queue, bindProps);
		}
		/// <summary> Cleans up resources associated with this connection.
		/// This method may be called by finalize() for the connection, or it may
		/// be called by LdapConnection.disconnect().
		/// Should not have a writeSemaphore lock in place, as deadlock can occur
		/// while abandoning connections.
		/// </summary>
		private void  shutdown(System.String reason, int semaphoreId, InterThreadException notifyUser)
		{
			Message info = null;
			if (!clientActive)
			{
				return ;
			}
			clientActive = false;
			while (true)
			{
				// remove messages from connection list and send abandon
				try
				{
					System.Object temp_object;
					temp_object = messages[0];
					messages.RemoveAt(0);
					info = (Message) temp_object;
				}
				catch (ArgumentOutOfRangeException ex)
				{
					// No more messages
					break;
				}
				info.Abandon(null, notifyUser); // also notifies the application
			}
			
			int semId = acquireWriteSemaphore(semaphoreId);
			// Now send unbind if socket not closed
			if ((bindProperties != null) && (out_Renamed != null) && (!bindProperties.Anonymous))
			{
				try
				{
					LdapMessage msg = new LdapUnbindRequest(null);
					sbyte[] ber = msg.Asn1Object.getEncoding(encoder);
					out_Renamed.Write(SupportClass.ToByteArray(ber), 0, ber.Length);
					out_Renamed.Flush();

				}
				catch (System.Exception ex)
				{
					; // don't worry about error
				}
			}
			bindProperties = null;
			
			in_Renamed = null;
			out_Renamed = null;
			if (socket != null)
			{
				// Close the socket
				try
				{
					if(Ssl)
					{
						sock.Shutdown(SocketShutdown.Both);
						sock.Close();
					}
					else
						socket.Close();
				}
				catch (System.IO.IOException ie)
				{
					// ignore problem closing socket
				}
				socket = null;
				sock = null;
			}
			freeWriteSemaphore(semId);
			return ;
		}
Esempio n. 6
0
 /// <summary> Send a request to the server.  A Message class is created
 /// for the specified request which causes the message to be sent.
 /// The request is added to the list of messages being managed by
 /// this agent.
 /// 
 /// </summary>
 /// <param name="conn">the connection that identifies the server.
 /// 
 /// </param>
 /// <param name="msg">the LdapMessage to send
 /// 
 /// </param>
 /// <param name="timeOut">the interval to wait for the message to complete or
 /// <code>null</code> if infinite.
 /// </param>
 /// <param name="queue">the LdapMessageQueue associated with this request.
 /// </param>
 /* package */
 internal void sendMessage(Connection conn, LdapMessage msg, int timeOut, LdapMessageQueue queue, BindProperties bindProps)
 {
     // creating a messageInfo causes the message to be sent
     // and a timer to be started if needed.
     Message message = new Message(msg, timeOut, conn, this, queue, bindProps);
     messages.Add(message);
     message.sendMessage(); // Now send message to server
     return ;
 }
Esempio n. 7
0
        public virtual LdapResponseQueue Bind(int version, System.String dn, sbyte[] passwd, LdapResponseQueue queue, LdapConstraints cons)
        {
            int msgId;
            BindProperties bindProps;
            if (cons == null)
                cons = defSearchCons;

            if ((System.Object) dn == null)
            {
                dn = "";
            }
            else
            {
                dn = dn.Trim();
            }

            if (passwd == null)
                passwd = new sbyte[]{};

            bool anonymous = false;
            if (passwd.Length == 0)
            {
                anonymous = true; // anonymous, passwd length zero with simple bind
                dn = ""; // set to null if anonymous
            }

            LdapMessage msg = new LdapBindRequest(version, dn, passwd, cons.getControls());

            msgId = msg.MessageID;
            bindProps = new BindProperties(version, dn, "simple", anonymous, null, null);

            // For bind requests, if not connected, attempt to reconnect
            if (!conn.Connected)
            {
                if ((System.Object) conn.Host != null)
                {
                    conn.connect(conn.Host, conn.Port);
                }
                else
                {
                    throw new LdapException(ExceptionMessages.CONNECTION_IMPOSSIBLE, LdapException.CONNECT_ERROR, null);
                }
            }

            // The semaphore is released when the bind response is queued.
            conn.acquireWriteSemaphore(msgId);

            return SendRequestToServer(msg, cons.TimeLimit, queue, bindProps);
        }