From 10db566489880acd510f8e07dc52a38dd82feafe Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Fri, 3 Jun 2022 10:54:35 +0200 Subject: [PATCH] w32: Allow Unicode filenames for iobuf_cancel. * common/iobuf.c (iobuf_cancel): Use gnupg_remove * common/mischelp.c (same_file_p): Allow for Unicode names. -- Note that the second patch is used to handle Unicode filenames which are symbolic links. --- common/iobuf.c | 9 +-------- common/mischelp.c | 43 +++++++++++++++++++------------------------ doc/scdaemon.texi | 7 ++++--- 3 files changed, 24 insertions(+), 35 deletions(-) diff --git a/common/iobuf.c b/common/iobuf.c index 9245a03e8..07edbbefd 100644 --- a/common/iobuf.c +++ b/common/iobuf.c @@ -1197,14 +1197,7 @@ iobuf_cancel (iobuf_t a) { /* Argg, MSDOS does not allow removing open files. So * we have to do it here */ -#ifdef HAVE_W32CE_SYSTEM - wchar_t *wtmp = utf8_to_wchar (remove_name); - if (wtmp) - DeleteFile (wtmp); - xfree (wtmp); -#else - remove (remove_name); -#endif + gnupg_remove (remove_name); xfree (remove_name); } #endif diff --git a/common/mischelp.c b/common/mischelp.c index 81dd501f8..ee8500297 100644 --- a/common/mischelp.c +++ b/common/mischelp.c @@ -80,35 +80,30 @@ same_file_p (const char *name1, const char *name2) #ifdef HAVE_W32_SYSTEM HANDLE file1, file2; BY_HANDLE_FILE_INFORMATION info1, info2; + wchar_t *wname; + + wname = gpgrt_fname_to_wchar (name1); + if (wname) + { + file1 = CreateFileW (wname, 0, 0, NULL, OPEN_EXISTING, 0, NULL); + xfree (wname); + } + else + file1 = INVALID_HANDLE_VALUE; -#ifdef HAVE_W32CE_SYSTEM - { - wchar_t *wname = utf8_to_wchar (name1); - if (wname) - file1 = CreateFile (wname, 0, 0, NULL, OPEN_EXISTING, 0, NULL); - else - file1 = INVALID_HANDLE_VALUE; - xfree (wname); - } -#else - file1 = CreateFile (name1, 0, 0, NULL, OPEN_EXISTING, 0, NULL); -#endif if (file1 == INVALID_HANDLE_VALUE) yes = 0; /* If we can't open the file, it is not the same. */ else { -#ifdef HAVE_W32CE_SYSTEM - { - wchar_t *wname = utf8_to_wchar (name2); - if (wname) - file2 = CreateFile (wname, 0, 0, NULL, OPEN_EXISTING, 0, NULL); - else - file2 = INVALID_HANDLE_VALUE; - xfree (wname); - } -#else - file2 = CreateFile (name2, 0, 0, NULL, OPEN_EXISTING, 0, NULL); -#endif + wname = gpgrt_fname_to_wchar (name2); + if (wname) + { + file2 = CreateFileW (wname, 0, 0, NULL, OPEN_EXISTING, 0, NULL); + xfree (wname); + } + else + file2 = INVALID_HANDLE_VALUE; + if (file2 == INVALID_HANDLE_VALUE) yes = 0; /* If we can't open the file, it is not the same. */ else diff --git a/doc/scdaemon.texi b/doc/scdaemon.texi index 1271994c4..98fa70c9b 100644 --- a/doc/scdaemon.texi +++ b/doc/scdaemon.texi @@ -258,9 +258,10 @@ this option only if you know what you are doing. @item --pcsc-driver @var{library} @opindex pcsc-driver Use @var{library} to access the smartcard reader. The current default -is @file{libpcsclite.so}. Instead of using this option you might also -want to install a symbolic link to the default file name -(e.g. from @file{libpcsclite.so.1}). +on Unix is @file{libpcsclite.so} and on Windows @file{winscard.dll}. +Instead of using this option you might also want to install a symbolic +link to the default file name (e.g. from @file{libpcsclite.so.1}). +A Unicode file name may not be used on Windows. @item --ctapi-driver @var{library} @opindex ctapi-driver