From 63b9f2e1aa1dc5604e46ffeb0cf5d0b83150b0f0 Mon Sep 17 00:00:00 2001 From: Franco Fichtner Date: Thu, 3 Apr 2025 11:16:39 +0200 Subject: [PATCH] system: allow multiple manual DNS search domains; closes #8522 The length and input isn't bound but when writing resolv.conf we will adhere to the requirement mentioned in the man page: The search list is currently limited to six domains with a total of 256 characters. We simply don't always know how many the system was being provided with from the ISP so it is what it is. --- src/etc/inc/system.inc | 16 ++++++++++------ src/www/system_general.php | 27 ++++++++++++++++++++------- 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/src/etc/inc/system.inc b/src/etc/inc/system.inc index 109dae929..9fbf9e4aa 100644 --- a/src/etc/inc/system.inc +++ b/src/etc/inc/system.inc @@ -326,13 +326,17 @@ function get_searchdomains() } if (!empty($syscfg['dnssearchdomain'])) { - if ($syscfg['dnssearchdomain'] == '.') { - /* pass root only */ - return [$syscfg['dnssearchdomain']]; - } + $dnssds = array_unique(explode(',', $syscfg['dnssearchdomain'])); - /* add custom search entries after default domain before potential provider entries */ - $master_list[] = $syscfg['dnssearchdomain']; + foreach ($dnssds as $dnssd) { + if ($dnssd == '.') { + /* pass root only but including other manually set domains as is */ + return $dnssds; + } + + /* add custom search entries after default domain before potential provider entries */ + $master_list[] = $dnssd; + } } if (!empty($syscfg['dnsallowoverride'])) { diff --git a/src/www/system_general.php b/src/www/system_general.php index 73372e2a0..d77c4d468 100644 --- a/src/www/system_general.php +++ b/src/www/system_general.php @@ -59,7 +59,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { explode(',', $config['system']['dnsallowoverride_exclude']) : []; $pconfig['dnslocalhost'] = isset($config['system']['dnslocalhost']); - $pconfig['dnssearchdomain'] = $config['system']['dnssearchdomain'] ?? null; + $pconfig['dnssearchdomain'] = !empty($config['system']['dnssearchdomain']) ? explode(',', $config['system']['dnssearchdomain']) : []; $pconfig['domain'] = $config['system']['domain']; $pconfig['hostname'] = $config['system']['hostname']; $pconfig['language'] = $config['system']['language']; @@ -123,8 +123,12 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { if (!empty($pconfig['domain']) && !is_domain($pconfig['domain'])) { $input_errors[] = gettext("The domain may only contain the characters a-z, 0-9, '-' and '.'."); } - if (!empty($pconfig['dnssearchdomain']) && !is_domain($pconfig['dnssearchdomain'], true)) { - $input_errors[] = gettext("A search domain may only contain the characters a-z, 0-9, '-' and '.'."); + if (!empty($pconfig['dnssearchdomain'])) { + foreach ($pconfig['dnssearchdomain'] as $dnssearchdomain) { + if (!is_domain($dnssearchdomain, true)) { + $input_errors[] = gettext("A search domain may only contain the characters a-z, 0-9, '-' and '.'."); + } + } } /* collect direct attached networks and static routes */ @@ -204,7 +208,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { } if (!empty($pconfig['dnssearchdomain'])) { - $config['system']['dnssearchdomain'] = $pconfig['dnssearchdomain']; + $config['system']['dnssearchdomain'] = implode(',', $pconfig['dnssearchdomain']); } elseif (isset($config['system']['dnssearchdomain'])) { unset($config['system']['dnssearchdomain']); } @@ -273,9 +277,14 @@ include("head.inc"); + + +