Skip to content

Commit

Permalink
Fixed hostname validation and write behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
mchf committed Feb 18, 2020
1 parent 8117879 commit dda85ee
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
13 changes: 4 additions & 9 deletions src/include/network/services/dns.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def initialize_network_services_dns(include_target)
@widget_descr_dns = {
"HOSTNAME" => {
"widget" => :textentry,
"label" => Label.HostName,
"label" => "Static H&ostname",
"opt" => [],
"help" => Ops.get_string(@help, "hostname_global", ""),
"valid_chars" => Hostname.ValidChars,
Expand Down Expand Up @@ -433,15 +433,10 @@ def HandleResolverData(key, _event)
# @param _event [Hash] the event being handled
# @return whether valid
def ValidateHostname(key, _event)
dhn = dhcp? && use_dhcp_hostname?
# If the names are set by dhcp, the user may enter backup values
# here - N#28427. That is, host and domain name are optional then.
# For static config, they are mandatory.
value = Convert.to_string(UI.QueryWidget(Id(key), :Value))

return Hostname.Check(value) if !dhn || value != ""
value = UI.QueryWidget(Id(key), :Value).to_s

true
# empty hostname is allowed - /etc/hostname gets cleared in such case
value.empty? || Hostname.Check(value)
end

# Validator for the search list
Expand Down
6 changes: 4 additions & 2 deletions src/lib/y2network/sysconfig/hostname_writer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,10 @@ def update_sysconfig_dhcp(hostname, old_hostname)
#
# @param hostname [Y2Network::Hostname] Hostname configuration
def update_hostname(hostname)
Yast::Execute.on_target!("/usr/bin/hostname", hostname.hostname.split(".")[0])
Yast::SCR.Write(Yast::Path.new(".target.string"), HOSTNAME_PATH, "#{hostname.hostname}\n")
# 1) when user asked for ereasing hostname from /etc/hostname, we keep runtime as it is
# 2) we will write whatever user wants even FQDN - no changes under the hood
Yast::Execute.on_target!("/usr/bin/hostname", hostname.static) if !hostname.static.empty?
Yast::SCR.Write(Yast::Path.new(".target.string"), HOSTNAME_PATH, hostname.static.empty? ? hostname.static : "#{hostname.static}\n")
end
end
end
Expand Down

0 comments on commit dda85ee

Please sign in to comment.