system: allow "." DNS search domain override; closes #6529

While here refactor get_searchdomain() a little to avoid complexity
in system_resolvconf_generate().
This commit is contained in:
Franco Fichtner 2023-05-24 09:29:10 +02:00
parent 33667b8bea
commit c586bdb1a5
2 changed files with 20 additions and 12 deletions

View File

@ -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');

View File

@ -454,7 +454,7 @@ $( document ).ready(function() {
<td>
<input name="dnssearchdomain" type="text" value="<?= $pconfig['dnssearchdomain'] ?>" />
<div class="hidden" data-for="help_for_dnssearchdomain">
<?= gettext('Enter an additional domain to add to the local list of search domains.') ?>
<?= gettext('Enter an additional domain to add to the local list of search domains. Use "." to disable passing any search domain for resolving.') ?>
</div>
</td>
</tr>