From e25f81718cb0caf9e801d15cc4d40cda0597c161 Mon Sep 17 00:00:00 2001 From: Lubomir Rintel <lkundrak@v3.sk> Date: Tue, 6 Sep 2016 12:18:21 +0200 Subject: [PATCH] config: allow ca-file, user-cert and user-key in configuration files Analogously to command line options. --- src/config.c | 7 +++++++ src/config.h | 5 ++++- src/main.c | 6 +++--- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/config.c b/src/config.c index 8466faa..f20af0a 100644 --- a/src/config.c +++ b/src/config.c @@ -204,6 +204,13 @@ int load_config(struct vpn_config *cfg, const char *filename) if (add_trusted_cert(cfg, val)) log_warn("Could not add certificate digest to " "whitelist.\n"); + + } else if (strcmp(key, "ca-file") == 0) { + cfg->ca_file = strdup(val); + } else if (strcmp(key, "user-cert") == 0) { + cfg->user_cert = strdup(val); + } else if (strcmp(key, "user-key") == 0) { + cfg->user_key = strdup(val); } else { log_warn("Bad key in config file: \"%s\".\n", key); goto err_free; diff --git a/src/config.h b/src/config.h index 4c35f63..2d6fa4f 100644 --- a/src/config.h +++ b/src/config.h @@ -95,7 +95,10 @@ struct vpn_config { struct x509_digest *tmp = (cfg)->cert_whitelist->next; \ free((cfg)->cert_whitelist); \ (cfg)->cert_whitelist = tmp; \ - } + } \ + free((cfg)->ca_file); \ + free((cfg)->user_cert); \ + free((cfg)->user_key); int add_trusted_cert(struct vpn_config *cfg, const char *digest); diff --git a/src/main.c b/src/main.c index 88ea109..f16e526 100644 --- a/src/main.c +++ b/src/main.c @@ -169,17 +169,17 @@ int main(int argc, char **argv) } if (strcmp(long_options[option_index].name, "ca-file") == 0) { - cfg.ca_file = optarg; + cfg.ca_file = strdup(optarg); break; } if (strcmp(long_options[option_index].name, "user-cert") == 0) { - cfg.user_cert = optarg; + cfg.user_cert = strdup(optarg); break; } if (strcmp(long_options[option_index].name, "user-key") == 0) { - cfg.user_key = optarg; + cfg.user_key = strdup(optarg); break; } if (strcmp(long_options[option_index].name, -- GitLab