From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 731DF9A200 for ; Fri, 17 Nov 2023 11:55:59 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 4E767301CA for ; Fri, 17 Nov 2023 11:55:29 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Fri, 17 Nov 2023 11:55:28 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 7DAF943DAA for ; Fri, 17 Nov 2023 11:55:28 +0100 (CET) From: Christoph Heiss To: pve-devel@lists.proxmox.com Date: Fri, 17 Nov 2023 11:55:15 +0100 Message-ID: <20231117105524.274413-1-c.heiss@proxmox.com> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -2.507 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 KAM_SOMETLD_ARE_BAD_TLD 5 .bar, .beauty, .buzz, .cam, .casa, .cfd, .club, .date, .guru, .link, .live, .monster, .online, .press, .pw, .quest, .rest, .sbs, .shop, .stream, .top, .trade, .wiki, .work, .xyz TLD abuse SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record T_SCC_BODY_TEXT_LINE -0.01 - Subject: [pve-devel] [PATCH installer] run env: strip out domain name from hostname 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: , X-List-Received-Date: Fri, 17 Nov 2023 10:55:59 -0000 The FQDN (retrieved via the DHCP `host-name` option) might contain the domain name too, as allowed by RFC 2132. E.g. if the DHCP server sends `host-name` => "foo.bar" `domain-name` => "bar" that would show up in the network setup screen in both UIs as "foo.bar.bar" as hostname/FQDN. Fixes: a805423 ("run env: do not store emtpy hostname") Signed-off-by: Christoph Heiss --- Tested this with various possible settings for the `host-name` DHCP option, also including e.g. if `host-name` is set to "" in the lease (which should never happen but you never know what shoddy DHCP implementations are out there). Proxmox/Install/RunEnv.pm | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Proxmox/Install/RunEnv.pm b/Proxmox/Install/RunEnv.pm index c393f67..214a001 100644 --- a/Proxmox/Install/RunEnv.pm +++ b/Proxmox/Install/RunEnv.pm @@ -258,18 +258,24 @@ sub query_installation_environment : prototype() { my $output = {}; my $routes = query_routes(); + my $dns = query_dns(); log_info("query block devices"); $output->{disks} = Proxmox::Sys::Block::get_cached_disks(); $output->{network} = { interfaces => query_netdevs(), routes => $routes, - dns => query_dns(), + dns => $dns, }; # avoid serializing out null or an empty string, that can trip up the UIs if (my $fqdn = Proxmox::Sys::Net::get_dhcp_fqdn()) { - $output->{network}->{hostname} = $fqdn; + # strip out the domain name if contained in the FQDN + if (defined($dns->{domain}) && $fqdn =~ m/^(.*)\.$dns->{domain}$/) { + $output->{network}->{hostname} = $1; + } else { + $output->{network}->{hostname} = $fqdn; + } } # FIXME: move whatever makes sense over to Proxmox::Sys::Net:: and keep that as single source, -- 2.42.0