X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=clients%2Ftools%2Fldapsearch.c;h=e365d7eff047c4491ab5b2ef8b09042fbea58503;hb=3bf87500a3a417d912ced6260464e709293098e5;hp=068acb3e1b5e30485409e7ef5dffaef49fd518a9;hpb=02cff39398a62956aa3a86b834fb317415ccc601;p=openldap
diff --git a/clients/tools/ldapsearch.c b/clients/tools/ldapsearch.c
index 068acb3e1b..e365d7eff0 100644
--- a/clients/tools/ldapsearch.c
+++ b/clients/tools/ldapsearch.c
@@ -2,7 +2,7 @@
/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software .
*
- * Copyright 1998-2011 The OpenLDAP Foundation.
+ * Copyright 1998-2012 The OpenLDAP Foundation.
* Portions Copyright 1998-2003 Kurt D. Zeilenga.
* Portions Copyright 1998-2001 Net Boolean Incorporated.
* Portions Copyright 2001-2003 IBM Corporation.
@@ -41,11 +41,12 @@
#include
#include
-
#include
#include
#include
#include
+#include
+
#include
#include
@@ -777,7 +778,7 @@ private_conn_setup( LDAP *ld )
!= LDAP_OPT_SUCCESS )
{
fprintf( stderr, _("Could not set LDAP_OPT_DEREF %d\n"), deref );
- exit( EXIT_FAILURE );
+ tool_exit( ld, EXIT_FAILURE );
}
}
@@ -908,7 +909,7 @@ getNextPage:
if ( !fp && infile ) {
if (( fp = fopen( infile, "r" )) == NULL ) {
perror( infile );
- return EXIT_FAILURE;
+ tool_exit( ld, EXIT_FAILURE );
}
}
save_nctrls = nctrls;
@@ -932,7 +933,7 @@ getNextPage:
#ifdef LDAP_CONTROL_DONTUSECOPY
if ( dontUseCopy ) {
if ( ctrl_add() ) {
- return EXIT_FAILURE;
+ tool_exit( ld, EXIT_FAILURE );
}
c[i].ldctl_oid = LDAP_CONTROL_DONTUSECOPY;
@@ -945,7 +946,7 @@ getNextPage:
if ( domainScope ) {
if ( ctrl_add() ) {
- return EXIT_FAILURE;
+ tool_exit( ld, EXIT_FAILURE );
}
c[i].ldctl_oid = LDAP_CONTROL_X_DOMAIN_SCOPE;
@@ -957,22 +958,22 @@ getNextPage:
if ( subentries ) {
if ( ctrl_add() ) {
- return EXIT_FAILURE;
+ tool_exit( ld, EXIT_FAILURE );
}
if (( seber = ber_alloc_t(LBER_USE_DER)) == NULL ) {
- return EXIT_FAILURE;
+ tool_exit( ld, EXIT_FAILURE );
}
err = ber_printf( seber, "b", abs(subentries) == 1 ? 0 : 1 );
if ( err == -1 ) {
ber_free( seber, 1 );
fprintf( stderr, _("Subentries control encoding error!\n") );
- return EXIT_FAILURE;
+ tool_exit( ld, EXIT_FAILURE );
}
if ( ber_flatten2( seber, &c[i].ldctl_value, 0 ) == -1 ) {
- return EXIT_FAILURE;
+ tool_exit( ld, EXIT_FAILURE );
}
c[i].ldctl_oid = LDAP_CONTROL_SUBENTRIES;
@@ -982,11 +983,11 @@ getNextPage:
if ( ldapsync ) {
if ( ctrl_add() ) {
- return EXIT_FAILURE;
+ tool_exit( ld, EXIT_FAILURE );
}
if (( syncber = ber_alloc_t(LBER_USE_DER)) == NULL ) {
- return EXIT_FAILURE;
+ tool_exit( ld, EXIT_FAILURE );
}
if ( sync_cookie.bv_len == 0 ) {
@@ -999,11 +1000,11 @@ getNextPage:
if ( err == -1 ) {
ber_free( syncber, 1 );
fprintf( stderr, _("ldap sync control encoding error!\n") );
- return EXIT_FAILURE;
+ tool_exit( ld, EXIT_FAILURE );
}
if ( ber_flatten( syncber, &syncbvalp ) == -1 ) {
- return EXIT_FAILURE;
+ tool_exit( ld, EXIT_FAILURE );
}
c[i].ldctl_oid = LDAP_CONTROL_SYNC;
@@ -1014,21 +1015,21 @@ getNextPage:
if ( valuesReturnFilter ) {
if ( ctrl_add() ) {
- return EXIT_FAILURE;
+ tool_exit( ld, EXIT_FAILURE );
}
if (( vrber = ber_alloc_t(LBER_USE_DER)) == NULL ) {
- return EXIT_FAILURE;
+ tool_exit( ld, EXIT_FAILURE );
}
if ( ( err = ldap_put_vrFilter( vrber, vrFilter ) ) == -1 ) {
ber_free( vrber, 1 );
fprintf( stderr, _("Bad ValuesReturnFilter: %s\n"), vrFilter );
- return EXIT_FAILURE;
+ tool_exit( ld, EXIT_FAILURE );
}
if ( ber_flatten2( vrber, &c[i].ldctl_value, 0 ) == -1 ) {
- return EXIT_FAILURE;
+ tool_exit( ld, EXIT_FAILURE );
}
c[i].ldctl_oid = LDAP_CONTROL_VALUESRETURNFILTER;
@@ -1038,13 +1039,13 @@ getNextPage:
if ( pagedResults ) {
if ( ctrl_add() ) {
- return EXIT_FAILURE;
+ tool_exit( ld, EXIT_FAILURE );
}
if ( ldap_create_page_control_value( ld,
pageSize, &pr_cookie, &c[i].ldctl_value ) )
{
- return EXIT_FAILURE;
+ tool_exit( ld, EXIT_FAILURE );
}
if ( pr_cookie.bv_val != NULL ) {
@@ -1060,13 +1061,13 @@ getNextPage:
if ( sss ) {
if ( ctrl_add() ) {
- return EXIT_FAILURE;
+ tool_exit( ld, EXIT_FAILURE );
}
if ( ldap_create_sort_control_value( ld,
sss_keys, &c[i].ldctl_value ) )
{
- return EXIT_FAILURE;
+ tool_exit( ld, EXIT_FAILURE );
}
c[i].ldctl_oid = LDAP_CONTROL_SORTREQUEST;
@@ -1076,13 +1077,13 @@ getNextPage:
if ( vlv ) {
if ( ctrl_add() ) {
- return EXIT_FAILURE;
+ tool_exit( ld, EXIT_FAILURE );
}
if ( ldap_create_vlv_control_value( ld,
&vlvInfo, &c[i].ldctl_value ) )
{
- return EXIT_FAILURE;
+ tool_exit( ld, EXIT_FAILURE );
}
c[i].ldctl_oid = LDAP_CONTROL_VLVREQUEST;
@@ -1097,7 +1098,7 @@ getNextPage:
assert( ds != NULL );
if ( ldap_create_deref_control_value( ld, ds, &derefval ) != LDAP_SUCCESS ) {
- return EXIT_FAILURE;
+ tool_exit( ld, EXIT_FAILURE );
}
for ( i = 0; ds[ i ].derefAttr != NULL; i++ ) {
@@ -1109,7 +1110,7 @@ getNextPage:
}
if ( ctrl_add() ) {
- exit( EXIT_FAILURE );
+ tool_exit( ld, EXIT_FAILURE );
}
c[ i ].ldctl_iscritical = derefcrit > 1;
@@ -1285,7 +1286,7 @@ getNextPage:
if ( num != 1 ) {
fprintf( stderr,
_("Invalid value for PagedResultsControl, %s.\n"), buf);
- return EXIT_FAILURE;
+ tool_exit( ld, EXIT_FAILURE );
}
pageSize = (ber_int_t)tmpSize;
@@ -1316,7 +1317,7 @@ getNextPage:
if ( buf[0] ) {
i = parse_vlv( strdup( buf ));
if ( i )
- return EXIT_FAILURE;
+ tool_exit( ld, EXIT_FAILURE );
} else {
vlvInfo.ldvlv_attrvalue = NULL;
vlvInfo.ldvlv_count = vlvCount;
@@ -1330,8 +1331,6 @@ getNextPage:
goto getNextPage;
}
- tool_unbind( ld );
- tool_destroy();
if ( base != NULL ) {
ber_memfree( base );
}
@@ -1358,7 +1357,7 @@ getNextPage:
c = NULL;
}
- return( rc );
+ tool_exit( ld, rc );
}
@@ -1623,7 +1622,7 @@ print_entry(
if( rc != LDAP_SUCCESS ) {
fprintf(stderr, _("print_entry: %d\n"), rc );
tool_perror( "ldap_get_entry_controls", rc, NULL, NULL, NULL, NULL );
- exit( EXIT_FAILURE );
+ tool_exit( ld, EXIT_FAILURE );
}
if( ctrls ) {
@@ -1721,7 +1720,7 @@ static void print_reference(
if( rc != LDAP_SUCCESS ) {
tool_perror( "ldap_parse_reference", rc, NULL, NULL, NULL, NULL );
- exit( EXIT_FAILURE );
+ tool_exit( ld, EXIT_FAILURE );
}
if( refs ) {
@@ -1756,7 +1755,7 @@ static void print_extended(
if( rc != LDAP_SUCCESS ) {
tool_perror( "ldap_parse_extended_result", rc, NULL, NULL, NULL, NULL );
- exit( EXIT_FAILURE );
+ tool_exit( ld, EXIT_FAILURE );
}
if ( ldif < 2 ) {
@@ -1794,7 +1793,7 @@ static void print_partial(
if( rc != LDAP_SUCCESS ) {
tool_perror( "ldap_parse_intermediate", rc, NULL, NULL, NULL, NULL );
- exit( EXIT_FAILURE );
+ tool_exit( ld, EXIT_FAILURE );
}
if ( ldif < 2 ) {
@@ -1844,7 +1843,7 @@ static int print_result(
if( rc != LDAP_SUCCESS ) {
tool_perror( "ldap_parse_result", rc, NULL, NULL, NULL, NULL );
- exit( EXIT_FAILURE );
+ tool_exit( ld, EXIT_FAILURE );
}