X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=libraries%2Flibldap%2Fopen.c;h=419b4277e0cca5b215c193fe9fd04a0d034cfdee;hb=5f53b747a5054cfecd6ade134fea27330062ffb8;hp=bfcec1b309309d0743117c5eeaab417e9cb235a5;hpb=f9bbdb34c5907d37d41864d04314861367de5675;p=openldap diff --git a/libraries/libldap/open.c b/libraries/libldap/open.c index bfcec1b309..419b4277e0 100644 --- a/libraries/libldap/open.c +++ b/libraries/libldap/open.c @@ -12,7 +12,8 @@ #include "portable.h" #include -#include + +#include #include #include @@ -39,9 +40,7 @@ LDAP * ldap_open( LDAP_CONST char *host, int port ) { LDAP *ld; -#ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS LDAPServer *srv; -#endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */ Debug( LDAP_DEBUG_TRACE, "ldap_open\n", 0, 0, 0 ); @@ -49,32 +48,23 @@ ldap_open( LDAP_CONST char *host, int port ) return( NULL ); } -#ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS - 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 ); } ++ld->ld_defconn->lconn_refcnt; /* so it never gets closed/freed */ -#else /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */ - if ( open_ldap_connection( ld, &ld->ld_sb, ld->ld_defhost, - ld->ld_defport, &ld->ld_host, 0 ) < 0 ) { - ldap_ld_free( ld, 0, NULL, NULL ); - return( NULL ); - } -#endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */ - Debug( LDAP_DEBUG_TRACE, "ldap_open successful, ld_host is %s\n", ( ld->ld_host == NULL ) ? "(null)" : ld->ld_host, 0, 0 ); @@ -96,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 ); @@ -140,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; @@ -156,34 +148,32 @@ 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); } -#ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS 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 ); } -#endif if(defport != 0) { ld->ld_defport = defport; @@ -262,9 +252,23 @@ open_ldap_connection( LDAP *ld, Sockbuf *sb, const char *host, int defport, ber_pvt_sb_set_io( sb, &ber_pvt_sb_io_tcp, NULL ); +#ifdef HAVE_TLS + if ( ld->ld_options.ldo_tls_mode == LDAP_OPT_X_TLS_HARD ) { + /* + * Fortunately, the lib uses blocking io... + */ + if ( ldap_pvt_tls_connect( sb, ld->ld_options.ldo_tls_ctx ) < + 0 ) { + return -1; + } + /* FIXME: hostname of server must be compared with name in + * certificate.... + */ + } +#endif if ( krbinstancep != NULL ) { - char *c; #ifdef HAVE_KERBEROS + char *c; if (( *krbinstancep = ldap_host_connected_to( sb )) != NULL && ( c = strchr( *krbinstancep, '.' )) != NULL ) { *c = '\0';