1
0
mirror of https://github.com/systemd/systemd.git synced 2024-11-05 23:51:28 +03:00

libsystemd-network: use domain validation instead of hostname validation for dhcp domain option

previously hostname_is_valid was used to validate domain names, which
would silently drop perfectly valid dns names that were longer than a
single dns label.
This commit is contained in:
Nick Owens 2015-06-02 16:30:42 -07:00
parent df6cfeeff7
commit 37de250906
2 changed files with 22 additions and 6 deletions

View File

@ -32,6 +32,7 @@
#include "dhcp-lease-internal.h" #include "dhcp-lease-internal.h"
#include "sd-dhcp-lease.h" #include "sd-dhcp-lease.h"
#include "network-internal.h" #include "network-internal.h"
#include "dns-domain.h"
int sd_dhcp_lease_get_address(sd_dhcp_lease *lease, struct in_addr *addr) { int sd_dhcp_lease_get_address(sd_dhcp_lease *lease, struct in_addr *addr) {
assert_return(lease, -EINVAL); assert_return(lease, -EINVAL);
@ -504,9 +505,18 @@ int dhcp_lease_parse_options(uint8_t code, uint8_t len, const uint8_t *option,
if (e) if (e)
*e = 0; *e = 0;
if (!hostname_is_valid(domainname) || is_localhost(domainname)) if (is_localhost(domainname))
break; break;
r = dns_name_is_valid(domainname);
if (r <= 0) {
if (r < 0)
log_error_errno(r, "Failed to validate domain name: %s: %m", domainname);
if (r == 0)
log_warning("Domain name is not valid, ignoring: %s", domainname);
break;
}
free(lease->domainname); free(lease->domainname);
lease->domainname = domainname; lease->domainname = domainname;
domainname = NULL; domainname = NULL;

View File

@ -30,6 +30,7 @@
#include "networkd-netdev.h" #include "networkd-netdev.h"
#include "networkd-link.h" #include "networkd-link.h"
#include "network-internal.h" #include "network-internal.h"
#include "dns-domain.h"
static int network_load_one(Manager *manager, const char *filename) { static int network_load_one(Manager *manager, const char *filename) {
_cleanup_network_free_ Network *network = NULL; _cleanup_network_free_ Network *network = NULL;
@ -466,11 +467,16 @@ int config_parse_domains(const char *unit,
STRV_FOREACH(domain, *domains) { STRV_FOREACH(domain, *domains) {
if (is_localhost(*domain)) if (is_localhost(*domain))
log_syntax(unit, LOG_ERR, filename, line, EINVAL, "'localhost' domain names may not be configured, ignoring assignment: %s", *domain); log_syntax(unit, LOG_ERR, filename, line, EINVAL, "'localhost' domain names may not be configured, ignoring assignment: %s", *domain);
else if (!hostname_is_valid(*domain)) { else {
if (!streq(*domain, "*")) r = dns_name_is_valid(*domain);
log_syntax(unit, LOG_ERR, filename, line, EINVAL, "domain name is not valid, ignoring assignment: %s", *domain); if (r <= 0 && !streq(*domain, "*")) {
} else if (r < 0)
continue; log_error_errno(r, "Failed to validate domain name: %s: %m", *domain);
if (r == 0)
log_warning("Domain name is not valid, ignoring assignment: %s", *domain);
} else
continue;
}
strv_remove(*domains, *domain); strv_remove(*domains, *domain);