summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarat Nepomnyashy <marat@eng-158.vyatta.com>2007-12-18 16:53:56 -0800
committerMarat Nepomnyashy <marat@eng-158.vyatta.com>2007-12-18 16:53:56 -0800
commit7dac33b3bfebabb3a9b95dfe6a0578b9f1c31453 (patch)
tree5acd7f3ded71a879c5e845a4a3e4a233c3ce2857
parentc30fc4752c878c12255101aa928c64f7a3511020 (diff)
downloadvyatta-cfg-system-7dac33b3bfebabb3a9b95dfe6a0578b9f1c31453.tar.gz
vyatta-cfg-system-7dac33b3bfebabb3a9b95dfe6a0578b9f1c31453.zip
Rewrite '/etc/resolv.conf' each time config at 'system domain-search domain $(@)' changes to update the 'search' params. Bug 2113 fix.
-rw-r--r--Makefile.am1
-rwxr-xr-xscripts/system/vyatta_update_resolv.pl95
-rw-r--r--templates/system/domain-search/domain/node.def7
3 files changed, 98 insertions, 5 deletions
diff --git a/Makefile.am b/Makefile.am
index 2d109577..a05602cb 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -17,6 +17,7 @@ sbin_SCRIPTS += scripts/quick-install
sbin_SCRIPTS += scripts/standalone_root_pw_reset
sbin_SCRIPTS += scripts/system/vyatta_update_login_user.pl
sbin_SCRIPTS += scripts/system/vyatta_update_logrotate.pl
+sbin_SCRIPTS += scripts/system/vyatta_update_resolv.pl
sbin_SCRIPTS += scripts/system/vyatta_update_syslog.pl
sbin_SCRIPTS += scripts/snmp/vyatta-snmp.pl
sbin_SCRIPTS += scripts/snmp/snmpd.init
diff --git a/scripts/system/vyatta_update_resolv.pl b/scripts/system/vyatta_update_resolv.pl
new file mode 100755
index 00000000..0255b256
--- /dev/null
+++ b/scripts/system/vyatta_update_resolv.pl
@@ -0,0 +1,95 @@
+#!/usr/bin/perl -w
+#
+# Module: vyatta_update_resolv.pl
+#
+# **** License ****
+# Version: VPL 1.0
+#
+# The contents of this file are subject to the Vyatta Public License
+# Version 1.0 ("License"); you may not use this file except in
+# compliance with the License. You may obtain a copy of the License at
+# http://www.vyatta.com/vpl
+#
+# Software distributed under the License is distributed on an "AS IS"
+# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+# the License for the specific language governing rights and limitations
+# under the License.
+#
+# This code was originally developed by Vyatta, Inc.
+# Portions created by Vyatta are Copyright (C) 2007 Vyatta, Inc.
+# All Rights Reserved.
+#
+# Author: Marat Nepomnyashy
+# Date: December 2007
+# Description: Script to update '/etc/resolv.conf' on commit of 'system domain-search domain' config.
+#
+# **** End License ****
+#
+
+use strict;
+use lib "/opt/vyatta/share/perl5/";
+
+
+use Getopt::Long;
+my $change_dir = '';
+my $modify_dir = '';
+GetOptions("change_dir=s" => \$change_dir, "modify_dir=s" => \$modify_dir);
+
+
+use VyattaConfig;
+my $vc = new VyattaConfig();
+
+if ($change_dir ne '') {
+ $vc->{_changes_only_dir_base} = $change_dir;
+}
+if ($modify_dir ne '') {
+ $vc->{_new_config_dir_base} = $modify_dir;
+}
+
+
+my $doms = '';
+$vc->setLevel('system domain-search domain');
+my @domains = $vc->returnValues('.');
+foreach my $domain (@domains) {
+ if (length($doms) > 0) {
+ $doms .= ' ';
+ }
+ $doms .= $domain;
+}
+
+my $search = '';
+if (length($doms) > 0) {
+ $search = "search\t\t$doms\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.
+
+my @resolv;
+if (-e '/etc/resolv.conf') {
+ open (RESOLV, '</etc/resolv.conf') or die("$0: Error! Unable to open '/etc/resolv.conf' for input: $!\n");
+ @resolv = <RESOLV>;
+ close (RESOLV);
+}
+
+
+my $foundSearch = 0;
+
+open (RESOLV, '>/etc/resolv.conf') or die("$0: Error! Unable to open '/etc/resolv.conf' for output: $!\n");
+foreach my $line (@resolv) {
+ if ($line =~ /^search\s/) {
+ $foundSearch = 1;
+ if (length($search) > 0) {
+ print RESOLV $search;
+ }
+ } else {
+ print RESOLV $line;
+ }
+}
+if ($foundSearch == 0 && length($search) > 0) {
+ print RESOLV $search;
+}
+
+close (RESOLV);
+
diff --git a/templates/system/domain-search/domain/node.def b/templates/system/domain-search/domain/node.def
index bc259182..e29df293 100644
--- a/templates/system/domain-search/domain/node.def
+++ b/templates/system/domain-search/domain/node.def
@@ -2,8 +2,5 @@ multi:
type: txt
help: "Configure DNS domain completion order"
syntax: pattern $(@) "^[-a-zA-Z0-9.]+$" ; "invalid domain name $(@)"
-update: "sudo sh -c \"touch /etc/resolv.conf && \
-if grep -q 'search\t $(@)' /etc/resolv.conf; then exit 0; \
-else echo \\\"search\t $(@)\\\" >> /etc/resolv.conf; fi\" "
-delete: "sudo sh -c \"touch /etc/resolv.conf && \
-sed -i '/search\\\\t $(@)/d' /etc/resolv.conf\" "
+update: "sudo /opt/vyatta/sbin/vyatta_update_resolv.pl"
+delete: "sudo /opt/vyatta/sbin/vyatta_update_resolv.pl"