summaryrefslogtreecommitdiff
path: root/scripts/system/vyatta_update_resolv.pl
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/system/vyatta_update_resolv.pl')
-rwxr-xr-xscripts/system/vyatta_update_resolv.pl30
1 files changed, 27 insertions, 3 deletions
diff --git a/scripts/system/vyatta_update_resolv.pl b/scripts/system/vyatta_update_resolv.pl
index 0255b256..a8d05cfd 100755
--- a/scripts/system/vyatta_update_resolv.pl
+++ b/scripts/system/vyatta_update_resolv.pl
@@ -47,9 +47,18 @@ if ($modify_dir ne '') {
}
+$vc->setLevel('system');
+
+my @domains = $vc->returnValues('domain-search domain');
+my $domain_name = $vc->returnValue('domain-name');
+
+if (@domains > 0 && $domain_name && length($domain_name) > 0) {
+ print STDERR "System configuration error. Both \'domain-name\' and \'domain-search\' are specified, but only one of these mutually exclusive parameters is allowed.\n";
+ print STDERR "System configuration commit aborted due to error(s).\n";
+ exit(1);
+}
+
my $doms = '';
-$vc->setLevel('system domain-search domain');
-my @domains = $vc->returnValues('.');
foreach my $domain (@domains) {
if (length($doms) > 0) {
$doms .= ' ';
@@ -62,9 +71,15 @@ if (length($doms) > 0) {
$search = "search\t\t$doms\t\t#line generated by $0\n";
}
+my $domain = '';
+if ($domain_name && length($domain_name) > 0) {
+ $domain = "domain\t\t$domain_name\t\t#line generated by $0\n";
+}
+
# The following will re-write '/etc/resolv.conf' line by line,
-# replacing the 'search' specifier with the latest values.
+# replacing the 'search' specifier with the latest values,
+# or replacing the 'domain' specifier with the latest value.
my @resolv;
if (-e '/etc/resolv.conf') {
@@ -75,6 +90,7 @@ if (-e '/etc/resolv.conf') {
my $foundSearch = 0;
+my $foundDomain = 0;
open (RESOLV, '>/etc/resolv.conf') or die("$0: Error! Unable to open '/etc/resolv.conf' for output: $!\n");
foreach my $line (@resolv) {
@@ -83,6 +99,11 @@ foreach my $line (@resolv) {
if (length($search) > 0) {
print RESOLV $search;
}
+ } elsif ($line =~ /^domain\s/) {
+ $foundDomain = 1;
+ if (length($domain) > 0) {
+ print RESOLV $domain;
+ }
} else {
print RESOLV $line;
}
@@ -90,6 +111,9 @@ foreach my $line (@resolv) {
if ($foundSearch == 0 && length($search) > 0) {
print RESOLV $search;
}
+if ($foundDomain == 0 && length($domain) > 0) {
+ print RESOLV $domain;
+}
close (RESOLV);