/*
*/
/*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
/*
* Copyright (c) 1995 Regents of the University of Michigan.
* All rights reserved.
*/
/*
* open.c
*/
#if 0
#ifndef lint
static char copyright[] = "@(#) Copyright (c) 1995 Regents of the University of Michigan.\nAll rights reserved.\n";
#endif
#endif
#include "ldap-int.h"
#ifdef LDAP_SASLIO_HOOKS
/* Valid for any ANSI C compiler */
#include <limits.h>
#endif
#ifndef INADDR_LOOPBACK
#endif
#ifndef MAXHOSTNAMELEN
#endif
#ifdef LDAP_DEBUG
int ldap_debug;
#endif
/*
* global defaults for callbacks are stored here. callers of the API set
* these by passing a NULL "ld" to ldap_set_option(). Everything in
* nsldapi_ld_defaults can be overridden on a per-ld basis as well (the
* memory allocation functions are global to all ld's).
*/
int nsldapi_initialized = 0;
#ifndef _WINDOWS
#include <pthread.h>
struct nsldapi_ldap_error {
int le_errno;
char *le_matched;
char *le_errmsg;
};
#else
#endif /* _WINDOWS */
#ifdef _WINDOWS
int
{
return( 1 );
else
return( 0 );
}
static void *
pthread_mutex_alloc( void )
{
}
return( mutexp );
}
int
{
if ( !(CloseHandle(*mp)) )
return( 1 );
else
return( 0 );
}
static void
{
}
int
{
return( 1 );
else
return( 0 );
}
int
{
if ( !(ReleaseMutex(*mp)) )
return( 1 );
else
return( 0 );
}
static int
get_errno( void )
{
return errno;
}
static void
{
}
static int
{
{
}
{
}
return nsldapi_gldaperrno;
}
static void
void * Args )
{
/* Clean up any previous string storage. */
if ( nsldapi_gmatched != NULL )
{
}
if ( nsldapi_gldaperror != NULL )
{
}
}
#else
static void *
pthread_mutex_alloc( void )
{
}
return( mutexp );
}
static void
{
}
static void
{
void *tsd;
}
return;
}
}
}
}
static int
{
}
}
} else {
}
return (LDAP_SUCCESS);
}
static void
{
}
static int
get_errno( void )
{
return( errno );
}
#endif /* _WINDOWS */
static struct ldap_thread_fns
(void *(*)(void))pthread_mutex_alloc,
(void (*)(void *))pthread_mutex_free,
(int (*)(void *))pthread_mutex_lock,
(int (*)(void *))pthread_mutex_unlock,
(int (*)(void))get_errno,
(void (*)(int))set_errno,
(int (*)(char **, char **, void *))get_ld_error,
(void (*)(int, char *, char *, void *))set_ld_error,
0 };
static struct ldap_extra_thread_fns
0, 0, 0, 0, 0,
#ifdef _WINDOWS
0
#else
(void *(*)(void))pthread_self
#endif /* _WINDOWS */
};
void
nsldapi_initialize_defaults( void )
{
if ( nsldapi_initialized ) {
return;
}
#ifdef _SOLARIS_SDK
/*
* This has to be called before nsldapi_initialized is set to 1
* because nsldapi_initialized does not have mutex protection
*/
#endif
#ifndef _WINDOWS
perror("pthread_key_create");
}
#endif /* _WINDOWS */
nsldapi_initialized = 1;
#ifdef LDAP_SASLIO_HOOKS
/* SASL default option settings */
/* SASL Security properties */
#endif
#if defined( STR_TRANSLATION ) && defined( LDAP_DEFAULT_CHARSET )
#endif /* LDAP_CHARSET_8859 == LDAP_DEFAULT_CHARSET */
#endif /* STR_TRANSLATION && LDAP_DEFAULT_CHARSET */
/* set default connect timeout (in milliseconds) */
/* this was picked as it is the standard tcp timeout as well */
/* load up default platform specific locking routines */
(void *)&nsldapi_default_thread_fns) != LDAP_SUCCESS) {
return;
}
#ifndef _WINDOWS
/* load up default threadid function */
(void *)&nsldapi_default_extra_thread_fns) != LDAP_SUCCESS) {
return;
}
#endif /* _WINDOWS */
}
/*
* ldap_version - report version levels for important properties
* This function is deprecated. Use ldap_get_option( ..., LDAP_OPT_API_INFO,
* ... ) instead.
*
* Example:
* LDAPVersion ver;
* ldap_version( &ver );
* if ( (ver.sdk_version < 100) || (ver.SSL_version < 300) )
* fprintf( stderr, "LDAP SDK level insufficient\n" );
*
* or:
* if ( ldap_version(NULL) < 100 )
* fprintf( stderr, "LDAP SDK level insufficient\n" );
*
*/
int
{
{
/*
* set security to none by default
*/
#if defined(LINK_SSL)
#if defined(NS_DOMESTIC)
#elif defined(NSS_EXPORT)
#endif
#endif
}
return (int)(VI_PRODUCTVERSION * 100);
}
/*
* ldap_open - initialize and connect to an ldap server. A magic cookie to
* be used for future communication is returned on success, NULL on failure.
* "host" may be a space-separated list of hosts or IP addresses
*
* Example:
* LDAP *ld;
* ld = ldap_open( hostname, port );
*/
LDAP *
{
return( NULL );
}
if ( nsldapi_open_ldap_defconn( ld ) < 0 ) {
return( NULL );
}
return( ld );
}
/*
* ldap_init - initialize the LDAP library. A magic cookie to be used for
* future communication is returned on success, NULL on failure.
* "defhost" may be a space-separated list of hosts or IP addresses
*
* Example:
* LDAP *ld;
* ld = ldap_init( default_hostname, default_port );
*/
LDAP *
{
if ( !nsldapi_initialized ) {
}
"ldap_init: port %d is invalid (port numbers must range from 1 to %d)\n",
defport, LDAP_PORT_MAX, 0 );
#endif
return( NULL );
}
return( NULL );
}
/* copy defaults */
sizeof( struct ldap_io_fns ))) == NULL ) {
NSLDAPI_FREE( (char *)ld );
return( NULL );
}
/* struct copy */
}
/* call the new handle I/O callback if one is defined */
/*
* We always pass the session extended I/O argument to
* the new handle callback.
*/
!= LDAP_SUCCESS ) {
NSLDAPI_FREE( (char*)ld );
return( NULL );
}
}
/* allocate session-specific resources */
}
}
NSLDAPI_FREE( (char*)ld );
return( NULL );
}
/* install Sockbuf I/O functions if set in LDAP * */
(void *)&lberiofns );
}
#ifdef _SOLARIS_SDK
/* Install the functions for IPv6 support */
/* code sequencing is critical from here to nsldapi_mutex_alloc_all */
prldap_install_dns_functions( ld ) != 0 ) {
}
}
NSLDAPI_FREE((char *)ld);
return( NULL );
}
#else
/* allocate mutexes */
#endif
/* set default port */
return( ld );
}
/* Returns 0 if no error in allocating mutex, -1 otherwise. */
int
{
int i;
for ( i = 0; i<LDAP_MAX_LOCK; i++ ) {
return (-1);
}
ld->ld_mutex_refcnt[i] = 0;
}
}
return (0);
}
void
{
int i;
for ( i = 0; i<LDAP_MAX_LOCK; i++ ) {
}
}
}
/* returns 0 if connection opened and -1 if an error occurs */
int
{
return( -1 );
}
#ifdef LDAP_SSLIO_HOOKS
}
#endif
== NULL ) {
}
NSLDAPI_FREE( (char *)srv );
return( -1 );
}
return( 0 );
}
struct ldap_x_hostlist_status {
char *lhs_hostlist;
char *lhs_nexthost;
int lhs_defport;
};
/*
* Return the first host and port in hostlist (setting *hostp and *portp).
* Return value is an LDAP API error code (LDAP_SUCCESS if all goes well).
* Note that a NULL or zero-length hostlist causes the host "127.0.0.1" to
* be returned.
*/
int LDAP_CALL
{
return( LDAP_PARAM_ERROR );
}
return( LDAP_NO_MEMORY );
}
return( LDAP_SUCCESS );
}
return( LDAP_NO_MEMORY );
}
return( LDAP_NO_MEMORY );
}
}
/*
* Return the next host and port in hostlist (setting *hostp and *portp).
* Return value is an LDAP API error code (LDAP_SUCCESS if all goes well).
* If no more hosts are available, LDAP_SUCCESS is returned but *hostp is set
* to NULL.
*/
int LDAP_CALL
struct ldap_x_hostlist_status *status )
{
char *q;
int squarebrackets = 0;
return( LDAP_PARAM_ERROR );
}
return( LDAP_SUCCESS );
}
/*
* skip past leading '[' if present (IPv6 addresses may be surrounded
* with square brackets, e.g., [fe80::a00:20ff:fee5:c0b4]:389
*/
++status->lhs_nexthost;
squarebrackets = 1;
}
/* copy host into *hostp */
return( LDAP_NO_MEMORY );
}
} else { /* last host */
return( LDAP_NO_MEMORY );
}
}
/*
* Look for closing ']' and skip past it before looking for port.
*/
*q++ = '\0';
} else {
q = *hostp;
}
/* determine and set port */
*q++ = '\0';
} else {
}
return( LDAP_SUCCESS );
}
void LDAP_CALL
{
}
NSLDAPI_FREE( status );
}
}
/*
* memory allocation functions. we include these in open.c since every
* LDAP application is likely to pull the rest of the code in this file
* in anyways.
*/
void *
{
}
void *
{
}
void *
{
}
void
{
} else {
}
}
/* if s is NULL, returns NULL */
char *
nsldapi_strdup( const char *s )
{
char *p;
if ( s == NULL ||
return( NULL );
strcpy( p, s );
return( p );
}