Fix regression in logging.

Add a registry key to enable catch-all remote debugging for W32.
Replace more stdio stuff by estream.
This commit is contained in:
Werner Koch 2010-08-18 19:25:15 +00:00
parent 7e752a4208
commit 34dde96669
20 changed files with 423 additions and 294 deletions

View File

@ -1,3 +1,7 @@
2010-08-16 Werner Koch <wk@g10code.com>
* gpg-agent.c: Repalce remaining printf by es_printf.
2010-08-11 Werner Koch <wk@g10code.com> 2010-08-11 Werner Koch <wk@g10code.com>
* call-pinentry.c (agent_get_passphrase, agent_askpin): Fix * call-pinentry.c (agent_get_passphrase, agent_askpin): Fix

View File

@ -823,9 +823,9 @@ main (int argc, char **argv )
if (greeting) if (greeting)
{ {
fprintf (stderr, "%s %s; %s\n", es_fprintf (es_stderr, "%s %s; %s\n",
strusage(11), strusage(13), strusage(14) ); strusage(11), strusage(13), strusage(14) );
fprintf (stderr, "%s\n", strusage(15) ); es_fprintf (es_stderr, "%s\n", strusage(15) );
} }
#ifdef IS_DEVELOPMENT_VERSION #ifdef IS_DEVELOPMENT_VERSION
/* We don't want to print it here because gpg-agent is useful of its /* We don't want to print it here because gpg-agent is useful of its
@ -874,12 +874,12 @@ main (int argc, char **argv )
filename = make_filename (opt.homedir, "gpg-agent.conf", NULL ); filename = make_filename (opt.homedir, "gpg-agent.conf", NULL );
filename_esc = percent_escape (filename, NULL); filename_esc = percent_escape (filename, NULL);
printf ("gpgconf-gpg-agent.conf:%lu:\"%s\n", es_printf ("gpgconf-gpg-agent.conf:%lu:\"%s\n",
GC_OPT_FLAG_DEFAULT, filename_esc); GC_OPT_FLAG_DEFAULT, filename_esc);
xfree (filename); xfree (filename);
xfree (filename_esc); xfree (filename_esc);
printf ("verbose:%lu:\n" es_printf ("verbose:%lu:\n"
"quiet:%lu:\n" "quiet:%lu:\n"
"debug-level:%lu:\"none:\n" "debug-level:%lu:\"none:\n"
"log-file:%lu:\n", "log-file:%lu:\n",
@ -887,35 +887,35 @@ main (int argc, char **argv )
GC_OPT_FLAG_NONE|GC_OPT_FLAG_RUNTIME, GC_OPT_FLAG_NONE|GC_OPT_FLAG_RUNTIME,
GC_OPT_FLAG_DEFAULT|GC_OPT_FLAG_RUNTIME, GC_OPT_FLAG_DEFAULT|GC_OPT_FLAG_RUNTIME,
GC_OPT_FLAG_NONE|GC_OPT_FLAG_RUNTIME ); GC_OPT_FLAG_NONE|GC_OPT_FLAG_RUNTIME );
printf ("default-cache-ttl:%lu:%d:\n", es_printf ("default-cache-ttl:%lu:%d:\n",
GC_OPT_FLAG_DEFAULT|GC_OPT_FLAG_RUNTIME, DEFAULT_CACHE_TTL ); GC_OPT_FLAG_DEFAULT|GC_OPT_FLAG_RUNTIME, DEFAULT_CACHE_TTL );
printf ("default-cache-ttl-ssh:%lu:%d:\n", es_printf ("default-cache-ttl-ssh:%lu:%d:\n",
GC_OPT_FLAG_DEFAULT|GC_OPT_FLAG_RUNTIME, DEFAULT_CACHE_TTL_SSH ); GC_OPT_FLAG_DEFAULT|GC_OPT_FLAG_RUNTIME, DEFAULT_CACHE_TTL_SSH );
printf ("max-cache-ttl:%lu:%d:\n", es_printf ("max-cache-ttl:%lu:%d:\n",
GC_OPT_FLAG_DEFAULT|GC_OPT_FLAG_RUNTIME, MAX_CACHE_TTL ); GC_OPT_FLAG_DEFAULT|GC_OPT_FLAG_RUNTIME, MAX_CACHE_TTL );
printf ("max-cache-ttl-ssh:%lu:%d:\n", es_printf ("max-cache-ttl-ssh:%lu:%d:\n",
GC_OPT_FLAG_DEFAULT|GC_OPT_FLAG_RUNTIME, MAX_CACHE_TTL_SSH ); GC_OPT_FLAG_DEFAULT|GC_OPT_FLAG_RUNTIME, MAX_CACHE_TTL_SSH );
printf ("enforce-passphrase-constraints:%lu:\n", es_printf ("enforce-passphrase-constraints:%lu:\n",
GC_OPT_FLAG_NONE|GC_OPT_FLAG_RUNTIME); GC_OPT_FLAG_NONE|GC_OPT_FLAG_RUNTIME);
printf ("min-passphrase-len:%lu:%d:\n", es_printf ("min-passphrase-len:%lu:%d:\n",
GC_OPT_FLAG_DEFAULT|GC_OPT_FLAG_RUNTIME, MIN_PASSPHRASE_LEN ); GC_OPT_FLAG_DEFAULT|GC_OPT_FLAG_RUNTIME, MIN_PASSPHRASE_LEN );
printf ("min-passphrase-nonalpha:%lu:%d:\n", es_printf ("min-passphrase-nonalpha:%lu:%d:\n",
GC_OPT_FLAG_DEFAULT|GC_OPT_FLAG_RUNTIME, GC_OPT_FLAG_DEFAULT|GC_OPT_FLAG_RUNTIME,
MIN_PASSPHRASE_NONALPHA); MIN_PASSPHRASE_NONALPHA);
printf ("check-passphrase-pattern:%lu:\n", es_printf ("check-passphrase-pattern:%lu:\n",
GC_OPT_FLAG_DEFAULT|GC_OPT_FLAG_RUNTIME); GC_OPT_FLAG_DEFAULT|GC_OPT_FLAG_RUNTIME);
printf ("max-passphrase-days:%lu:%d:\n", es_printf ("max-passphrase-days:%lu:%d:\n",
GC_OPT_FLAG_DEFAULT|GC_OPT_FLAG_RUNTIME, GC_OPT_FLAG_DEFAULT|GC_OPT_FLAG_RUNTIME,
MAX_PASSPHRASE_DAYS); MAX_PASSPHRASE_DAYS);
printf ("enable-passphrase-history:%lu:\n", es_printf ("enable-passphrase-history:%lu:\n",
GC_OPT_FLAG_NONE|GC_OPT_FLAG_RUNTIME); GC_OPT_FLAG_NONE|GC_OPT_FLAG_RUNTIME);
printf ("no-grab:%lu:\n", es_printf ("no-grab:%lu:\n",
GC_OPT_FLAG_NONE|GC_OPT_FLAG_RUNTIME); GC_OPT_FLAG_NONE|GC_OPT_FLAG_RUNTIME);
printf ("ignore-cache-for-signing:%lu:\n", es_printf ("ignore-cache-for-signing:%lu:\n",
GC_OPT_FLAG_NONE|GC_OPT_FLAG_RUNTIME); GC_OPT_FLAG_NONE|GC_OPT_FLAG_RUNTIME);
printf ("allow-mark-trusted:%lu:\n", es_printf ("allow-mark-trusted:%lu:\n",
GC_OPT_FLAG_NONE|GC_OPT_FLAG_RUNTIME); GC_OPT_FLAG_NONE|GC_OPT_FLAG_RUNTIME);
printf ("disable-scdaemon:%lu:\n", es_printf ("disable-scdaemon:%lu:\n",
GC_OPT_FLAG_NONE|GC_OPT_FLAG_RUNTIME); GC_OPT_FLAG_NONE|GC_OPT_FLAG_RUNTIME);
agent_exit (0); agent_exit (0);
@ -1026,7 +1026,7 @@ main (int argc, char **argv )
fflush (NULL); fflush (NULL);
#ifdef HAVE_W32_SYSTEM #ifdef HAVE_W32_SYSTEM
pid = getpid (); pid = getpid ();
printf ("set GPG_AGENT_INFO=%s;%lu;1\n", socket_name, (ulong)pid); es_printf ("set GPG_AGENT_INFO=%s;%lu;1\n", socket_name, (ulong)pid);
#else /*!HAVE_W32_SYSTEM*/ #else /*!HAVE_W32_SYSTEM*/
pid = fork (); pid = fork ();
if (pid == (pid_t)-1) if (pid == (pid_t)-1)
@ -1098,24 +1098,24 @@ main (int argc, char **argv )
if (env_file_name) if (env_file_name)
{ {
FILE *fp; estream_t fp;
fp = fopen (env_file_name, "w"); fp = es_fopen (env_file_name, "w");
if (!fp) if (!fp)
log_error (_("error creating `%s': %s\n"), log_error (_("error creating `%s': %s\n"),
env_file_name, strerror (errno)); env_file_name, strerror (errno));
else else
{ {
fputs (infostr, fp); es_fputs (infostr, fp);
putc ('\n', fp); es_putc ('\n', fp);
if (opt.ssh_support) if (opt.ssh_support)
{ {
fputs (infostr_ssh_sock, fp); es_fputs (infostr_ssh_sock, fp);
putc ('\n', fp); es_putc ('\n', fp);
fputs (infostr_ssh_pid, fp); es_fputs (infostr_ssh_pid, fp);
putc ('\n', fp); es_putc ('\n', fp);
} }
fclose (fp); es_fclose (fp);
} }
} }
@ -1163,22 +1163,24 @@ main (int argc, char **argv )
if (csh_style) if (csh_style)
{ {
*strchr (infostr, '=') = ' '; *strchr (infostr, '=') = ' ';
printf ("setenv %s\n", infostr); es_printf ("setenv %s\n", infostr);
if (opt.ssh_support) if (opt.ssh_support)
{ {
*strchr (infostr_ssh_sock, '=') = ' '; *strchr (infostr_ssh_sock, '=') = ' ';
printf ("setenv %s\n", infostr_ssh_sock); es_printf ("setenv %s\n", infostr_ssh_sock);
*strchr (infostr_ssh_pid, '=') = ' '; *strchr (infostr_ssh_pid, '=') = ' ';
printf ("setenv %s\n", infostr_ssh_pid); es_printf ("setenv %s\n", infostr_ssh_pid);
} }
} }
else else
{ {
printf ( "%s; export GPG_AGENT_INFO;\n", infostr); es_printf ( "%s; export GPG_AGENT_INFO;\n", infostr);
if (opt.ssh_support) if (opt.ssh_support)
{ {
printf ("%s; export SSH_AUTH_SOCK;\n", infostr_ssh_sock); es_printf ("%s; export SSH_AUTH_SOCK;\n",
printf ("%s; export SSH_AGENT_PID;\n", infostr_ssh_pid); infostr_ssh_sock);
es_printf ("%s; export SSH_AGENT_PID;\n",
infostr_ssh_pid);
} }
} }
xfree (infostr); xfree (infostr);

View File

@ -1,5 +1,16 @@
2010-08-18 Werner Koch <wk@g10code.com>
* logging.c (writen): Add arg IS_SOCKET.
(fun_writer): Pass the is_socket flag.
(do_logv) [W32]: Allow for a default log stream
* estream.c (struct estream_internal): Remove obsolete fields
PRINT_FP, PRINT_ERRNO, PRINT_ERR and all remaining code cruft.
2010-08-16 Werner Koch <wk@g10code.com> 2010-08-16 Werner Koch <wk@g10code.com>
* estream.c (es_printf_unlocked, es_printf): New.
* asshelp.c (lock_agent_t): Rename to lock_spawn_t. * asshelp.c (lock_agent_t): Rename to lock_spawn_t.
(lock_agent_spawning, unlock_agent_spawning): Factor code out to ... (lock_agent_spawning, unlock_agent_spawning): Factor code out to ...
(lock_spawning, unlock_spawning): .. new. (lock_spawning, unlock_spawning): .. new.

View File

@ -218,7 +218,7 @@ struct estream_internal
es_cookie_seek_function_t func_seek; es_cookie_seek_function_t func_seek;
es_cookie_close_function_t func_close; es_cookie_close_function_t func_close;
int strategy; int strategy;
int fd; int fd; /* Value to return by es_fileno(). */
struct struct
{ {
unsigned int err: 1; unsigned int err: 1;
@ -227,11 +227,8 @@ struct estream_internal
unsigned int deallocate_buffer: 1; unsigned int deallocate_buffer: 1;
unsigned int is_stdstream:1; /* This is a standard stream. */ unsigned int is_stdstream:1; /* This is a standard stream. */
unsigned int stdstream_fd:2; /* 0, 1 or 2 for a standard stream. */ unsigned int stdstream_fd:2; /* 0, 1 or 2 for a standard stream. */
unsigned int print_err: 1; /* Error in print_fun_writer. */
unsigned int printable_fname_inuse: 1; /* es_fname_get has been used. */ unsigned int printable_fname_inuse: 1; /* es_fname_get has been used. */
int print_errno; /* Errno from print_fun_writer. */ size_t print_ntotal; /* Bytes written from in print_writer. */
size_t print_ntotal; /* Bytes written from in print_fun_writer. */
FILE *print_fp; /* Stdio stream used by print_fun_writer. */
}; };
@ -899,7 +896,8 @@ typedef struct estream_cookie_fp
int no_close; /* If set we won't close the file pointer. */ int no_close; /* If set we won't close the file pointer. */
} *estream_cookie_fp_t; } *estream_cookie_fp_t;
/* Create function for fd objects. */
/* Create function for FILE objects. */
static int static int
es_func_fp_create (void **cookie, FILE *fp, es_func_fp_create (void **cookie, FILE *fp,
unsigned int modeflags, int no_close) unsigned int modeflags, int no_close)
@ -924,7 +922,7 @@ es_func_fp_create (void **cookie, FILE *fp,
*cookie = fp_cookie; *cookie = fp_cookie;
err = 0; err = 0;
} }
return err; return err;
} }
@ -948,12 +946,10 @@ es_func_fp_read (void *cookie, void *buffer, size_t size)
/* Write function for FILE* objects. */ /* Write function for FILE* objects. */
static ssize_t static ssize_t
es_func_fp_write (void *cookie, const void *buffer, size_t size) es_func_fp_write (void *cookie, const void *buffer, size_t size)
{ {
estream_cookie_fp_t file_cookie = cookie; estream_cookie_fp_t file_cookie = cookie;
size_t bytes_written; size_t bytes_written;
if (file_cookie->fp) if (file_cookie->fp)
{ {
#ifdef HAVE_W32_SYSTEM #ifdef HAVE_W32_SYSTEM
@ -1285,10 +1281,7 @@ es_initialize (estream_t stream,
stream->intern->func_close = functions.func_close; stream->intern->func_close = functions.func_close;
stream->intern->strategy = _IOFBF; stream->intern->strategy = _IOFBF;
stream->intern->fd = fd; stream->intern->fd = fd;
stream->intern->print_err = 0;
stream->intern->print_errno = 0;
stream->intern->print_ntotal = 0; stream->intern->print_ntotal = 0;
stream->intern->print_fp = NULL;
stream->intern->indicators.err = 0; stream->intern->indicators.err = 0;
stream->intern->indicators.eof = 0; stream->intern->indicators.eof = 0;
stream->intern->is_stdstream = 0; stream->intern->is_stdstream = 0;
@ -1319,14 +1312,6 @@ es_deinitialize (estream_t stream)
es_cookie_close_function_t func_close; es_cookie_close_function_t func_close;
int err, tmp_err; int err, tmp_err;
if (stream->intern->print_fp)
{
int save_errno = errno;
fclose (stream->intern->print_fp);
stream->intern->print_fp = NULL;
_set_errno (save_errno);
}
func_close = stream->intern->func_close; func_close = stream->intern->func_close;
err = 0; err = 0;
@ -3205,6 +3190,38 @@ es_fprintf (estream_t ES__RESTRICT stream,
return ret; return ret;
} }
int
es_printf_unlocked (const char *ES__RESTRICT format, ...)
{
int ret;
va_list ap;
va_start (ap, format);
ret = es_print (es_stdout, format, ap);
va_end (ap);
return ret;
}
int
es_printf (const char *ES__RESTRICT format, ...)
{
int ret;
estream_t stream = es_stdout;
va_list ap;
va_start (ap, format);
ESTREAM_LOCK (stream);
ret = es_print (stream, format, ap);
ESTREAM_UNLOCK (stream);
va_end (ap);
return ret;
}
/* A variant of asprintf. The function returns the allocated buffer /* A variant of asprintf. The function returns the allocated buffer
or NULL on error; ERRNO is set in the error case. The caller or NULL on error; ERRNO is set in the error case. The caller
should use es_free to release the buffer. This function actually should use es_free to release the buffer. This function actually

View File

@ -121,6 +121,8 @@
#define es_free _ESTREAM_PREFIX(es_free) #define es_free _ESTREAM_PREFIX(es_free)
#define es_fprintf _ESTREAM_PREFIX(es_fprintf) #define es_fprintf _ESTREAM_PREFIX(es_fprintf)
#define es_fprintf_unlocked _ESTREAM_PREFIX(es_fprintf_unlocked) #define es_fprintf_unlocked _ESTREAM_PREFIX(es_fprintf_unlocked)
#define es_printf _ESTREAM_PREFIX(es_printf)
#define es_printf_unlocked _ESTREAM_PREFIX(es_printf_unlocked)
#define es_vfprintf _ESTREAM_PREFIX(es_vfprint) #define es_vfprintf _ESTREAM_PREFIX(es_vfprint)
#define es_vfprintf_unlocked _ESTREAM_PREFIX(es_vfprint_unlocked) #define es_vfprintf_unlocked _ESTREAM_PREFIX(es_vfprint_unlocked)
#define es_setvbuf _ESTREAM_PREFIX(es_setvbuf) #define es_setvbuf _ESTREAM_PREFIX(es_setvbuf)
@ -345,6 +347,11 @@ int es_fprintf_unlocked (estream_t ES__RESTRICT stream,
const char *ES__RESTRICT format, ...) const char *ES__RESTRICT format, ...)
_ESTREAM_GCC_A_PRINTF(2,3); _ESTREAM_GCC_A_PRINTF(2,3);
int es_printf (const char *ES__RESTRICT format, ...)
_ESTREAM_GCC_A_PRINTF(1,2);
int es_printf_unlocked (const char *ES__RESTRICT format, ...)
_ESTREAM_GCC_A_PRINTF(1,2);
int es_vfprintf (estream_t ES__RESTRICT stream, int es_vfprintf (estream_t ES__RESTRICT stream,
const char *ES__RESTRICT format, va_list ap) const char *ES__RESTRICT format, va_list ap)
_ESTREAM_GCC_A_PRINTF(2,0); _ESTREAM_GCC_A_PRINTF(2,0);

View File

@ -120,19 +120,24 @@ struct fun_cookie_s
/* Write NBYTES of BUFFER to file descriptor FD. */ /* Write NBYTES of BUFFER to file descriptor FD. */
static int static int
writen (int fd, const void *buffer, size_t nbytes) writen (int fd, const void *buffer, size_t nbytes, int is_socket)
{ {
const char *buf = buffer; const char *buf = buffer;
size_t nleft = nbytes; size_t nleft = nbytes;
int nwritten; int nwritten;
#ifndef HAVE_W32_SYSTEM
(void)is_socket; /* Not required. */
#endif
while (nleft > 0) while (nleft > 0)
{ {
#ifdef HAVE_W32_SYSTEM #ifdef HAVE_W32_SYSTEM
nwritten = send (fd, buf, nleft, 0); if (is_socket)
#else nwritten = send (fd, buf, nleft, 0);
nwritten = write (fd, buf, nleft); else
#endif #endif
nwritten = write (fd, buf, nleft);
if (nwritten < 0 && errno == EINTR) if (nwritten < 0 && errno == EINTR)
continue; continue;
if (nwritten < 0) if (nwritten < 0)
@ -171,6 +176,9 @@ fun_writer (void *cookie_arg, const void *buffer, size_t size)
{ {
struct fun_cookie_s *cookie = cookie_arg; struct fun_cookie_s *cookie = cookie_arg;
/* FIXME: Use only estream with a callback for socket writing. This
avoids the ugly mix of fd and estream code. */
/* Note that we always try to reconnect to the socket but print /* Note that we always try to reconnect to the socket but print
error messages only the first time an error occured. If error messages only the first time an error occured. If
RUNNING_DETACHED is set we don't fall back to stderr and even do RUNNING_DETACHED is set we don't fall back to stderr and even do
@ -345,7 +353,7 @@ fun_writer (void *cookie_arg, const void *buffer, size_t size)
} }
log_socket = cookie->fd; log_socket = cookie->fd;
if (cookie->fd != -1 && !writen (cookie->fd, buffer, size)) if (cookie->fd != -1 && !writen (cookie->fd, buffer, size, cookie->is_socket))
return (ssize_t)size; /* Okay. */ return (ssize_t)size; /* Okay. */
if (!running_detached && cookie->fd != -1 if (!running_detached && cookie->fd != -1
@ -561,7 +569,16 @@ do_logv (int level, int ignore_arg_ptr, const char *fmt, va_list arg_ptr)
{ {
if (!logstream) if (!logstream)
{ {
#ifdef HAVE_W32_SYSTEM
char *tmp;
tmp = read_w32_registry_string (NULL, "Software\\GNU\\GnuPG",
"DefaultLogFile");
log_set_file (tmp);
jnlib_free (tmp);
#else
log_set_file (NULL); /* Make sure a log stream has been set. */ log_set_file (NULL); /* Make sure a log stream has been set. */
#endif
assert (logstream); assert (logstream);
} }

View File

@ -24,6 +24,7 @@
#include <stdio.h> #include <stdio.h>
#include "estream.h" #include "estream.h"
#include "mischelp.h" #include "mischelp.h"
#include "w32help.h"
/* Flag values for log_set_prefix. */ /* Flag values for log_set_prefix. */
#define JNLIB_LOG_WITH_PREFIX 1 #define JNLIB_LOG_WITH_PREFIX 1

View File

@ -1,3 +1,7 @@
2010-08-18 Werner Koch <wk@g10code.com>
* tools.texi (watchgnupg): Add examples section.
2010-06-10 Werner Koch <wk@g10code.com> 2010-06-10 Werner Koch <wk@g10code.com>
* Makefile.am (gnupg_TEXINFOS): Add dirmngr.texi. * Makefile.am (gnupg_TEXINFOS): Add dirmngr.texi.

View File

@ -42,11 +42,12 @@ GnuPG comes with a couple of smaller tools:
@end ifset @end ifset
@mansect description @mansect description
Most of the main utilities are able to write their log files to a Most of the main utilities are able to write their log files to a Unix
Unix Domain socket if configured that way. @command{watchgnupg} is a simple Domain socket if configured that way. @command{watchgnupg} is a simple
listener for such a socket. It ameliorates the output with a time listener for such a socket. It ameliorates the output with a time stamp
stamp and makes sure that long lines are not interspersed with log and makes sure that long lines are not interspersed with log output from
output from other utilities. other utilities. This tool is not available for Windows.
@noindent @noindent
@command{watchgnupg} is commonly invoked as @command{watchgnupg} is commonly invoked as
@ -70,6 +71,10 @@ This starts it on the current terminal for listening on the socket
@opindex force @opindex force
Delete an already existing socket file. Delete an already existing socket file.
@item --tcp @var{n}
Instead of reading from a local socket, listen for connects on TCP port
@var{n}.
@item --verbose @item --verbose
@opindex verbose @opindex verbose
Enable extra informational output. Enable extra informational output.
@ -84,6 +89,41 @@ Display a brief help page and exit.
@end table @end table
@noindent
@mansect examples
@chapheading Examples
@example
$ watchgnupg --force /home/foo/.gnupg/S.log
@end example
This waits for connections on the local socket
@file{/home/foo/.gnupg/S.log} and shows all log entries. To make this
work the option @option{log-file} needs to be used with all modules
which logs are to be shown. The value for that option must be given
with a special prefix (e.g. in the conf file):
@example
log-file socket:///home/foo/.gnupg/S.log
@end example
For debugging purposes it is also possible to do remote logging. Take
care if you use this feature because the information is send in the
clear over the network. Use this syntax in the conf files:
@example
log-file tcp://192.168.1.1:4711
@end example
You may use any port and not just 4711 as shown above; only IP addresses
are supported (v4 and v6) and no host names. You need to start
@command{watchgnupg} with the @option{tcp} option. Note that under
Windows the registry entry @var{HKCU\Software\GNU\GnuPG:DefaultLogFile}
can be used to change the default log output from @code{stderr} to
whatever is given by that entry. However the only useful entry is a TCP
name for remote debugging.
@mansect see also @mansect see also
@ifset isman @ifset isman
@command{gpg}(1), @command{gpg}(1),

View File

@ -1,3 +1,9 @@
2010-08-16 Werner Koch <wk@g10code.com>
* gpg.c (list_config, gpgconf_list): Use es_printf.
(print_hex, print_hashline, print_algo_numbers)
(print_algo_names): Use es_printf.
2010-07-20 Werner Koch <wk@g10code.com> 2010-07-20 Werner Koch <wk@g10code.com>
* mainproc.c (print_pkenc_list): Write a STATUS_ERROR. Fixes * mainproc.c (print_pkenc_list): Write a STATUS_ERROR. Fixes

165
g10/gpg.c
View File

@ -1449,8 +1449,8 @@ print_algo_numbers(int (*checker)(int))
if(first) if(first)
first=0; first=0;
else else
printf(";"); es_printf (";");
printf("%d",i); es_printf ("%d",i);
} }
} }
} }
@ -1468,8 +1468,8 @@ print_algo_names(int (*checker)(int),const char *(*mapper)(int))
if(first) if(first)
first=0; first=0;
else else
printf(";"); es_printf (";");
printf("%s",mapper(i)); es_printf ("%s",mapper(i));
} }
} }
} }
@ -1508,10 +1508,10 @@ list_config(char *items)
{ {
print_sanitized_string2 (stdout, sl->d, ':',';'); print_sanitized_string2 (stdout, sl->d, ':',';');
if(sl->next) if(sl->next)
printf(";"); es_printf(";");
} }
printf("\n"); es_printf("\n");
} }
any=1; any=1;
@ -1519,33 +1519,33 @@ list_config(char *items)
if(show_all || ascii_strcasecmp(name,"version")==0) if(show_all || ascii_strcasecmp(name,"version")==0)
{ {
printf("cfg:version:"); es_printf("cfg:version:");
es_write_sanitized (es_stdout, VERSION, strlen(VERSION), ":", NULL); es_write_sanitized (es_stdout, VERSION, strlen(VERSION), ":", NULL);
printf("\n"); es_printf ("\n");
any=1; any=1;
} }
if(show_all || ascii_strcasecmp(name,"pubkey")==0) if(show_all || ascii_strcasecmp(name,"pubkey")==0)
{ {
printf("cfg:pubkey:"); es_printf ("cfg:pubkey:");
print_algo_numbers (openpgp_pk_test_algo); print_algo_numbers (openpgp_pk_test_algo);
printf("\n"); es_printf ("\n");
any=1; any=1;
} }
if(show_all || ascii_strcasecmp(name,"cipher")==0) if(show_all || ascii_strcasecmp(name,"cipher")==0)
{ {
printf("cfg:cipher:"); es_printf ("cfg:cipher:");
print_algo_numbers(openpgp_cipher_test_algo); print_algo_numbers(openpgp_cipher_test_algo);
printf("\n"); es_printf ("\n");
any=1; any=1;
} }
if (show_all || !ascii_strcasecmp (name,"ciphername")) if (show_all || !ascii_strcasecmp (name,"ciphername"))
{ {
printf ("cfg:ciphername:"); es_printf ("cfg:ciphername:");
print_algo_names (openpgp_cipher_test_algo,openpgp_cipher_algo_name); print_algo_names (openpgp_cipher_test_algo,openpgp_cipher_algo_name);
printf ("\n"); es_printf ("\n");
any = 1; any = 1;
} }
@ -1553,9 +1553,9 @@ list_config(char *items)
|| ascii_strcasecmp(name,"digest")==0 || ascii_strcasecmp(name,"digest")==0
|| ascii_strcasecmp(name,"hash")==0) || ascii_strcasecmp(name,"hash")==0)
{ {
printf("cfg:digest:"); es_printf ("cfg:digest:");
print_algo_numbers(openpgp_md_test_algo); print_algo_numbers(openpgp_md_test_algo);
printf("\n"); es_printf ("\n");
any=1; any=1;
} }
@ -1563,17 +1563,17 @@ list_config(char *items)
|| !ascii_strcasecmp(name,"digestname") || !ascii_strcasecmp(name,"digestname")
|| !ascii_strcasecmp(name,"hashname")) || !ascii_strcasecmp(name,"hashname"))
{ {
printf ("cfg:digestname:"); es_printf ("cfg:digestname:");
print_algo_names (openpgp_md_test_algo, gcry_md_algo_name); print_algo_names (openpgp_md_test_algo, gcry_md_algo_name);
printf("\n"); es_printf ("\n");
any=1; any=1;
} }
if(show_all || ascii_strcasecmp(name,"compress")==0) if(show_all || ascii_strcasecmp(name,"compress")==0)
{ {
printf("cfg:compress:"); es_printf ("cfg:compress:");
print_algo_numbers(check_compress_algo); print_algo_numbers(check_compress_algo);
printf("\n"); es_printf ("\n");
any=1; any=1;
} }
@ -1587,7 +1587,7 @@ list_config(char *items)
for (p=list; p && (p2 = strchr (p, '\n')); p = p2+1) for (p=list; p && (p2 = strchr (p, '\n')); p = p2+1)
{ {
*p2 = 0; *p2 = 0;
printf("cfg:ccid-reader-id:%s\n", p); es_printf ("cfg:ccid-reader-id:%s\n", p);
} }
free (list); free (list);
#endif #endif
@ -1613,23 +1613,24 @@ gpgconf_list (const char *configfile)
{ {
char *configfile_esc = percent_escape (configfile, NULL); char *configfile_esc = percent_escape (configfile, NULL);
printf ("gpgconf-gpg.conf:%lu:\"%s\n", es_printf ("gpgconf-gpg.conf:%lu:\"%s\n",
GC_OPT_FLAG_DEFAULT, configfile_esc ? configfile_esc : "/dev/null"); GC_OPT_FLAG_DEFAULT,
printf ("verbose:%lu:\n", GC_OPT_FLAG_NONE); configfile_esc ? configfile_esc : "/dev/null");
printf ("quiet:%lu:\n", GC_OPT_FLAG_NONE); es_printf ("verbose:%lu:\n", GC_OPT_FLAG_NONE);
printf ("keyserver:%lu:\n", GC_OPT_FLAG_NONE); es_printf ("quiet:%lu:\n", GC_OPT_FLAG_NONE);
printf ("reader-port:%lu:\n", GC_OPT_FLAG_NONE); es_printf ("keyserver:%lu:\n", GC_OPT_FLAG_NONE);
printf ("default-key:%lu:\n", GC_OPT_FLAG_NONE); es_printf ("reader-port:%lu:\n", GC_OPT_FLAG_NONE);
printf ("encrypt-to:%lu:\n", GC_OPT_FLAG_NONE); es_printf ("default-key:%lu:\n", GC_OPT_FLAG_NONE);
printf ("auto-key-locate:%lu:\n", GC_OPT_FLAG_NONE); es_printf ("encrypt-to:%lu:\n", GC_OPT_FLAG_NONE);
printf ("log-file:%lu:\n", GC_OPT_FLAG_NONE); es_printf ("auto-key-locate:%lu:\n", GC_OPT_FLAG_NONE);
printf ("debug-level:%lu:\"none:\n", GC_OPT_FLAG_DEFAULT); es_printf ("log-file:%lu:\n", GC_OPT_FLAG_NONE);
printf ("group:%lu:\n", GC_OPT_FLAG_NONE); es_printf ("debug-level:%lu:\"none:\n", GC_OPT_FLAG_DEFAULT);
es_printf ("group:%lu:\n", GC_OPT_FLAG_NONE);
/* The next one is an info only item and should match the macros at /* The next one is an info only item and should match the macros at
the top of keygen.c */ the top of keygen.c */
printf ("default_pubkey_algo:%lu:\"%s:\n", GC_OPT_FLAG_DEFAULT, es_printf ("default_pubkey_algo:%lu:\"%s:\n", GC_OPT_FLAG_DEFAULT,
"RSA-2048"); "RSA-2048");
xfree (configfile_esc); xfree (configfile_esc);
} }
@ -2992,11 +2993,12 @@ main (int argc, char **argv)
if( nogreeting ) if( nogreeting )
greeting = 0; greeting = 0;
if( greeting ) { if( greeting )
fprintf(stderr, "%s %s; %s\n", {
strusage(11), strusage(13), strusage(14) ); es_fprintf (es_stderr, "%s %s; %s\n",
fprintf(stderr, "%s\n", strusage(15) ); strusage(11), strusage(13), strusage(14) );
} es_fprintf (es_stderr, "%s\n", strusage(15) );
}
#ifdef IS_DEVELOPMENT_VERSION #ifdef IS_DEVELOPMENT_VERSION
if (!opt.batch) if (!opt.batch)
{ {
@ -4092,33 +4094,33 @@ g10_exit( int rc )
display, but there are a few other similar assumptions in the display, but there are a few other similar assumptions in the
display code. */ display code. */
static void static void
print_hex( gcry_md_hd_t md, int algo, const char *fname ) print_hex (gcry_md_hd_t md, int algo, const char *fname)
{ {
int i,n,count,indent=0; int i,n,count,indent=0;
const byte *p; const byte *p;
if(fname) if (fname)
indent=printf("%s: ",fname); indent = es_printf("%s: ",fname);
if(indent>40) if (indent>40)
{ {
printf("\n"); printf("\n");
indent=0; indent=0;
} }
if(algo==DIGEST_ALGO_RMD160) if (algo==DIGEST_ALGO_RMD160)
indent+=printf("RMD160 = "); indent += es_printf("RMD160 = ");
else if(algo>0) else if (algo>0)
indent+=printf("%6s = ", gcry_md_algo_name (algo)); indent += es_printf("%6s = ", gcry_md_algo_name (algo));
else else
algo=abs(algo); algo = abs(algo);
count=indent; count = indent;
p = gcry_md_read (md, algo); p = gcry_md_read (md, algo);
n = gcry_md_get_algo_dlen (algo); n = gcry_md_get_algo_dlen (algo);
count += printf ("%02X",*p++); count += es_printf ("%02X",*p++);
for(i=1;i<n;i++,p++) for(i=1;i<n;i++,p++)
{ {
@ -4126,14 +4128,14 @@ print_hex( gcry_md_hd_t md, int algo, const char *fname )
{ {
if(count+2>79) if(count+2>79)
{ {
printf("\n%*s",indent," "); es_printf ("\n%*s",indent," ");
count=indent; count = indent;
} }
else else
count+=printf(" "); count += es_printf(" ");
if(!(i%8)) if (!(i%8))
count+=printf(" "); count += es_printf(" ");
} }
else if (n==20) else if (n==20)
{ {
@ -4141,58 +4143,59 @@ print_hex( gcry_md_hd_t md, int algo, const char *fname )
{ {
if(count+4>79) if(count+4>79)
{ {
printf("\n%*s",indent," "); es_printf ("\n%*s",indent," ");
count=indent; count=indent;
} }
else else
count+=printf(" "); count += es_printf(" ");
} }
if(!(i%10)) if (!(i%10))
count+=printf(" "); count += es_printf(" ");
} }
else else
{ {
if(!(i%4)) if(!(i%4))
{ {
if(count+8>79) if (count+8>79)
{ {
printf("\n%*s",indent," "); es_printf ("\n%*s",indent," ");
count=indent; count=indent;
} }
else else
count+=printf(" "); count += es_printf(" ");
} }
} }
count+=printf("%02X",*p); count += es_printf("%02X",*p);
} }
printf("\n"); es_printf ("\n");
} }
static void static void
print_hashline( gcry_md_hd_t md, int algo, const char *fname ) print_hashline( gcry_md_hd_t md, int algo, const char *fname )
{ {
int i, n; int i, n;
const byte *p; const byte *p;
if ( fname ) { if ( fname )
for (p = fname; *p; p++ ) { {
if ( *p <= 32 || *p > 127 || *p == ':' || *p == '%' ) for (p = fname; *p; p++ )
printf("%%%02X", *p ); {
else if ( *p <= 32 || *p > 127 || *p == ':' || *p == '%' )
putchar( *p ); es_printf ("%%%02X", *p );
else
es_putc (*p, es_stdout);
} }
} }
putchar(':'); es_putc (':', es_stdout);
printf("%d:", algo ); es_printf ("%d:", algo);
p = gcry_md_read (md, algo); p = gcry_md_read (md, algo);
n = gcry_md_get_algo_dlen (algo); n = gcry_md_get_algo_dlen (algo);
for(i=0; i < n ; i++, p++ ) for(i=0; i < n ; i++, p++ )
printf("%02X", *p ); es_printf ("%02X", *p);
putchar(':'); es_fputs (":\n", es_stdout);
putchar('\n');
} }
static void static void

View File

@ -1,3 +1,7 @@
2010-08-16 Werner Koch <wk@g10code.com>
* scdaemon.c: Replace remaining printf by es_printf.
2010-06-09 Werner Koch <wk@g10code.com> 2010-06-09 Werner Koch <wk@g10code.com>
* scdaemon.c (main): s/log_set_get_tid_callback/log_set_pid_suffix_cb/. * scdaemon.c (main): s/log_set_get_tid_callback/log_set_pid_suffix_cb/.

View File

@ -617,9 +617,9 @@ main (int argc, char **argv )
if (greeting) if (greeting)
{ {
fprintf (stderr, "%s %s; %s\n", es_fprintf (es_stderr, "%s %s; %s\n",
strusage(11), strusage(13), strusage(14) ); strusage(11), strusage(13), strusage(14) );
fprintf (stderr, "%s\n", strusage(15) ); es_fprintf (es_stderr, "%s\n", strusage(15) );
} }
#ifdef IS_DEVELOPMENT_VERSION #ifdef IS_DEVELOPMENT_VERSION
log_info ("NOTE: this is a development version!\n"); log_info ("NOTE: this is a development version!\n");
@ -651,30 +651,30 @@ main (int argc, char **argv )
filename = make_filename (opt.homedir, "scdaemon.conf", NULL); filename = make_filename (opt.homedir, "scdaemon.conf", NULL);
filename_esc = percent_escape (filename, NULL); filename_esc = percent_escape (filename, NULL);
printf ("gpgconf-scdaemon.conf:%lu:\"%s\n", es_printf ("gpgconf-scdaemon.conf:%lu:\"%s\n",
GC_OPT_FLAG_DEFAULT, filename_esc); GC_OPT_FLAG_DEFAULT, filename_esc);
xfree (filename_esc); xfree (filename_esc);
xfree (filename); xfree (filename);
printf ("verbose:%lu:\n" es_printf ("verbose:%lu:\n"
"quiet:%lu:\n" "quiet:%lu:\n"
"debug-level:%lu:\"none:\n" "debug-level:%lu:\"none:\n"
"log-file:%lu:\n", "log-file:%lu:\n",
GC_OPT_FLAG_NONE, GC_OPT_FLAG_NONE,
GC_OPT_FLAG_NONE, GC_OPT_FLAG_NONE,
GC_OPT_FLAG_DEFAULT, GC_OPT_FLAG_DEFAULT,
GC_OPT_FLAG_NONE ); GC_OPT_FLAG_NONE );
printf ("reader-port:%lu:\n", GC_OPT_FLAG_NONE ); es_printf ("reader-port:%lu:\n", GC_OPT_FLAG_NONE );
printf ("ctapi-driver:%lu:\n", GC_OPT_FLAG_NONE ); es_printf ("ctapi-driver:%lu:\n", GC_OPT_FLAG_NONE );
printf ("pcsc-driver:%lu:\"%s:\n", es_printf ("pcsc-driver:%lu:\"%s:\n",
GC_OPT_FLAG_DEFAULT, DEFAULT_PCSC_DRIVER ); GC_OPT_FLAG_DEFAULT, DEFAULT_PCSC_DRIVER );
#ifdef HAVE_LIBUSB #ifdef HAVE_LIBUSB
printf ("disable-ccid:%lu:\n", GC_OPT_FLAG_NONE ); es_printf ("disable-ccid:%lu:\n", GC_OPT_FLAG_NONE );
#endif #endif
printf ("deny-admin:%lu:\n", GC_OPT_FLAG_NONE ); es_printf ("deny-admin:%lu:\n", GC_OPT_FLAG_NONE );
printf ("disable-keypad:%lu:\n", GC_OPT_FLAG_NONE ); es_printf ("disable-keypad:%lu:\n", GC_OPT_FLAG_NONE );
printf ("card-timeout:%lu:%d:\n", GC_OPT_FLAG_DEFAULT, 0); es_printf ("card-timeout:%lu:%d:\n", GC_OPT_FLAG_DEFAULT, 0);
scd_exit (0); scd_exit (0);
} }
@ -831,11 +831,11 @@ main (int argc, char **argv )
if (csh_style) if (csh_style)
{ {
*strchr (infostr, '=') = ' '; *strchr (infostr, '=') = ' ';
printf ( "setenv %s\n", infostr); es_printf ( "setenv %s\n", infostr);
} }
else else
{ {
printf ( "%s; export SCDAEMON_INFO;\n", infostr); es_printf ( "%s; export SCDAEMON_INFO;\n", infostr);
} }
xfree (infostr); xfree (infostr);
exit (0); exit (0);

View File

@ -1,5 +1,7 @@
2010-08-16 Werner Koch <wk@g10code.com> 2010-08-16 Werner Koch <wk@g10code.com>
* gpgsm.c (main) <aGPGConfList>: Use es_printf.
* call-dirmngr.c (start_dirmngr_ext): Use new start_new_dirmngr * call-dirmngr.c (start_dirmngr_ext): Use new start_new_dirmngr
function. function.

View File

@ -908,7 +908,7 @@ main ( int argc, char **argv)
log_set_prefix ("gpgsm", 1); log_set_prefix ("gpgsm", 1);
/* Make sure that our subsystems are ready. */ /* Make sure that our subsystems are ready. */
i18n_init(); i18n_init ();
init_common_subsystems (&argc, &argv); init_common_subsystems (&argc, &argv);
/* Check that the libraries are suitable. Do it here because the /* Check that the libraries are suitable. Do it here because the
@ -1429,9 +1429,9 @@ main ( int argc, char **argv)
if (greeting) if (greeting)
{ {
fprintf(stderr, "%s %s; %s\n", es_fprintf (es_stderr, "%s %s; %s\n",
strusage(11), strusage(13), strusage(14) ); strusage(11), strusage(13), strusage(14) );
fprintf(stderr, "%s\n", strusage(15) ); es_fprintf (es_stderr, "%s\n", strusage(15) );
} }
# ifdef IS_DEVELOPMENT_VERSION # ifdef IS_DEVELOPMENT_VERSION
if (!opt.batch) if (!opt.batch)
@ -1638,33 +1638,33 @@ main ( int argc, char **argv)
{ /* List options and default values in the GPG Conf format. */ { /* List options and default values in the GPG Conf format. */
char *config_filename_esc = percent_escape (opt.config_filename, NULL); char *config_filename_esc = percent_escape (opt.config_filename, NULL);
printf ("gpgconf-gpgsm.conf:%lu:\"%s\n", es_printf ("gpgconf-gpgsm.conf:%lu:\"%s\n",
GC_OPT_FLAG_DEFAULT, config_filename_esc); GC_OPT_FLAG_DEFAULT, config_filename_esc);
xfree (config_filename_esc); xfree (config_filename_esc);
printf ("verbose:%lu:\n", GC_OPT_FLAG_NONE); es_printf ("verbose:%lu:\n", GC_OPT_FLAG_NONE);
printf ("quiet:%lu:\n", GC_OPT_FLAG_NONE); es_printf ("quiet:%lu:\n", GC_OPT_FLAG_NONE);
printf ("debug-level:%lu:\"none:\n", GC_OPT_FLAG_DEFAULT); es_printf ("debug-level:%lu:\"none:\n", GC_OPT_FLAG_DEFAULT);
printf ("log-file:%lu:\n", GC_OPT_FLAG_NONE); es_printf ("log-file:%lu:\n", GC_OPT_FLAG_NONE);
printf ("disable-crl-checks:%lu:\n", GC_OPT_FLAG_NONE); es_printf ("disable-crl-checks:%lu:\n", GC_OPT_FLAG_NONE);
printf ("disable-trusted-cert-crl-check:%lu:\n", GC_OPT_FLAG_NONE); es_printf ("disable-trusted-cert-crl-check:%lu:\n", GC_OPT_FLAG_NONE);
printf ("enable-ocsp:%lu:\n", GC_OPT_FLAG_NONE); es_printf ("enable-ocsp:%lu:\n", GC_OPT_FLAG_NONE);
printf ("include-certs:%lu:%d:\n", GC_OPT_FLAG_DEFAULT, es_printf ("include-certs:%lu:%d:\n", GC_OPT_FLAG_DEFAULT,
DEFAULT_INCLUDE_CERTS); DEFAULT_INCLUDE_CERTS);
printf ("disable-policy-checks:%lu:\n", GC_OPT_FLAG_NONE); es_printf ("disable-policy-checks:%lu:\n", GC_OPT_FLAG_NONE);
printf ("auto-issuer-key-retrieve:%lu:\n", GC_OPT_FLAG_NONE); es_printf ("auto-issuer-key-retrieve:%lu:\n", GC_OPT_FLAG_NONE);
printf ("disable-dirmngr:%lu:\n", GC_OPT_FLAG_NONE); es_printf ("disable-dirmngr:%lu:\n", GC_OPT_FLAG_NONE);
printf ("cipher-algo:%lu:\"%s:\n", GC_OPT_FLAG_DEFAULT, es_printf ("cipher-algo:%lu:\"%s:\n", GC_OPT_FLAG_DEFAULT,
DEFAULT_CIPHER_ALGO); DEFAULT_CIPHER_ALGO);
printf ("p12-charset:%lu:\n", GC_OPT_FLAG_DEFAULT); es_printf ("p12-charset:%lu:\n", GC_OPT_FLAG_DEFAULT);
printf ("default-key:%lu:\n", GC_OPT_FLAG_DEFAULT); es_printf ("default-key:%lu:\n", GC_OPT_FLAG_DEFAULT);
printf ("encrypt-to:%lu:\n", GC_OPT_FLAG_DEFAULT); es_printf ("encrypt-to:%lu:\n", GC_OPT_FLAG_DEFAULT);
printf ("keyserver:%lu:\n", GC_OPT_FLAG_NONE); es_printf ("keyserver:%lu:\n", GC_OPT_FLAG_NONE);
/* The next one is an info only item and should match what /* The next one is an info only item and should match what
proc_parameters actually implements. */ proc_parameters actually implements. */
printf ("default_pubkey_algo:%lu:\"%s:\n", GC_OPT_FLAG_DEFAULT, es_printf ("default_pubkey_algo:%lu:\"%s:\n", GC_OPT_FLAG_DEFAULT,
"RSA-2048"); "RSA-2048");
} }
break; break;

View File

@ -1,3 +1,13 @@
2010-08-16 Werner Koch <wk@g10code.com>
* gpgconf.c (get_outfp): Change to use estream.
(main): Replace fprintf by es_fprintf.
* gpgconf-comp.c (gc_component_list_components)
(gc_check_programs, gc_component_list_options)
(gc_component_change_options, gc_component_check_options)
(list_one_option, gc_process_gpgconf_conf): Replace FILE* args by
estream_t.
2010-08-13 Werner Koch <wk@g10code.com> 2010-08-13 Werner Koch <wk@g10code.com>
* Makefile.am (gpgkey2ssh_LDADD): Add NETLIBS. * Makefile.am (gpgkey2ssh_LDADD): Add NETLIBS.

View File

@ -994,7 +994,9 @@ do_open (char *line)
if (fd >= 0 && fd < DIM (open_fd_table)) if (fd >= 0 && fd < DIM (open_fd_table))
{ {
open_fd_table[fd].inuse = 1; open_fd_table[fd].inuse = 1;
#warning fixme: implement our pipe emulation. #ifdef HAVE_W32CE_SYSTEM
# warning fixme: implement our pipe emulation.
#endif
#if defined(HAVE_W32_SYSTEM) && !defined(HAVE_W32CE_SYSTEM) #if defined(HAVE_W32_SYSTEM) && !defined(HAVE_W32CE_SYSTEM)
{ {
HANDLE prochandle, handle, newhandle; HANDLE prochandle, handle, newhandle;
@ -1246,11 +1248,11 @@ main (int argc, char **argv)
if (opt.exec) if (opt.exec)
{ {
int no_close[3]; assuan_fd_t no_close[3];
no_close[0] = assuan_fd_from_posix_fd (fileno (stderr)); no_close[0] = assuan_fd_from_posix_fd (es_fileno (es_stderr));
no_close[1] = assuan_fd_from_posix_fd (log_get_fd ()); no_close[1] = assuan_fd_from_posix_fd (log_get_fd ());
no_close[2] = -1; no_close[2] = ASSUAN_INVALID_FD;
rc = assuan_new (&ctx); rc = assuan_new (&ctx);
if (rc) if (rc)

View File

@ -1284,7 +1284,7 @@ percent_deescape (const char *src)
/* List all components that are available. */ /* List all components that are available. */
void void
gc_component_list_components (FILE *out) gc_component_list_components (estream_t out)
{ {
gc_component_t component; gc_component_t component;
gc_option_t *option; gc_option_t *option;
@ -1320,9 +1320,9 @@ gc_component_list_components (FILE *out)
desc = gc_component[component].desc; desc = gc_component[component].desc;
desc = my_dgettext (gc_component[component].desc_domain, desc); desc = my_dgettext (gc_component[component].desc_domain, desc);
fprintf (out, "%s:%s:", es_fprintf (out, "%s:%s:",
gc_component[component].name, gc_percent_escape (desc)); gc_component[component].name, gc_percent_escape (desc));
fprintf (out, "%s\n", gc_percent_escape (pgmname)); es_fprintf (out, "%s\n", gc_percent_escape (pgmname));
} }
} }
} }
@ -1432,7 +1432,7 @@ collect_error_output (int fd, const char *tag)
/* Check the options of a single component. Returns 0 if everything /* Check the options of a single component. Returns 0 if everything
is OK. */ is OK. */
int int
gc_component_check_options (int component, FILE *out, const char *conf_file) gc_component_check_options (int component, estream_t out, const char *conf_file)
{ {
gpg_error_t err; gpg_error_t err;
unsigned int result; unsigned int result;
@ -1525,24 +1525,24 @@ gc_component_check_options (int component, FILE *out, const char *conf_file)
desc = gc_component[component].desc; desc = gc_component[component].desc;
desc = my_dgettext (gc_component[component].desc_domain, desc); desc = my_dgettext (gc_component[component].desc_domain, desc);
fprintf (out, "%s:%s:", es_fprintf (out, "%s:%s:",
gc_component[component].name, gc_percent_escape (desc)); gc_component[component].name, gc_percent_escape (desc));
fputs (gc_percent_escape (pgmname), out); es_fputs (gc_percent_escape (pgmname), out);
fprintf (out, ":%d:%d:", !(result & 1), !(result & 2)); es_fprintf (out, ":%d:%d:", !(result & 1), !(result & 2));
for (errptr = errlines; errptr; errptr = errptr->next) for (errptr = errlines; errptr; errptr = errptr->next)
{ {
if (errptr != errlines) if (errptr != errlines)
fputs ("\n:::::", out); /* Continuation line. */ es_fputs ("\n:::::", out); /* Continuation line. */
if (errptr->fname) if (errptr->fname)
fputs (gc_percent_escape (errptr->fname), out); es_fputs (gc_percent_escape (errptr->fname), out);
putc (':', out); es_putc (':', out);
if (errptr->fname) if (errptr->fname)
fprintf (out, "%u", errptr->lineno); es_fprintf (out, "%u", errptr->lineno);
putc (':', out); es_putc (':', out);
fputs (gc_percent_escape (errptr->errtext), out); es_fputs (gc_percent_escape (errptr->errtext), out);
putc (':', out); es_putc (':', out);
} }
putc ('\n', out); es_putc ('\n', out);
} }
while (errlines) while (errlines)
@ -1558,7 +1558,7 @@ gc_component_check_options (int component, FILE *out, const char *conf_file)
/* Check all components that are available. */ /* Check all components that are available. */
void void
gc_check_programs (FILE *out) gc_check_programs (estream_t out)
{ {
gc_component_t component; gc_component_t component;
@ -1587,7 +1587,7 @@ gc_component_find (const char *name)
/* List the option OPTION. */ /* List the option OPTION. */
static void static void
list_one_option (const gc_option_t *option, FILE *out) list_one_option (const gc_option_t *option, estream_t out)
{ {
const char *desc = NULL; const char *desc = NULL;
char *arg_name = NULL; char *arg_name = NULL;
@ -1617,16 +1617,16 @@ list_one_option (const gc_option_t *option, FILE *out)
FIELDS. */ FIELDS. */
/* The name field. */ /* The name field. */
fprintf (out, "%s", option->name); es_fprintf (out, "%s", option->name);
/* The flags field. */ /* The flags field. */
fprintf (out, ":%lu", option->flags); es_fprintf (out, ":%lu", option->flags);
if (opt.verbose) if (opt.verbose)
{ {
putc (' ', out); es_putc (' ', out);
if (!option->flags) if (!option->flags)
fprintf (out, "none"); es_fprintf (out, "none");
else else
{ {
unsigned long flags = option->flags; unsigned long flags = option->flags;
@ -1640,8 +1640,8 @@ list_one_option (const gc_option_t *option, FILE *out)
if (first) if (first)
first = 0; first = 0;
else else
putc (',', out); es_putc (',', out);
fprintf (out, "%s", gc_flag[flag].name); es_fprintf (out, "%s", gc_flag[flag].name);
} }
flags >>= 1; flags >>= 1;
flag++; flag++;
@ -1650,34 +1650,33 @@ list_one_option (const gc_option_t *option, FILE *out)
} }
/* The level field. */ /* The level field. */
fprintf (out, ":%u", option->level); es_fprintf (out, ":%u", option->level);
if (opt.verbose) if (opt.verbose)
fprintf (out, " %s", gc_level[option->level].name); es_fprintf (out, " %s", gc_level[option->level].name);
/* The description field. */ /* The description field. */
fprintf (out, ":%s", desc ? gc_percent_escape (desc) : ""); es_fprintf (out, ":%s", desc ? gc_percent_escape (desc) : "");
/* The type field. */ /* The type field. */
fprintf (out, ":%u", option->arg_type); es_fprintf (out, ":%u", option->arg_type);
if (opt.verbose) if (opt.verbose)
fprintf (out, " %s", gc_arg_type[option->arg_type].name); es_fprintf (out, " %s", gc_arg_type[option->arg_type].name);
/* The alternate type field. */ /* The alternate type field. */
fprintf (out, ":%u", gc_arg_type[option->arg_type].fallback); es_fprintf (out, ":%u", gc_arg_type[option->arg_type].fallback);
if (opt.verbose) if (opt.verbose)
fprintf (out, " %s", es_fprintf (out, " %s",
gc_arg_type[gc_arg_type[option->arg_type].fallback].name); gc_arg_type[gc_arg_type[option->arg_type].fallback].name);
/* The argument name field. */ /* The argument name field. */
fprintf (out, ":%s", arg_name ? gc_percent_escape (arg_name) : ""); es_fprintf (out, ":%s", arg_name ? gc_percent_escape (arg_name) : "");
if (arg_name) xfree (arg_name);
xfree (arg_name);
/* The default value field. */ /* The default value field. */
fprintf (out, ":%s", option->default_value ? option->default_value : ""); es_fprintf (out, ":%s", option->default_value ? option->default_value : "");
/* The default argument field. */ /* The default argument field. */
fprintf (out, ":%s", option->default_arg ? option->default_arg : ""); es_fprintf (out, ":%s", option->default_arg ? option->default_arg : "");
/* The value field. */ /* The value field. */
if (gc_arg_type[option->arg_type].fallback == GC_ARG_TYPE_NONE if (gc_arg_type[option->arg_type].fallback == GC_ARG_TYPE_NONE
@ -1685,19 +1684,19 @@ list_one_option (const gc_option_t *option, FILE *out)
&& option->value) && option->value)
/* The special format "1,1,1,1,...,1" is converted to a number /* The special format "1,1,1,1,...,1" is converted to a number
here. */ here. */
fprintf (out, ":%u", (unsigned int)((strlen (option->value) + 1) / 2)); es_fprintf (out, ":%u", (unsigned int)((strlen (option->value) + 1) / 2));
else else
fprintf (out, ":%s", option->value ? option->value : ""); es_fprintf (out, ":%s", option->value ? option->value : "");
/* ADD NEW FIELDS HERE. */ /* ADD NEW FIELDS HERE. */
putc ('\n', out); es_putc ('\n', out);
} }
/* List all options of the component COMPONENT. */ /* List all options of the component COMPONENT. */
void void
gc_component_list_options (int component, FILE *out) gc_component_list_options (int component, estream_t out)
{ {
const gc_option_t *option = gc_component[component].options; const gc_option_t *option = gc_component[component].options;
@ -2980,7 +2979,7 @@ change_one_value (gc_option_t *option, int *runtime,
modifications are expected to already have been set to the global modifications are expected to already have been set to the global
table. */ table. */
void void
gc_component_change_options (int component, FILE *in, FILE *out) gc_component_change_options (int component, estream_t in, estream_t out)
{ {
int err = 0; int err = 0;
int runtime[GC_BACKEND_NR]; int runtime[GC_BACKEND_NR];
@ -3004,7 +3003,7 @@ gc_component_change_options (int component, FILE *in, FILE *out)
if (in) if (in)
{ {
/* Read options from the file IN. */ /* Read options from the file IN. */
while ((length = read_line (in, &line, &line_len, NULL)) > 0) while ((length = es_read_line (in, &line, &line_len, NULL)) > 0)
{ {
char *linep; char *linep;
unsigned long flags = 0; unsigned long flags = 0;
@ -3347,7 +3346,7 @@ key_matches_user_or_group (char *user)
returned on error. */ returned on error. */
int int
gc_process_gpgconf_conf (const char *fname_arg, int update, int defaults, gc_process_gpgconf_conf (const char *fname_arg, int update, int defaults,
FILE *listfp) estream_t listfp)
{ {
int result = 0; int result = 0;
char *line = NULL; char *line = NULL;
@ -3560,19 +3559,19 @@ gc_process_gpgconf_conf (const char *fname_arg, int update, int defaults,
*p = 0; /* We better strip any extra stuff. */ *p = 0; /* We better strip any extra stuff. */
} }
fprintf (listfp, "k:%s:", gc_percent_escape (key)); es_fprintf (listfp, "k:%s:", gc_percent_escape (key));
fprintf (listfp, "%s\n", group? gc_percent_escape (group):""); es_fprintf (listfp, "%s\n", group? gc_percent_escape (group):"");
} }
/* All other lines are rule records. */ /* All other lines are rule records. */
fprintf (listfp, "r:::%s:%s:%s:", es_fprintf (listfp, "r:::%s:%s:%s:",
gc_component[component_id].name, gc_component[component_id].name,
option_info->name? option_info->name : "", option_info->name? option_info->name : "",
flags? flags : ""); flags? flags : "");
if (value != empty) if (value != empty)
fprintf (listfp, "\"%s", gc_percent_escape (value)); es_fprintf (listfp, "\"%s", gc_percent_escape (value));
putc ('\n', listfp); es_putc ('\n', listfp);
} }
/* Check whether the key matches but do this only if we are not /* Check whether the key matches but do this only if we are not

View File

@ -118,19 +118,19 @@ my_strusage( int level )
/* Return the fp for the output. This is usually stdout unless /* Return the fp for the output. This is usually stdout unless
--output has been used. In the latter case this function opens --output has been used. In the latter case this function opens
that file. */ that file. */
static FILE * static estream_t
get_outfp (FILE **fp) get_outfp (estream_t *fp)
{ {
if (!*fp) if (!*fp)
{ {
if (opt.outfile) if (opt.outfile)
{ {
*fp = fopen (opt.outfile, "w"); *fp = es_fopen (opt.outfile, "w");
if (!*fp) if (!*fp)
gc_error (1, errno, "can not open `%s'", opt.outfile); gc_error (1, errno, "can not open `%s'", opt.outfile);
} }
else else
*fp = stdout; *fp = es_stdout;
} }
return *fp; return *fp;
} }
@ -144,7 +144,7 @@ main (int argc, char **argv)
const char *fname; const char *fname;
int no_more_options = 0; int no_more_options = 0;
enum cmd_and_opt_values cmd = 0; enum cmd_and_opt_values cmd = 0;
FILE *outfp = NULL; estream_t outfp = NULL;
gnupg_reopen_std ("gpgconf"); gnupg_reopen_std ("gpgconf");
set_strusage (my_strusage); set_strusage (my_strusage);
@ -211,10 +211,10 @@ main (int argc, char **argv)
case aCheckOptions: case aCheckOptions:
if (!fname) if (!fname)
{ {
fputs (_("usage: gpgconf [options] "), stderr); es_fputs (_("usage: gpgconf [options] "), es_stderr);
putc ('\n',stderr); es_putc ('\n', es_stderr);
fputs (_("Need one component argument"), stderr); es_fputs (_("Need one component argument"), es_stderr);
putc ('\n',stderr); es_putc ('\n', es_stderr);
exit (2); exit (2);
} }
else else
@ -222,8 +222,8 @@ main (int argc, char **argv)
int idx = gc_component_find (fname); int idx = gc_component_find (fname);
if (idx < 0) if (idx < 0)
{ {
fputs (_("Component not found"), stderr); es_fputs (_("Component not found"), es_stderr);
putc ('\n', stderr); es_putc ('\n', es_stderr);
exit (1); exit (1);
} }
gc_component_retrieve_options (idx); gc_component_retrieve_options (idx);
@ -232,7 +232,7 @@ main (int argc, char **argv)
if (cmd == aListOptions) if (cmd == aListOptions)
gc_component_list_options (idx, get_outfp (&outfp)); gc_component_list_options (idx, get_outfp (&outfp));
else if (cmd == aChangeOptions) else if (cmd == aChangeOptions)
gc_component_change_options (idx, stdin, get_outfp (&outfp)); gc_component_change_options (idx, es_stdin, get_outfp (&outfp));
else else
gc_component_check_options (idx, get_outfp (&outfp), NULL); gc_component_check_options (idx, get_outfp (&outfp), NULL);
} }
@ -252,8 +252,8 @@ main (int argc, char **argv)
idx = gc_component_find (fname); idx = gc_component_find (fname);
if (idx < 0) if (idx < 0)
{ {
fputs (_("Component not found"), stderr); es_fputs (_("Component not found"), es_stderr);
putc ('\n', stderr); es_putc ('\n', es_stderr);
exit (1); exit (1);
} }
else else
@ -276,10 +276,10 @@ main (int argc, char **argv)
case aApplyDefaults: case aApplyDefaults:
if (fname) if (fname)
{ {
fputs (_("usage: gpgconf [options] "), stderr); es_fputs (_("usage: gpgconf [options] "), es_stderr);
putc ('\n',stderr); es_putc ('\n', es_stderr);
fputs (_("No argument allowed"), stderr); es_fputs (_("No argument allowed"), es_stderr);
putc ('\n',stderr); es_putc ('\n', es_stderr);
exit (2); exit (2);
} }
gc_component_retrieve_options (-1); gc_component_retrieve_options (-1);
@ -290,20 +290,20 @@ main (int argc, char **argv)
case aListDirs: case aListDirs:
/* Show the system configuration directories for gpgconf. */ /* Show the system configuration directories for gpgconf. */
get_outfp (&outfp); get_outfp (&outfp);
fprintf (outfp, "sysconfdir:%s\n", es_fprintf (outfp, "sysconfdir:%s\n",
gc_percent_escape (gnupg_sysconfdir ())); gc_percent_escape (gnupg_sysconfdir ()));
fprintf (outfp, "bindir:%s\n", es_fprintf (outfp, "bindir:%s\n",
gc_percent_escape (gnupg_bindir ())); gc_percent_escape (gnupg_bindir ()));
fprintf (outfp, "libexecdir:%s\n", es_fprintf (outfp, "libexecdir:%s\n",
gc_percent_escape (gnupg_libexecdir ())); gc_percent_escape (gnupg_libexecdir ()));
fprintf (outfp, "libdir:%s\n", es_fprintf (outfp, "libdir:%s\n",
gc_percent_escape (gnupg_libdir ())); gc_percent_escape (gnupg_libdir ()));
fprintf (outfp, "datadir:%s\n", es_fprintf (outfp, "datadir:%s\n",
gc_percent_escape (gnupg_datadir ())); gc_percent_escape (gnupg_datadir ()));
fprintf (outfp, "localedir:%s\n", es_fprintf (outfp, "localedir:%s\n",
gc_percent_escape (gnupg_localedir ())); gc_percent_escape (gnupg_localedir ()));
fprintf (outfp, "dirmngr-socket:%s\n", es_fprintf (outfp, "dirmngr-socket:%s\n",
gc_percent_escape (dirmngr_socket_name ())); gc_percent_escape (dirmngr_socket_name ()));
{ {
char *infostr = getenv ("GPG_AGENT_INFO"); char *infostr = getenv ("GPG_AGENT_INFO");
@ -323,21 +323,21 @@ main (int argc, char **argv)
else else
*tmp = 0; *tmp = 0;
} }
fprintf (outfp, "agent-socket:%s\n", es_fprintf (outfp, "agent-socket:%s\n",
infostr? gc_percent_escape (infostr) : ""); infostr? gc_percent_escape (infostr) : "");
xfree (infostr); xfree (infostr);
} }
{ {
/* We need to use make_filename to expand a possible "~/". */ /* We need to use make_filename to expand a possible "~/". */
char *tmp = make_filename (default_homedir (), NULL); char *tmp = make_filename (default_homedir (), NULL);
fprintf (outfp, "homedir:%s\n", gc_percent_escape (tmp)); es_fprintf (outfp, "homedir:%s\n", gc_percent_escape (tmp));
xfree (tmp); xfree (tmp);
} }
break; break;
} }
if (outfp && outfp != stdout) if (outfp != es_stdout)
if (fclose (outfp)) if (es_fclose (outfp))
gc_error (1, errno, "error closing `%s'", opt.outfile); gc_error (1, errno, "error closing `%s'", opt.outfile);
return 0; return 0;

View File

@ -48,10 +48,10 @@ void gc_error (int status, int errnum, const char *fmt, ...);
void gc_component_reload (int component); void gc_component_reload (int component);
/* List all components that are available. */ /* List all components that are available. */
void gc_component_list_components (FILE *out); void gc_component_list_components (estream_t out);
/* List all programs along with their status. */ /* List all programs along with their status. */
void gc_check_programs (FILE *out); void gc_check_programs (estream_t out);
/* Find the component with the name NAME. Returns -1 if not /* Find the component with the name NAME. Returns -1 if not
found. */ found. */
@ -62,19 +62,19 @@ int gc_component_find (const char *name);
void gc_component_retrieve_options (int component); void gc_component_retrieve_options (int component);
/* List all options of the component COMPONENT. */ /* List all options of the component COMPONENT. */
void gc_component_list_options (int component, FILE *out); void gc_component_list_options (int component, estream_t out);
/* Read the modifications from IN and apply them. */ /* Read the modifications from IN and apply them. */
void gc_component_change_options (int component, FILE *in, FILE *out); void gc_component_change_options (int component, estream_t in, estream_t out);
/* Check the options of a single component. Returns 0 if everything /* Check the options of a single component. Returns 0 if everything
is OK. */ is OK. */
int gc_component_check_options (int component, FILE *out, int gc_component_check_options (int component, estream_t out,
const char *conf_file); const char *conf_file);
/* Process global configuration file. */ /* Process global configuration file. */
int gc_process_gpgconf_conf (const char *fname, int update, int defaults, int gc_process_gpgconf_conf (const char *fname, int update, int defaults,
FILE *listfp); estream_t listfp);
#endif /*GPGCONF_H*/ #endif /*GPGCONF_H*/