[svn] GnuPG - r5294 - in trunk: . common doc g10 sm

svn author wk cvs at cvs.gnupg.org
Mon Mar 15 12:15:46 CET 2010


Author: wk
Date: 2010-03-15 12:15:45 +0100 (Mon, 15 Mar 2010)
New Revision: 5294

Modified:
   trunk/ChangeLog
   trunk/common/ChangeLog
   trunk/common/asshelp.c
   trunk/common/estream.c
   trunk/common/estream.h
   trunk/common/logging.c
   trunk/common/logging.h
   trunk/common/miscellaneous.c
   trunk/common/status.h
   trunk/common/ttyio.c
   trunk/common/ttyio.h
   trunk/common/util.h
   trunk/configure.ac
   trunk/doc/DETAILS
   trunk/g10/ChangeLog
   trunk/g10/armor.c
   trunk/g10/card-util.c
   trunk/g10/gpg.c
   trunk/g10/import.c
   trunk/g10/kbnode.c
   trunk/g10/keyedit.c
   trunk/g10/keylist.c
   trunk/g10/main.h
   trunk/g10/mainproc.c
   trunk/g10/misc.c
   trunk/g10/parse-packet.c
   trunk/g10/pkclist.c
   trunk/g10/plaintext.c
   trunk/g10/seckey-cert.c
   trunk/g10/trustdb.c
   trunk/sm/ChangeLog
   trunk/sm/verify.c
Log:
Finished the bulk of changes to use estream in most places instead of
stdio.


[The diff below has been truncated]

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2010-03-12 18:46:33 UTC (rev 5293)
+++ trunk/ChangeLog	2010-03-15 11:15:45 UTC (rev 5294)
@@ -1,3 +1,7 @@
+2010-03-12  Werner Koch  <wk at g10code.com>
+
+	* configure.ac (AC_INIT): Prepare for using git.
+
 2010-03-10  Werner Koch  <wk at g10code.com>
 
 	* jnlib/: Move all code to common/.

Modified: trunk/common/ChangeLog
===================================================================
--- trunk/common/ChangeLog	2010-03-12 18:46:33 UTC (rev 5293)
+++ trunk/common/ChangeLog	2010-03-15 11:15:45 UTC (rev 5294)
@@ -1,11 +1,27 @@
+2010-03-12  Werner Koch  <wk at g10code.com>
+
+	* status.h (STATUS_ENTER): New.
+
+	* ttyio.c (tty_fprintf): Change to use estream.
+
+	* miscellaneous.c (print_utf8_string): Rename to print_utf8_buffer
+	and change FP arg to an estream.  Change all callers.
+	(print_utf8_string2): Ditto; new name is to print_utf8_buffer2.
+
 2010-03-11  Werner Koch  <wk at g10code.com>
 
+	* miscellaneous.c (print_string): Remove.
+
 	* estream.c (es_setvbuf): Fix parameter check.
 	(es_set_buffering): Allow a SIZE of 0.
 	* asshelp.c (setup_libassuan_logging, my_libassuan_log_handler): New.
 	* logging.c (do_logv): Add arg IGNORE_ARG_PTR.  Change all callers.
 	(log_string): New.
+	(log_flush): New.
+	(set_file_fd): Simplify by using estreams es_stderr.
 
+	* estream.h (es_stdout, es_stderr, es_stdin): New.
+
 2010-03-10  Werner Koch  <wk at g10code.com>
 
 	* estream.c (es_func_fp_read, es_func_fp_write, es_func_fp_seek)

Modified: trunk/g10/ChangeLog
===================================================================
--- trunk/g10/ChangeLog	2010-03-12 18:46:33 UTC (rev 5293)
+++ trunk/g10/ChangeLog	2010-03-15 11:15:45 UTC (rev 5294)
@@ -1,5 +1,39 @@
+2010-03-15  Werner Koch  <wk at g10code.com>
+
+	* card-util.c: Replace stdio by estream.
+	* keylist.c: Ditto.
+
+2010-03-12  Werner Koch  <wk at g10code.com>
+
+	* plaintext.c (setup_plaintext_name): Do not encode pipe like
+	filenames.  This helps with bug#1201.
+
+	* seckey-cert.c (do_check): Return GPG_ERR_CANCELED.
+	* keyedit.c (change_passphrase): Add arg R_ERR.
+	(keyedit_passwd): Return the correct error or emit a success
+	status message.
+
 2010-03-11  Werner Koch  <wk at g10code.com>
 
+	* misc.c (mpi_print): Change to take a estream_t arg.
+
+	* parse-packet.c (listfp): Change to an estream_t.  Change all
+	users to use estream functions.
+
+	* kbnode.c (dump_kbnode): Change to use log functions.
+	* pkclist.c (do_show_revocation_reason): Ditto
+
+	* armor.c (parse_header_line): Replace print_string by
+	es_print_sanitized.
+	(fake_packet): Ditto.
+	* keyedit.c (print_and_check_one_sig_colon): Ditto.
+	(show_key_with_all_names_colon): Ditto.
+	(ask_revoke_sig): Ditto.
+	* keylist.c (list_keyblock_colon): Ditto.
+	* mainproc.c (print_userid, list_node): Ditto.
+	* trustdb.c (dump_key_array): Ditto.
+	* gpg.c (list_config): ditto.
+
 	* gpg.c: Include "asshelp.h".
 	(main): Remove assuan_set_assuan_log_prefix.  Add
 	assuan_set_log_cb.

Modified: trunk/sm/ChangeLog
===================================================================
--- trunk/sm/ChangeLog	2010-03-12 18:46:33 UTC (rev 5293)
+++ trunk/sm/ChangeLog	2010-03-15 11:15:45 UTC (rev 5294)
@@ -1,5 +1,7 @@
 2010-03-11  Werner Koch  <wk at g10code.com>
 
+	* verify.c (gpgsm_verify): Use gpgsm_es_print_name.
+
 	* gpgsm.c: Include "asshelp.h".
 	(main): Remove assuan_set_assuan_log_prefix.  Add
 	assuan_set_log_cb.

Modified: trunk/common/asshelp.c
===================================================================
--- trunk/common/asshelp.c	2010-03-12 18:46:33 UTC (rev 5293)
+++ trunk/common/asshelp.c	2010-03-15 11:15:45 UTC (rev 5294)
@@ -42,6 +42,8 @@
 {
   unsigned int dbgval;
 
+  (void)ctx;
+
   if (cat != ASSUAN_LOG_CONTROL)
     return 0; /* We only want the control channel messages.  */
   dbgval = hook? *(unsigned int*)hook : 0;

Modified: trunk/common/estream.c
===================================================================
--- trunk/common/estream.c	2010-03-12 18:46:33 UTC (rev 5293)
+++ trunk/common/estream.c	2010-03-15 11:15:45 UTC (rev 5294)
@@ -213,6 +213,8 @@
     unsigned int eof: 1;
   } indicators;
   unsigned int deallocate_buffer: 1;
+  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 print_err: 1;     /* Error in print_fun_writer.  */
   int print_errno;               /* Errno from print_fun_writer.  */
   size_t print_ntotal;           /* Bytes written from in print_fun_writer. */
@@ -302,9 +304,11 @@
  * List manipulation.
  */
 
-/* Add STREAM to the list of registered stream objects.  */
+/* Add STREAM to the list of registered stream objects.  If
+   WITH_LOCKED_LIST is true we assumed that the list of streams is
+   already locked.  */
 static int
-es_list_add (estream_t stream)
+es_list_add (estream_t stream, int with_locked_list)
 {
   estream_list_t list_obj;
   int ret;
@@ -314,14 +318,16 @@
     ret = -1;
   else
     {
-      ESTREAM_LIST_LOCK;
+      if (!with_locked_list)
+        ESTREAM_LIST_LOCK;
       list_obj->car = stream;
       list_obj->cdr = estream_list;
       list_obj->prev_cdr = &estream_list;
       if (estream_list)
 	estream_list->prev_cdr = &list_obj->cdr;
       estream_list = list_obj;
-      ESTREAM_LIST_UNLOCK;
+      if (!with_locked_list)
+        ESTREAM_LIST_UNLOCK;
       ret = 0;
     }
 
@@ -330,11 +336,12 @@
 
 /* Remove STREAM from the list of registered stream objects.  */
 static void
-es_list_remove (estream_t stream)
+es_list_remove (estream_t stream, int with_locked_list)
 {
   estream_list_t list_obj;
   
-  ESTREAM_LIST_LOCK;
+  if (!with_locked_list)
+    ESTREAM_LIST_LOCK;
   for (list_obj = estream_list; list_obj; list_obj = list_obj->cdr)
     if (list_obj->car == stream)
       {
@@ -344,7 +351,8 @@
 	mem_free (list_obj);
 	break;
       }
-  ESTREAM_LIST_UNLOCK;
+  if (!with_locked_list)
+    ESTREAM_LIST_UNLOCK;
 }
 
 /* Type of an stream-iterator-function.  */
@@ -1211,6 +1219,8 @@
   stream->intern->print_fp = NULL;
   stream->intern->indicators.err = 0;
   stream->intern->indicators.eof = 0;
+  stream->intern->is_stdstream = 0;
+  stream->intern->stdstream_fd = 0;
   stream->intern->deallocate_buffer = 0;
 
   stream->data_len = 0;
@@ -1219,7 +1229,7 @@
   stream->unread_data_len = 0;
   /* Depending on the modeflags we set whether we start in writing or
      reading mode.  This is required in case we are working on a
-     wronly stream which is not seeekable (like stdout).  Without this
+     stream which is not seeekable (like stdout).  Without this
      pre-initialization we would do a seek at the first write call and
      as this will fail no utput will be delivered. */
   if ((modeflags & O_WRONLY) || (modeflags & O_RDWR) )
@@ -1258,7 +1268,8 @@
 /* Create a new stream object, initialize it.  */
 static int
 es_create (estream_t *stream, void *cookie, int fd,
-	   es_cookie_io_functions_t functions, unsigned int modeflags)
+	   es_cookie_io_functions_t functions, unsigned int modeflags,
+           int with_locked_list)
 {
   estream_internal_t stream_internal_new;
   estream_t stream_new;
@@ -1290,7 +1301,7 @@
   ESTREAM_MUTEX_INITIALIZE (stream_new->intern->lock);
   es_initialize (stream_new, cookie, fd, functions, modeflags);
 
-  err = es_list_add (stream_new);
+  err = es_list_add (stream_new, with_locked_list);
   if (err)
     goto out;
 
@@ -1312,13 +1323,13 @@
 
 /* Deinitialize a stream object and destroy it.  */
 static int
-es_destroy (estream_t stream)
+es_destroy (estream_t stream, int with_locked_list)
 {
   int err = 0;
 
   if (stream)
     {
-      es_list_remove (stream);
+      es_list_remove (stream, with_locked_list);
       err = es_deinitialize (stream);
       mem_free (stream->intern);
       mem_free (stream);
@@ -1838,7 +1849,7 @@
     goto out;
 
   err = es_create (&line_stream, line_stream_cookie, -1,
-		   estream_functions_mem, O_RDWR);
+		   estream_functions_mem, O_RDWR, 0);
   if (err)
     goto out;
 
@@ -1923,7 +1934,7 @@
  out:
 
   if (line_stream)
-    es_destroy (line_stream);
+    es_destroy (line_stream, 0);
   else if (line_stream_cookie)
     es_func_mem_destroy (line_stream_cookie);
 
@@ -2122,7 +2133,7 @@
     goto out;
 
   create_called = 1;
-  err = es_create (&stream, cookie, fd, estream_functions_file, modeflags);
+  err = es_create (&stream, cookie, fd, estream_functions_file, modeflags, 0);
   if (err)
     goto out;
 
@@ -2162,7 +2173,7 @@
     goto out;
   
   create_called = 1;
-  err = es_create (&stream, cookie, -1, estream_functions_mem, modeflags);
+  err = es_create (&stream, cookie, -1, estream_functions_mem, modeflags, 0);
 
  out:
 
@@ -2193,7 +2204,7 @@
                           memlimit))
     return NULL;
   
-  if (es_create (&stream, cookie, -1, estream_functions_mem, modeflags))
+  if (es_create (&stream, cookie, -1, estream_functions_mem, modeflags, 0))
     (*estream_functions_mem.func_close) (cookie);
 
   return stream;
@@ -2217,7 +2228,7 @@
   if (err)
     goto out;
 
-  err = es_create (&stream, cookie, -1, functions, modeflags);
+  err = es_create (&stream, cookie, -1, functions, modeflags, 0);
   if (err)
     goto out;
 
@@ -2249,7 +2260,8 @@
     goto out;
 
   create_called = 1;
-  err = es_create (&stream, cookie, filedes, estream_functions_fd, modeflags);
+  err = es_create (&stream, cookie, filedes, estream_functions_fd,
+                   modeflags, 0);
 
  out:
 
@@ -2274,7 +2286,7 @@
 
 
 estream_t
-do_fpopen (FILE *fp, const char *mode, int no_close)
+do_fpopen (FILE *fp, const char *mode, int no_close, int with_locked_list)
 {
   unsigned int modeflags;
   int create_called;
@@ -2298,7 +2310,7 @@
   
   create_called = 1;
   err = es_create (&stream, cookie, fp? fileno (fp):-1, estream_functions_fp,
-                   modeflags);
+                   modeflags, with_locked_list);
 
  out:
 
@@ -2320,7 +2332,7 @@
 estream_t
 es_fpopen (FILE *fp, const char *mode)
 {
-  return do_fpopen (fp, mode, 0);
+  return do_fpopen (fp, mode, 0, 0);
 }
 
 
@@ -2328,11 +2340,56 @@
 estream_t
 es_fpopen_nc (FILE *fp, const char *mode)
 {
-  return do_fpopen (fp, mode, 1);
+  return do_fpopen (fp, mode, 1, 0);
 }
 
 
 estream_t
+_es_get_std_stream (int fd)
+{
+  estream_list_t list_obj;
+  estream_t stream = NULL;
+
+  fd %= 3; /* We only allow 0, 1 or 2 but we don't want to return an error. */
+  ESTREAM_LIST_LOCK;
+  for (list_obj = estream_list; list_obj; list_obj = list_obj->cdr)
+    if (list_obj->car->intern->is_stdstream
+        && list_obj->car->intern->stdstream_fd == fd)
+      {
+	stream = list_obj->car;
+	break;
+      }
+  if (!stream)
+    {
+      /* Standard stream not yet created - do it now.  */
+      if (!fd)
+        stream = do_fpopen (stdin, "r", 1, 1);
+      else if (fd == 1)
+        stream = do_fpopen (stdout, "a", 1, 1);
+      else
+        stream = do_fpopen (stderr, "a", 1, 1);
+
+      if (!stream) /* Fallback: Create a bit bucket.  */
+        {
+          stream = do_fpopen (NULL, fd? "a":"r", 0, 1);
+          if (!stream)
+            {
+              fprintf (stderr, "fatal: error creating a dummy estream"
+                       " for %d: %s\n", fd, strerror (errno));
+              abort();
+            }
+        }
+      stream->intern->is_stdstream = 1;
+      stream->intern->stdstream_fd = fd;
+      if (fd == 2)
+        es_set_buffering (stream, NULL, _IOLBF, 0);
+    }
+  ESTREAM_LIST_UNLOCK;
+  return stream;
+}
+
+
+estream_t
 es_freopen (const char *ES__RESTRICT path, const char *ES__RESTRICT mode,
 	    estream_t ES__RESTRICT stream)
 {
@@ -2370,7 +2427,7 @@
 	  if (create_called)
 	    es_func_fd_destroy (cookie);
       
-	  es_destroy (stream);
+	  es_destroy (stream, 0);
 	  stream = NULL;
 	}
       else
@@ -2381,7 +2438,7 @@
       /* FIXME?  We don't support re-opening at the moment.  */
       _set_errno (EINVAL);
       es_deinitialize (stream);
-      es_destroy (stream);
+      es_destroy (stream, 0);
       stream = NULL;
     }
 
@@ -2394,7 +2451,7 @@
 {
   int err;
 
-  err = es_destroy (stream);
+  err = es_destroy (stream, 0);
 
   return err;
 }
@@ -2496,6 +2553,23 @@
 }
 
 
+static int
+do_fflush (estream_t stream)
+{
+  int err;
+  
+  if (stream->flags.writing)
+    err = es_flush (stream);
+  else
+    {
+      es_empty (stream);
+      err = 0;
+    }
+
+  return err;
+}
+
+
 int
 es_fflush (estream_t stream)
 {
@@ -2504,17 +2578,11 @@
   if (stream)
     {
       ESTREAM_LOCK (stream);
-      if (stream->flags.writing)
-	err = es_flush (stream);
-      else
-	{
-	  es_empty (stream);
-	  err = 0;
-	}
+      err = do_fflush (stream);
       ESTREAM_UNLOCK (stream);
     }
   else
-    err = es_list_iterate (es_fflush);
+    err = es_list_iterate (do_fflush);
 
   return err ? EOF : 0;
 }
@@ -3186,7 +3254,7 @@
     goto out;
 
   create_called = 1;
-  err = es_create (&stream, cookie, fd, estream_functions_fd, modeflags);
+  err = es_create (&stream, cookie, fd, estream_functions_fd, modeflags, 0);
 
  out:
 

Modified: trunk/common/estream.h
===================================================================
--- trunk/common/estream.h	2010-03-12 18:46:33 UTC (rev 5293)
+++ trunk/common/estream.h	2010-03-15 11:15:45 UTC (rev 5294)
@@ -80,6 +80,7 @@
 #define es_fdopen_nc          _ESTREAM_PREFIX(es_fdopen_nc)
 #define es_fpopen             _ESTREAM_PREFIX(es_fpopen)
 #define es_fpopen_nc          _ESTREAM_PREFIX(es_fpopen_nc)
+#define _es_get_std_stream    _ESTREAM_PREFIX(_es_get_std_stream)
 #define es_freopen            _ESTREAM_PREFIX(es_freopen)
 #define es_fopencookie        _ESTREAM_PREFIX(es_fopencookie)
 #define es_fclose             _ESTREAM_PREFIX(es_fclose)
@@ -250,6 +251,13 @@
 int es_fileno (estream_t stream);
 int es_fileno_unlocked (estream_t stream);
 
+estream_t _es_get_std_stream (int fd);
+
+#define es_stdin  _es_get_std_stream (0)
+#define es_stdout _es_get_std_stream (1)
+#define es_stderr _es_get_std_stream (2)
+
+
 void es_flockfile (estream_t stream);
 int es_ftrylockfile (estream_t stream);
 void es_funlockfile (estream_t stream);

Modified: trunk/common/logging.c
===================================================================
--- trunk/common/logging.c	2010-03-12 18:46:33 UTC (rev 5293)
+++ trunk/common/logging.c	2010-03-15 11:15:45 UTC (rev 5294)
@@ -283,32 +283,7 @@
 
   /* On error default to a stderr based estream.  */
   if (!fp)
-    {
-      fp = es_fpopen (stderr, "a");
-      if (fp)
-        {
-          if (name)
-            es_fprintf (fp, "failed to open log file `%s': %s\n",
-                        name, strerror (errno));
-          else
-            es_fprintf (fp, "failed to fdopen file descriptor %d: %s\n",
-                        fd, strerror (errno));
-        }
-      else
-        {
-          fprintf (stderr, "failed to use stderr as log stream: %s\n",
-                   strerror (errno));
-          /* No way to log something.  Create a dummy estream so that
-             there is something we can use.  */
-          fp = es_fpopen (NULL, "a");
-          if (!fp)
-            {
-              fprintf (stderr, "fatal: failed to open dummy stream: %s\n",
-                       strerror (errno));
-              abort();
-            }
-        }
-    }
+    fp = es_stderr;
 
   es_setvbuf (fp, NULL, _IOLBF, 0);
   
@@ -605,6 +580,16 @@
 }
 
 
+/* Flush the log - this is useful to make sure that the trailing
+   linefeed has been printed.  */
+void
+log_flush (void)
+{
+  volatile va_list dummy_arg_ptr;
+  do_logv (JNLIB_LOG_CONT, 1, NULL, dummy_arg_ptr);
+}
+
+
 /* Print a hexdump of BUFFER.  With TEXT of NULL print just the raw
    dump, with TEXT just an empty string, print a trailing linefeed,
    otherwise print an entire debug line. */

Modified: trunk/common/logging.h
===================================================================
--- trunk/common/logging.h	2010-03-12 18:46:33 UTC (rev 5293)
+++ trunk/common/logging.h	2010-03-15 11:15:45 UTC (rev 5294)
@@ -75,6 +75,7 @@
 void log_info( const char *fmt, ... )	JNLIB_GCC_A_PRINTF(1,2);
 void log_debug( const char *fmt, ... )	JNLIB_GCC_A_PRINTF(1,2);
 void log_printf( const char *fmt, ... ) JNLIB_GCC_A_PRINTF(1,2);
+void log_flush (void);
 
 /* Print a hexdump of BUFFER.  With TEXT passes as NULL print just the
    raw dump, with TEXT being an empty string, print a trailing

Modified: trunk/common/miscellaneous.c
===================================================================
--- trunk/common/miscellaneous.c	2010-03-12 18:46:33 UTC (rev 5293)
+++ trunk/common/miscellaneous.c	2010-03-15 11:15:45 UTC (rev 5294)
@@ -117,23 +117,22 @@
     return s;
 }
 
-/* fixme: Globally replace it by print_sanitized_buffer. */
-void
-print_string( FILE *fp, const byte *p, size_t n, int delim )
-{
-  print_sanitized_buffer (fp, p, n, delim);
-}
 
 void
-print_utf8_string2 ( FILE *fp, const byte *p, size_t n, int delim )
+print_utf8_buffer2 (estream_t stream, const void *p, size_t n, int delim)
 {
-  print_sanitized_utf8_buffer (fp, p, n, delim);
+  char tmp[2];
+  
+  tmp[0] = delim;
+  tmp[1] = 0;
+  es_write_sanitized_utf8_buffer (stream, p, n, tmp, NULL);
 }
 
+
 void
-print_utf8_string( FILE *fp, const byte *p, size_t n )
+print_utf8_buffer (estream_t stream, const void *p, size_t n)
 {
-    print_utf8_string2 (fp, p, n, 0);
+  es_write_sanitized_utf8_buffer (stream, p, n, NULL, NULL);
 }
 
 /* Write LENGTH bytes of BUFFER to FP as a hex encoded string.

Modified: trunk/common/status.h
===================================================================
--- trunk/common/status.h	2010-03-12 18:46:33 UTC (rev 5293)
+++ trunk/common/status.h	2010-03-15 11:15:45 UTC (rev 5294)
@@ -126,7 +126,8 @@
     STATUS_TRUNCATED,
     STATUS_MOUNTPOINT,
 
-    STATUS_ERROR
+    STATUS_ERROR,
+    STATUS_SUCCESS
 };
 
 

Modified: trunk/common/ttyio.c
===================================================================
--- trunk/common/ttyio.c	2010-03-12 18:46:33 UTC (rev 5293)
+++ trunk/common/ttyio.c	2010-03-15 11:15:45 UTC (rev 5294)
@@ -1,6 +1,6 @@
 /* ttyio.c -  tty i/O functions
  * Copyright (C) 1998,1999,2000,2001,2002,2003,2004,2006,2007,
- *               2009 Free Software Foundation, Inc.
+ *               2009, 2010 Free Software Foundation, Inc.
  *
  * This file is part of GnuPG.
  *
@@ -244,14 +244,14 @@
 /* Same as tty_printf but if FP is not NULL, behave like a regular
    fprintf. */
 void
-tty_fprintf (FILE *fp, const char *fmt, ... )
+tty_fprintf (estream_t fp, const char *fmt, ... )
 {
   va_list arg_ptr;
 
   if (fp)
     {
       va_start (arg_ptr, fmt) ;
-      vfprintf (fp, fmt, arg_ptr );
+      es_vfprintf (fp, fmt, arg_ptr );
       va_end (arg_ptr);
       return;
     }
@@ -259,32 +259,32 @@
   if (no_terminal)
     return;
 
-  if( !initialized )
-    init_ttyfp();
+  if (!initialized)
+    init_ttyfp ();
 
-    va_start( arg_ptr, fmt ) ;
+  va_start (arg_ptr, fmt);
 #ifdef _WIN32
-    {   
-        char *buf = NULL;
-        int n;
-	DWORD nwritten;
-
-	n = vasprintf(&buf, fmt, arg_ptr);
-	if( !buf )
-	    log_bug("vasprintf() failed\n");
-        
-	if( !WriteConsoleA( con.out, buf, n, &nwritten, NULL ) )
-	    log_fatal("WriteConsole failed: rc=%d", (int)GetLastError() );
-	if( n != nwritten )
-	    log_fatal("WriteConsole failed: %d != %d\n", n, (int)nwritten );
-	last_prompt_len += n;
-        xfree (buf);
-    }
+  {   
+    char *buf = NULL;
+    int n;
+    DWORD nwritten;
+    
+    n = vasprintf(&buf, fmt, arg_ptr);
+    if (!buf)
+      log_bug("vasprintf() failed\n");
+    
+    if (!WriteConsoleA( con.out, buf, n, &nwritten, NULL ))
+      log_fatal("WriteConsole failed: rc=%d", (int)GetLastError() );
+    if (n != nwritten)
+      log_fatal("WriteConsole failed: %d != %d\n", n, (int)nwritten );
+    last_prompt_len += n;
+    xfree (buf);
+  }
 #else
-    last_prompt_len += vfprintf(ttyfp,fmt,arg_ptr) ;
-    fflush(ttyfp);
+  last_prompt_len += vfprintf(ttyfp,fmt,arg_ptr) ;
+  fflush(ttyfp);
 #endif
-    va_end(arg_ptr);
+  va_end(arg_ptr);
 }
 
 

Modified: trunk/common/ttyio.h
===================================================================
--- trunk/common/ttyio.h	2010-03-12 18:46:33 UTC (rev 5293)
+++ trunk/common/ttyio.h	2010-03-15 11:15:45 UTC (rev 5294)
@@ -28,13 +28,13 @@
 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 5 )
 void tty_printf (const char *fmt, ... )
                  __attribute__ ((format (printf,1,2)));
-void tty_fprintf (FILE *fp, const char *fmt, ... )
+void tty_fprintf (estream_t fp, const char *fmt, ... )
                  __attribute__ ((format (printf,2,3)));
 char *tty_getf (const char *promptfmt, ... )
                  __attribute__ ((format (printf,1,2)));
 #else
 void tty_printf (const char *fmt, ... );
-void tty_fprintf (FILE *fp, const char *fmt, ... );
+void tty_fprintf (estream_t fp, const char *fmt, ... );
 char *tty_getf (const char *promptfmt, ... );
 #endif
 void tty_print_string (const unsigned char *p, size_t n);

Modified: trunk/common/util.h
===================================================================
--- trunk/common/util.h	2010-03-12 18:46:33 UTC (rev 5293)
+++ trunk/common/util.h	2010-03-15 11:15:45 UTC (rev 5294)
@@ -278,9 +278,8 @@
 
 const char *print_fname_stdout (const char *s);
 const char *print_fname_stdin (const char *s);
-void print_string (FILE *fp, const byte *p, size_t n, int delim);
-void print_utf8_string2 ( FILE *fp, const byte *p, size_t n, int delim);
-void print_utf8_string (FILE *fp, const byte *p, size_t n);
+void print_utf8_buffer2 (estream_t fp, const void *p, size_t n, int delim);
+void print_utf8_buffer (estream_t fp, const void *p, size_t n);
 void print_hexstring (FILE *fp, const void *buffer, size_t length,
                       int reserved);
 char *make_printable_string (const void *p, size_t n, int delim);

Modified: trunk/configure.ac
===================================================================
--- trunk/configure.ac	2010-03-12 18:46:33 UTC (rev 5293)
+++ trunk/configure.ac	2010-03-15 11:15:45 UTC (rev 5294)
@@ -29,8 +29,11 @@
 
 m4_define([svn_revision], m4_esyscmd([printf "%d" $(svn info 2>/dev/null \
           | sed -n '/^Revision:/ s/[^0-9]//gp'|head -1)]))
+m4_define([git_revision], m4_esyscmd([git branch -v 2>/dev/null \
+          | awk '/^\* / {printf "%s",$3}']))
 AC_INIT([gnupg], 
-        [my_version[]m4_if(my_issvn,[yes],[-svn[]svn_revision])],
+        [my_version[]m4_if(my_issvn,[yes],
+        [m4_if(git_revision,[],[-svn[]svn_revision],[-git[]git_revision])])],
         [http://bugs.gnupg.org])
 # Set development_version to yes if the minor number is odd or you
 # feel that the default check for a development version is not

Modified: trunk/doc/DETAILS
===================================================================
--- trunk/doc/DETAILS	2010-03-12 18:46:33 UTC (rev 5293)
+++ trunk/doc/DETAILS	2010-03-15 11:15:45 UTC (rev 5294)
@@ -617,6 +617,12 @@
         prefixed with a numerical error code and an underscore; e.g.:
         "151011327_EOF".
 
+    SUCCESS [<location>]
+        Postive confirimation that an operation succeeded.  <location>
+        is optional but if given should not contain spaces. 
+        Used only with a few commands.
+            
+
     ATTRIBUTE <fpr> <octets> <type> <index> <count>
 	      <timestamp> <expiredate> <flags>
 	This is one long line issued for each attribute subpacket when

Modified: trunk/g10/armor.c
===================================================================
--- trunk/g10/armor.c	2010-03-12 18:46:33 UTC (rev 5293)
+++ trunk/g10/armor.c	2010-03-15 11:15:45 UTC (rev 5294)
@@ -415,9 +415,9 @@
     if( !p || (RFC2440 && p[1]!=' ')
 	|| (!RFC2440 && p[1]!=' ' && p[1]!='\n' && p[1]!='\r'))
       {
-	log_error(_("invalid armor header: "));
-	print_string( stderr, line, len, 0 );
-	putc('\n', stderr);
+	log_error (_("invalid armor header: "));
+	es_write_sanitized (log_get_stream (), line, len, NULL, NULL);
+	log_printf ("\n");
 	return -1;
       }
 
@@ -427,8 +427,8 @@
 
     if( opt.verbose ) {
 	log_info(_("armor header: "));
-	print_string( stderr, line, len, 0 );
-	putc('\n', stderr);
+	es_write_sanitized (log_get_stream (), line, len, NULL, NULL);
+	log_printf ("\n");
     }
 
     if( afx->in_cleartext )
@@ -453,8 +453,8 @@
 	   signed data section is "Hash". */
 
 	log_info(_("unknown armor header: "));
-	print_string( stderr, line, len, 0 );
-	putc('\n', stderr);
+	es_write_sanitized (log_get_stream (), line, len, NULL, NULL);
+	log_printf ("\n");
       }
 
     return 1;
@@ -641,8 +641,9 @@
 		    if( type != BEGIN_SIGNATURE )
 		      {
 			log_info(_("unexpected armor: "));
-			print_string( stderr, p, n, 0 );
-			putc('\n', stderr);
+			es_write_sanitized (log_get_stream (), p, n,
+                                            NULL, NULL);
+			log_printf ("\n");
 		      }
 
 		    lastline = 1;
@@ -652,9 +653,9 @@
 	    else if(!afx->not_dash_escaped)
 	      {
 		/* Bad dash-escaping. */
-		log_info(_("invalid dash escaped line: "));
-		print_string( stderr, p, n, 0 );
-		putc('\n', stderr);
+		log_info (_("invalid dash escaped line: "));
+		es_write_sanitized (log_get_stream (), p, n, NULL, NULL);
+		log_printf ("\n");
 	      }
 	  }
 

Modified: trunk/g10/card-util.c
===================================================================
--- trunk/g10/card-util.c	2010-03-12 18:46:33 UTC (rev 5293)
+++ trunk/g10/card-util.c	2010-03-15 11:15:45 UTC (rev 5294)
@@ -218,7 +218,7 @@
 
 
 static void
-print_sha1_fpr (FILE *fp, const unsigned char *fpr)
+print_sha1_fpr (estream_t fp, const unsigned char *fpr)
 {
   int i;
 
@@ -238,21 +238,21 @@
 
 
 static void
-print_sha1_fpr_colon (FILE *fp, const unsigned char *fpr)
+print_sha1_fpr_colon (estream_t fp, const unsigned char *fpr)
 {
   int i;
 
   if (fpr)
     {
       for (i=0; i < 20 ; i++, fpr++)
-        fprintf (fp, "%02X", *fpr);
+        es_fprintf (fp, "%02X", *fpr);
     }
-  putc (':', fp);
+  es_putc (':', fp);
 }
 
 
 static void
-print_name (FILE *fp, const char *text, const char *name)
+print_name (estream_t fp, const char *text, const char *name)
 {
   tty_fprintf (fp, "%s", text);
 
@@ -261,7 +261,7 @@
   if (name && *name)
     {
       if (fp)
-        print_utf8_string2 (fp, name, strlen (name), '\n');
+        print_utf8_buffer2 (fp, name, strlen (name), '\n');
       else
         tty_print_utf8_string2 (name, strlen (name), 0);
     }
@@ -271,10 +271,11 @@
 }
 
 static void
-print_isoname (FILE *fp, const char *text, const char *tag, const char *name)
+print_isoname (estream_t fp, const char *text,
+               const char *tag, const char *name)
 {
   if (opt.with_colons)
-    fprintf (fp, "%s:", tag);
+    es_fprintf (fp, "%s:", tag);
   else
     tty_fprintf (fp, "%s", text);
 
@@ -291,22 +292,22 @@
           *given = 0;
           given += 2;
           if (opt.with_colons)
-            print_string (fp, given, strlen (given), ':');
+            es_write_sanitized (fp, given, strlen (given), ":", NULL);
           else if (fp)
-            print_utf8_string2 (fp, given, strlen (given), '\n');
+            print_utf8_buffer2 (fp, given, strlen (given), '\n');
           else
             tty_print_utf8_string2 (given, strlen (given), 0);
 
           if (opt.with_colons)
-            putc (':', fp);
+            es_putc (':', fp);
           else if (*buf)
             tty_fprintf (fp, " ");
         }
 
       if (opt.with_colons)
-        print_string (fp, buf, strlen (buf), ':');
+        es_write_sanitized (fp, buf, strlen (buf), ":", NULL);
       else if (fp)
-        print_utf8_string2 (fp, buf, strlen (buf), '\n');
+        print_utf8_buffer2 (fp, buf, strlen (buf), '\n');
       else
         tty_print_utf8_string2 (buf, strlen (buf), 0);
       xfree (buf);
@@ -314,13 +315,13 @@
   else
     {
       if (opt.with_colons)
-        putc (':', fp);
+        es_putc (':', fp);
       else
         tty_fprintf (fp, _("[not set]"));
     }
 
   if (opt.with_colons)
-    fputs (":\n", fp);
+    es_fputs (":\n", fp);
   else
     tty_fprintf (fp, "\n");
 }
@@ -351,7 +352,7 @@
 
 /* Print all available information about the current card. */
 void
-card_status (FILE *fp, char *serialno, size_t serialnobuflen)
+card_status (estream_t fp, char *serialno, size_t serialnobuflen)
 {
   struct agent_card_info_s info;
   PKT_public_key *pk = xcalloc (1, sizeof *pk);
@@ -367,15 +368,14 @@
   if (rc)
     {
       if (opt.with_colons)
-        fputs ("AID:::\n", fp);
-      log_error (_("OpenPGP card not available: %s\n"),
-                  gpg_strerror (rc));
+        es_fputs ("AID:::\n", fp);
+      log_error (_("OpenPGP card not available: %s\n"), gpg_strerror (rc));
       xfree (pk);
       return;
     }
 
   if (opt.with_colons)
-    fprintf (fp, "AID:%s:", info.serialno? info.serialno : "");
+    es_fprintf (fp, "AID:%s:", info.serialno? info.serialno : "");
   else
     tty_fprintf (fp, "Application ID ...: %s\n",
                  info.serialno? info.serialno : "[none]");
@@ -385,31 +385,31 @@
       if (info.apptype && !strcmp (info.apptype, "NKS"))
         {
           if (opt.with_colons)
-            fputs ("netkey-card:\n", fp);
+            es_fputs ("netkey-card:\n", fp);
           log_info ("this is a NetKey card\n");
         }
       else if (info.apptype && !strcmp (info.apptype, "DINSIG"))
         {
           if (opt.with_colons)
-            fputs ("dinsig-card:\n", fp);
+            es_fputs ("dinsig-card:\n", fp);
           log_info ("this is a DINSIG compliant card\n");
         }
       else if (info.apptype && !strcmp (info.apptype, "P15"))
         {
           if (opt.with_colons)
-            fputs ("pkcs15-card:\n", fp);
+            es_fputs ("pkcs15-card:\n", fp);
           log_info ("this is a PKCS#15 compliant card\n");
         }
       else if (info.apptype && !strcmp (info.apptype, "GELDKARTE"))
         {
           if (opt.with_colons)
-            fputs ("geldkarte-card:\n", fp);
+            es_fputs ("geldkarte-card:\n", fp);
           log_info ("this is a Geldkarte compliant card\n");
         }
       else
         {
           if (opt.with_colons)
-            fputs ("unknown:\n", fp);
+            es_fputs ("unknown:\n", fp);
         }
       log_info ("not an OpenPGP card\n");
       agent_release_card_info (&info);
@@ -425,69 +425,72 @@
     strcpy (serialno, info.serialno);
 
   if (opt.with_colons)
-    fputs ("openpgp-card:\n", fp);
+    es_fputs ("openpgp-card:\n", fp);
 
 
   if (opt.with_colons)
     {
-      fprintf (fp, "version:%.4s:\n", info.serialno+12);
+      es_fprintf (fp, "version:%.4s:\n", info.serialno+12);
       uval = xtoi_2(info.serialno+16)*256 + xtoi_2 (info.serialno+18);
-      fprintf (fp, "vendor:%04x:%s:\n", uval, get_manufacturer (uval));
-      fprintf (fp, "serial:%.8s:\n", info.serialno+20);
+      es_fprintf (fp, "vendor:%04x:%s:\n", uval, get_manufacturer (uval));
+      es_fprintf (fp, "serial:%.8s:\n", info.serialno+20);
       
       print_isoname (fp, "Name of cardholder: ", "name", info.disp_name);
 
-      fputs ("lang:", fp);
+      es_fputs ("lang:", fp);
       if (info.disp_lang)
-        print_string (fp, info.disp_lang, strlen (info.disp_lang), ':');
-      fputs (":\n", fp);
+        es_write_sanitized (fp, info.disp_lang, strlen (info.disp_lang),
+                            ":", NULL);
+      es_fputs (":\n", fp);
 
-      fprintf (fp, "sex:%c:\n", (info.disp_sex == 1? 'm':
+      es_fprintf (fp, "sex:%c:\n", (info.disp_sex == 1? 'm':
                                  info.disp_sex == 2? 'f' : 'u'));
 
-      fputs ("url:", fp);
+      es_fputs ("url:", fp);
       if (info.pubkey_url)
-        print_string (fp, info.pubkey_url, strlen (info.pubkey_url), ':');
-      fputs (":\n", fp);
+        es_write_sanitized (fp, info.pubkey_url, strlen (info.pubkey_url),
+                            ":", NULL);
+      es_fputs (":\n", fp);
 
-      fputs ("login:", fp);
+      es_fputs ("login:", fp);
       if (info.login_data)
-        print_string (fp, info.login_data, strlen (info.login_data), ':');
-      fputs (":\n", fp);
+        es_write_sanitized (fp, info.login_data, strlen (info.login_data),
+                            ":", NULL);
+      es_fputs (":\n", fp);
 
-      fprintf (fp, "forcepin:%d:::\n", !info.chv1_cached);
+      es_fprintf (fp, "forcepin:%d:::\n", !info.chv1_cached);
       for (i=0; i < DIM (info.key_attr); i++)
         if (info.key_attr[0].algo)
-          fprintf (fp, "keyattr:%d:%d:%u:\n", i+1,
-                   info.key_attr[i].algo, info.key_attr[i].nbits);
-      fprintf (fp, "maxpinlen:%d:%d:%d:\n",
-                   info.chvmaxlen[0], info.chvmaxlen[1], info.chvmaxlen[2]);
-      fprintf (fp, "pinretry:%d:%d:%d:\n",
-                   info.chvretry[0], info.chvretry[1], info.chvretry[2]);
-      fprintf (fp, "sigcount:%lu:::\n", info.sig_counter);
+          es_fprintf (fp, "keyattr:%d:%d:%u:\n", i+1,
+                      info.key_attr[i].algo, info.key_attr[i].nbits);
+      es_fprintf (fp, "maxpinlen:%d:%d:%d:\n",
+                  info.chvmaxlen[0], info.chvmaxlen[1], info.chvmaxlen[2]);
+      es_fprintf (fp, "pinretry:%d:%d:%d:\n",
+                  info.chvretry[0], info.chvretry[1], info.chvretry[2]);
+      es_fprintf (fp, "sigcount:%lu:::\n", info.sig_counter);
 
       for (i=0; i < 4; i++)
         {
           if (info.private_do[i])
             {
-              fprintf (fp, "private_do:%d:", i+1);
-              print_string (fp, info.private_do[i],
-                            strlen (info.private_do[i]), ':');
-              fputs (":\n", fp);
+              es_fprintf (fp, "private_do:%d:", i+1);
+              es_write_sanitized (fp, info.private_do[i],
+                                  strlen (info.private_do[i]), ":", NULL);
+              es_fputs (":\n", fp);
             }
         }
 
-      fputs ("cafpr:", fp);
+      es_fputs ("cafpr:", fp);
       print_sha1_fpr_colon (fp, info.cafpr1valid? info.cafpr1:NULL);
       print_sha1_fpr_colon (fp, info.cafpr2valid? info.cafpr2:NULL);
       print_sha1_fpr_colon (fp, info.cafpr3valid? info.cafpr3:NULL);
-      putc ('\n', fp);
-      fputs ("fpr:", fp);
+      es_putc ('\n', fp);
+      es_fputs ("fpr:", fp);
       print_sha1_fpr_colon (fp, info.fpr1valid? info.fpr1:NULL);
       print_sha1_fpr_colon (fp, info.fpr2valid? info.fpr2:NULL);
       print_sha1_fpr_colon (fp, info.fpr3valid? info.fpr3:NULL);
-      putc ('\n', fp);
-      fprintf (fp, "fprtime:%lu:%lu:%lu:\n",
+      es_putc ('\n', fp);
+      es_fprintf (fp, "fprtime:%lu:%lu:%lu:\n",
                (unsigned long)info.fpr1time, (unsigned long)info.fpr2time,
                (unsigned long)info.fpr3time);
     }
@@ -764,13 +767,13 @@
 static int
 get_data_from_file (const char *fname, size_t maxlen, char **r_buffer)
 {
-  FILE *fp;
+  estream_t fp;
   char *data;
   int n;
   
   *r_buffer = NULL;
 
-  fp = fopen (fname, "rb");
+  fp = es_fopen (fname, "rb");
 #if GNUPG_MAJOR_VERSION == 1
   if (fp && is_secured_file (fileno (fp)))
     {
@@ -789,15 +792,15 @@
   if (!data)
     {
       tty_printf (_("error allocating enough memory: %s\n"), strerror (errno));
-      fclose (fp);
+      es_fclose (fp);
       return -1;
     }
 
   if (maxlen)
-    n = fread (data, 1, maxlen, fp);
+    n = es_fread (data, 1, maxlen, fp);
   else
     n = 0;
-  fclose (fp);
+  es_fclose (fp);
   if (n < 0)
     {
       tty_printf (_("error reading `%s': %s\n"), fname, strerror (errno));
@@ -814,9 +817,9 @@
 static int
 put_data_to_file (const char *fname, const void *buffer, size_t length)
 {
-  FILE *fp;
+  estream_t fp;
   
-  fp = fopen (fname, "wb");
+  fp = es_fopen (fname, "wb");
 #if GNUPG_MAJOR_VERSION == 1
   if (fp && is_secured_file (fileno (fp)))
     {
@@ -831,13 +834,13 @@
       return -1;
     }
           
-  if (length && fwrite (buffer, length, 1, fp) != 1)
+  if (length && es_fwrite (buffer, length, 1, fp) != 1)
     {
       tty_printf (_("error writing `%s': %s\n"), fname, strerror (errno));
-      fclose (fp);
+      es_fclose (fp);
       return -1;
     }
-  fclose (fp);
+  es_fclose (fp);
   return 0;
 }
 
@@ -1785,7 +1788,7 @@
         {
           if (opt.with_colons)
             {
-              card_status (stdout, serialnobuf, DIM (serialnobuf));
+              card_status (es_stdout, serialnobuf, DIM (serialnobuf));
               fflush (stdout);
             }
           else

Modified: trunk/g10/gpg.c
===================================================================
--- trunk/g10/gpg.c	2010-03-12 18:46:33 UTC (rev 5293)
+++ trunk/g10/gpg.c	2010-03-15 11:15:45 UTC (rev 5294)
@@ -1497,9 +1497,10 @@
 	    {
 	      strlist_t sl;
 
-	      printf("cfg:group:");
-	      print_string(stdout,iter->name,strlen(iter->name),':');
-	      printf(":");
+	      es_fprintf (es_stdout, "cfg:group:");
+	      es_write_sanitized (es_stdout, iter->name, strlen(iter->name),
+                                  ":", NULL);
+	      es_putc (':', es_stdout);
 
 	      for(sl=iter->values;sl;sl=sl->next)
 		{
@@ -1517,7 +1518,7 @@
       if(show_all || ascii_strcasecmp(name,"version")==0)
 	{
 	  printf("cfg:version:");
-	  print_string(stdout,VERSION,strlen(VERSION),':');
+	  es_write_sanitized (es_stdout, VERSION, strlen(VERSION), ":", NULL);
 	  printf("\n");
 	  any=1;
 	}
@@ -3828,29 +3829,30 @@
 	{   int mode = argc < 2 ? 0 : atoi(*argv);
 
 	    if( mode == 1 && argc == 2 ) {
-		mpi_print( stdout, generate_public_prime( atoi(argv[1]) ), 1);
+		mpi_print (es_stdout,
+                           generate_public_prime( atoi(argv[1]) ), 1);
 	    }
 	    else if( mode == 2 && argc == 3 ) {
-		mpi_print( stdout, generate_elg_prime(
+		mpi_print (es_stdout, generate_elg_prime(
 					     0, atoi(argv[1]),
 					     atoi(argv[2]), NULL,NULL ), 1);
 	    }
 	    else if( mode == 3 && argc == 3 ) {
 		MPI *factors;
-		mpi_print( stdout, generate_elg_prime(
+		mpi_print (es_stdout, generate_elg_prime(
 					     1, atoi(argv[1]),
 					     atoi(argv[2]), NULL,&factors ), 1);
 		putchar('\n');
-		mpi_print( stdout, factors[0], 1 ); /* print q */
+		mpi_print (es_stdout, factors[0], 1 ); /* print q */
 	    }
 	    else if( mode == 4 && argc == 3 ) {
 		MPI g = mpi_alloc(1);
-		mpi_print( stdout, generate_elg_prime(
+		mpi_print (es_stdout, generate_elg_prime(
 						 0, atoi(argv[1]),
 						 atoi(argv[2]), g, NULL ), 1);
 		putchar('\n');
-		mpi_print( stdout, g, 1 );
-		mpi_free(g);
+		mpi_print (es_stdout, g, 1 );
+		mpi_free (g);
 	    }
 	    else
 		wrong_args("--gen-prime mode bits [qbits] ");
@@ -3987,7 +3989,7 @@
       case aCardStatus:
         if (argc)
             wrong_args ("--card-status");
-        card_status (stdout, NULL, 0);
+        card_status (es_stdout, NULL, 0);
         break;
 
       case aCardEdit:

Modified: trunk/g10/import.c
===================================================================
--- trunk/g10/import.c	2010-03-12 18:46:33 UTC (rev 5293)
+++ trunk/g10/import.c	2010-03-15 11:15:45 UTC (rev 5294)
@@ -718,7 +718,7 @@
 		  pubkey_letter( pk->pubkey_algo ),
 		  keystr_from_pk(pk), datestr_from_pk(pk) );
 	if (uidnode)
-	  print_utf8_string (log_get_stream (),
+	  print_utf8_buffer (log_get_stream (),
                              uidnode->pkt->pkt.user_id->name,
 			     uidnode->pkt->pkt.user_id->len );
 	log_printf ("\n");
@@ -1127,7 +1127,7 @@
 		  pubkey_letter( sk->pubkey_algo ),
 		  keystr_from_sk(sk), datestr_from_sk(sk) );
 	if( uidnode )
-	  print_utf8_string( stderr, uidnode->pkt->pkt.user_id->name,
+	  print_utf8_buffer (es_stderr, uidnode->pkt->pkt.user_id->name,
 			     uidnode->pkt->pkt.user_id->len );
 	log_printf ("\n");
       }

Modified: trunk/g10/kbnode.c
===================================================================
--- trunk/g10/kbnode.c	2010-03-12 18:46:33 UTC (rev 5293)
+++ trunk/g10/kbnode.c	2010-03-15 11:15:45 UTC (rev 5294)
@@ -1,6 +1,6 @@
 /* kbnode.c -  keyblock node utility functions
  * Copyright (C) 1998, 1999, 2000, 2001, 2002,
- *               2005 Free Software Foundation, Inc.
+ *               2005, 2010 Free Software Foundation, Inc.
  *
  * This file is part of GnuPG.
  *
@@ -336,63 +336,71 @@
 
 
 void
-dump_kbnode( KBNODE node )
+dump_kbnode (KBNODE node)
 {
-    for(; node; node = node->next ) {
-	const char *s;
-	switch( node->pkt->pkttype ) {
-	  case 0:		s="empty"; break;
-	  case PKT_PUBLIC_KEY:	s="public-key"; break;
-	  case PKT_SECRET_KEY:	s="secret-key"; break;
-	  case PKT_SECRET_SUBKEY: s= "secret-subkey"; break;
-	  case PKT_PUBKEY_ENC:	s="public-enc"; break;
-	  case PKT_SIGNATURE:	s="signature"; break;
-	  case PKT_ONEPASS_SIG: s="onepass-sig"; break;
-	  case PKT_USER_ID:	s="user-id"; break;
-	  case PKT_PUBLIC_SUBKEY: s="public-subkey"; break;
-	  case PKT_COMMENT:	s="comment"; break;
-	  case PKT_RING_TRUST:	s="trust"; break;
-	  case PKT_PLAINTEXT:	s="plaintext"; break;
-	  case PKT_COMPRESSED:	s="compressed"; break;
-	  case PKT_ENCRYPTED:	s="encrypted"; break;
-          case PKT_GPG_CONTROL: s="gpg-control"; break;
-	  default:		s="unknown"; break;
+  for (; node; node = node->next ) 
+    {
+      const char *s;
+      switch (node->pkt->pkttype)
+        {
+        case 0:		s="empty"; break;
+        case PKT_PUBLIC_KEY:	s="public-key"; break;
+        case PKT_SECRET_KEY:	s="secret-key"; break;
+        case PKT_SECRET_SUBKEY: s= "secret-subkey"; break;
+        case PKT_PUBKEY_ENC:	s="public-enc"; break;
+        case PKT_SIGNATURE:	s="signature"; break;
+        case PKT_ONEPASS_SIG: s="onepass-sig"; break;
+        case PKT_USER_ID:	s="user-id"; break;
+        case PKT_PUBLIC_SUBKEY: s="public-subkey"; break;
+        case PKT_COMMENT:	s="comment"; break;
+        case PKT_RING_TRUST:	s="trust"; break;
+        case PKT_PLAINTEXT:	s="plaintext"; break;
+        case PKT_COMPRESSED:	s="compressed"; break;
+        case PKT_ENCRYPTED:	s="encrypted"; break;
+        case PKT_GPG_CONTROL: s="gpg-control"; break;
+        default:		s="unknown"; break;
 	}
-	fprintf(stderr, "node %p %02x/%02x type=%s",
-		node, node->flag, node->private_flag, s);
-	if( node->pkt->pkttype == PKT_USER_ID ) {
-            PKT_user_id *uid = node->pkt->pkt.user_id;
-	    fputs("  \"", stderr);
-	    print_string( stderr, uid->name, uid->len, 0 );
-	    fprintf (stderr, "\" %c%c%c%c\n",
-                     uid->is_expired? 'e':'.',
-                     uid->is_revoked? 'r':'.',
-                     uid->created?    'v':'.',
-                     uid->is_primary? 'p':'.' );
-	}
-	else if( node->pkt->pkttype == PKT_SIGNATURE ) {
-	    fprintf(stderr, "  class=%02x keyid=%08lX ts=%lu\n",
-		   node->pkt->pkt.signature->sig_class,
-		   (ulong)node->pkt->pkt.signature->keyid[1],
-                   (ulong)node->pkt->pkt.signature->timestamp);
-	}
-	else if( node->pkt->pkttype == PKT_GPG_CONTROL ) {
-	    fprintf(stderr, " ctrl=%d len=%u\n",
-                    node->pkt->pkt.gpg_control->control,
-                    (unsigned int)node->pkt->pkt.gpg_control->datalen);
-	}
-	else if( node->pkt->pkttype == PKT_PUBLIC_KEY
-		 || node->pkt->pkttype == PKT_PUBLIC_SUBKEY ) {
-            PKT_public_key *pk = node->pkt->pkt.public_key;
-	    fprintf(stderr, "  keyid=%08lX a=%d u=%d %c%c%c%c\n",
-                    (ulong)keyid_from_pk( pk, NULL ),
-                    pk->pubkey_algo, pk->pubkey_usage,
-                    pk->has_expired? 'e':'.',  
-                    pk->is_revoked?  'r':'.',  
-                    pk->is_valid?    'v':'.',
-                    pk->mdc_feature? 'm':'.');
-	}
-	else
-	    fputs("\n", stderr);
+      log_debug ("node %p %02x/%02x type=%s",
+                 node, node->flag, node->private_flag, s);
+      if (node->pkt->pkttype == PKT_USER_ID)
+        {
+          PKT_user_id *uid = node->pkt->pkt.user_id;
+          log_printf ("  \"");
+          es_write_sanitized (log_get_stream (), uid->name, uid->len,
+                              NULL, NULL);
+          log_printf ("\" %c%c%c%c\n",
+                      uid->is_expired? 'e':'.',
+                      uid->is_revoked? 'r':'.',
+                      uid->created?    'v':'.',
+                      uid->is_primary? 'p':'.' );
+        }
+      else if (node->pkt->pkttype == PKT_SIGNATURE)
+        {
+          log_printf ("  class=%02x keyid=%08lX ts=%lu\n",
+                      node->pkt->pkt.signature->sig_class,
+                      (ulong)node->pkt->pkt.signature->keyid[1],
+                      (ulong)node->pkt->pkt.signature->timestamp);
+        }
+      else if (node->pkt->pkttype == PKT_GPG_CONTROL)
+        {
+          log_printf (" ctrl=%d len=%u\n",
+                      node->pkt->pkt.gpg_control->control,
+                      (unsigned int)node->pkt->pkt.gpg_control->datalen);
+        }
+      else if (node->pkt->pkttype == PKT_PUBLIC_KEY
+               || node->pkt->pkttype == PKT_PUBLIC_SUBKEY)
+        {
+          PKT_public_key *pk = node->pkt->pkt.public_key;
+
+          log_printf ("  keyid=%08lX a=%d u=%d %c%c%c%c\n",
+                      (ulong)keyid_from_pk( pk, NULL ),
+                      pk->pubkey_algo, pk->pubkey_usage,
+                      pk->has_expired? 'e':'.',  
+                      pk->is_revoked?  'r':'.',  
+                      pk->is_valid?    'v':'.',
+                      pk->mdc_feature? 'm':'.');
+        }
+      
+      log_flush ();
     }
 }

Modified: trunk/g10/keyedit.c
===================================================================
--- trunk/g10/keyedit.c	2010-03-12 18:46:33 UTC (rev 5293)
+++ trunk/g10/keyedit.c	2010-03-15 11:15:45 UTC (rev 5294)
@@ -188,7 +188,9 @@
       printf(":");
 
       if(sig->trust_regexp)
-	print_string(stdout,sig->trust_regexp,strlen(sig->trust_regexp),':');
+	es_write_sanitized (es_stdout, 
+                            sig->trust_regexp, strlen (sig->trust_regexp),
+                            ":", NULL);
 
       printf("::%02x%c\n",sig->sig_class,sig->flags.exportable?'x':'l');
 
@@ -1100,7 +1102,7 @@
  * We use only one passphrase for all keys.
  */
 static int
-change_passphrase( KBNODE keyblock )
+change_passphrase (KBNODE keyblock, int *r_err)
 {
     int rc = 0;
     int changed=0;
@@ -1264,6 +1266,8 @@
   leave:
     xfree( passphrase );
     set_next_passphrase( NULL );
+    if (r_err)
+      *r_err = rc;
     return changed && !rc;
 }
 
@@ -2150,7 +2154,7 @@
 	    break;
 
 	  case cmdPASSWD:
-	    if( change_passphrase( sec_keyblock ) )
+	    if (change_passphrase (sec_keyblock, NULL))
 		sec_modified = 1;
 	    break;
 
@@ -2372,11 +2376,8 @@
   if (err) 
     goto leave;
 
-  if (!change_passphrase (keyblock))
-    {
-      err = gpg_error (GPG_ERR_GENERAL);
-      goto leave;
-    }
+  if (!change_passphrase (keyblock, &err))
+    goto leave;
 
   err = keydb_update_keyblock (kdh, keyblock);
   if (err)
@@ -2393,6 +2394,8 @@
                 username, gpg_strerror (err));
       write_status_error ("keyedit.passwd", err);
     }
+  else
+    write_status_text (STATUS_SUCCESS, "keyedit.passwd");
 }
 
 
@@ -2685,7 +2688,7 @@
 	    if(uid->attrib_data)
 	      printf ("%u %lu",uid->numattribs,uid->attrib_len);
 	    else
-	      print_string (stdout, uid->name, uid->len, ':');
+	      es_write_sanitized (es_stdout, uid->name, uid->len, ":", NULL);
 
             putchar (':');
             /* signature class */
@@ -4791,7 +4794,7 @@
 	else
 	  {
 	    printf("uid:::::::::");
-	    print_string (stdout, uid->name, uid->len, ':');
+	    es_write_sanitized (es_stdout, uid->name, uid->len, ":", NULL);
 	  }
 
 	printf("\n");

Modified: trunk/g10/keylist.c
===================================================================
--- trunk/g10/keylist.c	2010-03-12 18:46:33 UTC (rev 5293)
+++ trunk/g10/keylist.c	2010-03-15 11:15:45 UTC (rev 5294)
@@ -54,7 +54,7 @@
 };
 
 /* The stream used to write attribute packets to.  */
-static FILE *attrib_fp = NULL;
+static estream_t attrib_fp;
 
 
 /* List the keys.  If list is NULL, all available keys are listed.
@@ -71,32 +71,32 @@
       read_trust_options (&trust_model, &created, &nextcheck,
 			  &marginals, &completes, &cert_depth);
 
-      printf ("tru:");
+      es_fprintf (es_stdout, "tru:");
 
       if (nextcheck && nextcheck <= make_timestamp ())
-	printf ("o");
+	es_fprintf (es_stdout, "o");
       if (trust_model != opt.trust_model)
-	printf ("t");
+	es_fprintf (es_stdout, "t");
       if (opt.trust_model == TM_PGP || opt.trust_model == TM_CLASSIC)
 	{
 	  if (marginals != opt.marginals_needed)
-	    printf ("m");
+	    es_fprintf (es_stdout, "m");
 	  if (completes != opt.completes_needed)
-	    printf ("c");
+	    es_fprintf (es_stdout, "c");
 	  if (cert_depth != opt.max_cert_depth)
-	    printf ("d");
+	    es_fprintf (es_stdout, "d");
 	}
 
-      printf (":%d:%lu:%lu", trust_model, created, nextcheck);
+      es_fprintf (es_stdout, ":%d:%lu:%lu", trust_model, created, nextcheck);
 
       /* Only show marginals, completes, and cert_depth in the classic
          or PGP trust models since they are not meaningful
          otherwise. */
 
       if (trust_model == TM_PGP || trust_model == TM_CLASSIC)
-	printf (":%d:%d:%d", marginals, completes, cert_depth);
+	es_fprintf (es_stdout, ":%d:%d:%d", marginals, completes, cert_depth);
 
-      printf ("\n");
+      es_fprintf (es_stdout, "\n");
     }
 
   /* We need to do the stale check right here because it might need to
@@ -147,7 +147,7 @@
    the tty output interface is used, otherwise output is directted to
    the given stream.  */
 void
-print_pubkey_info (FILE * fp, PKT_public_key * pk)
+print_pubkey_info (estream_t fp, PKT_public_key * pk)
 {
   u32 keyid[2];
   char *p;
@@ -162,15 +162,11 @@
     p = get_user_id_native (keyid);
 
   if (fp)
-    fprintf (fp, "pub  %4u%c/%s %s %s\n",
-	     nbits_from_pk (pk),
-	     pubkey_letter (pk->pubkey_algo),
-	     keystr (keyid), datestr_from_pk (pk), p);
-  else
-    tty_printf ("\npub  %4u%c/%s %s %s\n",
-		nbits_from_pk (pk), pubkey_letter (pk->pubkey_algo),
-		keystr (keyid), datestr_from_pk (pk), p);
-
+    tty_printf ("\n");
+  tty_fprintf (fp, "pub  %4u%c/%s %s %s\n",
+               nbits_from_pk (pk),
+               pubkey_letter (pk->pubkey_algo),
+               keystr (keyid), datestr_from_pk (pk), p);
   xfree (p);
 }
 
@@ -178,7 +174,7 @@
 /* Print basic information of a secret key including the card serial




More information about the Gnupg-commits mailing list