]> git.sur5r.net Git - openldap/commitdiff
ITS#8648 init SASL library in global init
authorRyan Tandy <ryan@nardis.ca>
Fri, 5 May 2017 03:08:07 +0000 (03:08 +0000)
committerRyan Tandy <ryan@nardis.ca>
Sun, 7 May 2017 21:29:44 +0000 (21:29 +0000)
libraries/libldap/cyrus.c
libraries/libldap/init.c

index 53c5e704286caadaf879574f604a47b4dfbb1514..41322ff43e7366543830f8a6917a076380414ab0 100644 (file)
@@ -69,11 +69,11 @@ static const sasl_callback_t client_callbacks[] = {
        { SASL_CB_LIST_END, NULL, NULL }
 };
 
+/*
+ * ldap_int_initialize is responsible for calling this only once.
+ */
 int ldap_int_sasl_init( void )
 {
-       /* XXX not threadsafe */
-       static int sasl_initialized = 0;
-
 #ifdef HAVE_SASL_VERSION
        /* stringify the version number, sasl.h doesn't do it for us */
 #define VSTR0(maj, min, pat)   #maj "." #min "." #pat
@@ -96,9 +96,6 @@ int ldap_int_sasl_init( void )
        }
        }
 #endif
-       if ( sasl_initialized ) {
-               return 0;
-       }
 
 /* SASL 2 takes care of its own memory completely internally */
 #if SASL_VERSION_MAJOR < 2 && !defined(CSRIMALLOC)
@@ -118,7 +115,6 @@ int ldap_int_sasl_init( void )
 #endif
 
        if ( sasl_client_init( NULL ) == SASL_OK ) {
-               sasl_initialized = 1;
                return 0;
        }
 
@@ -329,11 +325,6 @@ ldap_int_sasl_open(
                return ld->ld_errno;
        }
 
-       if ( ldap_int_sasl_init() ) {
-               ld->ld_errno = LDAP_LOCAL_ERROR;
-               return ld->ld_errno;
-       }
-
 #if SASL_VERSION_MAJOR >= 2
        rc = sasl_client_new( "ldap", host, NULL, NULL,
                client_callbacks, 0, &ctx );
@@ -936,8 +927,6 @@ int
 ldap_int_sasl_get_option( LDAP *ld, int option, void *arg )
 {
        if ( option == LDAP_OPT_X_SASL_MECHLIST ) {
-               if ( ldap_int_sasl_init() )
-                       return -1;
                *(char ***)arg = (char **)sasl_global_listmech();
                return 0;
        }
index d5e125c216deaff2cd19b53e551fabb0d59e95be..3e602dff9ad9f4bf1f80348ae637159499381e08 100644 (file)
@@ -662,6 +662,12 @@ void ldap_int_initialize( struct ldapoptions *gopts, int *dbglvl )
        if ( ldap_int_tblsize == 0 ) ldap_int_ip_init();
 #endif
 
+#ifdef HAVE_CYRUS_SASL
+       if ( ldap_int_sasl_init() != 0 ) {
+               return;
+       }
+#endif
+
        ldap_int_initialize_global_options(gopts, dbglvl);
 
        if( getenv("LDAPNOINIT") != NULL ) {