EXPORTED void global_sasl_init(int client, int server, const sasl_callback_t *callbacks) { static int called_already = 0; assert(client || server); assert(!called_already); called_already = 1; /* set the SASL allocation functions */ sasl_set_alloc((sasl_malloc_t *) &xmalloc, (sasl_calloc_t *) &xcalloc, (sasl_realloc_t *) &xrealloc, (sasl_free_t *) &free); /* set the SASL mutex functions */ sasl_set_mutex((sasl_mutex_alloc_t *) &cyrus_mutex_alloc, (sasl_mutex_lock_t *) &cyrus_mutex_lock, (sasl_mutex_unlock_t *) &cyrus_mutex_unlock, (sasl_mutex_free_t *) &cyrus_mutex_free); if(client && sasl_client_init(callbacks)) { fatal("could not init sasl (client)", EC_SOFTWARE); } if(server && sasl_server_init(callbacks, "Cyrus")) { fatal("could not init sasl (server)", EC_SOFTWARE); } }
/** * Configures the SASL library to use allocator and mutex functions we specify, * unless the client application has previously initialized the SASL library. */ MONGO_INITIALIZER(CyrusSaslAllocatorsAndMutexes)(InitializerContext*) { sasl_set_alloc(saslOurMalloc, saslOurCalloc, saslOurRealloc, free); sasl_set_mutex(saslMutexAlloc, saslMutexLock, saslMutexUnlock, saslMutexFree); return Status::OK(); }
void nsldapi_initialize_defaults(void) { #ifdef _WINDOWS pthread_mutex_init(&nsldapi_init_mutex, NULL); #endif /* _WINDOWS */ #if defined(USE_PTHREADS) || defined(_WINDOWS) pthread_mutex_lock(&nsldapi_init_mutex); if (nsldapi_initialized) { pthread_mutex_unlock(&nsldapi_init_mutex); return; } #else if (nsldapi_initialized) { return; } #endif /* use_pthreads || _windows */ #ifdef USE_PTHREADS if (pthread_key_create(&nsldapi_key, free) != 0) { perror("pthread_key_create"); } #elif defined(USE_WINDOWS_TLS) dwTlsIndex = TlsAlloc(); #endif /* USE_WINDOWS_TLS */ memset(&nsldapi_memalloc_fns, 0, sizeof(nsldapi_memalloc_fns)); memset(&nsldapi_ld_defaults, 0, sizeof(nsldapi_ld_defaults)); nsldapi_ld_defaults.ld_options = LDAP_BITOPT_REFERRALS; nsldapi_ld_defaults.ld_version = LDAP_VERSION3; nsldapi_ld_defaults.ld_lberoptions = LBER_OPT_USE_DER; nsldapi_ld_defaults.ld_refhoplimit = LDAP_DEFAULT_REFHOPLIMIT; #ifdef LDAP_SASLIO_HOOKS /* SASL default option settings */ nsldapi_ld_defaults.ld_def_sasl_mech = NULL; nsldapi_ld_defaults.ld_def_sasl_realm = NULL; nsldapi_ld_defaults.ld_def_sasl_authcid = NULL; nsldapi_ld_defaults.ld_def_sasl_authzid = NULL; /* SASL Security properties */ nsldapi_ld_defaults.ld_sasl_secprops.max_ssf = UINT_MAX; nsldapi_ld_defaults.ld_sasl_secprops.maxbufsize = SASL_MAX_BUFF_SIZE; nsldapi_ld_defaults.ld_sasl_secprops.security_flags = SASL_SEC_NOPLAINTEXT | SASL_SEC_NOANONYMOUS; /* SASL mutex function callbacks */ sasl_set_mutex( (sasl_mutex_alloc_t *)nsldapi_default_thread_fns.ltf_mutex_alloc, (sasl_mutex_lock_t *)nsldapi_default_thread_fns.ltf_mutex_lock, (sasl_mutex_unlock_t *)nsldapi_default_thread_fns.ltf_mutex_unlock, (sasl_mutex_free_t *)nsldapi_default_thread_fns.ltf_mutex_free); /* SASL memory allocation function callbacks */ sasl_set_alloc((sasl_malloc_t *)ldap_x_malloc, (sasl_calloc_t *)ldap_x_calloc, (sasl_realloc_t *)ldap_x_realloc, (sasl_free_t *)ldap_x_free); /* SASL library initialization */ if (sasl_client_init(client_callbacks) != SASL_OK) { nsldapi_initialized = 0; pthread_mutex_unlock(&nsldapi_init_mutex); return; } #endif #if defined(STR_TRANSLATION) && defined(LDAP_DEFAULT_CHARSET) nsldapi_ld_defaults.ld_lberoptions |= LBER_OPT_TRANSLATE_STRINGS; # if LDAP_CHARSET_8859 == LDAP_DEFAULT_CHARSET ldap_set_string_translators(&nsldapi_ld_defaults, ldap_8859_to_t61, ldap_t61_to_8859); # endif /* LDAP_CHARSET_8859 == LDAP_DEFAULT_CHARSET */ #endif /* STR_TRANSLATION && LDAP_DEFAULT_CHARSET */ /* set default connect timeout (in milliseconds) */ /* this was picked as it is the standard tcp timeout as well */ nsldapi_ld_defaults.ld_connect_timeout = LDAP_X_IO_TIMEOUT_NO_TIMEOUT; #if defined(USE_PTHREADS) || defined(_WINDOWS) /* load up default platform specific locking routines */ if (ldap_set_option(&nsldapi_ld_defaults, LDAP_OPT_THREAD_FN_PTRS, (void *)&nsldapi_default_thread_fns) != LDAP_SUCCESS) { nsldapi_initialized = 0; pthread_mutex_unlock(&nsldapi_init_mutex); return; } # ifndef _WINDOWS /* load up default threadid function */ if (ldap_set_option(&nsldapi_ld_defaults, LDAP_OPT_EXTRA_THREAD_FN_PTRS, (void *)&nsldapi_default_extra_thread_fns) != LDAP_SUCCESS) { nsldapi_initialized = 0; pthread_mutex_unlock(&nsldapi_init_mutex); return; } # endif /* _WINDOWS */ nsldapi_initialized = 1; pthread_mutex_unlock(&nsldapi_init_mutex); #else nsldapi_initialized = 1; #endif /* use_pthreads || _windows */ }