mirror of
https://git.openldap.org/openldap/openldap.git
synced 2025-02-23 14:09:39 +08:00
Apply Novell's IN_KERNEL support (ITS#576)
This commit is contained in:
parent
3c0e4d35a1
commit
77b235fba5
@ -21,9 +21,6 @@
|
||||
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
|
||||
@ -96,6 +93,11 @@ static void openldap_ldap_init_w_conf(
|
||||
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 */
|
||||
@ -165,16 +167,16 @@ static void openldap_ldap_init_w_conf(
|
||||
|| (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;
|
||||
|
||||
@ -186,7 +188,7 @@ static void openldap_ldap_init_w_conf(
|
||||
kv++) {
|
||||
|
||||
if(strcasecmp(opt, kv->key) == 0) {
|
||||
p = &((char *) &gopts)[attrs[i].offset];
|
||||
p = &((char *) gopts)[attrs[i].offset];
|
||||
* (int*) p = kv->value;
|
||||
break;
|
||||
}
|
||||
@ -194,13 +196,13 @@ static void openldap_ldap_init_w_conf(
|
||||
} 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:
|
||||
@ -264,7 +266,9 @@ static void openldap_ldap_init_w_userconf(const char *file)
|
||||
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;
|
||||
@ -294,15 +298,15 @@ static void openldap_ldap_init_w_env(const char *prefix)
|
||||
|| (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;
|
||||
|
||||
@ -314,7 +318,7 @@ static void openldap_ldap_init_w_env(const char *prefix)
|
||||
kv++) {
|
||||
|
||||
if(strcasecmp(value, kv->key) == 0) {
|
||||
p = &((char *) &gopts)[attrs[i].offset];
|
||||
p = &((char *) gopts)[attrs[i].offset];
|
||||
* (int*) p = kv->value;
|
||||
break;
|
||||
}
|
||||
@ -322,7 +326,7 @@ static void openldap_ldap_init_w_env(const char *prefix)
|
||||
} 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;
|
||||
@ -332,7 +336,7 @@ static void openldap_ldap_init_w_env(const char *prefix)
|
||||
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:
|
||||
@ -346,9 +350,53 @@ static void openldap_ldap_init_w_env(const char *prefix)
|
||||
}
|
||||
}
|
||||
|
||||
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 ) {
|
||||
if (dbglvl)
|
||||
gopts->ldo_debug = *dbglvl;
|
||||
else
|
||||
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_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;
|
||||
|
||||
gopts->ldo_refhoplimit = LDAP_DEFAULT_REFHOPLIMIT;
|
||||
gopts->ldo_rebindproc = NULL;
|
||||
|
||||
LDAP_BOOL_ZERO(gopts);
|
||||
|
||||
LDAP_BOOL_SET(gopts, LDAP_BOOL_REFERRALS);
|
||||
|
||||
#ifdef HAVE_TLS
|
||||
gopts->ldo_tls_ctx = NULL;
|
||||
#endif
|
||||
#ifdef HAVE_CYRUS_SASL
|
||||
gopts->ldo_sasl_minssf = 0;
|
||||
gopts->ldo_sasl_maxssf = INT_MAX;
|
||||
#endif
|
||||
|
||||
gopts->ldo_valid = LDAP_INITIALIZED;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void ldap_int_initialize( struct ldapoptions *gopts, int *dbglvl )
|
||||
{
|
||||
if ( gopts->ldo_valid == LDAP_INITIALIZED ) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -365,41 +413,7 @@ void ldap_int_initialize( int *dbglvl )
|
||||
if ( ldap_int_tblsize == 0 )
|
||||
ldap_int_ip_init();
|
||||
|
||||
if (dbglvl)
|
||||
gopts.ldo_debug = *dbglvl;
|
||||
else
|
||||
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_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;
|
||||
|
||||
gopts.ldo_refhoplimit = LDAP_DEFAULT_REFHOPLIMIT;
|
||||
gopts.ldo_rebindproc = NULL;
|
||||
|
||||
LDAP_BOOL_ZERO(&gopts);
|
||||
|
||||
LDAP_BOOL_SET(&gopts, LDAP_BOOL_REFERRALS);
|
||||
|
||||
#ifdef HAVE_TLS
|
||||
gopts.ldo_tls_ctx = NULL;
|
||||
#endif
|
||||
#ifdef HAVE_CYRUS_SASL
|
||||
gopts.ldo_sasl_minssf = 0;
|
||||
gopts.ldo_sasl_maxssf = INT_MAX;
|
||||
#endif
|
||||
|
||||
gopts.ldo_valid = LDAP_INITIALIZED;
|
||||
ldap_int_initialize_global_options(gopts, NULL);
|
||||
|
||||
if( getenv("LDAPNOINIT") != NULL ) {
|
||||
return;
|
||||
@ -434,5 +448,5 @@ void ldap_int_initialize( int *dbglvl )
|
||||
LDAP_ENV_PREFIX "RC", 0, 0);
|
||||
}
|
||||
|
||||
openldap_ldap_init_w_env(NULL);
|
||||
openldap_ldap_init_w_env(gopts, NULL);
|
||||
}
|
||||
|
@ -19,7 +19,26 @@
|
||||
|
||||
#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"
|
||||
|
||||
@ -298,7 +317,9 @@ extern ldap_pvt_thread_mutex_t ldap_int_resolv_mutex;
|
||||
*/
|
||||
|
||||
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 */
|
||||
|
@ -78,10 +78,17 @@ int
|
||||
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 );
|
||||
@ -127,8 +134,7 @@ ldap_create( LDAP **ldp )
|
||||
}
|
||||
|
||||
/* 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;
|
||||
|
||||
@ -137,8 +143,7 @@ ldap_create( LDAP **ldp )
|
||||
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 );
|
||||
|
@ -79,16 +79,19 @@ ldap_get_option(
|
||||
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 ) ) {
|
||||
@ -301,6 +304,12 @@ ldap_set_option(
|
||||
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.
|
||||
@ -309,14 +318,11 @@ ldap_set_option(
|
||||
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 ) ) {
|
||||
|
@ -885,7 +885,7 @@ ldap_chase_referrals( LDAP *ld, LDAPRequest *lr, char **errstrp, int *hadrefp )
|
||||
*ports++ = '\0';
|
||||
srv->lud_port = atoi( ports );
|
||||
} else {
|
||||
srv->lud_port = ldap_int_global_options.ldo_defport;
|
||||
srv->lud_port = (LDAP_INT_GLOBAL_OPT())->ldo_defport;
|
||||
}
|
||||
|
||||
rinfo.ri_msgid = origreq->lr_origid;
|
||||
|
@ -227,7 +227,14 @@ ldap_url_parse( LDAP_CONST char *url_in, LDAPURLDesc **ludpp )
|
||||
return LDAP_URL_ERR_PARAM;
|
||||
}
|
||||
|
||||
#ifndef LDAP_INT_IN_KERNEL
|
||||
/* Global options may not be created yet
|
||||
* We can't test if the global options are initialized
|
||||
* because a call to LDAP_INT_GLOBAL_OPT() will try to allocate
|
||||
* the options and cause infinite recursion
|
||||
*/
|
||||
Debug( LDAP_DEBUG_TRACE, "ldap_url_parse(%s)\n", url_in, 0, 0 );
|
||||
#endif
|
||||
|
||||
*ludpp = NULL; /* pessimistic */
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user