|
Packit |
fc043f |
/* gpgrt-int.h - Internal definitions
|
|
Packit |
fc043f |
* Copyright (C) 2014, 2017 g10 Code GmbH
|
|
Packit |
fc043f |
*
|
|
Packit |
fc043f |
* This file is part of libgpg-error.
|
|
Packit |
fc043f |
*
|
|
Packit |
fc043f |
* libgpg-error is free software; you can redistribute it and/or
|
|
Packit |
fc043f |
* modify it under the terms of the GNU Lesser General Public License
|
|
Packit |
fc043f |
* as published by the Free Software Foundation; either version 2.1 of
|
|
Packit |
fc043f |
* the License, or (at your option) any later version.
|
|
Packit |
fc043f |
*
|
|
Packit |
fc043f |
* libgpg-error is distributed in the hope that it will be useful, but
|
|
Packit |
fc043f |
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
fc043f |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
fc043f |
* Lesser General Public License for more details.
|
|
Packit |
fc043f |
*
|
|
Packit |
fc043f |
* You should have received a copy of the GNU Lesser General Public
|
|
Packit |
fc043f |
* License along with this program; if not, see <https://www.gnu.org/licenses/>.
|
|
Packit |
fc043f |
* SPDX-License-Identifier: LGPL-2.1+
|
|
Packit |
fc043f |
*/
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
#ifndef _GPGRT_GPGRT_INT_H
|
|
Packit |
fc043f |
#define _GPGRT_GPGRT_INT_H
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
#include "gpg-error.h"
|
|
Packit |
fc043f |
#include "visibility.h"
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
/*
|
|
Packit |
fc043f |
* Internal i18n macros.
|
|
Packit |
fc043f |
*/
|
|
Packit |
fc043f |
#ifdef ENABLE_NLS
|
|
Packit |
fc043f |
# ifdef HAVE_W32_SYSTEM
|
|
Packit |
fc043f |
# include "gettext.h"
|
|
Packit |
fc043f |
# else
|
|
Packit |
fc043f |
# include <libintl.h>
|
|
Packit |
fc043f |
# endif
|
|
Packit |
fc043f |
# define _(a) gettext (a)
|
|
Packit |
fc043f |
# ifdef gettext_noop
|
|
Packit |
fc043f |
# define N_(a) gettext_noop (a)
|
|
Packit |
fc043f |
# else
|
|
Packit |
fc043f |
# define N_(a) (a)
|
|
Packit |
fc043f |
# endif
|
|
Packit |
fc043f |
#else /*!ENABLE_NLS*/
|
|
Packit |
fc043f |
# define _(a) (a)
|
|
Packit |
fc043f |
# define N_(a) (a)
|
|
Packit |
fc043f |
#endif /*!ENABLE_NLS */
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
/*
|
|
Packit |
fc043f |
* Hacks mainly required for Slowaris.
|
|
Packit |
fc043f |
*/
|
|
Packit |
fc043f |
#ifdef _GPGRT_NEED_AFLOCAL
|
|
Packit |
fc043f |
# ifndef HAVE_W32_SYSTEM
|
|
Packit |
fc043f |
# include <sys/socket.h>
|
|
Packit |
fc043f |
# include <sys/un.h>
|
|
Packit |
fc043f |
# else
|
|
Packit |
fc043f |
# ifdef HAVE_WINSOCK2_H
|
|
Packit |
fc043f |
# include <winsock2.h>
|
|
Packit |
fc043f |
# endif
|
|
Packit |
fc043f |
# include <windows.h>
|
|
Packit |
fc043f |
# endif
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
# ifndef PF_LOCAL
|
|
Packit |
fc043f |
# ifdef PF_UNIX
|
|
Packit |
fc043f |
# define PF_LOCAL PF_UNIX
|
|
Packit |
fc043f |
# else
|
|
Packit |
fc043f |
# define PF_LOCAL AF_UNIX
|
|
Packit |
fc043f |
# endif
|
|
Packit |
fc043f |
# endif /*PF_LOCAL*/
|
|
Packit |
fc043f |
# ifndef AF_LOCAL
|
|
Packit |
fc043f |
# define AF_LOCAL AF_UNIX
|
|
Packit |
fc043f |
# endif /*AF_UNIX*/
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
/* We used to avoid this macro in GnuPG and inlined the AF_LOCAL name
|
|
Packit |
fc043f |
* length computation directly with the little twist of adding 1 extra
|
|
Packit |
fc043f |
* byte. It seems that this was needed once on an old HP/UX box and
|
|
Packit |
fc043f |
* there are also rumours that 4.3 Reno and DEC systems need it. This
|
|
Packit |
fc043f |
* one-off buglet did not harm any current system until it came to Mac
|
|
Packit |
fc043f |
* OS X where the kernel (as of May 2009) exhibited a strange bug: The
|
|
Packit |
fc043f |
* systems basically froze in the connect call if the passed name
|
|
Packit |
fc043f |
* contained an invalid directory part. Ignore the old Unices. */
|
|
Packit |
fc043f |
# ifndef SUN_LEN
|
|
Packit |
fc043f |
# define SUN_LEN(ptr) ((size_t) (((struct sockaddr_un *) 0)->sun_path) \
|
|
Packit |
fc043f |
+ strlen ((ptr)->sun_path))
|
|
Packit |
fc043f |
# endif /*SUN_LEN*/
|
|
Packit |
fc043f |
#endif /*_GPGRT_NEED_AFLOCAL*/
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
/*
|
|
Packit |
fc043f |
* Common helper macros.
|
|
Packit |
fc043f |
*/
|
|
Packit |
fc043f |
#ifndef DIM
|
|
Packit |
fc043f |
# define DIM(array) (sizeof (array) / sizeof (*array))
|
|
Packit |
fc043f |
#endif
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
/*
|
|
Packit |
fc043f |
* Local error function prototypes.
|
|
Packit |
fc043f |
*/
|
|
Packit |
fc043f |
const char *_gpg_strerror (gpg_error_t err);
|
|
Packit |
fc043f |
int _gpg_strerror_r (gpg_error_t err, char *buf, size_t buflen);
|
|
Packit |
fc043f |
const char *_gpg_strsource (gpg_error_t err);
|
|
Packit |
fc043f |
gpg_err_code_t _gpg_err_code_from_errno (int err);
|
|
Packit |
fc043f |
int _gpg_err_code_to_errno (gpg_err_code_t code);
|
|
Packit |
fc043f |
gpg_err_code_t _gpg_err_code_from_syserror (void);
|
|
Packit |
fc043f |
void _gpg_err_set_errno (int err);
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
gpg_error_t _gpg_err_init (void);
|
|
Packit |
fc043f |
void _gpg_err_deinit (int mode);
|
|
Packit |
fc043f |
void _gpgrt_set_alloc_func (void *(*f)(void *a, size_t n));
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
void *_gpgrt_realloc (void *a, size_t n);
|
|
Packit |
fc043f |
void *_gpgrt_malloc (size_t n);
|
|
Packit |
fc043f |
void *_gpgrt_calloc (size_t n, size_t m);
|
|
Packit |
fc043f |
char *_gpgrt_strdup (const char *string);
|
|
Packit |
fc043f |
char *_gpgrt_strconcat (const char *s1, ...) GPGRT_ATTR_SENTINEL(0);
|
|
Packit |
fc043f |
void _gpgrt_free (void *a);
|
|
Packit |
fc043f |
/* The next is only to be used by visibility.c. */
|
|
Packit |
fc043f |
char *_gpgrt_strconcat_core (const char *s1, va_list arg_ptr);
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
#define xfree(a) _gpgrt_free ((a))
|
|
Packit |
fc043f |
#define xtrymalloc(a) _gpgrt_malloc ((a))
|
|
Packit |
fc043f |
#define xtrycalloc(a,b) _gpgrt_calloc ((a),(b))
|
|
Packit |
fc043f |
#define xtryrealloc(a,b) _gpgrt_realloc ((a),(b))
|
|
Packit |
fc043f |
#define xtrystrdup(a) _gpgrt_strdup ((a))
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
void _gpgrt_pre_syscall (void);
|
|
Packit |
fc043f |
void _gpgrt_post_syscall (void);
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
const char *_gpg_error_check_version (const char *req_version);
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
gpg_err_code_t _gpgrt_lock_init (gpgrt_lock_t *lockhd);
|
|
Packit |
fc043f |
gpg_err_code_t _gpgrt_lock_lock (gpgrt_lock_t *lockhd);
|
|
Packit |
fc043f |
gpg_err_code_t _gpgrt_lock_trylock (gpgrt_lock_t *lockhd);
|
|
Packit |
fc043f |
gpg_err_code_t _gpgrt_lock_unlock (gpgrt_lock_t *lockhd);
|
|
Packit |
fc043f |
gpg_err_code_t _gpgrt_lock_destroy (gpgrt_lock_t *lockhd);
|
|
Packit |
fc043f |
gpg_err_code_t _gpgrt_yield (void);
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
/*
|
|
Packit |
fc043f |
* Tracing
|
|
Packit |
fc043f |
*/
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
/* The trace macro is used this way:
|
|
Packit |
fc043f |
* trace (("enter - foo=%d bar=%s", foo, bar));
|
|
Packit |
fc043f |
* Note the double parenthesis, they are important.
|
|
Packit |
fc043f |
* To append the current errno to the output, use
|
|
Packit |
fc043f |
* trace_errno (EXTPR,("leave - baz=%d", faz));
|
|
Packit |
fc043f |
* If EXPR evaluates to true the output of strerror (errno)
|
|
Packit |
fc043f |
* is appended to the output. Note that the trace function does
|
|
Packit |
fc043f |
* not modify ERRNO. To enable tracing you need to have this
|
|
Packit |
fc043f |
* #define ENABLE_TRACING "modulename"
|
|
Packit |
fc043f |
* before you include gpgrt-int.h.
|
|
Packit |
fc043f |
*/
|
|
Packit |
fc043f |
#ifdef ENABLE_TRACING
|
|
Packit |
fc043f |
# define trace(X) do { \
|
|
Packit |
fc043f |
_gpgrt_internal_trace_begin \
|
|
Packit |
fc043f |
(ENABLE_TRACING, __func__, __LINE__, 0); \
|
|
Packit |
fc043f |
_gpgrt_internal_trace X; \
|
|
Packit |
fc043f |
_gpgrt_internal_trace_end (); \
|
|
Packit |
fc043f |
} while (0)
|
|
Packit |
fc043f |
# define trace_errno(C,X) do { \
|
|
Packit |
fc043f |
_gpgrt_internal_trace_begin \
|
|
Packit |
fc043f |
(ENABLE_TRACING, __func__, __LINE__, (C)); \
|
|
Packit |
fc043f |
_gpgrt_internal_trace X; \
|
|
Packit |
fc043f |
_gpgrt_internal_trace_end (); \
|
|
Packit |
fc043f |
} while (0)
|
|
Packit |
fc043f |
# define trace_start(X) do { \
|
|
Packit |
fc043f |
_gpgrt_internal_trace_begin \
|
|
Packit |
fc043f |
(ENABLE_TRACING, __func__, __LINE__, 0); \
|
|
Packit |
fc043f |
_gpgrt_internal_trace_printf X; \
|
|
Packit |
fc043f |
} while (0)
|
|
Packit |
fc043f |
# define trace_append(X) do { \
|
|
Packit |
fc043f |
_gpgrt_internal_trace_printf X; \
|
|
Packit |
fc043f |
} while (0)
|
|
Packit |
fc043f |
# define trace_finish(X) do { \
|
|
Packit |
fc043f |
_gpgrt_internal_trace_printf X; \
|
|
Packit |
fc043f |
_gpgrt_internal_trace_end (); \
|
|
Packit |
fc043f |
} while (0)
|
|
Packit |
fc043f |
#else
|
|
Packit |
fc043f |
# define trace(X) do { } while (0)
|
|
Packit |
fc043f |
# define trace_errno(C,X) do { } while (0)
|
|
Packit |
fc043f |
# define trace_start(X) do { } while (0)
|
|
Packit |
fc043f |
# define trace_append(X) do { } while (0)
|
|
Packit |
fc043f |
# define trace_finish(X) do { } while (0)
|
|
Packit |
fc043f |
#endif /*!ENABLE_TRACING*/
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
void _gpgrt_internal_trace_begin (const char *mod, const char *file, int line,
|
|
Packit |
fc043f |
int with_errno);
|
|
Packit |
fc043f |
void _gpgrt_internal_trace (const char *format,
|
|
Packit |
fc043f |
...) GPGRT_ATTR_PRINTF(1,2);
|
|
Packit |
fc043f |
void _gpgrt_internal_trace_printf (const char *format,
|
|
Packit |
fc043f |
...) GPGRT_ATTR_PRINTF(1,2);
|
|
Packit |
fc043f |
void _gpgrt_internal_trace_end (void);
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
/*
|
|
Packit |
fc043f |
* Local definitions for estream.
|
|
Packit |
fc043f |
*/
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
#if HAVE_W32_SYSTEM
|
|
Packit |
fc043f |
# ifndef O_NONBLOCK
|
|
Packit |
fc043f |
# define O_NONBLOCK 0x40000000 /* FIXME: Is that safe? */
|
|
Packit |
fc043f |
# endif
|
|
Packit |
fc043f |
#endif
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
/*
|
|
Packit |
fc043f |
* A private cookie function to implement an internal IOCTL service.
|
|
Packit |
fc043f |
* and ist IOCTL numbers.
|
|
Packit |
fc043f |
*/
|
|
Packit |
fc043f |
typedef int (*cookie_ioctl_function_t) (void *cookie, int cmd,
|
|
Packit |
fc043f |
void *ptr, size_t *len);
|
|
Packit |
fc043f |
#define COOKIE_IOCTL_SNATCH_BUFFER 1
|
|
Packit |
fc043f |
#define COOKIE_IOCTL_NONBLOCK 2
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
/* An internal variant of gpgrt_cookie_close_function_t with a slot
|
|
Packit |
fc043f |
* for the ioctl function. */
|
|
Packit |
fc043f |
struct cookie_io_functions_s
|
|
Packit |
fc043f |
{
|
|
Packit |
fc043f |
struct _gpgrt_cookie_io_functions public;
|
|
Packit |
fc043f |
cookie_ioctl_function_t func_ioctl;
|
|
Packit |
fc043f |
};
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
typedef enum
|
|
Packit |
fc043f |
{
|
|
Packit |
fc043f |
BACKEND_MEM,
|
|
Packit |
fc043f |
BACKEND_FD,
|
|
Packit |
fc043f |
BACKEND_W32,
|
|
Packit |
fc043f |
BACKEND_FP,
|
|
Packit |
fc043f |
BACKEND_USER,
|
|
Packit |
fc043f |
BACKEND_W32_POLLABLE
|
|
Packit |
fc043f |
} gpgrt_stream_backend_kind_t;
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
/*
|
|
Packit |
fc043f |
* A type to hold notification functions.
|
|
Packit |
fc043f |
*/
|
|
Packit |
fc043f |
struct notify_list_s
|
|
Packit |
fc043f |
{
|
|
Packit |
fc043f |
struct notify_list_s *next;
|
|
Packit |
fc043f |
void (*fnc) (estream_t, void*); /* The notification function. */
|
|
Packit |
fc043f |
void *fnc_value; /* The value to be passed to FNC. */
|
|
Packit |
fc043f |
};
|
|
Packit |
fc043f |
typedef struct notify_list_s *notify_list_t;
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
/*
|
|
Packit |
fc043f |
* Buffer management layer.
|
|
Packit |
fc043f |
*/
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
#define BUFFER_BLOCK_SIZE BUFSIZ
|
|
Packit |
fc043f |
#define BUFFER_UNREAD_SIZE 16
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
/*
|
|
Packit |
fc043f |
* The private object describing a stream.
|
|
Packit |
fc043f |
*/
|
|
Packit |
fc043f |
struct _gpgrt_stream_internal
|
|
Packit |
fc043f |
{
|
|
Packit |
fc043f |
unsigned char buffer[BUFFER_BLOCK_SIZE];
|
|
Packit |
fc043f |
unsigned char unread_buffer[BUFFER_UNREAD_SIZE];
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
gpgrt_lock_t lock; /* Lock. Used by *_stream_lock(). */
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
gpgrt_stream_backend_kind_t kind;
|
|
Packit |
fc043f |
void *cookie; /* Cookie. */
|
|
Packit |
fc043f |
void *opaque; /* Opaque data. */
|
|
Packit |
fc043f |
unsigned int modeflags; /* Flags for the backend. */
|
|
Packit |
fc043f |
char *printable_fname; /* Malloced filename for es_fname_get. */
|
|
Packit |
fc043f |
gpgrt_off_t offset;
|
|
Packit |
fc043f |
gpgrt_cookie_read_function_t func_read;
|
|
Packit |
fc043f |
gpgrt_cookie_write_function_t func_write;
|
|
Packit |
fc043f |
gpgrt_cookie_seek_function_t func_seek;
|
|
Packit |
fc043f |
gpgrt_cookie_close_function_t func_close;
|
|
Packit |
fc043f |
cookie_ioctl_function_t func_ioctl;
|
|
Packit |
fc043f |
int strategy;
|
|
Packit |
fc043f |
es_syshd_t syshd; /* A copy of the system handle. */
|
|
Packit |
fc043f |
struct
|
|
Packit |
fc043f |
{
|
|
Packit |
fc043f |
unsigned int err: 1;
|
|
Packit |
fc043f |
unsigned int eof: 1;
|
|
Packit |
fc043f |
unsigned int hup: 1;
|
|
Packit |
fc043f |
} indicators;
|
|
Packit |
fc043f |
unsigned int deallocate_buffer: 1;
|
|
Packit |
fc043f |
unsigned int is_stdstream:1; /* This is a standard stream. */
|
|
Packit |
fc043f |
unsigned int stdstream_fd:2; /* 0, 1 or 2 for a standard stream. */
|
|
Packit |
fc043f |
unsigned int printable_fname_inuse: 1; /* es_fname_get has been used. */
|
|
Packit |
fc043f |
unsigned int samethread: 1; /* The "samethread" mode keyword. */
|
|
Packit |
fc043f |
size_t print_ntotal; /* Bytes written from in print_writer. */
|
|
Packit |
fc043f |
notify_list_t onclose; /* On close notify function list. */
|
|
Packit |
fc043f |
};
|
|
Packit |
fc043f |
typedef struct _gpgrt_stream_internal *estream_internal_t;
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
/*
|
|
Packit |
fc043f |
* Local prototypes for estream.
|
|
Packit |
fc043f |
*/
|
|
Packit |
fc043f |
int _gpgrt_estream_init (void);
|
|
Packit |
fc043f |
void _gpgrt_set_syscall_clamp (void (*pre)(void), void (*post)(void));
|
|
Packit |
fc043f |
void _gpgrt_get_syscall_clamp (void (**r_pre)(void), void (**r_post)(void));
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
gpgrt_stream_t _gpgrt_fopen (const char *_GPGRT__RESTRICT path,
|
|
Packit |
fc043f |
const char *_GPGRT__RESTRICT mode);
|
|
Packit |
fc043f |
gpgrt_stream_t _gpgrt_mopen (void *_GPGRT__RESTRICT data,
|
|
Packit |
fc043f |
size_t data_n, size_t data_len,
|
|
Packit |
fc043f |
unsigned int grow,
|
|
Packit |
fc043f |
void *(*func_realloc) (void *mem, size_t size),
|
|
Packit |
fc043f |
void (*func_free) (void *mem),
|
|
Packit |
fc043f |
const char *_GPGRT__RESTRICT mode);
|
|
Packit |
fc043f |
gpgrt_stream_t _gpgrt_fopenmem (size_t memlimit,
|
|
Packit |
fc043f |
const char *_GPGRT__RESTRICT mode);
|
|
Packit |
fc043f |
gpgrt_stream_t _gpgrt_fopenmem_init (size_t memlimit,
|
|
Packit |
fc043f |
const char *_GPGRT__RESTRICT mode,
|
|
Packit |
fc043f |
const void *data, size_t datalen);
|
|
Packit |
fc043f |
gpgrt_stream_t _gpgrt_fdopen (int filedes, const char *mode);
|
|
Packit |
fc043f |
gpgrt_stream_t _gpgrt_fdopen_nc (int filedes, const char *mode);
|
|
Packit |
fc043f |
gpgrt_stream_t _gpgrt_sysopen (gpgrt_syshd_t *syshd, const char *mode);
|
|
Packit |
fc043f |
gpgrt_stream_t _gpgrt_sysopen_nc (gpgrt_syshd_t *syshd, const char *mode);
|
|
Packit |
fc043f |
gpgrt_stream_t _gpgrt_fpopen (FILE *fp, const char *mode);
|
|
Packit |
fc043f |
gpgrt_stream_t _gpgrt_fpopen_nc (FILE *fp, const char *mode);
|
|
Packit |
fc043f |
gpgrt_stream_t _gpgrt_freopen (const char *_GPGRT__RESTRICT path,
|
|
Packit |
fc043f |
const char *_GPGRT__RESTRICT mode,
|
|
Packit |
fc043f |
gpgrt_stream_t _GPGRT__RESTRICT stream);
|
|
Packit |
fc043f |
gpgrt_stream_t _gpgrt_fopencookie (void *_GPGRT__RESTRICT cookie,
|
|
Packit |
fc043f |
const char *_GPGRT__RESTRICT mode,
|
|
Packit |
fc043f |
gpgrt_cookie_io_functions_t functions);
|
|
Packit |
fc043f |
int _gpgrt_fclose (gpgrt_stream_t stream);
|
|
Packit |
fc043f |
int _gpgrt_fclose_snatch (gpgrt_stream_t stream,
|
|
Packit |
fc043f |
void **r_buffer, size_t *r_buflen);
|
|
Packit |
fc043f |
int _gpgrt_onclose (gpgrt_stream_t stream, int mode,
|
|
Packit |
fc043f |
void (*fnc) (gpgrt_stream_t, void*), void *fnc_value);
|
|
Packit |
fc043f |
int _gpgrt_fileno (gpgrt_stream_t stream);
|
|
Packit |
fc043f |
int _gpgrt_fileno_unlocked (gpgrt_stream_t stream);
|
|
Packit |
fc043f |
int _gpgrt_syshd (gpgrt_stream_t stream, gpgrt_syshd_t *syshd);
|
|
Packit |
fc043f |
int _gpgrt_syshd_unlocked (gpgrt_stream_t stream, gpgrt_syshd_t *syshd);
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
void _gpgrt__set_std_fd (int no, int fd);
|
|
Packit |
fc043f |
gpgrt_stream_t _gpgrt__get_std_stream (int fd);
|
|
Packit |
fc043f |
/* The es_stderr et al macros are pretty common so that we want to use
|
|
Packit |
fc043f |
* them too. This requires that we redefine them. */
|
|
Packit |
fc043f |
#undef es_stdin
|
|
Packit |
fc043f |
#define es_stdin _gpgrt__get_std_stream (0)
|
|
Packit |
fc043f |
#undef es_stdout
|
|
Packit |
fc043f |
#define es_stdout _gpgrt__get_std_stream (1)
|
|
Packit |
fc043f |
#undef es_stderr
|
|
Packit |
fc043f |
#define es_stderr _gpgrt__get_std_stream (2)
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
void _gpgrt_flockfile (gpgrt_stream_t stream);
|
|
Packit |
fc043f |
int _gpgrt_ftrylockfile (gpgrt_stream_t stream);
|
|
Packit |
fc043f |
void _gpgrt_funlockfile (gpgrt_stream_t stream);
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
int _gpgrt_feof (gpgrt_stream_t stream);
|
|
Packit |
fc043f |
int _gpgrt_feof_unlocked (gpgrt_stream_t stream);
|
|
Packit |
fc043f |
int _gpgrt_ferror (gpgrt_stream_t stream);
|
|
Packit |
fc043f |
int _gpgrt_ferror_unlocked (gpgrt_stream_t stream);
|
|
Packit |
fc043f |
void _gpgrt_clearerr (gpgrt_stream_t stream);
|
|
Packit |
fc043f |
void _gpgrt_clearerr_unlocked (gpgrt_stream_t stream);
|
|
Packit |
fc043f |
int _gpgrt__pending (gpgrt_stream_t stream);
|
|
Packit |
fc043f |
int _gpgrt__pending_unlocked (gpgrt_stream_t stream);
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
int _gpgrt_fflush (gpgrt_stream_t stream);
|
|
Packit |
fc043f |
int _gpgrt_fseek (gpgrt_stream_t stream, long int offset, int whence);
|
|
Packit |
fc043f |
int _gpgrt_fseeko (gpgrt_stream_t stream, gpgrt_off_t offset, int whence);
|
|
Packit |
fc043f |
long int _gpgrt_ftell (gpgrt_stream_t stream);
|
|
Packit |
fc043f |
gpgrt_off_t _gpgrt_ftello (gpgrt_stream_t stream);
|
|
Packit |
fc043f |
void _gpgrt_rewind (gpgrt_stream_t stream);
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
int _gpgrt_fgetc (gpgrt_stream_t stream);
|
|
Packit |
fc043f |
int _gpgrt_fputc (int c, gpgrt_stream_t stream);
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
int _gpgrt__getc_underflow (gpgrt_stream_t stream);
|
|
Packit |
fc043f |
int _gpgrt__putc_overflow (int c, gpgrt_stream_t stream);
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
/* Note: Keeps the next two macros in sync
|
|
Packit |
fc043f |
with their counterparts in gpg-error.h. */
|
|
Packit |
fc043f |
#define _gpgrt_getc_unlocked(stream) \
|
|
Packit |
fc043f |
(((!(stream)->flags.writing) \
|
|
Packit |
fc043f |
&& ((stream)->data_offset < (stream)->data_len) \
|
|
Packit |
fc043f |
&& (! (stream)->unread_data_len)) \
|
|
Packit |
fc043f |
? ((int) (stream)->buffer[((stream)->data_offset)++]) \
|
|
Packit |
fc043f |
: _gpgrt__getc_underflow ((stream)))
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
#define _gpgrt_putc_unlocked(c, stream) \
|
|
Packit |
fc043f |
(((stream)->flags.writing \
|
|
Packit |
fc043f |
&& ((stream)->data_offset < (stream)->buffer_size) \
|
|
Packit |
fc043f |
&& (c != '\n')) \
|
|
Packit |
fc043f |
? ((int) ((stream)->buffer[((stream)->data_offset)++] = (c))) \
|
|
Packit |
fc043f |
: _gpgrt__putc_overflow ((c), (stream)))
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
int _gpgrt_ungetc (int c, gpgrt_stream_t stream);
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
int _gpgrt_read (gpgrt_stream_t _GPGRT__RESTRICT stream,
|
|
Packit |
fc043f |
void *_GPGRT__RESTRICT buffer, size_t bytes_to_read,
|
|
Packit |
fc043f |
size_t *_GPGRT__RESTRICT bytes_read);
|
|
Packit |
fc043f |
int _gpgrt_write (gpgrt_stream_t _GPGRT__RESTRICT stream,
|
|
Packit |
fc043f |
const void *_GPGRT__RESTRICT buffer, size_t bytes_to_write,
|
|
Packit |
fc043f |
size_t *_GPGRT__RESTRICT bytes_written);
|
|
Packit |
fc043f |
int _gpgrt_write_sanitized (gpgrt_stream_t _GPGRT__RESTRICT stream,
|
|
Packit |
fc043f |
const void *_GPGRT__RESTRICT buffer, size_t length,
|
|
Packit |
fc043f |
const char *delimiters,
|
|
Packit |
fc043f |
size_t *_GPGRT__RESTRICT bytes_written);
|
|
Packit |
fc043f |
int _gpgrt_write_hexstring (gpgrt_stream_t _GPGRT__RESTRICT stream,
|
|
Packit |
fc043f |
const void *_GPGRT__RESTRICT buffer, size_t length,
|
|
Packit |
fc043f |
int reserved,
|
|
Packit |
fc043f |
size_t *_GPGRT__RESTRICT bytes_written);
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
size_t _gpgrt_fread (void *_GPGRT__RESTRICT ptr, size_t size, size_t nitems,
|
|
Packit |
fc043f |
gpgrt_stream_t _GPGRT__RESTRICT stream);
|
|
Packit |
fc043f |
size_t _gpgrt_fwrite (const void *_GPGRT__RESTRICT ptr,
|
|
Packit |
fc043f |
size_t size, size_t memb,
|
|
Packit |
fc043f |
gpgrt_stream_t _GPGRT__RESTRICT stream);
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
char *_gpgrt_fgets (char *_GPGRT__RESTRICT s, int n,
|
|
Packit |
fc043f |
gpgrt_stream_t _GPGRT__RESTRICT stream);
|
|
Packit |
fc043f |
int _gpgrt_fputs (const char *_GPGRT__RESTRICT s,
|
|
Packit |
fc043f |
gpgrt_stream_t _GPGRT__RESTRICT stream);
|
|
Packit |
fc043f |
int _gpgrt_fputs_unlocked (const char *_GPGRT__RESTRICT s,
|
|
Packit |
fc043f |
gpgrt_stream_t _GPGRT__RESTRICT stream);
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
gpgrt_ssize_t _gpgrt_getline (char *_GPGRT__RESTRICT *_GPGRT__RESTRICT lineptr,
|
|
Packit |
fc043f |
size_t *_GPGRT__RESTRICT n,
|
|
Packit |
fc043f |
gpgrt_stream_t stream);
|
|
Packit |
fc043f |
gpgrt_ssize_t _gpgrt_read_line (gpgrt_stream_t stream,
|
|
Packit |
fc043f |
char **addr_of_buffer, size_t *length_of_buffer,
|
|
Packit |
fc043f |
size_t *max_length);
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
int _gpgrt_fprintf (gpgrt_stream_t _GPGRT__RESTRICT stream,
|
|
Packit |
fc043f |
const char *_GPGRT__RESTRICT format, ...)
|
|
Packit |
fc043f |
GPGRT_ATTR_PRINTF(2,3);
|
|
Packit |
fc043f |
int _gpgrt_fprintf_unlocked (gpgrt_stream_t _GPGRT__RESTRICT stream,
|
|
Packit |
fc043f |
const char *_GPGRT__RESTRICT format, ...)
|
|
Packit |
fc043f |
GPGRT_ATTR_PRINTF(2,3);
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
int _gpgrt_vfprintf (gpgrt_stream_t _GPGRT__RESTRICT stream,
|
|
Packit |
fc043f |
const char *_GPGRT__RESTRICT format, va_list ap)
|
|
Packit |
fc043f |
GPGRT_ATTR_PRINTF(2,0);
|
|
Packit |
fc043f |
int _gpgrt_vfprintf_unlocked (gpgrt_stream_t _GPGRT__RESTRICT stream,
|
|
Packit |
fc043f |
const char *_GPGRT__RESTRICT format, va_list ap)
|
|
Packit |
fc043f |
GPGRT_ATTR_PRINTF(2,0);
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
int _gpgrt_setvbuf (gpgrt_stream_t _GPGRT__RESTRICT stream,
|
|
Packit |
fc043f |
char *_GPGRT__RESTRICT buf, int mode, size_t size);
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
void _gpgrt_set_binary (gpgrt_stream_t stream);
|
|
Packit |
fc043f |
int _gpgrt_set_nonblock (gpgrt_stream_t stream, int onoff);
|
|
Packit |
fc043f |
int _gpgrt_get_nonblock (gpgrt_stream_t stream);
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
int _gpgrt_poll (gpgrt_poll_t *fds, unsigned int nfds, int timeout);
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
gpgrt_stream_t _gpgrt_tmpfile (void);
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
void _gpgrt_opaque_set (gpgrt_stream_t _GPGRT__RESTRICT stream,
|
|
Packit |
fc043f |
void *_GPGRT__RESTRICT opaque);
|
|
Packit |
fc043f |
void *_gpgrt_opaque_get (gpgrt_stream_t stream);
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
void _gpgrt_fname_set (gpgrt_stream_t stream, const char *fname);
|
|
Packit |
fc043f |
const char *_gpgrt_fname_get (gpgrt_stream_t stream);
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
#include "estream-printf.h"
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
/* Make sure we always use our snprintf */
|
|
Packit |
fc043f |
#define snprintf _gpgrt_estream_snprintf
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
#if HAVE_W32_SYSTEM
|
|
Packit |
fc043f |
/* Prototypes for w32-estream.c. */
|
|
Packit |
fc043f |
struct cookie_io_functions_s _gpgrt_functions_w32_pollable;
|
|
Packit |
fc043f |
int _gpgrt_w32_pollable_create (void *_GPGRT__RESTRICT *_GPGRT__RESTRICT cookie,
|
|
Packit |
fc043f |
unsigned int modeflags,
|
|
Packit |
fc043f |
struct cookie_io_functions_s next_functions,
|
|
Packit |
fc043f |
void *next_cookie);
|
|
Packit |
fc043f |
int _gpgrt_w32_poll (gpgrt_poll_t *fds, size_t nfds, int timeout);
|
|
Packit |
fc043f |
#endif /*HAVE_W32_SYSTEM*/
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
/*
|
|
Packit |
fc043f |
* Local prototypes for the encoders.
|
|
Packit |
fc043f |
*/
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
struct _gpgrt_b64state
|
|
Packit |
fc043f |
{
|
|
Packit |
fc043f |
int idx;
|
|
Packit |
fc043f |
int quad_count;
|
|
Packit |
fc043f |
estream_t stream;
|
|
Packit |
fc043f |
char *title;
|
|
Packit |
fc043f |
unsigned char radbuf[4];
|
|
Packit |
fc043f |
unsigned int crc;
|
|
Packit |
fc043f |
gpg_err_code_t lasterr;
|
|
Packit |
fc043f |
unsigned int flags;
|
|
Packit |
fc043f |
int stop_seen:1;
|
|
Packit |
fc043f |
int invalid_encoding:1;
|
|
Packit |
fc043f |
int using_decoder:1;
|
|
Packit |
fc043f |
};
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
gpgrt_b64state_t _gpgrt_b64enc_start (estream_t stream, const char *title);
|
|
Packit |
fc043f |
gpg_err_code_t _gpgrt_b64enc_write (gpgrt_b64state_t state,
|
|
Packit |
fc043f |
const void *buffer, size_t nbytes);
|
|
Packit |
fc043f |
gpg_err_code_t _gpgrt_b64enc_finish (gpgrt_b64state_t state);
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
gpgrt_b64state_t _gpgrt_b64dec_start (const char *title);
|
|
Packit |
fc043f |
gpg_err_code_t _gpgrt_b64dec_proc (gpgrt_b64state_t state, void *buffer,
|
|
Packit |
fc043f |
size_t length, size_t *r_nbytes);
|
|
Packit |
fc043f |
gpg_err_code_t _gpgrt_b64dec_finish (gpgrt_b64state_t state);
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
/*
|
|
Packit |
fc043f |
* Local prototypes for logging
|
|
Packit |
fc043f |
*/
|
|
Packit |
fc043f |
int _gpgrt_get_errorcount (int clear);
|
|
Packit |
fc043f |
void _gpgrt_inc_errorcount (void);
|
|
Packit |
fc043f |
void _gpgrt_log_set_sink (const char *name, estream_t stream, int fd);
|
|
Packit |
fc043f |
void _gpgrt_log_set_socket_dir_cb (const char *(*fnc)(void));
|
|
Packit |
fc043f |
void _gpgrt_log_set_pid_suffix_cb (int (*cb)(unsigned long *r_value));
|
|
Packit |
fc043f |
void _gpgrt_log_set_prefix (const char *text, unsigned int flags);
|
|
Packit |
fc043f |
const char *_gpgrt_log_get_prefix (unsigned int *flags);
|
|
Packit |
fc043f |
int _gpgrt_log_test_fd (int fd);
|
|
Packit |
fc043f |
int _gpgrt_log_get_fd (void);
|
|
Packit |
fc043f |
estream_t _gpgrt_log_get_stream (void);
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
void _gpgrt_log (int level, const char *fmt, ...) GPGRT_ATTR_PRINTF(2,3);
|
|
Packit |
fc043f |
void _gpgrt_logv (int level, const char *fmt, va_list arg_ptr);
|
|
Packit |
fc043f |
void _gpgrt_logv_prefix (int level, const char *prefix,
|
|
Packit |
fc043f |
const char *fmt, va_list arg_ptr);
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
void _gpgrt_log_string (int level, const char *string);
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
void _gpgrt_log_bug (const char *fmt, ...) GPGRT_ATTR_NR_PRINTF(1,2);
|
|
Packit |
fc043f |
void _gpgrt_log_fatal (const char *fmt, ...) GPGRT_ATTR_NR_PRINTF(1,2);
|
|
Packit |
fc043f |
void _gpgrt_log_error (const char *fmt, ...) GPGRT_ATTR_PRINTF(1,2);
|
|
Packit |
fc043f |
void _gpgrt_log_info (const char *fmt, ...) GPGRT_ATTR_PRINTF(1,2);
|
|
Packit |
fc043f |
void _gpgrt_log_debug (const char *fmt, ...) GPGRT_ATTR_PRINTF(1,2);
|
|
Packit |
fc043f |
void _gpgrt_log_debug_string (const char *string, const char *fmt,
|
|
Packit |
fc043f |
...) GPGRT_ATTR_PRINTF(2,3);
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
void _gpgrt_log_printf (const char *fmt, ...) GPGRT_ATTR_PRINTF(1,2);
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
void _gpgrt_log_flush (void);
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
void _gpgrt_logv_printhex (const void *buffer, size_t length,
|
|
Packit |
fc043f |
const char *fmt, va_list arg_ptr);
|
|
Packit |
fc043f |
void _gpgrt_log_printhex (const void *buffer, size_t length,
|
|
Packit |
fc043f |
const char *fmt, ...) GPGRT_ATTR_PRINTF(3,4);;
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
void _gpgrt_logv_clock (const char *fmt, va_list arg_ptr);
|
|
Packit |
fc043f |
void _gpgrt_log_clock (const char *fmt, ...) GPGRT_ATTR_PRINTF(1,2);
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
void _gpgrt__log_assert (const char *expr, const char *file, int line,
|
|
Packit |
fc043f |
const char *func) GPGRT_ATTR_NORETURN;
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
/* Redefine the assert macro to use our internal function. */
|
|
Packit |
fc043f |
#undef gpgrt_assert
|
|
Packit |
fc043f |
#ifdef GPGRT_HAVE_MACRO_FUNCTION
|
|
Packit |
fc043f |
#define gpgrt_assert(expr) \
|
|
Packit |
fc043f |
((expr) \
|
|
Packit |
fc043f |
? (void) 0 \
|
|
Packit |
fc043f |
: _gpgrt__log_assert (#expr, __FILE__, __LINE__, __FUNCTION__))
|
|
Packit |
fc043f |
#else /*!GPGRT_HAVE_MACRO_FUNCTION*/
|
|
Packit |
fc043f |
/* # define BUG() bug_at( __FILE__ , __LINE__ ) */
|
|
Packit |
fc043f |
#define gpgrt_assert(expr) \
|
|
Packit |
fc043f |
((expr) \
|
|
Packit |
fc043f |
? (void) 0 \
|
|
Packit |
fc043f |
: _gpgrt__log_assert (#expr, __FILE__, __LINE__, NULL))
|
|
Packit |
fc043f |
#endif /*!GPGRT_HAVE_MACRO_FUNCTION*/
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
/* Note: The next function is only to be used by visibility.c. */
|
|
Packit |
fc043f |
int _gpgrt_logv_internal (int level, int ignore_arg_ptr,
|
|
Packit |
fc043f |
const char *extrastring,
|
|
Packit |
fc043f |
const char *prefmt, const char *fmt,
|
|
Packit |
fc043f |
va_list arg_ptr);
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
/*
|
|
Packit |
fc043f |
* Local prototypes for the spawn functions.
|
|
Packit |
fc043f |
*
|
|
Packit |
fc043f |
* We put the docs here because we have separate implementations in
|
|
Packit |
fc043f |
* the files spawn-posix.c and spawn-w32.c
|
|
Packit |
fc043f |
*/
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
/* Return the maximum number of currently allowed file descriptors.
|
|
Packit |
fc043f |
* Only useful on POSIX systems. */
|
|
Packit |
fc043f |
/* int get_max_fds (void); */
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
/* Close all file descriptors starting with descriptor FIRST. If
|
|
Packit |
fc043f |
* EXCEPT is not NULL, it is expected to be a list of file descriptors
|
|
Packit |
fc043f |
* which are not to close. This list shall be sorted in ascending
|
|
Packit |
fc043f |
* order with its end marked by -1. */
|
|
Packit |
fc043f |
/* void close_all_fds (int first, int *except); */
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
/* Returns an array with all currently open file descriptors. The end
|
|
Packit |
fc043f |
* of the array is marked by -1. The caller needs to release this
|
|
Packit |
fc043f |
* array using the *standard free* and not with xfree. This allow the
|
|
Packit |
fc043f |
* use of this function right at startup even before libgcrypt has
|
|
Packit |
fc043f |
* been initialized. Returns NULL on error and sets ERRNO accordingly. */
|
|
Packit |
fc043f |
/* int *get_all_open_fds (void); */
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
/* Create a pipe. The DIRECTION parameter gives the type of the created pipe:
|
|
Packit |
fc043f |
* DIRECTION < 0 := Inbound pipe: On Windows the write end is inheritable.
|
|
Packit |
fc043f |
* DIRECTION > 0 := Outbound pipe: On Windows the read end is inheritable.
|
|
Packit |
fc043f |
* If R_FP is NULL a standard pipe and no stream is created, DIRECTION
|
|
Packit |
fc043f |
* should then be 0. */
|
|
Packit |
fc043f |
gpg_err_code_t _gpgrt_make_pipe (int filedes[2], estream_t *r_fp,
|
|
Packit |
fc043f |
int direction, int nonblock);
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
/* Convenience macros to create a pipe. */
|
|
Packit |
fc043f |
#define _gpgrt_create_pipe(a) _gpgrt_make_pipe ((a),NULL, 0, 0);
|
|
Packit |
fc043f |
#define _gpgrt_create_inbound_pipe(a,b,c) _gpgrt_make_pipe ((a), (b), -1, (c));
|
|
Packit |
fc043f |
#define _gpgrt_create_outbound_pipe(a,b,c) _gpgrt_make_pipe ((a), (b), 1, (c));
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
/* Fork and exec the program PGMNAME.
|
|
Packit |
fc043f |
*
|
|
Packit |
fc043f |
* If R_INFP is NULL connect stdin of the new process to /dev/null; if
|
|
Packit |
fc043f |
* it is not NULL store the address of a pointer to a new estream
|
|
Packit |
fc043f |
* there. If R_OUTFP is NULL connect stdout of the new process to
|
|
Packit |
fc043f |
* /dev/null; if it is not NULL store the address of a pointer to a
|
|
Packit |
fc043f |
* new estream there. If R_ERRFP is NULL connect stderr of the new
|
|
Packit |
fc043f |
* process to /dev/null; if it is not NULL store the address of a
|
|
Packit |
fc043f |
* pointer to a new estream there. On success the pid of the new
|
|
Packit |
fc043f |
* process is stored at PID. On error -1 is stored at PID and if
|
|
Packit |
fc043f |
* R_OUTFP or R_ERRFP are not NULL, NULL is stored there.
|
|
Packit |
fc043f |
*
|
|
Packit |
fc043f |
* The arguments for the process are expected in the NULL terminated
|
|
Packit |
fc043f |
* array ARGV. The program name itself should not be included there.
|
|
Packit |
fc043f |
* If PREEXEC is not NULL, the given function will be called right
|
|
Packit |
fc043f |
* before the exec.
|
|
Packit |
fc043f |
*
|
|
Packit |
fc043f |
* IF EXCEPT is not NULL, it is expected to be an ordered list of file
|
|
Packit |
fc043f |
* descriptors, terminated by an entry with the value (-1). These
|
|
Packit |
fc043f |
* file descriptors won't be closed before spawning a new program.
|
|
Packit |
fc043f |
*
|
|
Packit |
fc043f |
* Returns 0 on success or an error code. Calling gpgrt_wait_process
|
|
Packit |
fc043f |
* and gpgrt_release_process is required if the function succeeded.
|
|
Packit |
fc043f |
*
|
|
Packit |
fc043f |
* FLAGS is a bit vector:
|
|
Packit |
fc043f |
*
|
|
Packit |
fc043f |
* GPGRT_SPAWN_NONBLOCK
|
|
Packit |
fc043f |
* If set the two output streams are created in non-blocking
|
|
Packit |
fc043f |
* mode and the input stream is switched to non-blocking mode.
|
|
Packit |
fc043f |
* This is merely a convenience feature because the caller
|
|
Packit |
fc043f |
* could do the same with gpgrt_set_nonblock. Does not yet
|
|
Packit |
fc043f |
* work for Windows.
|
|
Packit |
fc043f |
*
|
|
Packit |
fc043f |
* GPGRT_SPAWN_DETACHED
|
|
Packit |
fc043f |
* If set the process will be started as a background process.
|
|
Packit |
fc043f |
* This flag is only useful under W32 (but not W32CE) systems,
|
|
Packit |
fc043f |
* so that no new console is created and pops up a console
|
|
Packit |
fc043f |
* window when starting the server. Does not work on W32CE.
|
|
Packit |
fc043f |
*
|
|
Packit |
fc043f |
* GPGRT_SPAWN_RUN_ASFW
|
|
Packit |
fc043f |
* On W32 (but not on W32CE) run AllowSetForegroundWindow for
|
|
Packit |
fc043f |
* the child. Note that due to unknown problems this actually
|
|
Packit |
fc043f |
* allows SetForegroundWindow for all children of this process.
|
|
Packit |
fc043f |
*/
|
|
Packit |
fc043f |
gpg_err_code_t
|
|
Packit |
fc043f |
_gpgrt_spawn_process (const char *pgmname, const char *argv[],
|
|
Packit |
fc043f |
int *execpt, void (*preexec)(void), unsigned int flags,
|
|
Packit |
fc043f |
estream_t *r_infp,
|
|
Packit |
fc043f |
estream_t *r_outfp,
|
|
Packit |
fc043f |
estream_t *r_errfp,
|
|
Packit |
fc043f |
pid_t *pid);
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
/* Simplified version of gpgrt_spawn_process. This function forks and
|
|
Packit |
fc043f |
* then execs PGMNAME, while connecting INFD to stdin, OUTFD to stdout
|
|
Packit |
fc043f |
* and ERRFD to stderr (any of them may be -1 to connect them to
|
|
Packit |
fc043f |
* /dev/null). The arguments for the process are expected in the NULL
|
|
Packit |
fc043f |
* terminated array ARGV. The program name itself should not be
|
|
Packit |
fc043f |
* included there. Calling gpgrt_wait_process and
|
|
Packit |
fc043f |
* gpgrt_release_process is required. Returns 0 on success or an
|
|
Packit |
fc043f |
* error code. */
|
|
Packit |
fc043f |
gpg_err_code_t _gpgrt_spawn_process_fd (const char *pgmname,
|
|
Packit |
fc043f |
const char *argv[],
|
|
Packit |
fc043f |
int infd, int outfd, int errfd,
|
|
Packit |
fc043f |
pid_t *pid);
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
/* Spawn a new process and immediately detach from it. The name of
|
|
Packit |
fc043f |
* the program to exec is PGMNAME and its arguments are in ARGV (the
|
|
Packit |
fc043f |
* programname is automatically passed as first argument).
|
|
Packit |
fc043f |
* Environment strings in ENVP are set. An error is returned if
|
|
Packit |
fc043f |
* pgmname is not executable; to make this work it is necessary to
|
|
Packit |
fc043f |
* provide an absolute file name. */
|
|
Packit |
fc043f |
gpg_err_code_t _gpgrt_spawn_process_detached (const char *pgmname,
|
|
Packit |
fc043f |
const char *argv[],
|
|
Packit |
fc043f |
const char *envp[] );
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
/* If HANG is true, waits for the process identified by PID to exit;
|
|
Packit |
fc043f |
* if HANG is false, checks whether the process has terminated.
|
|
Packit |
fc043f |
* PGMNAME should be the same as supplied to the spawn function and is
|
|
Packit |
fc043f |
* only used for diagnostics. Return values:
|
|
Packit |
fc043f |
*
|
|
Packit |
fc043f |
* 0
|
|
Packit |
fc043f |
* The process exited successful. 0 is stored at R_EXITCODE.
|
|
Packit |
fc043f |
*
|
|
Packit |
fc043f |
* GPG_ERR_GENERAL
|
|
Packit |
fc043f |
* The process exited without success. The exit code of process
|
|
Packit |
fc043f |
* is then stored at R_EXITCODE. An exit code of -1 indicates
|
|
Packit |
fc043f |
* that the process terminated abnormally (e.g. due to a signal).
|
|
Packit |
fc043f |
*
|
|
Packit |
fc043f |
* GPG_ERR_TIMEOUT
|
|
Packit |
fc043f |
* The process is still running (returned only if HANG is false).
|
|
Packit |
fc043f |
*
|
|
Packit |
fc043f |
* GPG_ERR_INV_VALUE
|
|
Packit |
fc043f |
* An invalid PID has been specified.
|
|
Packit |
fc043f |
*
|
|
Packit |
fc043f |
* Other error codes may be returned as well. Unless otherwise noted,
|
|
Packit |
fc043f |
* -1 will be stored at R_EXITCODE. R_EXITCODE may be passed as NULL
|
|
Packit |
fc043f |
* if the exit code is not required (in that case an error message will
|
|
Packit |
fc043f |
* be printed). Note that under Windows PID is not the process id but
|
|
Packit |
fc043f |
* the handle of the process. */
|
|
Packit |
fc043f |
gpg_err_code_t _gpgrt_wait_process (const char *pgmname, pid_t pid, int hang,
|
|
Packit |
fc043f |
int *r_exitcode);
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
/* Like _gpgrt_wait_process, but for COUNT processes. */
|
|
Packit |
fc043f |
gpg_err_code_t _gpgrt_wait_processes (const char **pgmnames, pid_t *pids,
|
|
Packit |
fc043f |
size_t count, int hang, int *r_exitcodes);
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
/* Kill a process; that is send an appropriate signal to the process.
|
|
Packit |
fc043f |
* gpgrt_wait_process must be called to actually remove the process
|
|
Packit |
fc043f |
* from the system. An invalid PID is ignored. */
|
|
Packit |
fc043f |
void _gpgrt_kill_process (pid_t pid);
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
/* Release the process identified by PID. This function is actually
|
|
Packit |
fc043f |
* only required for Windows but it does not harm to always call it.
|
|
Packit |
fc043f |
* It is a nop if PID is invalid. */
|
|
Packit |
fc043f |
void _gpgrt_release_process (pid_t pid);
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
/*
|
|
Packit |
fc043f |
* Local prototypes for argparse.
|
|
Packit |
fc043f |
*/
|
|
Packit |
fc043f |
int _gpgrt_argparse (estream_t fp, gpgrt_argparse_t *arg, gpgrt_opt_t *opts);
|
|
Packit |
fc043f |
void _gpgrt_usage (int level);
|
|
Packit |
fc043f |
const char *_gpgrt_strusage (int level);
|
|
Packit |
fc043f |
void _gpgrt_set_strusage (const char *(*f)(int));
|
|
Packit |
fc043f |
void _gpgrt_set_usage_outfnc (int (*fnc)(int, const char *));
|
|
Packit |
fc043f |
void _gpgrt_set_fixed_string_mapper (const char *(*f)(const char*));
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
/*
|
|
Packit |
fc043f |
* Internal platform abstraction functions (sysutils.c)
|
|
Packit |
fc043f |
*/
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
/* Return true if FD is valid. */
|
|
Packit |
fc043f |
int _gpgrt_fd_valid_p (int fd);
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
/* A getenv variant which returns a malloced copy. */
|
|
Packit |
fc043f |
char *_gpgrt_getenv (const char *name);
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
/* A setenv variant which can be used for unsetenv by setting VALUE to
|
|
Packit |
fc043f |
* NULL and OVERRIDE to true. */
|
|
Packit |
fc043f |
gpg_err_code_t _gpgrt_setenv (const char *name,
|
|
Packit |
fc043f |
const char *value, int overwrite);
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
/* A wrapper around mkdir using a string for the mode (permissions). */
|
|
Packit |
fc043f |
gpg_err_code_t _gpgrt_mkdir (const char *name, const char *modestr);
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
/* A simple wrapper around chdir. */
|
|
Packit |
fc043f |
gpg_err_code_t _gpgrt_chdir (const char *name);
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
/* Return the current WD as a malloced string. */
|
|
Packit |
fc043f |
char *_gpgrt_getcwd (void);
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
/*
|
|
Packit |
fc043f |
* Platform specific functions (Windows)
|
|
Packit |
fc043f |
*/
|
|
Packit |
fc043f |
#ifdef HAVE_W32_SYSTEM
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
char *_gpgrt_w32_reg_query_string (const char *root,
|
|
Packit |
fc043f |
const char *dir,
|
|
Packit |
fc043f |
const char *name);
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
#endif /*HAVE_W32_SYSTEM*/
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
/*
|
|
Packit |
fc043f |
* Missing functions implemented inline.
|
|
Packit |
fc043f |
*/
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
#ifndef HAVE_STPCPY
|
|
Packit |
fc043f |
static GPG_ERR_INLINE char *
|
|
Packit |
fc043f |
_gpgrt_stpcpy (char *a, const char *b)
|
|
Packit |
fc043f |
{
|
|
Packit |
fc043f |
while (*b)
|
|
Packit |
fc043f |
*a++ = *b++;
|
|
Packit |
fc043f |
*a = 0;
|
|
Packit |
fc043f |
return a;
|
|
Packit |
fc043f |
}
|
|
Packit |
fc043f |
#define stpcpy(a,b) _gpgrt_stpcpy ((a), (b))
|
|
Packit |
fc043f |
#endif /*!HAVE_STPCPY*/
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
#endif /*_GPGRT_GPGRT_INT_H*/
|