#include <version-etc.h>
#include <read-file.h>
#include <getpass.h>
+#include <minmax.h>
#include "common.h"
#include "cli-gaa.h"
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;
}
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");
#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");