mirror of
git://git.gnupg.org/gnupg.git
synced 2025-07-02 22:46:30 +02:00
Some changes to suport g13.
This commit is contained in:
parent
c11c23b6ac
commit
27c1b4bef8
37 changed files with 2069 additions and 324 deletions
|
@ -1,3 +1,15 @@
|
|||
2009-09-29 Werner Koch <wk@g10code.com>
|
||||
|
||||
* exechelp.c (create_inheritable_pipe): Rename to
|
||||
create_inheritable_pipe_w.
|
||||
(create_inheritable_pipe_r): New.
|
||||
(gnupg_create_outbound_pipe): New.
|
||||
|
||||
* iobuf.h: Include "sysutils.h"
|
||||
|
||||
* iobuf.c (iobuf_open_fd_or_name): New.
|
||||
(iobuf_get_fname_nonnull): New.
|
||||
|
||||
2009-09-23 Marcus Brinkmann <marcus@g10code.de>
|
||||
|
||||
* asshelp.c (start_new_gpg_agent): Allocate assuan context before
|
||||
|
|
|
@ -62,6 +62,15 @@ typedef enum
|
|||
operations the Dirmngr is not required and thus no such event
|
||||
will be logged. */
|
||||
|
||||
AUDIT_GPG_READY, /* err */
|
||||
/* Indicates whether the Gpg engine is available. */
|
||||
|
||||
AUDIT_GPGSM_READY, /* err */
|
||||
/* Indicates whether the Gpgsm engine is available. */
|
||||
|
||||
AUDIT_G13_READY, /* err */
|
||||
/* Indicates whether the G13 engine is available. */
|
||||
|
||||
AUDIT_GOT_DATA,
|
||||
/* Data to be processed has been seen. */
|
||||
|
||||
|
|
|
@ -304,7 +304,7 @@ build_w32_commandline (const char *pgmname, const char * const *argv,
|
|||
#ifdef HAVE_W32_SYSTEM
|
||||
/* Create pipe where the write end is inheritable. */
|
||||
static int
|
||||
create_inheritable_pipe (int filedes[2])
|
||||
create_inheritable_pipe_w (int filedes[2])
|
||||
{
|
||||
HANDLE r, w, h;
|
||||
SECURITY_ATTRIBUTES sec_attr;
|
||||
|
@ -332,6 +332,37 @@ create_inheritable_pipe (int filedes[2])
|
|||
filedes[1] = handle_to_fd (w);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Create pipe where the read end is inheritable. */
|
||||
static int
|
||||
create_inheritable_pipe_r (int filedes[2])
|
||||
{
|
||||
HANDLE r, w, h;
|
||||
SECURITY_ATTRIBUTES sec_attr;
|
||||
|
||||
memset (&sec_attr, 0, sizeof sec_attr );
|
||||
sec_attr.nLength = sizeof sec_attr;
|
||||
sec_attr.bInheritHandle = FALSE;
|
||||
|
||||
if (!CreatePipe (&r, &w, &sec_attr, 0))
|
||||
return -1;
|
||||
|
||||
if (!DuplicateHandle (GetCurrentProcess(), r,
|
||||
GetCurrentProcess(), &h, 0,
|
||||
TRUE, DUPLICATE_SAME_ACCESS ))
|
||||
{
|
||||
log_error ("DuplicateHandle failed: %s\n", w32_strerror (-1));
|
||||
CloseHandle (r);
|
||||
CloseHandle (w);
|
||||
return -1;
|
||||
}
|
||||
CloseHandle (r);
|
||||
r = h;
|
||||
|
||||
filedes[0] = handle_to_fd (r);
|
||||
filedes[1] = handle_to_fd (w);
|
||||
return 0;
|
||||
}
|
||||
#endif /*HAVE_W32_SYSTEM*/
|
||||
|
||||
|
||||
|
@ -425,7 +456,51 @@ gnupg_create_inbound_pipe (int filedes[2])
|
|||
|
||||
filedes[0] = filedes[1] = -1;
|
||||
err = gpg_error (GPG_ERR_GENERAL);
|
||||
if (!create_inheritable_pipe (fds))
|
||||
if (!create_inheritable_pipe_w (fds))
|
||||
{
|
||||
filedes[0] = _open_osfhandle (fds[0], 0);
|
||||
if (filedes[0] == -1)
|
||||
{
|
||||
log_error ("failed to translate osfhandle %p\n", (void*)fds[0]);
|
||||
CloseHandle (fd_to_handle (fds[1]));
|
||||
}
|
||||
else
|
||||
{
|
||||
filedes[1] = _open_osfhandle (fds[1], 1);
|
||||
if (filedes[1] == -1)
|
||||
{
|
||||
log_error ("failed to translate osfhandle %p\n", (void*)fds[1]);
|
||||
close (filedes[0]);
|
||||
filedes[0] = -1;
|
||||
CloseHandle (fd_to_handle (fds[1]));
|
||||
}
|
||||
else
|
||||
err = 0;
|
||||
}
|
||||
}
|
||||
#else
|
||||
if (pipe (filedes) == -1)
|
||||
{
|
||||
err = gpg_error_from_syserror ();
|
||||
filedes[0] = filedes[1] = -1;
|
||||
}
|
||||
#endif
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
/* Portable function to create a pipe. Under Windows the read end is
|
||||
inheritable. */
|
||||
gpg_error_t
|
||||
gnupg_create_outbound_pipe (int filedes[2])
|
||||
{
|
||||
gpg_error_t err = 0;
|
||||
#if HAVE_W32_SYSTEM
|
||||
int fds[2];
|
||||
|
||||
filedes[0] = filedes[1] = -1;
|
||||
err = gpg_error (GPG_ERR_GENERAL);
|
||||
if (!create_inheritable_pipe_r (fds))
|
||||
{
|
||||
filedes[0] = _open_osfhandle (fds[0], 0);
|
||||
if (filedes[0] == -1)
|
||||
|
@ -522,7 +597,7 @@ gnupg_spawn_process (const char *pgmname, const char *argv[],
|
|||
return err;
|
||||
|
||||
/* Create a pipe. */
|
||||
if (create_inheritable_pipe (rp))
|
||||
if (create_inheritable_pipe_w (rp))
|
||||
{
|
||||
err = gpg_error (GPG_ERR_GENERAL);
|
||||
log_error (_("error creating a pipe: %s\n"), gpg_strerror (err));
|
||||
|
|
|
@ -44,6 +44,10 @@ int *get_all_open_fds (void);
|
|||
inheritable. */
|
||||
gpg_error_t gnupg_create_inbound_pipe (int filedes[2]);
|
||||
|
||||
/* Portable function to create a pipe. Under Windows the read end is
|
||||
inheritable. */
|
||||
gpg_error_t gnupg_create_outbound_pipe (int filedes[2]);
|
||||
|
||||
|
||||
/* Fork and exec the PGMNAME, connect the file descriptor of INFILE to
|
||||
stdin, write the output to OUTFILE, return a new stream in
|
||||
|
|
|
@ -1260,6 +1260,32 @@ iobuf_is_pipe_filename (const char *fname)
|
|||
return check_special_filename (fname) != -1;
|
||||
}
|
||||
|
||||
|
||||
/* Either open the file specified by the file descriptor FD or - if FD
|
||||
is GNUPG_INVALID_FD - the file with name FNAME. As of now MODE is
|
||||
assumed to be "rb" if FNAME is used. In contrast to iobuf_fdopen
|
||||
the fiel descriptor FD will not be closed during an iobuf_close. */
|
||||
iobuf_t
|
||||
iobuf_open_fd_or_name (gnupg_fd_t fd, const char *fname, const char *mode)
|
||||
{
|
||||
iobuf_t a;
|
||||
|
||||
if (fd == GNUPG_INVALID_FD)
|
||||
a = iobuf_open (fname);
|
||||
else
|
||||
{
|
||||
gnupg_fd_t fd2;
|
||||
|
||||
fd2 = dup (fd);
|
||||
if (fd2 == GNUPG_INVALID_FD)
|
||||
a = NULL;
|
||||
else
|
||||
a = iobuf_fdopen (fd2, mode);
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
|
||||
/****************
|
||||
* Create a head iobuf for reading from a file
|
||||
* returns: NULL if an error occures and sets errno
|
||||
|
@ -1306,8 +1332,8 @@ iobuf_open (const char *fname)
|
|||
}
|
||||
|
||||
/****************
|
||||
* Create a head iobuf for reading from a file
|
||||
* returns: NULL if an error occures and sets errno
|
||||
* Create a head iobuf for reading or writing from/to a file
|
||||
* Returns: NULL if an error occures and sets ERRNO.
|
||||
*/
|
||||
iobuf_t
|
||||
iobuf_fdopen (int fd, const char *mode)
|
||||
|
@ -2355,7 +2381,9 @@ iobuf_seek (iobuf_t a, off_t newpos)
|
|||
|
||||
|
||||
/****************
|
||||
* Retrieve the real filename
|
||||
* Retrieve the real filename. This is the filename actually used on
|
||||
* disk and not a made up one. Returns NULL if no real filename is
|
||||
* available.
|
||||
*/
|
||||
const char *
|
||||
iobuf_get_real_fname (iobuf_t a)
|
||||
|
@ -2376,7 +2404,7 @@ iobuf_get_real_fname (iobuf_t a)
|
|||
|
||||
|
||||
/****************
|
||||
* Retrieve the filename
|
||||
* Retrieve the filename. This name should only be used in diagnostics.
|
||||
*/
|
||||
const char *
|
||||
iobuf_get_fname (iobuf_t a)
|
||||
|
@ -2390,6 +2418,16 @@ iobuf_get_fname (iobuf_t a)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
/* Same as iobuf_get_fname but never returns NULL. */
|
||||
const char *
|
||||
iobuf_get_fname_nonnull (iobuf_t a)
|
||||
{
|
||||
const char *fname;
|
||||
|
||||
fname = iobuf_get_fname (a);
|
||||
return fname? fname : "[?]";
|
||||
}
|
||||
|
||||
|
||||
/****************
|
||||
* enable partial block mode as described in the OpenPGP draft.
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
#define GNUPG_COMMON_IOBUF_H
|
||||
|
||||
#include "../include/types.h" /* fixme: should be moved elsewhere. */
|
||||
|
||||
#include "../common/sysutils.h"
|
||||
|
||||
#define DBG_IOBUF iobuf_debug_mode
|
||||
|
||||
|
@ -85,6 +85,8 @@ int iobuf_is_pipe_filename (const char *fname);
|
|||
iobuf_t iobuf_alloc (int use, size_t bufsize);
|
||||
iobuf_t iobuf_temp (void);
|
||||
iobuf_t iobuf_temp_with_content (const char *buffer, size_t length);
|
||||
iobuf_t iobuf_open_fd_or_name (gnupg_fd_t fd, const char *fname,
|
||||
const char *mode);
|
||||
iobuf_t iobuf_open (const char *fname);
|
||||
iobuf_t iobuf_fdopen (int fd, const char *mode);
|
||||
iobuf_t iobuf_sockopen (int fd, const char *mode);
|
||||
|
@ -131,6 +133,7 @@ off_t iobuf_get_filelength (iobuf_t a, int *overflow);
|
|||
int iobuf_get_fd (iobuf_t a);
|
||||
const char *iobuf_get_real_fname (iobuf_t a);
|
||||
const char *iobuf_get_fname (iobuf_t a);
|
||||
const char *iobuf_get_fname_nonnull (iobuf_t a);
|
||||
|
||||
void iobuf_set_partial_block_mode (iobuf_t a, size_t len);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue