X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=libraries%2Flibldap%2Fopen.c;h=e9a7353ab66b4a71db401d8f9f5f675795f5c10c;hb=c8e37af0ca8302c276e8c6af84eca4f926171261;hp=5149af1df6fef7f686e68e3570acb90c423e7858;hpb=22d98c85c3ece96dd2e3d9b76195973d0639cd49;p=openldap diff --git a/libraries/libldap/open.c b/libraries/libldap/open.c index 5149af1df6..e9a7353ab6 100644 --- a/libraries/libldap/open.c +++ b/libraries/libldap/open.c @@ -12,7 +12,8 @@ #include "portable.h" #include -#include + +#include #include #include @@ -47,18 +48,18 @@ ldap_open( LDAP_CONST char *host, int port ) return( NULL ); } - if (( srv = (LDAPServer *)calloc( 1, sizeof( LDAPServer ))) == + if (( srv = (LDAPServer *)LDAP_CALLOC( 1, sizeof( LDAPServer ))) == NULL || ( ld->ld_defhost != NULL && ( srv->lsrv_host = - strdup( ld->ld_defhost )) == NULL )) { - if(srv != NULL) free( (char*) srv ); + LDAP_STRDUP( ld->ld_defhost )) == NULL )) { + if(srv != NULL) LDAP_FREE( (char*) srv ); ldap_ld_free( ld, 0, NULL, NULL ); return( NULL ); } srv->lsrv_port = ld->ld_defport; if (( ld->ld_defconn = ldap_new_connection( ld, &srv, 1,1,0 )) == NULL ) { - if ( ld->ld_defhost != NULL ) free( srv->lsrv_host ); - free( (char *)srv ); + if ( ld->ld_defhost != NULL ) LDAP_FREE( srv->lsrv_host ); + LDAP_FREE( (char *)srv ); ldap_ld_free( ld, 0, NULL, NULL ); return( NULL ); } @@ -85,8 +86,8 @@ ldap_init( LDAP_CONST char *defhost, int defport ) { LDAP *ld; - if(!openldap_ldap_initialized) { - openldap_ldap_initialize(); + if( ldap_int_global_options.ldo_valid != LDAP_INITIALIZED ) { + ldap_int_initialize(); } Debug( LDAP_DEBUG_TRACE, "ldap_init\n", 0, 0, 0 ); @@ -129,15 +130,17 @@ ldap_init( LDAP_CONST char *defhost, int defport ) } #endif - if ( (ld = (LDAP *) calloc( 1, sizeof(LDAP) )) == NULL ) { + if ( (ld = (LDAP *) LDAP_CALLOC( 1, sizeof(LDAP) )) == NULL ) { WSACleanup( ); return( NULL ); } /* copy the global options */ - memcpy(&ld->ld_options, &openldap_ldap_global_options, + memcpy(&ld->ld_options, &ldap_int_global_options, sizeof(ld->ld_options)); + ld->ld_valid = LDAP_VALID_SESSION; + /* but not pointers to malloc'ed items */ ld->ld_options.ldo_defbase = NULL; ld->ld_options.ldo_defhost = NULL; @@ -145,29 +148,29 @@ ldap_init( LDAP_CONST char *defhost, int defport ) ld->ld_options.ldo_cctrls = NULL; if ( defhost != NULL ) { - ld->ld_options.ldo_defhost = strdup( defhost ); + ld->ld_options.ldo_defhost = LDAP_STRDUP( defhost ); } else { - ld->ld_options.ldo_defhost = strdup( - openldap_ldap_global_options.ldo_defhost); + ld->ld_options.ldo_defhost = LDAP_STRDUP( + ldap_int_global_options.ldo_defhost); } if ( ld->ld_options.ldo_defhost == NULL ) { - free( (char*)ld ); + LDAP_FREE( (char*)ld ); WSACleanup( ); return( NULL ); } - if ( openldap_ldap_global_options.ldo_defbase != NULL ) { - ld->ld_options.ldo_defbase = strdup( - openldap_ldap_global_options.ldo_defbase); + if ( ldap_int_global_options.ldo_defbase != NULL ) { + ld->ld_options.ldo_defbase = LDAP_STRDUP( + ldap_int_global_options.ldo_defbase); } if (( ld->ld_selectinfo = ldap_new_select_info()) == NULL ) { - free( (char*) ld->ld_options.ldo_defhost ); + LDAP_FREE( (char*) ld->ld_options.ldo_defhost ); if ( ld->ld_options.ldo_defbase == NULL ) { - free( (char*) ld->ld_options.ldo_defbase ); + LDAP_FREE( (char*) ld->ld_options.ldo_defbase ); } - free( (char*) ld ); + LDAP_FREE( (char*) ld ); WSACleanup( ); return( NULL ); }