]> git.sur5r.net Git - openldap/blobdiff - libraries/libldap/options.c
stdlib.h should be included as <ac/stdlib.h>
[openldap] / libraries / libldap / options.c
index acea330be965bf77c170e25d2ecedb06331b07cd..7d099089cb714f32dd12feef2bea816d2c38daff 100644 (file)
@@ -17,6 +17,7 @@
 #include "ldap-int.h"
 
 #define LDAP_OPT_REBIND_PROC 0x4e814d
+#define LDAP_OPT_REBIND_PARAMS 0x4e814e
 
 static const LDAPAPIFeatureInfo features[] = {
 #ifdef LDAP_API_FEATURE_X_OPENLDAP
@@ -79,16 +80,19 @@ ldap_get_option(
        int             option,
        void    *outvalue)
 {
-       const struct ldapoptions *lo;
+       struct ldapoptions *lo;
 
-       if( ldap_int_global_options.ldo_valid != LDAP_INITIALIZED ) {
-               ldap_int_initialize(NULL);
+       /* Get pointer to global option structure */
+       lo = LDAP_INT_GLOBAL_OPT();   
+       if (NULL == lo) {
+               return LDAP_NO_MEMORY;
        }
 
-       if(ld == NULL) {
-               lo = &ldap_int_global_options;
+       if( lo->ldo_valid != LDAP_INITIALIZED ) {
+               ldap_int_initialize(lo, NULL);
+       }
 
-       } else {
+       if(ld != NULL) {
                assert( LDAP_VALID( ld ) );
 
                if( !LDAP_VALID( ld ) ) {
@@ -278,12 +282,14 @@ ldap_get_option(
 
        default:
 #ifdef HAVE_TLS
-               if ( ldap_pvt_tls_get_option((struct ldapoptions *)lo, option, outvalue ) == 0 )
-                       return LDAP_OPT_SUCCESS;
+               if ( ldap_pvt_tls_get_option( ld, option, outvalue ) == 0 ) {
+                       return LDAP_OPT_SUCCESS;
+               }
 #endif
 #ifdef HAVE_CYRUS_SASL
-               if ( ldap_pvt_sasl_get_option(ld, option, outvalue ) == 0 )
-                       return LDAP_OPT_SUCCESS;
+               if ( ldap_int_sasl_get_option( ld, option, outvalue ) == 0 ) {
+                       return LDAP_OPT_SUCCESS;
+               }
 #endif
                /* bad param */
                break;
@@ -301,6 +307,12 @@ ldap_set_option(
        struct ldapoptions *lo;
        int *dbglvl = NULL;
 
+       /* Get pointer to global option structure */
+       lo = LDAP_INT_GLOBAL_OPT();
+       if (lo == NULL) {
+               return LDAP_NO_MEMORY;
+       }
+
        /*
         * The architecture to turn on debugging has a chicken and egg
         * problem. Thus, we introduce a fix here.
@@ -309,14 +321,11 @@ ldap_set_option(
        if (option == LDAP_OPT_DEBUG_LEVEL)
            dbglvl = (int *) invalue;
 
-       if( ldap_int_global_options.ldo_valid != LDAP_INITIALIZED ) {
-               ldap_int_initialize(dbglvl);
+       if( lo->ldo_valid != LDAP_INITIALIZED ) {
+               ldap_int_initialize(lo, dbglvl);
        }
 
-       if(ld == NULL) {
-               lo = &ldap_int_global_options;
-
-       } else {
+       if(ld != NULL) {
                assert( LDAP_VALID( ld ) );
 
                if( !LDAP_VALID( ld ) ) {
@@ -414,7 +423,10 @@ ldap_set_option(
 
        /* Only accessed from inside this function by ldap_set_rebind_proc() */
        case LDAP_OPT_REBIND_PROC: {
-                       lo->ldo_rebindproc = (LDAP_REBIND_PROC *)invalue;               
+                       lo->ldo_rebind_proc = (LDAP_REBIND_PROC *)invalue;              
+               } return LDAP_OPT_SUCCESS;
+       case LDAP_OPT_REBIND_PARAMS: {
+                       lo->ldo_rebind_params = (void *)invalue;                
                } return LDAP_OPT_SUCCESS;
        }
 
@@ -459,7 +471,8 @@ ldap_set_option(
                        int rc = LDAP_OPT_SUCCESS;
 
                        if(host != NULL) {
-                               rc = ldap_url_parsehosts(&ludlist, host);
+                               rc = ldap_url_parsehosts( &ludlist, host,
+                                       lo->ldo_defport ? lo->ldo_defport : LDAP_PORT );
 
                        } else if(ld == NULL) {
                                /*
@@ -572,11 +585,11 @@ ldap_set_option(
 
        default:
 #ifdef HAVE_TLS
-               if ( ldap_pvt_tls_set_option( lo, option, (void *)invalue ) == 0 )
+               if ( ldap_pvt_tls_set_option( ld, option, (void *)invalue ) == 0 )
                return LDAP_OPT_SUCCESS;
 #endif
 #ifdef HAVE_CYRUS_SASL
-               if ( ldap_pvt_sasl_set_option( ld, option, (void *)invalue ) == 0 )
+               if ( ldap_int_sasl_set_option( ld, option, (void *)invalue ) == 0 )
                        return LDAP_OPT_SUCCESS;
 #endif
                /* bad param */
@@ -585,8 +598,13 @@ ldap_set_option(
        return LDAP_OPT_ERROR;
 }
 
-LIBLDAP_F(int)
-ldap_set_rebind_proc( LDAP *ld, LDAP_REBIND_PROC *rebind_proc)
+int
+ldap_set_rebind_proc( LDAP *ld, LDAP_REBIND_PROC *proc, void *params )
 {
-       return( ldap_set_option( ld, LDAP_OPT_REBIND_PROC, (void *)rebind_proc));
+       int rc;
+       rc = ldap_set_option( ld, LDAP_OPT_REBIND_PROC, (void *)proc );
+       if( rc != LDAP_OPT_SUCCESS ) return rc;
+
+       rc = ldap_set_option( ld, LDAP_OPT_REBIND_PARAMS, (void *)params );
+       return rc;
 }