dhcp watchers: strip trailing and leading dots from hostname

This commit is contained in:
Stephan de Wit 2023-06-21 15:58:16 +02:00
parent 2b89ff975f
commit 60fcb48d23
2 changed files with 2 additions and 2 deletions

View File

@ -58,7 +58,7 @@ def run_watcher(target_filename, default_domain, watch_file, service_pid):
for lease in dhcpdleases.watch():
if 'ends' in lease and lease['ends'] > time.time() \
and 'client-hostname' in lease and 'address' in lease and lease['client-hostname']:
if all(hostname_pattern.match(part) for part in lease['client-hostname'].strip().split('.')):
if all(hostname_pattern.match(part) for part in lease['client-hostname'].strip('.').split('.')):
address = ipaddress.ip_address(lease['address'])
lease['domain'] = default_domain
cached_leases[lease['address']] = lease

View File

@ -145,7 +145,7 @@ def run_watcher(target_filename, default_domain, watch_file, config):
for lease in dhcpdleases.watch():
if 'ends' in lease and lease['ends'] > time.time() \
and 'client-hostname' in lease and 'address' in lease and lease['client-hostname']:
if all(hostname_pattern.match(part) for part in lease['client-hostname'].strip().split('.')):
if all(hostname_pattern.match(part) for part in lease['client-hostname'].strip('.').split('.')):
address = ipaddress.ip_address(lease['address'])
lease['domain'] = default_domain
for lease_config in lease_configs: