From: Howard Chu Date: Fri, 7 Apr 2006 00:48:41 +0000 (+0000) Subject: ITS#4422, rearrange options to allow passing NULL args to TLS/Cyrus X-Git-Tag: OPENLDAP_REL_ENG_2_4_0ALPHA~25 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=51d5db03ff1d6ea2fc0806630175ec3b463d9bab;p=openldap ITS#4422, rearrange options to allow passing NULL args to TLS/Cyrus --- diff --git a/libraries/libldap/cyrus.c b/libraries/libldap/cyrus.c index dc78ebdadb..6c82969f09 100644 --- a/libraries/libldap/cyrus.c +++ b/libraries/libldap/cyrus.c @@ -1186,7 +1186,7 @@ ldap_int_sasl_get_option( LDAP *ld, int option, void *arg ) int ldap_int_sasl_set_option( LDAP *ld, int option, void *arg ) { - if ( ld == NULL ) + if ( ld == NULL || arg == NULL ) return -1; switch ( option ) { diff --git a/libraries/libldap/options.c b/libraries/libldap/options.c index 4b76a0c5f7..1cfd9487b7 100644 --- a/libraries/libldap/options.c +++ b/libraries/libldap/options.c @@ -542,74 +542,12 @@ ldap_set_option( return rc; } - /* Only accessed from inside this function by ldap_set_rebind_proc() */ - case LDAP_OPT_REBIND_PROC: { - 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; - - /* Only accessed from inside this function by ldap_set_nextref_proc() */ - case LDAP_OPT_NEXTREF_PROC: { - lo->ldo_nextref_proc = (LDAP_NEXTREF_PROC *)invalue; - } return LDAP_OPT_SUCCESS; - case LDAP_OPT_NEXTREF_PARAMS: { - lo->ldo_nextref_params = (void *)invalue; - } return LDAP_OPT_SUCCESS; - } - - if(invalue == NULL) { - /* no place to set from */ - return LDAP_OPT_ERROR; - } - - /* options which cannot withstand invalue == NULL */ - - switch(option) { - case LDAP_OPT_API_INFO: - case LDAP_OPT_DESC: - /* READ ONLY */ - break; - - case LDAP_OPT_DEREF: - lo->ldo_deref = * (const int *) invalue; - return LDAP_OPT_SUCCESS; - - case LDAP_OPT_SIZELIMIT: - lo->ldo_sizelimit = * (const int *) invalue; - return LDAP_OPT_SUCCESS; - - case LDAP_OPT_TIMELIMIT: - lo->ldo_timelimit = * (const int *) invalue; - return LDAP_OPT_SUCCESS; - - case LDAP_OPT_PROTOCOL_VERSION: { - int vers = * (const int *) invalue; - if (vers < LDAP_VERSION_MIN || vers > LDAP_VERSION_MAX) { - /* not supported */ - break; - } - lo->ldo_version = vers; - } return LDAP_OPT_SUCCESS; - - case LDAP_OPT_ERROR_NUMBER: { - int err = * (const int *) invalue; - - if(ld == NULL) { - /* need a struct ldap */ - break; - } - - ld->ld_errno = err; - } return LDAP_OPT_SUCCESS; - case LDAP_OPT_ERROR_STRING: { const char *err = (const char *) invalue; if(ld == NULL) { /* need a struct ldap */ - break; + return LDAP_OPT_ERROR; } if( ld->ld_error ) { @@ -627,7 +565,7 @@ ldap_set_option( if (ld == NULL) { /* need a struct ldap */ - break; + return LDAP_OPT_ERROR; } if( ld->ld_matched ) { @@ -645,23 +583,52 @@ ldap_set_option( if(ld == NULL) { /* need a struct ldap */ - break; + return LDAP_OPT_ERROR; } if( ld->ld_referrals ) { LDAP_VFREE(ld->ld_referrals); } - ld->ld_referrals = ldap_value_dup(referrals); + if ( referrals ) { + ld->ld_referrals = ldap_value_dup(referrals); + } } return LDAP_OPT_SUCCESS; + /* Only accessed from inside this function by ldap_set_rebind_proc() */ + case LDAP_OPT_REBIND_PROC: { + 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; + + /* Only accessed from inside this function by ldap_set_nextref_proc() */ + case LDAP_OPT_NEXTREF_PROC: { + lo->ldo_nextref_proc = (LDAP_NEXTREF_PROC *)invalue; + } return LDAP_OPT_SUCCESS; + case LDAP_OPT_NEXTREF_PARAMS: { + lo->ldo_nextref_params = (void *)invalue; + } return LDAP_OPT_SUCCESS; + + /* read-only options */ + case LDAP_OPT_API_INFO: + case LDAP_OPT_DESC: case LDAP_OPT_API_FEATURE_INFO: - /* read-only */ - break; + return LDAP_OPT_ERROR; + /* options which cannot withstand invalue == NULL */ + case LDAP_OPT_DEREF: + case LDAP_OPT_SIZELIMIT: + case LDAP_OPT_TIMELIMIT: + case LDAP_OPT_PROTOCOL_VERSION: + case LDAP_OPT_ERROR_NUMBER: case LDAP_OPT_DEBUG_LEVEL: - lo->ldo_debug = * (const int *) invalue; - return LDAP_OPT_SUCCESS; + if(invalue == NULL) { + /* no place to set from */ + return LDAP_OPT_ERROR; + } + break; default: #ifdef HAVE_TLS @@ -673,7 +640,47 @@ ldap_set_option( return LDAP_OPT_SUCCESS; #endif /* bad param */ - break; + return LDAP_OPT_ERROR; + } + + /* options which cannot withstand invalue == NULL */ + + switch(option) { + case LDAP_OPT_DEREF: + lo->ldo_deref = * (const int *) invalue; + return LDAP_OPT_SUCCESS; + + case LDAP_OPT_SIZELIMIT: + lo->ldo_sizelimit = * (const int *) invalue; + return LDAP_OPT_SUCCESS; + + case LDAP_OPT_TIMELIMIT: + lo->ldo_timelimit = * (const int *) invalue; + return LDAP_OPT_SUCCESS; + + case LDAP_OPT_PROTOCOL_VERSION: { + int vers = * (const int *) invalue; + if (vers < LDAP_VERSION_MIN || vers > LDAP_VERSION_MAX) { + /* not supported */ + break; + } + lo->ldo_version = vers; + } return LDAP_OPT_SUCCESS; + + case LDAP_OPT_ERROR_NUMBER: { + int err = * (const int *) invalue; + + if(ld == NULL) { + /* need a struct ldap */ + break; + } + + ld->ld_errno = err; + } return LDAP_OPT_SUCCESS; + + case LDAP_OPT_DEBUG_LEVEL: + lo->ldo_debug = * (const int *) invalue; + return LDAP_OPT_SUCCESS; } return LDAP_OPT_ERROR; }