1N/A#pragma ident "%Z%%M% %I% %E% SMI"
1N/A
1N/A/*
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 * the License at http://www.mozilla.org/NPL/
1N/A *
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 *
1N/A * The Original Code is Mozilla Communicator client code, released
1N/A * March 31, 1998.
1N/A *
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 * Rights Reserved.
1N/A *
1N/A * Contributor(s):
1N/A */
1N/A/*
1N/A * bind.c
1N/A */
1N/A
1N/A#if 0
1N/A#ifndef lint
1N/Astatic char copyright[] = "@(#) Copyright (c) 1990 Regents of the University of Michigan.\nAll rights reserved.\n";
1N/A#endif
1N/A#endif
1N/A
1N/A#include "ldap-int.h"
1N/A
1N/A/*
1N/A * ldap_bind - bind to the ldap server. The dn and password
1N/A * of the entry to which to bind are supplied, along with the authentication
1N/A * method to use. The msgid of the bind request is returned on success,
1N/A * -1 if there's trouble. Note, the kerberos support assumes the user already
1N/A * has a valid tgt for now. ldap_result() should be called to find out the
1N/A * outcome of the bind request.
1N/A *
1N/A * Example:
1N/A * ldap_bind( ld, "cn=manager, o=university of michigan, c=us", "secret",
1N/A * LDAP_AUTH_SIMPLE )
1N/A */
1N/A
1N/Aint
1N/ALDAP_CALL
1N/Aldap_bind( LDAP *ld, const char *dn, const char *passwd, int authmethod )
1N/A{
1N/A /*
1N/A * The bind request looks like this:
1N/A * BindRequest ::= SEQUENCE {
1N/A * version INTEGER,
1N/A * name DistinguishedName, -- who
1N/A * authentication CHOICE {
1N/A * simple [0] OCTET STRING -- passwd
1N/A * }
1N/A * }
1N/A * all wrapped up in an LDAPMessage sequence.
1N/A */
1N/A
1N/A LDAPDebug( LDAP_DEBUG_TRACE, "ldap_bind\n", 0, 0, 0 );
1N/A
1N/A if ( !NSLDAPI_VALID_LDAP_POINTER( ld )) {
1N/A return( -1 );
1N/A }
1N/A
1N/A switch ( authmethod ) {
1N/A case LDAP_AUTH_SIMPLE:
1N/A return( ldap_simple_bind( ld, dn, passwd ) );
1N/A
1N/A default:
1N/A LDAP_SET_LDERRNO( ld, LDAP_AUTH_UNKNOWN, NULL, NULL );
1N/A return( -1 );
1N/A }
1N/A}
1N/A
1N/A/*
1N/A * ldap_bind_s - bind to the ldap server. The dn and password
1N/A * of the entry to which to bind are supplied, along with the authentication
1N/A * method to use. This routine just calls whichever bind routine is
1N/A * appropriate and returns the result of the bind (e.g. LDAP_SUCCESS or
1N/A * some other error indication). Note, the kerberos support assumes the
1N/A * user already has a valid tgt for now.
1N/A *
1N/A * Examples:
1N/A * ldap_bind_s( ld, "cn=manager, o=university of michigan, c=us",
1N/A * "secret", LDAP_AUTH_SIMPLE )
1N/A * ldap_bind_s( ld, "cn=manager, o=university of michigan, c=us",
1N/A * NULL, LDAP_AUTH_KRBV4 )
1N/A */
1N/Aint
1N/ALDAP_CALL
1N/Aldap_bind_s( LDAP *ld, const char *dn, const char *passwd, int authmethod )
1N/A{
1N/A int err;
1N/A
1N/A LDAPDebug( LDAP_DEBUG_TRACE, "ldap_bind_s\n", 0, 0, 0 );
1N/A
1N/A switch ( authmethod ) {
1N/A case LDAP_AUTH_SIMPLE:
1N/A return( ldap_simple_bind_s( ld, dn, passwd ) );
1N/A
1N/A default:
1N/A err = LDAP_AUTH_UNKNOWN;
1N/A LDAP_SET_LDERRNO( ld, err, NULL, NULL );
1N/A return( err );
1N/A }
1N/A}
1N/A
1N/A
1N/Avoid
1N/ALDAP_CALL
1N/Aldap_set_rebind_proc( LDAP *ld, LDAP_REBINDPROC_CALLBACK *rebindproc,
1N/A void *arg )
1N/A{
1N/A if ( ld == NULL ) {
1N/A if ( !nsldapi_initialized ) {
1N/A nsldapi_initialize_defaults();
1N/A }
1N/A ld = &nsldapi_ld_defaults;
1N/A }
1N/A
1N/A if ( NSLDAPI_VALID_LDAP_POINTER( ld )) {
1N/A LDAP_MUTEX_LOCK( ld, LDAP_OPTION_LOCK );
1N/A ld->ld_rebind_fn = rebindproc;
1N/A ld->ld_rebind_arg = arg;
1N/A LDAP_MUTEX_UNLOCK( ld, LDAP_OPTION_LOCK );
1N/A }
1N/A}
1N/A
1N/A
1N/A/*
1N/A * return a pointer to the bind DN for the default connection (a copy is
1N/A * not made). If there is no bind DN available, NULL is returned.
1N/A */
1N/Achar *
1N/Ansldapi_get_binddn( LDAP *ld )
1N/A{
1N/A char *binddn;
1N/A
1N/A binddn = NULL; /* default -- assume they are not bound */
1N/A
1N/A LDAP_MUTEX_LOCK( ld, LDAP_CONN_LOCK );
1N/A if ( NULL != ld->ld_defconn && LDAP_CONNST_CONNECTED ==
1N/A ld->ld_defconn->lconn_status && ld->ld_defconn->lconn_bound ) {
1N/A if (( binddn = ld->ld_defconn->lconn_binddn ) == NULL ) {
1N/A binddn = "";
1N/A }
1N/A }
1N/A LDAP_MUTEX_UNLOCK( ld, LDAP_CONN_LOCK );
1N/A
1N/A return( binddn );
1N/A}