sbind.c revision 1
1N/A#
pragma ident "%Z%%M% %I% %E% SMI" 1N/A * The contents of this file are subject to the Netscape Public 1N/A * License Version 1.1 (the "License"); you may not use this file 1N/A * except in compliance with the License. You may obtain a copy of 1N/A * Software distributed under the License is distributed on an "AS 1N/A * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 1N/A * implied. See the License for the specific language governing 1N/A * rights and limitations under the License. 1N/A * The Original Code is Mozilla Communicator client code, released 1N/A * The Initial Developer of the Original Code is Netscape 1N/A * Communications Corporation. Portions created by Netscape are 1N/A * Copyright (C) 1998-1999 Netscape Communications Corporation. All 1N/A * Copyright (c) 1993 Regents of the University of Michigan. 1N/A * All rights reserved. 1N/Astatic char copyright[] =
"@(#) Copyright (c) 1993 Regents of the University of Michigan.\nAll rights reserved.\n";
1N/A * ldap_simple_bind - bind to the ldap server. The dn and 1N/A * password of the entry to which to bind are supplied. The message id 1N/A * of the request initiated is returned. 1N/A * ldap_simple_bind( ld, "cn=manager, o=university of michigan, c=us", 1N/A * The bind request looks like this: 1N/A * BindRequest ::= SEQUENCE { 1N/A * name DistinguishedName, -- who 1N/A * authentication CHOICE { 1N/A * simple [0] OCTET STRING -- passwd 1N/A * all wrapped up in an LDAPMessage sequence. 1N/A /* if ( unlock_permitted ) LDAP_MUTEX_UNLOCK( ld ); */ 1N/A /* if ( unlock_permitted ) LDAP_MUTEX_LOCK( ld ); */ 1N/A /* create a message to send */ 1N/A /* send the message */ 1N/A * ldap_simple_bind - bind to the ldap server using simple 1N/A * authentication. The dn and password of the entry to which to bind are 1N/A * supplied. LDAP_SUCCESS is returned upon success, the ldap error code 1N/A * ldap_simple_bind_s( ld, "cn=manager, o=university of michigan, c=us", 1N/A * simple_bindifnot_s() is like ldap_simple_bind_s() except that it only does 1N/A * a bind if the default connection is not currently bound. 1N/A * If a successful bind using the same DN has already taken place we just 1N/A * return LDAP_SUCCESS without conversing with the server at all. 1N/A dn =
"";
/* to make comparisons simpler */ 1N/A * if we are already bound using the same DN, just return LDAP_SUCCESS. 1N/A * if the default connection has been lost and is now marked dead, 1N/A * dispose of the default connection so it will get re-established. 1N/A * if not, clear the bind DN and status to ensure that we don't 1N/A * report the wrong bind DN to a different thread while waiting 1N/A * for our bind result to return from the server. 1N/A * finally, bind (this will open a new connection if necessary) 1N/A * do everything under the protection of the result lock to 1N/A * ensure that only one thread will be in this code at a time. 1N/A * XXXmcs: we should use a condition variable instead? 1N/A * Note that at this point the bind request is on its way to the 1N/A * server and at any time now we will either be bound as the new 1N/A * DN (if the bind succeeded) or we will be bound as anonymous (if 1N/A * Wait for the bind result. Code inside result.c:read1msg() 1N/A * takes care of setting the connection's bind DN and status.