2018-11-16 12:27:33 +00:00
|
|
|
|
/* assuan-support.c - Assuan wrappers
|
|
|
|
|
* Copyright (C) 2009 g10 Code GmbH
|
|
|
|
|
*
|
|
|
|
|
* This file is part of GPGME.
|
|
|
|
|
*
|
|
|
|
|
* GPGME is free software; you can redistribute it and/or modify it
|
|
|
|
|
* under the terms of the GNU Lesser General Public License as
|
|
|
|
|
* published by the Free Software Foundation; either version 2.1 of
|
|
|
|
|
* the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* GPGME is distributed in the hope that it will be useful, but
|
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
* License along with this program; if not, see <https://gnu.org/licenses/>.
|
|
|
|
|
* SPDX-License-Identifier: LGPL-2.1-or-later
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
2009-10-20 16:05:21 +00:00
|
|
|
|
#if HAVE_CONFIG_H
|
|
|
|
|
#include <config.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
#include <stdlib.h>
|
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
|
|
|
|
#include <errno.h>
|
2009-10-20 16:05:21 +00:00
|
|
|
|
|
2022-04-05 05:17:21 +00:00
|
|
|
|
#ifdef HAVE_SYS_TYPES_H
|
|
|
|
|
# include <sys/types.h>
|
|
|
|
|
#endif
|
2022-04-05 05:42:59 +00:00
|
|
|
|
#ifdef HAVE_SYS_TIME_H
|
|
|
|
|
# include <sys/time.h>
|
|
|
|
|
#endif
|
2022-04-05 05:17:21 +00:00
|
|
|
|
#ifndef HAVE_W32_SYSTEM
|
2022-04-05 05:42:59 +00:00
|
|
|
|
#include <unistd.h>
|
2022-04-05 05:17:21 +00:00
|
|
|
|
#include <sys/wait.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2009-10-20 16:05:21 +00:00
|
|
|
|
#include "assuan.h"
|
|
|
|
|
|
|
|
|
|
#include "gpgme.h"
|
|
|
|
|
#include "priv-io.h"
|
|
|
|
|
#include "debug.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct assuan_malloc_hooks _gpgme_assuan_malloc_hooks =
|
|
|
|
|
{
|
|
|
|
|
malloc,
|
|
|
|
|
realloc,
|
|
|
|
|
free
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
_gpgme_assuan_log_cb (assuan_context_t ctx, void *hook,
|
|
|
|
|
unsigned int cat, const char *msg)
|
|
|
|
|
{
|
2016-09-13 18:53:14 +00:00
|
|
|
|
(void)ctx;
|
|
|
|
|
(void)hook;
|
|
|
|
|
(void)cat;
|
|
|
|
|
|
2009-10-20 16:05:21 +00:00
|
|
|
|
if (msg == NULL)
|
|
|
|
|
return 1;
|
|
|
|
|
|
2019-06-05 13:48:33 +00:00
|
|
|
|
_gpgme_debug (NULL, DEBUG_ASSUAN, -1, NULL, NULL, NULL, "%s", msg);
|
2009-10-20 16:05:21 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
my_usleep (assuan_context_t ctx, unsigned int usec)
|
|
|
|
|
{
|
2022-04-05 05:42:59 +00:00
|
|
|
|
(void)ctx;
|
|
|
|
|
|
|
|
|
|
if (!usec)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_W32_SYSTEM
|
|
|
|
|
Sleep (usec / 1000);
|
|
|
|
|
#else
|
|
|
|
|
# ifdef HAVE_NANOSLEEP
|
|
|
|
|
{
|
|
|
|
|
struct timespec req;
|
|
|
|
|
struct timespec rem;
|
|
|
|
|
|
|
|
|
|
req.tv_sec = usec / 1000000;
|
|
|
|
|
req.tv_nsec = (usec % 1000000) * 1000;
|
|
|
|
|
while (nanosleep (&req, &rem) < 0 && errno == EINTR)
|
|
|
|
|
req = rem;
|
|
|
|
|
}
|
|
|
|
|
# else
|
|
|
|
|
usleep (usec);
|
|
|
|
|
# endif
|
|
|
|
|
#endif
|
2009-10-20 16:05:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-05-07 01:06:14 +00:00
|
|
|
|
|
2009-10-20 16:05:21 +00:00
|
|
|
|
/* Create a pipe with an inheritable end. */
|
|
|
|
|
static int
|
|
|
|
|
my_pipe (assuan_context_t ctx, assuan_fd_t fds[2], int inherit_idx)
|
|
|
|
|
{
|
2010-05-07 01:06:14 +00:00
|
|
|
|
int res;
|
|
|
|
|
int gfds[2];
|
|
|
|
|
|
2016-09-13 18:53:14 +00:00
|
|
|
|
(void)ctx;
|
|
|
|
|
|
2010-05-07 01:06:14 +00:00
|
|
|
|
res = _gpgme_io_pipe (gfds, inherit_idx);
|
|
|
|
|
|
|
|
|
|
/* For now... */
|
|
|
|
|
fds[0] = (assuan_fd_t) gfds[0];
|
|
|
|
|
fds[1] = (assuan_fd_t) gfds[1];
|
|
|
|
|
|
|
|
|
|
return res;
|
2009-10-20 16:05:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Close the given file descriptor, created with _assuan_pipe or one
|
|
|
|
|
of the socket functions. */
|
|
|
|
|
static int
|
|
|
|
|
my_close (assuan_context_t ctx, assuan_fd_t fd)
|
|
|
|
|
{
|
2016-09-13 18:53:14 +00:00
|
|
|
|
(void)ctx;
|
2010-05-07 01:06:14 +00:00
|
|
|
|
return _gpgme_io_close ((int) fd);
|
2009-10-20 16:05:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
Make definition of off_t robust against misbehaving w32 toolchains.
* configure.ac (NEED__FILE_OFFSET_BITS): Change to define gpgme_off_t
and gpgme_ssize_t.
(API__OFF_T, API__SSIZE_T): New ac_subst.
* src/gpgme.h.in: Replace all ssize_t and off_t by ac_subst macros.
* src/assuan-support.c, src/ath-pthread.c, src/ath.c, src/ath.h
* src/data-compat.c, src/data-fd.c, src/data-mem.c, src/data-stream.c
* src/data-user.c, src/data.c, src/data.h, src/engine-gpgsm.c
* src/engine-uiserver.c, src/gpgme-tool.c, src/gpgme.c: Replace off_t
by gpgme_off_t and sszie_t by gpgme_ssize_t.
* src/ath-pthread.c, src/ath.h: Include gpgme.h.
--
For a detailed description, see the gpgme.texi diff.
2013-04-25 11:00:16 +00:00
|
|
|
|
static gpgme_ssize_t
|
2009-10-20 16:05:21 +00:00
|
|
|
|
my_read (assuan_context_t ctx, assuan_fd_t fd, void *buffer, size_t size)
|
|
|
|
|
{
|
2016-09-13 18:53:14 +00:00
|
|
|
|
(void)ctx;
|
2010-05-07 01:06:14 +00:00
|
|
|
|
return _gpgme_io_read ((int) fd, buffer, size);
|
2009-10-20 16:05:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
Make definition of off_t robust against misbehaving w32 toolchains.
* configure.ac (NEED__FILE_OFFSET_BITS): Change to define gpgme_off_t
and gpgme_ssize_t.
(API__OFF_T, API__SSIZE_T): New ac_subst.
* src/gpgme.h.in: Replace all ssize_t and off_t by ac_subst macros.
* src/assuan-support.c, src/ath-pthread.c, src/ath.c, src/ath.h
* src/data-compat.c, src/data-fd.c, src/data-mem.c, src/data-stream.c
* src/data-user.c, src/data.c, src/data.h, src/engine-gpgsm.c
* src/engine-uiserver.c, src/gpgme-tool.c, src/gpgme.c: Replace off_t
by gpgme_off_t and sszie_t by gpgme_ssize_t.
* src/ath-pthread.c, src/ath.h: Include gpgme.h.
--
For a detailed description, see the gpgme.texi diff.
2013-04-25 11:00:16 +00:00
|
|
|
|
static gpgme_ssize_t
|
2009-10-20 16:05:21 +00:00
|
|
|
|
my_write (assuan_context_t ctx, assuan_fd_t fd, const void *buffer, size_t size)
|
|
|
|
|
{
|
2016-09-13 18:53:14 +00:00
|
|
|
|
(void)ctx;
|
2010-05-07 01:06:14 +00:00
|
|
|
|
return _gpgme_io_write ((int) fd, buffer, size);
|
2009-10-20 16:05:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
my_recvmsg (assuan_context_t ctx, assuan_fd_t fd, assuan_msghdr_t msg,
|
|
|
|
|
int flags)
|
|
|
|
|
{
|
2016-09-13 18:53:14 +00:00
|
|
|
|
(void)ctx;
|
2009-10-20 16:05:21 +00:00
|
|
|
|
#ifdef HAVE_W32_SYSTEM
|
2016-09-22 10:58:23 +00:00
|
|
|
|
(void)fd;
|
|
|
|
|
(void)msg;
|
|
|
|
|
(void)flags;
|
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
|
|
|
|
gpg_err_set_errno (ENOSYS);
|
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
|
|
|
|
return -1;
|
2009-10-20 16:05:21 +00:00
|
|
|
|
#else
|
2010-05-07 01:06:14 +00:00
|
|
|
|
return _gpgme_io_recvmsg ((int) fd, msg, flags);
|
2009-10-20 16:05:21 +00:00
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
my_sendmsg (assuan_context_t ctx, assuan_fd_t fd, const assuan_msghdr_t msg,
|
|
|
|
|
int flags)
|
|
|
|
|
{
|
2016-09-13 18:53:14 +00:00
|
|
|
|
(void)ctx;
|
2009-10-20 16:05:21 +00:00
|
|
|
|
#ifdef HAVE_W32_SYSTEM
|
2016-09-22 10:58:23 +00:00
|
|
|
|
(void)fd;
|
|
|
|
|
(void)msg;
|
|
|
|
|
(void)flags;
|
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
|
|
|
|
gpg_err_set_errno (ENOSYS);
|
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
|
|
|
|
return -1;
|
2009-10-20 16:05:21 +00:00
|
|
|
|
#else
|
2010-05-07 01:06:14 +00:00
|
|
|
|
return _gpgme_io_sendmsg ((int) fd, msg, flags);
|
2009-10-20 16:05:21 +00:00
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* If NAME is NULL, don't exec, just fork. FD_CHILD_LIST is modified
|
|
|
|
|
to reflect the value of the FD in the peer process (on
|
|
|
|
|
Windows). */
|
|
|
|
|
static int
|
|
|
|
|
my_spawn (assuan_context_t ctx, pid_t *r_pid, const char *name,
|
|
|
|
|
const char **argv,
|
|
|
|
|
assuan_fd_t fd_in, assuan_fd_t fd_out,
|
|
|
|
|
assuan_fd_t *fd_child_list,
|
|
|
|
|
void (*atfork) (void *opaque, int reserved),
|
|
|
|
|
void *atforkvalue, unsigned int flags)
|
|
|
|
|
{
|
2019-03-25 13:56:37 +00:00
|
|
|
|
int err = 0;
|
2009-10-20 16:05:21 +00:00
|
|
|
|
struct spawn_fd_item_s *fd_items;
|
|
|
|
|
int i;
|
|
|
|
|
|
2016-09-13 18:53:14 +00:00
|
|
|
|
(void)ctx;
|
|
|
|
|
(void)flags;
|
|
|
|
|
|
2009-10-20 16:05:21 +00:00
|
|
|
|
assert (name);
|
|
|
|
|
|
|
|
|
|
if (! name)
|
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
|
|
|
|
{
|
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
|
|
|
|
gpg_err_set_errno (ENOSYS);
|
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
|
|
|
|
return -1;
|
|
|
|
|
}
|
2009-10-20 16:05:21 +00:00
|
|
|
|
|
|
|
|
|
i = 0;
|
2009-10-30 14:21:08 +00:00
|
|
|
|
if (fd_child_list)
|
|
|
|
|
{
|
|
|
|
|
while (fd_child_list[i] != ASSUAN_INVALID_FD)
|
|
|
|
|
i++;
|
|
|
|
|
}
|
2009-10-20 16:05:21 +00:00
|
|
|
|
/* fd_in, fd_out, terminator */
|
|
|
|
|
i += 3;
|
2009-12-15 01:01:40 +00:00
|
|
|
|
fd_items = calloc (i, sizeof (struct spawn_fd_item_s));
|
2009-10-20 16:05:21 +00:00
|
|
|
|
if (! fd_items)
|
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
|
|
|
|
return -1;
|
2009-10-20 16:05:21 +00:00
|
|
|
|
i = 0;
|
2009-10-30 14:21:08 +00:00
|
|
|
|
if (fd_child_list)
|
2009-10-20 16:05:21 +00:00
|
|
|
|
{
|
2009-10-30 14:21:08 +00:00
|
|
|
|
while (fd_child_list[i] != ASSUAN_INVALID_FD)
|
|
|
|
|
{
|
2010-05-07 01:06:14 +00:00
|
|
|
|
fd_items[i].fd = (int) fd_child_list[i];
|
2009-10-30 14:21:08 +00:00
|
|
|
|
fd_items[i].dup_to = -1;
|
|
|
|
|
i++;
|
|
|
|
|
}
|
2009-10-20 16:05:21 +00:00
|
|
|
|
}
|
|
|
|
|
if (fd_in != ASSUAN_INVALID_FD)
|
|
|
|
|
{
|
2010-05-07 01:06:14 +00:00
|
|
|
|
fd_items[i].fd = (int) fd_in;
|
2009-10-20 16:05:21 +00:00
|
|
|
|
fd_items[i].dup_to = 0;
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
if (fd_out != ASSUAN_INVALID_FD)
|
|
|
|
|
{
|
2010-05-07 01:06:14 +00:00
|
|
|
|
fd_items[i].fd = (int) fd_out;
|
2009-10-20 16:05:21 +00:00
|
|
|
|
fd_items[i].dup_to = 1;
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
fd_items[i].fd = -1;
|
|
|
|
|
fd_items[i].dup_to = -1;
|
|
|
|
|
|
2019-03-25 13:56:37 +00:00
|
|
|
|
#ifdef HAVE_W32_SYSTEM
|
|
|
|
|
/* Fix up a potential logger fd so that on windows the fd
|
|
|
|
|
* translation can work through gpgme-w32spawn.
|
|
|
|
|
*
|
|
|
|
|
* We do this here as a hack because we would
|
|
|
|
|
* otherwise have to change assuan_api and the current
|
|
|
|
|
* plan in 2019 is to change away from this to gpgrt
|
|
|
|
|
* based IPC. */
|
|
|
|
|
if (argv)
|
|
|
|
|
{
|
|
|
|
|
int loc = 0;
|
|
|
|
|
while (argv[loc])
|
|
|
|
|
{
|
|
|
|
|
if (!strcmp ("--logger-fd", argv[loc]))
|
|
|
|
|
{
|
|
|
|
|
long logger_fd = -1;
|
|
|
|
|
char *tail;
|
|
|
|
|
int k = 0;
|
|
|
|
|
loc++;
|
|
|
|
|
if (!argv[loc])
|
|
|
|
|
{
|
|
|
|
|
err = GPG_ERR_INV_ARG;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2019-03-26 15:35:13 +00:00
|
|
|
|
logger_fd = strtol (argv[loc], &tail, 10);
|
2019-03-27 15:12:38 +00:00
|
|
|
|
if (tail == argv[loc] || logger_fd < 0)
|
2019-03-25 13:56:37 +00:00
|
|
|
|
{
|
|
|
|
|
err = GPG_ERR_INV_ARG;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
while (fd_items[k++].fd != -1)
|
|
|
|
|
{
|
|
|
|
|
if (fd_items[k].fd == logger_fd)
|
|
|
|
|
{
|
|
|
|
|
fd_items[k].arg_loc = loc;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
loc++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
if (!err)
|
|
|
|
|
{
|
|
|
|
|
err = _gpgme_io_spawn (name, (char*const*)argv,
|
|
|
|
|
(IOSPAWN_FLAG_NOCLOSE | IOSPAWN_FLAG_DETACHED),
|
|
|
|
|
fd_items, atfork, atforkvalue, r_pid);
|
|
|
|
|
}
|
|
|
|
|
if (!err)
|
2009-10-20 16:05:21 +00:00
|
|
|
|
{
|
|
|
|
|
i = 0;
|
|
|
|
|
|
2009-10-30 14:21:08 +00:00
|
|
|
|
if (fd_child_list)
|
2009-10-20 16:05:21 +00:00
|
|
|
|
{
|
2009-10-30 14:21:08 +00:00
|
|
|
|
while (fd_child_list[i] != ASSUAN_INVALID_FD)
|
|
|
|
|
{
|
2010-05-07 01:06:14 +00:00
|
|
|
|
fd_child_list[i] = (assuan_fd_t) fd_items[i].peer_name;
|
2009-10-30 14:21:08 +00:00
|
|
|
|
i++;
|
|
|
|
|
}
|
2009-10-20 16:05:21 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
free (fd_items);
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* If action is 0, like waitpid. If action is 1, just release the PID? */
|
|
|
|
|
static pid_t
|
|
|
|
|
my_waitpid (assuan_context_t ctx, pid_t pid,
|
|
|
|
|
int nowait, int *status, int options)
|
|
|
|
|
{
|
2016-09-13 18:53:14 +00:00
|
|
|
|
(void)ctx;
|
2009-10-20 16:05:21 +00:00
|
|
|
|
#ifdef HAVE_W32_SYSTEM
|
2016-09-22 10:58:23 +00:00
|
|
|
|
(void)nowait;
|
|
|
|
|
(void)status;
|
|
|
|
|
(void)options;
|
2018-11-02 10:26:19 +00:00
|
|
|
|
(void)pid; /* Just a number without a kernel object. */
|
2009-10-20 16:05:21 +00:00
|
|
|
|
#else
|
|
|
|
|
/* We can't just release the PID, a waitpid is mandatory. But
|
|
|
|
|
NOWAIT in POSIX systems just means the caller already did the
|
|
|
|
|
waitpid for this child. */
|
|
|
|
|
if (! nowait)
|
2022-04-05 05:17:21 +00:00
|
|
|
|
return waitpid (pid, status, options);
|
2009-10-20 16:05:21 +00:00
|
|
|
|
#endif
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
my_socketpair (assuan_context_t ctx, int namespace, int style,
|
|
|
|
|
int protocol, assuan_fd_t filedes[2])
|
|
|
|
|
{
|
2016-09-22 10:58:23 +00:00
|
|
|
|
(void)ctx;
|
2022-04-05 05:42:59 +00:00
|
|
|
|
#ifdef HAVE_W32_SYSTEM
|
2016-09-22 10:58:23 +00:00
|
|
|
|
(void)namespace;
|
|
|
|
|
(void)style;
|
|
|
|
|
(void)protocol;
|
|
|
|
|
(void)filedes;
|
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
|
|
|
|
gpg_err_set_errno (ENOSYS);
|
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
|
|
|
|
return -1;
|
|
|
|
|
#else
|
|
|
|
|
/* FIXME: Debug output missing. */
|
2022-04-05 05:42:59 +00:00
|
|
|
|
return socketpair (namespace, style, protocol, filedes);
|
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
|
|
|
|
#endif
|
2009-10-20 16:05:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2011-02-02 13:07:05 +00:00
|
|
|
|
static int
|
|
|
|
|
my_socket (assuan_context_t ctx, int namespace, int style, int protocol)
|
|
|
|
|
{
|
2016-09-13 18:53:14 +00:00
|
|
|
|
(void)ctx;
|
2011-02-02 13:07:05 +00:00
|
|
|
|
return _gpgme_io_socket (namespace, style, protocol);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
my_connect (assuan_context_t ctx, int sock, struct sockaddr *addr,
|
|
|
|
|
socklen_t length)
|
|
|
|
|
{
|
2016-09-13 18:53:14 +00:00
|
|
|
|
(void)ctx;
|
2011-02-02 13:07:05 +00:00
|
|
|
|
return _gpgme_io_connect (sock, addr, length);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2014-06-25 18:25:28 +00:00
|
|
|
|
/* Note for Windows: Ignore the incompatible pointer type warning for
|
|
|
|
|
my_read and my_write. Mingw has been changed to use int for
|
|
|
|
|
ssize_t on 32 bit systems while we use long. For 64 bit we use
|
|
|
|
|
int64_t while mingw uses __int64_t. It doe not matter at all
|
|
|
|
|
because under Windows long and int are both 32 bit even on 64
|
|
|
|
|
bit. */
|
2009-10-20 16:05:21 +00:00
|
|
|
|
struct assuan_system_hooks _gpgme_assuan_system_hooks =
|
|
|
|
|
{
|
|
|
|
|
ASSUAN_SYSTEM_HOOKS_VERSION,
|
|
|
|
|
my_usleep,
|
|
|
|
|
my_pipe,
|
|
|
|
|
my_close,
|
|
|
|
|
my_read,
|
|
|
|
|
my_write,
|
|
|
|
|
my_recvmsg,
|
|
|
|
|
my_sendmsg,
|
|
|
|
|
my_spawn,
|
|
|
|
|
my_waitpid,
|
2011-02-02 13:07:05 +00:00
|
|
|
|
my_socketpair,
|
|
|
|
|
my_socket,
|
|
|
|
|
my_connect
|
2009-10-20 16:05:21 +00:00
|
|
|
|
};
|