From 76a567d1bf4469aff684a43e4a3391d6b32cc934 Mon Sep 17 00:00:00 2001 From: Neshura Date: Wed, 10 Apr 2024 23:22:11 +0200 Subject: [PATCH] Add duplicate domain check, closes #5 --- src/main.rs | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index a874d2c..eba4c8b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -146,6 +146,7 @@ impl Config { let msg = format!("Using {}", path); directories.push(system_path.to_path_buf()); info!(msg); + Self::check_for_duplicate_domains(&user_config.domain_configs); Ok((Config { user: user_config, system: data, @@ -211,7 +212,7 @@ impl Config { let new_root = root.join(paths[0]); println!("{}", &new_root.display()); let ret = unix::fs::chown(&new_root, Some(uid), Some(gid)); - + let mut new_paths = paths.clone(); new_paths.remove(0); match Self::fix_path_ownership(new_root, new_paths) { @@ -224,6 +225,32 @@ impl Config { } } } + + fn check_for_duplicate_domains(domain_configs: &[DomainLinkConfig]) { + let mut checked_domains: Vec = vec![]; + for (cfg_idx, config) in domain_configs.iter().enumerate() { + for (idx, domain) in config.domains.iter().enumerate() { + if !checked_domains.contains(domain) { + if config.domains[idx+1..].contains(domain) { + // Error + let msg = format!("Duplicate Domain use detected for '{domain}"); + warn!(msg); + checked_domains.push(domain.clone()); + } + else { + for d in domain_configs[cfg_idx+1..].iter() { + if d.domains.contains(domain) { + let msg = format!("Duplicate Domain use detected for '{domain}"); + warn!(msg); + checked_domains.push(domain.clone()); + break; + } + } + } + } + } + } + } } #[actix_web::main]