]> git.sur5r.net Git - openldap/commitdiff
Apply Novell's IN_KERNEL support (ITS#576)
authorKurt Zeilenga <kurt@openldap.org>
Thu, 8 Jun 2000 17:11:57 +0000 (17:11 +0000)
committerKurt Zeilenga <kurt@openldap.org>
Thu, 8 Jun 2000 17:11:57 +0000 (17:11 +0000)
libraries/libldap/init.c
libraries/libldap/ldap-int.h
libraries/libldap/open.c
libraries/libldap/options.c
libraries/libldap/request.c
libraries/libldap/url.c

index a9afa385c5d5310e73317c9412808afa9abbfbde..03fee191de20c21244f775bea2e579ae8ebfb1e8 100644 (file)
@@ -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,60 +350,70 @@ 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 ) {
-               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;
@@ -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);
 }
index dc75c231a1a22dd99d4fa7739885c0b262252ac6..41e125cfc0c54f903f0b75affeba67e81ccf4779 100644 (file)
 
 #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 */
index f97b6c8b9b00a19050c7025f8357b041ad2ebecf..41d4f1ceda9a1a534eb442ca31cd6c102de6b161 100644 (file)
@@ -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 );
index acea330be965bf77c170e25d2ecedb06331b07cd..879c70f3a897eddc6c0277b7dad37c2c06689db6 100644 (file)
@@ -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 ) ) {
index 033914e899e86bc9e5069a2c1fe3daf4da1e4130..cb645b18a7dc9a3ab4529ace7461a31e74ac09df 100644 (file)
@@ -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;
index d72dbcb5b2fc4a6f244a553b943028f148ccd30c..8571b1557b700225eacfef8c803154563611b5b2 100644 (file)
@@ -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 */