diff --git a/Makefile b/Makefile index c2d9a7ba..334757f5 100644 --- 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 diff --git a/defines.mk b/defines.mk index 0dcdfd89..3cc60cc1 100644 --- a/defines.mk +++ b/defines.mk @@ -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 diff --git a/src/auth_helpers.rs b/src/auth_helpers.rs index 7c06b988..f8805816 100644 --- a/src/auth_helpers.rs +++ b/src/auth_helpers.rs @@ -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 = - 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, 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 { fn load_public_auth_key() -> Result, 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 index 00000000..f0d24b8e --- /dev/null +++ b/src/buildcfg.rs @@ -0,0 +1,6 @@ +pub const CONFIGDIR: &'static str = env!("PROXMOX_CONFIGDIR"); + +#[macro_export] +macro_rules! configdir { + ($subdir:expr) => (concat!(env!("PROXMOX_CONFIGDIR"), $subdir)) +} diff --git a/src/lib.rs b/src/lib.rs index 2f31c96c..21048399 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,6 @@ +#[macro_use] +pub mod buildcfg; + #[macro_use] pub mod tools;