11 static const char* features[] = {
12 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_DNS
15 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS
16 "X_OPENLDAP_V2_REFERRALS",
27 struct ldapoptions *lo;
29 if(!openldap_ldap_initialized) {
30 openldap_ldap_initialize();
33 if(outvalue == NULL) {
34 /* no place to get to */
39 lo = &openldap_ldap_global_options;
45 case LDAP_OPT_API_INFO: {
46 struct ldapapiinfo *info = (struct ldapapiinfo *) outvalue;
49 /* outvalue must point to an apiinfo structure */
53 if(info->ldapai_info_version != LDAP_API_INFO_VERSION) {
54 /* api info version mismatch */
55 info->ldapai_info_version = LDAP_API_INFO_VERSION;
59 info->ldapai_api_version = LDAP_API_VERSION;
60 info->ldapai_api_version = LDAP_API_VERSION;
61 info->ldapai_protocol_version = LDAP_VERSION_MAX;
62 if(features[0] == NULL) {
63 info->ldapai_extensions = NULL;
66 info->ldapai_extensions = malloc(sizeof(features));
68 for(i=0; features[i] != NULL; i++) {
69 info->ldapai_extensions[i] = strdup(features[i]);
72 info->ldapai_extensions[i] = NULL;
75 info->ldapai_vendor_name = strdup(LDAP_VENDOR_NAME);
76 info->ldapai_vendor_version = LDAP_VENDOR_VERSION;
87 * (int *) outvalue = ld->ld_sb.sb_sd;
91 * (int *) outvalue = lo->ldo_deref;
94 case LDAP_OPT_SIZELIMIT:
95 * (int *) outvalue = lo->ldo_sizelimit;
98 case LDAP_OPT_TIMELIMIT:
99 * (int *) outvalue = lo->ldo_timelimit;
102 case LDAP_OPT_REFERRALS:
103 * (int *) outvalue = (int) LDAP_BOOL_GET(lo, LDAP_BOOL_REFERRALS);
106 case LDAP_OPT_RESTART:
107 * (int *) outvalue = (int) LDAP_BOOL_GET(lo, LDAP_BOOL_RESTART);
110 case LDAP_OPT_DNS: /* LDAPv2 */
111 * (int *) outvalue = (int) LDAP_BOOL_GET(lo, LDAP_BOOL_DNS);
114 case LDAP_OPT_PROTOCOL_VERSION:
115 if ((ld != NULL) && ld->ld_version) {
116 * (int *) outvalue = ld->ld_version;
118 * (int *) outvalue = lo->ldo_version;
122 case LDAP_OPT_SERVER_CONTROLS:
123 case LDAP_OPT_CLIENT_CONTROLS:
124 /* not yet supported */
127 case LDAP_OPT_HOST_NAME:
129 * draft-ietf-ldapext-ldap-c-api-01 doesn't state
130 * whether client to have to free host names or no,
134 * (char **) outvalue = strdup(lo->ldo_defhost);
137 case LDAP_OPT_ERROR_NUMBER:
142 * (int *) outvalue = ld->ld_errno;
145 case LDAP_OPT_ERROR_STRING:
146 /* not yet supported */
153 * draft-ietf-ldapext-ldap-c-api-01 doesn't require
154 * the client to have to free error strings, we do
157 if( ld->ld_error == NULL ) {
158 * (char **) outvalue = NULL;
160 * (char **) outvalue = strdup(ld->ld_error);
178 struct ldapoptions *lo;
180 if(!openldap_ldap_initialized) {
181 openldap_ldap_initialize();
184 if(invalue == NULL) {
185 /* no place to set from */
190 lo = &openldap_ldap_global_options;
192 lo = &ld->ld_options;
196 case LDAP_OPT_API_INFO:
202 lo->ldo_deref = * (int *) invalue;
205 case LDAP_OPT_SIZELIMIT:
206 lo->ldo_sizelimit = * (int *) invalue;
209 case LDAP_OPT_TIMELIMIT:
210 lo->ldo_timelimit = * (int *) invalue;
213 case LDAP_OPT_REFERRALS:
214 if((int) invalue == (int) LDAP_OPT_ON) {
215 LDAP_BOOL_SET(lo, LDAP_BOOL_REFERRALS);
217 LDAP_BOOL_CLR(lo, LDAP_BOOL_REFERRALS);
221 case LDAP_OPT_RESTART:
222 if((int) invalue == (int) LDAP_OPT_ON) {
223 LDAP_BOOL_SET(lo, LDAP_BOOL_RESTART);
225 LDAP_BOOL_CLR(lo, LDAP_BOOL_RESTART);
229 case LDAP_OPT_PROTOCOL_VERSION: {
230 int vers = * (int *) invalue;
231 if (vers < LDAP_VERSION_MIN || vers > LDAP_VERSION_MAX) {
235 ld->ld_version = vers;
238 case LDAP_OPT_SERVER_CONTROLS:
239 case LDAP_OPT_CLIENT_CONTROLS:
240 /* not yet supported */
243 case LDAP_OPT_HOST_NAME: {
244 char* host = * (char **) invalue;
246 if(lo->ldo_defhost != NULL) {
247 free(lo->ldo_defhost);
248 lo->ldo_defhost = NULL;
252 lo->ldo_defhost = strdup(host);
258 * must want global default returned
259 * to initial condition.
261 lo->ldo_defhost = strdup("localhost");
265 * must want the session default
266 * updated to the current global default
268 lo->ldo_defhost = strdup(
269 openldap_ldap_global_options.ldo_defhost);
273 case LDAP_OPT_ERROR_NUMBER: {
274 int err = * (int *) invalue;
278 /* we only allow ld_errno to be cleared. */
283 /* need a struct ldap */
290 case LDAP_OPT_ERROR_STRING: {
291 char* err = * (char **) invalue;
295 /* we only allow ld_error to be cleared. */
300 /* need a struct ldap */