* [pve-devel] [PATCH installer] tui: fix FQDN validation
@ 2023-06-22 11:05 Christoph Heiss
0 siblings, 0 replies; only message in thread
From: Christoph Heiss @ 2023-06-22 11:05 UTC (permalink / raw)
To: pve-devel
Add checks to ensure that:
* It actually has a hostname, not just a domain name
* Properly check if the hostname is purely numeric, by verifying each
FQDN part
Signed-off-by: Christoph Heiss <c.heiss@proxmox.com>
---
proxmox-tui-installer/src/main.rs | 8 ++++++--
proxmox-tui-installer/src/utils.rs | 12 +++++++++++-
2 files changed, 17 insertions(+), 3 deletions(-)
diff --git a/proxmox-tui-installer/src/main.rs b/proxmox-tui-installer/src/main.rs
index d2a5fcf..b49f2be 100644
--- a/proxmox-tui-installer/src/main.rs
+++ b/proxmox-tui-installer/src/main.rs
@@ -587,10 +587,14 @@ fn network_dialog(siv: &mut Cursive) -> InstallerView {
Err("host and gateway IP address version must not differ".to_owned())
} else if address.addr().is_ipv4() != dns_server.is_ipv4() {
Err("host and DNS IP address version must not differ".to_owned())
- } else if fqdn.to_string().chars().all(|c| c.is_ascii_digit()) {
+ } else if fqdn
+ .parts()
+ .iter()
+ .any(|p| p.chars().all(|c| c.is_ascii_digit() || c == '.'))
+ {
// Not supported/allowed on Debian
Err("hostname cannot be purely numeric".to_owned())
- } else if fqdn.to_string().ends_with(".invalid") {
+ } else if !fqdn.is_valid() || fqdn.to_string().ends_with(".invalid") {
Err("hostname does not look valid".to_owned())
} else {
Ok(NetworkOptions {
diff --git a/proxmox-tui-installer/src/utils.rs b/proxmox-tui-installer/src/utils.rs
index 3245fac..08521f3 100644
--- a/proxmox-tui-installer/src/utils.rs
+++ b/proxmox-tui-installer/src/utils.rs
@@ -122,7 +122,7 @@ impl Fqdn {
.map(ToOwned::to_owned)
.collect::<Vec<String>>();
- if !parts.iter().all(&Self::validate_single) {
+ if parts.is_empty() || !parts.iter().all(&Self::validate_single) {
Err(())
} else {
Ok(Self { parts })
@@ -143,6 +143,16 @@ impl Fqdn {
parts.join(".")
}
+ pub fn parts(&self) -> &[String] {
+ &self.parts
+ }
+
+ pub fn is_valid(&self) -> bool {
+ // It's a valid FQDN if it has at least a hostname and a TLD name, the
+ // latter is ensured by the constructor.
+ self.has_host()
+ }
+
fn has_host(&self) -> bool {
self.parts.len() > 1
}
--
2.40.1
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-06-22 11:06 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-22 11:05 [pve-devel] [PATCH installer] tui: fix FQDN validation Christoph Heiss
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox