Project

General

Profile

« Previous | Next » 

Revision 324bbc3f

Added by Jim Pingle about 8 years ago

Restructure how unbound zone data is written to fix processing of "redirect" zone entries. Fixes #7690
Also corrects some other misc issues for formatting of zone data.
While here, add an option, not exposed in the GUI, for users to get the previous behavior of defining short names for hosts.

(cherry picked from commit 021332fa29f0c08bff833ce1c7ddcb9ac9a769b1)

View differences:

src/etc/inc/unbound.inc
568 568
	}
569 569
}
570 570

  
571
function unbound_add_host_entries($cfgsubdir = "") {
572
	global $config, $g;
573

  
574
	// Make sure the config setting is a valid unbound local zone type.  If not use "transparent".
575
	if (array_key_exists($config['unbound']['system_domain_local_zone_type'], unbound_local_zone_types())) {
576
		$system_domain_local_zone_type = $config['unbound']['system_domain_local_zone_type'];
571
function unbound_generate_zone_data($domain, $hosts, &$added_ptr, $zone_type = "transparent", $write_domiain_zone_declaration = false, $always_add_short_names = false) {
572
	global $config;
573
	if ($write_domiain_zone_declaration) {
574
		$zone_data = "local-zone: \"{$domain}.\" {$zone_type}\n";
577 575
	} else {
578
		$system_domain_local_zone_type = "transparent";
576
		$zone_data = "";
579 577
	}
580

  
581
	$unbound_entries = "local-zone: \"{$config['system']['domain']}\" {$system_domain_local_zone_type}\n";
582

  
583
	$hosts = system_hosts_entries($config['unbound']);
584
	$added_ptr = array();
585 578
	foreach ($hosts as $host) {
586 579
		if (is_ipaddrv4($host['ipaddr'])) {
587 580
			$type = 'A';
......
590 583
		} else {
591 584
			continue;
592 585
		}
593

  
594 586
		if (!$added_ptr[$host['ipaddr']]) {
595
			$unbound_entries .= "local-data-ptr: \"{$host['ipaddr']} {$host['fqdn']}\"\n";
587
			$zone_data .= "local-data-ptr: \"{$host['ipaddr']} {$host['fqdn']}\"\n";
596 588
			$added_ptr[$host['ipaddr']] = true;
597 589
		}
598
		$unbound_entries .= "local-data: \"{$host['fqdn']} {$type} {$host['ipaddr']}\"\n";
599
		if (isset($host['name'])) {
600
			$unbound_entries .= "local-data: \"{$host['name']} {$type} {$host['ipaddr']}\"\n";
590
		/* For the system localhost entry, write an entry for just the hostname. */
591
		if ((($host['name'] == "localhost") && ($domain == $config['system']['domain'])) || $always_add_short_names) {
592
			$zone_data .= "local-data: \"{$host['name']}. {$type} {$host['ipaddr']}\"\n";
601 593
		}
594
		/* Redirect zones must have a zone declaration that matches the
595
		 * local-data record exactly, it cannot have entries "under" the
596
		 * domain.
597
		 */
598
		if ($zone_type == "redirect") {
599
			$zone_data .= "local-zone: \"{$host['fqdn']}.\" {$zone_type}\n";;
600
		}
601
		$zone_data .= "local-data: \"{$host['fqdn']}. {$type} {$host['ipaddr']}\"\n";
602
	}
603
	return $zone_data;
604
}
605

  
606
function unbound_add_host_entries($cfgsubdir = "") {
607
	global $config, $g;
608

  
609
	$hosts = system_hosts_entries($config['unbound']);
610

  
611
	/* Pass 1: Build domain list and hosts inside domains */
612
	$hosts_by_domain = array();
613
	foreach ($hosts as $host) {
614
		if (!array_key_exists($host['domain'], $hosts_by_domain)) {
615
			$hosts_by_domain[$host['domain']] = array();
616
		}
617
		$hosts_by_domain[$host['domain']][] = $host;
618
	}
619

  
620
	$added_ptr = array();
621
	/* Build local zone data */
622
	// Check if auto add host entries is not set
623
	$system_domain_local_zone_type = "transparent";
624
	if (!isset($config['unbound']['disable_auto_added_host_entries'])) {
625
		// Make sure the config setting is a valid unbound local zone type.  If not use "transparent".
626
		if (array_key_exists($config['unbound']['system_domain_local_zone_type'], unbound_local_zone_types())) {
627
			$system_domain_local_zone_type = $config['unbound']['system_domain_local_zone_type'];
628
		}
629
	}
630
	/* Add entries for the system domain before all others */
631
	if (array_key_exists($config['system']['domain'], $hosts_by_domain)) {
632
		$unbound_entries .= unbound_generate_zone_data($config['system']['domain'],
633
					$hosts_by_domain[$config['system']['domain']],
634
					$added_ptr,
635
					$system_domain_local_zone_type,
636
					true);
637
		/* Unset this so it isn't processed again by the loop below. */
638
		unset($hosts_by_domain[$config['system']['domain']]);
639
	}
640

  
641
	/* Build zone data for other domain */
642
	foreach ($hosts_by_domain as $domain => $hosts) {
643
		$unbound_entries .= unbound_generate_zone_data($domain,
644
					$hosts,
645
					$added_ptr,
646
					"transparent",
647
					false,
648
					isset($config['unbound']['always_add_short_names']));
602 649
	}
603 650

  
604 651
	// Write out entries

Also available in: Unified diff