From ebdb91fda46b08dc2a86c378bbe7fce791705cf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodolphe=20Br=C3=A9ard?= Date: Sun, 26 Mar 2023 22:46:49 +0200 Subject: [PATCH] Add key_data_base to the CLI --- src/config.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/config.rs b/src/config.rs index 7637919..769c149 100644 --- a/src/config.rs +++ b/src/config.rs @@ -12,6 +12,8 @@ use std::path::{Path, PathBuf}; pub struct Config { #[arg(short, long, default_value_t = Algorithm::default())] algorithm: Algorithm, + #[arg(short = 'b', long, value_name = "FILE")] + key_data_base: Option, #[arg(short, long, default_value_t = Canonicalization::default())] canonicalization: Canonicalization, #[arg(short, long)] @@ -39,6 +41,7 @@ pub struct Config { impl Config { pub fn init() -> Result { let mut cnf = Self::parse(); + cnf.key_data_base = process_key_data_base(cnf.key_data_base); cnf.domain = process_domains(&cnf.domain, &cnf.domain_file)?; cnf.header = process_headers(&cnf.header, crate::DEFAULT_HEADERS); cnf.header_optional = process_headers(&cnf.header_optional, crate::DEFAULT_HEADERS_OPT); @@ -49,6 +52,10 @@ impl Config { self.algorithm } + pub fn key_data_base(&self) -> PathBuf { + self.key_data_base.clone().unwrap() + } + pub fn canonicalization(&self) -> Canonicalization { self.canonicalization } @@ -97,6 +104,15 @@ impl Config { } } +fn process_key_data_base(opt: Option) -> Option { + match opt { + Some(p) => Some(p), + None => Some(PathBuf::from( + "/var/lib/opensmtpd-filter-dkimout/key-db.sqlite3", + )), + } +} + fn process_domains(lst: &[String], domain_file: &Option) -> Result, String> { let mut domain_set: HashSet = lst.iter().map(|e| e.to_string()).collect(); if let Some(path) = domain_file {