]> git.proxmox.com Git - proxmox-backup.git/commitdiff
introduce buildcfg module and PROXMOX_CONFIGDIR
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Mon, 4 Feb 2019 14:13:03 +0000 (15:13 +0100)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Mon, 4 Feb 2019 14:13:08 +0000 (15:13 +0100)
buildcfg.rs should contain convenience variables or macros
for using build-time configured variables

For now we replace hardcoded "/etc/proxmox-backup/<foo>"
with configdir!("<foo>").

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
Makefile
defines.mk
src/auth_helpers.rs
src/buildcfg.rs [new file with mode: 0644]
src/lib.rs

index c2d9a7bac3599b85acb24a0dac48577d026c8283..334757f5e7738b640aa9ebf60f8e6f7fda17a6d0 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -33,6 +33,7 @@ export PROXMOX_PKG_RELEASE=${PKGREL}
 export PROXMOX_PKG_REPOID=${GITVERSION}
 
 export PROXMOX_JSDIR := $(JSDIR)
+export PROXMOX_CONFIGDIR := $(SYSCONFDIR)/proxmox-backup
 
 DEB=${PACKAGE}_${PKGVER}-${PKGREL}_${ARCH}.deb
 DSC=${PACKAGE}_${PKGVER}-${PKGREL}.dsc
index 0dcdfd896c5c0d386c510c7c1f31571383af814c..3cc60cc1180e3fbeabc4b225fb2977415a28cd2e 100644 (file)
@@ -9,6 +9,7 @@ LIBDIR := $(PREFIX)/lib
 LIBEXECDIR := $(LIBDIR)
 DATAROOTDIR := $(PREFIX)/share
 JSDIR := $(DATAROOTDIR)/javascript/proxmox-backup
+SYSCONFDIR := /etc
 
 # For local overrides
 -include local.mak
index 7c06b98882b568a66ef9ed2c4ad6ac4d936418a4..f8805816a822b1704d1e9d9f78dffa1db44fe54e 100644 (file)
@@ -29,7 +29,7 @@ pub fn assemble_csrf_prevention_token(
 
 pub fn generate_csrf_key() -> Result<(), Error> {
 
-    let path = PathBuf::from("/etc/proxmox-backup/csrf.key");
+    let path = PathBuf::from(configdir!("/csrf.key"));
 
     if path.exists() { return Ok(()); }
 
@@ -49,7 +49,7 @@ pub fn generate_csrf_key() -> Result<(), Error> {
 
 pub fn generate_auth_key() -> Result<(), Error> {
 
-    let priv_path = PathBuf::from("/etc/proxmox-backup/authkey.key");
+    let priv_path = PathBuf::from(configdir!("/authkey.key"));
 
     let mut public_path = priv_path.clone();
     public_path.set_extension("pub");
@@ -77,7 +77,7 @@ pub fn csrf_secret() -> &'static [u8] {
 
     lazy_static! {
         static ref SECRET: Vec<u8> =
-            tools::file_get_contents("/etc/proxmox-backup/csrf.key").unwrap();
+            tools::file_get_contents(configdir!("/csrf.key")).unwrap();
     }
 
     &SECRET
@@ -85,7 +85,7 @@ pub fn csrf_secret() -> &'static [u8] {
 
 fn load_private_auth_key() -> Result<PKey<Private>, Error> {
 
-    let pem = tools::file_get_contents("/etc/proxmox-backup/authkey.key")?;
+    let pem = tools::file_get_contents(configdir!("/authkey.key"))?;
     let rsa = Rsa::private_key_from_pem(&pem)?;
     let key = PKey::from_rsa(rsa)?;
 
@@ -103,7 +103,7 @@ pub fn private_auth_key() -> &'static PKey<Private> {
 
 fn load_public_auth_key() -> Result<PKey<Public>, Error> {
 
-    let pem = tools::file_get_contents("/etc/proxmox-backup/authkey.pub")?;
+    let pem = tools::file_get_contents(configdir!("/authkey.pub"))?;
     let rsa = Rsa::public_key_from_pem(&pem)?;
     let key = PKey::from_rsa(rsa)?;
 
diff --git a/src/buildcfg.rs b/src/buildcfg.rs
new file mode 100644 (file)
index 0000000..f0d24b8
--- /dev/null
@@ -0,0 +1,6 @@
+pub const CONFIGDIR: &'static str = env!("PROXMOX_CONFIGDIR");
+
+#[macro_export]
+macro_rules! configdir {
+    ($subdir:expr) => (concat!(env!("PROXMOX_CONFIGDIR"), $subdir))
+}
index 2f31c96c3669ddd66c165dcae310a69be3c6752d..21048399b374c4565038ffda8762457a286abde7 100644 (file)
@@ -1,3 +1,6 @@
+#[macro_use]
+pub mod buildcfg;
+
 #[macro_use]
 pub mod tools;