From 4ff0c359ee7e2b002d96a0a1ff70e9577cde3f51 Mon Sep 17 00:00:00 2001 From: leonid-ed Date: Wed, 25 May 2016 18:05:40 +0300 Subject: [PATCH] [code] Added checking on existence of certificate files; --- lib/hub.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/lib/hub.c b/lib/hub.c index 362aafe..f8e2cb1 100644 --- a/lib/hub.c +++ b/lib/hub.c @@ -651,10 +651,28 @@ sxhub_t *sxhub_create(void) int sxhub_setsslserts(sxhub_t *ssys, const char *rootca, const char *certpem, const char *certkey) { - int r = ENOMEM; + if (!ssys || !rootca || !certpem || !certkey) + return EINVAL; + + /* check on existence of certificate files */ + if (access(rootca, R_OK) == -1) { + fprintf(stderr, "Unable to access rootca file ('%s'): ", rootca); + perror(""); + return ENOENT; + } + if (access(certpem, R_OK) == -1) { + fprintf(stderr, "Unable to access certpem file ('%s'): ", certpem); + perror(""); + return ENOENT; + } + if (access(certkey, R_OK) == -1) { + fprintf(stderr, "Unable to access certkey file ('%s'): ", certkey); + perror(""); + return ENOENT; + } - if(!ssys) return EINVAL; /* simply copying */ + int r = ENOMEM; if(!(ssys->rootca = strdup(rootca))) return ENOMEM; if(!(ssys->certkey = strdup(certkey))) goto __fail; if(!(ssys->certpem = strdup(certpem))) goto __fail;