From 9b1ac3dd401e25632fba992bd86a4a7902b30ceb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20Beauz=C3=A9e-Luyssen?= Date: Mon, 18 Feb 2019 14:41:56 +0100 Subject: Revert "Revert "verify-high2: Fix cert dir iteration on Win32"" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 681330882da19099eea360fab141cab937c45677. Signed-off-by: Hugo Beauzée-Luyssen --- lib/x509/verify-high2.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/lib/x509/verify-high2.c b/lib/x509/verify-high2.c index f4a580bb05..6c7cf99012 100644 --- a/lib/x509/verify-high2.c +++ b/lib/x509/verify-high2.c @@ -45,6 +45,10 @@ # endif #endif +#ifdef _WIN32 +# include +#endif + /* Convenience functions for verify-high functionality */ @@ -386,12 +390,14 @@ int load_dir_certs(const char *dirname, unsigned int tl_flags, unsigned int tl_vflags, unsigned type, unsigned crl) { - DIR *dirp; - struct dirent *d; int ret; int r = 0; char path[GNUTLS_PATH_MAX]; +#if !defined(_WIN32) || !defined(_UNICODE) + DIR *dirp; + struct dirent *d; + dirp = opendir(dirname); if (dirp != NULL) { do { @@ -422,7 +428,47 @@ int load_dir_certs(const char *dirname, while (d != NULL); closedir(dirp); } +#else /* _WIN32 */ + _TDIR *dirp; + struct _tdirent *d; + gnutls_datum_t utf16 = {NULL, 0}; + + r = _gnutls_utf8_to_ucs2(dirname, strlen(dirname), &utf16); + if (r < 0) + return gnutls_assert_val(r); + dirp = _topendir((_TCHAR*)utf16.data); + gnutls_free(utf16.data); + if (dirp != NULL) { + do { + d = _treaddir(dirp); + if (d != NULL +#ifdef _DIRENT_HAVE_D_TYPE + && (d->d_type == DT_REG || d->d_type == DT_LNK || d->d_type == DT_UNKNOWN) +#endif + ) { + snprintf(path, sizeof(path), "%s/%S", + dirname, d->d_name); + + if (crl != 0) { + ret = + gnutls_x509_trust_list_add_trust_file + (list, NULL, path, type, tl_flags, + tl_vflags); + } else { + ret = + gnutls_x509_trust_list_add_trust_file + (list, path, NULL, type, tl_flags, + tl_vflags); + } + if (ret >= 0) + r += ret; + } + } + while (d != NULL); + _tclosedir(dirp); + } +#endif /* _WIN32 */ return r; } -- cgit v1.2.1