struct ldapoptions ldap_int_global_options =
{ LDAP_UNINITIALIZED, LDAP_DEBUG_NONE };
-#undef gopts
-#define gopts ldap_int_global_options
-
#define ATTR_NONE 0
#define ATTR_BOOL 1
#define ATTR_INT 2
int i;
char *cmd, *opt;
char *start, *end;
+ struct ldapoptions *gopts;
+
+ if ((gopts = LDAP_INT_GLOBAL_OPT()) == NULL) {
+ return; /* Could not allocate mem for global options */
+ }
if (file == NULL) {
/* no file name */
|| (strcasecmp(opt, "yes") == 0)
|| (strcasecmp(opt, "true") == 0))
{
- LDAP_BOOL_SET(&gopts, attrs[i].offset);
+ LDAP_BOOL_SET(gopts, attrs[i].offset);
} else {
- LDAP_BOOL_CLR(&gopts, attrs[i].offset);
+ LDAP_BOOL_CLR(gopts, attrs[i].offset);
}
break;
case ATTR_INT:
- p = &((char *) &gopts)[attrs[i].offset];
+ p = &((char *) gopts)[attrs[i].offset];
* (int*) p = atoi(opt);
break;
kv++) {
if(strcasecmp(opt, kv->key) == 0) {
- p = &((char *) &gopts)[attrs[i].offset];
+ p = &((char *) gopts)[attrs[i].offset];
* (int*) p = kv->value;
break;
}
} break;
case ATTR_STRING:
- p = &((char *) &gopts)[attrs[i].offset];
+ p = &((char *) gopts)[attrs[i].offset];
if (* (char**) p != NULL) LDAP_FREE(* (char**) p);
* (char**) p = LDAP_STRDUP(opt);
break;
case ATTR_TLS:
#ifdef HAVE_TLS
- ldap_pvt_tls_config( &gopts, attrs[i].offset, opt );
+ ldap_pvt_tls_config( gopts, attrs[i].offset, opt );
#endif
break;
case ATTR_URIS:
openldap_ldap_init_w_conf(file, 1);
}
-static void openldap_ldap_init_w_env(const char *prefix)
+static void openldap_ldap_init_w_env(
+ struct ldapoptions *gopts,
+ const char *prefix)
{
char buf[MAX_LDAP_ATTR_LEN+MAX_LDAP_ENV_PREFIX_LEN];
int len;
|| (strcasecmp(value, "yes") == 0)
|| (strcasecmp(value, "true") == 0))
{
- LDAP_BOOL_SET(&gopts, attrs[i].offset);
+ LDAP_BOOL_SET(gopts, attrs[i].offset);
} else {
- LDAP_BOOL_CLR(&gopts, attrs[i].offset);
+ LDAP_BOOL_CLR(gopts, attrs[i].offset);
}
break;
case ATTR_INT:
- p = &((char *) &gopts)[attrs[i].offset];
+ p = &((char *) gopts)[attrs[i].offset];
* (int*) p = atoi(value);
break;
kv++) {
if(strcasecmp(value, kv->key) == 0) {
- p = &((char *) &gopts)[attrs[i].offset];
+ p = &((char *) gopts)[attrs[i].offset];
* (int*) p = kv->value;
break;
}
} break;
case ATTR_STRING:
- p = &((char *) &gopts)[attrs[i].offset];
+ p = &((char *) gopts)[attrs[i].offset];
if (* (char**) p != NULL) LDAP_FREE(* (char**) p);
if (*value == '\0') {
* (char**) p = NULL;
break;
case ATTR_TLS:
#ifdef HAVE_TLS
- ldap_pvt_tls_config( &gopts, attrs[i].offset, value );
+ ldap_pvt_tls_config( gopts, attrs[i].offset, value );
#endif
break;
case ATTR_URIS:
}
}
-void ldap_int_initialize( int *dbglvl )
+/*
+ * Initialize the global options structure with default values.
+ */
+void ldap_int_initialize_global_options( struct ldapoptions *gopts, int *dbglvl )
{
- if ( gopts.ldo_valid == LDAP_INITIALIZED ) {
- return;
- }
-
- ldap_int_utils_init();
-
-#ifdef HAVE_TLS
- ldap_pvt_tls_init();
-#endif
-
-#ifdef HAVE_CYRUS_SASL
- ldap_pvt_sasl_init();
-#endif
-
- if ( ldap_int_tblsize == 0 )
- ldap_int_ip_init();
-
if (dbglvl)
- gopts.ldo_debug = *dbglvl;
+ gopts->ldo_debug = *dbglvl;
else
- gopts.ldo_debug = 0;
+ gopts->ldo_debug = 0;
- gopts.ldo_version = LDAP_VERSION2;
- gopts.ldo_deref = LDAP_DEREF_NEVER;
- gopts.ldo_timelimit = LDAP_NO_LIMIT;
- gopts.ldo_sizelimit = LDAP_NO_LIMIT;
+ gopts->ldo_version = LDAP_VERSION2;
+ gopts->ldo_deref = LDAP_DEREF_NEVER;
+ gopts->ldo_timelimit = LDAP_NO_LIMIT;
+ gopts->ldo_sizelimit = LDAP_NO_LIMIT;
- gopts.ldo_tm_api = (struct timeval *)NULL;
- gopts.ldo_tm_net = (struct timeval *)NULL;
+ gopts->ldo_tm_api = (struct timeval *)NULL;
+ gopts->ldo_tm_net = (struct timeval *)NULL;
/* ldo_defludp is leaked, we should have an at_exit() handler
* to free this and whatever else needs to cleaned up.
*/
- ldap_url_parselist(&gopts.ldo_defludp, "ldap://localhost/");
- gopts.ldo_defport = LDAP_PORT;
+ ldap_url_parselist(&gopts->ldo_defludp, "ldap://localhost/");
+ gopts->ldo_defport = LDAP_PORT;
- gopts.ldo_refhoplimit = LDAP_DEFAULT_REFHOPLIMIT;
- gopts.ldo_rebindproc = NULL;
+ gopts->ldo_refhoplimit = LDAP_DEFAULT_REFHOPLIMIT;
+ gopts->ldo_rebindproc = NULL;
- LDAP_BOOL_ZERO(&gopts);
+ LDAP_BOOL_ZERO(gopts);
- LDAP_BOOL_SET(&gopts, LDAP_BOOL_REFERRALS);
+ LDAP_BOOL_SET(gopts, LDAP_BOOL_REFERRALS);
#ifdef HAVE_TLS
- gopts.ldo_tls_ctx = NULL;
+ gopts->ldo_tls_ctx = NULL;
#endif
#ifdef HAVE_CYRUS_SASL
- gopts.ldo_sasl_minssf = 0;
- gopts.ldo_sasl_maxssf = INT_MAX;
+ gopts->ldo_sasl_minssf = 0;
+ gopts->ldo_sasl_maxssf = INT_MAX;
#endif
- gopts.ldo_valid = LDAP_INITIALIZED;
+ gopts->ldo_valid = LDAP_INITIALIZED;
+
+ return;
+}
+
+void ldap_int_initialize( struct ldapoptions *gopts, int *dbglvl )
+{
+ if ( gopts->ldo_valid == LDAP_INITIALIZED ) {
+ return;
+ }
+
+ ldap_int_utils_init();
+
+#ifdef HAVE_TLS
+ ldap_pvt_tls_init();
+#endif
+
+#ifdef HAVE_CYRUS_SASL
+ ldap_pvt_sasl_init();
+#endif
+
+ if ( ldap_int_tblsize == 0 )
+ ldap_int_ip_init();
+
+ ldap_int_initialize_global_options(gopts, NULL);
if( getenv("LDAPNOINIT") != NULL ) {
return;
LDAP_ENV_PREFIX "RC", 0, 0);
}
- openldap_ldap_init_w_env(NULL);
+ openldap_ldap_init_w_env(gopts, NULL);
}
#include "../liblber/lber-int.h"
-#define ldap_debug (ldap_int_global_options.ldo_debug)
+/*
+ * Support needed if the library is running in the kernel
+ */
+#if LDAP_INT_IN_KERNEL
+ /*
+ * Platform specific function to return a pointer to the
+ * process-specific global options.
+ *
+ * This function should perform the following functions:
+ * Allocate and initialize a global options struct on a per process basis
+ * Use callers process identifier to return its global options struct
+ * Note: Deallocate structure when the process exits
+ */
+# define LDAP_INT_GLOBAL_OPT() ldap_int_global_opt()
+ struct ldapoptions *ldap_int_global_opt(void);
+#else
+# define LDAP_INT_GLOBAL_OPT() (&ldap_int_global_options)
+#endif
+
+#define ldap_debug ((LDAP_INT_GLOBAL_OPT())->ldo_debug)
#include "ldap_log.h"
*/
LIBLDAP_F ( struct ldapoptions ) ldap_int_global_options;
-LIBLDAP_F ( void ) ldap_int_initialize LDAP_P((int *));
+LIBLDAP_F ( void ) ldap_int_initialize LDAP_P((struct ldapoptions *, int *));
+LIBLDAP_F ( void ) ldap_int_initialize_global_options LDAP_P((
+ struct ldapoptions *, int *));
/* memory.c */
/* simple macros to realloc for now */
ldap_create( LDAP **ldp )
{
LDAP *ld;
+ struct ldapoptions *gopts;
*ldp = NULL;
- if( ldap_int_global_options.ldo_valid != LDAP_INITIALIZED ) {
- ldap_int_initialize(NULL);
+ /* Get pointer to global option structure */
+ if ( (gopts = LDAP_INT_GLOBAL_OPT()) == NULL) {
+ return LDAP_NO_MEMORY;
+ }
+
+ /* Initialize the global options, if not already done. */
+ if( gopts->ldo_valid != LDAP_INITIALIZED ) {
+ ldap_int_initialize(gopts, NULL);
}
Debug( LDAP_DEBUG_TRACE, "ldap_init\n", 0, 0, 0 );
}
/* copy the global options */
- memcpy(&ld->ld_options, &ldap_int_global_options,
- sizeof(ld->ld_options));
+ memcpy(&ld->ld_options, gopts, sizeof(ld->ld_options));
ld->ld_valid = LDAP_VALID_SESSION;
ld->ld_options.ldo_sctrls = NULL;
ld->ld_options.ldo_cctrls = NULL;
- ld->ld_options.ldo_defludp =
- ldap_url_duplist(ldap_int_global_options.ldo_defludp);
+ ld->ld_options.ldo_defludp = ldap_url_duplist(gopts->ldo_defludp);
if ( ld->ld_options.ldo_defludp == NULL ) {
LDAP_FREE( (char*)ld );
int option,
void *outvalue)
{
- const struct ldapoptions *lo;
+ struct ldapoptions *lo;
- if( ldap_int_global_options.ldo_valid != LDAP_INITIALIZED ) {
- ldap_int_initialize(NULL);
+ /* Get pointer to global option structure */
+ lo = LDAP_INT_GLOBAL_OPT();
+ if (NULL == lo) {
+ return LDAP_NO_MEMORY;
}
- if(ld == NULL) {
- lo = &ldap_int_global_options;
+ if( lo->ldo_valid != LDAP_INITIALIZED ) {
+ ldap_int_initialize(lo, NULL);
+ }
- } else {
+ if(ld != NULL) {
assert( LDAP_VALID( ld ) );
if( !LDAP_VALID( ld ) ) {
struct ldapoptions *lo;
int *dbglvl = NULL;
+ /* Get pointer to global option structure */
+ lo = LDAP_INT_GLOBAL_OPT();
+ if (lo == NULL) {
+ return LDAP_NO_MEMORY;
+ }
+
/*
* The architecture to turn on debugging has a chicken and egg
* problem. Thus, we introduce a fix here.
if (option == LDAP_OPT_DEBUG_LEVEL)
dbglvl = (int *) invalue;
- if( ldap_int_global_options.ldo_valid != LDAP_INITIALIZED ) {
- ldap_int_initialize(dbglvl);
+ if( lo->ldo_valid != LDAP_INITIALIZED ) {
+ ldap_int_initialize(lo, dbglvl);
}
- if(ld == NULL) {
- lo = &ldap_int_global_options;
-
- } else {
+ if(ld != NULL) {
assert( LDAP_VALID( ld ) );
if( !LDAP_VALID( ld ) ) {