From 2a6c25416ccc94912206a72698aef52be52eca29 Mon Sep 17 00:00:00 2001 From: Christian Breunig Date: Thu, 30 May 2024 09:38:55 +0200 Subject: hostname: T6421: enforce explicit CLI priority for host-name and domain-name To prevent any possible races in the future the host-name and domain-name nodes should be set with explicit priorities! (cherry picked from commit 96d0e23a32a0e1b990ce022546ed7225956a0494) --- interface-definitions/system_domain-name.xml.in | 1 + interface-definitions/system_host-name.xml.in | 1 + 2 files changed, 2 insertions(+) diff --git a/interface-definitions/system_domain-name.xml.in b/interface-definitions/system_domain-name.xml.in index bfca9b8ce..695af29d9 100644 --- a/interface-definitions/system_domain-name.xml.in +++ b/interface-definitions/system_domain-name.xml.in @@ -5,6 +5,7 @@ System domain name + 6 diff --git a/interface-definitions/system_host-name.xml.in b/interface-definitions/system_host-name.xml.in index 423531a68..f74baab48 100644 --- a/interface-definitions/system_host-name.xml.in +++ b/interface-definitions/system_host-name.xml.in @@ -6,6 +6,7 @@ System host name (default: vyos) + 5 #include -- cgit v1.2.3 From 013ed1d6ff6360db771cb992d8331a5dceada154 Mon Sep 17 00:00:00 2001 From: Christian Breunig Date: Thu, 30 May 2024 09:44:55 +0200 Subject: vyos.ifconfig: T6421: verify /etc/hostname exists before reading Inspired-By: Brandon Zhi (cherry picked from commit cf07a55d183be1f4d28b8b50a0784513d91d6fe2) --- python/vyos/ifconfig/interface.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/python/vyos/ifconfig/interface.py b/python/vyos/ifconfig/interface.py index fbbc04532..fa79395ff 100644 --- a/python/vyos/ifconfig/interface.py +++ b/python/vyos/ifconfig/interface.py @@ -39,6 +39,7 @@ from vyos.utils.network import get_interface_config from vyos.utils.process import is_systemd_service_active from vyos.template import is_ipv4 from vyos.template import is_ipv6 +from vyos.utils.file import read_file from vyos.utils.network import is_intf_addr_assigned from vyos.utils.network import is_ipv6_link_local from vyos.utils.assertion import assert_boolean @@ -1286,12 +1287,13 @@ class Interface(Control): if enable and 'disable' not in self.config: if dict_search('dhcp_options.host_name', self.config) == None: # read configured system hostname. - # maybe change to vyos hostd client ??? + # maybe change to vyos-hostsd client ??? hostname = 'vyos' - with open('/etc/hostname', 'r') as f: - hostname = f.read().rstrip('\n') - tmp = {'dhcp_options' : { 'host_name' : hostname}} - self.config = dict_merge(tmp, self.config) + hostname_file = '/etc/hostname' + if os.path.isfile(hostname_file): + hostname = read_file(hostname_file) + tmp = {'dhcp_options' : { 'host_name' : hostname}} + self.config = dict_merge(tmp, self.config) render(systemd_override_file, 'dhcp-client/override.conf.j2', self.config) render(dhclient_config_file, 'dhcp-client/ipv4.j2', self.config) -- cgit v1.2.3