diff --git a/sxmp/hub.c b/sxmp/hub.c index f8e2cb1..da92491 100644 --- a/sxmp/hub.c +++ b/sxmp/hub.c @@ -656,29 +656,44 @@ int sxhub_setsslserts(sxhub_t *ssys, const char *rootca, /* check on existence of certificate files */ if (access(rootca, R_OK) == -1) { - fprintf(stderr, "Unable to access rootca file ('%s'): ", rootca); - perror(""); + ssys->log(SXERROR_LOG, "Unable to read rootca file '%s': %s\n", + rootca, sys_errlist[errno]); return ENOENT; } if (access(certpem, R_OK) == -1) { - fprintf(stderr, "Unable to access certpem file ('%s'): ", certpem); - perror(""); + ssys->log(SXERROR_LOG, "Unable to read certpem file '%s': %s\n", + certpem, sys_errlist[errno]); return ENOENT; } if (access(certkey, R_OK) == -1) { - fprintf(stderr, "Unable to access certkey file ('%s'): ", certkey); - perror(""); + ssys->log(SXERROR_LOG, "Unable to read certkey file '%s': %s\n", + certkey, sys_errlist[errno]); return ENOENT; } - /* 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; + /* obtain full paths of certificate files */ + int r; + if (NULL == (ssys->rootca = realpath(rootca, NULL))) { + ssys->log(SXERROR_LOG, "Unable to obtain the full path of '%s': %s\n", + rootca, sys_errlist[errno]); + if (errno == ENOMEM) r = errno; + goto __fail; + } + if (NULL == (ssys->certpem = realpath(certpem, NULL))) { + ssys->log(SXERROR_LOG, "Unable to obtain the full path of '%s': %s\n", + certpem, sys_errlist[errno]); + if (errno == ENOMEM) r = errno; + goto __fail; + } + if (NULL == (ssys->certkey = realpath(certkey, NULL))) { + ssys->log(SXERROR_LOG, "Unable to obtain the full path of '%s': %s\n", + certkey, sys_errlist[errno]); + if (errno == ENOMEM) r = errno; + goto __fail; + } - r = 0; return 0; + __fail: if(ssys->rootca) free(ssys->rootca); if(ssys->certkey) free(ssys->certkey);