sd-dhcp: permit unsetting the hostname again

Let's handle NULL hostnames (for unsetting it) before we validate the name.
This commit is contained in:
Lennart Poettering 2016-11-18 12:33:14 +01:00
parent c5066640a1
commit 17f6ed4d59

View file

@ -390,17 +390,21 @@ int sd_dhcp_client_set_hostname(
assert_return(client, -EINVAL);
if (!hostname) {
client->hostname = mfree(client->hostname);
return 0;
}
/* Refuse hostnames that neither qualify as DNS nor as Linux hosntames */
if (!hostname_is_valid(hostname, false) && !dns_name_is_valid(hostname))
return -EINVAL;
if (streq_ptr(client->hostname, hostname))
return 0;
if (hostname) {
new_hostname = strdup(hostname);
if (!new_hostname)
return -ENOMEM;
}
new_hostname = strdup(hostname);
if (!new_hostname)
return -ENOMEM;
free(client->hostname);
client->hostname = new_hostname;