Beispiel #1
0
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_mutex(saslMutexAlloc,
                    saslMutexLock,
                    saslMutexUnlock,
                    saslMutexFree);
     return Status::OK();
 }
Beispiel #3
0
static MONGOC_ONCE_FUN( _mongoc_do_init)
{
#ifdef MONGOC_ENABLE_SSL_OPENSSL
   _mongoc_openssl_init();
#endif

#ifdef MONGOC_ENABLE_SSL
   _mongoc_scram_startup();
#endif

#ifdef MONGOC_ENABLE_SASL
   /* The following functions should not use tracing, as they may be invoked
    * before mongoc_log_set_handler() can complete. */
   sasl_set_mutex (mongoc_sasl_mutex_alloc,
                   mongoc_sasl_mutex_lock,
                   mongoc_sasl_mutex_unlock,
                   mongoc_sasl_mutex_free);

   /* TODO: logging callback? */
   sasl_client_init (NULL);
#endif

   _mongoc_counters_init();

#ifdef _WIN32
   {
      WORD wVersionRequested;
      WSADATA wsaData;
      int err;

      wVersionRequested = MAKEWORD (2, 2);

      err = WSAStartup (wVersionRequested, &wsaData);

      /* check the version perhaps? */

      BSON_ASSERT (err == 0);
   }
#endif

   MONGOC_ONCE_RETURN;
}
Beispiel #4
0
DWORD
VmDirSASLInit(
    VOID
    )
{
    DWORD       dwError = 0;

    static sasl_callback_t saslServerCB[] =
    {
        { SASL_CB_LOG, (int (*)(void))_VmDirSASLLog, NULL },
        { SASL_CB_GETPATH, (int (*)(void)) _VmDirSASL2PATH, &g_pszSASL2Path },
        { SASL_CB_LIST_END, NULL, NULL }
    };

    dwError = VmDirSASL2PATH(&g_pszSASL2Path);
    BAIL_ON_VMDIR_ERROR(dwError);

    // provide SASL mutex functions
    sasl_set_mutex( _VmDirSASLMutexNew,
                    _VmDirSASLMutexLock,
                    _VmDirSASLMutexUnlock,
                    _VmDirSASLMutexDispose);

    dwError = sasl_server_init( saslServerCB, "vmdird");
    BAIL_ON_SASL_ERROR(dwError);

cleanup:

    return dwError;

error:

    VMDIR_SAFE_FREE_MEMORY(g_pszSASL2Path);
sasl_error:

    goto cleanup;
}
Beispiel #5
0
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 */
}