From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id EA10F1FF16B for ; Tue, 15 Jul 2025 15:56:12 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id B62683E524; Tue, 15 Jul 2025 15:57:04 +0200 (CEST) From: Christoph Heiss To: pve-devel@lists.proxmox.com Date: Tue, 15 Jul 2025 15:55:40 +0200 Message-ID: <20250715135620.1023136-3-c.heiss@proxmox.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250715135620.1023136-1-c.heiss@proxmox.com> References: <20250715135620.1023136-1-c.heiss@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.028 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_MSPIKE_H2 0.001 Average reputation (+2) RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [answer.rs, proxmox.com, parse-answer.rs] Subject: [pve-devel] [PATCH installer 2/3] auto: answer: deserialize empty domain name as `None` X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox VE development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" This handles the case where users set `global.fqdn.domain = ""`, which would result incorrect parsing and finally resulting in the FQDN of the target machine being set to `.example.invalid`. Reported on the community forum [0]. [0] https://forum.proxmox.com/threads/auto-install-fetching-fqdn-through-dhcp-does-not-set-search-domain-correctly.168369/ Fixes: a37e044 ("fix #5811: auto: add option to retrieve FQDN from DHCP configuration") Signed-off-by: Christoph Heiss --- proxmox-auto-installer/src/answer.rs | 13 +++++++++++++ proxmox-auto-installer/tests/parse-answer.rs | 1 + ...n_from_dhcp_empty_dhcp_domain_setting.json | 19 +++++++++++++++++++ ...n_from_dhcp_empty_dhcp_domain_setting.toml | 17 +++++++++++++++++ 4 files changed, 50 insertions(+) create mode 100644 proxmox-auto-installer/tests/resources/parse_answer/fqdn_from_dhcp_empty_dhcp_domain_setting.json create mode 100644 proxmox-auto-installer/tests/resources/parse_answer/fqdn_from_dhcp_empty_dhcp_domain_setting.toml diff --git a/proxmox-auto-installer/src/answer.rs b/proxmox-auto-installer/src/answer.rs index b461976..88f4c87 100644 --- a/proxmox-auto-installer/src/answer.rs +++ b/proxmox-auto-installer/src/answer.rs @@ -90,6 +90,7 @@ pub struct FqdnExtendedConfig { #[serde(default)] pub source: FqdnSourceMode, /// Domain to use if none is received via DHCP. + #[serde(default, deserialize_with = "deserialize_non_empty_string_maybe")] pub domain: Option, } @@ -444,3 +445,15 @@ pub enum KeyboardLayout { } serde_plain::derive_display_from_serialize!(KeyboardLayout); + +fn deserialize_non_empty_string_maybe<'de, D>(deserializer: D) -> Result, D::Error> +where + D: serde::Deserializer<'de>, +{ + let val: Option = Deserialize::deserialize(deserializer)?; + + match val { + Some(s) if !s.is_empty() => Ok(Some(s)), + _ => Ok(None), + } +} diff --git a/proxmox-auto-installer/tests/parse-answer.rs b/proxmox-auto-installer/tests/parse-answer.rs index 88f30aa..a354f21 100644 --- a/proxmox-auto-installer/tests/parse-answer.rs +++ b/proxmox-auto-installer/tests/parse-answer.rs @@ -124,6 +124,7 @@ mod tests { disk_match_any, first_boot, fqdn_from_dhcp, + fqdn_from_dhcp_empty_dhcp_domain_setting, fqdn_from_dhcp_no_dhcp_domain_with_default_domain, full_fqdn_from_dhcp_with_default_domain, hashed_root_password, diff --git a/proxmox-auto-installer/tests/resources/parse_answer/fqdn_from_dhcp_empty_dhcp_domain_setting.json b/proxmox-auto-installer/tests/resources/parse_answer/fqdn_from_dhcp_empty_dhcp_domain_setting.json new file mode 100644 index 0000000..5ec6656 --- /dev/null +++ b/proxmox-auto-installer/tests/resources/parse_answer/fqdn_from_dhcp_empty_dhcp_domain_setting.json @@ -0,0 +1,19 @@ +{ + "autoreboot": 1, + "cidr": "192.168.1.114/24", + "country": "at", + "dns": "192.168.1.254", + "domain": "test.local", + "filesys": "ext4", + "gateway": "192.168.1.1", + "hdsize": 223.57088470458984, + "existing_storage_auto_rename": 1, + "hostname": "pveauto", + "keymap": "de", + "mailto": "mail@no.invalid", + "mngmt_nic": "eno1", + "root_password": { "plain": "12345678" }, + "target_hd": "/dev/sda", + "timezone": "Europe/Vienna", + "first_boot": { "enabled": 0 } +} diff --git a/proxmox-auto-installer/tests/resources/parse_answer/fqdn_from_dhcp_empty_dhcp_domain_setting.toml b/proxmox-auto-installer/tests/resources/parse_answer/fqdn_from_dhcp_empty_dhcp_domain_setting.toml new file mode 100644 index 0000000..a19e342 --- /dev/null +++ b/proxmox-auto-installer/tests/resources/parse_answer/fqdn_from_dhcp_empty_dhcp_domain_setting.toml @@ -0,0 +1,17 @@ +[global] +keyboard = "de" +country = "at" +mailto = "mail@no.invalid" +timezone = "Europe/Vienna" +root-password = "12345678" + +[global.fqdn] +source = "from-dhcp" +domain = "" + +[network] +source = "from-dhcp" + +[disk-setup] +filesystem = "ext4" +disk-list = ["sda"] -- 2.49.0 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel