aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorflu0r1ne <flu0r1ne@flu0r1ne.net>2023-08-31 19:11:21 -0500
committerflu0r1ne <flu0r1ne@flu0r1ne.net>2023-08-31 19:11:21 -0500
commitea718c0997cd2e61c2a7fb491d1e7479296e710f (patch)
tree5efa9b9756371c705ac7a5b542f696c7fa31b690
parent5ac99650c9c39e85ea7ce132de49ed013acc4f2b (diff)
downloadwg2nd-ea718c0997cd2e61c2a7fb491d1e7479296e710f.tar.xz
wg2nd-ea718c0997cd2e61c2a7fb491d1e7479296e710f.zip
Ensure the config path of symmetric keyfiles are absolute
-rw-r--r--src/wg2nd.cpp9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/wg2nd.cpp b/src/wg2nd.cpp
index 9397a0b..deb3212 100644
--- a/src/wg2nd.cpp
+++ b/src/wg2nd.cpp
@@ -372,7 +372,7 @@ namespace wg2nd {
}
static std::string _gen_netdev_cfg(Config const & cfg, uint32_t fwd_table, std::filesystem::path const & private_keyfile,
- std::vector<SystemdFilespec> & symmetric_keyfiles) {
+ std::filesystem::path const & output_path, std::vector<SystemdFilespec> & symmetric_keyfiles) {
std::stringstream netdev;
netdev << "# Autogenerated by wg2nd\n";
@@ -429,7 +429,7 @@ namespace wg2nd {
.contents = peer.preshared_key + "\n",
});
- netdev << "PresharedKeyFile = " << filename << "\n";
+ netdev << "PresharedKeyFile = " << (output_path / filename).c_str() << "\n";
}
for(Cidr const & cidr : peer.allowed_ips) {
@@ -571,12 +571,15 @@ namespace wg2nd {
std::vector<SystemdFilespec> symmetric_keyfiles;
std::filesystem::path keyfile_path;
+ std::filesystem::path output_path;
if(keyfile_or_output_path.has_filename()) {
keyfile_path = keyfile_or_output_path;
+ output_path = keyfile_or_output_path.parent_path();
} else {
std::string private_keyfile = private_keyfile_name(cfg.intf.private_key);
keyfile_path = keyfile_or_output_path / private_keyfile;
+ output_path = keyfile_or_output_path;
}
std::vector<std::string> warnings;
@@ -601,7 +604,7 @@ if(!cfg.intf.field_.empty()) { \
return SystemdConfig {
.netdev = {
.name = basename + ".netdev",
- .contents = _gen_netdev_cfg(cfg, fwd_table, keyfile_path, symmetric_keyfiles),
+ .contents = _gen_netdev_cfg(cfg, fwd_table, keyfile_path, output_path, symmetric_keyfiles),
},
.network = {
.name = basename + ".network",