[svn] GnuPG - r5366 - in trunk: . common dirmngr doc scripts/gpg-w32-dev tools

svn author wk cvs at cvs.gnupg.org
Fri Jul 16 15:19:48 CEST 2010


Author: wk
Date: 2010-07-16 15:19:45 +0200 (Fri, 16 Jul 2010)
New Revision: 5366

Added:
   trunk/dirmngr/dirmngr-err.h
Removed:
   trunk/dirmngr/b64dec.c
   trunk/dirmngr/b64enc.c
   trunk/dirmngr/http.c
   trunk/dirmngr/http.h
Modified:
   trunk/autogen.sh
   trunk/common/ChangeLog
   trunk/common/b64enc.c
   trunk/common/estream.c
   trunk/common/http.c
   trunk/common/http.h
   trunk/common/util.h
   trunk/dirmngr/ChangeLog
   trunk/dirmngr/Makefile.am
   trunk/dirmngr/cdblib.c
   trunk/dirmngr/certcache.c
   trunk/dirmngr/crlcache.c
   trunk/dirmngr/crlcache.h
   trunk/dirmngr/crlfetch.c
   trunk/dirmngr/dirmngr-client.c
   trunk/dirmngr/dirmngr.c
   trunk/dirmngr/dirmngr.h
   trunk/dirmngr/dirmngr_ldap.c
   trunk/dirmngr/ocsp.c
   trunk/dirmngr/server.c
   trunk/doc/gpg.texi
   trunk/scripts/gpg-w32-dev/GNUmakefile
   trunk/tools/ChangeLog
   trunk/tools/Makefile.am
   trunk/tools/gpgtar-create.c
   trunk/tools/gpgtar-extract.c
   trunk/tools/gpgtar-list.c
   trunk/tools/gpgtar.c
   trunk/tools/gpgtar.h
Log:
Some work on porting dirmngr (unfinished)
Ported gpgtar to W32.


[The diff below has been truncated]

Modified: trunk/common/ChangeLog
===================================================================
--- trunk/common/ChangeLog	2010-06-28 13:37:44 UTC (rev 5365)
+++ trunk/common/ChangeLog	2010-07-16 13:19:45 UTC (rev 5366)
@@ -1,3 +1,32 @@
+2010-07-16  Werner Koch  <wk at g10code.com>
+
+	* http.h (HTTP_FLAG_IGNORE_CL): Add flag .
+	* http.c (WITHOUT_GNU_PTH): Test macro for Pth support.
+	(http_parse_uri): s/xcalloc/xtrycalloc/.
+	(send_request): Replace of discrete allocation and sprintf by
+	xtryasprintf.
+	(http_wait_response): Replace HTTP_FLAG_NO_SHUTDOWN by
+	HTTP_FLAG_SHUTDOWN to change the default to no shutdown.
+	(cookie_read) [HAVE_PTH]: Use pth_read.
+	(longcounter_t): New.
+	(struct cookie_s): Add support for content length.  Turn flag
+	fields into bit types.
+	(parse_response): Parse content length header.
+	(cookie_read): Take care of the content length.
+
+2010-07-08  Werner Koch  <wk at g10code.com>
+
+	* estream.c (estream_functions_file): Remove and replace by
+	identical estream_functions_fd.
+
+2010-07-06  Werner Koch  <wk at g10code.com>
+
+	* util.h (b64state): Add field STREAM.
+	* b64enc.c (b64enc_start): Factor code out to ..
+	(enc_start): new.
+	(b64enc_start_es, my_fputs): New.
+	(b64enc_write, b64enc_finish): Support estream.
+
 2010-06-24  Werner Koch  <wk at g10code.com>
 
 	* asshelp.c (lock_agent_spawning) [W32]: Use CreateMutexW.

Modified: trunk/dirmngr/ChangeLog
===================================================================
--- trunk/dirmngr/ChangeLog	2010-06-28 13:37:44 UTC (rev 5365)
+++ trunk/dirmngr/ChangeLog	2010-07-16 13:19:45 UTC (rev 5366)
@@ -1,3 +1,26 @@
+2010-07-16  Werner Koch  <wk at g10code.com>
+
+	* http.c, http.h: Remove.
+
+	* dirmngr-err.h: New.
+	* dirmngr.h: Include dirmngr-err.h instead of gpg-error.h
+
+	* cdblib.c: Replace assignments to ERRNO by a call to
+	gpg_err_set_errno.  Include dirmngr-err.h.
+	(cdb_free) [__MINGW32CE__]: Do not use get_osfhandle.
+
+	* dirmngr.c [!HAVE_SIGNAL_H]: Don't include signal.h.
+	(USE_W32_SERVICE): New.  Use this to control the use of the W32
+	service system.
+
+2010-07-06  Werner Koch  <wk at g10code.com>
+
+	* dirmngr.c (main): Print note on directory name changes.
+
+	Replace almost all uses of stdio by estream.
+
+	* b64dec.c, b64enc.c: Remove.  They are duplicated in ../common/.
+
 2010-06-28  Werner Koch  <wk at g10code.com>
 
 	* dirmngr_ldap.c (my_i18n_init): Remove.

Modified: trunk/tools/ChangeLog
===================================================================
--- trunk/tools/ChangeLog	2010-06-28 13:37:44 UTC (rev 5365)
+++ trunk/tools/ChangeLog	2010-07-16 13:19:45 UTC (rev 5366)
@@ -1,3 +1,11 @@
+2010-07-16  Werner Koch  <wk at g10code.com>
+
+	* gpgtar-create.c: Rewrite to better support W32.
+
+2010-07-01  Werner Koch  <wk at g10code.com>
+
+	* gpgtar.c: Add option --set-filename.
+
 2010-06-24  Werner Koch  <wk at g10code.com>
 
 	* gpgconf-comp.c (gpg_agent_runtime_change)

Modified: trunk/autogen.sh
===================================================================
--- trunk/autogen.sh	2010-06-28 13:37:44 UTC (rev 5365)
+++ trunk/autogen.sh	2010-07-16 13:19:45 UTC (rev 5366)
@@ -103,13 +103,13 @@
           w32root="$w32ce_root"
           [ -z "$w32root" ] && w32root="$HOME/w32ce_root"
           toolprefixes="$w32ce_toolprefixes arm-mingw32ce"
-          extraoptions="--disable-scdaemon --disable-zip --disable-ldap --disable-dirmngr $w32ce_extraoptions"
+          extraoptions="--disable-scdaemon --disable-zip $w32ce_extraoptions"
           ;;
         *)
           [ -z "$w32root" ] && w32root="$HOME/w32root"
           toolprefixes="$w32_toolprefixes i586-mingw32msvc"
           toolprefixes="$toolprefixes i386-mingw32msvc mingw32"
-          extraoptions="$w32_extraoptions"
+          extraoptions="--enable-gpgtar $w32_extraoptions"
           ;;
     esac
     echo "Using $w32root as standard install directory" >&2

Modified: trunk/common/b64enc.c
===================================================================
--- trunk/common/b64enc.c	2010-06-28 13:37:44 UTC (rev 5365)
+++ trunk/common/b64enc.c	2010-07-16 13:19:45 UTC (rev 5366)
@@ -1,5 +1,5 @@
 /* b64enc.c - Simple Base64 encoder.
- * Copyright (C) 2001, 2003, 2004, 2008 Free Software Foundation, Inc.
+ * Copyright (C) 2001, 2003, 2004, 2008, 2010 Free Software Foundation, Inc.
  *
  * This file is part of GnuPG.
  *
@@ -136,20 +136,13 @@
 };
 
 
-/* Prepare for base-64 writing to the stream FP.  If TITLE is not NULL
-   and not an empty string, this string will be used as the title for
-   the armor lines, with TITLE being an empty string, we don't write
-   the header lines and furthermore even don't write any linefeeds.
-   If TITLE starts with "PGP " the OpenPGP CRC checksum will be
-   written as well.  With TITLE beeing NULL, we merely don't write
-   header but make sure that lines are not too long. Note, that we
-   don't write any output unless at least one byte get written using
-   b64enc_write. */
-gpg_error_t
-b64enc_start (struct b64state *state, FILE *fp, const char *title)
+static gpg_error_t
+enc_start (struct b64state *state, FILE *fp, estream_t stream,
+           const char *title)
 {
   memset (state, 0, sizeof *state);
   state->fp = fp;
+  state->stream = stream;
   if (title && !*title)
     state->flags |= B64ENC_NO_LINEFEEDS;
   else if (title)
@@ -167,6 +160,39 @@
 }
 
 
+/* Prepare for base-64 writing to the stream FP.  If TITLE is not NULL
+   and not an empty string, this string will be used as the title for
+   the armor lines, with TITLE being an empty string, we don't write
+   the header lines and furthermore even don't write any linefeeds.
+   If TITLE starts with "PGP " the OpenPGP CRC checksum will be
+   written as well.  With TITLE beeing NULL, we merely don't write
+   header but make sure that lines are not too long. Note, that we
+   don't write any output unless at least one byte get written using
+   b64enc_write. */
+gpg_error_t
+b64enc_start (struct b64state *state, FILE *fp, const char *title)
+{
+  return enc_start (state, fp, NULL, title);
+}
+
+/* Same as b64enc_start but takes an estream.  */
+gpg_error_t
+b64enc_start_es (struct b64state *state, estream_t fp, const char *title)
+{
+  return enc_start (state, NULL, fp, title);
+}
+
+
+static int
+my_fputs (const char *string, struct b64state *state)
+{
+  if (state->stream)
+    return es_fputs (string, state->stream);
+  else
+    return fputs (string, state->fp);
+}
+
+
 /* Write NBYTES from BUFFER to the Base 64 stream identified by
    STATE. With BUFFER and NBYTES being 0, merely do a fflush on the
    stream. */
@@ -176,13 +202,13 @@
   unsigned char radbuf[4];
   int idx, quad_count;
   const unsigned char *p;
-  FILE *fp = state->fp;
 
 
   if (!nbytes)
     {
-      if (buffer && fflush (fp))
-        goto write_error;
+      if (buffer)
+        if (state->stream? es_fflush (state->stream) : fflush (state->fp))
+          goto write_error;
       return 0;
     }
 
@@ -190,12 +216,12 @@
     {
       if (state->title)
         {
-          if ( fputs ("-----BEGIN ", fp) == EOF
-               || fputs (state->title, fp) == EOF
-               || fputs ("-----\n", fp) == EOF)
+          if ( my_fputs ("-----BEGIN ", state) == EOF
+               || my_fputs (state->title, state) == EOF
+               || my_fputs ("-----\n", state) == EOF)
             goto write_error;
           if ( (state->flags & B64ENC_USE_PGPCRC) 
-               && fputs ("\n", fp) == EOF)
+               && my_fputs ("\n", state) == EOF)
             goto write_error;
         }
         
@@ -228,16 +254,27 @@
           tmp[1] = bintoasc[(((*radbuf<<4)&060)|((radbuf[1] >> 4)&017))&077];
           tmp[2] = bintoasc[(((radbuf[1]<<2)&074)|((radbuf[2]>>6)&03))&077];
           tmp[3] = bintoasc[radbuf[2]&077];
-          for (idx=0; idx < 4; idx++)
-            putc (tmp[idx], fp);
-          idx = 0;
-          if (ferror (fp))
-            goto write_error;
+          if (state->stream)
+            {
+              for (idx=0; idx < 4; idx++)
+                es_putc (tmp[idx], state->stream);
+              idx = 0;
+              if (es_ferror (state->stream))
+                goto write_error;
+            }
+          else
+            {
+              for (idx=0; idx < 4; idx++)
+                putc (tmp[idx], state->fp);
+              idx = 0;
+              if (ferror (state->fp))
+                goto write_error;
+            }
           if (++quad_count >= (64/4)) 
             {
               quad_count = 0;
               if (!(state->flags & B64ENC_NO_LINEFEEDS)
-                  && fputs ("\n", fp) == EOF)
+                  && my_fputs ("\n", state) == EOF)
                 goto write_error;
             }
         }
@@ -251,20 +288,19 @@
   return gpg_error_from_syserror ();
 }
 
+
 gpg_error_t
 b64enc_finish (struct b64state *state)
 {
   gpg_error_t err = 0;
   unsigned char radbuf[4];
   int idx, quad_count;
-  FILE *fp;
   char tmp[4];
 
   if (!(state->flags & B64ENC_DID_HEADER))
     goto cleanup;
 
   /* Flush the base64 encoding */
-  fp = state->fp;
   idx = state->idx;
   quad_count = state->quad_count;
   assert (idx < 4);
@@ -285,17 +321,28 @@
           tmp[2] = bintoasc[((radbuf[1] << 2) & 074) & 077];
           tmp[3] = '=';
         }
-      for (idx=0; idx < 4; idx++)
-        putc (tmp[idx], fp);
-      idx = 0;
-      if (ferror (fp))
-        goto write_error;
-      
+      if (state->stream)
+        {
+          for (idx=0; idx < 4; idx++)
+            es_putc (tmp[idx], state->stream);
+          idx = 0;
+          if (es_ferror (state->stream))
+            goto write_error;
+        }
+      else
+        {
+          for (idx=0; idx < 4; idx++)
+            putc (tmp[idx], state->fp);
+          idx = 0;
+          if (ferror (state->fp))
+            goto write_error;
+        }
+
       if (++quad_count >= (64/4)) 
         {
           quad_count = 0;
           if (!(state->flags & B64ENC_NO_LINEFEEDS)
-              && fputs ("\n", fp) == EOF)
+              && my_fputs ("\n", state) == EOF)
             goto write_error;
         }
     }
@@ -303,13 +350,13 @@
   /* Finish the last line and write the trailer. */
   if (quad_count
       && !(state->flags & B64ENC_NO_LINEFEEDS)
-      && fputs ("\n", fp) == EOF)
+      && my_fputs ("\n", state) == EOF)
     goto write_error;
   
   if ( (state->flags & B64ENC_USE_PGPCRC) )
     {
       /* Write the CRC.  */
-      putc ('=', fp);
+      my_fputs ("=", state);
       radbuf[0] = state->crc >>16;
       radbuf[1] = state->crc >> 8;
       radbuf[2] = state->crc;
@@ -317,20 +364,30 @@
       tmp[1] = bintoasc[(((*radbuf<<4)&060)|((radbuf[1]>>4)&017))&077];
       tmp[2] = bintoasc[(((radbuf[1]<<2)&074)|((radbuf[2]>>6)&03))&077];
       tmp[3] = bintoasc[radbuf[2]&077];
-      for (idx=0; idx < 4; idx++)
-        putc (tmp[idx], fp);
-      if (ferror (fp))
-        goto write_error;
+      if (state->stream)
+        {
+          for (idx=0; idx < 4; idx++)
+            es_putc (tmp[idx], state->stream);
+          if (es_ferror (state->stream))
+            goto write_error;
+        }
+      else
+        {
+          for (idx=0; idx < 4; idx++)
+            putc (tmp[idx], state->fp);
+          if (ferror (state->fp))
+            goto write_error;
+        }
       if (!(state->flags & B64ENC_NO_LINEFEEDS)
-          && fputs ("\n", fp) == EOF)
+          && my_fputs ("\n", state) == EOF)
         goto write_error;
     }
 
   if (state->title)
     {
-      if ( fputs ("-----END ", fp) == EOF
-           || fputs (state->title, fp) == EOF
-           || fputs ("-----\n", fp) == EOF)
+      if ( my_fputs ("-----END ", state) == EOF
+           || my_fputs (state->title, state) == EOF
+           || my_fputs ("-----\n", state) == EOF)
         goto write_error;
     }
 
@@ -346,6 +403,7 @@
       state->title = NULL;
     }
   state->fp = NULL;
+  state->stream = NULL;
   return err;
 }
 

Modified: trunk/common/estream.c
===================================================================
--- trunk/common/estream.c	2010-06-28 13:37:44 UTC (rev 5365)
+++ trunk/common/estream.c	2010-07-16 13:19:45 UTC (rev 5366)
@@ -994,7 +994,7 @@
   return 0;
 }
 
-/* Destroy function for fd objects.  */
+/* Destroy function for FILE* objects.  */
 static int
 es_func_fp_destroy (void *cookie)
 {
@@ -1076,14 +1076,6 @@
   return err;
 }
 
-static es_cookie_io_functions_t estream_functions_file =
-  {
-    es_func_fd_read,
-    es_func_fd_write,
-    es_func_fd_seek,
-    es_func_fd_destroy
-  };
-
 
 static int
 es_convert_mode (const char *mode, unsigned int *modeflags)
@@ -2197,7 +2189,7 @@
     goto out;
 
   create_called = 1;
-  err = es_create (&stream, cookie, fd, estream_functions_file, modeflags, 0);
+  err = es_create (&stream, cookie, fd, estream_functions_fd, modeflags, 0);
   if (err)
     goto out;
 
@@ -2207,7 +2199,7 @@
  out:
   
   if (err && create_called)
-    (*estream_functions_file.func_close) (cookie);
+    (*estream_functions_fd.func_close) (cookie);
 
   return stream;
 }
@@ -2519,7 +2511,7 @@
 	goto leave;
 
       create_called = 1;
-      es_initialize (stream, cookie, fd, estream_functions_file, modeflags);
+      es_initialize (stream, cookie, fd, estream_functions_fd, modeflags);
 
     leave:
 

Modified: trunk/common/http.c
===================================================================
--- trunk/common/http.c	2010-06-28 13:37:44 UTC (rev 5365)
+++ trunk/common/http.c	2010-07-16 13:19:45 UTC (rev 5366)
@@ -1,6 +1,6 @@
 /* http.c  -  HTTP protocol handler
  * Copyright (C) 1999, 2001, 2002, 2003, 2004, 2006,
- *               2009 Free Software Foundation, Inc.
+ *               2009, 2010 Free Software Foundation, Inc.
  *
  * This file is part of GnuPG.
  *
@@ -57,6 +57,16 @@
 # include <netdb.h>
 #endif /*!HAVE_W32_SYSTEM*/
 
+#ifdef WITHOUT_GNU_PTH /* Give the Makefile a chance to build without Pth.  */
+# undef HAVE_PTH
+# undef USE_GNU_PTH
+#endif
+
+#ifdef HAVE_PTH
+# include <pth.h>
+#endif
+
+
 #ifdef HTTP_USE_GNUTLS
 # include <gnutls/gnutls.h>
 /* For non-understandable reasons GNUTLS dropped the _t suffix from
@@ -75,13 +85,13 @@
 #include "i18n.h"
 #include "http.h"
 #ifdef USE_DNS_SRV
-#include "srv.h"
+# include "srv.h"
 #else /*!USE_DNS_SRV*/
-/* If we are not compiling with SRV record support we provide stub
-   data structures. */
-#ifndef MAXDNAME
-#define MAXDNAME 1025
-#endif
+  /* If we are not compiling with SRV record support we provide stub
+     data structures. */
+# ifndef MAXDNAME
+#  define MAXDNAME 1025
+# endif
 struct srventry
 {
   unsigned short priority;
@@ -110,6 +120,15 @@
                         "01234567890@"                 \
                         "!\"#$%&'()*+,-./:;<=>?[\\]^_{|}~"
 
+/* A long counter type.  */
+#ifdef HAVE_STRTOULL
+typedef unsigned long long longcounter_t;
+# define counter_strtoul(a) strtoull ((a), NULL, 10)
+#else
+typedef unsigned long longcounter_t;
+# define counter_strtoul(a) strtoul ((a), NULL, 10)
+#endif
+
 /* Define a prefix to map stream functions to the estream library. */
 #ifdef HTTP_USE_ESTREAM
 #define P_ES(a)  es_ ## a
@@ -152,9 +171,19 @@
 
 struct cookie_s 
 {
-  int fd;  /* File descriptor or -1 if already closed. */
-  gnutls_session_t tls_session;  /* TLS session context or NULL if not used. */
-  int keep_socket; /* Flag to communicate with teh close handler. */
+  /* File descriptor or -1 if already closed. */
+  int fd;
+
+  /* TLS session context or NULL if not used. */
+  gnutls_session_t tls_session; 
+
+  /* The remaining content length and a flag telling whether to use
+     the content length.  */
+  longcounter_t content_length;  
+  unsigned int content_length_valid:1;
+
+  /* Flag to communicate with the close handler. */
+  unsigned int keep_socket:1; 
 };
 typedef struct cookie_s *cookie_t;
 
@@ -180,17 +209,18 @@
 {
   unsigned int status_code;
   int sock;
-  int in_data;
+  unsigned int in_data:1;
+  unsigned int is_http_0_9:1;
 #ifdef HTTP_USE_ESTREAM
   estream_t fp_read;
   estream_t fp_write;
   void *write_cookie;
+  void *read_cookie;
 #else /*!HTTP_USE_ESTREAM*/
   FILE *fp_read;
   FILE *fp_write;
 #endif /*!HTTP_USE_ESTREAM*/
   void *tls_context;
-  int is_http_0_9;
   parsed_uri_t uri;
   http_req_t req_type;
   char *buffer;          /* Line buffer. */
@@ -417,7 +447,10 @@
   hd->write_cookie = NULL;
 #endif
 
-  if (!(hd->flags & HTTP_FLAG_NO_SHUTDOWN))
+  /* Shutdown one end of the socket is desired.  As per HTTP/1.0 this
+     is not required but some very old servers (e.g. the original pksd
+     key server didn't worked without it.  */
+  if ((hd->flags & HTTP_FLAG_SHUTDOWN))
     shutdown (hd->sock, 1);
   hd->in_data = 0;
 
@@ -537,7 +570,9 @@
 gpg_error_t
 http_parse_uri (parsed_uri_t * ret_uri, const char *uri)
 {
-  *ret_uri = xcalloc (1, sizeof **ret_uri + strlen (uri));
+  *ret_uri = xtrycalloc (1, sizeof **ret_uri + strlen (uri));
+  if (!*ret_uri)
+    return gpg_error_from_syserror ();
   strcpy ((*ret_uri)->buffer, uri);
   return do_parse_uri (*ret_uri, 0);
 }
@@ -980,29 +1015,16 @@
   if (!p)
     return gpg_error_from_syserror ();
 
-  request = xtrymalloc (2 * strlen (server) 
-                        + strlen (p)
-                        + (authstr?strlen(authstr):0)
-                        + (proxy_authstr?strlen(proxy_authstr):0)
-                        + 100);
-  if (!request)
-    {
-      err = gpg_error_from_syserror ();
-      xfree (p);
-      xfree (authstr);
-      xfree (proxy_authstr);
-      return err;
-    }
-
   if (http_proxy && *http_proxy)
     {
-      sprintf (request, "%s http://%s:%hu%s%s HTTP/1.0\r\n%s%s",
-	       hd->req_type == HTTP_REQ_GET ? "GET" :
-	       hd->req_type == HTTP_REQ_HEAD ? "HEAD" :
-	       hd->req_type == HTTP_REQ_POST ? "POST" : "OOPS",
-	       server, port, *p == '/' ? "" : "/", p,
-	       authstr ? authstr : "",
-               proxy_authstr ? proxy_authstr : "");
+      request = xtryasprintf 
+        ("%s http://%s:%hu%s%s HTTP/1.0\r\n%s%s",
+         hd->req_type == HTTP_REQ_GET ? "GET" :
+         hd->req_type == HTTP_REQ_HEAD ? "HEAD" :
+         hd->req_type == HTTP_REQ_POST ? "POST" : "OOPS",
+         server, port, *p == '/' ? "" : "/", p,
+         authstr ? authstr : "",
+         proxy_authstr ? proxy_authstr : "");
     }
   else
     {
@@ -1011,16 +1033,24 @@
       if (port == 80)
         *portstr = 0;
       else
-        sprintf (portstr, ":%u", port);
+        snprintf (portstr, sizeof portstr, ":%u", port);
 
-      sprintf (request, "%s %s%s HTTP/1.0\r\nHost: %s%s\r\n%s",
-	       hd->req_type == HTTP_REQ_GET ? "GET" :
-	       hd->req_type == HTTP_REQ_HEAD ? "HEAD" :
-	       hd->req_type == HTTP_REQ_POST ? "POST" : "OOPS",
-	       *p == '/' ? "" : "/", p, server, portstr,
-               authstr? authstr:"");
+      request = xtryasprintf 
+        ("%s %s%s HTTP/1.0\r\nHost: %s%s\r\n%s",
+         hd->req_type == HTTP_REQ_GET ? "GET" :
+         hd->req_type == HTTP_REQ_HEAD ? "HEAD" :
+         hd->req_type == HTTP_REQ_POST ? "POST" : "OOPS",
+         *p == '/' ? "" : "/", p, server, portstr,
+         authstr? authstr:"");
     }
   xfree (p);
+  if (!request)
+    {
+      err = gpg_error_from_syserror ();
+      xfree (authstr);
+      xfree (proxy_authstr);
+      return err;
+    }
 
 
 #ifdef HTTP_USE_ESTREAM
@@ -1072,18 +1102,16 @@
      function and only then assign a stdio stream.  This allows for
      better error reporting that through standard stdio means. */
   err = write_server (hd->sock, request, strlen (request));
-
-  if(err==0)
-    for(;headers;headers=headers->next)
+  if (!err)
+    for (;headers;headers=headers->next)
       {
-	err = write_server( hd->sock, headers->d, strlen(headers->d) );
-	if(err)
+	err = write_server (hd->sock, headers->d, strlen(headers->d));
+	if (err)
 	  break;
-	err = write_server( hd->sock, "\r\n", 2 );
-	if(err)
+	err = write_server (hd->sock, "\r\n", 2);
+	if (err)
 	  break;
       }
-
   if (!err)
     {
       hd->fp_write = fdopen (hd->sock, "w");
@@ -1351,9 +1379,7 @@
    is valid as along as HD has not been closed and no othe request has
    been send. If the header was not found, NULL is returned.  Name
    must be canonicalized, that is the first letter of each dash
-   delimited part must be uppercase and all other letters lowercase.
-   Note that the context must have been opened with the
-   HTTP_FLAG_NEED_HEADER. */
+   delimited part must be uppercase and all other letters lowercase.  */
 const char *
 http_get_header (http_t hd, const char *name)
 {
@@ -1376,6 +1402,8 @@
 {
   char *line, *p, *p2;
   size_t maxlen, len;
+  cookie_t cookie = hd->read_cookie;
+  const char *s;
 
   /* Delete old header lines.  */
   while (hd->headers)
@@ -1447,7 +1475,7 @@
       if ( (hd->flags & HTTP_FLAG_LOG_RESP) )
         log_info ("RESP: `%.*s'\n",
                   (int)strlen(line)-(*line&&line[1]?2:0),line);
-      if ( (hd->flags & HTTP_FLAG_NEED_HEADER) && *line )
+      if (*line)
         {
           gpg_error_t err = store_header (hd, line);
           if (err)
@@ -1456,6 +1484,17 @@
     }
   while (len && *line);
 
+  cookie->content_length_valid = 0;
+  if (!(hd->flags & HTTP_FLAG_IGNORE_CL))
+    {
+      s = http_get_header (hd, "Content-Length");
+      if (s)
+        {
+          cookie->content_length_valid = 1;
+          cookie->content_length = counter_strtoul (s);
+        }
+    }
+
   return 0;
 }
 
@@ -1601,6 +1640,7 @@
 	}
     }
 #else
+  (void)flags;
   (void)srvtag;
 #endif /*USE_DNS_SRV*/
 
@@ -1739,6 +1779,7 @@
 {
   int nleft;
 
+  /* FIXME: We would better use pth I/O functions.  */
   nleft = length;
   while (nleft > 0)
     {
@@ -1787,6 +1828,14 @@
   cookie_t c = cookie;
   int nread;
 
+  if (c->content_length_valid)
+    {
+      if (!c->content_length)
+        return 0; /* EOF */
+      if (c->content_length < size)
+        size = c->content_length;
+    }
+
 #ifdef HTTP_USE_GNUTLS
   if (c->tls_session)
     {
@@ -1817,7 +1866,9 @@
     {
       do
         {
-#ifdef HAVE_W32_SYSTEM
+#ifdef HAVE_PTH
+          nread = pth_read (c->fd, buffer, size);
+#elif defined(HAVE_W32_SYSTEM)
           /* Under Windows we need to use recv for a socket.  */
           nread = recv (c->fd, buffer, size, 0);
 #else          
@@ -1827,6 +1878,14 @@
       while (nread == -1 && errno == EINTR);
     }
 
+  if (c->content_length_valid && nread > 0)
+    {
+      if (nread < c->content_length)
+        c->content_length -= nread;
+      else
+        c->content_length = 0;          
+    }
+
   return nread;
 }
 
@@ -2028,9 +2087,7 @@
   http_release_parsed_uri (uri);
   uri = NULL;
 
-  rc = http_open_document (&hd, *argv, NULL, 
-                           HTTP_FLAG_NO_SHUTDOWN | HTTP_FLAG_NEED_HEADER,
-                           NULL, tls_session);
+  rc = http_open_document (&hd, *argv, NULL, 0, NULL, tls_session);
   if (rc)
     {
       log_error ("can't get `%s': %s\n", *argv, gpg_strerror (rc));

Modified: trunk/common/http.h
===================================================================
--- trunk/common/http.h	2010-06-28 13:37:44 UTC (rev 5365)
+++ trunk/common/http.h	2010-07-16 13:19:45 UTC (rev 5366)
@@ -1,6 +1,6 @@
 /* http.h  -  HTTP protocol handler
- * Copyright (C) 1999, 2000, 2001, 2003,
- *               2006 Free Software Foundation, Inc.
+ * Copyright (C) 1999, 2000, 2001, 2003, 2006,
+ *               2010 Free Software Foundation, Inc.
  *     
  * This file is part of GnuPG.
  *
@@ -62,9 +62,9 @@
 enum
   { 
     HTTP_FLAG_TRY_PROXY = 1,
-    HTTP_FLAG_NO_SHUTDOWN = 2,
-    HTTP_FLAG_LOG_RESP = 4,
-    HTTP_FLAG_NEED_HEADER = 8
+    HTTP_FLAG_SHUTDOWN = 2,
+    HTTP_FLAG_LOG_RESP = 8,
+    HTTP_FLAG_IGNORE_CL = 32
   };
 
 struct http_context_s;

Modified: trunk/common/util.h
===================================================================
--- trunk/common/util.h	2010-06-28 13:37:44 UTC (rev 5365)
+++ trunk/common/util.h	2010-07-16 13:19:45 UTC (rev 5366)
@@ -27,6 +27,9 @@
 #ifndef GPG_ERR_MISSING_KEY
 #define GPG_ERR_MISSING_KEY 181
 #endif
+#ifndef GPG_ERR_LIMIT_REACHED
+#define GPG_ERR_LIMIT_REACHED 183
+#endif
 
 /* Hash function used with libksba. */
 #define HASH_FNC ((void (*)(void *, const void*,size_t))gcry_md_write)
@@ -128,6 +131,7 @@
   int idx;
   int quad_count;
   FILE *fp;
+  estream_t stream;
   char *title;
   unsigned char radbuf[4];
   u32 crc;
@@ -136,6 +140,8 @@
 };
 
 gpg_error_t b64enc_start (struct b64state *state, FILE *fp, const char *title);
+gpg_error_t b64enc_start_es (struct b64state *state, estream_t fp,
+                             const char *title);
 gpg_error_t b64enc_write (struct b64state *state,
                           const void *buffer, size_t nbytes);
 gpg_error_t b64enc_finish (struct b64state *state);

Modified: trunk/dirmngr/Makefile.am
===================================================================
--- trunk/dirmngr/Makefile.am	2010-06-28 13:37:44 UTC (rev 5365)
+++ trunk/dirmngr/Makefile.am	2010-07-16 13:19:45 UTC (rev 5366)
@@ -38,7 +38,7 @@
 
 dirmngr_SOURCES = dirmngr.c dirmngr.h server.c crlcache.c crlfetch.c	\
 	ldapserver.h ldapserver.c certcache.c certcache.h \
-	b64dec.c cdb.h cdblib.c ldap.c http.c http.h misc.c	\
+	cdb.h cdblib.c ldap.c misc.c dirmngr-err.h \
 	ocsp.c ocsp.h validate.c validate.h
 
 dirmngr_LDADD = $(libcommonpth) ../gl/libgnu.a $(DNSLIBS) $(LIBASSUAN_LIBS) \
@@ -56,7 +56,7 @@
 dirmngr_ldap_LDADD = $(libcommon) ../gl/libgnu.a $(DNSLIBS) \
 		     $(GPG_ERROR_LIBS) $(LDAPLIBS) $(LIBINTL) $(LIBICONV)
 
-dirmngr_client_SOURCES = dirmngr-client.c b64enc.c no-libgcrypt.c
+dirmngr_client_SOURCES = dirmngr-client.c no-libgcrypt.c
 dirmngr_client_LDADD = $(libcommon) ../gl/libgnu.a $(LIBASSUAN_LIBS) \
 	               $(GPG_ERROR_LIBS) $(LIBINTL) $(LIBICONV)
 

Modified: trunk/dirmngr/cdblib.c
===================================================================
--- trunk/dirmngr/cdblib.c	2010-06-28 13:37:44 UTC (rev 5365)
+++ trunk/dirmngr/cdblib.c	2010-07-16 13:19:45 UTC (rev 5366)
@@ -73,6 +73,8 @@
 # endif
 #endif
 #include <sys/stat.h>
+
+#include "dirmngr-err.h"
 #include "cdb.h"
 
 #ifndef EPROTO
@@ -123,13 +125,17 @@
     return -1;
   /* trivial sanity check: at least toc should be here */
   if (st.st_size < 2048) {
-    errno = EPROTO;
+    gpg_err_set_errno (EPROTO);
     return -1;
   }
   fsize = (unsigned)(st.st_size & 0xffffffffu);
   /* memory-map file */
 #ifdef _WIN32
+# ifdef __MINGW32CE__
+  hFile = fd;
+# else
   hFile = (HANDLE) _get_osfhandle(fd);
+#endif
   if (hFile == (HANDLE) -1)
     return -1;
   hMapping = CreateFileMapping(hFile, NULL, PAGE_READONLY, 0, 0, NULL);
@@ -177,7 +183,11 @@
     HANDLE hFile, hMapping;
 #endif
 #ifdef _WIN32
+#ifdef __MINGW32CE__
+    hFile = cdbp->cdb_fd;
+#else
     hFile = (HANDLE) _get_osfhandle(cdbp->cdb_fd);
+#endif
     hMapping = CreateFileMapping(hFile, NULL, PAGE_READONLY, 0, 0, NULL);
     UnmapViewOfFile((void*) cdbp->cdb_mem);
     CloseHandle(hMapping);
@@ -199,7 +209,7 @@
 cdb_read(const struct cdb *cdbp, void *buf, unsigned len, cdbi_t pos)
 {
   if (pos > cdbp->cdb_fsize || cdbp->cdb_fsize - pos < len) {
-    errno = EPROTO;
+    gpg_err_set_errno (EPROTO);
     return -1;
   }
   memcpy(buf, cdbp->cdb_mem + pos, len);
@@ -243,7 +253,7 @@
       || pos > cdbp->cdb_fsize /* htab start within file ? */
       || httodo > cdbp->cdb_fsize - pos) /* entrie htab within file ? */
   {
-    errno = EPROTO;
+    gpg_err_set_errno (EPROTO);
     return -1;
   }
 
@@ -258,19 +268,19 @@
       return 0;
     if (cdb_unpack(htp) == hval) {
       if (pos > cdbp->cdb_fsize - 8) { /* key+val lengths */
-	errno = EPROTO;
+	gpg_err_set_errno (EPROTO);
 	return -1;
       }
       if (cdb_unpack(cdbp->cdb_mem + pos) == klen) {
 	if (cdbp->cdb_fsize - klen < pos + 8) {
-	  errno = EPROTO;
+	  gpg_err_set_errno (EPROTO);
 	  return -1;
 	}
 	if (memcmp(key, cdbp->cdb_mem + pos + 8, klen) == 0) {
 	  n = cdb_unpack(cdbp->cdb_mem + pos + 4);
 	  pos += 8 + klen;
 	  if (cdbp->cdb_fsize < n || cdbp->cdb_fsize - n < pos) {
-	    errno = EPROTO;
+	    gpg_err_set_errno (EPROTO);
 	    return -1;
 	  }
 	  cdbp->cdb_vpos = pos;
@@ -331,7 +341,7 @@
           || pos > cdbp->cdb_fsize
           || cdbfp->cdb_httodo > cdbp->cdb_fsize - pos)
         {
-          errno = EPROTO;
+          gpg_err_set_errno (EPROTO);
           return -1;
         }
 
@@ -368,12 +378,12 @@
         cdbfp->cdb_httodo -= 8;
         if (n) {
           if (pos > cdbp->cdb_fsize - 8) {
-            errno = EPROTO;
+            gpg_err_set_errno (EPROTO);
             return -1;
           }
           if (cdb_unpack(cdbp->cdb_mem + pos) == cdbfp->cdb_klen) {
             if (cdbp->cdb_fsize - cdbfp->cdb_klen < pos + 8) {
-              errno = EPROTO;
+              gpg_err_set_errno (EPROTO);
               return -1;
             }
             if (memcmp(cdbfp->cdb_key,
@@ -381,7 +391,7 @@
               n = cdb_unpack(cdbp->cdb_mem + pos + 4);
               pos += 8 + cdbfp->cdb_klen;
               if (cdbp->cdb_fsize < n || cdbp->cdb_fsize - n < pos) {
-                errno = EPROTO;
+                gpg_err_set_errno (EPROTO);
                 return -1;
               }
               cdbp->cdb_vpos = pos;
@@ -410,7 +420,7 @@
                   || pos > cdbp->cdb_fsize
                   || cdbfp->cdb_httodo > cdbp->cdb_fsize - pos)
                 {
-                  errno = EPROTO;
+                  gpg_err_set_errno (EPROTO);
                   return -1;
                 }
               
@@ -425,7 +435,7 @@
       while (!pos);
       if (pos > cdbp->cdb_fsize - 8)
         {
-          errno = EPROTO;
+          gpg_err_set_errno (EPROTO);
           return -1;
         }
       
@@ -436,7 +446,7 @@
       n = 8 + cdbp->cdb_klen + cdbp->cdb_vlen;
       if ( pos > cdbp->cdb_fsize || pos > cdbp->cdb_fsize - n)
         {
-          errno = EPROTO;
+          gpg_err_set_errno (EPROTO);
           return -1;
         }
       return 1; /* Found. */
@@ -454,7 +464,7 @@
     while(l < 0 && errno == EINTR);
     if (l <= 0) {
       if (!l)
-        errno = EIO;
+        gpg_err_set_errno (EIO);
       return -1;
     }
     buf = (char*)buf + l;
@@ -555,7 +565,7 @@
   struct cdb_rl *rl;
   if (klen > 0xffffffff - (cdbmp->cdb_dpos + 8) ||
       vlen > 0xffffffff - (cdbmp->cdb_dpos + klen + 8)) {
-    errno = ENOMEM;
+    gpg_err_set_errno (ENOMEM);
     return -1;
   }
   hval = cdb_hash(key, klen);
@@ -563,7 +573,7 @@
   if (!rl || rl->cnt >= sizeof(rl->rec)/sizeof(rl->rec[0])) {
     rl = (struct cdb_rl*)malloc(sizeof(struct cdb_rl));
     if (!rl) {
-      errno = ENOMEM;
+      gpg_err_set_errno (ENOMEM);
       return -1;
     }
     rl->cnt = 0;
@@ -603,7 +613,7 @@
 	return -1;
       if (c) {
 	if (flags == CDB_PUT_INSERT) {
-	  errno = EEXIST;
+	  gpg_err_set_errno (EEXIST);
 	  return 1;
 	}
 	else if (flags == CDB_PUT_REPLACE) {
@@ -621,7 +631,7 @@
       if (!rl || rl->cnt >= sizeof(rl->rec)/sizeof(rl->rec[0])) {
  	rl = (struct cdb_rl*)malloc(sizeof(struct cdb_rl));
 	if (!rl) {
-	  errno = ENOMEM;
+	  gpg_err_set_errno (ENOMEM);
 	  return -1;
 	}
 	rl->cnt = 0;
@@ -633,13 +643,13 @@
       break;
 
     default:
-      errno = EINVAL;
+      gpg_err_set_errno (EINVAL);
       return -1;
   }
 
   if (klen > 0xffffffff - (cdbmp->cdb_dpos + 8) ||
       vlen > 0xffffffff - (cdbmp->cdb_dpos + klen + 8)) {
-    errno = ENOMEM;
+    gpg_err_set_errno (ENOMEM);
     return -1;
   }
   rl->rec[c].hval = hval;
@@ -812,7 +822,7 @@
   unsigned t, i;
 
   if (((0xffffffff - cdbmp->cdb_dpos) >> 3) < cdbmp->cdb_rcnt) {
-    errno = ENOMEM;
+    gpg_err_set_errno (ENOMEM);
     return -1;
   }
 
@@ -837,7 +847,7 @@
   /* allocate memory to hold max htable */
   htab = (struct cdb_rec*)malloc((hsize + 2) * sizeof(struct cdb_rec));
   if (!htab) {
-    errno = ENOENT;
+    gpg_err_set_errno (ENOENT);
     return -1;
   }
   p = (unsigned char *)htab;

Modified: trunk/dirmngr/certcache.c
===================================================================
--- trunk/dirmngr/certcache.c	2010-06-28 13:37:44 UTC (rev 5365)
+++ trunk/dirmngr/certcache.c	2010-07-16 13:19:45 UTC (rev 5366)
@@ -328,7 +328,7 @@
   struct dirent *ep;
   char *p;
   size_t n;
-  FILE *fp;
+  estream_t fp;
   ksba_reader_t reader;
   ksba_cert_t cert;
   char *fname = NULL;
@@ -353,7 +353,7 @@
       
       xfree (fname);
       fname = make_filename (dirname, p, NULL);
-      fp = fopen (fname, "rb");
+      fp = es_fopen (fname, "rb");
       if (!fp)
         {
           log_error (_("can't open `%s': %s\n"),
@@ -367,7 +367,7 @@
         {
           log_error (_("can't setup KSBA reader: %s\n"), gpg_strerror (err));
           ksba_reader_release (reader);
-          fclose (fp);
+          es_fclose (fp);
           continue;
         }
 
@@ -375,7 +375,7 @@
       if (!err)
         err = ksba_cert_read_der (cert, reader);
       ksba_reader_release (reader);
-      fclose (fp);
+      es_fclose (fp);
       if (err)
         {
           log_error (_("can't parse certificate `%s': %s\n"),

Modified: trunk/dirmngr/crlcache.c
===================================================================
--- trunk/dirmngr/crlcache.c	2010-06-28 13:37:44 UTC (rev 5365)
+++ trunk/dirmngr/crlcache.c	2010-07-16 13:19:45 UTC (rev 5366)
@@ -218,7 +218,7 @@
           log_error (_("error creating directory `%s': %s\n"),
                      fname, strerror (errno));
           xfree (fname);
-          errno = save_errno;
+          gpg_err_set_errno (save_errno);
           return -1;
         }
     } 
@@ -298,7 +298,7 @@
    removed, the function will read the last line of a file, even if
    that is not terminated by a LF. */
 static char *
-next_line_from_file (FILE *fp, gpg_error_t *r_err)
+next_line_from_file (estream_t fp, gpg_error_t *r_err)
 {
   char buf[300];
   char *largebuf = NULL;
@@ -311,7 +311,7 @@
   *r_err = 0;
   p = buf;
   buflen = sizeof buf - 1;
-  while ((c=getc (fp)) != EOF && c != '\n')
+  while ((c=es_getc (fp)) != EOF && c != '\n')
     {
       if (len >= buflen)
         {
@@ -401,12 +401,12 @@
 
 /* Open the dir file FNAME or create a new one if it does not yet
    exist. */
-static FILE *
+static estream_t
 open_dir_file (const char *fname)
 {
-  FILE *fp;
+  estream_t fp;
 
-  fp = fopen (fname, "r");
+  fp = es_fopen (fname, "r");
   if (!fp)
     {
       log_error (_("failed to open cache dir file `%s': %s\n"),
@@ -416,22 +416,22 @@
       if (create_directory_if_needed (NULL) 
           || create_directory_if_needed (DBDIR_D)) 
         return NULL;
-      fp = fopen (fname, "w");
+      fp = es_fopen (fname, "w");
       if (!fp)
         {
           log_error (_("error creating new cache dir file `%s': %s\n"),
                      fname, strerror (errno));
           return NULL;
         }
-      fprintf (fp, "v:%d:\n", DBDIRVERSION);
-      if (ferror (fp))
+      es_fprintf (fp, "v:%d:\n", DBDIRVERSION);
+      if (es_ferror (fp))
         {
           log_error (_("error writing new cache dir file `%s': %s\n"),
                      fname, strerror (errno));
-          fclose (fp);
+          es_fclose (fp);
           return NULL;
         }
-      if (fclose (fp))
+      if (es_fclose (fp))
         {
           log_error (_("error closing new cache dir file `%s': %s\n"),
                      fname, strerror (errno));
@@ -440,7 +440,7 @@
 
       log_info (_("new cache dir file `%s' created\n"), fname);
 
-      fp = fopen (fname, "r");
+      fp = es_fopen (fname, "r");
       if (!fp)
         {
           log_error (_("failed to re-open cache dir file `%s': %s\n"),
@@ -454,13 +454,13 @@
 
 /* Helper for open_dir. */
 static gpg_error_t
-check_dir_version (FILE **fpadr, const char *fname,
+check_dir_version (estream_t *fpadr, const char *fname,
                          unsigned int *lineno,
                          int cleanup_on_mismatch)
 {
   char *line;
   gpg_error_t lineerr = 0;
-  FILE *fp = *fpadr;
+  estream_t fp = *fpadr;
   int created = 0;
 
  retry:
@@ -485,7 +485,7 @@
       if (!created && cleanup_on_mismatch)
         {
           log_error (_("old version of cache directory - cleaning up\n"));
-          fclose (fp);
+          es_fclose (fp);
           *fpadr = NULL;
           if (!cleanup_cache_dir (1))
             {
@@ -521,7 +521,7 @@
   char *fname; 
   char *line = NULL;
   gpg_error_t lineerr = 0;
-  FILE *fp;
+  estream_t fp;
   crl_cache_entry_t entry, *entrytail;
   unsigned int lineno;
   gpg_error_t err = 0;
@@ -649,7 +649,7 @@
       log_error (_("error reading `%s': %s\n"), fname, gpg_strerror (err));
       goto leave;
     }
-  if (ferror (fp))
+  if (es_ferror (fp))
     {
       log_error (_("error reading `%s': %s\n"), fname, strerror (errno));
       err = gpg_error (GPG_ERR_CONFIGURATION);
@@ -695,8 +695,7 @@
 
 
  leave:
-  if (fp)
-    fclose (fp);
+  es_fclose (fp);
   xfree (line);
   xfree (fname);
   if (err)
@@ -709,54 +708,54 @@
 }
 
 static void
-write_percented_string (const char *s, FILE *fp)
+write_percented_string (const char *s, estream_t fp)
 {
   for (; *s; s++)
     if (*s == ':')
-      fputs ("%3A", fp);
+      es_fputs ("%3A", fp);
     else if (*s == '\n')
-      fputs ("%0A", fp);
+      es_fputs ("%0A", fp);
     else if (*s == '\r')
-      fputs ("%0D", fp);
+      es_fputs ("%0D", fp);
     else
-      putc (*s, fp);
+      es_putc (*s, fp);
 }
 
 
 static void
-write_dir_line_crl (FILE *fp, crl_cache_entry_t e)
+write_dir_line_crl (estream_t fp, crl_cache_entry_t e)
 {
   if (e->invalid)
-    fprintf (fp, "i%d", e->invalid);
+    es_fprintf (fp, "i%d", e->invalid);
   else if (e->user_trust_req)
-    putc ('u', fp);
+    es_putc ('u', fp);
   else
-    putc ('c', fp);
-  putc (':', fp);
-  fputs (e->issuer_hash, fp);
-  putc (':', fp);
+    es_putc ('c', fp);
+  es_putc (':', fp);
+  es_fputs (e->issuer_hash, fp);
+  es_putc (':', fp);
   write_percented_string (e->issuer, fp);
-  putc (':', fp);
+  es_putc (':', fp);
   write_percented_string (e->url, fp);
-  putc (':', fp);
-  fwrite (e->this_update, 15, 1, fp); 
-  putc (':', fp);
-  fwrite (e->next_update, 15, 1, fp); 
-  putc (':', fp);
-  fputs (e->dbfile_hash, fp);
-  putc (':', fp);
+  es_putc (':', fp);
+  es_fwrite (e->this_update, 15, 1, fp); 
+  es_putc (':', fp);
+  es_fwrite (e->next_update, 15, 1, fp); 
+  es_putc (':', fp);
+  es_fputs (e->dbfile_hash, fp);
+  es_putc (':', fp);
   if (e->crl_number)
-    fputs (e->crl_number, fp);
-  putc (':', fp);
+    es_fputs (e->crl_number, fp);
+  es_putc (':', fp);
   if (e->authority_issuer)
     write_percented_string (e->authority_issuer, fp);
-  putc (':', fp);
+  es_putc (':', fp);
   if (e->authority_serialno)
-    fputs (e->authority_serialno, fp);
-  putc (':', fp);
+    es_fputs (e->authority_serialno, fp);
+  es_putc (':', fp);
   if (e->check_trust_anchor && e->user_trust_req)
-    fputs (e->check_trust_anchor, fp);
-  putc ('\n', fp);
+    es_fputs (e->check_trust_anchor, fp);
+  es_putc ('\n', fp);
 }
 
 
@@ -768,7 +767,8 @@
   char *tmpfname = NULL;
   char *line = NULL;
   gpg_error_t lineerr = 0;
-  FILE *fp, *fpout = NULL;
+  estream_t fp;
+  estream_t fpout = NULL;
   crl_cache_entry_t e;
   unsigned int lineno;
   gpg_error_t err = 0;
@@ -781,7 +781,7 @@
     e->mark = 1;
 
   lineno = 0;
-  fp = fopen (fname, "r");
+  fp = es_fopen (fname, "r");
   if (!fp)
     {
       err = gpg_error_from_errno (errno);
@@ -792,7 +792,7 @@
   err = check_dir_version (&fp, fname, &lineno, 0);
   if (err)
     goto leave;
-  rewind (fp);
+  es_rewind (fp);
   lineno = 0;
 
   /* Create a temporary DIR file. */
@@ -827,7 +827,7 @@
     tmpfname = make_filename (opt.homedir_cache, DBDIR_D, tmpbuf, NULL);
     xfree (tmpbuf);
   }
-  fpout = fopen (tmpfname, "w");
+  fpout = es_fopen (tmpfname, "w");
   if (!fpout)
     {
       err = gpg_error_from_errno (errno);
@@ -868,30 +868,30 @@
                 { /* We ignore entries we don't have in our cache
                      because they may have been added in the meantime
                      by other instances of dirmngr. */
-                  fprintf (fpout, "# Next line added by "
-                           "another process; our pid is %lu\n", 
-                           (unsigned long)getpid ());
-                  fputs (line, fpout);
-                  putc ('\n', fpout);
+                  es_fprintf (fpout, "# Next line added by "
+                              "another process; our pid is %lu\n", 
+                              (unsigned long)getpid ());
+                  es_fputs (line, fpout);
+                  es_putc ('\n', fpout);
                 }
             }
           else
             {
-              fputs ("# Invalid line detected: ", fpout);
-              fputs (line, fpout);
-              putc ('\n', fpout);
+              es_fputs ("# Invalid line detected: ", fpout);
+              es_fputs (line, fpout);
+              es_putc ('\n', fpout);
             }
         }
       else 
         {
           /* Write out all non CRL lines as they are. */
-          fputs (line, fpout);
-          putc ('\n', fpout);
+          es_fputs (line, fpout);
+          es_putc ('\n', fpout);
         }
 
       xfree (line);
     }
-  if (!ferror (fp) && !ferror (fpout) && !lineerr)
+  if (!es_ferror (fp) && !ferror (es_fpout) && !lineerr)
     {
       /* Write out the remaining entries. */
       for (e= cache->entries; e; e = e->next)
@@ -908,12 +908,12 @@
       log_error (_("error reading `%s': %s\n"), fname, gpg_strerror (err));
       goto leave;
     }
-  if (ferror (fp))
+  if (es_ferror (fp))
     {
       err = gpg_error_from_errno (errno);
       log_error (_("error reading `%s': %s\n"), fname, strerror (errno));
     }
-  if (ferror (fpout))
+  if (es_ferror (fpout))
     {
       err = gpg_error_from_errno (errno);
       log_error (_("error writing `%s': %s\n"), tmpfname, strerror (errno));
@@ -922,9 +922,9 @@
     goto leave;
 
   /* Rename the files. */
-  fclose (fp);
+  es_fclose (fp);
   fp = NULL;
-  if (fclose (fpout))
+  if (es_fclose (fpout))
     {
       err = gpg_error_from_errno (errno);
       log_error (_("error closing `%s': %s\n"), tmpfname, strerror (errno));
@@ -947,14 +947,13 @@
  leave:
   /* Fixme: Relinquish update lock. */
   xfree (line);
-  if (fp)
-    fclose (fp);
+  es_fclose (fp);
   xfree (fname);
   if (fpout)
     {
-      fclose (fpout);
+      es_fclose (fpout);
       if (err && tmpfname)
-        remove (tmpfname);
+        gnupg_remove (tmpfname);
     }
   xfree (tmpfname);
   return err;
@@ -984,14 +983,14 @@
 static int
 hash_dbfile (const char *fname, unsigned char *md5buffer)
 {
-  FILE *fp;
+  estream_t fp;
   char *buffer;
   size_t n;
   gcry_md_hd_t md5;
   gpg_err_code_t err;
 
   buffer = xtrymalloc (65536);
-  fp = buffer? fopen (fname, "rb") : NULL;
+  fp = buffer? es_fopen (fname, "rb") : NULL;
   if (!fp)
     {
       log_error (_("can't hash `%s': %s\n"), fname, strerror (errno));
@@ -1005,7 +1004,7 @@
       log_error (_("error setting up MD5 hash context: %s\n"),
                  gpg_strerror (err));
       xfree (buffer);
-      fclose (fp);
+      es_fclose (fp);
       return -1;
     }
 
@@ -1015,12 +1014,12 @@
     
   for (;;)
     {
-      n = fread (buffer, 1, 65536, fp);
-      if (n < 65536 && ferror (fp))
+      n = es_fread (buffer, 1, 65536, fp);
+      if (n < 65536 && es_ferror (fp))
         {
           log_error (_("error hashing `%s': %s\n"), fname, strerror (errno));
           xfree (buffer);
-          fclose (fp);
+          es_fclose (fp);
           gcry_md_close (md5);
           return -1;
         }
@@ -1028,7 +1027,7 @@
         break;
       gcry_md_write (md5, buffer, n);
     }
-  fclose (fp);
+  es_fclose (fp);
   xfree (buffer);
   gcry_md_final (md5);
 
@@ -2017,7 +2016,7 @@
         *p = '.';
     fname = make_filename (opt.homedir_cache, DBDIR_D, tmpfname, NULL);
     xfree (tmpfname);
-    if (!remove (fname))
+    if (!gnupg_remove (fname))
       log_info (_("removed stale temporary cache file `%s'\n"), fname);
     else if (errno != ENOENT) 
       {
@@ -2198,7 +2197,7 @@
     close (fd_cdb);
   if (fname)
     {
-      remove (fname);
+      gnupg_remove (fname);
       xfree (fname);
     }
   xfree (newfname);
@@ -2214,7 +2213,7 @@
 /* Print one cached entry E in a human readable format to stream
    FP. Return 0 on success. */
 static gpg_error_t
-list_one_crl_entry (crl_cache_t cache, crl_cache_entry_t e, FILE *fp)
+list_one_crl_entry (crl_cache_t cache, crl_cache_entry_t e, estream_t fp)
 {
   struct cdb_find cdbfp;
   struct cdb *cdb;
@@ -2222,44 +2221,46 @@
   int warn = 0;
   const unsigned char *s;
 
-  fputs ("--------------------------------------------------------\n", fp );
-  fprintf (fp, _("Begin CRL dump (retrieved via %s)\n"), e->url );
-  fprintf (fp, " Issuer:\t%s\n", e->issuer );
-  fprintf (fp, " Issuer Hash:\t%s\n", e->issuer_hash );
-  fprintf (fp, " This Update:\t%s\n", e->this_update ); 
-  fprintf (fp, " Next Update:\t%s\n", e->next_update ); 
-  fprintf (fp, " CRL Number :\t%s\n", e->crl_number? e->crl_number: "none");
-  fprintf (fp, " AuthKeyId  :\t%s\n",
-           e->authority_serialno? e->authority_serialno:"none");
+  es_fputs ("--------------------------------------------------------\n", fp );
+  es_fprintf (fp, _("Begin CRL dump (retrieved via %s)\n"), e->url );
+  es_fprintf (fp, " Issuer:\t%s\n", e->issuer );
+  es_fprintf (fp, " Issuer Hash:\t%s\n", e->issuer_hash );
+  es_fprintf (fp, " This Update:\t%s\n", e->this_update ); 
+  es_fprintf (fp, " Next Update:\t%s\n", e->next_update ); 
+  es_fprintf (fp, " CRL Number :\t%s\n", e->crl_number? e->crl_number: "none");
+  es_fprintf (fp, " AuthKeyId  :\t%s\n",
+              e->authority_serialno? e->authority_serialno:"none");
   if (e->authority_serialno && e->authority_issuer)
     {
-      fputs ("             \t", fp);
+      es_fputs ("             \t", fp);
       for (s=e->authority_issuer; *s; s++)
         if (*s == '\x01')
-          fputs ("\n             \t", fp);
+          es_fputs ("\n             \t", fp);
         else
-          putc (*s, fp);
-      putc ('\n', fp);
+          es_putc (*s, fp);
+      es_putc ('\n', fp);
     }
-  fprintf (fp, " Trust Check:\t%s\n", 
-           !e->user_trust_req? "[system]" :
-           e->check_trust_anchor? e->check_trust_anchor:"[missing]");
+  es_fprintf (fp, " Trust Check:\t%s\n", 
+              !e->user_trust_req? "[system]" :
+              e->check_trust_anchor? e->check_trust_anchor:"[missing]");
 
   if ((e->invalid & 1))
-    fprintf (fp, _(" ERROR: The CRL will not be used because it was still too old after an update!\n"));




More information about the Gnupg-commits mailing list