diff --git a/config/config.toml b/config/config.toml index 8e69961..bd198ea 100644 --- a/config/config.toml +++ b/config/config.toml @@ -25,6 +25,10 @@ txt_records = [ [ "_psl", "https://github.com/publicsuffix/list/pull/XYZ" ], [ "@", "something useful" ], ] +cname_records = [ + [ "subdomain.mydomain.org", "mydomain.org" ], + [ "subdomain2.mydomain.org", "mydomain.org" ], +] soa_record = "ns1.mydomain.org. dns-admin.mydomain.org. 2018082801 900 900 1209600 60" www_addresses = [ "10.11.12.13", diff --git a/src/config.rs b/src/config.rs index 8968b4b..e08d814 100644 --- a/src/config.rs +++ b/src/config.rs @@ -41,6 +41,7 @@ pub struct PdnsOptions { pub mx_records: Vec, pub ns_records: Vec>, pub txt_records: Vec>, + pub cname_records: Vec>, pub soa_record: String, pub www_addresses: Vec, pub geoip: GeoIp, diff --git a/src/pdns.rs b/src/pdns.rs index e68a43a..9f0d6c7 100644 --- a/src/pdns.rs +++ b/src/pdns.rs @@ -277,6 +277,37 @@ fn build_txt_response( records } +// Returns a CNAME record for a given qname. +fn build_config_cname_response( + qname: &str, + config: &Config, +) -> Vec { + let sanitized_qname = remove_trailing_dot(qname); + let mut records = vec![]; + for cname in &config.options.pdns.cname_records { + if cname[0] == sanitized_qname { + records.push(PdnsLookupResponse { + qtype: "CNAME".to_owned(), + qname: qname.to_owned(), + content: cname[1].to_owned(), + ttl: config.options.pdns.dns_ttl, + domain_id: None, + scope_mask: None, + auth: None, + }); + } + } + + records +} + +fn remove_trailing_dot(s: &str) -> &str { + match s.chars().last() { + Some('.') => &s[0..s.len() - 1], + _ => s + } +} + // Returns a TXT record with the DNS challenge content. fn build_dns_challenge_response( qname: &str, @@ -476,6 +507,13 @@ fn handle_lookup(req: PdnsRequest, config: &Config) -> Result