diff options
author | Galen Guyer <galen@galenguyer.com> | 2022-08-31 17:10:59 -0400 |
---|---|---|
committer | Galen Guyer <galen@galenguyer.com> | 2022-08-31 17:10:59 -0400 |
commit | 31370d1a1b287c3202fc69b5f6db4c9e174123c6 (patch) | |
tree | e9a70e258e6bd1b47f713a772f56c216d01553e6 | |
parent | ee62cd357fdb0cfc9116aec7e28162ad684a8599 (diff) |
Validate more record types
-rw-r--r-- | src/routes/v1/records.rs | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/routes/v1/records.rs b/src/routes/v1/records.rs index 3c424c9..f8dcc9a 100644 --- a/src/routes/v1/records.rs +++ b/src/routes/v1/records.rs @@ -10,7 +10,7 @@ use sqlx::{Pool, Postgres}; use std::net::{Ipv4Addr, Ipv6Addr}; use std::str::FromStr; use std::sync::Arc; -use trust_dns_proto::rr::RecordType; +use trust_dns_proto::rr::{Name, RecordType}; use uuid::Uuid; pub async fn get_records( @@ -205,6 +205,15 @@ fn validate_record(rtype: &str, content: &str) -> Result<(), String> { .parse::<Ipv6Addr>() .map(|_| ()) .map_err(|_| String::from("Invalid IPv6 address")), + RecordType::CNAME => content + .parse::<Name>() + .map(|_| ()) + .map_err(|_| String::from("Invalid CNAME")), + RecordType::MX => content + .parse::<Name>() + .map(|_| ()) + .map_err(|_| String::from("Invalid MX record")), + RecordType::TXT => Ok(()), _ => Err(String::from("Unknown record type")), }, _ => Err(String::from("Unknown record type")), |