From: Christoph Heiss <c.heiss@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH installer] tui: fix FQDN validation
Date: Thu, 22 Jun 2023 13:05:39 +0200 [thread overview]
Message-ID: <20230622110539.905687-1-c.heiss@proxmox.com> (raw)
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
reply other threads:[~2023-06-22 11:06 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230622110539.905687-1-c.heiss@proxmox.com \
--to=c.heiss@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox