1998-11-04 09:41:00 +08:00
|
|
|
#include "portable.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include <ac/socket.h>
|
|
|
|
#include <ac/string.h>
|
|
|
|
|
|
|
|
#include "ldap-int.h"
|
|
|
|
|
|
|
|
int
|
|
|
|
ldap_get_option(
|
1998-11-10 02:40:37 +08:00
|
|
|
LDAP *ld,
|
1998-11-04 09:41:00 +08:00
|
|
|
int option,
|
|
|
|
void *outvalue)
|
|
|
|
{
|
1998-11-10 02:40:37 +08:00
|
|
|
struct ldapoptions *lo;
|
1998-11-04 09:41:00 +08:00
|
|
|
|
|
|
|
if(!openldap_ldap_initialized) {
|
|
|
|
openldap_ldap_initialize();
|
|
|
|
}
|
|
|
|
|
|
|
|
if(outvalue == NULL) {
|
|
|
|
/* no place to get to */
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
1998-11-10 02:40:37 +08:00
|
|
|
if(ld == NULL) {
|
|
|
|
lo = &openldap_ldap_global_options;
|
1998-11-04 09:41:00 +08:00
|
|
|
} else {
|
1998-11-10 02:40:37 +08:00
|
|
|
lo = &ld->ld_options;
|
1998-11-04 09:41:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
1998-11-05 04:08:37 +08:00
|
|
|
if(info->ldapai_info_version != LDAP_API_INFO_VERSION) {
|
|
|
|
/* api info version mismatch */
|
|
|
|
info->ldapai_info_version = LDAP_API_INFO_VERSION;
|
1998-11-04 09:41:00 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
1998-11-05 04:08:37 +08:00
|
|
|
info->ldapai_api_version = LDAP_API_VERSION;
|
1998-11-04 09:41:00 +08:00
|
|
|
info->ldapai_api_version = LDAP_API_VERSION;
|
|
|
|
info->ldapai_protocol_version = LDAP_VERSION_MAX;
|
|
|
|
info->ldapai_extensions = NULL;
|
1998-11-05 04:08:37 +08:00
|
|
|
info->ldapai_vendor_name = strdup(LDAP_VENDOR_NAME);
|
1998-11-04 09:41:00 +08:00
|
|
|
info->ldapai_vendor_version = LDAP_VENDOR_VERSION;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case LDAP_OPT_DESC:
|
1998-11-10 02:40:37 +08:00
|
|
|
if(ld == NULL) {
|
1998-11-04 09:41:00 +08:00
|
|
|
/* bad param */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
* (int *) outvalue = ld->ld_sb.sb_sd;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case LDAP_OPT_DEREF:
|
1998-11-10 02:40:37 +08:00
|
|
|
* (int *) outvalue = lo->ldo_deref;
|
1998-11-04 09:41:00 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
case LDAP_OPT_SIZELIMIT:
|
1998-11-10 02:40:37 +08:00
|
|
|
* (int *) outvalue = lo->ldo_sizelimit;
|
1998-11-04 09:41:00 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
case LDAP_OPT_TIMELIMIT:
|
1998-11-10 02:40:37 +08:00
|
|
|
* (int *) outvalue = lo->ldo_timelimit;
|
1998-11-04 09:41:00 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
case LDAP_OPT_REFERRALS:
|
1998-11-10 02:40:37 +08:00
|
|
|
* (int *) outvalue = (int) LDAP_BOOL_GET(lo, LDAP_BOOL_REFERRALS);
|
1998-11-04 09:41:00 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
case LDAP_OPT_RESTART:
|
1998-11-10 02:40:37 +08:00
|
|
|
* (int *) outvalue = (int) LDAP_BOOL_GET(lo, LDAP_BOOL_RESTART);
|
1998-11-04 09:41:00 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
case LDAP_OPT_DNS: /* LDAPv2 */
|
1998-11-10 02:40:37 +08:00
|
|
|
* (int *) outvalue = (int) LDAP_BOOL_GET(lo, LDAP_BOOL_DNS);
|
1998-11-04 09:41:00 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
case LDAP_OPT_PROTOCOL_VERSION:
|
1998-11-10 02:40:37 +08:00
|
|
|
if(ld == NULL) {
|
|
|
|
/* bad param */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1998-11-04 09:41:00 +08:00
|
|
|
* (int *) outvalue = ld->ld_version;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case LDAP_OPT_SERVER_CONTROLS:
|
|
|
|
case LDAP_OPT_CLIENT_CONTROLS:
|
|
|
|
/* not yet supported */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LDAP_OPT_HOST_NAME:
|
1998-11-10 02:40:37 +08:00
|
|
|
if(ld == NULL) {
|
|
|
|
/* bad param */
|
|
|
|
break;
|
|
|
|
}
|
1998-11-04 09:41:00 +08:00
|
|
|
* (char **) outvalue = ld->ld_host;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case LDAP_OPT_ERROR_NUMBER:
|
1998-11-10 02:40:37 +08:00
|
|
|
if(ld == NULL) {
|
|
|
|
/* bad param */
|
|
|
|
break;
|
|
|
|
}
|
1998-11-04 09:41:00 +08:00
|
|
|
* (int *) outvalue = ld->ld_errno;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case LDAP_OPT_ERROR_STRING:
|
|
|
|
/* not yet supported */
|
1998-11-10 02:40:37 +08:00
|
|
|
if(ld == NULL) {
|
|
|
|
/* bad param */
|
|
|
|
break;
|
|
|
|
}
|
1998-11-04 09:41:00 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
/* bad param */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ldap_set_option(
|
1998-11-10 02:40:37 +08:00
|
|
|
LDAP *ld,
|
1998-11-04 09:41:00 +08:00
|
|
|
int option,
|
|
|
|
void *invalue)
|
|
|
|
{
|
1998-11-10 02:40:37 +08:00
|
|
|
struct ldapoptions *lo;
|
1998-11-04 09:41:00 +08:00
|
|
|
|
|
|
|
if(!openldap_ldap_initialized) {
|
|
|
|
openldap_ldap_initialize();
|
|
|
|
}
|
|
|
|
|
|
|
|
if(invalue == NULL) {
|
|
|
|
/* no place to set from */
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
1998-11-10 02:40:37 +08:00
|
|
|
if(ld == NULL) {
|
|
|
|
lo = &openldap_ldap_global_options;
|
1998-11-04 09:41:00 +08:00
|
|
|
} else {
|
1998-11-10 02:40:37 +08:00
|
|
|
lo = &ld->ld_options;
|
1998-11-04 09:41:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
switch(option) {
|
|
|
|
case LDAP_OPT_API_INFO:
|
|
|
|
case LDAP_OPT_DESC:
|
|
|
|
/* READ ONLY */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LDAP_OPT_DEREF:
|
1998-11-10 02:40:37 +08:00
|
|
|
lo->ldo_deref = * (int *) invalue;
|
1998-11-04 09:41:00 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
case LDAP_OPT_SIZELIMIT:
|
1998-11-10 02:40:37 +08:00
|
|
|
lo->ldo_sizelimit = * (int *) invalue;
|
1998-11-04 09:41:00 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
case LDAP_OPT_TIMELIMIT:
|
1998-11-10 02:40:37 +08:00
|
|
|
lo->ldo_timelimit = * (int *) invalue;
|
1998-11-04 09:41:00 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
case LDAP_OPT_REFERRALS:
|
|
|
|
if((int) invalue == (int) LDAP_OPT_ON) {
|
1998-11-10 02:40:37 +08:00
|
|
|
LDAP_BOOL_SET(lo, LDAP_BOOL_REFERRALS);
|
1998-11-04 09:41:00 +08:00
|
|
|
} else {
|
1998-11-10 02:40:37 +08:00
|
|
|
LDAP_BOOL_CLR(lo, LDAP_BOOL_REFERRALS);
|
1998-11-04 09:41:00 +08:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case LDAP_OPT_RESTART:
|
|
|
|
if((int) invalue == (int) LDAP_OPT_ON) {
|
1998-11-10 02:40:37 +08:00
|
|
|
LDAP_BOOL_SET(lo, LDAP_BOOL_RESTART);
|
1998-11-04 09:41:00 +08:00
|
|
|
} else {
|
1998-11-10 02:40:37 +08:00
|
|
|
LDAP_BOOL_CLR(lo, LDAP_BOOL_RESTART);
|
1998-11-04 09:41:00 +08:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case LDAP_OPT_PROTOCOL_VERSION: {
|
|
|
|
int vers = * (int *) invalue;
|
1998-11-05 04:08:37 +08:00
|
|
|
if (vers < LDAP_VERSION_MIN || vers > LDAP_VERSION_MAX) {
|
1998-11-04 09:41:00 +08:00
|
|
|
/* not supported */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ld->ld_version = vers;
|
|
|
|
} return 0;
|
|
|
|
|
|
|
|
case LDAP_OPT_SERVER_CONTROLS:
|
|
|
|
case LDAP_OPT_CLIENT_CONTROLS:
|
|
|
|
case LDAP_OPT_HOST_NAME:
|
|
|
|
case LDAP_OPT_ERROR_NUMBER:
|
|
|
|
case LDAP_OPT_ERROR_STRING:
|
|
|
|
/* not yet supported */
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* bad param */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|