From ea718c0997cd2e61c2a7fb491d1e7479296e710f Mon Sep 17 00:00:00 2001
From: flu0r1ne <flu0r1ne@flu0r1ne.net>
Date: Thu, 31 Aug 2023 19:11:21 -0500
Subject: Ensure the config path of symmetric keyfiles are absolute

---
 src/wg2nd.cpp | 9 ++++++---
 1 file 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",
-- 
cgit v1.2.3