diff --git a/README.md b/README.md index f3fe4a9..6822a44 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,19 @@ DKIM filter for [OpenSMTPD](https://www.opensmtpd.org/). This is a work in progress, it is not supposed to work yet. +## Building and packaging + +``` +cargo build --release +``` + +Packagers may want to set the `VARLIBDIR` to a custom value (default is `/var/lib`): + +``` +VARLIBDIR="/usr/local/var/lib" cargo build --release +``` + + ## Frequently Asked Questions ### Does this filter signs outgoing emails using DKIM or check the DKIM signature of incoming emails? diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..78a4e6e --- /dev/null +++ b/build.rs @@ -0,0 +1,9 @@ +use std::env; + +const DEFAULT_VARLIBDIR: &str = "/var/lib/"; + +fn main() { + if let Err(_) = env::var("VARLIBDIR") { + println!("cargo:rustc-env={}={}", "VARLIBDIR", DEFAULT_VARLIBDIR); + } +} diff --git a/src/config.rs b/src/config.rs index dd659ea..c1df822 100644 --- a/src/config.rs +++ b/src/config.rs @@ -109,6 +109,7 @@ fn process_key_data_base(opt: Option) -> Option { Some(p) => Some(p), None => { let mut path = PathBuf::from(crate::DEFAULT_LIB_DIR); + path.push(env!("CARGO_PKG_NAME")); path.push(crate::DEFAULT_CNF_KEY_DB); Some(path) } diff --git a/src/main.rs b/src/main.rs index e5c5f04..0b2380a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -24,7 +24,7 @@ const DEFAULT_CNF_HEADERS: &str = "from:reply-to:subject:date:to:cc"; const DEFAULT_CNF_HEADERS_OPT: &str = "resent-date:resent-from:resent-to:resent-cc:in-reply-to:references:list-id:list-help:list-unsubscribe:list-subscribe:list-post:list-owner:list-archive"; const DEFAULT_CNF_KEY_DB: &str = "key-db.sqlite3"; const DEFAULT_CNF_REVOCATION: u64 = 1728000; -const DEFAULT_LIB_DIR: &str = "/var/lib/opensmtpd-filter-dkimout"; +const DEFAULT_LIB_DIR: &str = env!("VARLIBDIR"); const DEFAULT_MSG_SIZE: usize = 1024 * 1024; const LOG_LEVEL_ENV_VAR: &str = "OPENSMTPD_FILTER_DKIMOUT_LOG_LEVEL";