summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohit Mehta <mohit.mehta@vyatta.com>2008-08-08 22:53:05 +0000
committerMohit Mehta <mohit.mehta@vyatta.com>2008-08-08 22:53:05 +0000
commitee955bd93bd5199d885c1d6c4c4b18a059ea4c38 (patch)
tree877f71adcf55f655dc3f322ad42aade56bfda397
parent6567750f6bf6d721432d57ef737b72070e697f64 (diff)
downloadvyatta-cfg-quagga-ee955bd93bd5199d885c1d6c4c4b18a059ea4c38.tar.gz
vyatta-cfg-quagga-ee955bd93bd5199d885c1d6c4c4b18a059ea4c38.zip
tighten the checks for checking the existence or removal or nameservers
-rwxr-xr-xscripts/system/vyatta_update_resolv.pl19
-rw-r--r--templates/system/name-server/node.def30
2 files changed, 30 insertions, 19 deletions
diff --git a/scripts/system/vyatta_update_resolv.pl b/scripts/system/vyatta_update_resolv.pl
index cb6599ae..054e8ee9 100755
--- a/scripts/system/vyatta_update_resolv.pl
+++ b/scripts/system/vyatta_update_resolv.pl
@@ -121,8 +121,19 @@ if ($dhclient_script == 1) {
chomp $ns;
$current_dhcp_nameservers[$ns_count] = $ns;
$ns_count++;
- my $search_ns_in_resolvconf = `grep $ns /etc/resolv.conf 2> /dev/null | wc -l`;
- if ($search_ns_in_resolvconf == 0) {
+ my @search_ns_in_resolvconf = `grep $ns /etc/resolv.conf`;
+ my $ns_in_resolvconf = 0;
+ if (@search_ns_in_resolvconf > 0) {
+ foreach my $ns_resolvconf (@search_ns_in_resolvconf) {
+ my @resolv_ns = split(/\s+/, $ns_resolvconf);
+ my $final_ns = $resolv_ns[1];
+ chomp $final_ns;
+ if ($final_ns eq $ns) {
+ $ns_in_resolvconf = 1;
+ }
+ }
+ }
+ if ($ns_in_resolvconf == 0) {
open (APPEND, ">>/etc/resolv.conf") or die "$! error trying to overwrite";
print APPEND "nameserver\t$ns\t\t#nameserver written by $0\n";
close (APPEND);
@@ -145,7 +156,7 @@ if ($dhclient_script == 1) {
}
if ($#current_dhcp_nameservers < 0) {
for my $dhcpnameserver (@dhcp_nameservers_in_resolvconf) {
- my $cmd = "sed -i '/$dhcpnameserver/d' /etc/resolv.conf";
+ my $cmd = "sed -i '/$dhcpnameserver\t/d' /etc/resolv.conf";
system($cmd);
$restart_ntp = 1;
}
@@ -158,7 +169,7 @@ if ($dhclient_script == 1) {
}
}
if ($found == 0) {
- my $cmd = "sed -i '/$dhcpnameserver/d' /etc/resolv.conf";
+ my $cmd = "sed -i '/$dhcpnameserver\t/d' /etc/resolv.conf";
system($cmd);
$restart_ntp = 1;
}
diff --git a/templates/system/name-server/node.def b/templates/system/name-server/node.def
index b5f38527..fce5cac9 100644
--- a/templates/system/name-server/node.def
+++ b/templates/system/name-server/node.def
@@ -1,22 +1,22 @@
multi:
type: ipv4
help: Set Domain Name Server (DNS)
-update:expression: "sudo sh -c \"touch /etc/resolv.conf && \
-if grep -q '$VAR(@)' /etc/resolv.conf; then \
- exit 0; \
-else \
- mv -f /etc/resolv.conf /etc/old_resolv.conf && \
- echo \\\"nameserver\t $VAR(@)\\\" >> /etc/resolv.conf && \
- cat /etc/old_resolv.conf >> /etc/resolv.conf; \
-fi && \
-if [ -d /opt/vyatta/config/active/service/dns/forwarding ]; then \
- /opt/vyatta/sbin/vyatta-dns-forwarding.pl --update-dnsforwarding >&/dev/null; \
-fi && \
-if [ -f /etc/ntp.conf ] && grep -q 'server' /etc/ntp.conf; then \
- /usr/sbin/invoke-rc.d ntp restart >&/dev/null; \
-fi\" "
+update: sudo sh -c "touch /etc/resolv.conf &&
+if grep -q \"$VAR(@)\($\|[[:space:]]\)\" /etc/resolv.conf; then
+ exit 0;
+else
+ mv -f /etc/resolv.conf /etc/old_resolv.conf &&
+ echo \"nameserver $VAR(@)\" >> /etc/resolv.conf &&
+ cat /etc/old_resolv.conf >> /etc/resolv.conf;
+fi &&
+if [ -d /opt/vyatta/config/active/service/dns/forwarding ]; then
+ /opt/vyatta/sbin/vyatta-dns-forwarding.pl --update-dnsforwarding >&/dev/null;
+fi &&
+if [ -f /etc/ntp.conf ] && grep -q 'server' /etc/ntp.conf; then
+ /usr/sbin/invoke-rc.d ntp restart >&/dev/null;
+fi"
delete:expression: "sudo sh -c \"touch /etc/resolv.conf && \
-sed -i '/$VAR(@)/d' /etc/resolv.conf && \
+sed -i '/$VAR(@)$/d' /etc/resolv.conf && \
if [ -f /etc/ntp.conf ] && grep -q 'server' /etc/ntp.conf; then \
/usr/sbin/invoke-rc.d ntp restart >&/dev/null; \
fi && \