X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;ds=sidebyside;f=libraries%2Flibldap%2Foptions.c;h=329047143100d217e65b86d92375d97f974727fb;hb=3a48db631e2caade14d991d75bd8f5fba97974b8;hp=7bc03b141dcc389ff7db875906e0a5221cc204b8;hpb=8153a4039b9049da4fc324cd0807d3dc964596ab;p=openldap
diff --git a/libraries/libldap/options.c b/libraries/libldap/options.c
index 7bc03b141d..3290471431 100644
--- a/libraries/libldap/options.c
+++ b/libraries/libldap/options.c
@@ -1,45 +1,92 @@
-/*
- * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
- * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
+/* $OpenLDAP$ */
+/* This work is part of OpenLDAP Software .
+ *
+ * Copyright 1998-2008 The OpenLDAP Foundation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted only as authorized by the OpenLDAP
+ * Public License.
+ *
+ * A copy of this license is available in the file LICENSE in the
+ * top-level directory of the distribution or, alternatively, at
+ * .
*/
#include "portable.h"
#include
-#include
+
+#include
#include
#include
+#include
#include "ldap-int.h"
+#define LDAP_OPT_REBIND_PROC 0x4e814d
+#define LDAP_OPT_REBIND_PARAMS 0x4e814e
+
+#define LDAP_OPT_NEXTREF_PROC 0x4e815d
+#define LDAP_OPT_NEXTREF_PARAMS 0x4e815e
+
+#define LDAP_OPT_URLLIST_PROC 0x4e816d
+#define LDAP_OPT_URLLIST_PARAMS 0x4e816e
+
static const LDAPAPIFeatureInfo features[] = {
-#ifdef LDAP_API_FEATURE_INFO
- {"INFO", LDAP_API_FEATURE_INFO},
+#ifdef LDAP_API_FEATURE_X_OPENLDAP
+ { /* OpenLDAP Extensions API Feature */
+ LDAP_FEATURE_INFO_VERSION,
+ "X_OPENLDAP",
+ LDAP_API_FEATURE_X_OPENLDAP
+ },
#endif
+
#ifdef LDAP_API_FEATURE_THREAD_SAFE
- {"THREAD_SAFE", LDAP_API_FEATURE_THREAD_SAFE},
+ { /* Basic Thread Safe */
+ LDAP_FEATURE_INFO_VERSION,
+ "THREAD_SAFE",
+ LDAP_API_FEATURE_THREAD_SAFE
+ },
#endif
#ifdef LDAP_API_FEATURE_SESSION_THREAD_SAFE
- {"SESSION_THREAD_SAFE", LDAP_API_FEATURE_SESSION_THREAD_SAFE},
+ { /* Session Thread Safe */
+ LDAP_FEATURE_INFO_VERSION,
+ "SESSION_THREAD_SAFE",
+ LDAP_API_FEATURE_SESSION_THREAD_SAFE
+ },
#endif
#ifdef LDAP_API_FEATURE_OPERATION_THREAD_SAFE
- {"OPERATION_THREAD_SAFE", LDAP_API_FEATURE_OPERATION_THREAD_SAFE},
+ { /* Operation Thread Safe */
+ LDAP_FEATURE_INFO_VERSION,
+ "OPERATION_THREAD_SAFE",
+ LDAP_API_FEATURE_OPERATION_THREAD_SAFE
+ },
#endif
-#ifdef LDAP_API_FEATURE_X_OPENLDAP_REEENTRANT
- {"X_OPENLDAP_REENTRANT", LDAP_API_FEATURE_X_OPENLDAP_REENTRANT},
+#ifdef LDAP_API_FEATURE_X_OPENLDAP_REENTRANT
+ { /* OpenLDAP Reentrant */
+ LDAP_FEATURE_INFO_VERSION,
+ "X_OPENLDAP_REENTRANT",
+ LDAP_API_FEATURE_X_OPENLDAP_REENTRANT
+ },
#endif
#if defined( LDAP_API_FEATURE_X_OPENLDAP_THREAD_SAFE ) && \
defined( LDAP_THREAD_SAFE )
- {"X_OPENLDAP_THREAD_SAFE", LDAP_API_FEATURE_X_OPENLDAP_THREAD_SAFE},
-#endif
-#ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_DNS
- {"X_OPENLDAP_V2_DNS", LDAP_API_FEATURE_X_OPENLDAP_V2_DNS},
+ { /* OpenLDAP Thread Safe */
+ LDAP_FEATURE_INFO_VERSION,
+ "X_OPENLDAP_THREAD_SAFE",
+ LDAP_API_FEATURE_X_OPENLDAP_THREAD_SAFE
+ },
#endif
#ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS
- {"X_OPENLDAP_V2_REFERRALS", LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS},
+ { /* V2 Referrals */
+ LDAP_FEATURE_INFO_VERSION,
+ "X_OPENLDAP_V2_REFERRALS",
+ LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS
+ },
#endif
- {NULL, 0}
+ {0, NULL, 0}
};
int
@@ -50,37 +97,46 @@ ldap_get_option(
{
struct ldapoptions *lo;
- if(!openldap_ldap_initialized) {
- openldap_ldap_initialize();
+ /* Get pointer to global option structure */
+ lo = LDAP_INT_GLOBAL_OPT();
+ if (NULL == lo) {
+ return LDAP_NO_MEMORY;
}
- if(outvalue == NULL) {
- /* no place to get to */
- return -1;
+ if( lo->ldo_valid != LDAP_INITIALIZED ) {
+ ldap_int_initialize(lo, NULL);
}
- if(ld == NULL) {
- lo = &openldap_ldap_global_options;
- } else {
+ if(ld != NULL) {
+ assert( LDAP_VALID( ld ) );
+
+ if( !LDAP_VALID( ld ) ) {
+ return LDAP_OPT_ERROR;
+ }
+
lo = &ld->ld_options;
}
+ if(outvalue == NULL) {
+ /* no place to get to */
+ return LDAP_OPT_ERROR;
+ }
+
switch(option) {
case LDAP_OPT_API_INFO: {
struct ldapapiinfo *info = (struct ldapapiinfo *) outvalue;
if(info == NULL) {
/* outvalue must point to an apiinfo structure */
- return -1;
+ return LDAP_OPT_ERROR;
}
if(info->ldapai_info_version != LDAP_API_INFO_VERSION) {
/* api info version mismatch */
info->ldapai_info_version = LDAP_API_INFO_VERSION;
- return -1;
+ return LDAP_OPT_ERROR;
}
- info->ldapai_api_version = LDAP_API_VERSION;
info->ldapai_api_version = LDAP_API_VERSION;
info->ldapai_protocol_version = LDAP_VERSION_MAX;
@@ -88,125 +144,196 @@ ldap_get_option(
info->ldapai_extensions = NULL;
} else {
int i;
- info->ldapai_extensions = malloc(sizeof(char *) *
+ info->ldapai_extensions = LDAP_MALLOC(sizeof(char *) *
sizeof(features)/sizeof(LDAPAPIFeatureInfo));
for(i=0; features[i].ldapaif_name != NULL; i++) {
info->ldapai_extensions[i] =
- strdup(features[i].ldapaif_name);
+ LDAP_STRDUP(features[i].ldapaif_name);
}
info->ldapai_extensions[i] = NULL;
}
- info->ldapai_vendor_name = strdup(LDAP_VENDOR_NAME);
+ info->ldapai_vendor_name = LDAP_STRDUP(LDAP_VENDOR_NAME);
info->ldapai_vendor_version = LDAP_VENDOR_VERSION;
- return 0;
+ return LDAP_OPT_SUCCESS;
} break;
case LDAP_OPT_DESC:
- if(ld == NULL) {
+ if( ld == NULL || ld->ld_sb == NULL ) {
/* bad param */
break;
}
- * (int *) outvalue = lber_pvt_sb_get_desc( &(ld->ld_sb) );
- return 0;
+ ber_sockbuf_ctrl( ld->ld_sb, LBER_SB_OPT_GET_FD, outvalue );
+ return LDAP_OPT_SUCCESS;
+
+ case LDAP_OPT_SOCKBUF:
+ if( ld == NULL ) break;
+ *(Sockbuf **)outvalue = ld->ld_sb;
+ return LDAP_OPT_SUCCESS;
+
+ case LDAP_OPT_TIMEOUT:
+ /* the caller has to free outvalue ! */
+ if ( lo->ldo_tm_api.tv_sec < 0 ) {
+ *(void **)outvalue = NULL;
+ } else if ( ldap_int_timeval_dup( outvalue, &lo->ldo_tm_api ) != 0 ) {
+ return LDAP_OPT_ERROR;
+ }
+ return LDAP_OPT_SUCCESS;
+
+ case LDAP_OPT_NETWORK_TIMEOUT:
+ /* the caller has to free outvalue ! */
+ if ( lo->ldo_tm_net.tv_sec < 0 ) {
+ *(void **)outvalue = NULL;
+ } else if ( ldap_int_timeval_dup( outvalue, &lo->ldo_tm_net ) != 0 ) {
+ return LDAP_OPT_ERROR;
+ }
+ return LDAP_OPT_SUCCESS;
case LDAP_OPT_DEREF:
* (int *) outvalue = lo->ldo_deref;
- return 0;
+ return LDAP_OPT_SUCCESS;
case LDAP_OPT_SIZELIMIT:
* (int *) outvalue = lo->ldo_sizelimit;
- return 0;
+ return LDAP_OPT_SUCCESS;
case LDAP_OPT_TIMELIMIT:
* (int *) outvalue = lo->ldo_timelimit;
- return 0;
+ return LDAP_OPT_SUCCESS;
case LDAP_OPT_REFERRALS:
* (int *) outvalue = (int) LDAP_BOOL_GET(lo, LDAP_BOOL_REFERRALS);
- return 0;
+ return LDAP_OPT_SUCCESS;
case LDAP_OPT_RESTART:
* (int *) outvalue = (int) LDAP_BOOL_GET(lo, LDAP_BOOL_RESTART);
- return 0;
-
- case LDAP_OPT_DNS: /* LDAPv2 */
- * (int *) outvalue = (int) LDAP_BOOL_GET(lo, LDAP_BOOL_DNS);
- return 0;
+ return LDAP_OPT_SUCCESS;
case LDAP_OPT_PROTOCOL_VERSION:
- if ((ld != NULL) && ld->ld_version) {
- * (int *) outvalue = ld->ld_version;
- } else {
- * (int *) outvalue = lo->ldo_version;
- }
- return 0;
+ * (int *) outvalue = lo->ldo_version;
+ return LDAP_OPT_SUCCESS;
case LDAP_OPT_SERVER_CONTROLS:
* (LDAPControl ***) outvalue =
- ldap_controls_dup( lo->ldo_server_controls );
+ ldap_controls_dup( lo->ldo_sctrls );
- return 0;
+ return LDAP_OPT_SUCCESS;
case LDAP_OPT_CLIENT_CONTROLS:
* (LDAPControl ***) outvalue =
- ldap_controls_dup( lo->ldo_client_controls );
+ ldap_controls_dup( lo->ldo_cctrls );
- return 0;
+ return LDAP_OPT_SUCCESS;
case LDAP_OPT_HOST_NAME:
- /*
- * draft-ietf-ldapext-ldap-c-api-01 doesn't state
- * whether caller has to free host names or not,
- * we do.
- */
+ * (char **) outvalue = ldap_url_list2hosts(lo->ldo_defludp);
+ return LDAP_OPT_SUCCESS;
- * (char **) outvalue = strdup(lo->ldo_defhost);
- return 0;
+ case LDAP_OPT_URI:
+ * (char **) outvalue = ldap_url_list2urls(lo->ldo_defludp);
+ return LDAP_OPT_SUCCESS;
- case LDAP_OPT_ERROR_NUMBER:
+ case LDAP_OPT_DEFBASE:
+ if( lo->ldo_defbase == NULL ) {
+ * (char **) outvalue = NULL;
+ } else {
+ * (char **) outvalue = LDAP_STRDUP(lo->ldo_defbase);
+ }
+
+ return LDAP_OPT_SUCCESS;
+
+ case LDAP_OPT_CONNECT_ASYNC:
+ * (int *) outvalue = (int) LDAP_BOOL_GET(lo, LDAP_BOOL_CONNECT_ASYNC);
+ return LDAP_OPT_SUCCESS;
+
+ case LDAP_OPT_CONNECT_CB:
+ {
+ /* Getting deletes the specified callback */
+ ldaplist **ll = &lo->ldo_conn_cbs;
+ for (;*ll;ll = &(*ll)->ll_next) {
+ if ((*ll)->ll_data == outvalue) {
+ ldaplist *lc = *ll;
+ *ll = lc->ll_next;
+ LDAP_FREE(lc);
+ break;
+ }
+ }
+ }
+ return LDAP_OPT_SUCCESS;
+
+ case LDAP_OPT_RESULT_CODE:
if(ld == NULL) {
/* bad param */
break;
}
* (int *) outvalue = ld->ld_errno;
- return 0;
+ return LDAP_OPT_SUCCESS;
- case LDAP_OPT_ERROR_STRING:
+ case LDAP_OPT_DIAGNOSTIC_MESSAGE:
if(ld == NULL) {
/* bad param */
break;
}
- /*
- * draft-ietf-ldapext-ldap-c-api-01 doesn't require
- * the client to have to free error strings, we do
- */
-
if( ld->ld_error == NULL ) {
* (char **) outvalue = NULL;
} else {
- * (char **) outvalue = strdup(ld->ld_error);
+ * (char **) outvalue = LDAP_STRDUP(ld->ld_error);
+ }
+
+ return LDAP_OPT_SUCCESS;
+
+ case LDAP_OPT_MATCHED_DN:
+ if(ld == NULL) {
+ /* bad param */
+ break;
+ }
+
+ if( ld->ld_matched == NULL ) {
+ * (char **) outvalue = NULL;
+ } else {
+ * (char **) outvalue = LDAP_STRDUP( ld->ld_matched );
+ }
+
+ return LDAP_OPT_SUCCESS;
+
+ case LDAP_OPT_REFERRAL_URLS:
+ if(ld == NULL) {
+ /* bad param */
+ break;
+ }
+
+ if( ld->ld_referrals == NULL ) {
+ * (char ***) outvalue = NULL;
+ } else {
+ * (char ***) outvalue = ldap_value_dup(ld->ld_referrals);
}
- return 0;
+ return LDAP_OPT_SUCCESS;
case LDAP_OPT_API_FEATURE_INFO: {
LDAPAPIFeatureInfo *info = (LDAPAPIFeatureInfo *) outvalue;
int i;
- if(info == NULL) return -1;
- if(info->ldapaif_name == NULL) return -1;
+ if(info == NULL) return LDAP_OPT_ERROR;
+
+ if(info->ldapaif_info_version != LDAP_FEATURE_INFO_VERSION) {
+ /* api info version mismatch */
+ info->ldapaif_info_version = LDAP_FEATURE_INFO_VERSION;
+ return LDAP_OPT_ERROR;
+ }
+
+ if(info->ldapaif_name == NULL) return LDAP_OPT_ERROR;
for(i=0; features[i].ldapaif_name != NULL; i++) {
if(!strcmp(info->ldapaif_name, features[i].ldapaif_name)) {
info->ldapaif_version =
features[i].ldapaif_version;
- return 0;
+ return LDAP_OPT_SUCCESS;
}
}
}
@@ -214,187 +341,468 @@ ldap_get_option(
case LDAP_OPT_DEBUG_LEVEL:
* (int *) outvalue = lo->ldo_debug;
- return 0;
+ return LDAP_OPT_SUCCESS;
default:
+#ifdef HAVE_TLS
+ if ( ldap_pvt_tls_get_option( ld, option, outvalue ) == 0 ) {
+ return LDAP_OPT_SUCCESS;
+ }
+#endif
+#ifdef HAVE_CYRUS_SASL
+ if ( ldap_int_sasl_get_option( ld, option, outvalue ) == 0 ) {
+ return LDAP_OPT_SUCCESS;
+ }
+#endif
+#ifdef HAVE_GSSAPI
+ if ( ldap_int_gssapi_get_option( ld, option, outvalue ) == 0 ) {
+ return LDAP_OPT_SUCCESS;
+ }
+#endif
/* bad param */
break;
}
- return -1;
+ return LDAP_OPT_ERROR;
}
int
ldap_set_option(
LDAP *ld,
int option,
- void *invalue)
+ LDAP_CONST void *invalue)
{
struct ldapoptions *lo;
+ int *dbglvl = NULL;
- if(!openldap_ldap_initialized) {
- openldap_ldap_initialize();
+ /* Get pointer to global option structure */
+ lo = LDAP_INT_GLOBAL_OPT();
+ if (lo == NULL) {
+ return LDAP_NO_MEMORY;
}
- if(invalue == NULL) {
- /* no place to set from */
- return -1;
- }
+ /*
+ * The architecture to turn on debugging has a chicken and egg
+ * problem. Thus, we introduce a fix here.
+ */
- if(ld == NULL) {
- lo = &openldap_ldap_global_options;
- } else {
- lo = &ld->ld_options;
+ if (option == LDAP_OPT_DEBUG_LEVEL) {
+ dbglvl = (int *) invalue;
}
- switch(option) {
- case LDAP_OPT_API_INFO:
- case LDAP_OPT_DESC:
- /* READ ONLY */
- break;
+ if( lo->ldo_valid != LDAP_INITIALIZED ) {
+ ldap_int_initialize(lo, dbglvl);
+ }
- case LDAP_OPT_DEREF:
- lo->ldo_deref = * (int *) invalue;
- return 0;
+ if(ld != NULL) {
+ assert( LDAP_VALID( ld ) );
- case LDAP_OPT_SIZELIMIT:
- lo->ldo_sizelimit = * (int *) invalue;
- return 0;
+ if( !LDAP_VALID( ld ) ) {
+ return LDAP_OPT_ERROR;
+ }
- case LDAP_OPT_TIMELIMIT:
- lo->ldo_timelimit = * (int *) invalue;
- return 0;
+ lo = &ld->ld_options;
+ }
+ switch(option) {
case LDAP_OPT_REFERRALS:
- if((int) invalue == (int) LDAP_OPT_ON) {
- LDAP_BOOL_SET(lo, LDAP_BOOL_REFERRALS);
- } else {
+ if(invalue == LDAP_OPT_OFF) {
LDAP_BOOL_CLR(lo, LDAP_BOOL_REFERRALS);
+ } else {
+ LDAP_BOOL_SET(lo, LDAP_BOOL_REFERRALS);
}
- return 0;
+ return LDAP_OPT_SUCCESS;
case LDAP_OPT_RESTART:
- if((int) invalue == (int) LDAP_OPT_ON) {
- LDAP_BOOL_SET(lo, LDAP_BOOL_RESTART);
- } else {
+ if(invalue == LDAP_OPT_OFF) {
LDAP_BOOL_CLR(lo, LDAP_BOOL_RESTART);
+ } else {
+ LDAP_BOOL_SET(lo, LDAP_BOOL_RESTART);
}
- return 0;
+ return LDAP_OPT_SUCCESS;
- case LDAP_OPT_PROTOCOL_VERSION: {
- int vers = * (int *) invalue;
- if (vers < LDAP_VERSION_MIN || vers > LDAP_VERSION_MAX) {
- /* not supported */
- break;
- }
- ld->ld_version = vers;
- } return 0;
+ case LDAP_OPT_CONNECT_ASYNC:
+ if(invalue == LDAP_OPT_OFF) {
+ LDAP_BOOL_CLR(lo, LDAP_BOOL_CONNECT_ASYNC);
+ } else {
+ LDAP_BOOL_SET(lo, LDAP_BOOL_CONNECT_ASYNC);
+ }
+ return LDAP_OPT_SUCCESS;
+ }
+ /* options which can withstand invalue == NULL */
+ switch ( option ) {
case LDAP_OPT_SERVER_CONTROLS: {
- LDAPControl **controls = (LDAPControl **) invalue;
+ LDAPControl *const *controls =
+ (LDAPControl *const *) invalue;
- ldap_controls_free( lo->ldo_server_controls );
+ if( lo->ldo_sctrls )
+ ldap_controls_free( lo->ldo_sctrls );
if( controls == NULL || *controls == NULL ) {
- lo->ldo_server_controls = NULL;
- return 0;
+ lo->ldo_sctrls = NULL;
+ return LDAP_OPT_SUCCESS;
}
- lo->ldo_server_controls =
- ldap_controls_dup( (LDAPControl **) invalue );
+ lo->ldo_sctrls = ldap_controls_dup( controls );
- if(lo->ldo_server_controls == NULL) {
+ if(lo->ldo_sctrls == NULL) {
/* memory allocation error ? */
break;
}
- } return 0;
+ } return LDAP_OPT_SUCCESS;
case LDAP_OPT_CLIENT_CONTROLS: {
- LDAPControl **controls = (LDAPControl **) invalue;
+ LDAPControl *const *controls =
+ (LDAPControl *const *) invalue;
- ldap_controls_free( lo->ldo_client_controls );
+ if( lo->ldo_cctrls )
+ ldap_controls_free( lo->ldo_cctrls );
if( controls == NULL || *controls == NULL ) {
- lo->ldo_client_controls = NULL;
- return 0;
+ lo->ldo_cctrls = NULL;
+ return LDAP_OPT_SUCCESS;
}
- lo->ldo_client_controls =
- ldap_controls_dup( (LDAPControl **) invalue );
+ lo->ldo_cctrls = ldap_controls_dup( controls );
- if(lo->ldo_client_controls == NULL) {
+ if(lo->ldo_cctrls == NULL) {
/* memory allocation error ? */
break;
}
- } return 0;
+ } return LDAP_OPT_SUCCESS;
+
case LDAP_OPT_HOST_NAME: {
- char* host = (char *) invalue;
+ const char *host = (const char *) invalue;
+ LDAPURLDesc *ludlist = NULL;
+ int rc = LDAP_OPT_SUCCESS;
+
+ if(host != NULL) {
+ rc = ldap_url_parsehosts( &ludlist, host,
+ lo->ldo_defport ? lo->ldo_defport : LDAP_PORT );
+
+ } else if(ld == NULL) {
+ /*
+ * must want global default returned
+ * to initial condition.
+ */
+ rc = ldap_url_parselist_ext(&ludlist, "ldap://localhost/", NULL,
+ LDAP_PVT_URL_PARSE_NOEMPTY_HOST
+ | LDAP_PVT_URL_PARSE_DEF_PORT );
- if(lo->ldo_defhost != NULL) {
- free(lo->ldo_defhost);
- lo->ldo_defhost = NULL;
+ } else {
+ /*
+ * must want the session default
+ * updated to the current global default
+ */
+ ludlist = ldap_url_duplist(
+ ldap_int_global_options.ldo_defludp);
+ if (ludlist == NULL)
+ rc = LDAP_NO_MEMORY;
}
- if(host != NULL) {
- lo->ldo_defhost = strdup(host);
- return 0;
+ if (rc == LDAP_OPT_SUCCESS) {
+ if (lo->ldo_defludp != NULL)
+ ldap_free_urllist(lo->ldo_defludp);
+ lo->ldo_defludp = ludlist;
}
+ return rc;
+ }
- if(ld == NULL) {
+ case LDAP_OPT_URI: {
+ const char *urls = (const char *) invalue;
+ LDAPURLDesc *ludlist = NULL;
+ int rc = LDAP_OPT_SUCCESS;
+
+ if(urls != NULL) {
+ rc = ldap_url_parselist_ext(&ludlist, urls, NULL,
+ LDAP_PVT_URL_PARSE_NOEMPTY_HOST
+ | LDAP_PVT_URL_PARSE_DEF_PORT );
+ } else if(ld == NULL) {
/*
* must want global default returned
* to initial condition.
*/
- lo->ldo_defhost = strdup("localhost");
+ rc = ldap_url_parselist_ext(&ludlist, "ldap://localhost/", NULL,
+ LDAP_PVT_URL_PARSE_NOEMPTY_HOST
+ | LDAP_PVT_URL_PARSE_DEF_PORT );
} else {
/*
* must want the session default
* updated to the current global default
*/
- lo->ldo_defhost = strdup(
- openldap_ldap_global_options.ldo_defhost);
+ ludlist = ldap_url_duplist(
+ ldap_int_global_options.ldo_defludp);
+ if (ludlist == NULL)
+ rc = LDAP_URL_ERR_MEM;
}
- } return 0;
- case LDAP_OPT_ERROR_NUMBER: {
- int err = * (int *) invalue;
+ switch (rc) {
+ case LDAP_URL_SUCCESS: /* Success */
+ rc = LDAP_SUCCESS;
+ break;
- if(ld == NULL) {
- /* need a struct ldap */
+ case LDAP_URL_ERR_MEM: /* can't allocate memory space */
+ rc = LDAP_NO_MEMORY;
+ break;
+
+ case LDAP_URL_ERR_PARAM: /* parameter is bad */
+ case LDAP_URL_ERR_BADSCHEME: /* URL doesn't begin with "ldap[si]://" */
+ case LDAP_URL_ERR_BADENCLOSURE: /* URL is missing trailing ">" */
+ case LDAP_URL_ERR_BADURL: /* URL is bad */
+ case LDAP_URL_ERR_BADHOST: /* host port is bad */
+ case LDAP_URL_ERR_BADATTRS: /* bad (or missing) attributes */
+ case LDAP_URL_ERR_BADSCOPE: /* scope string is invalid (or missing) */
+ case LDAP_URL_ERR_BADFILTER: /* bad or missing filter */
+ case LDAP_URL_ERR_BADEXTS: /* bad or missing extensions */
+ rc = LDAP_PARAM_ERROR;
break;
}
- ld->ld_errno = err;
- } return 0;
+ if (rc == LDAP_SUCCESS) {
+ if (lo->ldo_defludp != NULL)
+ ldap_free_urllist(lo->ldo_defludp);
+ lo->ldo_defludp = ludlist;
+ }
+ return rc;
+ }
- case LDAP_OPT_ERROR_STRING: {
- char* err = (char *) invalue;
+ case LDAP_OPT_DEFBASE: {
+ const char *newbase = (const char *) invalue;
+ char *defbase = NULL;
+
+ if ( newbase != NULL ) {
+ defbase = LDAP_STRDUP( newbase );
+ if ( defbase == NULL ) return LDAP_NO_MEMORY;
+
+ } else if ( ld != NULL ) {
+ defbase = LDAP_STRDUP( ldap_int_global_options.ldo_defbase );
+ if ( defbase == NULL ) return LDAP_NO_MEMORY;
+ }
+
+ if ( lo->ldo_defbase != NULL )
+ LDAP_FREE( lo->ldo_defbase );
+ lo->ldo_defbase = defbase;
+ } return LDAP_OPT_SUCCESS;
+
+ case LDAP_OPT_DIAGNOSTIC_MESSAGE: {
+ const char *err = (const char *) invalue;
if(ld == NULL) {
/* need a struct ldap */
- break;
+ return LDAP_OPT_ERROR;
}
if( ld->ld_error ) {
- free(ld->ld_error);
+ LDAP_FREE(ld->ld_error);
+ ld->ld_error = NULL;
}
- ld->ld_error = strdup(err);
- } return 0;
+ if ( err ) {
+ ld->ld_error = LDAP_STRDUP(err);
+ }
+ } return LDAP_OPT_SUCCESS;
+ case LDAP_OPT_MATCHED_DN: {
+ const char *matched = (const char *) invalue;
+
+ if (ld == NULL) {
+ /* need a struct ldap */
+ return LDAP_OPT_ERROR;
+ }
+
+ if( ld->ld_matched ) {
+ LDAP_FREE(ld->ld_matched);
+ ld->ld_matched = NULL;
+ }
+
+ if ( matched ) {
+ ld->ld_matched = LDAP_STRDUP( matched );
+ }
+ } return LDAP_OPT_SUCCESS;
+
+ case LDAP_OPT_REFERRAL_URLS: {
+ char *const *referrals = (char *const *) invalue;
+
+ if(ld == NULL) {
+ /* need a struct ldap */
+ return LDAP_OPT_ERROR;
+ }
+
+ if( ld->ld_referrals ) {
+ LDAP_VFREE(ld->ld_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;
+
+ /* Only accessed from inside this function by ldap_set_urllist_proc() */
+ case LDAP_OPT_URLLIST_PROC: {
+ lo->ldo_urllist_proc = (LDAP_URLLIST_PROC *)invalue;
+ } return LDAP_OPT_SUCCESS;
+ case LDAP_OPT_URLLIST_PARAMS: {
+ lo->ldo_urllist_params = (void *)invalue;
+ } return LDAP_OPT_SUCCESS;
+
+ /* read-only options */
+ case LDAP_OPT_API_INFO:
+ case LDAP_OPT_DESC:
+ case LDAP_OPT_SOCKBUF:
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_RESULT_CODE:
case LDAP_OPT_DEBUG_LEVEL:
- lo->ldo_debug = * (int *) invalue;
- return 0;
+ case LDAP_OPT_TIMEOUT:
+ case LDAP_OPT_NETWORK_TIMEOUT:
+ case LDAP_OPT_CONNECT_CB:
+ if(invalue == NULL) {
+ /* no place to set from */
+ return LDAP_OPT_ERROR;
+ }
+ break;
default:
+#ifdef HAVE_TLS
+ if ( ldap_pvt_tls_set_option( ld, option, (void *)invalue ) == 0 )
+ return LDAP_OPT_SUCCESS;
+#endif
+#ifdef HAVE_CYRUS_SASL
+ if ( ldap_int_sasl_set_option( ld, option, (void *)invalue ) == 0 )
+ return LDAP_OPT_SUCCESS;
+#endif
+#ifdef HAVE_GSSAPI
+ if ( ldap_int_gssapi_set_option( ld, option, (void *)invalue ) == 0 )
+ return LDAP_OPT_SUCCESS;
+#endif
/* bad param */
- break;
+ return LDAP_OPT_ERROR;
}
- return -1;
+
+ /* options which cannot withstand invalue == NULL */
+
+ switch(option) {
+ case LDAP_OPT_DEREF:
+ /* FIXME: check value for protocol compliance? */
+ lo->ldo_deref = * (const int *) invalue;
+ return LDAP_OPT_SUCCESS;
+
+ case LDAP_OPT_SIZELIMIT:
+ /* FIXME: check value for protocol compliance? */
+ lo->ldo_sizelimit = * (const int *) invalue;
+ return LDAP_OPT_SUCCESS;
+
+ case LDAP_OPT_TIMELIMIT:
+ /* FIXME: check value for protocol compliance? */
+ lo->ldo_timelimit = * (const int *) invalue;
+ return LDAP_OPT_SUCCESS;
+
+ case LDAP_OPT_TIMEOUT: {
+ const struct timeval *tv =
+ (const struct timeval *) invalue;
+
+ lo->ldo_tm_api = *tv;
+ } return LDAP_OPT_SUCCESS;
+
+ case LDAP_OPT_NETWORK_TIMEOUT: {
+ const struct timeval *tv =
+ (const struct timeval *) invalue;
+
+ lo->ldo_tm_net = *tv;
+ } 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_RESULT_CODE: {
+ 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;
+
+ case LDAP_OPT_CONNECT_CB:
+ {
+ /* setting pushes the callback */
+ ldaplist *ll;
+ ll = LDAP_MALLOC( sizeof( *ll ));
+ ll->ll_data = (void *)invalue;
+ ll->ll_next = lo->ldo_conn_cbs;
+ lo->ldo_conn_cbs = ll;
+ }
+ return LDAP_OPT_SUCCESS;
+ }
+ return LDAP_OPT_ERROR;
+}
+
+int
+ldap_set_rebind_proc( LDAP *ld, LDAP_REBIND_PROC *proc, void *params )
+{
+ 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;
+}
+
+int
+ldap_set_nextref_proc( LDAP *ld, LDAP_NEXTREF_PROC *proc, void *params )
+{
+ int rc;
+ rc = ldap_set_option( ld, LDAP_OPT_NEXTREF_PROC, (void *)proc );
+ if( rc != LDAP_OPT_SUCCESS ) return rc;
+
+ rc = ldap_set_option( ld, LDAP_OPT_NEXTREF_PARAMS, (void *)params );
+ return rc;
+}
+
+int
+ldap_set_urllist_proc( LDAP *ld, LDAP_URLLIST_PROC *proc, void *params )
+{
+ int rc;
+ rc = ldap_set_option( ld, LDAP_OPT_URLLIST_PROC, (void *)proc );
+ if( rc != LDAP_OPT_SUCCESS ) return rc;
+
+ rc = ldap_set_option( ld, LDAP_OPT_URLLIST_PARAMS, (void *)params );
+ return rc;
}