From: Nikos Mavrogiannopoulos Date: Sat, 2 Mar 2013 09:18:45 +0000 (+0100) Subject: some simplifications in gnutls_x509_trust_list_add_system_trust() X-Git-Tag: gnutls_3_1_10~81 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=4f123f701cdbb2cfd8717c82b5bcb495d14048c5;p=thirdparty%2Fgnutls.git some simplifications in gnutls_x509_trust_list_add_system_trust() --- diff --git a/lib/Makefile.am b/lib/Makefile.am index a9bd6ff684..a34977c0ef 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -72,7 +72,7 @@ COBJECTS = gnutls_range.c gnutls_record.c \ gnutls_global.c gnutls_constate.c gnutls_anon_cred.c \ $(srcdir)/pkix_asn1_tab.c \ $(srcdir)/gnutls_asn1_tab.c \ - gnutls_mem.c gnutls_ui.c \ + gnutls_mem.c gnutls_ui.c \ gnutls_sig.c gnutls_ecc.c gnutls_dh_primes.c gnutls_alert.c \ system.c gnutls_str.c gnutls_state.c gnutls_x509.c \ gnutls_rsa_export.c gnutls_helper.c gnutls_supplemental.c \ diff --git a/lib/system.c b/lib/system.c index f42938d2d3..53e2939900 100644 --- a/lib/system.c +++ b/lib/system.c @@ -383,36 +383,10 @@ const char *home_dir = getenv ("HOME"); return 0; } -/** - * gnutls_x509_trust_list_add_system_trust: - * @list: The structure of the list - * @tl_flags: GNUTLS_TL_* - * @tl_vflags: gnutls_certificate_verify_flags if flags specifies GNUTLS_TL_VERIFY_CRL - * - * This function adds the system's default trusted certificate - * authorities to the trusted list. Note that on unsupported system - * this function returns %GNUTLS_E_UNIMPLEMENTED_FEATURE. - * - * Returns: The number of added elements or a negative error code on error. - * - * Since: 3.1 - **/ -int -gnutls_x509_trust_list_add_system_trust(gnutls_x509_trust_list_t list, - unsigned int tl_flags, unsigned int tl_vflags) +#ifdef _WIN32 +static +int add_win32_system_trust(gnutls_x509_trust_list_t list, unsigned int tl_flags, unsigned int tl_vflags) { -#if !defined(DEFAULT_TRUST_STORE_PKCS11) && !defined(DEFAULT_TRUST_STORE_FILE) && !defined(_WIN32) - return GNUTLS_E_UNIMPLEMENTED_FEATURE; -#else - int ret, r = 0; - const char* crl_file = -# ifdef DEFAULT_CRL_FILE - DEFAULT_CRL_FILE; -# else - NULL; -# endif - -# ifdef _WIN32 unsigned int i; for (i=0;i<2;i++) @@ -454,23 +428,57 @@ gnutls_x509_trust_list_add_system_trust(gnutls_x509_trust_list_t list, } CertCloseStore(store, 0); } -# endif +} +#endif -# if defined(ENABLE_PKCS11) && defined(DEFAULT_TRUST_STORE_PKCS11) +/** + * gnutls_x509_trust_list_add_system_trust: + * @list: The structure of the list + * @tl_flags: GNUTLS_TL_* + * @tl_vflags: gnutls_certificate_verify_flags if flags specifies GNUTLS_TL_VERIFY_CRL + * + * This function adds the system's default trusted certificate + * authorities to the trusted list. Note that on unsupported system + * this function returns %GNUTLS_E_UNIMPLEMENTED_FEATURE. + * + * Returns: The number of added elements or a negative error code on error. + * + * Since: 3.1 + **/ +int +gnutls_x509_trust_list_add_system_trust(gnutls_x509_trust_list_t list, + unsigned int tl_flags, unsigned int tl_vflags) +{ +#if defined(_WIN32) + return add_win32_system_trust(list, tl_flags, tl_vflags); +#else + +# if !defined(DEFAULT_TRUST_STORE_PKCS11) && !defined(DEFAULT_TRUST_STORE_FILE) + return GNUTLS_E_UNIMPLEMENTED_FEATURE; +# else + int ret, r = 0; + const char* crl_file = +# ifdef DEFAULT_CRL_FILE + DEFAULT_CRL_FILE; +# else + NULL; +# endif + +# if defined(ENABLE_PKCS11) && defined(DEFAULT_TRUST_STORE_PKCS11) ret = gnutls_x509_trust_list_add_trust_file(list, DEFAULT_TRUST_STORE_PKCS11, crl_file, GNUTLS_X509_FMT_DER, tl_flags, tl_vflags); if (ret > 0) r += ret; -# endif +# endif -# ifdef DEFAULT_TRUST_STORE_FILE +# ifdef DEFAULT_TRUST_STORE_FILE ret = gnutls_x509_trust_list_add_trust_file(list, DEFAULT_TRUST_STORE_FILE, crl_file, GNUTLS_X509_FMT_PEM, tl_flags, tl_vflags); if (ret > 0) r += ret; -# endif +# endif return r; -#endif +# endif } #if defined(HAVE_ICONV)