]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Make a isValidHostname() callable from Rust that calls into DNSName::is_hostname()
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Tue, 26 Mar 2024 08:29:22 +0000 (09:29 +0100)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Thu, 25 Apr 2024 09:31:40 +0000 (11:31 +0200)
pdns/recursordist/settings/cxxsupport.cc
pdns/recursordist/settings/rust-bridge-in.rs
pdns/recursordist/settings/rust/Cargo.lock
pdns/recursordist/settings/rust/Cargo.toml
pdns/recursordist/settings/rust/build.rs
pdns/recursordist/settings/rust/src/bridge.hh
pdns/recursordist/settings/rust/src/bridge.rs

index d34cbca4e5c01ca0ee19691012f2c5df4b9401fd..71f76b1fa415e78062a4ed27415dc1978d2bb5cf 100644 (file)
@@ -1376,3 +1376,14 @@ uint16_t pdns::rust::settings::rec::qTypeStringToCode(::rust::Str str)
   std::string tmp(str.data(), str.length());
   return QType::chartocode(tmp.c_str());
 }
+
+bool pdns::rust::settings::rec::isValidHostname(::rust::Str str)
+{
+  try {
+    auto name = DNSName(string(str));
+    return name.isHostname();
+  }
+  catch (...) {
+    return false;
+  }
+}
index bf155c2b0e9751cc1347c19a31da460cb84e9bb6..427da15c74a3f81bd268e90a70a4a6ca1a1c789a 100644 (file)
@@ -347,4 +347,5 @@ extern "Rust" {
 unsafe extern "C++" {
     include!("bridge.hh");
     fn qTypeStringToCode(name: &str) -> u16;
+    fn isValidHostname(name: &str) -> bool;
 }
index 48d4f5457123c534761b5e4e4754a087e38880d2..25fa9b107b276ba48c0ccb775c9d161ddc1652c5 100644 (file)
@@ -83,12 +83,6 @@ version = "0.14.3"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604"
 
-[[package]]
-name = "hostname-validator"
-version = "1.1.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f558a64ac9af88b5ba400d99b579451af0d39c6d360980045b91aac966d705e2"
-
 [[package]]
 name = "indexmap"
 version = "2.1.0"
@@ -202,7 +196,6 @@ dependencies = [
  "base64",
  "cxx",
  "cxx-build",
- "hostname-validator",
  "ipnet",
  "once_cell",
  "serde",
index 3dd157c50d1e22694c2c796e821df22420ce9ee3..6179bd863b6a058f7f7cbd17da79c343e677d3b1 100644 (file)
@@ -13,7 +13,6 @@ serde = { version = "1.0", features = ["derive"] }
 serde_yaml = "0.9"
 ipnet = "2.8"
 once_cell = "1.18.0"
-hostname-validator = "1.1.1" # This is temporary. PR 13819 has the infra to call C++ from, so we can arrange for DNSName::ishostname() to be called instead of importing another crate after that one is merged.
 base64 = "0.21"
 
 [build-dependencies]
index 256f9981bfb1207a70c38141a57449145bedc07e..ddddf7f2928e929713f536f268afa3c3eb143f51 100644 (file)
@@ -1,6 +1,6 @@
 fn main() {
     cxx_build::bridge("src/lib.rs")
-        // .file("src/source.cc") at the moment no C++ code callable from Rust
+        // .file("src/source.cc") Code callable from Rust is in ../cxxsupport.cc
         .flag_if_supported("-std=c++17")
         .flag("-Isrc")
         .compile("settings");
index 02f8beb733648c087a434f374d352bb0ec5c7ff5..6a6fd2b41d77ffdd6dbe29bb27575af459c398aa 100644 (file)
@@ -26,4 +26,5 @@
 namespace pdns::rust::settings::rec
 {
 uint16_t qTypeStringToCode(::rust::Str str);
+bool isValidHostname(::rust::Str str);
 }
index cbb9ef04ee6f20b8584d19771099c59072dccaaf..24998e2d1d37c20ea2d778a9504c2f924c647847 100644 (file)
@@ -89,10 +89,10 @@ fn is_port_number(str: &str) -> bool {
 pub fn validate_socket_address_or_name(field: &str, val: &String) -> Result<(), ValidationError> {
     let sa = validate_socket_address(field, val);
     if sa.is_err() {
-        if !hostname_validator::is_valid(val) {
+        if !isValidHostname(val) {
             let parts: Vec<&str> = val.split(':').collect();
             if parts.len() != 2
-                || !hostname_validator::is_valid(parts[0])
+                || !isValidHostname(parts[0])
                 || !is_port_number(parts[1])
             {
                 let msg = format!(