From c586bdb1a5f3252d4fb7cbbeb6b18a9617db62f3 Mon Sep 17 00:00:00 2001 From: Franco Fichtner Date: Wed, 24 May 2023 09:29:10 +0200 Subject: [PATCH] system: allow "." DNS search domain override; closes #6529 While here refactor get_searchdomain() a little to avoid complexity in system_resolvconf_generate(). --- src/etc/inc/system.inc | 30 +++++++++++++++++++----------- src/www/system_general.php | 2 +- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/etc/inc/system.inc b/src/etc/inc/system.inc index 1c18eab33..5f743d2f2 100644 --- a/src/etc/inc/system.inc +++ b/src/etc/inc/system.inc @@ -184,8 +184,8 @@ function system_resolvconf_generate($verbose = false) $syscfg = config_read_array('system'); $resolvconf = ''; - $search = []; $routes = []; + $search = []; mwexecf( '/etc/rc.d/ip6addrctl %s', @@ -194,25 +194,20 @@ function system_resolvconf_generate($verbose = false) if (!empty($syscfg['domain'])) { $resolvconf = "domain {$syscfg['domain']}\n"; - $search[] = $syscfg['domain']; - } - - if (!empty($syscfg['dnssearchdomain'])) { - /* add custom search entries after default domain before potential provider entries */ - $search[] = $syscfg['dnssearchdomain']; } if (!isset($syscfg['dnslocalhost']) && !empty(service_by_filter(['dns_ports' => '53']))) { $resolvconf .= "nameserver 127.0.0.1\n"; } - $search = array_merge($search, get_searchdomains()); $routes = system_resolvconf_host_routes(); foreach (array_keys($routes) as $host) { $resolvconf .= "nameserver {$host}\n"; } + $search = get_searchdomains(); + if (count($search)) { $result = $search[0]; /* resolv.conf search keyword limit is 6 domains, 256 characters */ @@ -237,10 +232,9 @@ function system_resolvconf_generate($verbose = false) /* setup static routes for DNS servers as configured */ foreach ($routes as $host => $gateway) { - if (empty($gateway)) { - continue; + if (!empty($gateway)) { + system_host_route($host, $gateway); } - system_host_route($host, $gateway); } service_log("done.\n", $verbose); @@ -306,6 +300,20 @@ function get_searchdomains() $master_list = []; $search_list = []; + if (!empty($syscfg['domain'])) { + $master_list[] = $syscfg['domain']; + } + + if (!empty($syscfg['dnssearchdomain'])) { + if ($syscfg['dnssearchdomain'] == '.') { + /* pass root only */ + return [$syscfg['dnssearchdomain']]; + } + + /* add custom search entries after default domain before potential provider entries */ + $master_list[] = $syscfg['dnssearchdomain']; + } + if (isset($syscfg['dnsallowoverride'])) { /* return domains as required by configuration */ $list = shell_safe('/usr/local/sbin/ifctl -sl'); diff --git a/src/www/system_general.php b/src/www/system_general.php index cda98d79e..f123d9d22 100644 --- a/src/www/system_general.php +++ b/src/www/system_general.php @@ -454,7 +454,7 @@ $( document ).ready(function() {