From: Sebastian Harl Date: Fri, 30 Jan 2015 10:26:49 +0000 (+0100) Subject: SSL utils: Add sdb_ssl_free_options(). X-Git-Tag: sysdb-0.7.0~36 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=2db6eca73081252f6af31f17c84e892cc4d33e36;p=sysdb.git SSL utils: Add sdb_ssl_free_options(). --- diff --git a/src/client/sock.c b/src/client/sock.c index b67910e..65b6b0e 100644 --- a/src/client/sock.c +++ b/src/client/sock.c @@ -188,20 +188,6 @@ connect_tcp(sdb_client_t *client, const char *address) return client->fd; } /* connect_tcp */ -static void -free_ssl_options(sdb_ssl_options_t *opts) -{ - if (opts->ca_file) - free(opts->ca_file); - if (opts->key_file) - free(opts->key_file); - if (opts->cert_file) - free(opts->cert_file); - if (opts->crl_file) - free(opts->crl_file); - opts->ca_file = opts->key_file = opts->cert_file = opts->crl_file = NULL; -} /* free_ssl_options */ - /* * public API */ @@ -249,7 +235,7 @@ sdb_client_destroy(sdb_client_t *client) free(client->address); client->address = NULL; - free_ssl_options(&client->ssl_opts); + sdb_ssl_free_options(&client->ssl_opts); free(client); } /* sdb_client_destroy */ @@ -262,7 +248,7 @@ sdb_client_set_ssl_options(sdb_client_t *client, const sdb_ssl_options_t *opts) if ((! client) || (! opts)) return -1; - free_ssl_options(&client->ssl_opts); + sdb_ssl_free_options(&client->ssl_opts); if (opts->ca_file) { client->ssl_opts.ca_file = strdup(opts->ca_file); @@ -286,7 +272,7 @@ sdb_client_set_ssl_options(sdb_client_t *client, const sdb_ssl_options_t *opts) } if (ret) - free_ssl_options(&client->ssl_opts); + sdb_ssl_free_options(&client->ssl_opts); return ret; } /* sdb_client_set_ssl_options */ diff --git a/src/include/utils/ssl.h b/src/include/utils/ssl.h index 6489f8b..801c574 100644 --- a/src/include/utils/ssl.h +++ b/src/include/utils/ssl.h @@ -143,6 +143,14 @@ sdb_ssl_session_write(sdb_ssl_session_t *session, const void *buf, size_t n); ssize_t sdb_ssl_session_read(sdb_ssl_session_t *session, void *buf, size_t n); +/* + * sdb_ssl_free_options: + * Free all strings stored in the specified options. All fields will be set to + * NULL. + */ +void +sdb_ssl_free_options(sdb_ssl_options_t *opts); + #ifdef __cplusplus } /* extern "C" */ #endif diff --git a/src/utils/ssl.c b/src/utils/ssl.c index 477d16c..f75223c 100644 --- a/src/utils/ssl.c +++ b/src/utils/ssl.c @@ -164,19 +164,6 @@ copy_options(sdb_ssl_options_t *dst, sdb_ssl_options_t *src) return 0; } /* copy_options */ -static void -free_options(sdb_ssl_options_t *opts) -{ - if (opts->ca_file) - free(opts->ca_file); - if (opts->key_file) - free(opts->key_file); - if (opts->cert_file) - free(opts->cert_file); - if (opts->crl_file) - free(opts->crl_file); -} /* free_options */ - /* * public API */ @@ -243,7 +230,7 @@ sdb_ssl_client_destroy(sdb_ssl_client_t *client) if (client->ctx) SSL_CTX_free(client->ctx); - free_options(&client->opts); + sdb_ssl_free_options(&client->opts); free(client); } /* sdb_ssl_client_destroy */ @@ -364,7 +351,7 @@ sdb_ssl_server_destroy(sdb_ssl_server_t *server) if (server->ctx) SSL_CTX_free(server->ctx); - free_options(&server->opts); + sdb_ssl_free_options(&server->opts); free(server); } /* sdb_ssl_server_destroy */ @@ -512,5 +499,23 @@ sdb_ssl_session_read(sdb_ssl_session_t *session, void *buf, size_t n) return -1; } /* sdb_ssl_session_read */ +void +sdb_ssl_free_options(sdb_ssl_options_t *opts) +{ + if (! opts) + return; + + if (opts->ca_file) + free(opts->ca_file); + if (opts->key_file) + free(opts->key_file); + if (opts->cert_file) + free(opts->cert_file); + if (opts->crl_file) + free(opts->crl_file); + + opts->ca_file = opts->key_file = opts->cert_file = opts->crl_file = NULL; +} /* sdb_ssl_free_options */ + /* vim: set tw=78 sw=4 ts=4 noexpandtab : */