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>
|
Protoized, moved extern definitions to .h files, fixed related bugs.
Most function and variable definitions are now preceded by its extern
definition, for error checking. Retyped a number of functions, usually
to return void. Fixed a number of printf format errors.
API changes (in ldap/include):
Added avl_dup_ok, avl_prefixapply, removed ber_fatten (probably typo
for ber_flatten), retyped ldap_sort_strcasecmp, grew lutil.h.
A number of `extern' declarations are left (some added by protoize), to
be cleaned away later. Mostly strdup(), strcasecmp(), mktemp(), optind,
optarg, errno.
1998-11-16 06:40:11 +08:00
|
|
|
extern char *strdup (const char *);
|
1998-11-04 09:41:00 +08:00
|
|
|
|
|
|
|
#include "ldap-int.h"
|
|
|
|
|
1998-11-10 07:21:38 +08:00
|
|
|
static const char* features[] = {
|
|
|
|
#ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_DNS
|
|
|
|
"X_OPENLDAP_V2_DNS",
|
|
|
|
#endif
|
|
|
|
#ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS
|
|
|
|
"X_OPENLDAP_V2_REFERRALS",
|
|
|
|
#endif
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
1998-11-04 09:41:00 +08:00
|
|
|
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;
|
1998-11-10 07:21:38 +08:00
|
|
|
if(features[0] == NULL) {
|
|
|
|
info->ldapai_extensions = NULL;
|
|
|
|
} else {
|
|
|
|
int i;
|
|
|
|
info->ldapai_extensions = malloc(sizeof(features));
|
|
|
|
|
|
|
|
for(i=0; features[i] != NULL; i++) {
|
|
|
|
info->ldapai_extensions[i] = strdup(features[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
info->ldapai_extensions[i] = 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-11 07:37:30 +08:00
|
|
|
if ((ld != NULL) && ld->ld_version) {
|
|
|
|
* (int *) outvalue = ld->ld_version;
|
|
|
|
} else {
|
|
|
|
* (int *) outvalue = lo->ldo_version;
|
|
|
|
}
|
1998-11-04 09:41:00 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
case LDAP_OPT_SERVER_CONTROLS:
|
|
|
|
case LDAP_OPT_CLIENT_CONTROLS:
|
|
|
|
/* not yet supported */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LDAP_OPT_HOST_NAME:
|
1998-11-11 07:37:30 +08:00
|
|
|
/*
|
|
|
|
* draft-ietf-ldapext-ldap-c-api-01 doesn't state
|
|
|
|
* whether client to have to free host names or no,
|
|
|
|
* we do
|
|
|
|
*/
|
|
|
|
|
|
|
|
* (char **) outvalue = strdup(lo->ldo_defhost);
|
1998-11-04 09:41:00 +08:00
|
|
|
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-11 07:37:30 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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);
|
|
|
|
}
|
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:
|
|
|
|
/* not yet supported */
|
|
|
|
break;
|
1998-11-11 07:37:30 +08:00
|
|
|
|
|
|
|
case LDAP_OPT_HOST_NAME: {
|
|
|
|
char* host = * (char **) invalue;
|
|
|
|
|
|
|
|
if(lo->ldo_defhost != NULL) {
|
|
|
|
free(lo->ldo_defhost);
|
|
|
|
lo->ldo_defhost = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(host != NULL) {
|
|
|
|
lo->ldo_defhost = strdup(host);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(ld == NULL) {
|
|
|
|
/*
|
|
|
|
* must want global default returned
|
|
|
|
* to initial condition.
|
|
|
|
*/
|
|
|
|
lo->ldo_defhost = strdup("localhost");
|
|
|
|
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* must want the session default
|
|
|
|
* updated to the current global default
|
|
|
|
*/
|
|
|
|
lo->ldo_defhost = strdup(
|
|
|
|
openldap_ldap_global_options.ldo_defhost);
|
|
|
|
}
|
|
|
|
} return 0;
|
|
|
|
|
|
|
|
case LDAP_OPT_ERROR_NUMBER: {
|
|
|
|
int err = * (int *) invalue;
|
|
|
|
|
|
|
|
if (err != 0 ) {
|
|
|
|
/* not supported */
|
|
|
|
/* we only allow ld_errno to be cleared. */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(ld == NULL) {
|
|
|
|
/* need a struct ldap */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ld->ld_errno = err;
|
|
|
|
} return 0;
|
|
|
|
|
|
|
|
case LDAP_OPT_ERROR_STRING: {
|
|
|
|
char* err = * (char **) invalue;
|
|
|
|
|
|
|
|
if (err != NULL ) {
|
|
|
|
/* not supported */
|
|
|
|
/* we only allow ld_error to be cleared. */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(ld == NULL) {
|
|
|
|
/* need a struct ldap */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ld->ld_error = err;
|
|
|
|
} return 0;
|
|
|
|
|
1998-11-04 09:41:00 +08:00
|
|
|
default:
|
|
|
|
/* bad param */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|