From: Sebastian Harl Date: Fri, 30 Jan 2015 11:35:20 +0000 (+0100) Subject: SSL utils: Pass a constant options object to all constructors. X-Git-Tag: sysdb-0.7.0~32 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=4be4932836dbd85adc9f19b4490daed5712bf2fb;p=sysdb.git SSL utils: Pass a constant options object to all constructors. --- diff --git a/src/include/utils/ssl.h b/src/include/utils/ssl.h index 801c574..5379bc9 100644 --- a/src/include/utils/ssl.h +++ b/src/include/utils/ssl.h @@ -73,7 +73,7 @@ typedef struct sdb_ssl_session sdb_ssl_session_t; * options are specified, default values will be used instead. */ sdb_ssl_client_t * -sdb_ssl_client_create(sdb_ssl_options_t *opts); +sdb_ssl_client_create(const sdb_ssl_options_t *opts); /* * sdb_ssl_client_destroy: @@ -95,7 +95,7 @@ sdb_ssl_client_connect(sdb_ssl_client_t *client, int fd); * options are specified, default values will be used instead. */ sdb_ssl_server_t * -sdb_ssl_server_create(sdb_ssl_options_t *opts); +sdb_ssl_server_create(const sdb_ssl_options_t *opts); /* * sdb_ssl_server_destroy: diff --git a/src/utils/ssl.c b/src/utils/ssl.c index d9ad060..723df21 100644 --- a/src/utils/ssl.c +++ b/src/utils/ssl.c @@ -137,27 +137,30 @@ ssl_log_err(int prio, SSL *ssl, int status, const char *prefix, ...) } /* ssl_log_err */ static int -copy_options(sdb_ssl_options_t *dst, sdb_ssl_options_t *src) +copy_options(sdb_ssl_options_t *dst, const sdb_ssl_options_t *src) { + sdb_ssl_options_t tmp; sdb_ssl_options_t def = SDB_SSL_DEFAULT_OPTIONS; - if (! src) - src = &def; - - if (! src->ca_file) - src->ca_file = def.ca_file; - if (! src->key_file) - src->key_file = def.key_file; - if (! src->cert_file) - src->cert_file = def.cert_file; - - dst->ca_file = strdup(src->ca_file); - dst->key_file = strdup(src->key_file); - dst->cert_file = strdup(src->cert_file); + if (src) + tmp = *src; + else + tmp = def; + + if (! tmp.ca_file) + tmp.ca_file = def.ca_file; + if (! tmp.key_file) + tmp.key_file = def.key_file; + if (! tmp.cert_file) + tmp.cert_file = def.cert_file; + + dst->ca_file = strdup(tmp.ca_file); + dst->key_file = strdup(tmp.key_file); + dst->cert_file = strdup(tmp.cert_file); if ((! dst->ca_file) || (! dst->key_file) || (! dst->cert_file)) return -1; - if (src->crl_file) { - dst->crl_file = strdup(src->crl_file); + if (tmp.crl_file) { + dst->crl_file = strdup(tmp.crl_file); if (! dst->crl_file) return -1; } @@ -169,7 +172,7 @@ copy_options(sdb_ssl_options_t *dst, sdb_ssl_options_t *src) */ sdb_ssl_client_t * -sdb_ssl_client_create(sdb_ssl_options_t *opts) +sdb_ssl_client_create(const sdb_ssl_options_t *opts) { sdb_ssl_client_t *client; @@ -278,7 +281,7 @@ sdb_ssl_client_connect(sdb_ssl_client_t *client, int fd) } /* sdb_ssl_client_connect */ sdb_ssl_server_t * -sdb_ssl_server_create(sdb_ssl_options_t *opts) +sdb_ssl_server_create(const sdb_ssl_options_t *opts) { sdb_ssl_server_t *server;