[pve-devel] [PATCH common 2/2] Fix #1270: properly read multiple search domains in /etc/resolv.conf

Emmanuel Kasper e.kasper at proxmox.com
Wed Mar 8 13:08:18 CET 2017


---
 src/PVE/INotify.pm                       |  2 +-
 test/inotify/resolv.conf_multiple_search |  5 +++++
 test/inotify/run_inotify_tests.pl        | 16 +++++++++++++++-
 3 files changed, 21 insertions(+), 2 deletions(-)
 create mode 100644 test/inotify/resolv.conf_multiple_search

diff --git a/src/PVE/INotify.pm b/src/PVE/INotify.pm
index 7d2001f..91aa89a 100644
--- a/src/PVE/INotify.pm
+++ b/src/PVE/INotify.pm
@@ -541,7 +541,7 @@ sub read_etc_resolv_conf {
 	chomp $line;
 	# resolv.conf should *either* have a search or domain, else behaviour is undefined
 	# see res_init.c in libc, havesearch is set to 0 when a domain entry is found
-	if ($line =~ m/^(search|domain)\s+(\S+)\s*/) {
+	if ($line =~ m/^(search|domain)\s+((\S+\s*)*)$/) {
 	    $res->{search} = $2;
 	} elsif ($line =~ m/^\s*nameserver\s+($PVE::Tools::IPRE)\s*/) {
 	    $nscount++;
diff --git a/test/inotify/resolv.conf_multiple_search b/test/inotify/resolv.conf_multiple_search
new file mode 100644
index 0000000..7100596
--- /dev/null
+++ b/test/inotify/resolv.conf_multiple_search
@@ -0,0 +1,5 @@
+# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
+#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
+nameserver 8.8.4.4
+nameserver 8.8.8.8
+search proxmox.com proxmox.org proxmox.at
diff --git a/test/inotify/run_inotify_tests.pl b/test/inotify/run_inotify_tests.pl
index 5ecfc5e..775c431 100755
--- a/test/inotify/run_inotify_tests.pl
+++ b/test/inotify/run_inotify_tests.pl
@@ -47,4 +47,18 @@ is(($data_to_write =~ m/^search proxmox.com\n/), 1, 'single entry search was cor
 
 $fh->close();
 
-done_testing();
\ No newline at end of file
+# reading a resolv.conf with a search entry containing multiple domains
+# we don't retest for nameservers as the test data is the same for those
+my $multiple_search = join('/', $Bin, 'resolv.conf_multiple_search');
+$fh = IO::File->new("< $multiple_search");
+$data = PVE::INotify::read_etc_resolv_conf($multiple_search, $fh);
+
+is($data->{search}, 'proxmox.com proxmox.org proxmox.at', 'multiple search domains were correctly read');
+
+$fh->seek(0,0);
+$data_to_write = PVE::INotify::update_etc_resolv_conf($multiple_search, $fh, $data, @args);
+
+is(($data_to_write =~ m/^search proxmox.com proxmox.org proxmox.at\n/), 1, 'multiple search domains were correctly added');
+
+$fh->close();
+done_testing();
-- 
2.1.4





More information about the pve-devel mailing list