introduce buildcfg module and PROXMOX_CONFIGDIR
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>
This commit is contained in:
parent
0d176f3681
commit
9f4962d396
1
Makefile
1
Makefile
|
@ -33,6 +33,7 @@ export PROXMOX_PKG_RELEASE=${PKGREL}
|
||||||
export PROXMOX_PKG_REPOID=${GITVERSION}
|
export PROXMOX_PKG_REPOID=${GITVERSION}
|
||||||
|
|
||||||
export PROXMOX_JSDIR := $(JSDIR)
|
export PROXMOX_JSDIR := $(JSDIR)
|
||||||
|
export PROXMOX_CONFIGDIR := $(SYSCONFDIR)/proxmox-backup
|
||||||
|
|
||||||
DEB=${PACKAGE}_${PKGVER}-${PKGREL}_${ARCH}.deb
|
DEB=${PACKAGE}_${PKGVER}-${PKGREL}_${ARCH}.deb
|
||||||
DSC=${PACKAGE}_${PKGVER}-${PKGREL}.dsc
|
DSC=${PACKAGE}_${PKGVER}-${PKGREL}.dsc
|
||||||
|
|
|
@ -9,6 +9,7 @@ LIBDIR := $(PREFIX)/lib
|
||||||
LIBEXECDIR := $(LIBDIR)
|
LIBEXECDIR := $(LIBDIR)
|
||||||
DATAROOTDIR := $(PREFIX)/share
|
DATAROOTDIR := $(PREFIX)/share
|
||||||
JSDIR := $(DATAROOTDIR)/javascript/proxmox-backup
|
JSDIR := $(DATAROOTDIR)/javascript/proxmox-backup
|
||||||
|
SYSCONFDIR := /etc
|
||||||
|
|
||||||
# For local overrides
|
# For local overrides
|
||||||
-include local.mak
|
-include local.mak
|
||||||
|
|
|
@ -29,7 +29,7 @@ pub fn assemble_csrf_prevention_token(
|
||||||
|
|
||||||
pub fn generate_csrf_key() -> Result<(), Error> {
|
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(()); }
|
if path.exists() { return Ok(()); }
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ pub fn generate_csrf_key() -> Result<(), Error> {
|
||||||
|
|
||||||
pub fn generate_auth_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();
|
let mut public_path = priv_path.clone();
|
||||||
public_path.set_extension("pub");
|
public_path.set_extension("pub");
|
||||||
|
@ -77,7 +77,7 @@ pub fn csrf_secret() -> &'static [u8] {
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
static ref SECRET: Vec<u8> =
|
static ref SECRET: Vec<u8> =
|
||||||
tools::file_get_contents("/etc/proxmox-backup/csrf.key").unwrap();
|
tools::file_get_contents(configdir!("/csrf.key")).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
&SECRET
|
&SECRET
|
||||||
|
@ -85,7 +85,7 @@ pub fn csrf_secret() -> &'static [u8] {
|
||||||
|
|
||||||
fn load_private_auth_key() -> Result<PKey<Private>, Error> {
|
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 rsa = Rsa::private_key_from_pem(&pem)?;
|
||||||
let key = PKey::from_rsa(rsa)?;
|
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> {
|
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 rsa = Rsa::public_key_from_pem(&pem)?;
|
||||||
let key = PKey::from_rsa(rsa)?;
|
let key = PKey::from_rsa(rsa)?;
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
pub const CONFIGDIR: &'static str = env!("PROXMOX_CONFIGDIR");
|
||||||
|
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! configdir {
|
||||||
|
($subdir:expr) => (concat!(env!("PROXMOX_CONFIGDIR"), $subdir))
|
||||||
|
}
|
|
@ -1,3 +1,6 @@
|
||||||
|
#[macro_use]
|
||||||
|
pub mod buildcfg;
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
pub mod tools;
|
pub mod tools;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue