2009-09-30 15:28:38 +00:00
|
|
|
|
/* call-gpg.c - Communication with the GPG
|
|
|
|
|
* Copyright (C) 2009 Free Software Foundation, Inc.
|
|
|
|
|
*
|
|
|
|
|
* This file is part of GnuPG.
|
|
|
|
|
*
|
|
|
|
|
* GnuPG is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* GnuPG 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 General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
2015-11-24 13:40:56 +01:00
|
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
#include <assuan.h>
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
#include <npth.h>
|
2009-09-30 15:28:38 +00:00
|
|
|
|
#include <stdlib.h>
|
2015-11-24 13:40:56 +01:00
|
|
|
|
#include <stdio.h>
|
2009-09-30 15:28:38 +00:00
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
|
|
#include "call-gpg.h"
|
2015-11-24 13:40:56 +01:00
|
|
|
|
#include "exechelp.h"
|
|
|
|
|
#include "i18n.h"
|
|
|
|
|
#include "logging.h"
|
|
|
|
|
#include "membuf.h"
|
2015-11-26 15:01:40 +01:00
|
|
|
|
#include "strlist.h"
|
2015-11-24 13:40:56 +01:00
|
|
|
|
#include "util.h"
|
2009-09-30 15:28:38 +00:00
|
|
|
|
|
2015-12-14 19:55:34 +01:00
|
|
|
|
|
|
|
|
|
static GPGRT_INLINE gpg_error_t
|
|
|
|
|
my_error_from_syserror (void)
|
|
|
|
|
{
|
|
|
|
|
return gpg_err_make (default_errsource, gpg_err_code_from_syserror ());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static GPGRT_INLINE gpg_error_t
|
|
|
|
|
my_error_from_errno (int e)
|
|
|
|
|
{
|
|
|
|
|
return gpg_err_make (default_errsource, gpg_err_code_from_errno (e));
|
|
|
|
|
}
|
|
|
|
|
|
2009-09-30 15:28:38 +00:00
|
|
|
|
|
|
|
|
|
/* Fire up a new GPG. Handle the server's initial greeting. Returns
|
|
|
|
|
0 on success and stores the assuan context at R_CTX. */
|
|
|
|
|
static gpg_error_t
|
2015-11-26 15:01:40 +01:00
|
|
|
|
start_gpg (ctrl_t ctrl, const char *gpg_program, strlist_t gpg_arguments,
|
2015-11-24 13:40:56 +01:00
|
|
|
|
int input_fd, int output_fd, assuan_context_t *r_ctx)
|
2009-09-30 15:28:38 +00:00
|
|
|
|
{
|
|
|
|
|
gpg_error_t err;
|
|
|
|
|
assuan_context_t ctx = NULL;
|
|
|
|
|
const char *pgmname;
|
2015-11-26 15:01:40 +01:00
|
|
|
|
const char **argv;
|
2015-11-27 17:58:51 +01:00
|
|
|
|
assuan_fd_t no_close_list[5];
|
2009-09-30 15:28:38 +00:00
|
|
|
|
int i;
|
|
|
|
|
char line[ASSUAN_LINELENGTH];
|
|
|
|
|
|
|
|
|
|
(void)ctrl;
|
|
|
|
|
|
|
|
|
|
*r_ctx = NULL;
|
|
|
|
|
|
|
|
|
|
err = assuan_new (&ctx);
|
|
|
|
|
if (err)
|
|
|
|
|
{
|
|
|
|
|
log_error ("can't allocate assuan context: %s\n", gpg_strerror (err));
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* The first time we are used, intialize the gpg_program variable. */
|
2015-11-24 13:40:56 +01:00
|
|
|
|
if ( !gpg_program || !*gpg_program )
|
|
|
|
|
gpg_program = gnupg_module_name (GNUPG_MODULE_NAME_GPG);
|
2011-02-04 12:57:53 +01:00
|
|
|
|
|
2009-09-30 15:28:38 +00:00
|
|
|
|
/* Compute argv[0]. */
|
2015-11-24 13:40:56 +01:00
|
|
|
|
if ( !(pgmname = strrchr (gpg_program, '/')))
|
|
|
|
|
pgmname = gpg_program;
|
2009-09-30 15:28:38 +00:00
|
|
|
|
else
|
|
|
|
|
pgmname++;
|
|
|
|
|
|
|
|
|
|
if (fflush (NULL))
|
|
|
|
|
{
|
2015-12-14 19:55:34 +01:00
|
|
|
|
err = my_error_from_syserror ();
|
2009-09-30 15:28:38 +00:00
|
|
|
|
log_error ("error flushing pending output: %s\n", gpg_strerror (err));
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-26 15:01:40 +01:00
|
|
|
|
argv = xtrycalloc (strlist_length (gpg_arguments) + 3, sizeof *argv);
|
|
|
|
|
if (argv == NULL)
|
|
|
|
|
{
|
2015-12-14 19:55:34 +01:00
|
|
|
|
err = my_error_from_syserror ();
|
2015-11-26 15:01:40 +01:00
|
|
|
|
return err;
|
|
|
|
|
}
|
2009-09-30 15:28:38 +00:00
|
|
|
|
i = 0;
|
|
|
|
|
argv[i++] = pgmname;
|
|
|
|
|
argv[i++] = "--server";
|
2015-11-26 15:01:40 +01:00
|
|
|
|
for (; gpg_arguments; gpg_arguments = gpg_arguments->next)
|
|
|
|
|
argv[i++] = gpg_arguments->d;
|
2009-09-30 15:28:38 +00:00
|
|
|
|
argv[i++] = NULL;
|
2011-02-04 12:57:53 +01:00
|
|
|
|
|
2009-09-30 15:28:38 +00:00
|
|
|
|
i = 0;
|
|
|
|
|
if (log_get_fd () != -1)
|
2009-12-08 04:43:15 +00:00
|
|
|
|
no_close_list[i++] = assuan_fd_from_posix_fd (log_get_fd ());
|
|
|
|
|
no_close_list[i++] = assuan_fd_from_posix_fd (fileno (stderr));
|
2009-09-30 15:28:38 +00:00
|
|
|
|
if (input_fd != -1)
|
2009-12-08 04:43:15 +00:00
|
|
|
|
no_close_list[i++] = assuan_fd_from_posix_fd (input_fd);
|
2009-09-30 15:28:38 +00:00
|
|
|
|
if (output_fd != -1)
|
2009-12-08 04:43:15 +00:00
|
|
|
|
no_close_list[i++] = assuan_fd_from_posix_fd (output_fd);
|
2015-11-27 17:58:51 +01:00
|
|
|
|
no_close_list[i] = ASSUAN_INVALID_FD;
|
2009-09-30 15:28:38 +00:00
|
|
|
|
|
|
|
|
|
/* Connect to GPG and perform initial handshaking. */
|
2015-11-24 13:40:56 +01:00
|
|
|
|
err = assuan_pipe_connect (ctx, gpg_program, argv, no_close_list,
|
2009-11-05 12:06:45 +00:00
|
|
|
|
NULL, NULL, 0);
|
2009-09-30 15:28:38 +00:00
|
|
|
|
if (err)
|
|
|
|
|
{
|
|
|
|
|
assuan_release (ctx);
|
|
|
|
|
log_error ("can't connect to GPG: %s\n", gpg_strerror (err));
|
|
|
|
|
return gpg_error (GPG_ERR_NO_ENGINE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (input_fd != -1)
|
|
|
|
|
{
|
|
|
|
|
snprintf (line, sizeof line, "INPUT FD=%d", input_fd);
|
|
|
|
|
err = assuan_transact (ctx, line, NULL, NULL, NULL, NULL, NULL, NULL);
|
|
|
|
|
if (err)
|
|
|
|
|
{
|
|
|
|
|
assuan_release (ctx);
|
|
|
|
|
log_error ("error sending INPUT command: %s\n", gpg_strerror (err));
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (output_fd != -1)
|
|
|
|
|
{
|
|
|
|
|
snprintf (line, sizeof line, "OUTPUT FD=%d", output_fd);
|
|
|
|
|
err = assuan_transact (ctx, line, NULL, NULL, NULL, NULL, NULL, NULL);
|
|
|
|
|
if (err)
|
|
|
|
|
{
|
|
|
|
|
assuan_release (ctx);
|
|
|
|
|
log_error ("error sending OUTPUT command: %s\n", gpg_strerror (err));
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*r_ctx = ctx;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Release the assuan context created by start_gpg. */
|
|
|
|
|
static void
|
|
|
|
|
release_gpg (assuan_context_t ctx)
|
|
|
|
|
{
|
|
|
|
|
assuan_release (ctx);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-02-04 12:57:53 +01:00
|
|
|
|
/* The data passed to the writer_thread. */
|
2009-09-30 15:28:38 +00:00
|
|
|
|
struct writer_thread_parms
|
|
|
|
|
{
|
|
|
|
|
int fd;
|
|
|
|
|
const void *data;
|
|
|
|
|
size_t datalen;
|
2015-11-24 18:31:14 +01:00
|
|
|
|
estream_t stream;
|
2009-09-30 15:28:38 +00:00
|
|
|
|
gpg_error_t *err_addr;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* The thread started by start_writer. */
|
|
|
|
|
static void *
|
Port to npth.
* configure.ac: Don't check for PTH but for NPTH.
(AH_BOTTOM): Remove PTH_SYSCALL_SOFT.
(have_pth): Rename to ...
(have_npth): ... this.
(USE_GNU_NPTH): Rename to ...
(USE_GNU_PTH): ... this.
* m4/npth.m4: New file.
* agent/Makefile.am, agent/cache.c, agent/call-pinentry.c,
agent/call-scd.c, agent/findkey.c, agent/gpg-agent.c,
agent/trustlist.c, common/Makefile.am, common/estream.c,
common/exechelp-posix.c, common/exechelp-w32.c,
common/exechelp-w32ce.c, common/http.c, common/init.c,
common/sysutils.c, dirmngr/Makefile.am, dirmngr/crlfetch.c,
dirmngr/dirmngr.c, dirmngr/dirmngr_ldap.c, dirmngr/ldap-wrapper-ce.c,
dirmngr/ldap-wrapper.c, dirmngr/ldap.c, g13/Makefile.am,
g13/call-gpg.c, g13/g13.c, g13/runner.c, scd/Makefile.am,
scd/apdu.c, scd/app.c, scd/ccid-driver.c, scd/command.c,
scd/scdaemon.c, tools/Makefile.am: Port to npth.
2012-01-03 22:12:37 +01:00
|
|
|
|
writer_thread_main (void *arg)
|
2009-09-30 15:28:38 +00:00
|
|
|
|
{
|
2015-11-24 18:31:14 +01:00
|
|
|
|
gpg_error_t err = 0;
|
2009-09-30 15:28:38 +00:00
|
|
|
|
struct writer_thread_parms *parm = arg;
|
2015-11-24 18:31:14 +01:00
|
|
|
|
char _buffer[4096];
|
|
|
|
|
char *buffer;
|
|
|
|
|
size_t length;
|
|
|
|
|
|
|
|
|
|
if (parm->stream)
|
|
|
|
|
{
|
|
|
|
|
buffer = _buffer;
|
|
|
|
|
err = es_read (parm->stream, buffer, sizeof _buffer, &length);
|
|
|
|
|
if (err)
|
|
|
|
|
{
|
|
|
|
|
log_error ("reading stream failed: %s\n", gpg_strerror (err));
|
|
|
|
|
goto leave;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
buffer = (char *) parm->data;
|
|
|
|
|
length = parm->datalen;
|
|
|
|
|
}
|
2009-09-30 15:28:38 +00:00
|
|
|
|
|
|
|
|
|
while (length)
|
|
|
|
|
{
|
|
|
|
|
ssize_t nwritten;
|
|
|
|
|
|
Port to npth.
* configure.ac: Don't check for PTH but for NPTH.
(AH_BOTTOM): Remove PTH_SYSCALL_SOFT.
(have_pth): Rename to ...
(have_npth): ... this.
(USE_GNU_NPTH): Rename to ...
(USE_GNU_PTH): ... this.
* m4/npth.m4: New file.
* agent/Makefile.am, agent/cache.c, agent/call-pinentry.c,
agent/call-scd.c, agent/findkey.c, agent/gpg-agent.c,
agent/trustlist.c, common/Makefile.am, common/estream.c,
common/exechelp-posix.c, common/exechelp-w32.c,
common/exechelp-w32ce.c, common/http.c, common/init.c,
common/sysutils.c, dirmngr/Makefile.am, dirmngr/crlfetch.c,
dirmngr/dirmngr.c, dirmngr/dirmngr_ldap.c, dirmngr/ldap-wrapper-ce.c,
dirmngr/ldap-wrapper.c, dirmngr/ldap.c, g13/Makefile.am,
g13/call-gpg.c, g13/g13.c, g13/runner.c, scd/Makefile.am,
scd/apdu.c, scd/app.c, scd/ccid-driver.c, scd/command.c,
scd/scdaemon.c, tools/Makefile.am: Port to npth.
2012-01-03 22:12:37 +01:00
|
|
|
|
nwritten = npth_write (parm->fd, buffer, length < 4096? length:4096);
|
2009-09-30 15:28:38 +00:00
|
|
|
|
if (nwritten < 0)
|
|
|
|
|
{
|
|
|
|
|
if (errno == EINTR)
|
|
|
|
|
continue;
|
2015-12-14 19:55:34 +01:00
|
|
|
|
err = my_error_from_syserror ();
|
2009-09-30 15:28:38 +00:00
|
|
|
|
break; /* Write error. */
|
|
|
|
|
}
|
|
|
|
|
length -= nwritten;
|
2015-11-24 18:31:14 +01:00
|
|
|
|
|
|
|
|
|
if (parm->stream)
|
|
|
|
|
{
|
|
|
|
|
if (length == 0)
|
|
|
|
|
{
|
|
|
|
|
err = es_read (parm->stream, buffer, sizeof _buffer, &length);
|
|
|
|
|
if (err)
|
|
|
|
|
{
|
|
|
|
|
log_error ("reading stream failed: %s\n",
|
|
|
|
|
gpg_strerror (err));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (length == 0)
|
|
|
|
|
/* We're done. */
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
buffer += nwritten;
|
2009-09-30 15:28:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-11-24 18:31:14 +01:00
|
|
|
|
leave:
|
|
|
|
|
*parm->err_addr = err;
|
2009-09-30 15:28:38 +00:00
|
|
|
|
if (close (parm->fd))
|
|
|
|
|
log_error ("closing writer fd %d failed: %s\n", parm->fd, strerror (errno));
|
|
|
|
|
xfree (parm);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Fire up a thread to send (DATA,DATALEN) to the file descriptor FD.
|
|
|
|
|
On success the thread receives the ownership over FD. The thread
|
|
|
|
|
ID is stored at R_TID. WRITER_ERR is the address of an gpg_error_t
|
|
|
|
|
variable to receive a possible write error after the thread has
|
|
|
|
|
finished. */
|
|
|
|
|
static gpg_error_t
|
2015-11-24 18:31:14 +01:00
|
|
|
|
start_writer (int fd, const void *data, size_t datalen, estream_t stream,
|
Port to npth.
* configure.ac: Don't check for PTH but for NPTH.
(AH_BOTTOM): Remove PTH_SYSCALL_SOFT.
(have_pth): Rename to ...
(have_npth): ... this.
(USE_GNU_NPTH): Rename to ...
(USE_GNU_PTH): ... this.
* m4/npth.m4: New file.
* agent/Makefile.am, agent/cache.c, agent/call-pinentry.c,
agent/call-scd.c, agent/findkey.c, agent/gpg-agent.c,
agent/trustlist.c, common/Makefile.am, common/estream.c,
common/exechelp-posix.c, common/exechelp-w32.c,
common/exechelp-w32ce.c, common/http.c, common/init.c,
common/sysutils.c, dirmngr/Makefile.am, dirmngr/crlfetch.c,
dirmngr/dirmngr.c, dirmngr/dirmngr_ldap.c, dirmngr/ldap-wrapper-ce.c,
dirmngr/ldap-wrapper.c, dirmngr/ldap.c, g13/Makefile.am,
g13/call-gpg.c, g13/g13.c, g13/runner.c, scd/Makefile.am,
scd/apdu.c, scd/app.c, scd/ccid-driver.c, scd/command.c,
scd/scdaemon.c, tools/Makefile.am: Port to npth.
2012-01-03 22:12:37 +01:00
|
|
|
|
npth_t *r_thread, gpg_error_t *err_addr)
|
2009-09-30 15:28:38 +00:00
|
|
|
|
{
|
|
|
|
|
gpg_error_t err;
|
|
|
|
|
struct writer_thread_parms *parm;
|
Port to npth.
* configure.ac: Don't check for PTH but for NPTH.
(AH_BOTTOM): Remove PTH_SYSCALL_SOFT.
(have_pth): Rename to ...
(have_npth): ... this.
(USE_GNU_NPTH): Rename to ...
(USE_GNU_PTH): ... this.
* m4/npth.m4: New file.
* agent/Makefile.am, agent/cache.c, agent/call-pinentry.c,
agent/call-scd.c, agent/findkey.c, agent/gpg-agent.c,
agent/trustlist.c, common/Makefile.am, common/estream.c,
common/exechelp-posix.c, common/exechelp-w32.c,
common/exechelp-w32ce.c, common/http.c, common/init.c,
common/sysutils.c, dirmngr/Makefile.am, dirmngr/crlfetch.c,
dirmngr/dirmngr.c, dirmngr/dirmngr_ldap.c, dirmngr/ldap-wrapper-ce.c,
dirmngr/ldap-wrapper.c, dirmngr/ldap.c, g13/Makefile.am,
g13/call-gpg.c, g13/g13.c, g13/runner.c, scd/Makefile.am,
scd/apdu.c, scd/app.c, scd/ccid-driver.c, scd/command.c,
scd/scdaemon.c, tools/Makefile.am: Port to npth.
2012-01-03 22:12:37 +01:00
|
|
|
|
npth_attr_t tattr;
|
|
|
|
|
npth_t thread;
|
|
|
|
|
int ret;
|
2009-09-30 15:28:38 +00:00
|
|
|
|
|
Port to npth.
* configure.ac: Don't check for PTH but for NPTH.
(AH_BOTTOM): Remove PTH_SYSCALL_SOFT.
(have_pth): Rename to ...
(have_npth): ... this.
(USE_GNU_NPTH): Rename to ...
(USE_GNU_PTH): ... this.
* m4/npth.m4: New file.
* agent/Makefile.am, agent/cache.c, agent/call-pinentry.c,
agent/call-scd.c, agent/findkey.c, agent/gpg-agent.c,
agent/trustlist.c, common/Makefile.am, common/estream.c,
common/exechelp-posix.c, common/exechelp-w32.c,
common/exechelp-w32ce.c, common/http.c, common/init.c,
common/sysutils.c, dirmngr/Makefile.am, dirmngr/crlfetch.c,
dirmngr/dirmngr.c, dirmngr/dirmngr_ldap.c, dirmngr/ldap-wrapper-ce.c,
dirmngr/ldap-wrapper.c, dirmngr/ldap.c, g13/Makefile.am,
g13/call-gpg.c, g13/g13.c, g13/runner.c, scd/Makefile.am,
scd/apdu.c, scd/app.c, scd/ccid-driver.c, scd/command.c,
scd/scdaemon.c, tools/Makefile.am: Port to npth.
2012-01-03 22:12:37 +01:00
|
|
|
|
memset (r_thread, '\0', sizeof (*r_thread));
|
2009-09-30 15:28:38 +00:00
|
|
|
|
*err_addr = 0;
|
|
|
|
|
|
|
|
|
|
parm = xtrymalloc (sizeof *parm);
|
|
|
|
|
if (!parm)
|
2015-12-14 19:55:34 +01:00
|
|
|
|
return my_error_from_syserror ();
|
2009-09-30 15:28:38 +00:00
|
|
|
|
parm->fd = fd;
|
|
|
|
|
parm->data = data;
|
|
|
|
|
parm->datalen = datalen;
|
2015-11-24 18:31:14 +01:00
|
|
|
|
parm->stream = stream;
|
2009-09-30 15:28:38 +00:00
|
|
|
|
parm->err_addr = err_addr;
|
|
|
|
|
|
Port to npth.
* configure.ac: Don't check for PTH but for NPTH.
(AH_BOTTOM): Remove PTH_SYSCALL_SOFT.
(have_pth): Rename to ...
(have_npth): ... this.
(USE_GNU_NPTH): Rename to ...
(USE_GNU_PTH): ... this.
* m4/npth.m4: New file.
* agent/Makefile.am, agent/cache.c, agent/call-pinentry.c,
agent/call-scd.c, agent/findkey.c, agent/gpg-agent.c,
agent/trustlist.c, common/Makefile.am, common/estream.c,
common/exechelp-posix.c, common/exechelp-w32.c,
common/exechelp-w32ce.c, common/http.c, common/init.c,
common/sysutils.c, dirmngr/Makefile.am, dirmngr/crlfetch.c,
dirmngr/dirmngr.c, dirmngr/dirmngr_ldap.c, dirmngr/ldap-wrapper-ce.c,
dirmngr/ldap-wrapper.c, dirmngr/ldap.c, g13/Makefile.am,
g13/call-gpg.c, g13/g13.c, g13/runner.c, scd/Makefile.am,
scd/apdu.c, scd/app.c, scd/ccid-driver.c, scd/command.c,
scd/scdaemon.c, tools/Makefile.am: Port to npth.
2012-01-03 22:12:37 +01:00
|
|
|
|
npth_attr_init (&tattr);
|
|
|
|
|
npth_attr_setdetachstate (&tattr, NPTH_CREATE_JOINABLE);
|
2009-09-30 15:28:38 +00:00
|
|
|
|
|
Port to npth.
* configure.ac: Don't check for PTH but for NPTH.
(AH_BOTTOM): Remove PTH_SYSCALL_SOFT.
(have_pth): Rename to ...
(have_npth): ... this.
(USE_GNU_NPTH): Rename to ...
(USE_GNU_PTH): ... this.
* m4/npth.m4: New file.
* agent/Makefile.am, agent/cache.c, agent/call-pinentry.c,
agent/call-scd.c, agent/findkey.c, agent/gpg-agent.c,
agent/trustlist.c, common/Makefile.am, common/estream.c,
common/exechelp-posix.c, common/exechelp-w32.c,
common/exechelp-w32ce.c, common/http.c, common/init.c,
common/sysutils.c, dirmngr/Makefile.am, dirmngr/crlfetch.c,
dirmngr/dirmngr.c, dirmngr/dirmngr_ldap.c, dirmngr/ldap-wrapper-ce.c,
dirmngr/ldap-wrapper.c, dirmngr/ldap.c, g13/Makefile.am,
g13/call-gpg.c, g13/g13.c, g13/runner.c, scd/Makefile.am,
scd/apdu.c, scd/app.c, scd/ccid-driver.c, scd/command.c,
scd/scdaemon.c, tools/Makefile.am: Port to npth.
2012-01-03 22:12:37 +01:00
|
|
|
|
ret = npth_create (&thread, &tattr, writer_thread_main, parm);
|
|
|
|
|
if (ret)
|
2009-09-30 15:28:38 +00:00
|
|
|
|
{
|
2015-12-14 19:55:34 +01:00
|
|
|
|
err = my_error_from_errno (ret);
|
2009-09-30 15:28:38 +00:00
|
|
|
|
log_error ("error spawning writer thread: %s\n", gpg_strerror (err));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
Port to npth.
* configure.ac: Don't check for PTH but for NPTH.
(AH_BOTTOM): Remove PTH_SYSCALL_SOFT.
(have_pth): Rename to ...
(have_npth): ... this.
(USE_GNU_NPTH): Rename to ...
(USE_GNU_PTH): ... this.
* m4/npth.m4: New file.
* agent/Makefile.am, agent/cache.c, agent/call-pinentry.c,
agent/call-scd.c, agent/findkey.c, agent/gpg-agent.c,
agent/trustlist.c, common/Makefile.am, common/estream.c,
common/exechelp-posix.c, common/exechelp-w32.c,
common/exechelp-w32ce.c, common/http.c, common/init.c,
common/sysutils.c, dirmngr/Makefile.am, dirmngr/crlfetch.c,
dirmngr/dirmngr.c, dirmngr/dirmngr_ldap.c, dirmngr/ldap-wrapper-ce.c,
dirmngr/ldap-wrapper.c, dirmngr/ldap.c, g13/Makefile.am,
g13/call-gpg.c, g13/g13.c, g13/runner.c, scd/Makefile.am,
scd/apdu.c, scd/app.c, scd/ccid-driver.c, scd/command.c,
scd/scdaemon.c, tools/Makefile.am: Port to npth.
2012-01-03 22:12:37 +01:00
|
|
|
|
npth_setname_np (thread, "fd-writer");
|
2009-09-30 15:28:38 +00:00
|
|
|
|
err = 0;
|
Port to npth.
* configure.ac: Don't check for PTH but for NPTH.
(AH_BOTTOM): Remove PTH_SYSCALL_SOFT.
(have_pth): Rename to ...
(have_npth): ... this.
(USE_GNU_NPTH): Rename to ...
(USE_GNU_PTH): ... this.
* m4/npth.m4: New file.
* agent/Makefile.am, agent/cache.c, agent/call-pinentry.c,
agent/call-scd.c, agent/findkey.c, agent/gpg-agent.c,
agent/trustlist.c, common/Makefile.am, common/estream.c,
common/exechelp-posix.c, common/exechelp-w32.c,
common/exechelp-w32ce.c, common/http.c, common/init.c,
common/sysutils.c, dirmngr/Makefile.am, dirmngr/crlfetch.c,
dirmngr/dirmngr.c, dirmngr/dirmngr_ldap.c, dirmngr/ldap-wrapper-ce.c,
dirmngr/ldap-wrapper.c, dirmngr/ldap.c, g13/Makefile.am,
g13/call-gpg.c, g13/g13.c, g13/runner.c, scd/Makefile.am,
scd/apdu.c, scd/app.c, scd/ccid-driver.c, scd/command.c,
scd/scdaemon.c, tools/Makefile.am: Port to npth.
2012-01-03 22:12:37 +01:00
|
|
|
|
*r_thread = thread;
|
2009-09-30 15:28:38 +00:00
|
|
|
|
}
|
Port to npth.
* configure.ac: Don't check for PTH but for NPTH.
(AH_BOTTOM): Remove PTH_SYSCALL_SOFT.
(have_pth): Rename to ...
(have_npth): ... this.
(USE_GNU_NPTH): Rename to ...
(USE_GNU_PTH): ... this.
* m4/npth.m4: New file.
* agent/Makefile.am, agent/cache.c, agent/call-pinentry.c,
agent/call-scd.c, agent/findkey.c, agent/gpg-agent.c,
agent/trustlist.c, common/Makefile.am, common/estream.c,
common/exechelp-posix.c, common/exechelp-w32.c,
common/exechelp-w32ce.c, common/http.c, common/init.c,
common/sysutils.c, dirmngr/Makefile.am, dirmngr/crlfetch.c,
dirmngr/dirmngr.c, dirmngr/dirmngr_ldap.c, dirmngr/ldap-wrapper-ce.c,
dirmngr/ldap-wrapper.c, dirmngr/ldap.c, g13/Makefile.am,
g13/call-gpg.c, g13/g13.c, g13/runner.c, scd/Makefile.am,
scd/apdu.c, scd/app.c, scd/ccid-driver.c, scd/command.c,
scd/scdaemon.c, tools/Makefile.am: Port to npth.
2012-01-03 22:12:37 +01:00
|
|
|
|
npth_attr_destroy (&tattr);
|
2009-09-30 15:28:38 +00:00
|
|
|
|
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-02-04 12:57:53 +01:00
|
|
|
|
/* The data passed to the reader_thread. */
|
2009-09-30 15:28:38 +00:00
|
|
|
|
struct reader_thread_parms
|
|
|
|
|
{
|
|
|
|
|
int fd;
|
|
|
|
|
membuf_t *mb;
|
2015-11-24 18:31:14 +01:00
|
|
|
|
estream_t stream;
|
2009-09-30 15:28:38 +00:00
|
|
|
|
gpg_error_t *err_addr;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* The thread started by start_reader. */
|
|
|
|
|
static void *
|
Port to npth.
* configure.ac: Don't check for PTH but for NPTH.
(AH_BOTTOM): Remove PTH_SYSCALL_SOFT.
(have_pth): Rename to ...
(have_npth): ... this.
(USE_GNU_NPTH): Rename to ...
(USE_GNU_PTH): ... this.
* m4/npth.m4: New file.
* agent/Makefile.am, agent/cache.c, agent/call-pinentry.c,
agent/call-scd.c, agent/findkey.c, agent/gpg-agent.c,
agent/trustlist.c, common/Makefile.am, common/estream.c,
common/exechelp-posix.c, common/exechelp-w32.c,
common/exechelp-w32ce.c, common/http.c, common/init.c,
common/sysutils.c, dirmngr/Makefile.am, dirmngr/crlfetch.c,
dirmngr/dirmngr.c, dirmngr/dirmngr_ldap.c, dirmngr/ldap-wrapper-ce.c,
dirmngr/ldap-wrapper.c, dirmngr/ldap.c, g13/Makefile.am,
g13/call-gpg.c, g13/g13.c, g13/runner.c, scd/Makefile.am,
scd/apdu.c, scd/app.c, scd/ccid-driver.c, scd/command.c,
scd/scdaemon.c, tools/Makefile.am: Port to npth.
2012-01-03 22:12:37 +01:00
|
|
|
|
reader_thread_main (void *arg)
|
2009-09-30 15:28:38 +00:00
|
|
|
|
{
|
2015-11-24 18:31:14 +01:00
|
|
|
|
gpg_error_t err = 0;
|
2009-09-30 15:28:38 +00:00
|
|
|
|
struct reader_thread_parms *parm = arg;
|
|
|
|
|
char buffer[4096];
|
|
|
|
|
int nread;
|
|
|
|
|
|
Port to npth.
* configure.ac: Don't check for PTH but for NPTH.
(AH_BOTTOM): Remove PTH_SYSCALL_SOFT.
(have_pth): Rename to ...
(have_npth): ... this.
(USE_GNU_NPTH): Rename to ...
(USE_GNU_PTH): ... this.
* m4/npth.m4: New file.
* agent/Makefile.am, agent/cache.c, agent/call-pinentry.c,
agent/call-scd.c, agent/findkey.c, agent/gpg-agent.c,
agent/trustlist.c, common/Makefile.am, common/estream.c,
common/exechelp-posix.c, common/exechelp-w32.c,
common/exechelp-w32ce.c, common/http.c, common/init.c,
common/sysutils.c, dirmngr/Makefile.am, dirmngr/crlfetch.c,
dirmngr/dirmngr.c, dirmngr/dirmngr_ldap.c, dirmngr/ldap-wrapper-ce.c,
dirmngr/ldap-wrapper.c, dirmngr/ldap.c, g13/Makefile.am,
g13/call-gpg.c, g13/g13.c, g13/runner.c, scd/Makefile.am,
scd/apdu.c, scd/app.c, scd/ccid-driver.c, scd/command.c,
scd/scdaemon.c, tools/Makefile.am: Port to npth.
2012-01-03 22:12:37 +01:00
|
|
|
|
while ( (nread = npth_read (parm->fd, buffer, sizeof buffer)) )
|
2009-09-30 15:28:38 +00:00
|
|
|
|
{
|
|
|
|
|
if (nread < 0)
|
|
|
|
|
{
|
|
|
|
|
if (errno == EINTR)
|
|
|
|
|
continue;
|
2015-12-14 19:55:34 +01:00
|
|
|
|
err = my_error_from_syserror ();
|
2009-09-30 15:28:38 +00:00
|
|
|
|
break; /* Read error. */
|
|
|
|
|
}
|
2011-02-04 12:57:53 +01:00
|
|
|
|
|
2015-11-24 18:31:14 +01:00
|
|
|
|
if (parm->stream)
|
|
|
|
|
{
|
|
|
|
|
const char *p = buffer;
|
|
|
|
|
size_t nwritten;
|
|
|
|
|
while (nread)
|
|
|
|
|
{
|
|
|
|
|
err = es_write (parm->stream, p, nread, &nwritten);
|
|
|
|
|
if (err)
|
|
|
|
|
{
|
|
|
|
|
log_error ("writing stream failed: %s\n",
|
|
|
|
|
gpg_strerror (err));
|
|
|
|
|
goto leave;
|
|
|
|
|
}
|
|
|
|
|
nread -= nwritten;
|
|
|
|
|
p += nwritten;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
put_membuf (parm->mb, buffer, nread);
|
2009-09-30 15:28:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-11-24 18:31:14 +01:00
|
|
|
|
leave:
|
|
|
|
|
*parm->err_addr = err;
|
2009-09-30 15:28:38 +00:00
|
|
|
|
if (close (parm->fd))
|
|
|
|
|
log_error ("closing reader fd %d failed: %s\n", parm->fd, strerror (errno));
|
|
|
|
|
xfree (parm);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Fire up a thread to receive data from the file descriptor FD. On
|
|
|
|
|
success the thread receives the ownership over FD. The thread ID
|
|
|
|
|
is stored at R_TID. After the thread has finished an error from
|
|
|
|
|
the thread will be stored at ERR_ADDR. */
|
|
|
|
|
static gpg_error_t
|
2015-11-24 18:31:14 +01:00
|
|
|
|
start_reader (int fd, membuf_t *mb, estream_t stream,
|
|
|
|
|
npth_t *r_thread, gpg_error_t *err_addr)
|
2009-09-30 15:28:38 +00:00
|
|
|
|
{
|
|
|
|
|
gpg_error_t err;
|
|
|
|
|
struct reader_thread_parms *parm;
|
Port to npth.
* configure.ac: Don't check for PTH but for NPTH.
(AH_BOTTOM): Remove PTH_SYSCALL_SOFT.
(have_pth): Rename to ...
(have_npth): ... this.
(USE_GNU_NPTH): Rename to ...
(USE_GNU_PTH): ... this.
* m4/npth.m4: New file.
* agent/Makefile.am, agent/cache.c, agent/call-pinentry.c,
agent/call-scd.c, agent/findkey.c, agent/gpg-agent.c,
agent/trustlist.c, common/Makefile.am, common/estream.c,
common/exechelp-posix.c, common/exechelp-w32.c,
common/exechelp-w32ce.c, common/http.c, common/init.c,
common/sysutils.c, dirmngr/Makefile.am, dirmngr/crlfetch.c,
dirmngr/dirmngr.c, dirmngr/dirmngr_ldap.c, dirmngr/ldap-wrapper-ce.c,
dirmngr/ldap-wrapper.c, dirmngr/ldap.c, g13/Makefile.am,
g13/call-gpg.c, g13/g13.c, g13/runner.c, scd/Makefile.am,
scd/apdu.c, scd/app.c, scd/ccid-driver.c, scd/command.c,
scd/scdaemon.c, tools/Makefile.am: Port to npth.
2012-01-03 22:12:37 +01:00
|
|
|
|
npth_attr_t tattr;
|
|
|
|
|
npth_t thread;
|
|
|
|
|
int ret;
|
2009-09-30 15:28:38 +00:00
|
|
|
|
|
Port to npth.
* configure.ac: Don't check for PTH but for NPTH.
(AH_BOTTOM): Remove PTH_SYSCALL_SOFT.
(have_pth): Rename to ...
(have_npth): ... this.
(USE_GNU_NPTH): Rename to ...
(USE_GNU_PTH): ... this.
* m4/npth.m4: New file.
* agent/Makefile.am, agent/cache.c, agent/call-pinentry.c,
agent/call-scd.c, agent/findkey.c, agent/gpg-agent.c,
agent/trustlist.c, common/Makefile.am, common/estream.c,
common/exechelp-posix.c, common/exechelp-w32.c,
common/exechelp-w32ce.c, common/http.c, common/init.c,
common/sysutils.c, dirmngr/Makefile.am, dirmngr/crlfetch.c,
dirmngr/dirmngr.c, dirmngr/dirmngr_ldap.c, dirmngr/ldap-wrapper-ce.c,
dirmngr/ldap-wrapper.c, dirmngr/ldap.c, g13/Makefile.am,
g13/call-gpg.c, g13/g13.c, g13/runner.c, scd/Makefile.am,
scd/apdu.c, scd/app.c, scd/ccid-driver.c, scd/command.c,
scd/scdaemon.c, tools/Makefile.am: Port to npth.
2012-01-03 22:12:37 +01:00
|
|
|
|
memset (r_thread, '\0', sizeof (*r_thread));
|
2009-09-30 15:28:38 +00:00
|
|
|
|
*err_addr = 0;
|
|
|
|
|
|
|
|
|
|
parm = xtrymalloc (sizeof *parm);
|
|
|
|
|
if (!parm)
|
2015-12-14 19:55:34 +01:00
|
|
|
|
return my_error_from_syserror ();
|
2009-09-30 15:28:38 +00:00
|
|
|
|
parm->fd = fd;
|
|
|
|
|
parm->mb = mb;
|
2015-11-24 18:31:14 +01:00
|
|
|
|
parm->stream = stream;
|
2009-09-30 15:28:38 +00:00
|
|
|
|
parm->err_addr = err_addr;
|
|
|
|
|
|
Port to npth.
* configure.ac: Don't check for PTH but for NPTH.
(AH_BOTTOM): Remove PTH_SYSCALL_SOFT.
(have_pth): Rename to ...
(have_npth): ... this.
(USE_GNU_NPTH): Rename to ...
(USE_GNU_PTH): ... this.
* m4/npth.m4: New file.
* agent/Makefile.am, agent/cache.c, agent/call-pinentry.c,
agent/call-scd.c, agent/findkey.c, agent/gpg-agent.c,
agent/trustlist.c, common/Makefile.am, common/estream.c,
common/exechelp-posix.c, common/exechelp-w32.c,
common/exechelp-w32ce.c, common/http.c, common/init.c,
common/sysutils.c, dirmngr/Makefile.am, dirmngr/crlfetch.c,
dirmngr/dirmngr.c, dirmngr/dirmngr_ldap.c, dirmngr/ldap-wrapper-ce.c,
dirmngr/ldap-wrapper.c, dirmngr/ldap.c, g13/Makefile.am,
g13/call-gpg.c, g13/g13.c, g13/runner.c, scd/Makefile.am,
scd/apdu.c, scd/app.c, scd/ccid-driver.c, scd/command.c,
scd/scdaemon.c, tools/Makefile.am: Port to npth.
2012-01-03 22:12:37 +01:00
|
|
|
|
npth_attr_init (&tattr);
|
|
|
|
|
npth_attr_setdetachstate (&tattr, NPTH_CREATE_JOINABLE);
|
2009-09-30 15:28:38 +00:00
|
|
|
|
|
Port to npth.
* configure.ac: Don't check for PTH but for NPTH.
(AH_BOTTOM): Remove PTH_SYSCALL_SOFT.
(have_pth): Rename to ...
(have_npth): ... this.
(USE_GNU_NPTH): Rename to ...
(USE_GNU_PTH): ... this.
* m4/npth.m4: New file.
* agent/Makefile.am, agent/cache.c, agent/call-pinentry.c,
agent/call-scd.c, agent/findkey.c, agent/gpg-agent.c,
agent/trustlist.c, common/Makefile.am, common/estream.c,
common/exechelp-posix.c, common/exechelp-w32.c,
common/exechelp-w32ce.c, common/http.c, common/init.c,
common/sysutils.c, dirmngr/Makefile.am, dirmngr/crlfetch.c,
dirmngr/dirmngr.c, dirmngr/dirmngr_ldap.c, dirmngr/ldap-wrapper-ce.c,
dirmngr/ldap-wrapper.c, dirmngr/ldap.c, g13/Makefile.am,
g13/call-gpg.c, g13/g13.c, g13/runner.c, scd/Makefile.am,
scd/apdu.c, scd/app.c, scd/ccid-driver.c, scd/command.c,
scd/scdaemon.c, tools/Makefile.am: Port to npth.
2012-01-03 22:12:37 +01:00
|
|
|
|
ret = npth_create (&thread, &tattr, reader_thread_main, parm);
|
|
|
|
|
if (ret)
|
2009-09-30 15:28:38 +00:00
|
|
|
|
{
|
2015-12-14 19:55:34 +01:00
|
|
|
|
err = my_error_from_errno (ret);
|
2009-09-30 15:28:38 +00:00
|
|
|
|
log_error ("error spawning reader thread: %s\n", gpg_strerror (err));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
Port to npth.
* configure.ac: Don't check for PTH but for NPTH.
(AH_BOTTOM): Remove PTH_SYSCALL_SOFT.
(have_pth): Rename to ...
(have_npth): ... this.
(USE_GNU_NPTH): Rename to ...
(USE_GNU_PTH): ... this.
* m4/npth.m4: New file.
* agent/Makefile.am, agent/cache.c, agent/call-pinentry.c,
agent/call-scd.c, agent/findkey.c, agent/gpg-agent.c,
agent/trustlist.c, common/Makefile.am, common/estream.c,
common/exechelp-posix.c, common/exechelp-w32.c,
common/exechelp-w32ce.c, common/http.c, common/init.c,
common/sysutils.c, dirmngr/Makefile.am, dirmngr/crlfetch.c,
dirmngr/dirmngr.c, dirmngr/dirmngr_ldap.c, dirmngr/ldap-wrapper-ce.c,
dirmngr/ldap-wrapper.c, dirmngr/ldap.c, g13/Makefile.am,
g13/call-gpg.c, g13/g13.c, g13/runner.c, scd/Makefile.am,
scd/apdu.c, scd/app.c, scd/ccid-driver.c, scd/command.c,
scd/scdaemon.c, tools/Makefile.am: Port to npth.
2012-01-03 22:12:37 +01:00
|
|
|
|
npth_setname_np (thread, "fd-reader");
|
2009-09-30 15:28:38 +00:00
|
|
|
|
err = 0;
|
Port to npth.
* configure.ac: Don't check for PTH but for NPTH.
(AH_BOTTOM): Remove PTH_SYSCALL_SOFT.
(have_pth): Rename to ...
(have_npth): ... this.
(USE_GNU_NPTH): Rename to ...
(USE_GNU_PTH): ... this.
* m4/npth.m4: New file.
* agent/Makefile.am, agent/cache.c, agent/call-pinentry.c,
agent/call-scd.c, agent/findkey.c, agent/gpg-agent.c,
agent/trustlist.c, common/Makefile.am, common/estream.c,
common/exechelp-posix.c, common/exechelp-w32.c,
common/exechelp-w32ce.c, common/http.c, common/init.c,
common/sysutils.c, dirmngr/Makefile.am, dirmngr/crlfetch.c,
dirmngr/dirmngr.c, dirmngr/dirmngr_ldap.c, dirmngr/ldap-wrapper-ce.c,
dirmngr/ldap-wrapper.c, dirmngr/ldap.c, g13/Makefile.am,
g13/call-gpg.c, g13/g13.c, g13/runner.c, scd/Makefile.am,
scd/apdu.c, scd/app.c, scd/ccid-driver.c, scd/command.c,
scd/scdaemon.c, tools/Makefile.am: Port to npth.
2012-01-03 22:12:37 +01:00
|
|
|
|
*r_thread = thread;
|
2009-09-30 15:28:38 +00:00
|
|
|
|
}
|
Port to npth.
* configure.ac: Don't check for PTH but for NPTH.
(AH_BOTTOM): Remove PTH_SYSCALL_SOFT.
(have_pth): Rename to ...
(have_npth): ... this.
(USE_GNU_NPTH): Rename to ...
(USE_GNU_PTH): ... this.
* m4/npth.m4: New file.
* agent/Makefile.am, agent/cache.c, agent/call-pinentry.c,
agent/call-scd.c, agent/findkey.c, agent/gpg-agent.c,
agent/trustlist.c, common/Makefile.am, common/estream.c,
common/exechelp-posix.c, common/exechelp-w32.c,
common/exechelp-w32ce.c, common/http.c, common/init.c,
common/sysutils.c, dirmngr/Makefile.am, dirmngr/crlfetch.c,
dirmngr/dirmngr.c, dirmngr/dirmngr_ldap.c, dirmngr/ldap-wrapper-ce.c,
dirmngr/ldap-wrapper.c, dirmngr/ldap.c, g13/Makefile.am,
g13/call-gpg.c, g13/g13.c, g13/runner.c, scd/Makefile.am,
scd/apdu.c, scd/app.c, scd/ccid-driver.c, scd/command.c,
scd/scdaemon.c, tools/Makefile.am: Port to npth.
2012-01-03 22:12:37 +01:00
|
|
|
|
npth_attr_destroy (&tattr);
|
2009-09-30 15:28:38 +00:00
|
|
|
|
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-02-04 12:57:53 +01:00
|
|
|
|
/* Call GPG to encrypt a block of data.
|
2009-09-30 15:28:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/
|
2015-11-24 14:58:31 +01:00
|
|
|
|
static gpg_error_t
|
2015-11-26 15:01:40 +01:00
|
|
|
|
_gpg_encrypt (ctrl_t ctrl,
|
|
|
|
|
const char *gpg_program,
|
|
|
|
|
strlist_t gpg_arguments,
|
2015-11-24 14:58:31 +01:00
|
|
|
|
const void *plain, size_t plainlen,
|
2015-11-24 18:31:14 +01:00
|
|
|
|
estream_t plain_stream,
|
2015-11-24 14:58:31 +01:00
|
|
|
|
strlist_t keys,
|
2015-11-24 18:31:14 +01:00
|
|
|
|
membuf_t *reader_mb,
|
|
|
|
|
estream_t cipher_stream)
|
2009-09-30 15:28:38 +00:00
|
|
|
|
{
|
|
|
|
|
gpg_error_t err;
|
2014-09-18 16:00:34 +02:00
|
|
|
|
assuan_context_t ctx = NULL;
|
2009-09-30 15:28:38 +00:00
|
|
|
|
int outbound_fds[2] = { -1, -1 };
|
|
|
|
|
int inbound_fds[2] = { -1, -1 };
|
2014-09-18 16:00:34 +02:00
|
|
|
|
npth_t writer_thread = (npth_t)0;
|
|
|
|
|
npth_t reader_thread = (npth_t)0;
|
2009-09-30 15:28:38 +00:00
|
|
|
|
gpg_error_t writer_err, reader_err;
|
2009-10-19 09:18:46 +00:00
|
|
|
|
char line[ASSUAN_LINELENGTH];
|
|
|
|
|
strlist_t sl;
|
Port to npth.
* configure.ac: Don't check for PTH but for NPTH.
(AH_BOTTOM): Remove PTH_SYSCALL_SOFT.
(have_pth): Rename to ...
(have_npth): ... this.
(USE_GNU_NPTH): Rename to ...
(USE_GNU_PTH): ... this.
* m4/npth.m4: New file.
* agent/Makefile.am, agent/cache.c, agent/call-pinentry.c,
agent/call-scd.c, agent/findkey.c, agent/gpg-agent.c,
agent/trustlist.c, common/Makefile.am, common/estream.c,
common/exechelp-posix.c, common/exechelp-w32.c,
common/exechelp-w32ce.c, common/http.c, common/init.c,
common/sysutils.c, dirmngr/Makefile.am, dirmngr/crlfetch.c,
dirmngr/dirmngr.c, dirmngr/dirmngr_ldap.c, dirmngr/ldap-wrapper-ce.c,
dirmngr/ldap-wrapper.c, dirmngr/ldap.c, g13/Makefile.am,
g13/call-gpg.c, g13/g13.c, g13/runner.c, scd/Makefile.am,
scd/apdu.c, scd/app.c, scd/ccid-driver.c, scd/command.c,
scd/scdaemon.c, tools/Makefile.am: Port to npth.
2012-01-03 22:12:37 +01:00
|
|
|
|
int ret;
|
2009-09-30 15:28:38 +00:00
|
|
|
|
|
2015-11-24 18:31:14 +01:00
|
|
|
|
/* Make sure that either the stream interface xor the buffer
|
|
|
|
|
interface is used. */
|
|
|
|
|
assert ((plain == NULL) != (plain_stream == NULL));
|
|
|
|
|
assert ((reader_mb == NULL) != (cipher_stream == NULL));
|
|
|
|
|
|
2009-09-30 15:28:38 +00:00
|
|
|
|
/* Create two pipes. */
|
|
|
|
|
err = gnupg_create_outbound_pipe (outbound_fds);
|
|
|
|
|
if (!err)
|
|
|
|
|
err = gnupg_create_inbound_pipe (inbound_fds);
|
|
|
|
|
if (err)
|
|
|
|
|
{
|
|
|
|
|
log_error (_("error creating a pipe: %s\n"), gpg_strerror (err));
|
|
|
|
|
goto leave;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Start GPG and send the INPUT and OUTPUT commands. */
|
2015-11-26 15:01:40 +01:00
|
|
|
|
err = start_gpg (ctrl, gpg_program, gpg_arguments,
|
|
|
|
|
outbound_fds[0], inbound_fds[1], &ctx);
|
2009-09-30 15:28:38 +00:00
|
|
|
|
if (err)
|
|
|
|
|
goto leave;
|
|
|
|
|
close (outbound_fds[0]); outbound_fds[0] = -1;
|
|
|
|
|
close (inbound_fds[1]); inbound_fds[1] = -1;
|
2011-02-04 12:57:53 +01:00
|
|
|
|
|
2009-09-30 15:28:38 +00:00
|
|
|
|
/* Start a writer thread to feed the INPUT command of the server. */
|
2015-11-24 18:31:14 +01:00
|
|
|
|
err = start_writer (outbound_fds[1], plain, plainlen, plain_stream,
|
Port to npth.
* configure.ac: Don't check for PTH but for NPTH.
(AH_BOTTOM): Remove PTH_SYSCALL_SOFT.
(have_pth): Rename to ...
(have_npth): ... this.
(USE_GNU_NPTH): Rename to ...
(USE_GNU_PTH): ... this.
* m4/npth.m4: New file.
* agent/Makefile.am, agent/cache.c, agent/call-pinentry.c,
agent/call-scd.c, agent/findkey.c, agent/gpg-agent.c,
agent/trustlist.c, common/Makefile.am, common/estream.c,
common/exechelp-posix.c, common/exechelp-w32.c,
common/exechelp-w32ce.c, common/http.c, common/init.c,
common/sysutils.c, dirmngr/Makefile.am, dirmngr/crlfetch.c,
dirmngr/dirmngr.c, dirmngr/dirmngr_ldap.c, dirmngr/ldap-wrapper-ce.c,
dirmngr/ldap-wrapper.c, dirmngr/ldap.c, g13/Makefile.am,
g13/call-gpg.c, g13/g13.c, g13/runner.c, scd/Makefile.am,
scd/apdu.c, scd/app.c, scd/ccid-driver.c, scd/command.c,
scd/scdaemon.c, tools/Makefile.am: Port to npth.
2012-01-03 22:12:37 +01:00
|
|
|
|
&writer_thread, &writer_err);
|
2009-09-30 15:28:38 +00:00
|
|
|
|
if (err)
|
|
|
|
|
return err;
|
|
|
|
|
outbound_fds[1] = -1; /* The thread owns the FD now. */
|
|
|
|
|
|
|
|
|
|
/* Start a reader thread to eat from the OUTPUT command of the
|
|
|
|
|
server. */
|
2015-11-24 18:31:14 +01:00
|
|
|
|
err = start_reader (inbound_fds[0], reader_mb, cipher_stream,
|
Port to npth.
* configure.ac: Don't check for PTH but for NPTH.
(AH_BOTTOM): Remove PTH_SYSCALL_SOFT.
(have_pth): Rename to ...
(have_npth): ... this.
(USE_GNU_NPTH): Rename to ...
(USE_GNU_PTH): ... this.
* m4/npth.m4: New file.
* agent/Makefile.am, agent/cache.c, agent/call-pinentry.c,
agent/call-scd.c, agent/findkey.c, agent/gpg-agent.c,
agent/trustlist.c, common/Makefile.am, common/estream.c,
common/exechelp-posix.c, common/exechelp-w32.c,
common/exechelp-w32ce.c, common/http.c, common/init.c,
common/sysutils.c, dirmngr/Makefile.am, dirmngr/crlfetch.c,
dirmngr/dirmngr.c, dirmngr/dirmngr_ldap.c, dirmngr/ldap-wrapper-ce.c,
dirmngr/ldap-wrapper.c, dirmngr/ldap.c, g13/Makefile.am,
g13/call-gpg.c, g13/g13.c, g13/runner.c, scd/Makefile.am,
scd/apdu.c, scd/app.c, scd/ccid-driver.c, scd/command.c,
scd/scdaemon.c, tools/Makefile.am: Port to npth.
2012-01-03 22:12:37 +01:00
|
|
|
|
&reader_thread, &reader_err);
|
2009-09-30 15:28:38 +00:00
|
|
|
|
if (err)
|
|
|
|
|
return err;
|
|
|
|
|
outbound_fds[0] = -1; /* The thread owns the FD now. */
|
|
|
|
|
|
|
|
|
|
/* Run the encryption. */
|
2009-10-19 09:18:46 +00:00
|
|
|
|
for (sl = keys; sl; sl = sl->next)
|
2009-09-30 15:28:38 +00:00
|
|
|
|
{
|
2009-10-19 09:18:46 +00:00
|
|
|
|
snprintf (line, sizeof line, "RECIPIENT -- %s", sl->d);
|
|
|
|
|
err = assuan_transact (ctx, line, NULL, NULL, NULL, NULL, NULL, NULL);
|
|
|
|
|
if (err)
|
|
|
|
|
{
|
|
|
|
|
log_error ("the engine's RECIPIENT command failed: %s <%s>\n",
|
2009-09-30 15:28:38 +00:00
|
|
|
|
gpg_strerror (err), gpg_strsource (err));
|
2009-10-19 09:18:46 +00:00
|
|
|
|
goto leave;
|
|
|
|
|
}
|
2009-09-30 15:28:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
err = assuan_transact (ctx, "ENCRYPT", NULL, NULL, NULL, NULL, NULL, NULL);
|
|
|
|
|
if (err)
|
|
|
|
|
{
|
|
|
|
|
log_error ("the engine's ENCRYPT command failed: %s <%s>\n",
|
|
|
|
|
gpg_strerror (err), gpg_strsource (err));
|
|
|
|
|
goto leave;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Wait for reader and return the data. */
|
Port to npth.
* configure.ac: Don't check for PTH but for NPTH.
(AH_BOTTOM): Remove PTH_SYSCALL_SOFT.
(have_pth): Rename to ...
(have_npth): ... this.
(USE_GNU_NPTH): Rename to ...
(USE_GNU_PTH): ... this.
* m4/npth.m4: New file.
* agent/Makefile.am, agent/cache.c, agent/call-pinentry.c,
agent/call-scd.c, agent/findkey.c, agent/gpg-agent.c,
agent/trustlist.c, common/Makefile.am, common/estream.c,
common/exechelp-posix.c, common/exechelp-w32.c,
common/exechelp-w32ce.c, common/http.c, common/init.c,
common/sysutils.c, dirmngr/Makefile.am, dirmngr/crlfetch.c,
dirmngr/dirmngr.c, dirmngr/dirmngr_ldap.c, dirmngr/ldap-wrapper-ce.c,
dirmngr/ldap-wrapper.c, dirmngr/ldap.c, g13/Makefile.am,
g13/call-gpg.c, g13/g13.c, g13/runner.c, scd/Makefile.am,
scd/apdu.c, scd/app.c, scd/ccid-driver.c, scd/command.c,
scd/scdaemon.c, tools/Makefile.am: Port to npth.
2012-01-03 22:12:37 +01:00
|
|
|
|
ret = npth_join (reader_thread, NULL);
|
|
|
|
|
if (ret)
|
2009-09-30 15:28:38 +00:00
|
|
|
|
{
|
2015-12-14 19:55:34 +01:00
|
|
|
|
err = my_error_from_errno (ret);
|
2009-09-30 15:28:38 +00:00
|
|
|
|
log_error ("waiting for reader thread failed: %s\n", gpg_strerror (err));
|
|
|
|
|
goto leave;
|
|
|
|
|
}
|
Port to npth.
* configure.ac: Don't check for PTH but for NPTH.
(AH_BOTTOM): Remove PTH_SYSCALL_SOFT.
(have_pth): Rename to ...
(have_npth): ... this.
(USE_GNU_NPTH): Rename to ...
(USE_GNU_PTH): ... this.
* m4/npth.m4: New file.
* agent/Makefile.am, agent/cache.c, agent/call-pinentry.c,
agent/call-scd.c, agent/findkey.c, agent/gpg-agent.c,
agent/trustlist.c, common/Makefile.am, common/estream.c,
common/exechelp-posix.c, common/exechelp-w32.c,
common/exechelp-w32ce.c, common/http.c, common/init.c,
common/sysutils.c, dirmngr/Makefile.am, dirmngr/crlfetch.c,
dirmngr/dirmngr.c, dirmngr/dirmngr_ldap.c, dirmngr/ldap-wrapper-ce.c,
dirmngr/ldap-wrapper.c, dirmngr/ldap.c, g13/Makefile.am,
g13/call-gpg.c, g13/g13.c, g13/runner.c, scd/Makefile.am,
scd/apdu.c, scd/app.c, scd/ccid-driver.c, scd/command.c,
scd/scdaemon.c, tools/Makefile.am: Port to npth.
2012-01-03 22:12:37 +01:00
|
|
|
|
/* FIXME: Not really valid, as npth_t is an opaque type. */
|
|
|
|
|
memset (&reader_thread, '\0', sizeof (reader_thread));
|
2009-09-30 15:28:38 +00:00
|
|
|
|
if (reader_err)
|
|
|
|
|
{
|
|
|
|
|
err = reader_err;
|
|
|
|
|
log_error ("read error in reader thread: %s\n", gpg_strerror (err));
|
|
|
|
|
goto leave;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Wait for the writer to catch a writer error. */
|
Port to npth.
* configure.ac: Don't check for PTH but for NPTH.
(AH_BOTTOM): Remove PTH_SYSCALL_SOFT.
(have_pth): Rename to ...
(have_npth): ... this.
(USE_GNU_NPTH): Rename to ...
(USE_GNU_PTH): ... this.
* m4/npth.m4: New file.
* agent/Makefile.am, agent/cache.c, agent/call-pinentry.c,
agent/call-scd.c, agent/findkey.c, agent/gpg-agent.c,
agent/trustlist.c, common/Makefile.am, common/estream.c,
common/exechelp-posix.c, common/exechelp-w32.c,
common/exechelp-w32ce.c, common/http.c, common/init.c,
common/sysutils.c, dirmngr/Makefile.am, dirmngr/crlfetch.c,
dirmngr/dirmngr.c, dirmngr/dirmngr_ldap.c, dirmngr/ldap-wrapper-ce.c,
dirmngr/ldap-wrapper.c, dirmngr/ldap.c, g13/Makefile.am,
g13/call-gpg.c, g13/g13.c, g13/runner.c, scd/Makefile.am,
scd/apdu.c, scd/app.c, scd/ccid-driver.c, scd/command.c,
scd/scdaemon.c, tools/Makefile.am: Port to npth.
2012-01-03 22:12:37 +01:00
|
|
|
|
ret = npth_join (writer_thread, NULL);
|
|
|
|
|
if (ret)
|
2009-09-30 15:28:38 +00:00
|
|
|
|
{
|
2015-12-14 19:55:34 +01:00
|
|
|
|
err = my_error_from_errno (ret);
|
2009-09-30 15:28:38 +00:00
|
|
|
|
log_error ("waiting for writer thread failed: %s\n", gpg_strerror (err));
|
|
|
|
|
goto leave;
|
|
|
|
|
}
|
Port to npth.
* configure.ac: Don't check for PTH but for NPTH.
(AH_BOTTOM): Remove PTH_SYSCALL_SOFT.
(have_pth): Rename to ...
(have_npth): ... this.
(USE_GNU_NPTH): Rename to ...
(USE_GNU_PTH): ... this.
* m4/npth.m4: New file.
* agent/Makefile.am, agent/cache.c, agent/call-pinentry.c,
agent/call-scd.c, agent/findkey.c, agent/gpg-agent.c,
agent/trustlist.c, common/Makefile.am, common/estream.c,
common/exechelp-posix.c, common/exechelp-w32.c,
common/exechelp-w32ce.c, common/http.c, common/init.c,
common/sysutils.c, dirmngr/Makefile.am, dirmngr/crlfetch.c,
dirmngr/dirmngr.c, dirmngr/dirmngr_ldap.c, dirmngr/ldap-wrapper-ce.c,
dirmngr/ldap-wrapper.c, dirmngr/ldap.c, g13/Makefile.am,
g13/call-gpg.c, g13/g13.c, g13/runner.c, scd/Makefile.am,
scd/apdu.c, scd/app.c, scd/ccid-driver.c, scd/command.c,
scd/scdaemon.c, tools/Makefile.am: Port to npth.
2012-01-03 22:12:37 +01:00
|
|
|
|
memset (&writer_thread, '\0', sizeof (writer_thread));
|
2009-09-30 15:28:38 +00:00
|
|
|
|
if (writer_err)
|
|
|
|
|
{
|
|
|
|
|
err = writer_err;
|
|
|
|
|
log_error ("write error in writer thread: %s\n", gpg_strerror (err));
|
|
|
|
|
goto leave;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
leave:
|
Port to npth.
* configure.ac: Don't check for PTH but for NPTH.
(AH_BOTTOM): Remove PTH_SYSCALL_SOFT.
(have_pth): Rename to ...
(have_npth): ... this.
(USE_GNU_NPTH): Rename to ...
(USE_GNU_PTH): ... this.
* m4/npth.m4: New file.
* agent/Makefile.am, agent/cache.c, agent/call-pinentry.c,
agent/call-scd.c, agent/findkey.c, agent/gpg-agent.c,
agent/trustlist.c, common/Makefile.am, common/estream.c,
common/exechelp-posix.c, common/exechelp-w32.c,
common/exechelp-w32ce.c, common/http.c, common/init.c,
common/sysutils.c, dirmngr/Makefile.am, dirmngr/crlfetch.c,
dirmngr/dirmngr.c, dirmngr/dirmngr_ldap.c, dirmngr/ldap-wrapper-ce.c,
dirmngr/ldap-wrapper.c, dirmngr/ldap.c, g13/Makefile.am,
g13/call-gpg.c, g13/g13.c, g13/runner.c, scd/Makefile.am,
scd/apdu.c, scd/app.c, scd/ccid-driver.c, scd/command.c,
scd/scdaemon.c, tools/Makefile.am: Port to npth.
2012-01-03 22:12:37 +01:00
|
|
|
|
/* FIXME: Not valid, as npth_t is an opaque type. */
|
|
|
|
|
if (reader_thread)
|
|
|
|
|
npth_detach (reader_thread);
|
|
|
|
|
if (writer_thread)
|
|
|
|
|
npth_detach (writer_thread);
|
2009-09-30 15:28:38 +00:00
|
|
|
|
if (outbound_fds[0] != -1)
|
|
|
|
|
close (outbound_fds[0]);
|
|
|
|
|
if (outbound_fds[1] != -1)
|
|
|
|
|
close (outbound_fds[1]);
|
|
|
|
|
if (inbound_fds[0] != -1)
|
|
|
|
|
close (inbound_fds[0]);
|
|
|
|
|
if (inbound_fds[1] != -1)
|
|
|
|
|
close (inbound_fds[1]);
|
|
|
|
|
release_gpg (ctx);
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-24 14:58:31 +01:00
|
|
|
|
gpg_error_t
|
2015-11-26 15:01:40 +01:00
|
|
|
|
gpg_encrypt_blob (ctrl_t ctrl,
|
|
|
|
|
const char *gpg_program,
|
|
|
|
|
strlist_t gpg_arguments,
|
2015-11-24 14:58:31 +01:00
|
|
|
|
const void *plain, size_t plainlen,
|
|
|
|
|
strlist_t keys,
|
|
|
|
|
void **r_ciph, size_t *r_ciphlen)
|
|
|
|
|
{
|
|
|
|
|
gpg_error_t err;
|
|
|
|
|
membuf_t reader_mb;
|
|
|
|
|
|
|
|
|
|
*r_ciph = NULL;
|
|
|
|
|
*r_ciphlen = 0;
|
|
|
|
|
|
|
|
|
|
/* Init the memory buffer to receive the encrypted stuff. */
|
|
|
|
|
init_membuf (&reader_mb, 4096);
|
|
|
|
|
|
2015-11-26 15:01:40 +01:00
|
|
|
|
err = _gpg_encrypt (ctrl, gpg_program, gpg_arguments,
|
2015-11-24 18:31:14 +01:00
|
|
|
|
plain, plainlen, NULL,
|
2015-11-24 14:58:31 +01:00
|
|
|
|
keys,
|
2015-11-24 18:31:14 +01:00
|
|
|
|
&reader_mb, NULL);
|
2015-11-24 14:58:31 +01:00
|
|
|
|
|
|
|
|
|
if (! err)
|
|
|
|
|
{
|
|
|
|
|
/* Return the data. */
|
|
|
|
|
*r_ciph = get_membuf (&reader_mb, r_ciphlen);
|
|
|
|
|
if (!*r_ciph)
|
|
|
|
|
{
|
2015-12-14 19:55:34 +01:00
|
|
|
|
err = my_error_from_syserror ();
|
2015-11-24 14:58:31 +01:00
|
|
|
|
log_error ("error while storing the data in the reader thread: %s\n",
|
|
|
|
|
gpg_strerror (err));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
xfree (get_membuf (&reader_mb, NULL));
|
|
|
|
|
return err;
|
|
|
|
|
}
|
2009-09-30 15:28:38 +00:00
|
|
|
|
|
2015-11-24 18:31:14 +01:00
|
|
|
|
gpg_error_t
|
2015-11-26 15:01:40 +01:00
|
|
|
|
gpg_encrypt_stream (ctrl_t ctrl,
|
|
|
|
|
const char *gpg_program,
|
|
|
|
|
strlist_t gpg_arguments,
|
2015-11-24 18:31:14 +01:00
|
|
|
|
estream_t plain_stream,
|
|
|
|
|
strlist_t keys,
|
|
|
|
|
estream_t cipher_stream)
|
|
|
|
|
{
|
2015-11-26 15:01:40 +01:00
|
|
|
|
return _gpg_encrypt (ctrl, gpg_program, gpg_arguments,
|
2015-11-24 18:31:14 +01:00
|
|
|
|
NULL, 0, plain_stream,
|
|
|
|
|
keys,
|
|
|
|
|
NULL, cipher_stream);
|
|
|
|
|
}
|
2009-10-13 19:17:24 +00:00
|
|
|
|
|
2011-02-04 12:57:53 +01:00
|
|
|
|
/* Call GPG to decrypt a block of data.
|
2009-10-13 19:17:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/
|
2015-11-24 14:58:31 +01:00
|
|
|
|
static gpg_error_t
|
2015-11-26 15:01:40 +01:00
|
|
|
|
_gpg_decrypt (ctrl_t ctrl,
|
|
|
|
|
const char *gpg_program,
|
|
|
|
|
strlist_t gpg_arguments,
|
2015-11-24 14:58:31 +01:00
|
|
|
|
const void *ciph, size_t ciphlen,
|
2015-11-24 18:31:14 +01:00
|
|
|
|
estream_t cipher_stream,
|
|
|
|
|
membuf_t *reader_mb,
|
|
|
|
|
estream_t plain_stream)
|
2009-10-13 19:17:24 +00:00
|
|
|
|
{
|
|
|
|
|
gpg_error_t err;
|
2014-09-18 16:00:34 +02:00
|
|
|
|
assuan_context_t ctx = NULL;
|
2009-10-13 19:17:24 +00:00
|
|
|
|
int outbound_fds[2] = { -1, -1 };
|
|
|
|
|
int inbound_fds[2] = { -1, -1 };
|
2014-09-18 16:00:34 +02:00
|
|
|
|
npth_t writer_thread = (npth_t)0;
|
|
|
|
|
npth_t reader_thread = (npth_t)0;
|
2009-10-13 19:17:24 +00:00
|
|
|
|
gpg_error_t writer_err, reader_err;
|
Port to npth.
* configure.ac: Don't check for PTH but for NPTH.
(AH_BOTTOM): Remove PTH_SYSCALL_SOFT.
(have_pth): Rename to ...
(have_npth): ... this.
(USE_GNU_NPTH): Rename to ...
(USE_GNU_PTH): ... this.
* m4/npth.m4: New file.
* agent/Makefile.am, agent/cache.c, agent/call-pinentry.c,
agent/call-scd.c, agent/findkey.c, agent/gpg-agent.c,
agent/trustlist.c, common/Makefile.am, common/estream.c,
common/exechelp-posix.c, common/exechelp-w32.c,
common/exechelp-w32ce.c, common/http.c, common/init.c,
common/sysutils.c, dirmngr/Makefile.am, dirmngr/crlfetch.c,
dirmngr/dirmngr.c, dirmngr/dirmngr_ldap.c, dirmngr/ldap-wrapper-ce.c,
dirmngr/ldap-wrapper.c, dirmngr/ldap.c, g13/Makefile.am,
g13/call-gpg.c, g13/g13.c, g13/runner.c, scd/Makefile.am,
scd/apdu.c, scd/app.c, scd/ccid-driver.c, scd/command.c,
scd/scdaemon.c, tools/Makefile.am: Port to npth.
2012-01-03 22:12:37 +01:00
|
|
|
|
int ret;
|
2009-10-13 19:17:24 +00:00
|
|
|
|
|
2015-11-24 18:31:14 +01:00
|
|
|
|
/* Make sure that either the stream interface xor the buffer
|
|
|
|
|
interface is used. */
|
|
|
|
|
assert ((ciph == NULL) != (cipher_stream == NULL));
|
|
|
|
|
assert ((reader_mb == NULL) != (plain_stream == NULL));
|
|
|
|
|
|
2009-10-13 19:17:24 +00:00
|
|
|
|
/* Create two pipes. */
|
|
|
|
|
err = gnupg_create_outbound_pipe (outbound_fds);
|
|
|
|
|
if (!err)
|
|
|
|
|
err = gnupg_create_inbound_pipe (inbound_fds);
|
|
|
|
|
if (err)
|
|
|
|
|
{
|
|
|
|
|
log_error (_("error creating a pipe: %s\n"), gpg_strerror (err));
|
|
|
|
|
goto leave;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Start GPG and send the INPUT and OUTPUT commands. */
|
2015-11-26 15:01:40 +01:00
|
|
|
|
err = start_gpg (ctrl, gpg_program, gpg_arguments,
|
|
|
|
|
outbound_fds[0], inbound_fds[1], &ctx);
|
2009-10-13 19:17:24 +00:00
|
|
|
|
if (err)
|
|
|
|
|
goto leave;
|
|
|
|
|
close (outbound_fds[0]); outbound_fds[0] = -1;
|
|
|
|
|
close (inbound_fds[1]); inbound_fds[1] = -1;
|
2011-02-04 12:57:53 +01:00
|
|
|
|
|
2009-10-13 19:17:24 +00:00
|
|
|
|
/* Start a writer thread to feed the INPUT command of the server. */
|
2015-11-24 18:31:14 +01:00
|
|
|
|
err = start_writer (outbound_fds[1], ciph, ciphlen, cipher_stream,
|
Port to npth.
* configure.ac: Don't check for PTH but for NPTH.
(AH_BOTTOM): Remove PTH_SYSCALL_SOFT.
(have_pth): Rename to ...
(have_npth): ... this.
(USE_GNU_NPTH): Rename to ...
(USE_GNU_PTH): ... this.
* m4/npth.m4: New file.
* agent/Makefile.am, agent/cache.c, agent/call-pinentry.c,
agent/call-scd.c, agent/findkey.c, agent/gpg-agent.c,
agent/trustlist.c, common/Makefile.am, common/estream.c,
common/exechelp-posix.c, common/exechelp-w32.c,
common/exechelp-w32ce.c, common/http.c, common/init.c,
common/sysutils.c, dirmngr/Makefile.am, dirmngr/crlfetch.c,
dirmngr/dirmngr.c, dirmngr/dirmngr_ldap.c, dirmngr/ldap-wrapper-ce.c,
dirmngr/ldap-wrapper.c, dirmngr/ldap.c, g13/Makefile.am,
g13/call-gpg.c, g13/g13.c, g13/runner.c, scd/Makefile.am,
scd/apdu.c, scd/app.c, scd/ccid-driver.c, scd/command.c,
scd/scdaemon.c, tools/Makefile.am: Port to npth.
2012-01-03 22:12:37 +01:00
|
|
|
|
&writer_thread, &writer_err);
|
2009-10-13 19:17:24 +00:00
|
|
|
|
if (err)
|
|
|
|
|
return err;
|
|
|
|
|
outbound_fds[1] = -1; /* The thread owns the FD now. */
|
|
|
|
|
|
|
|
|
|
/* Start a reader thread to eat from the OUTPUT command of the
|
|
|
|
|
server. */
|
2015-11-24 18:31:14 +01:00
|
|
|
|
err = start_reader (inbound_fds[0], reader_mb, plain_stream,
|
Port to npth.
* configure.ac: Don't check for PTH but for NPTH.
(AH_BOTTOM): Remove PTH_SYSCALL_SOFT.
(have_pth): Rename to ...
(have_npth): ... this.
(USE_GNU_NPTH): Rename to ...
(USE_GNU_PTH): ... this.
* m4/npth.m4: New file.
* agent/Makefile.am, agent/cache.c, agent/call-pinentry.c,
agent/call-scd.c, agent/findkey.c, agent/gpg-agent.c,
agent/trustlist.c, common/Makefile.am, common/estream.c,
common/exechelp-posix.c, common/exechelp-w32.c,
common/exechelp-w32ce.c, common/http.c, common/init.c,
common/sysutils.c, dirmngr/Makefile.am, dirmngr/crlfetch.c,
dirmngr/dirmngr.c, dirmngr/dirmngr_ldap.c, dirmngr/ldap-wrapper-ce.c,
dirmngr/ldap-wrapper.c, dirmngr/ldap.c, g13/Makefile.am,
g13/call-gpg.c, g13/g13.c, g13/runner.c, scd/Makefile.am,
scd/apdu.c, scd/app.c, scd/ccid-driver.c, scd/command.c,
scd/scdaemon.c, tools/Makefile.am: Port to npth.
2012-01-03 22:12:37 +01:00
|
|
|
|
&reader_thread, &reader_err);
|
2009-10-13 19:17:24 +00:00
|
|
|
|
if (err)
|
|
|
|
|
return err;
|
|
|
|
|
outbound_fds[0] = -1; /* The thread owns the FD now. */
|
|
|
|
|
|
|
|
|
|
/* Run the decryption. */
|
|
|
|
|
err = assuan_transact (ctx, "DECRYPT", NULL, NULL, NULL, NULL, NULL, NULL);
|
|
|
|
|
if (err)
|
|
|
|
|
{
|
|
|
|
|
log_error ("the engine's DECRYPT command failed: %s <%s>\n",
|
|
|
|
|
gpg_strerror (err), gpg_strsource (err));
|
|
|
|
|
goto leave;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Wait for reader and return the data. */
|
Port to npth.
* configure.ac: Don't check for PTH but for NPTH.
(AH_BOTTOM): Remove PTH_SYSCALL_SOFT.
(have_pth): Rename to ...
(have_npth): ... this.
(USE_GNU_NPTH): Rename to ...
(USE_GNU_PTH): ... this.
* m4/npth.m4: New file.
* agent/Makefile.am, agent/cache.c, agent/call-pinentry.c,
agent/call-scd.c, agent/findkey.c, agent/gpg-agent.c,
agent/trustlist.c, common/Makefile.am, common/estream.c,
common/exechelp-posix.c, common/exechelp-w32.c,
common/exechelp-w32ce.c, common/http.c, common/init.c,
common/sysutils.c, dirmngr/Makefile.am, dirmngr/crlfetch.c,
dirmngr/dirmngr.c, dirmngr/dirmngr_ldap.c, dirmngr/ldap-wrapper-ce.c,
dirmngr/ldap-wrapper.c, dirmngr/ldap.c, g13/Makefile.am,
g13/call-gpg.c, g13/g13.c, g13/runner.c, scd/Makefile.am,
scd/apdu.c, scd/app.c, scd/ccid-driver.c, scd/command.c,
scd/scdaemon.c, tools/Makefile.am: Port to npth.
2012-01-03 22:12:37 +01:00
|
|
|
|
ret = npth_join (reader_thread, NULL);
|
|
|
|
|
if (ret)
|
2009-10-13 19:17:24 +00:00
|
|
|
|
{
|
2015-12-14 19:55:34 +01:00
|
|
|
|
err = my_error_from_errno (ret);
|
2009-10-13 19:17:24 +00:00
|
|
|
|
log_error ("waiting for reader thread failed: %s\n", gpg_strerror (err));
|
|
|
|
|
goto leave;
|
|
|
|
|
}
|
Port to npth.
* configure.ac: Don't check for PTH but for NPTH.
(AH_BOTTOM): Remove PTH_SYSCALL_SOFT.
(have_pth): Rename to ...
(have_npth): ... this.
(USE_GNU_NPTH): Rename to ...
(USE_GNU_PTH): ... this.
* m4/npth.m4: New file.
* agent/Makefile.am, agent/cache.c, agent/call-pinentry.c,
agent/call-scd.c, agent/findkey.c, agent/gpg-agent.c,
agent/trustlist.c, common/Makefile.am, common/estream.c,
common/exechelp-posix.c, common/exechelp-w32.c,
common/exechelp-w32ce.c, common/http.c, common/init.c,
common/sysutils.c, dirmngr/Makefile.am, dirmngr/crlfetch.c,
dirmngr/dirmngr.c, dirmngr/dirmngr_ldap.c, dirmngr/ldap-wrapper-ce.c,
dirmngr/ldap-wrapper.c, dirmngr/ldap.c, g13/Makefile.am,
g13/call-gpg.c, g13/g13.c, g13/runner.c, scd/Makefile.am,
scd/apdu.c, scd/app.c, scd/ccid-driver.c, scd/command.c,
scd/scdaemon.c, tools/Makefile.am: Port to npth.
2012-01-03 22:12:37 +01:00
|
|
|
|
memset (&reader_thread, '\0', sizeof (reader_thread));
|
2009-10-13 19:17:24 +00:00
|
|
|
|
if (reader_err)
|
|
|
|
|
{
|
|
|
|
|
err = reader_err;
|
|
|
|
|
log_error ("read error in reader thread: %s\n", gpg_strerror (err));
|
|
|
|
|
goto leave;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Wait for the writer to catch a writer error. */
|
Port to npth.
* configure.ac: Don't check for PTH but for NPTH.
(AH_BOTTOM): Remove PTH_SYSCALL_SOFT.
(have_pth): Rename to ...
(have_npth): ... this.
(USE_GNU_NPTH): Rename to ...
(USE_GNU_PTH): ... this.
* m4/npth.m4: New file.
* agent/Makefile.am, agent/cache.c, agent/call-pinentry.c,
agent/call-scd.c, agent/findkey.c, agent/gpg-agent.c,
agent/trustlist.c, common/Makefile.am, common/estream.c,
common/exechelp-posix.c, common/exechelp-w32.c,
common/exechelp-w32ce.c, common/http.c, common/init.c,
common/sysutils.c, dirmngr/Makefile.am, dirmngr/crlfetch.c,
dirmngr/dirmngr.c, dirmngr/dirmngr_ldap.c, dirmngr/ldap-wrapper-ce.c,
dirmngr/ldap-wrapper.c, dirmngr/ldap.c, g13/Makefile.am,
g13/call-gpg.c, g13/g13.c, g13/runner.c, scd/Makefile.am,
scd/apdu.c, scd/app.c, scd/ccid-driver.c, scd/command.c,
scd/scdaemon.c, tools/Makefile.am: Port to npth.
2012-01-03 22:12:37 +01:00
|
|
|
|
ret = npth_join (writer_thread, NULL);
|
|
|
|
|
if (ret)
|
2009-10-13 19:17:24 +00:00
|
|
|
|
{
|
2015-12-14 19:55:34 +01:00
|
|
|
|
err = my_error_from_errno (ret);
|
2009-10-13 19:17:24 +00:00
|
|
|
|
log_error ("waiting for writer thread failed: %s\n", gpg_strerror (err));
|
|
|
|
|
goto leave;
|
|
|
|
|
}
|
Port to npth.
* configure.ac: Don't check for PTH but for NPTH.
(AH_BOTTOM): Remove PTH_SYSCALL_SOFT.
(have_pth): Rename to ...
(have_npth): ... this.
(USE_GNU_NPTH): Rename to ...
(USE_GNU_PTH): ... this.
* m4/npth.m4: New file.
* agent/Makefile.am, agent/cache.c, agent/call-pinentry.c,
agent/call-scd.c, agent/findkey.c, agent/gpg-agent.c,
agent/trustlist.c, common/Makefile.am, common/estream.c,
common/exechelp-posix.c, common/exechelp-w32.c,
common/exechelp-w32ce.c, common/http.c, common/init.c,
common/sysutils.c, dirmngr/Makefile.am, dirmngr/crlfetch.c,
dirmngr/dirmngr.c, dirmngr/dirmngr_ldap.c, dirmngr/ldap-wrapper-ce.c,
dirmngr/ldap-wrapper.c, dirmngr/ldap.c, g13/Makefile.am,
g13/call-gpg.c, g13/g13.c, g13/runner.c, scd/Makefile.am,
scd/apdu.c, scd/app.c, scd/ccid-driver.c, scd/command.c,
scd/scdaemon.c, tools/Makefile.am: Port to npth.
2012-01-03 22:12:37 +01:00
|
|
|
|
memset (&writer_thread, '\0', sizeof (writer_thread));
|
2009-10-13 19:17:24 +00:00
|
|
|
|
if (writer_err)
|
|
|
|
|
{
|
|
|
|
|
err = writer_err;
|
|
|
|
|
log_error ("write error in writer thread: %s\n", gpg_strerror (err));
|
|
|
|
|
goto leave;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
leave:
|
Port to npth.
* configure.ac: Don't check for PTH but for NPTH.
(AH_BOTTOM): Remove PTH_SYSCALL_SOFT.
(have_pth): Rename to ...
(have_npth): ... this.
(USE_GNU_NPTH): Rename to ...
(USE_GNU_PTH): ... this.
* m4/npth.m4: New file.
* agent/Makefile.am, agent/cache.c, agent/call-pinentry.c,
agent/call-scd.c, agent/findkey.c, agent/gpg-agent.c,
agent/trustlist.c, common/Makefile.am, common/estream.c,
common/exechelp-posix.c, common/exechelp-w32.c,
common/exechelp-w32ce.c, common/http.c, common/init.c,
common/sysutils.c, dirmngr/Makefile.am, dirmngr/crlfetch.c,
dirmngr/dirmngr.c, dirmngr/dirmngr_ldap.c, dirmngr/ldap-wrapper-ce.c,
dirmngr/ldap-wrapper.c, dirmngr/ldap.c, g13/Makefile.am,
g13/call-gpg.c, g13/g13.c, g13/runner.c, scd/Makefile.am,
scd/apdu.c, scd/app.c, scd/ccid-driver.c, scd/command.c,
scd/scdaemon.c, tools/Makefile.am: Port to npth.
2012-01-03 22:12:37 +01:00
|
|
|
|
if (reader_thread)
|
|
|
|
|
npth_detach (reader_thread);
|
|
|
|
|
if (writer_thread)
|
|
|
|
|
npth_detach (writer_thread);
|
2009-10-13 19:17:24 +00:00
|
|
|
|
if (outbound_fds[0] != -1)
|
|
|
|
|
close (outbound_fds[0]);
|
|
|
|
|
if (outbound_fds[1] != -1)
|
|
|
|
|
close (outbound_fds[1]);
|
|
|
|
|
if (inbound_fds[0] != -1)
|
|
|
|
|
close (inbound_fds[0]);
|
|
|
|
|
if (inbound_fds[1] != -1)
|
|
|
|
|
close (inbound_fds[1]);
|
|
|
|
|
release_gpg (ctx);
|
2015-11-24 14:58:31 +01:00
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gpg_error_t
|
2015-11-26 15:01:40 +01:00
|
|
|
|
gpg_decrypt_blob (ctrl_t ctrl,
|
|
|
|
|
const char *gpg_program,
|
|
|
|
|
strlist_t gpg_arguments,
|
2015-11-24 14:58:31 +01:00
|
|
|
|
const void *ciph, size_t ciphlen,
|
|
|
|
|
void **r_plain, size_t *r_plainlen)
|
|
|
|
|
{
|
|
|
|
|
gpg_error_t err;
|
|
|
|
|
membuf_t reader_mb;
|
|
|
|
|
|
|
|
|
|
*r_plain = NULL;
|
|
|
|
|
*r_plainlen = 0;
|
|
|
|
|
|
|
|
|
|
/* Init the memory buffer to receive the encrypted stuff. */
|
|
|
|
|
init_membuf_secure (&reader_mb, 1024);
|
|
|
|
|
|
2015-11-26 15:01:40 +01:00
|
|
|
|
err = _gpg_decrypt (ctrl, gpg_program, gpg_arguments,
|
2015-11-24 18:31:14 +01:00
|
|
|
|
ciph, ciphlen, NULL,
|
|
|
|
|
&reader_mb, NULL);
|
2015-11-24 14:58:31 +01:00
|
|
|
|
|
|
|
|
|
if (! err)
|
|
|
|
|
{
|
|
|
|
|
/* Return the data. */
|
|
|
|
|
*r_plain = get_membuf (&reader_mb, r_plainlen);
|
|
|
|
|
if (!*r_plain)
|
|
|
|
|
{
|
2015-12-14 19:55:34 +01:00
|
|
|
|
err = my_error_from_syserror ();
|
2015-11-24 14:58:31 +01:00
|
|
|
|
log_error ("error while storing the data in the reader thread: %s\n",
|
|
|
|
|
gpg_strerror (err));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-13 19:17:24 +00:00
|
|
|
|
xfree (get_membuf (&reader_mb, NULL));
|
|
|
|
|
return err;
|
|
|
|
|
}
|
2015-11-24 18:31:14 +01:00
|
|
|
|
|
|
|
|
|
gpg_error_t
|
2015-11-26 15:01:40 +01:00
|
|
|
|
gpg_decrypt_stream (ctrl_t ctrl,
|
|
|
|
|
const char *gpg_program,
|
|
|
|
|
strlist_t gpg_arguments,
|
2015-11-24 18:31:14 +01:00
|
|
|
|
estream_t cipher_stream,
|
|
|
|
|
estream_t plain_stream)
|
|
|
|
|
{
|
2015-11-26 15:01:40 +01:00
|
|
|
|
return _gpg_decrypt (ctrl, gpg_program, gpg_arguments,
|
2015-11-24 18:31:14 +01:00
|
|
|
|
NULL, 0, cipher_stream,
|
|
|
|
|
NULL, plain_stream);
|
|
|
|
|
}
|