ReactOS 0.4.15-dev-8408-g466a198
schannel_mbedtls_lazyload.h
Go to the documentation of this file.
1/* Copyright 2015 Ismael Ferreras Morezuelas <swyterzone+ros@gmail.com>
2 *
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public
5 * License as published by the Free Software Foundation; either
6 * version 2.1 of the License, or (at your option) any later version.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
16 *
17 * --
18 *
19 * This file transparently wraps lazy-loading hooks in the schannel
20 * implementation on top of the PolarSSL/mbedTLS open source library.
21 */
22
23static void *libmbedtls_handle;
24
25#define MAKE_FUNCPTR(f) static typeof(f) * p##f;
26
60
61#undef MAKE_FUNCPTR
62
63/* replace the initialization functions by our own, specially tailored, ones */
64
66{
68
70 {
71 WARN("Failed to load the mbedTLS dynamic library (" SONAME_LIBMBEDTLS ").\n");
72 return FALSE;
73 }
74
75#define LOAD_FUNCPTR(f) \
76 if (!(p##f = wine_dlsym(libmbedtls_handle, #f, NULL, 0))) \
77 { \
78 ERR("Failed to retrieve function %s from the mbedTLS dynamic library (" SONAME_LIBMBEDTLS ")\n", #f); \
79 goto fail; \
80 }
81
115
116#undef LOAD_FUNCPTR
117
118 return TRUE;
119
120fail:
121
124
125 return FALSE;
126}
127
128void schan_imp_deinit(void)
129{
132}
133
134/* now that we have overridden the initialization functions
135 cancel out the original stubs used when dynamically linking */
136
137#define schan_imp_init schan_imp_init_unused
138#define schan_imp_deinit schan_imp_deinit_unused
139
140/* seamlessly redirect the function pointers with some preprocessor magic */
141
142#define mbedtls_ctr_drbg_free pmbedtls_ctr_drbg_free
143#define mbedtls_ctr_drbg_init pmbedtls_ctr_drbg_init
144#define mbedtls_ctr_drbg_random pmbedtls_ctr_drbg_random
145#define mbedtls_entropy_free pmbedtls_entropy_free
146#define mbedtls_entropy_func pmbedtls_entropy_func
147#define mbedtls_entropy_init pmbedtls_entropy_init
148#define mbedtls_ssl_ciphersuite_from_id pmbedtls_ssl_ciphersuite_from_id
149#define mbedtls_ssl_free pmbedtls_ssl_free
150#define mbedtls_ssl_get_ciphersuite pmbedtls_ssl_get_ciphersuite
151#define mbedtls_ssl_get_ciphersuite_id pmbedtls_ssl_get_ciphersuite_id
152#define mbedtls_ssl_get_max_frag_len pmbedtls_ssl_get_max_frag_len
153#define mbedtls_ssl_get_version pmbedtls_ssl_get_version
154#define mbedtls_ssl_handshake pmbedtls_ssl_handshake
155#define mbedtls_ssl_init pmbedtls_ssl_init
156#define mbedtls_ssl_read pmbedtls_ssl_read
157#define mbedtls_ssl_conf_authmode pmbedtls_ssl_conf_authmode
158#define mbedtls_ssl_set_bio pmbedtls_ssl_set_bio
159#define mbedtls_ssl_conf_endpoint pmbedtls_ssl_conf_endpoint
160#define mbedtls_ssl_set_hostname pmbedtls_ssl_set_hostname
161#define mbedtls_ssl_conf_max_version pmbedtls_ssl_conf_max_version
162#define mbedtls_ssl_conf_min_version pmbedtls_ssl_conf_min_version
163#define mbedtls_ssl_conf_rng pmbedtls_ssl_conf_rng
164#define mbedtls_ssl_write pmbedtls_ssl_write
165#define mbedtls_ssl_get_peer_cert pmbedtls_ssl_get_peer_cert
166#define mbedtls_ssl_config_init pmbedtls_ssl_config_init
167#define mbedtls_ssl_config_free pmbedtls_ssl_config_free
168#define mbedtls_ssl_config_defaults pmbedtls_ssl_config_defaults
169#define mbedtls_ssl_conf_dbg pmbedtls_ssl_conf_dbg
170#define mbedtls_ssl_setup pmbedtls_ssl_setup
171#define mbedtls_cipher_info_from_type pmbedtls_cipher_info_from_type
172#define mbedtls_md_info_from_type pmbedtls_md_info_from_type
173#define mbedtls_pk_get_bitlen pmbedtls_pk_get_bitlen
174#define mbedtls_ctr_drbg_seed pmbedtls_ctr_drbg_seed
#define WARN(fmt,...)
Definition: precomp.h:61
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
void * wine_dlopen(const char *filename, int flag, char *error, size_t errorsize)
Definition: loader.c:53
int wine_dlclose(void *handle, char *error, size_t errorsize)
Definition: loader.c:58
#define RTLD_NOW
Definition: port.h:100
#define mbedtls_ssl_free
#define mbedtls_ssl_get_max_frag_len
static void * libmbedtls_handle
#define mbedtls_md_info_from_type
#define mbedtls_ssl_init
#define mbedtls_ssl_set_hostname
#define mbedtls_ctr_drbg_seed
#define mbedtls_ctr_drbg_random
#define mbedtls_entropy_free
#define mbedtls_ctr_drbg_init
#define schan_imp_init
#define mbedtls_entropy_init
#define mbedtls_ssl_conf_authmode
#define mbedtls_entropy_func
#define mbedtls_ssl_write
#define mbedtls_ssl_conf_endpoint
#define mbedtls_cipher_info_from_type
#define mbedtls_pk_get_bitlen
#define mbedtls_ssl_config_defaults
#define MAKE_FUNCPTR(f)
#define mbedtls_ssl_get_ciphersuite_id
#define mbedtls_ssl_setup
#define LOAD_FUNCPTR(f)
#define mbedtls_ssl_set_bio
#define schan_imp_deinit
#define mbedtls_ssl_conf_rng
#define mbedtls_ssl_config_free
#define mbedtls_ssl_handshake
#define mbedtls_ssl_get_version
#define mbedtls_ssl_get_peer_cert
#define mbedtls_ssl_conf_max_version
#define mbedtls_ctr_drbg_free
#define mbedtls_ssl_ciphersuite_from_id
#define mbedtls_ssl_read
#define mbedtls_ssl_conf_min_version
#define mbedtls_ssl_conf_dbg
#define mbedtls_ssl_config_init
#define mbedtls_ssl_get_ciphersuite
#define SONAME_LIBMBEDTLS
Definition: config.h:1245