From: Nikos Mavrogiannopoulos Date: Sat, 15 Sep 2012 11:43:28 +0000 (+0200) Subject: mingw32 support. Based on patch by LRN. X-Git-Tag: gnutls_3_1_2~69 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2cc740eb52abac318176c49f8e8358666c8457cd;p=thirdparty%2Fgnutls.git mingw32 support. Based on patch by LRN. --- diff --git a/lib/gnutls_global.c b/lib/gnutls_global.c index 8b84f46f5a..4c9eabf394 100644 --- a/lib/gnutls_global.c +++ b/lib/gnutls_global.c @@ -270,6 +270,13 @@ gnutls_global_init (void) goto out; } + result = gnutls_system_global_init (); + if (result < 0) + { + gnutls_assert (); + goto out; + } + #ifdef ENABLE_PKCS11 gnutls_pkcs11_init (GNUTLS_PKCS11_FLAG_AUTO, NULL); #endif @@ -302,6 +309,7 @@ gnutls_global_deinit (void) asn1_delete_structure (&_gnutls_pkix1_asn); _gnutls_crypto_deregister (); _gnutls_cryptodev_deinit (); + gnutls_system_global_deinit (); #ifdef ENABLE_PKCS11 gnutls_pkcs11_deinit (); #endif diff --git a/lib/system.c b/lib/system.c index 067f189bf1..b22e07d590 100644 --- a/lib/system.c +++ b/lib/system.c @@ -31,6 +31,11 @@ #ifdef _WIN32 # include # include +# if defined(__MINGW32__) && !defined(__MINGW64__) && __MINGW32_MAJOR_VERSION <= 3 && __MINGW32_MINOR_VERSION <= 20 +typedef PCCRL_CONTEXT WINAPI (*Type_CertEnumCRLsInStore) (HCERTSTORE hCertStore, PCCRL_CONTEXT pPrevCrlContext); +static Type_CertEnumCRLsInStore Loaded_CertEnumCRLsInStore; +static HMODULE Crypt32_dll; +# endif #else # ifdef HAVE_PTHREAD_LOCKS @@ -51,10 +56,7 @@ /* System specific function wrappers. */ -/* wrappers for write() and writev() - */ #ifdef _WIN32 - int system_errno (gnutls_transport_ptr p) { @@ -150,9 +152,6 @@ int fd = GNUTLS_POINTER_TO_INT(ptr); /* Thread stuff */ #ifdef HAVE_WIN32_LOCKS - - -/* FIXME: win32 locks are untested */ static int gnutls_system_mutex_init (void **priv) { @@ -285,6 +284,41 @@ mutex_deinit_func gnutls_mutex_deinit = gnutls_system_mutex_deinit; mutex_lock_func gnutls_mutex_lock = gnutls_system_mutex_lock; mutex_unlock_func gnutls_mutex_unlock = gnutls_system_mutex_unlock; +int +gnutls_system_global_init () +{ +#ifdef _WIN32 +# if defined(__MINGW32__) && !defined(__MINGW64__) && __MINGW32_MAJOR_VERSION <= 3 && __MINGW32_MINOR_VERSION <= 20 + HMODULE crypto; + crypto = LoadLibraryA ("Crypt32.dll"); + + if (crypto == NULL) + return GNUTLS_E_CRYPTO_INIT_FAILED; + + Loaded_CertEnumCRLsInStore = (Type_CertEnumCRLsInStore) GetProcAddress (crypto, "CertEnumCRLsInStore"); + if (Loaded_CertEnumCRLsInStore == NULL) + { + FreeLibrary (crypto); + return GNUTLS_E_CRYPTO_INIT_FAILED; + } + + Crypt32_dll = crypto; +# endif +#endif + return 0; +} + +void +gnutls_system_global_deinit () +{ +#ifdef _WIN32 +# if defined(__MINGW32__) && !defined(__MINGW64__) && __MINGW32_MAJOR_VERSION <= 3 && __MINGW32_MINOR_VERSION <= 20 + FreeLibrary (Crypt32_dll); +# endif +#endif +} + + #define CONFIG_PATH ".gnutls" /* Returns a path to store user-specific configuration @@ -392,7 +426,7 @@ gnutls_x509_trust_list_add_system_trust(gnutls_x509_trust_list_t list, if (store == NULL) return GNUTLS_E_FILE_ERROR; cert = CertEnumCertificatesInStore(store, NULL); - crl = CertEnumCRLsInStore(store, NULL); + crl = Loaded_CertEnumCRLsInStore(store, NULL); while(cert != NULL) { @@ -414,7 +448,7 @@ gnutls_x509_trust_list_add_system_trust(gnutls_x509_trust_list_t list, data.size = crl->cbCrlEncoded; gnutls_x509_trust_list_add_trust_mem(list, NULL, &data, GNUTLS_X509_FMT_DER, tl_flags, tl_vflags); } - crl = CertEnumCRLsInStore(store, crl); + crl = Loaded_CertEnumCRLsInStore(store, crl); } CertCloseStore(store, 0); } diff --git a/lib/system.h b/lib/system.h index 0178bd58ef..0afbdd2554 100644 --- a/lib/system.h +++ b/lib/system.h @@ -71,4 +71,7 @@ struct timespec ts; int _gnutls_find_config_path(char* path, size_t max_size); +int gnutls_system_global_init (); +void gnutls_system_global_deinit (); + #endif /* SYSTEM_H */