/*
* Portions Copyright 1998 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* Copyright (c) 1990, 1994 Regents of the University of Michigan.
* All rights reserved.
*
* cldap.c - synchronous, retrying interface to the cldap protocol
*/
#ifdef CLDAP
#ifndef lint
static char copyright[] = "@(#) Copyright (c) 1990, 1994 Regents of the University of Michigan.\nAll rights reserved.\n";
#endif
#include <stdio.h>
#include <string.h>
#include <errno.h>
#ifdef MACOS
#include <stdlib.h>
#include "macos.h"
#else /* MACOS */
#ifdef DOS
#include "msdos.h"
#else /* DOS */
#include <netdb.h>
#endif /* DOS */
#endif /* MACOS */
#ifdef SUN
#include <nss_dbdefs.h>
#endif
#include "lber.h"
#include "ldap.h"
#include "ldap-private.h"
#include "ldap-int.h"
#ifndef INADDR_LOOPBACK
#endif
struct cldap_retinfo {
int cri_maxtries;
int cri_try;
int cri_useaddr;
};
#ifdef NEEDPROTOS
#else /* NEEDPROTOS */
static int add_addr();
static int cldap_result();
static int cldap_parsemsg();
#endif /* NEEDPROTOS */
/*
* cldap_open - initialize and connect to an ldap server. A magic cookie to
* be used for future communication is returned on success, NULL on failure.
*
* Example:
* LDAP *ld;
* ld = cldap_open( hostname, port );
*/
LDAP *
{
int s;
char *p;
int i;
#ifdef SUN
int hperrno;
#endif
int close(int);
if ( port == 0 ) {
}
return( NULL );
}
close( s );
return( NULL );
}
close( s );
return( NULL );
}
close( s );
return( NULL );
}
/*
* 'host' may be a space-separated list.
*/
for (*p++ = '\0'; *p == ' '; p++) {
;
}
}
#ifdef SUN
continue;
}
#else
continue;
}
#endif
for ( i = 0; hp->h_addr_list[ i ] != 0; ++i ) {
(char *)hp->h_addr_list[ i ],
close( s );
return( NULL );
}
}
} else {
close( s );
return( NULL );
}
}
}
}
} else {
close( s );
return( NULL );
}
}
#ifdef LDAP_REFERRALS
#endif /* LDAP_REFERRALS */
) {
return( NULL );
}
cldap_setretryinfo( ld, 0, 0 );
#ifdef LDAP_DEBUG
putchar( '\n' );
i, inet_ntoa( ((struct sockaddr_in *)
}
#endif
return( ld );
}
void
{
ldap_ld_free( ld, 0 );
}
void
{
#if defined( SUN ) && defined( _REENTRANT )
#endif
#if defined( SUN ) && defined( _REENTRANT )
#endif
}
int
{
#if defined( SUN ) && defined( _REENTRANT )
#endif
}
do {
}
attrsonly )) == -1 ) {
#if defined( SUN ) && defined( _REENTRANT )
#endif
}
#ifndef NO_CACHE
#if defined( SUN ) && defined( _REENTRANT )
#endif
0, 0, 0 );
#if defined( SUN ) && defined( _REENTRANT )
return( ret );
#else
#endif
}
#endif /* NO_CACHE */
#if defined( SUN ) && defined( _REENTRANT )
#endif
} while (ret == -1);
return( ret );
}
static int
{
== NULL ) {
return( -1 );
}
} else {
}
return( -1 );
}
return( 0 );
}
static int
{
char *logdn;
#if defined( SUN ) && defined( _REENTRANT )
#endif
fromaddr = -1;
crip->cri_useaddr = 0;
}
}
ber_zero_init( &ber, 0 );
ret, 0, 0 );
/*
* It timed out; is it time to give up?
*/
ret = LDAP_TIMEOUT;
} else {
/*
* new round: reset address to first one and
* double the timeout
*/
crip->cri_useaddr = 0;
}
ret = -1;
}
} else {
/*
* Got a response. It should look like:
* { msgid, logdn, { searchresponse...}}
*/
ret, 0, 0 );
} else {
/*
* got a result: determine which server it came from
* decode into ldap message chain
*/
if ( memcmp( &((struct sockaddr_in *)
sizeof( struct in_addr )) == 0 ) {
break;
}
}
}
}
}
/*
* If we are giving up (successfully or otherwise) then
* abandon any outstanding requests.
*/
if ( ret != -1 ) {
}
for ( ; i >= 0; --i ) {
if ( i == fromaddr ) {
continue;
}
}
}
#if defined( SUN ) && defined( _REENTRANT )
#endif
}
static int
{
int rc;
== NULLBER ) {
rc = LDAP_NO_MEMORY;
}
if ( tag == LDAP_RES_SEARCH_RESULT ) {
0, 0, 0 );
}
}
ber_bvfree( bv );
rc = LDAP_SUCCESS;
} else if ( tag == LDAP_RES_SEARCH_ENTRY ) {
}
baselen > 0 ) {
/*
* substitute original searchbase for trailing '*'
*/
rc = LDAP_NO_MEMORY;
}
dn = p;
}
}
ber_bvfree( bv );
} else {
tag, 0, 0 );
}
/* Reset message ber so we can read from it later. Gack! */
#ifdef LDAP_DEBUG
if ( ldap_debug & LDAP_DEBUG_PACKETS ) {
}
#endif /* LDAP_DEBUG */
#ifndef NO_CACHE
}
#endif /* NO_CACHE */
} else {
}
}
/* dispose of any leftovers */
}
}
ber_bvfree( bv );
}
/* return chain, calling result2error if we got anything at all */
}
#endif /* CLDAP */