diff options
author | Jan Vcelak <jan.vcelak@nic.cz> | 2016-04-03 16:25:24 +0200 |
---|---|---|
committer | Ondřej Surý <ondrej@sury.org> | 2016-08-05 11:47:14 +0200 |
commit | 449ff02c001ac37edc111a250347d670f05d5fef (patch) | |
tree | efde4ed82dd738c1eead68412a203608d941f7f4 /daemon/network.c | |
parent | daemon: ported DNS/TLS preparation code to 1.1 (diff) | |
download | knot-resolver-449ff02c001ac37edc111a250347d670f05d5fef.tar.xz knot-resolver-449ff02c001ac37edc111a250347d670f05d5fef.zip |
daemon/network: global TLS certificate and key configuration
Diffstat (limited to 'daemon/network.c')
-rw-r--r-- | daemon/network.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/daemon/network.c b/daemon/network.c index e0e46e35..325e3644 100644 --- a/daemon/network.c +++ b/daemon/network.c @@ -101,6 +101,10 @@ void network_deinit(struct network *net) map_walk(&net->endpoints, close_key, 0); map_walk(&net->endpoints, free_key, 0); map_clear(&net->endpoints); + free(net->tls_cert); + net->tls_cert = NULL; + free(net->tls_key); + net->tls_key = NULL; } } @@ -329,3 +333,33 @@ int network_close(struct network *net, const char *addr, uint16_t port) return kr_ok(); } + +static int str_replace(char **where_ptr, const char *with) +{ + char *copy = with ? strdup(with) : NULL; + if (with && !copy) { + return kr_error(ENOMEM); + } + + free(*where_ptr); + *where_ptr = copy; + return kr_ok(); +} + +int network_set_tls_cert(struct network *net, const char *value) +{ + if (!net) { + return kr_error(EINVAL); + } + + return str_replace(&net->tls_cert, value); +} + +int network_set_tls_key(struct network *net, const char *value) +{ + if (!net) { + return kr_error(EINVAL); + } + + return str_replace(&net->tls_key, value); +} |