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); }
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); }