openldap/libraries/libldap/references.c

141 lines
2.4 KiB
C
Raw Normal View History

/* $OpenLDAP$ */
1998-12-29 04:53:15 +08:00
/*
2003-01-04 04:20:47 +08:00
* Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
1998-12-29 04:53:15 +08:00
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
/*
* references.c
*/
#include "portable.h"
#include <stdio.h>
1999-06-03 08:37:44 +08:00
#include <ac/stdlib.h>
#include <ac/socket.h>
#include <ac/string.h>
#include <ac/time.h>
#include "ldap-int.h"
LDAPMessage *
ldap_first_reference( LDAP *ld, LDAPMessage *chain )
{
assert( ld != NULL );
1999-06-22 06:38:00 +08:00
assert( LDAP_VALID( ld ) );
assert( chain != NULL );
return chain->lm_msgtype == LDAP_RES_SEARCH_REFERENCE
? chain
: ldap_next_reference( ld, chain );
}
LDAPMessage *
ldap_next_reference( LDAP *ld, LDAPMessage *ref )
{
assert( ld != NULL );
1999-06-22 06:38:00 +08:00
assert( LDAP_VALID( ld ) );
assert( ref != NULL );
for (
ref = ref->lm_chain;
ref != NULL;
ref = ref->lm_chain )
{
if( ref->lm_msgtype == LDAP_RES_SEARCH_REFERENCE ) {
return( ref );
}
}
return( NULL );
}
int
ldap_count_references( LDAP *ld, LDAPMessage *chain )
{
int i;
assert( ld != NULL );
1999-06-22 06:38:00 +08:00
assert( LDAP_VALID( ld ) );
for ( i = 0; chain != NULL; chain = chain->lm_chain ) {
if( chain->lm_msgtype == LDAP_RES_SEARCH_REFERENCE ) {
i++;
}
}
return( i );
}
int
ldap_parse_reference(
LDAP *ld,
LDAPMessage *ref,
char ***referralsp,
LDAPControl ***serverctrls,
int freeit)
{
BerElement be;
char **refs = NULL;
int rc;
assert( ld != NULL );
1999-06-22 06:38:00 +08:00
assert( LDAP_VALID( ld ) );
assert( ref != NULL );
if( ref->lm_msgtype != LDAP_RES_SEARCH_REFERENCE ) {
return LDAP_PARAM_ERROR;
}
/* make a private copy of BerElement */
AC_MEMCPY(&be, ref->lm_ber, sizeof(be));
if ( ber_scanf( &be, "{v" /*}*/, &refs ) == LBER_ERROR ) {
rc = LDAP_DECODING_ERROR;
goto free_and_return;
}
if ( serverctrls == NULL ) {
rc = LDAP_SUCCESS;
goto free_and_return;
}
if ( ber_scanf( &be, /*{*/ "}" ) == LBER_ERROR ) {
rc = LDAP_DECODING_ERROR;
goto free_and_return;
}
Vienna Bulk Commit This commit includes many changes. All changes compile under NT but have not been tested under UNIX. A Summary of changes (likely incomplete): NT changes: Removed lint. Clean up configuration support for "Debug", "Release", "SDebug", and "SRelease" configurations. Share output directories for clients, libraries, and slapd. (maybe they should be combined further and moved to build/{,S}{Debug,Release}). Enable threading when _MT is defined. Enable debuging when _DEBUG is defined. Disable setting of NDEBUG under Release/SRelease. Asserts are disabled in <ac/assert.h> when LDAP_DEBUG is not defined. Added 'build/main.dsp' Master project. Removed non-slapd projects from slapd.dsp (see main.dsp). Removed replaced many uses of _WIN32 macro with feature based macros. ldap_cdefs.h changes #define LDAP_CONST const (see below) #define LDAP_F(type) LDAP_F_PRE type LDAP_F_POST To allow specifiers to be added before and after the type declaration. (For DLL handling) LBER/LDAP changes Namespace changes: s/lber_/ber_/ for here and there. s/NAME_ERROR/LDAP_NAME_ERROR/g Deleted NULLMSG and other NULL* macros for namespace reasons. "const" libraries. Installed headers (ie: lber.h, ldap.h) use LDAP_CONST macro. Normally set to 'const' when __STDC__. Can be set externally to enable/disable 'constification' of external interface. Internal interface always uses 'const'. Did not fix warnings in -lldif (in lieu of new LDIF parser). Added _ext API implementations (excepting search and bind). Need to implement ldap_int_get_controls() for reponses with controls. Added numberous assert() checks. LDAP_R _MT defines HAVE_NT_THREADS Added numberous assert() checks. Changed ldap_pthread_t back to unsigned long. Used cast to HANDLE in _join(). LDBM Replaced _WIN32 with HAVE_SYSLOG ud Added version string if MKVERSION is not defined. (MKVERSION needs to be set under UNIX). slapd Made connection sockbuf field a pointer to a sockbuf. This removed slap.h dependency on lber-int.h. lber-int.h now only included by those files needing to mess with the sockbuf. Used ber_* functions/macros to access sockbuf internals whenever possible. Added version string if MKVERSION is not defined. (MKVERSION needs to be set under UNIX). Removed FD_SET unsigned lint slapd/tools Used EXEEXT to added ".exe" to routines. Need to define EXEEXT under UNIX. ldappasswd Added ldappasswd.dsp. Ported to NT. Used getpid() to seed rand(). nt_debug Minor cleanup. Added "portable.h" include and used <ac/*.h> where appropriate. Added const to char* format argument.
1999-05-19 09:12:33 +08:00
rc = ldap_int_get_controls( &be, serverctrls );
free_and_return:
if( referralsp != NULL ) {
/* provide references regradless of return code */
*referralsp = refs;
} else {
LDAP_VFREE( refs );
}
if( freeit ) {
ldap_msgfree( ref );
}
if( rc != LDAP_SUCCESS ) {
ld->ld_errno = rc;
if( ld->ld_matched != NULL ) {
LDAP_FREE( ld->ld_matched );
ld->ld_matched = NULL;
}
if( ld->ld_error != NULL ) {
LDAP_FREE( ld->ld_error );
ld->ld_error = NULL;
}
}
return rc;
}