Add openldap_ldap_initialize() call to ldap_init/ldap_open/ldap_get/set_options.
#include "ldap-int.h"
-struct ldap openldap_ld_globals;
+struct ldapoptions openldap_ldap_global_options;
int openldap_ldap_initialized = 0;
#define LDAP_BOOL_RESTART 1
#define LDAP_BOOL_DNS 2
+#define LDAP_BOOLEANS unsigned long
#define LDAP_BOOL(n) (1 << (n))
-#define LDAP_BOOL_GET(ld, bool) ((ld)->ld_booleans & LDAP_BOOL(bool) \
+#define LDAP_BOOL_GET(lo, bool) ((lo)->ldo_booleans & LDAP_BOOL(bool) \
? LDAP_OPT_ON : LDAP_OPT_OFF)
-#define LDAP_BOOL_SET(ld, bool) ((ld)->ld_booleans |= LDAP_BOOL(bool))
-#define LDAP_BOOL_CLR(ld, bool) ((ld)->ld_booleans &= ~LDAP_BOOL(bool))
-#define LDAP_BOOL_ZERO(ld) ((ld)->ld_booleans = 0)
+#define LDAP_BOOL_SET(lo, bool) ((lo)->ldo_booleans |= LDAP_BOOL(bool))
+#define LDAP_BOOL_CLR(lo, bool) ((lo)->ldo_booleans &= ~LDAP_BOOL(bool))
+#define LDAP_BOOL_ZERO(lo) ((lo)->ldo_booleans = 0)
/*
* This structure represents both ldap messages and ldap responses.
unsigned int lm_time; /* used to maintain cache */
};
+/*
+ * structure representing get/set'able options
+ * which have global defaults.
+ */
+struct ldapoptions {
+ int ldo_version; /* version to connect at */
+ int ldo_deref;
+ int ldo_timelimit;
+ int ldo_sizelimit;
+
+ int ldo_cldaptries; /* connectionless search retry count */
+ int ldo_cldaptimeout;/* time between retries */
+ int ldo_refhoplimit; /* limit on referral nesting */
+
+ LDAP_BOOLEANS ldo_booleans; /* boolean options */
+};
+
/*
* structure representing an ldap connection
*/
struct ldap {
Sockbuf ld_sb; /* socket descriptor & buffer */
- char *ld_host;
- int ld_version;
- char ld_lberoptions;
- int ld_deref;
- int ld_timelimit;
- int ld_sizelimit;
+
+ struct ldapoptions ld_options;
+
+#define ld_deref ld_options.ldo_deref
+#define ld_timelimit ld_options.ldo_timelimit
+#define ld_sizelimit ld_options.ldo_sizelimit
+
+#define ld_cldaptries ld_options.ldo_cldaptries
+#define ld_cldaptimeout ld_options.ldo_cldaptimeout
+#define ld_refhoplimit ld_options.ldo_refhoplimit
+
+ int ld_version; /* version connected at */
+ char *ld_host;
+ char ld_lberoptions;
LDAPFiltDesc *ld_filtd; /* from getfilter for ufn searches */
char *ld_ufnprefix; /* for incomplete ufn's */
int ld_errno;
- char *ld_error;
- char *ld_matched;
+ char *ld_error;
+ char *ld_matched;
int ld_msgid;
/* do not mess with these */
LDAPCache *ld_cache; /* non-null if cache is initialized */
char *ld_cldapdn; /* DN used in connectionless search */
- /* it is OK to change these next four values directly */
- int ld_cldaptries; /* connectionless search retry count */
- int ld_cldaptimeout;/* time between retries */
- int ld_refhoplimit; /* limit on referral nesting */
- unsigned long ld_booleans; /* boolean options */
-
/* do not mess with the rest though */
char *ld_defhost; /* full name of default server */
int ld_defport; /* port of default server */
BERTranslateProc ld_lber_encode_translate_proc;
BERTranslateProc ld_lber_decode_translate_proc;
+
#ifdef LDAP_REFERRALS
LDAPConn *ld_defconn; /* default connection */
LDAPConn *ld_conns; /* list of server connections */
* in init.c
*/
extern int openldap_ldap_initialized;
-extern struct ldap openldap_ld_globals;
+extern struct ldapoptions openldap_ldap_global_options;
void openldap_ldap_initialize LDAP_P((void));
/*
{
LDAP *ld;
+ if(!openldap_ldap_initialized) {
+ openldap_ldap_initialize();
+ }
+
Debug( LDAP_DEBUG_TRACE, "ldap_init\n", 0, 0, 0 );
#ifdef HAVE_WINSOCK2
return( NULL );
}
- LDAP_BOOL_ZERO(ld);
- LDAP_BOOL_SET(ld, LDAP_BOOL_REFERRALS);
+ LDAP_BOOL_ZERO(&ld->ld_options);
+ LDAP_BOOL_SET(&ld->ld_options, LDAP_BOOL_REFERRALS);
#else
- LDAP_BOOL_ZERO(ld);
+ LDAP_BOOL_ZERO(&ld->ld_options);
#endif
if ( defhost != NULL &&
ld->ld_defport = ( defport == 0 ) ? LDAP_PORT : defport;
ld->ld_version = LDAP_VERSION;
ld->ld_lberoptions = LBER_USE_DER;
- ld->ld_refhoplimit = LDAP_DEFAULT_REFHOPLIMIT;
+ ld->ld_options.ldo_refhoplimit = LDAP_DEFAULT_REFHOPLIMIT;
#ifdef LDAP_REFERRALS
- LDAP_BOOL_SET(ld, LDAP_BOOL_REFERRALS);
+ LDAP_BOOL_SET(&ld->ld_options, LDAP_BOOL_REFERRALS);
#endif /* LDAP_REFERRALS */
#if defined( STR_TRANSLATION ) && defined( LDAP_DEFAULT_CHARSET )
int
ldap_get_option(
- LDAP *ldp,
+ LDAP *ld,
int option,
void *outvalue)
{
- LDAP *ld;
+ struct ldapoptions *lo;
if(!openldap_ldap_initialized) {
openldap_ldap_initialize();
return -1;
}
- if(ldp == NULL) {
- ld = &openldap_ld_globals;
+ if(ld == NULL) {
+ lo = &openldap_ldap_global_options;
} else {
- ld = ldp;
+ lo = &ld->ld_options;
}
switch(option) {
} break;
case LDAP_OPT_DESC:
- if(ldp == NULL) {
+ if(ld == NULL) {
/* bad param */
break;
}
return 0;
case LDAP_OPT_DEREF:
- * (int *) outvalue = ld->ld_deref;
+ * (int *) outvalue = lo->ldo_deref;
return 0;
case LDAP_OPT_SIZELIMIT:
- * (int *) outvalue = ld->ld_sizelimit;
+ * (int *) outvalue = lo->ldo_sizelimit;
return 0;
case LDAP_OPT_TIMELIMIT:
- * (int *) outvalue = ld->ld_timelimit;
+ * (int *) outvalue = lo->ldo_timelimit;
return 0;
case LDAP_OPT_REFERRALS:
- * (int *) outvalue = (int) LDAP_BOOL_GET(ld, LDAP_BOOL_REFERRALS);
+ * (int *) outvalue = (int) LDAP_BOOL_GET(lo, LDAP_BOOL_REFERRALS);
return 0;
case LDAP_OPT_RESTART:
- * (int *) outvalue = (int) LDAP_BOOL_GET(ld, LDAP_BOOL_RESTART);
+ * (int *) outvalue = (int) LDAP_BOOL_GET(lo, LDAP_BOOL_RESTART);
return 0;
case LDAP_OPT_DNS: /* LDAPv2 */
- * (int *) outvalue = (int) LDAP_BOOL_GET(ld, LDAP_BOOL_DNS);
+ * (int *) outvalue = (int) LDAP_BOOL_GET(lo, LDAP_BOOL_DNS);
return 0;
case LDAP_OPT_PROTOCOL_VERSION:
+ if(ld == NULL) {
+ /* bad param */
+ break;
+ }
+
* (int *) outvalue = ld->ld_version;
return 0;
break;
case LDAP_OPT_HOST_NAME:
+ if(ld == NULL) {
+ /* bad param */
+ break;
+ }
* (char **) outvalue = ld->ld_host;
return 0;
case LDAP_OPT_ERROR_NUMBER:
+ if(ld == NULL) {
+ /* bad param */
+ break;
+ }
* (int *) outvalue = ld->ld_errno;
return 0;
case LDAP_OPT_ERROR_STRING:
/* not yet supported */
+ if(ld == NULL) {
+ /* bad param */
+ break;
+ }
break;
default:
int
ldap_set_option(
- LDAP *ldp,
+ LDAP *ld,
int option,
void *invalue)
{
- LDAP *ld;
+ struct ldapoptions *lo;
if(!openldap_ldap_initialized) {
openldap_ldap_initialize();
return -1;
}
- if(ldp == NULL) {
- ld = &openldap_ld_globals;
+ if(ld == NULL) {
+ lo = &openldap_ldap_global_options;
} else {
- ld = ldp;
+ lo = &ld->ld_options;
}
switch(option) {
break;
case LDAP_OPT_DEREF:
- ld->ld_deref = * (int *) invalue;
+ lo->ldo_deref = * (int *) invalue;
return 0;
case LDAP_OPT_SIZELIMIT:
- ld->ld_sizelimit = * (int *) invalue;
+ lo->ldo_sizelimit = * (int *) invalue;
return 0;
case LDAP_OPT_TIMELIMIT:
- ld->ld_timelimit = * (int *) invalue;
+ lo->ldo_timelimit = * (int *) invalue;
return 0;
case LDAP_OPT_REFERRALS:
if((int) invalue == (int) LDAP_OPT_ON) {
- LDAP_BOOL_SET(ld, LDAP_BOOL_REFERRALS);
+ LDAP_BOOL_SET(lo, LDAP_BOOL_REFERRALS);
} else {
- LDAP_BOOL_CLR(ld, LDAP_BOOL_REFERRALS);
+ LDAP_BOOL_CLR(lo, LDAP_BOOL_REFERRALS);
}
return 0;
case LDAP_OPT_RESTART:
if((int) invalue == (int) LDAP_OPT_ON) {
- LDAP_BOOL_SET(ld, LDAP_BOOL_RESTART);
+ LDAP_BOOL_SET(lo, LDAP_BOOL_RESTART);
} else {
- LDAP_BOOL_CLR(ld, LDAP_BOOL_RESTART);
+ LDAP_BOOL_CLR(lo, LDAP_BOOL_RESTART);
}
return 0;
#else /* !LDAP_REFERRALS && !LDAP_DNS */
#ifdef LDAP_DNS
- if (( LDAP_BOOL_GET(ld, LDAP_BOOL_DNS ) == LDAP_OPT_ON )
+ if (( LDAP_BOOL_GET(&ld->ld_options, LDAP_BOOL_DNS ) == LDAP_OPT_ON )
&& ldap_is_dns_dn( dn ) )
{
if (( servers = dn2servers( ld, dn )) == NULL ) {
rc = ldap_select1( ld, tvp );
if ( rc == 0 || ( rc == -1 && (
- (LDAP_BOOL_GET(ld, LDAP_BOOL_RESTART) == LDAP_OPT_OFF)
+ ( LDAP_BOOL_GET(&ld->ld_options, LDAP_BOOL_RESTART)
+ == LDAP_OPT_OFF )
|| errno != EINTR ))) {
ld->ld_errno = (rc == -1 ? LDAP_SERVER_DOWN :
LDAP_TIMEOUT);
#endif
if ( rc == 0 || ( rc == -1 && (
- (LDAP_BOOL_GET(ld, LDAP_BOOL_RESTART) == LDAP_OPT_OFF)
- || errno != EINTR ))) {
+ ( LDAP_BOOL_GET(&ld->ld_options, LDAP_BOOL_RESTART)
+ == LDAP_OPT_OFF )
+ || errno != EINTR )))
+ {
ld->ld_errno = (rc == -1 ? LDAP_SERVER_DOWN :
LDAP_TIMEOUT);
return( rc );
if ( tag != LDAP_RES_SEARCH_ENTRY ) {
if ( ld->ld_version >= LDAP_VERSION2 &&
- ( lr->lr_parent != NULL ||
- (LDAP_BOOL_GET(ld, LDAP_BOOL_REFERRALS) != LDAP_OPT_OFF))) {
+ ( lr->lr_parent != NULL ||
+ ( LDAP_BOOL_GET(&ld->ld_options, LDAP_BOOL_REFERRALS)
+ != LDAP_OPT_OFF ) ) )
+ {
tmpber = ber; /* struct copy */
if ( ber_scanf( &tmpber, "{iaa}", &lderr,
&lr->lr_res_matched, &lr->lr_res_error )
getline( line, sizeof(line), stdin, "sizelimit?" );
ld->ld_sizelimit = atoi( line );
- LDAP_BOOL_ZERO(ld);
+ LDAP_BOOL_ZERO(&ld->ld_options);
#ifdef STR_TRANSLATION
getline( line, sizeof(line), stdin,
getline( line, sizeof(line), stdin,
"Use DN & DNS to determine where to send requests (0=no, 1=yes)?" );
if ( atoi( line ) != 0 ) {
- LDAP_BOOL_SET(ld, LDAP_BOOL_DNS);
+ LDAP_BOOL_SET(&ld->ld_options, LDAP_BOOL_DNS);
}
#endif /* LDAP_DNS */
getline( line, sizeof(line), stdin,
"Recognize and chase referrals (0=no, 1=yes)?" );
if ( atoi( line ) != 0 ) {
- LDAP_BOOL_SET(ld, LDAP_BOOL_REFERRALS);
+ LDAP_BOOL_SET(&ld->ld_options, LDAP_BOOL_REFERRALS);
getline( line, sizeof(line), stdin,
"Prompt for bind credentials when chasing referrals (0=no, 1=yes)?" );
if ( atoi( line ) != 0 ) {