Commit 2cecf544 authored by Ken Thomases's avatar Ken Thomases Committed by Alexandre Julliard

secur32: Extract schan_imp_init/deinit functions.

parent 9124cdc2
...@@ -391,6 +391,86 @@ static void schan_imp_free_certificate_credentials(schan_imp_certificate_credent ...@@ -391,6 +391,86 @@ static void schan_imp_free_certificate_credentials(schan_imp_certificate_credent
pgnutls_certificate_free_credentials((gnutls_certificate_credentials)c); pgnutls_certificate_free_credentials((gnutls_certificate_credentials)c);
} }
static void schan_gnutls_log(int level, const char *msg)
{
TRACE("<%d> %s", level, msg);
}
static BOOL schan_imp_init(void)
{
int ret;
libgnutls_handle = wine_dlopen(SONAME_LIBGNUTLS, RTLD_NOW, NULL, 0);
if (!libgnutls_handle)
{
WARN("Failed to load libgnutls.\n");
return FALSE;
}
#define LOAD_FUNCPTR(f) \
if (!(p##f = wine_dlsym(libgnutls_handle, #f, NULL, 0))) \
{ \
ERR("Failed to load %s\n", #f); \
goto fail; \
}
LOAD_FUNCPTR(gnutls_alert_get)
LOAD_FUNCPTR(gnutls_alert_get_name)
LOAD_FUNCPTR(gnutls_certificate_allocate_credentials)
LOAD_FUNCPTR(gnutls_certificate_free_credentials)
LOAD_FUNCPTR(gnutls_certificate_get_peers)
LOAD_FUNCPTR(gnutls_cipher_get)
LOAD_FUNCPTR(gnutls_cipher_get_key_size)
LOAD_FUNCPTR(gnutls_credentials_set)
LOAD_FUNCPTR(gnutls_deinit)
LOAD_FUNCPTR(gnutls_global_deinit)
LOAD_FUNCPTR(gnutls_global_init)
LOAD_FUNCPTR(gnutls_global_set_log_function)
LOAD_FUNCPTR(gnutls_global_set_log_level)
LOAD_FUNCPTR(gnutls_handshake)
LOAD_FUNCPTR(gnutls_init)
LOAD_FUNCPTR(gnutls_kx_get)
LOAD_FUNCPTR(gnutls_mac_get)
LOAD_FUNCPTR(gnutls_mac_get_key_size)
LOAD_FUNCPTR(gnutls_perror)
LOAD_FUNCPTR(gnutls_protocol_get_version)
LOAD_FUNCPTR(gnutls_set_default_priority)
LOAD_FUNCPTR(gnutls_record_recv);
LOAD_FUNCPTR(gnutls_record_send);
LOAD_FUNCPTR(gnutls_transport_set_errno)
LOAD_FUNCPTR(gnutls_transport_set_ptr)
LOAD_FUNCPTR(gnutls_transport_set_pull_function)
LOAD_FUNCPTR(gnutls_transport_set_push_function)
#undef LOAD_FUNCPTR
ret = pgnutls_global_init();
if (ret != GNUTLS_E_SUCCESS)
{
pgnutls_perror(ret);
goto fail;
}
if (TRACE_ON(secur32))
{
pgnutls_global_set_log_level(4);
pgnutls_global_set_log_function(schan_gnutls_log);
}
return TRUE;
fail:
wine_dlclose(libgnutls_handle, NULL, 0);
libgnutls_handle = NULL;
return FALSE;
}
static void schan_imp_deinit(void)
{
pgnutls_global_deinit();
wine_dlclose(libgnutls_handle, NULL, 0);
libgnutls_handle = NULL;
}
#define SCHAN_INVALID_HANDLE ~0UL #define SCHAN_INVALID_HANDLE ~0UL
...@@ -1520,11 +1600,6 @@ static SECURITY_STATUS SEC_ENTRY schan_DeleteSecurityContext(PCtxtHandle context ...@@ -1520,11 +1600,6 @@ static SECURITY_STATUS SEC_ENTRY schan_DeleteSecurityContext(PCtxtHandle context
return SEC_E_OK; return SEC_E_OK;
} }
static void schan_gnutls_log(int level, const char *msg)
{
TRACE("<%d> %s", level, msg);
}
static const SecurityFunctionTableA schanTableA = { static const SecurityFunctionTableA schanTableA = {
1, 1,
NULL, /* EnumerateSecurityPackagesA */ NULL, /* EnumerateSecurityPackagesA */
...@@ -1616,63 +1691,9 @@ void SECUR32_initSchannelSP(void) ...@@ -1616,63 +1691,9 @@ void SECUR32_initSchannelSP(void)
(SEC_WCHAR *)schannelComment }, (SEC_WCHAR *)schannelComment },
}; };
SecureProvider *provider; SecureProvider *provider;
int ret;
libgnutls_handle = wine_dlopen(SONAME_LIBGNUTLS, RTLD_NOW, NULL, 0); if (!schan_imp_init())
if (!libgnutls_handle)
{
WARN("Failed to load libgnutls.\n");
return; return;
}
#define LOAD_FUNCPTR(f) \
if (!(p##f = wine_dlsym(libgnutls_handle, #f, NULL, 0))) \
{ \
ERR("Failed to load %s\n", #f); \
goto fail; \
}
LOAD_FUNCPTR(gnutls_alert_get)
LOAD_FUNCPTR(gnutls_alert_get_name)
LOAD_FUNCPTR(gnutls_certificate_allocate_credentials)
LOAD_FUNCPTR(gnutls_certificate_free_credentials)
LOAD_FUNCPTR(gnutls_certificate_get_peers)
LOAD_FUNCPTR(gnutls_cipher_get)
LOAD_FUNCPTR(gnutls_cipher_get_key_size)
LOAD_FUNCPTR(gnutls_credentials_set)
LOAD_FUNCPTR(gnutls_deinit)
LOAD_FUNCPTR(gnutls_global_deinit)
LOAD_FUNCPTR(gnutls_global_init)
LOAD_FUNCPTR(gnutls_global_set_log_function)
LOAD_FUNCPTR(gnutls_global_set_log_level)
LOAD_FUNCPTR(gnutls_handshake)
LOAD_FUNCPTR(gnutls_init)
LOAD_FUNCPTR(gnutls_kx_get)
LOAD_FUNCPTR(gnutls_mac_get)
LOAD_FUNCPTR(gnutls_mac_get_key_size)
LOAD_FUNCPTR(gnutls_perror)
LOAD_FUNCPTR(gnutls_protocol_get_version)
LOAD_FUNCPTR(gnutls_set_default_priority)
LOAD_FUNCPTR(gnutls_record_recv);
LOAD_FUNCPTR(gnutls_record_send);
LOAD_FUNCPTR(gnutls_transport_set_errno)
LOAD_FUNCPTR(gnutls_transport_set_ptr)
LOAD_FUNCPTR(gnutls_transport_set_pull_function)
LOAD_FUNCPTR(gnutls_transport_set_push_function)
#undef LOAD_FUNCPTR
ret = pgnutls_global_init();
if (ret != GNUTLS_E_SUCCESS)
{
pgnutls_perror(ret);
goto fail;
}
if (TRACE_ON(secur32))
{
pgnutls_global_set_log_level(4);
pgnutls_global_set_log_function(schan_gnutls_log);
}
schan_handle_table = HeapAlloc(GetProcessHeap(), 0, 64 * sizeof(*schan_handle_table)); schan_handle_table = HeapAlloc(GetProcessHeap(), 0, 64 * sizeof(*schan_handle_table));
if (!schan_handle_table) if (!schan_handle_table)
...@@ -1696,8 +1717,7 @@ void SECUR32_initSchannelSP(void) ...@@ -1696,8 +1717,7 @@ void SECUR32_initSchannelSP(void)
fail: fail:
HeapFree(GetProcessHeap(), 0, schan_handle_table); HeapFree(GetProcessHeap(), 0, schan_handle_table);
schan_handle_table = NULL; schan_handle_table = NULL;
wine_dlclose(libgnutls_handle, NULL, 0); schan_imp_deinit();
libgnutls_handle = NULL;
return; return;
} }
...@@ -1705,7 +1725,7 @@ void SECUR32_deinitSchannelSP(void) ...@@ -1705,7 +1725,7 @@ void SECUR32_deinitSchannelSP(void)
{ {
SIZE_T i = schan_handle_count; SIZE_T i = schan_handle_count;
if (!libgnutls_handle) return; if (!schan_handle_table) return;
/* deinitialized sessions first because a pointer to the credentials /* deinitialized sessions first because a pointer to the credentials
* may be stored for the session. */ * may be stored for the session. */
...@@ -1730,8 +1750,7 @@ void SECUR32_deinitSchannelSP(void) ...@@ -1730,8 +1750,7 @@ void SECUR32_deinitSchannelSP(void)
} }
} }
HeapFree(GetProcessHeap(), 0, schan_handle_table); HeapFree(GetProcessHeap(), 0, schan_handle_table);
pgnutls_global_deinit(); schan_imp_deinit();
wine_dlclose(libgnutls_handle, NULL, 0);
} }
#else /* SONAME_LIBGNUTLS */ #else /* SONAME_LIBGNUTLS */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment