Commit Graph

55 Commits

Author SHA1 Message Date
Ingo Klöcker
57205c1dfa
doc: Fix typos in documentation and source code comments
--

Anonymous contribution

Signed-off-by: Ingo Klöcker <dev@ingo-kloecker.de>
2023-10-13 09:18:12 +02:00
Andre Heinecke
fe2892618c
core,w32: Initialize dbg_help for socket debugging
* src/w32-io.c (_gpgme_io_select): Initialize dbg_help.

--
This fixes a crash on Windows because dbg_help might
be used unitialized.
2019-10-28 16:02:22 +01:00
Andre Heinecke
a82e3a0ae5
core,w32: Improve handling of Unicode paths
* src/dirinfo.c (get_gpgconf_item): Use _gpgme_access.
* src/posix-util.c (_gpgme_access): Add forward to normal access.
* src/sys-util.h (_gpgme_access): New for posix and w32.
* src/w32-io.c (_gpgme_io_spawn): Use _gpgme_crate_process_utf8.
* src/w32-util.c (utf8_to_wchar, utf8_to_wchar0): The usual w32 conv.
(find_program_in_dir): Use _gpgme_access.
(find_program_at_standard_place): Use wchar API and convert to UTF-8.
(_gpgme_access): Convert UTF-8 to wchar and use wchar API.
(_gpgme_create_process_utf8): Convert UTF-8 to wchar and use wchar API.

--
While we should not say that we have full support for unicode path
installations of GnuPG, this ensures that GPGME works if GPGME
itself is installed in a unicode path. e.g.: Libreoffice supports
this.

GnuPG-Bug-Id: T4453

Based on a patch provided by Egor Pugin. Thanks.
2019-04-09 13:42:58 +02:00
Andre Heinecke
937adfdcbb
core,w32: Show w32-spawn warning only once
* src/w32-io.c (_gpgme_io_spawn): Show MessageBox only once.

--
This prevents multiple message boxes from showing when
the GPGME installation is unworkable.

GnuPG-Bug-Id: T4453
2019-04-09 13:25:08 +02:00
Werner Koch
b182838f71
core: Fix format string errors in w32-io.c and use of TRACE_SUC.
* src/w32-io.c: Fix use of TRACE_SUC.  Fix some format strung errors.

Signed-off-by: Werner Koch <wk@gnupg.org>
2018-11-19 12:49:40 +01:00
Werner Koch
5857491a2a
core: Simplify the trace maros by using variadics.
* src/debug.h (TRACE_BEG, TRACE_LOG, TRACE_SUC): Use variadic macros
and remove the TRACE_BEG1 et al.  Change all users to always pass a
format string.
(TRACE): Ditto.
* src/debug.c (_gpgme_debugf): New.
* configure.ac <GCC>: Add -Wno-format-zero-length.
--

This makes it easier for use to enable format checks.  The zero-length
format is required to allow for an empty format due to the comman
problematic of __VA_ARGS__.

Signed-off-by: Werner Koch <wk@gnupg.org>
2018-11-16 16:25:49 +01:00
Daniel Kahn Gillmor
2557d0ae6f spelling: fix misspellings
Signed-off-by: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
2018-11-08 12:34:27 +07:00
Werner Koch
5262ce0c81
w32: Fix a few compiler warnings.
* src/debug.h (TRACE_SYSERR_NR): New.
* src/w32-io.c: Fix compiler warnings.

Signed-off-by: Werner Koch <wk@gnupg.org>
2018-11-02 12:54:22 +01:00
Werner Koch
ed3f5ad760
w32: Log all errors from CloseHandle and WFSO in w32-io.
* src/w32-io.c (close_handle, _close_handle): New macro and function;
use in place of all CloseHandle calls.
(wait_for_single_object, _wait_for_single_object): Likewise.

Signed-off-by: Werner Koch <wk@gnupg.org>
2018-11-02 12:28:17 +01:00
Werner Koch
da89528ac3
w32: Revamp the closing of system objects.
* src/w32-io.c (hddesc_t): New.
(reader_context_s, writer_context_s): Replace file_sock and file_hd by
the hddesc_t hdd.
(fd_table): Ditto.  Add want_reader and want_writer.
(hddesc_lock): New lock variable.
(new_hddesc, ref_hddesc): New.
(release_hddesc): New.
(reader, writer): Call release_hddesc.
(create_reader, create_writer): Change for new hddesc scheme.
(destroy_reader, destroy_writer): Replace closing by a call to
release_hddesc.
(_gpgme_io_pipe): Change for new hddesc scheme.
(_gpgme_io_close): Ditto.
(_gpgme_io_dup): Ditto.  Use want_reader and want_writer.
(_gpgme_io_socket): Change for new hddesc scheme.
--

GnuPG-bug-id: 4237
Signed-off-by: Werner Koch <wk@gnupg.org>
2018-11-02 09:14:58 +01:00
Werner Koch
63ba09b541
w32: Use CancelSynchronousIo in destroy_reader.
* src/w32-util.c (_gpgme_w32_cancel_synchronous_io): New.
* src/w32-io.c (destroy_reader): Use it here.
--

This has not been tested but should on Vista and later help to fix a
possible hang.

Signed-off-by: Werner Koch <wk@gnupg.org>
2018-11-01 09:55:24 +01:00
Werner Koch
338e9edfdb
w32: Merge all the object tables of w32-io into one.
* src/w32-io.c (fd_table_size): New.  Used in most places instead of
the MAX_SLAFD constant.
(reader_table, writer_table, notify_table): Merge them into ...
(fd_table): this table.  Chnage all affected code to take just one
lock.

Signed-off-by: Werner Koch <wk@gnupg.org>
2018-11-01 09:53:48 +01:00
Werner Koch
79fc7c0fe8
w32: Remove unused arg from two functions.
* src/w32-io.c (find_reader, find_writer): Remove unused start_it
arg.  It is always passed as true.  Change callers.

Signed-off-by: Werner Koch <wk@gnupg.org>
2018-10-31 14:58:23 +01:00
Werner Koch
3c04dea3ec
w32: Remove all support for WindowsCE
* configure.ac: Remove WindwosCE support.
* contrib/: Remove all; it was only used for WindowsCE.
* src/w32-ce.c, src/w32-ce.h: Remove files.
* src/Makefile.am (system_components): Remove these files.
* src/ath.c, src/ath.h: Remove W32CE support.
* src/data-compat.c (gpgme_data_new_from_filepart): Ditto.
(gpgme_data_new_from_file): Ditto.
* src/debug.c (debug_init, _gpgme_debug): Ditto.
* src/gpgme-tool.c (gpgme_server): Ditto.
(main): Ditto.
* src/priv-io.h: Do not include w32-ce.h.
* src/util.h: Remove WindowsCE support.
* src/w32-io.c: Ditto.
* src/w32-util.c: Ditto.
* src/debug.h (TRACE_SUC4): New.
--

There is no more hardware to test our code, the support for Windows CE
terminated along time ago.  Note that our code worked only with the
old WindowsCE with that overall system limit of 31 processes.

Signed-off-by: Werner Koch <wk@gnupg.org>
2018-10-31 12:35:14 +01:00
Werner Koch
2e07d4f89a
w32: Remove cruft in w32-io from WindowsME times.
* src/w32-io.c (set_synchronize): Remove.
(create_reader, create_writer): No need for set_synchronize.
--

The set_synchronize dates back to 2001 at a time when I wrote the
Windows support on WindowsME and Windows2000.  Maybe this was required
then due to bugs in that old NT or partly NT based Windows versions.

Signed-off-by: Werner Koch <wk@gnupg.org>
2018-10-31 12:00:08 +01:00
Werner Koch
9eef23fcf3
w32: Fix previous commit.
* src/w32-io.c (_gpgme_io_spawn): Move freeing of TMP_NAME behind its
use in an error handling.

Signed-off-by: Werner Koch <wk@gnupg.org>
2018-10-30 11:19:33 +01:00
Andre Heinecke
7a1b58045f
core,w32: Fix memleak of tmp_name in w32-io
* src/w32-io.c (_gpgme_io_spawn): Free tmp_name.

--
GnuPG-Bug-Id: T4238
2018-10-29 19:44:02 +01:00
Andre Heinecke
f10605ffb5
core, w32: Fix flags passing to gpgme-w32-spawn
* src/w32-io.c (_gpgme_io_spawn): Don't hardcode flags value.

--
IOSPAWN_FLAG_ALLOW_SET_FG is 2 and was translated to 1.

This might fix the pinentry foreground handling pass through.
2018-02-09 16:11:03 +01:00
Werner Koch
15050ce5fc
core: Replace all calls to *sprintf by gpgrt_*sprintf.
* configure.ac (vasprintf): Remove check.
* src/vasprintf.c: Remove file.
* src/util.h (vasprintf, asprintf): Remove prototypes.  Replace all
calls to vasprintf and asprintf by gpgrt_vasprintf or gpgrt_asprintf.
Also take care to use gpgrt_free on the returned value.
* src/w32-util.c (_gpgme_get_gpgconf_path): Replace a gpgrt_asprintf
by _gpgme_strconcat.
(snprintf): New macro to use gpgrt_snprintf instead of the system's
standard snprintf.

Signed-off-by: Werner Koch <wk@gnupg.org>
2017-02-02 12:35:59 +01:00
Justus Winter
6f02133bb0 w32: Fix closing file descriptors.
* src/w32-io.c (writer): Only stop once the buffer is drained.
(destroy_writer): Wait for the writers buffer to be drained.  This
aligns '_gpgme_io_close's behavior with close(2) and fclose(3).

GnuPG-bug-id: 2881
Signed-off-by: Justus Winter <justus@g10code.com>
2017-01-23 15:08:23 +01:00
Werner Koch
10f2e1c30b
w32: Better protect the IO-system's fd_table
* src/w32-io.c (fd_table_lock): New.
(new_fd): Lock allocation of a new slot.
(release_fd): Lock deallocation of a slot.
--

Note that we lock only the allocation but not the sanitiy checks we do
further down in the code.

Signed-off-by: Werner Koch <wk@gnupg.org>
2016-11-09 08:34:15 +01:00
Andre Heinecke
30f156280f core: Remove (now) useless diagnostic
* src/w32-io.c(_gpgme_io_spawn): Remove spawnhelper not found
diagnostic.

--
When spawnhelper is not found the error is now catched before
the CreateProcess call so the added diagnostic in bb2d11c
(which was not helpful because the value for spawnhelper
would be NULL in that case) is now no longer needed.
2016-08-18 17:14:36 +02:00
Andre Heinecke
9cf983b019 core: Fail loudly in case w32 spawner not found
* src/w32-io.c (_gpgme_io_spawn): Show a message box in
case gpgme-w32spawn.exe not found.

--
Otherwise every engine call will just fail with unsupported
protocol. Even in the debug output the problem was not made
clear because CreateProcess will fail with error code 87
(Invalid Parameter) because spawnhelper is NULL. The helpful
error message for ERROR_INVALID_PARAMETER would have been:
"is 'NULL' correctly installed"

As GpgME basically becomes useless on Windows without the
spawnhelper we want to fail very loud in that case.
2016-08-18 17:09:04 +02:00
Justus Winter
8c61cbfb8f Fix typos found by codespell.
--
Signed-off-by: Justus Winter <justus@g10code.com>
2015-12-02 11:28:07 +01:00
Werner Koch
bb2d11c1ee
w32: Add extra diagnostic about possible missing gpgme-w32spawn.exe.
* src/w32-io.c (_gpgme_io_spawn): Add a new diagnostic.

Signed-off-by: Werner Koch <wk@gnupg.org>
2015-10-28 16:28:48 +01:00
Werner Koch
62711e5614 w32: Fix another memleak on error.
* src/w32-io.c (create_reader): free CTX.
--

Found by Hans-Christoph Steiner with cppcheck.
2014-04-16 10:19:54 +02:00
Werner Koch
85a07ca7e3 w32: Fix memleak in an error code paths.
* src/w32-io.c (create_writer): Free CTX in cased of bad FD.
* src/w32-util.c (_gpgme_mkstemp): Free TMPNAME in case of a failed
mkstemp.
--

Found by Hans-Christoph Steiner with cppcheck.
2014-04-15 22:18:04 +02:00
Werner Koch
443f6b76a9 Make use of internal iospawn flags more flexible.
* src/priv-io.h (IOSPAWN_FLAG_DETACHED): New. Renumber the others.
* src/w32-io.c (_gpgme_io_spawn): Use DETACHED_PROCESS process only if
IOSPAWN_FLAG_DETACHED is given.
* src/w32-qt-io.cpp (_gpgme_io_spawn): Ditto.
* src/w32-glib-io.c (_gpgme_io_spawn): Ditto.
* src/assuan-support.c (my_spawn): Pass IOSPAWN_FLAG_DETACHED flags.
* src/dirinfo.c (read_gpgconf_dirs): Ditto.
* src/engine-gpg.c (start): Ditto.
* src/engine-gpgconf.c (gpgconf_read, gpgconf_write): Ditto.
* src/version.c (_gpgme_get_program_version): Ditto.
2014-04-10 11:39:14 +02:00
Werner Koch
9e7df9aa6d w32: Change the way the I/O threads are cleaned up.
* src/w32-io.c (reader_context_s, create_reader)
(writer_context_s, create_writer): Rename STOPPED to CLOSE_EV.
(reader, writer): Remove setting of STOPPED.  Wait for CLOSE_EV and
then release the context.
(destroy_reader, destroy_writer): Do not wait but set the CLOSE_EV.
(kill_reader, kill_writer): Remove.
(_gpgme_io_close): Add code from kill_reader and kill_writer.
--

The old code was prone to deadlocks which were actually exhibited at
Kleopatra startup.  The new code is much more straightforward and
easier to understand.  The reason for the complex old code was
probably due to our former idea to allow re-use of the I/O threads.
However we have long given up on this.
2013-05-11 15:38:08 +02:00
Werner Koch
9f330be821 Fix hang in socket closing.
* src/w32-io.c (destroy_reader): Call shutdown.
(reader): Do not print an error in the shutdown case.
2013-05-08 20:38:50 +02:00
Werner Koch
2118f49701 Improve debug output of the I/O reader and writer.
* src/w32-io.c (reader, writer): Also print file_sock.
2013-05-08 19:10:41 +02:00
Werner Koch
139e798c87 Remove all trailing whitespace from source files
--
Command used:  sed -i 's,[ \t]*$,,' FILE
2012-09-25 15:29:49 +02:00
Marcus Brinkmann
2bdbe88822 Fix socket implementation on Windows.
2011-02-03  Marcus Brinkmann  <marcus@g10code.com>

        * w32-io.c (_gpgme_io_socket): Return fd, not res.
2011-02-03 12:38:28 +01:00
Marcus Brinkmann
129741d2f7 Fix Windows port (spawn and assuan engine).
2011-02-02  Marcus Brinkmann  <mb@g10code.com>

        * configure.ac (NEED_LIBASSUAN_VERSION): Bump to 2.0.2 for system hooks.

src/
2011-02-02  Marcus Brinkmann  <mb@g10code.com>

        * assuan-support.c (my_socket, my_connect): New functions.
        (_gpgme_assuan_system_hooks): Add my_Socket, my_connect.
        * priv-io.h (_gpgme_io_socket): New prototype.
        * w32-io.c (pid_to_handle, handle_to_oid, fd_to_handle): Remove macros.
        (is_socket): Remove function.
        (_gpgme_io_spawn) [HAVE_W32CE_SYSTEM]: Remove some dead code.
        (_gpgme_io_spawn): Translate handles before DuplicateHandle them.
2011-02-02 14:11:18 +01:00
Marcus Brinkmann
e59b0a98ba 2010-11-23 Marcus Brinkmann <mb@g10code.com>
* w32-io.c (create_reader, create_writer): Use small stack size on
        Windows CE.
2010-11-23 10:47:59 +00:00
Werner Koch
21eb91ae3a More include guards.
Provide access for Wince.
Install dummy sehmap.h
2010-11-03 09:56:27 +00:00
Werner Koch
987993a38d First take on changes to allow building with MSC for W32CE.
Fixed regression in plain W32 build.
2010-11-02 16:27:46 +00:00
Marcus Brinkmann
03c7412e47 2010-09-01 Marcus Brinkmann <marcus@g10code.de>
* w32-io.c: Revert change from 2009-06-18, as it created a race
        condition.
2010-09-01 00:46:19 +00:00
Marcus Brinkmann
bfd550e0d9 Are you ready already? 2010-08-04 07:47:05 +00:00
Marcus Brinkmann
6e5c9be0b6 2010-08-03 Marcus Brinkmann <marcus@g10code.de>
* w32-io.c (GPGCEDEV_IOCTL_ASSIGN_RVID): New macro.
        (_gpgme_io_spawn): Use ASSIGN_RVID.
2010-08-03 09:01:24 +00:00
Marcus Brinkmann
6181854e4d 2010-06-11 Marcus Brinkmann <marcus@g10code.de>
* w32-io.c (_gpgme_io_spawn): Remove debug printf.
2010-06-10 23:29:06 +00:00
Marcus Brinkmann
dbb1112da1 2010-06-10 Marcus Brinkmann <marcus@g10code.de>
* debug.h (TRACE_SUC6): New macro.
	* w32-io.c (MAX_SLAFD): New macro.
	(fd_table): New static variable.
	(new_fd, release_fd): New functions.
	(fd_to_handle, handle_to_fd, handle_to_socket): Remove macros.
	(MAX_READERS, MAX_WRITERS): Increase to 64.
	(notify_table): Increase to MAX_SLAFD.
	(struct reader_context_s, struct writer_context_s): Add member
	file_sock.
	(reader, writer): Use file_hd vs file_sock to decide if socket
	operations to use.  Remove auto-detect mode.
	(create_reader, create_writer): Set file_sock.  Unblock pending
	thread only if this is a pipe fd.
	(_gpgme_io_pipe): Allocate fds from table and return slot indices
	instead of windows handles.  This allows to properly handle RVIDs.
	(_gpgme_io_close): Handle dup'ed file descriptors.
	(build_commandline) [HAVE_W32_SYSTEM]: Use RVID from fd table now.
	(_gpgme_io_spawn): Use fd table now.
	(_gpgme_io_fd2str): Use RVID from fd table now.
	(_gpgme_io_dup): Implement using fd table.
	(_gpgme_io_socket): Allocate fds from table.
	(_gpgme_io_connect): Use fd from table.
2010-06-10 13:49:19 +00:00
Marcus Brinkmann
9386a5e760 2010-06-09 Marcus Brinkmann <marcus@g10code.de>
* w32-io.c [HAVE_W32CE_SYSTEM]: Include assuan.h and winioctl.h.
	(GPGCEDEV_IOCTL_UNBLOCK) [HAVE_W32CE_SYSTEM]: Define.
	(set_synchronize) [HAVE_W32CE_SYSTEM]: Stub it out.
	(is_socket): Allow to return -1 for auto-detect (old behaviour).
	(is_socket) [HAVE_W32CE_SYSTEM]: Return -1.
	(reader): Handle auto-detect case.  Handle ctx->stop_me before
	checking for EOF.
	(destroy_reader) [HAVE_W32CE_SYSTEM]: Unblock a pending reader.
	(writer): Handle auto-detect case.  Handle ctx->stop_me with
	ERROR_BUSY.
	(destroy_writer) [HAVE_W32CE_SYSTEM]: Unblock a pending writer.
	(_gpgme_io_pipe) [HAVE_W32CE_SYSTEM]: Implement in terms of a
	half-pipe.
	(build_commandline) [HAVE_W32CE_SYSTEM]: New function.
	(_gpgme_io_spawn) [HAVE_W32CE_SYSTEM]: Implement it differently
	for this platform.
	(_gpgme_io_fd2str) [HAVE_W32CE_SYSTEM]: Implement it for RVIDs.
	(_gpgme_io_dup) [HAVE_W32CE_SYSTEM]: Stub it out.
2010-06-09 13:33:31 +00:00
Marcus Brinkmann
9121a17238 2010-05-06 Marcus Brinkmann <marcus@g10code.de>
* w32-glib-io.c, w32-io.c, w32-qt-io.cpp, w32-sema.c, w32-util.c:
	Do not include <signal.h>.
2010-05-06 15:16:57 +00:00
Marcus Brinkmann
749325d6c1 2010-05-06 Marcus Brinkmann <marcus@g10code.de>
* configure.ac: Require libgpg-error 1.8.

src/
2010-05-06  Marcus Brinkmann  <marcus@g10code.de>

	* sign.c, data-user.c, conversion.c, debug.c, verify.c, data.c,
	decrypt.c, delete.c, assuan-support.c, import.c, engine-gpgsm.c,
	data-mem.c, op-support.c, w32-io.c, w32-util.c, data-compat.c: Use
	gpg_error_from_syserror instead gpg_error_from_errno, and use
	gpg_err_set_errno to set error number.
	* setenv.c: Include <gpg-error.h> and define __set_errno to use
	gpg_err_set_errno.
	* gpgme-tool.c (ARGP_ERR_UNKNOWN): Define to EDEADLOCK (which is
	mapped in Windows CE) instead of E2BIG (which is not).
	(gt_import_keys): Initialize err.
2010-05-06 13:39:55 +00:00
Werner Koch
779823c09c More robust detection of handle and sockets 2010-04-16 14:08:41 +00:00
Werner Koch
dbcce0df8f Allow the native W32 version to properly work with sockets. 2010-01-25 16:04:27 +00:00
Marcus Brinkmann
96cf17b159 2009-11-10 Marcus Brinkmann <marcus@g10code.de>
* configure.ac: Activate UIServer if FD passing is enabled and
	Assuan is available.

m4/
2009-11-10  Marcus Brinkmann  <marcus@g10code.de>

	* libassuan.m4: Fix LIBASSUAN_VERSION.

src/
2009-11-10  Marcus Brinkmann  <marcus@g10code.de>

	* Makefile.am (uiserver_components): New variable.
	(main_sources): Add it.
	* ops.h, key.c (_gpgme_key_append_name): Take CONVERT argument,
	implement it.  Adjust callers.
	(gpgme_key_from_uid): New function.
	* gpgme.h.in (gpgme_protocol_t): Add GPGME_PROTOCOL_DEFAULT.
	(gpgme_encrypt_flags_t): Add GPGME_ENCRYPT_PREPARE,
	GPGME_ENCRYPT_EXPECT_SIGN.
	(gpgme_set_sub_protocol, gpgme_key_from_uid): New functions.
	* libgpgme.vers, gpgme.def: Add new functions.
	* gpgme.c (gpgme_set_protocol): Add UIServer protocol.
	(gpgme_set_sub_protocol): New function.
	(gpgme_get_protocol_name): Add UIServer and default protocol.
	* assuan-support.c: Return correct error values, implement
	socketpair for POSIX.
	* priv-io.h, posix-io.c, w32-io.c, w32-glib-io.c,
	w32-qt-io.cpp (_gpgme_io_spawn): Add ATFORK and ATFORKVALUE
	arguments.  Implement it for POSIX.  Adjust all callers.
	* engine.h, engine-backend.h (_gpgme_engine_set_protocol)
	(_gpgme_engine_op_decrypt_verify): New prototypes.  Adjust all
	users.
	* engine.c (engine_ops, gpgme_get_engine_info): Add UIServer
	engine.
	(_gpgme_engine_set_protocol, _gpgme_engine_op_decrypt_verify): New
	function.
	* decrypt-verify.c (decrypt_verify_start): Call
	_gpgme_engine_op_decrypt_verify.
	* util.h, posix-util.c,
	w32-util.c (_gpgme_get_uiserver_socket_path): New function.
	* engine-gpgsm.c (gpgsm_set_fd): Fix _gpgme_io_pipe invocation.
	* gpgme-tool.c: Some support for UIServer protocol.
	* engine-uiserver.c: New file.
2009-11-10 09:07:19 +00:00
Marcus Brinkmann
59dc98545a 2009-11-05 Marcus Brinkmann <marcus@g10code.de>
* priv-io.h (IOSPAWN_FLAG_NOCLOSE): New flag.
	* w32-io.c (_gpgme_io_spawn): Implement this flag.
	* posix-io.c (_gpgme_io_spawn): Likewise.
	* w32-glib-io.c (_gpgme_io_spawn): Likewise.
	* assuan-support.c (my_spawn): Set this flag.
2009-11-05 02:39:31 +00:00
Marcus Brinkmann
e6ff9579ba 2009-06-18 Marcus Brinkmann <marcus@g10code.de>
* gpgme.def: Fix stupid typo.
	* w32-io.c (_gpgme_io_pipe): Add missing declaration.
2009-06-18 16:51:56 +00:00