From e366aefffc3c1948b3e301adfd3542d74a3bceab Mon Sep 17 00:00:00 2001 From: Kurt Zeilenga Date: Wed, 13 Sep 2000 21:49:31 +0000 Subject: [PATCH] Fix ldap_init/initialize error checking --- clients/tools/ldapdelete.c | 17 +++++++++++------ clients/tools/ldapmodify.c | 17 +++++++++++------ clients/tools/ldapmodrdn.c | 17 +++++++++++------ clients/tools/ldappasswd.c | 17 +++++++++++------ clients/tools/ldapsearch.c | 18 +++++++++++------- 5 files changed, 55 insertions(+), 31 deletions(-) diff --git a/clients/tools/ldapdelete.c b/clients/tools/ldapdelete.c index 80e15939b3..7be56175c1 100644 --- a/clients/tools/ldapdelete.c +++ b/clients/tools/ldapdelete.c @@ -501,20 +501,25 @@ main( int argc, char **argv ) ldaphost != NULL ? ldaphost : "", ldapport ); } + ld = ldap_init( ldaphost, ldapport ); + if( ld == NULL ) { + perror("ldapsearch: ldap_init"); + return EXIT_FAILURE; + } } else { if ( verbose ) { fprintf( stderr, "ldap_initialize( %s )\n", ldapuri != NULL ? ldapuri : "" ); } - (void) ldap_initialize( &ld, ldapuri ); - } - if( ld == NULL ) { - fprintf( stderr, "Could not create LDAP session handle (%d): %s\n", - rc, ldap_err2string(rc) ); - return EXIT_FAILURE; + rc = ldap_initialize( &ld, ldapuri ); + if( rc != LDAP_SUCCESS ) { + fprintf( stderr, "Could not create LDAP session handle (%d): %s\n", + rc, ldap_err2string(rc) ); + return EXIT_FAILURE; + } } { diff --git a/clients/tools/ldapmodify.c b/clients/tools/ldapmodify.c index 690bff7e40..ab484c7bfd 100644 --- a/clients/tools/ldapmodify.c +++ b/clients/tools/ldapmodify.c @@ -568,20 +568,25 @@ main( int argc, char **argv ) ldaphost != NULL ? ldaphost : "", ldapport ); } + ld = ldap_init( ldaphost, ldapport ); + if( ld == NULL ) { + perror("ldapsearch: ldap_init"); + return EXIT_FAILURE; + } } else { if ( verbose ) { fprintf( stderr, "ldap_initialize( %s )\n", ldapuri != NULL ? ldapuri : "" ); } - (void) ldap_initialize( &ld, ldapuri ); - } - if( ld == NULL ) { - fprintf( stderr, "Could not create LDAP session handle (%d): %s\n", - rc, ldap_err2string(rc) ); - return EXIT_FAILURE; + rc = ldap_initialize( &ld, ldapuri ); + if( rc != LDAP_SUCCESS ) { + fprintf( stderr, "Could not create LDAP session handle (%d): %s\n", + rc, ldap_err2string(rc) ); + return EXIT_FAILURE; + } } /* referrals */ diff --git a/clients/tools/ldapmodrdn.c b/clients/tools/ldapmodrdn.c index 32ac8e0553..16da3786c0 100644 --- a/clients/tools/ldapmodrdn.c +++ b/clients/tools/ldapmodrdn.c @@ -544,20 +544,25 @@ main(int argc, char **argv) ldaphost != NULL ? ldaphost : "", ldapport ); } + ld = ldap_init( ldaphost, ldapport ); + if( ld == NULL ) { + perror("ldapsearch: ldap_init"); + return EXIT_FAILURE; + } } else { if ( verbose ) { fprintf( stderr, "ldap_initialize( %s )\n", ldapuri != NULL ? ldapuri : "" ); } - (void) ldap_initialize( &ld, ldapuri ); - } - if( ld == NULL ) { - fprintf( stderr, "Could not create LDAP session handle (%d): %s\n", - rc, ldap_err2string(rc) ); - return EXIT_FAILURE; + rc = ldap_initialize( &ld, ldapuri ); + if( rc != LDAP_SUCCESS ) { + fprintf( stderr, "Could not create LDAP session handle (%d): %s\n", + rc, ldap_err2string(rc) ); + return EXIT_FAILURE; + } } /* referrals */ diff --git a/clients/tools/ldappasswd.c b/clients/tools/ldappasswd.c index 7928d4c05c..cf49fa678a 100644 --- a/clients/tools/ldappasswd.c +++ b/clients/tools/ldappasswd.c @@ -558,20 +558,25 @@ main( int argc, char *argv[] ) ldaphost != NULL ? ldaphost : "", ldapport ); } + ld = ldap_init( ldaphost, ldapport ); + if( ld == NULL ) { + perror("ldapsearch: ldap_init"); + return EXIT_FAILURE; + } } else { if ( verbose ) { fprintf( stderr, "ldap_initialize( %s )\n", ldapuri != NULL ? ldapuri : "" ); } - (void) ldap_initialize( &ld, ldapuri ); - } - if( ld == NULL ) { - fprintf( stderr, "Could not create LDAP session handle (%d): %s\n", - rc, ldap_err2string(rc) ); - return EXIT_FAILURE; + rc = ldap_initialize( &ld, ldapuri ); + if( rc != LDAP_SUCCESS ) { + fprintf( stderr, "Could not create LDAP session handle (%d): %s\n", + rc, ldap_err2string(rc) ); + return EXIT_FAILURE; + } } /* referrals */ diff --git a/clients/tools/ldapsearch.c b/clients/tools/ldapsearch.c index 21d15ec528..0cbe940464 100644 --- a/clients/tools/ldapsearch.c +++ b/clients/tools/ldapsearch.c @@ -663,27 +663,31 @@ main( int argc, char **argv ) (void) SIGNAL( SIGPIPE, SIG_IGN ); #endif - if( ( ldaphost != NULL || ldapport ) && ( ldapuri == NULL ) ) { if ( verbose ) { fprintf( stderr, "ldap_init( %s, %d )\n", ldaphost != NULL ? ldaphost : "", ldapport ); } + ld = ldap_init( ldaphost, ldapport ); + if( ld == NULL ) { + perror("ldapsearch: ldap_init"); + return EXIT_FAILURE; + } } else { if ( verbose ) { fprintf( stderr, "ldap_initialize( %s )\n", ldapuri != NULL ? ldapuri : "" ); } - (void) ldap_initialize( &ld, ldapuri ); - } - if( ld == NULL ) { - fprintf( stderr, "Could not create LDAP session handle (%d): %s\n", - rc, ldap_err2string(rc) ); - return EXIT_FAILURE; + rc = ldap_initialize( &ld, ldapuri ); + if( rc != LDAP_SUCCESS ) { + fprintf( stderr, "Could not create LDAP session handle (%d): %s\n", + rc, ldap_err2string(rc) ); + return EXIT_FAILURE; + } } if (deref != -1 && -- 2.39.5