2 * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
3 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
11 #include <ac/socket.h>
12 #include <ac/string.h>
16 static const LDAPAPIFeatureInfo features[] = {
17 #ifdef LDAP_API_FEATURE_INFO
18 {"INFO", LDAP_API_FEATURE_INFO},
20 #ifdef LDAP_API_FEATURE_THREAD_SAFE
21 {"THREAD_SAFE", LDAP_API_FEATURE_THREAD_SAFE},
23 #ifdef LDAP_API_FEATURE_SESSION_THREAD_SAFE
24 {"SESSION_THREAD_SAFE", LDAP_API_FEATURE_SESSION_THREAD_SAFE},
26 #ifdef LDAP_API_FEATURE_OPERATION_THREAD_SAFE
27 {"OPERATION_THREAD_SAFE", LDAP_API_FEATURE_OPERATION_THREAD_SAFE},
29 #ifdef LDAP_API_FEATURE_X_OPENLDAP_REEENTRANT
30 {"X_OPENLDAP_REENTRANT", LDAP_API_FEATURE_X_OPENLDAP_REENTRANT},
32 #if defined( LDAP_API_FEATURE_X_OPENLDAP_THREAD_SAFE ) && \
33 defined( LDAP_THREAD_SAFE )
34 {"X_OPENLDAP_THREAD_SAFE", LDAP_API_FEATURE_X_OPENLDAP_THREAD_SAFE},
36 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_DNS
37 {"X_OPENLDAP_V2_DNS", LDAP_API_FEATURE_X_OPENLDAP_V2_DNS},
39 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS
40 {"X_OPENLDAP_V2_REFERRALS", LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS},
51 struct ldapoptions *lo;
53 if(!openldap_ldap_initialized) {
54 openldap_ldap_initialize();
57 if(outvalue == NULL) {
58 /* no place to get to */
63 lo = &openldap_ldap_global_options;
69 case LDAP_OPT_API_INFO: {
70 struct ldapapiinfo *info = (struct ldapapiinfo *) outvalue;
73 /* outvalue must point to an apiinfo structure */
77 if(info->ldapai_info_version != LDAP_API_INFO_VERSION) {
78 /* api info version mismatch */
79 info->ldapai_info_version = LDAP_API_INFO_VERSION;
83 info->ldapai_api_version = LDAP_API_VERSION;
84 info->ldapai_api_version = LDAP_API_VERSION;
85 info->ldapai_protocol_version = LDAP_VERSION_MAX;
87 if(features[0].ldapaif_name == NULL) {
88 info->ldapai_extensions = NULL;
91 info->ldapai_extensions = malloc(sizeof(char *) *
92 sizeof(features)/sizeof(LDAPAPIFeatureInfo));
94 for(i=0; features[i].ldapaif_name != NULL; i++) {
95 info->ldapai_extensions[i] =
96 strdup(features[i].ldapaif_name);
99 info->ldapai_extensions[i] = NULL;
102 info->ldapai_vendor_name = strdup(LDAP_VENDOR_NAME);
103 info->ldapai_vendor_version = LDAP_VENDOR_VERSION;
114 * (int *) outvalue = lber_pvt_sb_get_desc( &(ld->ld_sb) );
118 * (int *) outvalue = lo->ldo_deref;
121 case LDAP_OPT_SIZELIMIT:
122 * (int *) outvalue = lo->ldo_sizelimit;
125 case LDAP_OPT_TIMELIMIT:
126 * (int *) outvalue = lo->ldo_timelimit;
129 case LDAP_OPT_REFERRALS:
130 * (int *) outvalue = (LDAP_BOOL_GET(lo, LDAP_BOOL_REFERRALS) ==
134 case LDAP_OPT_RESTART:
135 * (int *) outvalue = (LDAP_BOOL_GET(lo, LDAP_BOOL_RESTART) ==
139 case LDAP_OPT_DNS: /* LDAPv2 */
140 * (int *) outvalue = (LDAP_BOOL_GET(lo, LDAP_BOOL_DNS) ==
144 case LDAP_OPT_PROTOCOL_VERSION:
145 if ((ld != NULL) && ld->ld_version) {
146 * (int *) outvalue = ld->ld_version;
148 * (int *) outvalue = lo->ldo_version;
152 case LDAP_OPT_SERVER_CONTROLS:
153 * (LDAPControl ***) outvalue =
154 ldap_controls_dup( lo->ldo_server_controls );
158 case LDAP_OPT_CLIENT_CONTROLS:
159 * (LDAPControl ***) outvalue =
160 ldap_controls_dup( lo->ldo_client_controls );
164 case LDAP_OPT_HOST_NAME:
166 * draft-ietf-ldapext-ldap-c-api-01 doesn't state
167 * whether caller has to free host names or not,
171 * (char **) outvalue = strdup(lo->ldo_defhost);
174 case LDAP_OPT_ERROR_NUMBER:
179 * (int *) outvalue = ld->ld_errno;
182 case LDAP_OPT_ERROR_STRING:
189 * draft-ietf-ldapext-ldap-c-api-01 doesn't require
190 * the client to have to free error strings, we do
193 if( ld->ld_error == NULL ) {
194 * (char **) outvalue = NULL;
196 * (char **) outvalue = strdup(ld->ld_error);
201 case LDAP_OPT_API_FEATURE_INFO: {
202 LDAPAPIFeatureInfo *info = (LDAPAPIFeatureInfo *) outvalue;
205 if(info == NULL) return -1;
206 if(info->ldapaif_name == NULL) return -1;
208 for(i=0; features[i].ldapaif_name != NULL; i++) {
209 if(!strcmp(info->ldapaif_name, features[i].ldapaif_name)) {
210 info->ldapaif_version =
211 features[i].ldapaif_version;
218 case LDAP_OPT_DEBUG_LEVEL:
219 * (int *) outvalue = lo->ldo_debug;
236 struct ldapoptions *lo;
238 if(!openldap_ldap_initialized) {
239 openldap_ldap_initialize();
243 lo = &openldap_ldap_global_options;
245 lo = &ld->ld_options;
249 case LDAP_OPT_REFERRALS:
250 if(invalue == LDAP_OPT_ON) {
251 LDAP_BOOL_SET(lo, LDAP_BOOL_REFERRALS);
253 LDAP_BOOL_CLR(lo, LDAP_BOOL_REFERRALS);
257 case LDAP_OPT_RESTART:
258 if(invalue == LDAP_OPT_ON) {
259 LDAP_BOOL_SET(lo, LDAP_BOOL_RESTART);
261 LDAP_BOOL_CLR(lo, LDAP_BOOL_RESTART);
266 if(invalue == NULL) {
267 /* no place to set from */
272 case LDAP_OPT_API_INFO:
278 lo->ldo_deref = * (int *) invalue;
281 case LDAP_OPT_SIZELIMIT:
282 lo->ldo_sizelimit = * (int *) invalue;
285 case LDAP_OPT_TIMELIMIT:
286 lo->ldo_timelimit = * (int *) invalue;
289 case LDAP_OPT_PROTOCOL_VERSION: {
290 int vers = * (int *) invalue;
291 if (vers < LDAP_VERSION_MIN || vers > LDAP_VERSION_MAX) {
295 ld->ld_version = vers;
298 case LDAP_OPT_SERVER_CONTROLS: {
299 LDAPControl **controls = (LDAPControl **) invalue;
301 ldap_controls_free( lo->ldo_server_controls );
303 if( controls == NULL || *controls == NULL ) {
304 lo->ldo_server_controls = NULL;
308 lo->ldo_server_controls =
309 ldap_controls_dup( (LDAPControl **) invalue );
311 if(lo->ldo_server_controls == NULL) {
312 /* memory allocation error ? */
317 case LDAP_OPT_CLIENT_CONTROLS: {
318 LDAPControl **controls = (LDAPControl **) invalue;
320 ldap_controls_free( lo->ldo_client_controls );
322 if( controls == NULL || *controls == NULL ) {
323 lo->ldo_client_controls = NULL;
327 lo->ldo_client_controls =
328 ldap_controls_dup( (LDAPControl **) invalue );
330 if(lo->ldo_client_controls == NULL) {
331 /* memory allocation error ? */
336 case LDAP_OPT_HOST_NAME: {
337 char* host = (char *) invalue;
339 if(lo->ldo_defhost != NULL) {
340 free(lo->ldo_defhost);
341 lo->ldo_defhost = NULL;
345 lo->ldo_defhost = strdup(host);
351 * must want global default returned
352 * to initial condition.
354 lo->ldo_defhost = strdup("localhost");
358 * must want the session default
359 * updated to the current global default
361 lo->ldo_defhost = strdup(
362 openldap_ldap_global_options.ldo_defhost);
366 case LDAP_OPT_ERROR_NUMBER: {
367 int err = * (int *) invalue;
370 /* need a struct ldap */
377 case LDAP_OPT_ERROR_STRING: {
378 char* err = (char *) invalue;
381 /* need a struct ldap */
389 ld->ld_error = strdup(err);
392 case LDAP_OPT_API_FEATURE_INFO:
396 case LDAP_OPT_DEBUG_LEVEL:
397 lo->ldo_debug = * (int *) invalue;