From: Simon Josefsson Date: Wed, 11 Feb 2009 16:26:16 +0000 (+0100) Subject: Use more gnulib interfaces. X-Git-Tag: gnutls_2_7_6~28 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=20ab2b58da366d7ee3a8fb35e306e021d172eae7;p=thirdparty%2Fgnutls.git Use more gnulib interfaces. --- diff --git a/src/cli.c b/src/cli.c index 97f01a4595..9b9c57d7e4 100644 --- a/src/cli.c +++ b/src/cli.c @@ -44,6 +44,7 @@ #include #include #include +#include #include "common.h" #include "cli-gaa.h" @@ -115,34 +116,19 @@ static void check_rehandshake (socket_st * socket, int ret); static int do_handshake (socket_st * socket); static void init_global_tls_stuff (void); - -#undef MAX -#define MAX(X,Y) (X >= Y ? X : Y); - - /* Helper functions to load a certificate and key * files into memory. */ static gnutls_datum_t load_file (const char *file) { - FILE *f; gnutls_datum_t loaded_file = { NULL, 0 }; - long filelen; - void *ptr; - - if (!(f = fopen (file, "r")) - || fseek (f, 0, SEEK_END) != 0 - || (filelen = ftell (f)) < 0 - || fseek (f, 0, SEEK_SET) != 0 - || !(ptr = malloc ((size_t) filelen)) - || fread (ptr, 1, (size_t) filelen, f) < (size_t) filelen) - { - return loaded_file; - } + size_t length; + + loaded_file.data = read_binary_file (file, &length); + if (loaded_file.data) + loaded_file.size = (unsigned int) length; - loaded_file.data = ptr; - loaded_file.size = (unsigned int) filelen; return loaded_file; } @@ -1077,9 +1063,8 @@ init_global_tls_stuff (void) if (x509_cafile != NULL) { - ret = - gnutls_certificate_set_x509_trust_file (xcred, - x509_cafile, x509ctype); + ret = gnutls_certificate_set_x509_trust_file (xcred, + x509_cafile, x509ctype); if (ret < 0) { fprintf (stderr, "Error setting the x509 trust file\n"); @@ -1092,8 +1077,8 @@ init_global_tls_stuff (void) #ifdef ENABLE_PKI if (x509_crlfile != NULL) { - ret = - gnutls_certificate_set_x509_crl_file (xcred, x509_crlfile, x509ctype); + ret = gnutls_certificate_set_x509_crl_file (xcred, x509_crlfile, + x509ctype); if (ret < 0) { fprintf (stderr, "Error setting the x509 CRL file\n");