]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
Use read_binary_file from gnulib instead of strfile stuff,
authorSimon Josefsson <simon@josefsson.org>
Fri, 16 Jun 2006 13:29:35 +0000 (13:29 +0000)
committerSimon Josefsson <simon@josefsson.org>
Fri, 16 Jun 2006 13:29:35 +0000 (13:29 +0000)
to fix problem with binary files on mingw.

configure.in
lib/Makefile.am
lib/gnutls_x509.c
libextra/gnutls_openpgp.c

index ede9faea0681a48eb8df374ec04667bbcf181dba..0a8f916c31fef1cd32eb428980145a50e93541d6 100644 (file)
@@ -183,7 +183,7 @@ AC_CHECK_HEADERS(errno.h sys/time.h time.h)
 AC_CHECK_HEADERS(math.h limits.h float.h stdarg.h ctype.h)
 dnl opencdk
 AC_CHECK_HEADERS(netdb.h)
-AC_CHECK_FUNCS(umask vasprintf isascii mmap gmtime_r,,)
+AC_CHECK_FUNCS(umask vasprintf isascii gmtime_r,,)
 AC_FUNC_ALLOCA
 
 AC_MSG_RESULT([***
index 504dbf62bf572c5625430158346af5e00cc2688f..310840e8c6cae4d489449ee9391d6bc6ac410d16 100644 (file)
@@ -84,9 +84,9 @@ HFILES = debug.h gnutls_compress.h defines.h gnutls_cipher.h          \
        gnutls_extensions.h gnutls_buffer.h gnutls_auth_int.h           \
        x509_b64.h gnutls_v2_compat.h gnutls_datum.h auth_cert.h        \
        gnutls_mpi.h gnutls_pk.h gnutls_record.h gnutls_cert.h          \
-       gnutls_constate.h gnutls_global.h strfile.h gnutls_sig.h        \
-       gnutls_mem.h io_debug.h ext_max_record.h gnutls_session_pack.h  \
-       gnutls_str.h gnutls_state.h gnutls_x509.h ext_cert_type.h       \
+       gnutls_constate.h gnutls_global.h gnutls_sig.h gnutls_mem.h     \
+       io_debug.h ext_max_record.h gnutls_session_pack.h gnutls_str.h  \
+       gnutls_state.h gnutls_x509.h ext_cert_type.h                    \
        gnutls_rsa_export.h ext_server_name.h auth_dh_common.h          \
        ext_srp.h gnutls_srp.h auth_srp.h auth_srp_passwd.h             \
        gnutls_helper.h auth_psk.h auth_psk_passwd.h                    \
index ba4021f3b0ea1323cd5f9d0e6e44ab4af1cdc641..bee9748e28a21472a48b0b7b212b4a1cb5a41514 100644 (file)
@@ -48,6 +48,7 @@
 #include "x509/mpi.h"
 #include "x509/pkcs7.h"
 #include "x509/privkey.h"
+#include "read-file.h"
 
 /*
  * some x509 certificate parsing functions.
@@ -737,126 +738,6 @@ read_key_mem (gnutls_certificate_credentials_t res,
   return 0;
 }
 
-/* Opens a file reads its contents and stores it
- * in allocated memory, which is returned.
- */
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <errno.h>
-
-#ifdef HAVE_MMAP
-# include <unistd.h>
-# include <sys/mman.h>
-# ifndef MAP_FAILED
-#  define MAP_FAILED (void *)-1L
-# endif
-#endif
-
-#include <strfile.h>
-
-void
-_gnutls_strfile_free (strfile * x)
-{
-#ifdef HAVE_MMAP
-  if (x->mmaped)
-    {
-      munmap (x->data, x->size);
-      return;
-    }
-#endif
-
-  gnutls_free (x->data);
-  x->data = NULL;
-}
-
-strfile
-_gnutls_file_to_str (const char *file)
-{
-  int fd1 = -1;
-  struct stat stat_st;
-  size_t tot_size;
-  size_t left;
-  opaque *tmp;
-  ssize_t i = 0;
-  strfile null = { NULL, 0, 0 };
-  strfile ret = { NULL, 0, 0 };
-
-  fd1 = open (file, 0);
-  if (fd1 == -1)
-    {
-      gnutls_assert ();
-      return null;
-    }
-
-  if (fstat (fd1, &stat_st) == -1)
-    {
-      gnutls_assert ();
-      goto error;
-    }
-
-  tot_size = stat_st.st_size;
-  if (tot_size == 0)
-    {
-      gnutls_assert ();
-      goto error;
-    }
-#ifdef HAVE_MMAP
-  if ((tmp =
-       mmap (NULL, tot_size, PROT_READ, MAP_SHARED, fd1, 0)) != MAP_FAILED)
-    {
-      ret.mmaped = 1;
-      ret.data = tmp;
-      ret.size = tot_size;
-
-      close (fd1);
-      return ret;
-    }
-#endif
-
-  ret.data = gnutls_malloc (tot_size);
-  if (ret.data == NULL)
-    {
-      gnutls_assert ();
-      goto error;
-    }
-
-  left = tot_size;
-  while (left > 0)
-    {
-      i = read (fd1, &ret.data[tot_size - left], left);
-      if (i == -1)
-       {
-         if (errno == EAGAIN || errno == EINTR)
-           continue;
-         else
-           {
-             gnutls_assert ();
-             goto error;
-           }
-       }
-      else if (i == 0)
-       break;
-
-      left -= i;
-    }
-
-  ret.size = tot_size - left;
-
-  ret.mmaped = 0;
-
-  close (fd1);
-
-  return ret;
-
-error:
-
-  if (!ret.mmaped)
-    gnutls_free (ret.data);
-  close (fd1);
-  return null;
-}
-
 /* Reads a certificate file
  */
 static int
@@ -864,17 +745,17 @@ read_cert_file (gnutls_certificate_credentials_t res,
                const char *certfile, gnutls_x509_crt_fmt_t type)
 {
   int ret;
-  strfile x;
+  size_t size;
+  char *data = read_binary_file (certfile, &size);
 
-  x = _gnutls_file_to_str (certfile);
-  if (x.data == NULL)
+  if (data == NULL)
     {
       gnutls_assert ();
       return GNUTLS_E_FILE_ERROR;
     }
 
-  ret = read_cert_mem (res, x.data, x.size, type);
-  _gnutls_strfile_free (&x);
+  ret = read_cert_mem (res, data, size, type);
+  free (data);
 
   return ret;
 
@@ -890,17 +771,17 @@ read_key_file (gnutls_certificate_credentials_t res,
               const char *keyfile, gnutls_x509_crt_fmt_t type)
 {
   int ret;
-  strfile x;
+  size_t size;
+  char *data = read_binary_file (keyfile, &size);
 
-  x = _gnutls_file_to_str (keyfile);
-  if (x.data == NULL)
+  if (data == NULL)
     {
       gnutls_assert ();
       return GNUTLS_E_FILE_ERROR;
     }
 
-  ret = read_key_mem (res, x.data, x.size, type);
-  _gnutls_strfile_free (&x);
+  ret = read_key_mem (res, data, size, type);
+  free (data);
 
   return ret;
 }
@@ -1482,10 +1363,10 @@ gnutls_certificate_set_x509_trust_file (gnutls_certificate_credentials_t
                                        gnutls_x509_crt_fmt_t type)
 {
   int ret, ret2;
-  strfile x;
+  size_t size;
+  char *data = read_binary_file (cafile, &size);
 
-  x = _gnutls_file_to_str (cafile);
-  if (x.data == NULL)
+  if (data == NULL)
     {
       gnutls_assert ();
       return GNUTLS_E_FILE_ERROR;
@@ -1493,12 +1374,12 @@ gnutls_certificate_set_x509_trust_file (gnutls_certificate_credentials_t
 
   if (type == GNUTLS_X509_FMT_DER)
     ret = parse_der_ca_mem (&res->x509_ca_list, &res->x509_ncas,
-                           x.data, x.size);
+                           data, size);
   else
     ret = parse_pem_ca_mem (&res->x509_ca_list, &res->x509_ncas,
-                           x.data, x.size);
+                           data, size);
 
-  _gnutls_strfile_free (&x);
+  free (data);
 
   if (ret < 0)
     {
@@ -1776,10 +1657,10 @@ gnutls_certificate_set_x509_crl_file (gnutls_certificate_credentials_t
                                      gnutls_x509_crt_fmt_t type)
 {
   int ret;
-  strfile x;
+  size_t size;
+  char *data = read_binary_file (crlfile, &size);
 
-  x = _gnutls_file_to_str (crlfile);
-  if (x.data == NULL)
+  if (data == NULL)
     {
       gnutls_assert ();
       return GNUTLS_E_FILE_ERROR;
@@ -1787,12 +1668,12 @@ gnutls_certificate_set_x509_crl_file (gnutls_certificate_credentials_t
 
   if (type == GNUTLS_X509_FMT_DER)
     ret = parse_der_crl_mem (&res->x509_crl_list, &res->x509_ncrls,
-                            x.data, x.size);
+                            data, size);
   else
     ret = parse_pem_crl_mem (&res->x509_crl_list, &res->x509_ncrls,
-                            x.data, x.size);
+                            data, size);
 
-  _gnutls_strfile_free (&x);
+  free (data);
 
   if (ret < 0)
     {
@@ -2000,7 +1881,6 @@ int
   gnutls_x509_crt_t cert = NULL;
   gnutls_x509_crl_t crl = NULL;
   int ret;
-  strfile x;
 
   ret = gnutls_pkcs12_init (&p12);
   if (ret < 0)
@@ -2009,19 +1889,16 @@ int
       return ret;
     }
 
-  x = _gnutls_file_to_str (pkcs12file);
-  if (x.data == NULL)
+  p12blob.data = read_binary_file (pkcs12file, &p12blob.size);
+  if (p12blob.data == NULL)
     {
       gnutls_assert ();
       gnutls_pkcs12_deinit (p12);
       return GNUTLS_E_FILE_ERROR;
     }
 
-  p12blob.data = x.data;
-  p12blob.size = x.size;
-
   ret = gnutls_pkcs12_import (p12, &p12blob, type, 0);
-  _gnutls_strfile_free (&x);
+  free (p12blob.data);
   if (ret < 0)
     {
       gnutls_assert ();
index 750c3b4e97814e78f24618449b3dab2d29db743d..478b4bd63fe2dc81ba0ba91f5784143837e177ca 100644 (file)
@@ -29,7 +29,7 @@
 #include "gnutls_datum.h"
 #include "gnutls_global.h"
 #include <openpgp/gnutls_openpgp.h>
-#include <strfile.h>
+#include "read-file.h"
 #include <gnutls_str.h>
 #include <stdio.h>
 #include <gcrypt.h>
@@ -723,7 +723,6 @@ gnutls_certificate_set_openpgp_key_file (gnutls_certificate_credentials_t
   struct stat statbuf;
   int rc = 0;
   gnutls_datum_t key, cert;
-  strfile xcert, xkey;
 
   if (!res || !keyfile || !certfile)
     {
@@ -737,31 +736,25 @@ gnutls_certificate_set_openpgp_key_file (gnutls_certificate_credentials_t
       return GNUTLS_E_FILE_ERROR;
     }
 
-  xcert = _gnutls_file_to_str (certfile);
-  if (xcert.data == NULL)
+  cert.data = read_binary_file (certfile, &cert.size);
+  if (cert.data == NULL)
     {
       gnutls_assert ();
       return GNUTLS_E_FILE_ERROR;
     }
 
-  xkey = _gnutls_file_to_str (keyfile);
-  if (xkey.data == NULL)
+  key.data = read_binary_file (keyfile, &key.size);
+  if (key.data == NULL)
     {
       gnutls_assert ();
-      _gnutls_strfile_free (&xcert);
+      free (cert.data);
       return GNUTLS_E_FILE_ERROR;
     }
 
-  key.data = xkey.data;
-  key.size = xkey.size;
-
-  cert.data = xcert.data;
-  cert.size = xcert.size;
-
   rc = gnutls_certificate_set_openpgp_key_mem (res, &cert, &key);
 
-  _gnutls_strfile_free (&xcert);
-  _gnutls_strfile_free (&xkey);
+  free (cert.data);
+  free (key.data);
 
   if (rc < 0)
     {