]> git.sur5r.net Git - openldap/commitdiff
ITS#6548,#7092 Unbind,cleanup before client exit.
authorHallvard Furuseth <hallvard@openldap.org>
Sun, 20 Nov 2011 12:52:40 +0000 (13:52 +0100)
committerHallvard Furuseth <hallvard@openldap.org>
Sun, 20 Nov 2011 12:52:40 +0000 (13:52 +0100)
Gets rid of "(connection lost)" in slapd statslog "closed" message.

clients/tools/common.c
clients/tools/common.h
clients/tools/ldapcompare.c
clients/tools/ldapdelete.c
clients/tools/ldapexop.c
clients/tools/ldapmodify.c
clients/tools/ldapmodrdn.c
clients/tools/ldappasswd.c
clients/tools/ldapsearch.c
clients/tools/ldapvc.c
clients/tools/ldapwhoami.c

index 262631e4cad1ca904c684786ff9fc4d33cdadbe9..913b5cfab2dea6a7ff8b81caf8779ec4955faeb7 100644 (file)
@@ -252,6 +252,10 @@ tool_init( tool_type_t type )
 void
 tool_destroy( void )
 {
+       static int destroyed;
+       if ( destroyed++ )
+               return;
+
 #ifdef HAVE_CYRUS_SASL
        sasl_done();
 #endif
@@ -1401,7 +1405,7 @@ dnssrv_free:;
                {
                        fprintf( stderr, "Could not set LDAP_OPT_REFERRALS %s\n",
                                referrals ? "on" : "off" );
-                       exit( EXIT_FAILURE );
+                       tool_exit( ld, EXIT_FAILURE );
                }
 
 #ifdef HAVE_CYRUS_SASL
@@ -1411,7 +1415,7 @@ dnssrv_free:;
                {
                        fprintf( stderr, "Could not set LDAP_OPT_X_SASL_NOCANON %s\n",
                                nocanon ? "on" : "off" );
-                       exit( EXIT_FAILURE );
+                       tool_exit( ld, EXIT_FAILURE );
                }
 #endif
                if( ldap_set_option( ld, LDAP_OPT_PROTOCOL_VERSION, &protocol )
@@ -1419,7 +1423,7 @@ dnssrv_free:;
                {
                        fprintf( stderr, "Could not set LDAP_OPT_PROTOCOL_VERSION %d\n",
                                protocol );
-                       exit( EXIT_FAILURE );
+                       tool_exit( ld, EXIT_FAILURE );
                }
 
                if ( use_tls ) {
@@ -1430,7 +1434,7 @@ dnssrv_free:;
                                tool_perror( "ldap_start_tls", rc, NULL, NULL, msg, NULL );
                                ldap_memfree(msg);
                                if ( use_tls > 1 ) {
-                                       exit( EXIT_FAILURE );
+                                       tool_exit( ld, EXIT_FAILURE );
                                }
                        }
                }
@@ -1441,7 +1445,7 @@ dnssrv_free:;
                        {
                                fprintf( stderr, "Could not set LDAP_OPT_NETWORK_TIMEOUT %ld\n",
                                        (long)nettimeout.tv_sec );
-                               exit( EXIT_FAILURE );
+                               tool_exit( ld, EXIT_FAILURE );
                        }
                }
        }
@@ -1500,7 +1504,7 @@ tool_bind( LDAP *ld )
                LDAPControl c;
 
                if ( BER_BVISNULL( &stValue) && st_value( ld, &stValue ) ) {
-                       exit( EXIT_FAILURE );
+                       tool_exit( ld, EXIT_FAILURE );
                }
 
                c.ldctl_oid = LDAP_CONTROL_X_SESSION_TRACKING;
@@ -1524,7 +1528,7 @@ tool_bind( LDAP *ld )
 
                if ( pw_file ) {
                        if ( lutil_get_filed_password( pw_file, &passwd ) ) {
-                               exit( EXIT_FAILURE );
+                               tool_exit( ld, EXIT_FAILURE );
                        }
 
                } else {
@@ -1549,7 +1553,7 @@ tool_bind( LDAP *ld )
                                fprintf( stderr,
                                        "Could not set LDAP_OPT_X_SASL_SECPROPS: %s\n",
                                        sasl_secprops );
-                               exit( LDAP_LOCAL_ERROR );
+                               tool_exit( ld, LDAP_LOCAL_ERROR );
                        }
                }
 
@@ -1576,7 +1580,7 @@ tool_bind( LDAP *ld )
                                tool_perror( "ldap_sasl_interactive_bind",
                                        err, NULL, NULL, info, NULL );
                                ldap_memfree( info );
-                               exit( err );
+                               tool_exit( ld, err );
                        }
                } while ( rc == LDAP_SASL_BIND_IN_PROGRESS );
 
@@ -1587,11 +1591,11 @@ tool_bind( LDAP *ld )
                        tool_perror( "ldap_sasl_interactive_bind",
                                rc, NULL, NULL, info, NULL );
                        ldap_memfree( info );
-                       exit( rc );
+                       tool_exit( ld, rc );
                }
 #else
                fprintf( stderr, "%s: not compiled with SASL support\n", prog );
-               exit( LDAP_NOT_SUPPORTED );
+               tool_exit( ld, LDAP_NOT_SUPPORTED );
 #endif
        } else {
                /* simple bind */
@@ -1600,18 +1604,18 @@ tool_bind( LDAP *ld )
                if ( msgid == -1 ) {
                        tool_perror( "ldap_sasl_bind(SIMPLE)", rc,
                                NULL, NULL, NULL, NULL );
-                       exit( rc );
+                       tool_exit( ld, rc );
                }
 
                rc = ldap_result( ld, msgid, LDAP_MSG_ALL, NULL, &result );
                if ( rc == -1 ) {
                        tool_perror( "ldap_result", -1, NULL, NULL, NULL, NULL );
-                       exit( LDAP_LOCAL_ERROR );
+                       tool_exit( ld, LDAP_LOCAL_ERROR );
                }
 
                if ( rc == 0 ) {
                        tool_perror( "ldap_result", LDAP_TIMEOUT, NULL, NULL, NULL, NULL );
-                       exit( LDAP_LOCAL_ERROR );
+                       tool_exit( ld, LDAP_LOCAL_ERROR );
                }
        }
 
@@ -1619,7 +1623,7 @@ tool_bind( LDAP *ld )
                &ctrls, 1 );
        if ( rc != LDAP_SUCCESS ) {
                tool_perror( "ldap_bind parse result", rc, NULL, matched, info, refs );
-               exit( LDAP_LOCAL_ERROR );
+               tool_exit( ld, LDAP_LOCAL_ERROR );
        }
 
 #ifdef LDAP_CONTROL_PASSWORDPOLICYREQUEST
@@ -1682,7 +1686,7 @@ tool_bind( LDAP *ld )
                if( info ) ber_memfree( info );
                if( refs ) ber_memvfree( (void **)refs );
 
-               if ( err != LDAP_SUCCESS ) exit( err );
+               if ( err != LDAP_SUCCESS ) tool_exit( ld, err );
        }
 }
 
@@ -1698,6 +1702,16 @@ tool_unbind( LDAP *ld )
        (void) ldap_unbind_ext( ld, NULL, NULL );
 }
 
+void
+tool_exit( LDAP *ld, int status )
+{
+       if ( ld != NULL ) {
+               tool_unbind( ld );
+       }
+       tool_destroy();
+       exit( status );
+}
+
 
 /* Set server controls.  Add controls extra_c[0..count-1], if set. */
 void
@@ -1734,7 +1748,7 @@ tool_server_controls( LDAP *ld, LDAPControl *extra_c, int count )
        ctrls = (LDAPControl**) malloc(sizeof(c) + (count + unknown_ctrls_num + 1)*sizeof(LDAPControl*));
        if ( ctrls == NULL ) {
                fprintf( stderr, "No memory\n" );
-               exit( EXIT_FAILURE );
+               tool_exit( ld, EXIT_FAILURE );
        }
 
        if ( assertctl ) {
@@ -1774,11 +1788,11 @@ tool_server_controls( LDAP *ld, LDAPControl *extra_c, int count )
                ber_init2( ber, NULL, LBER_USE_DER );
 
                if ( ber_printf( ber, "s", proxydn ) == -1 ) {
-                       exit( EXIT_FAILURE );
+                       tool_exit( ld, EXIT_FAILURE );
                }
 
                if ( ber_flatten2( ber, &c[i].ldctl_value, 0 ) == -1 ) {
-                       exit( EXIT_FAILURE );
+                       tool_exit( ld, EXIT_FAILURE );
                }
 
                c[i].ldctl_oid = LDAP_CONTROL_OBSOLETE_PROXY_AUTHZ;
@@ -1835,13 +1849,13 @@ tool_server_controls( LDAP *ld, LDAPControl *extra_c, int count )
 
                if( ber_printf( ber, "{v}", attrs ) == -1 ) {
                        fprintf( stderr, "preread attrs encode failed.\n" );
-                       exit( EXIT_FAILURE );
+                       tool_exit( ld, EXIT_FAILURE );
                }
 
                err = ber_flatten2( ber, &c[i].ldctl_value, 0 );
                if( err < 0 ) {
                        fprintf( stderr, "preread flatten failed (%d)\n", err );
-                       exit( EXIT_FAILURE );
+                       tool_exit( ld, EXIT_FAILURE );
                }
 
                c[i].ldctl_oid = LDAP_CONTROL_PRE_READ;
@@ -1865,13 +1879,13 @@ tool_server_controls( LDAP *ld, LDAPControl *extra_c, int count )
 
                if( ber_printf( ber, "{v}", attrs ) == -1 ) {
                        fprintf( stderr, "postread attrs encode failed.\n" );
-                       exit( EXIT_FAILURE );
+                       tool_exit( ld, EXIT_FAILURE );
                }
 
                err = ber_flatten2( ber, &c[i].ldctl_value, 0 );
                if( err < 0 ) {
                        fprintf( stderr, "postread flatten failed (%d)\n", err );
-                       exit( EXIT_FAILURE );
+                       tool_exit( ld, EXIT_FAILURE );
                }
 
                c[i].ldctl_oid = LDAP_CONTROL_POST_READ;
@@ -1894,7 +1908,7 @@ tool_server_controls( LDAP *ld, LDAPControl *extra_c, int count )
                        if ( err == -1 ) {
                                ber_free( ber, 1 );
                                fprintf( stderr, _("Chaining behavior control encoding error!\n") );
-                               exit( EXIT_FAILURE );
+                               tool_exit( ld, EXIT_FAILURE );
                        }
 
                        if ( chainingContinuation > -1 ) {
@@ -1902,7 +1916,7 @@ tool_server_controls( LDAP *ld, LDAPControl *extra_c, int count )
                                if ( err == -1 ) {
                                        ber_free( ber, 1 );
                                        fprintf( stderr, _("Chaining behavior control encoding error!\n") );
-                                       exit( EXIT_FAILURE );
+                                       tool_exit( ld, EXIT_FAILURE );
                                }
                        }
 
@@ -1910,11 +1924,11 @@ tool_server_controls( LDAP *ld, LDAPControl *extra_c, int count )
                        if ( err == -1 ) {
                                ber_free( ber, 1 );
                                fprintf( stderr, _("Chaining behavior control encoding error!\n") );
-                               exit( EXIT_FAILURE );
+                               tool_exit( ld, EXIT_FAILURE );
                        }
 
                        if ( ber_flatten2( ber, &c[i].ldctl_value, 0 ) == -1 ) {
-                               exit( EXIT_FAILURE );
+                               tool_exit( ld, EXIT_FAILURE );
                        }
 
                } else {
@@ -1931,7 +1945,7 @@ tool_server_controls( LDAP *ld, LDAPControl *extra_c, int count )
 #ifdef LDAP_CONTROL_X_SESSION_TRACKING
        if ( sessionTracking ) {
                if ( BER_BVISNULL( &stValue ) && st_value( ld, &stValue ) ) {
-                       exit( EXIT_FAILURE );
+                       tool_exit( ld, EXIT_FAILURE );
                }
 
                c[i].ldctl_oid = LDAP_CONTROL_X_SESSION_TRACKING;
@@ -1963,7 +1977,7 @@ tool_server_controls( LDAP *ld, LDAPControl *extra_c, int count )
 
        free( ctrls );
        if ( crit ) {
-               exit( EXIT_FAILURE );
+               tool_exit( ld, EXIT_FAILURE );
        }
 }
 
@@ -2497,4 +2511,3 @@ tool_is_oid( const char *s )
 
        return 1;
 }
-
index 1f60d5a42d3f09369890c6d597c73b6ce79ef247..364cae36f85fb1d3b3a71e6df2410c2080f0022b 100644 (file)
@@ -119,6 +119,7 @@ LDAP *tool_conn_setup LDAP_P(( int dont, void (*private_setup)( LDAP * ) ));
 void tool_bind LDAP_P(( LDAP * ));
 void tool_unbind LDAP_P(( LDAP * ));
 void tool_destroy LDAP_P(( void ));
+void tool_exit LDAP_P(( LDAP *ld, int status )) LDAP_GCCATTR((noreturn));
 void tool_server_controls LDAP_P(( LDAP *, LDAPControl *, int ));
 int tool_check_abandon LDAP_P(( LDAP *ld, int msgid ));
 void tool_perror LDAP_P((
index 24e1a75853bbde71fc3238e8ff4dbc7f27f68e13..3b88f664049750a1ff38df74b9825b0b32ff95b3 100644 (file)
@@ -260,9 +260,7 @@ main( int argc, char **argv )
 
        free( bvalue.bv_val );
 
-       tool_unbind( ld );
-       tool_destroy();
-       return rc;
+       tool_exit( ld, rc );
 }
 
 
index f1db45eaa22396b7d06ad652e64373b6285f4f57..1e823eec0bf5de78bfe29647c8e5cb0f871ffe57 100644 (file)
@@ -218,9 +218,7 @@ main( int argc, char **argv )
                        fclose( fp );
        }
 
-       tool_unbind( ld );
-       tool_destroy();
-    return retval;
+       tool_exit( ld, retval );
 }
 
 
index 6fc4d1e3c6b3a1f93746ff3f6bbf92fb85a52e9e..cf30a379478ad0957c5ff4ca8329c22349a98889 100644 (file)
@@ -213,7 +213,7 @@ main( int argc, char *argv[] )
                struct timeval  tv;
 
                if ( tool_check_abandon( ld, id ) ) {
-                       return LDAP_CANCELLED;
+                       tool_exit( ld, LDAP_CANCELLED );
                }
 
                tv.tv_sec = 0;
@@ -351,8 +351,5 @@ skip:
        /* disconnect from server */
        if ( res )
                ldap_msgfree( res );
-       tool_unbind( ld );
-       tool_destroy();
-
-       return code == LDAP_SUCCESS ? EXIT_SUCCESS : EXIT_FAILURE;
+       tool_exit( ld, code == LDAP_SUCCESS ? EXIT_SUCCESS : EXIT_FAILURE );
 }
index 2f0edf9239fe801a3431b75c65ae518ba0ba0156..01df3c72b17d95303825e81d2da830fc2a730c70 100644 (file)
@@ -363,12 +363,6 @@ main( int argc, char **argv )
        }
 #endif
 
-       if ( !dont && ld != NULL ) {
-               tool_unbind( ld );
-       }
-
-       tool_destroy();
-
 fail:;
        if ( rejfp != NULL ) {
                fclose( rejfp );
@@ -378,7 +372,7 @@ fail:;
                ldif_close( ldiffp );
        }
 
-       return( retval );
+       tool_exit( ld, retval );
 }
 
 
index 42c37aa31b0d9844726aec742f87bc9c878f172b..1483d157c9d65bdb5030aaefa241533d4a4ec641 100644 (file)
@@ -156,7 +156,7 @@ main(int argc, char **argv)
 {
        char            *entrydn = NULL, *rdn = NULL, buf[ 4096 ];
        FILE            *fp = NULL;
-       LDAP            *ld;
+       LDAP            *ld = NULL;
        int             rc, retval, havedn;
 
        tool_init( TOOL_MODRDN );
@@ -227,13 +227,11 @@ main(int argc, char **argv)
                }
        }
 
-       tool_unbind( ld );
-       tool_destroy();
 fail:
        if ( fp && fp != stdin ) fclose( fp );
        if ( entrydn ) free( entrydn );
        if ( rdn ) free( rdn );
-       return( retval );
+       tool_exit( ld, retval );
 }
 
 static int domodrdn(
index 81e9c76c9526001aaf5aba0fa359a4a2b57dbcd3..1e350f153c7ce7d3b9c8de348ecc65775854f787 100644 (file)
@@ -313,7 +313,7 @@ main( int argc, char *argv[] )
                struct timeval  tv;
 
                if ( tool_check_abandon( ld, id ) ) {
-                       return LDAP_CANCELLED;
+                       tool_exit( ld, LDAP_CANCELLED );
                }
 
                tv.tv_sec = 0;
@@ -322,7 +322,7 @@ main( int argc, char *argv[] )
                rc = ldap_result( ld, LDAP_RES_ANY, LDAP_MSG_ALL, &tv, &res );
                if ( rc < 0 ) {
                        tool_perror( "ldap_result", rc, NULL, NULL, NULL, NULL );
-                       return rc;
+                       tool_exit( ld, rc );
                }
 
                if ( rc != 0 ) {
@@ -409,8 +409,5 @@ main( int argc, char *argv[] )
 
 done:
        /* disconnect from server */
-       if ( ld )
-               tool_unbind( ld ); 
-       tool_destroy();
-       return rc;
+       tool_exit( ld, rc ); 
 }
index 068acb3e1b5e30485409e7ef5dffaef49fd518a9..5fd68bf5db0cdb5288018aeb7499eaccaeb65d2c 100644 (file)
@@ -777,7 +777,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 +908,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 +932,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 +945,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 +957,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 +982,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 +999,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 +1014,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 +1038,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 +1060,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 +1076,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 +1097,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 +1109,7 @@ getNextPage:
                        }
 
                        if ( ctrl_add() ) {
-                               exit( EXIT_FAILURE );
+                               tool_exit( ld, EXIT_FAILURE );
                        }
 
                        c[ i ].ldctl_iscritical = derefcrit > 1;
@@ -1285,7 +1285,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 +1316,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 +1330,6 @@ getNextPage:
                goto getNextPage;
        }
 
-       tool_unbind( ld );
-       tool_destroy();
        if ( base != NULL ) {
                ber_memfree( base );
        }
@@ -1358,7 +1356,7 @@ getNextPage:
                c = NULL;
        }
 
-       return( rc );
+       tool_exit( ld, rc );
 }
 
 
@@ -1623,7 +1621,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 +1719,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 +1754,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 +1792,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 +1842,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 );
        }
 
 
index 73166b1d8ee61a083a976d564ce483b34c4552bf..5ed2ad3a9e5ed260b8a9869e87567c6866ad5c43 100644 (file)
@@ -382,7 +382,7 @@ main( int argc, char *argv[] )
                                ldap_get_option(ld, LDAP_OPT_DIAGNOSTIC_MESSAGE, (void*) &text);
                                tool_perror( "ldap_verify_credentials_interactive", rc, NULL, NULL, text, NULL);
                                ldap_memfree(text);
-                               exit(rc);
+                               tool_exit(ld, rc);
                        }
                } while (rc == LDAP_SASL_BIND_IN_PROGRESS);
 
@@ -415,7 +415,7 @@ main( int argc, char *argv[] )
                    struct timeval      tv;
 
                    if ( tool_check_abandon( ld, id ) ) {
-                           return LDAP_CANCELLED;
+                           tool_exit( ld, LDAP_CANCELLED );
                    }
 
                    tv.tv_sec = 0;
@@ -424,7 +424,7 @@ main( int argc, char *argv[] )
                    rc = ldap_result( ld, LDAP_RES_ANY, LDAP_MSG_ALL, &tv, &res );
                    if ( rc < 0 ) {
                            tool_perror( "ldap_result", rc, NULL, NULL, NULL, NULL );
-                           return rc;
+                           tool_exit( ld, rc );
                    }
 
                    if ( rc != 0 ) {
@@ -504,8 +504,5 @@ skip:
        free( cred.bv_val );
 
        /* disconnect from server */
-       tool_unbind( ld );
-       tool_destroy();
-
-       return code == LDAP_SUCCESS ? EXIT_SUCCESS : EXIT_FAILURE;
+       tool_exit( ld, code == LDAP_SUCCESS ? EXIT_SUCCESS : EXIT_FAILURE );
 }
index 4f4c9f6290578d447077eebd077c606d041dcce5..ff57fda808f0f7e77723374f36ebafadf69b1485 100644 (file)
@@ -151,7 +151,7 @@ main( int argc, char *argv[] )
                struct timeval  tv;
 
                if ( tool_check_abandon( ld, id ) ) {
-                       return LDAP_CANCELLED;
+                       tool_exit( ld, LDAP_CANCELLED );
                }
 
                tv.tv_sec = 0;
@@ -160,7 +160,7 @@ main( int argc, char *argv[] )
                rc = ldap_result( ld, LDAP_RES_ANY, LDAP_MSG_ALL, &tv, &res );
                if ( rc < 0 ) {
                        tool_perror( "ldap_result", rc, NULL, NULL, NULL, NULL );
-                       return rc;
+                       tool_exit( ld, rc );
                }
 
                if ( rc != 0 ) {
@@ -231,8 +231,5 @@ skip:
        ber_bvfree( authzid );
 
        /* disconnect from server */
-       tool_unbind( ld );
-       tool_destroy();
-
-       return code == LDAP_SUCCESS ? EXIT_SUCCESS : EXIT_FAILURE;
+       tool_exit( ld, code == LDAP_SUCCESS ? EXIT_SUCCESS : EXIT_FAILURE );
 }