From e171516225bad627b70aed808868396d9264a707 Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Thu, 14 Feb 2019 22:34:06 +0100 Subject: T1174: migrate local hostname/DNS handling to vyos-1x --- ChangeLog | 7 + Makefile.am | 2 - debian/changelog | 7 + scripts/system/vyatta_update_resolv.pl | 268 --------------------- scripts/vyatta-system-nameservers | 102 -------- templates/system/disable-dhcp-nameservers/node.def | 5 - templates/system/domain-search/domain/node.def | 6 - templates/system/domain-search/node.def | 2 - templates/system/name-server/node.def | 10 - 9 files changed, 14 insertions(+), 395 deletions(-) delete mode 100755 scripts/system/vyatta_update_resolv.pl delete mode 100755 scripts/vyatta-system-nameservers delete mode 100644 templates/system/disable-dhcp-nameservers/node.def delete mode 100644 templates/system/domain-search/domain/node.def delete mode 100644 templates/system/domain-search/node.def delete mode 100644 templates/system/name-server/node.def diff --git a/ChangeLog b/ChangeLog index 2d7dc77f..c6b5cd90 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +vyatta-cfg-system (0.20.44+vyos2+current20) unstable; urgency=medium + + * Remove nodes which rely on vyatta_update_resolv.pl + in favor of a vyos-1x migration + + -- Christian Poessinger Thu, 14 Feb 2019 22:34:06 +0100 + vyatta-cfg-system (0.20.44+vyos2+current3) unstable; urgency=medium [ Kim Hagen ] diff --git a/Makefile.am b/Makefile.am index 990cba46..ac414b34 100644 --- a/Makefile.am +++ b/Makefile.am @@ -41,14 +41,12 @@ sbin_SCRIPTS += scripts/system/vyatta_check_domainname.pl sbin_SCRIPTS += scripts/system/vyatta_interface_rescan sbin_SCRIPTS += scripts/system/vyatta_update_login.pl sbin_SCRIPTS += scripts/system/vyatta_update_logrotate.pl -sbin_SCRIPTS += scripts/system/vyatta_update_resolv.pl sbin_SCRIPTS += scripts/system/vyatta_update_sysctl.pl #sbin_SCRIPTS += scripts/system/vyatta_update_syslog.pl sbin_SCRIPTS += scripts/system/vyatta_update_console.pl sbin_SCRIPTS += scripts/system/irq-affinity.pl sbin_SCRIPTS += scripts/snmp/if-mib-alias sbin_SCRIPTS += scripts/telnetd.init -sbin_SCRIPTS += scripts/vyatta-system-nameservers sbin_SCRIPTS += scripts/vyatta-interfaces.pl sbin_SCRIPTS += scripts/vyatta-address sbin_SCRIPTS += scripts/vyatta-tunnel-cleanup diff --git a/debian/changelog b/debian/changelog index 4f4d5fda..66cefb5f 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,10 @@ +vyatta-cfg-system (0.20.44+vyos2+current20) unstable; urgency=medium + + * Remove nodes which rely on vyatta_update_resolv.pl + in favor of a vyos-1x migration + + -- Christian Poessinger Thu, 14 Feb 2019 22:34:06 +0100 + vyatta-cfg-system (0.20.44+vyos2+current19) unstable; urgency=low * linkdown.d and linkup.d scripts moved into vyos-netplug diff --git a/scripts/system/vyatta_update_resolv.pl b/scripts/system/vyatta_update_resolv.pl deleted file mode 100755 index de09a760..00000000 --- a/scripts/system/vyatta_update_resolv.pl +++ /dev/null @@ -1,268 +0,0 @@ -#!/usr/bin/perl -w -# -# Module: vyatta_update_resolv.pl -# -# **** License **** -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License version 2 as -# published by the Free Software Foundation. -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. -# -# 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; -use Vyatta::Config; - -my $dhclient_script = 0; -my $config_mode = 0; - -GetOptions("dhclient-script=i" => \$dhclient_script, - "config-mode=i" => \$config_mode, -); - -my $vc = new Vyatta::Config(); -$vc->setLevel('system'); - -my @search_domains; -my $domain_name = undef; -my $disable_dhcp_nameservers = undef; - -if ($config_mode == 1) { - $disable_dhcp_nameservers = $vc->exists('disable-dhcp-nameservers'); -} else { - $disable_dhcp_nameservers = $vc->existsOrig('disable-dhcp-nameservers'); -} - -if ($dhclient_script == 1) { - @search_domains = $vc->returnOrigValues('domain-search domain'); - $domain_name = $vc->returnOrigValue('domain-name'); -} else { - @search_domains = $vc->returnValues('domain-search domain'); - $domain_name = $vc->returnValue('domain-name'); -} - -if ($dhclient_script == 0 && @search_domains > 0 && $domain_name && length($domain_name) > 0) { - my @location; - if ($vc->returnOrigValues('domain-search domain') > 0) { - @location = ["system","domain-name"]; - } - else { - @location = ["system","domain-search","domain"]; - } - Vyatta::Config::outputError(@location,"System configuration error. Both \'domain-name\' and \'domain-search\' are specified, but only one of these mutually exclusive parameters is allowed."); - exit(1); -} - -my $search_domain_list = ''; -my $search_includes_system = 0; - -foreach my $domain (@search_domains) { - if (length($search_domain_list) > 0) { - $search_domain_list .= ' '; - } - $search_domain_list .= $domain; - $search_includes_system = 1; -} - -# add domain searches received from the dhcp client to those already in /etc/resolv.conf, as long as domain-name is not set in the CLI - -my $search_includes_dhcp = 0; - -if (!defined($domain_name)) { - my @dhcp_interfaces_resolv_files = `ls /etc/ | grep resolv.conf.dhclient-new`; - if ($#dhcp_interfaces_resolv_files >= 0) { - for my $each_file (@dhcp_interfaces_resolv_files) { - chomp $each_file; - my $find_search = `grep "^search" /etc/$each_file 2> /dev/null | wc -l`; - if ($find_search == 1) { - my $search_string = `grep "^search" /etc/$each_file`; - my @dhcp_domains = split(/\s+/, $search_string, 2); - my $dhcp_domain = $dhcp_domains[1]; - chomp $dhcp_domain; - if (length($search_domain_list) > 0) { - $search_domain_list .= ' '; - } - $search_domain_list .= $dhcp_domain; - $search_includes_dhcp = 1; - } - } - } -} - -my $search = ''; -if (length($search_domain_list) > 0) { - my $source; - if ($search_includes_system == 1) { - if ($search_includes_dhcp == 1) { - $source = "(system + dhcp)"; - } else { - $source = "(system)"; - } - } else { - $source = "(dhcp)"; - } - $search = "#line generated by vyatta_update_resolv.pl $source\nsearch\t\t$search_domain_list\n"; -} - -my $domain = ''; -if ($domain_name && length($domain_name) > 0) { - $domain = "#line generated by vyatta_update_resolv.pl (system)\ndomain\t\t$domain_name\n"; -} - -# update /etc/resolv.conf with name-servers received from dhcp client, done when this script is called -# with either the dhclient-script (on DHCP changes) or config-mode (disable-dhcp-nameservers) options. - -if (($dhclient_script == 1) || ($config_mode == 1)) { - my @current_dhcp_nameservers; - - # code below to add new name-servers received from dhcp client, but only if disable-dhcp-nameservers - # hasn't been enabled. - - my @dhcp_interfaces_resolv_files = `ls /etc/ | grep resolv.conf.dhclient-new`; - if ($#dhcp_interfaces_resolv_files >= 0) { - my $ns_count = 0; - for my $each_file (@dhcp_interfaces_resolv_files) { - chomp $each_file; - my $find_nameserver = `grep nameserver /etc/$each_file 2> /dev/null | wc -l`; - if ($find_nameserver > 0) { - my @nameservers = `grep nameserver /etc/$each_file`; - for my $each_nameserver (@nameservers) { - my @nameserver = split(/ /, $each_nameserver, 2); - my $ns = $nameserver[1]; - chomp $ns; - $current_dhcp_nameservers[$ns_count] = $ns; - $ns_count++; - 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) && !($disable_dhcp_nameservers)) { - open (my $rf, '>>', '/etc/resolv.conf') - or die "$! error trying to overwrite"; - print $rf "#nameserver written by vyatta_update_resolv.pl (dhcp)\nnameserver\t$ns\n"; - close $rf; - } - } - } - } - } - - # code below to remove old name-servers from /etc/resolv.conf that were not received in this response - # from dhcp-server, or to remove previous dhcp supplied name-servers if disable-dhcp-nameservers has - # been enabled. - - my $found_old = 0; - - my @nameservers_dhcp_in_resolvconf = `sed -n '/nameserver written/{n;P;}' /etc/resolv.conf`; - for my $old_style_nameservers (@nameservers_dhcp_in_resolvconf) { - if ($old_style_nameservers =~ /#line generated by/){ - @nameservers_dhcp_in_resolvconf = `sed -n '/nameserver written/{P;}' /etc/resolv.conf`; - $found_old = 1; - last; - } - } - my @dhcp_nameservers_in_resolvconf; - my $count_nameservers_in_resolvconf = 0; - for my $count_dhcp_nameserver (@nameservers_dhcp_in_resolvconf) { - my @dhcp_nameserver = split(/\t/, $count_dhcp_nameserver, 3); - $dhcp_nameservers_in_resolvconf[$count_nameservers_in_resolvconf] = $dhcp_nameserver[1]; - $count_nameservers_in_resolvconf++; - } - if (($#current_dhcp_nameservers < 0) || ($disable_dhcp_nameservers)) { - for my $dhcpnameserver (@dhcp_nameservers_in_resolvconf) { - my $cmd; - chomp $dhcpnameserver; - if ($found_old == 1) { - $cmd = "sed -i '/nameserver\t$dhcpnameserver/d' /etc/resolv.conf"; - } else { - $cmd = "sed -i -n '/nameserver\t$dhcpnameserver/".'{n;x;d;};x;1d;p;${x;p;}'."' /etc/resolv.conf"; - } - system($cmd); - } - } else { - for my $dhcpnameserver (@dhcp_nameservers_in_resolvconf) { - my $found = 0; - my $cmd; - chomp $dhcpnameserver; - for my $currentnameserver (@current_dhcp_nameservers) { - if ($dhcpnameserver eq $currentnameserver){ - $found = 1; - } - } - if ($found == 0) { - if ($found_old == 1) { - $cmd = "sed -i '/nameserver\t$dhcpnameserver/d' /etc/resolv.conf"; - } else { - $cmd = "sed -i -n '/nameserver\t$dhcpnameserver/".'{n;x;d;};x;1d;p;${x;p;}'."' /etc/resolv.conf"; - } - system($cmd); - } - } - } -} - -# The following will re-write '/etc/resolv.conf' line by line, -# replacing the 'search' specifier with the latest values, -# or replacing the 'domain' specifier with the latest value. - -my @resolv; -if (-e '/etc/resolv.conf') { - open (my $f, '<', '/etc/resolv.conf') - or die("$0: Error! Unable to open '/etc/resolv.conf' for input: $!\n"); - @resolv = <$f>; - close ($f); -} - -my $foundSearch = 0; -my $foundDomain = 0; - -open (my $r, '>', '/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 $r $search; - } - } elsif ($line =~ /^domain\s/) { - $foundDomain = 1; - if (length($domain) > 0) { - print $r $domain; - } - } elsif ($line !~ /^#line generated by\s/) { - print $r $line; - } -} - -if ($foundSearch == 0 && length($search) > 0) { - print $r $search; -} -if ($foundDomain == 0 && length($domain) > 0) { - print $r $domain; -} - -close ($r); diff --git a/scripts/vyatta-system-nameservers b/scripts/vyatta-system-nameservers deleted file mode 100755 index 9c688e80..00000000 --- a/scripts/vyatta-system-nameservers +++ /dev/null @@ -1,102 +0,0 @@ -#!/bin/bash -# -# Module: vyatta-system-nameservers -# -# **** License **** -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License version 2 as -# published by the Free Software Foundation. -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. -# -# This code was originally developed by Vyatta, Inc. -# Portions created by Vyatta are Copyright (C) 2008 Vyatta, Inc. -# All Rights Reserved. -# -# Author: Mohit Mehta -# Date: September 2008 -# Description: CLI back-end script for setting/deleting system nameservers -# -# **** End License **** -# - -print_usage() { - echo "Usage:" - echo -e "\t$0 update " - echo -e "\t$0 delete " -} - -restart_dnsmasq () { - # restart dnsmasq if dns-forwarding is configured - if cli-shell-api existsActive service dns forwarding; then - /opt/vyatta/sbin/vyatta-dns-forwarding.pl --update-dnsforwarding >&/dev/null - fi -} - -update_system_nameservers () { - nameserver=$1 - touch /etc/resolv.conf - # if name-server already in /etc/resolv.conf then exit - if grep -q "$nameserver\($\|[[:space:]]\)" /etc/resolv.conf; then - exit 0 - else - # find last instance of cli inserted nameserver - # insert currently received nameserver immediately after that - # this is done to keep system set nameservers priority over dhcp received nameservers - cli_ns_array=($(awk '{if (/(dhcp)/) exit 0; if (!$3) print $2}' /etc/resolv.conf)) - cli_ns_array_len=${#cli_ns_array[*]} - line_num=0 - if [ $cli_ns_array_len -gt 0 ]; then - grepped_ns_line=`grep "${cli_ns_array[$cli_ns_array_len-1]}$" -n /etc/resolv.conf` - echo ${grepped_ns_line%%:*} > /etc/resolv_tmp.conf - line_num=`cat /etc/resolv_tmp.conf` - fi - head -$line_num /etc/resolv.conf > /etc/resolv_tmp.conf - echo "nameserver $nameserver" >> /etc/resolv_tmp.conf - total_lines=`cat /etc/resolv.conf | wc -l` - rest_lines=`expr $total_lines - $line_num` - tail -$rest_lines /etc/resolv.conf >> /etc/resolv_tmp.conf - mv -f /etc/resolv_tmp.conf /etc/resolv.conf - fi - restart_dnsmasq -} - -delete_system_nameserver () { - nameserver=$1 - touch /etc/resolv.conf - # remove specified nameserver - sed -i "/$nameserver$/d" /etc/resolv.conf - restart_dnsmasq -} - -# -# main -# - -case "$1" in - update) - if [ $# -ne 2 ]; then - print_usage - exit 1 - fi - update_system_nameservers $2 - exit 0 - ;; - - delete) - if [ $# -ne 2 ]; then - print_usage - exit 1 - fi - delete_system_nameserver $2 - exit 0 - ;; - - *) - print_usage - exit 1 - ;; -esac diff --git a/templates/system/disable-dhcp-nameservers/node.def b/templates/system/disable-dhcp-nameservers/node.def deleted file mode 100644 index adf84948..00000000 --- a/templates/system/disable-dhcp-nameservers/node.def +++ /dev/null @@ -1,5 +0,0 @@ -priority: 300 -help: Disable DHCP updates of DNS settings - -create: sudo /opt/vyatta/sbin/vyatta_update_resolv.pl --config-mode 1 -delete: sudo /opt/vyatta/sbin/vyatta_update_resolv.pl --config-mode 1 diff --git a/templates/system/domain-search/domain/node.def b/templates/system/domain-search/domain/node.def deleted file mode 100644 index d455745b..00000000 --- a/templates/system/domain-search/domain/node.def +++ /dev/null @@ -1,6 +0,0 @@ -multi: -type: txt -help: DNS domain completion order -syntax:expression: pattern $VAR(@) "^[-a-zA-Z0-9.]+$" ; "invalid domain name $VAR(@)" -create:expression: "sudo /opt/vyatta/sbin/vyatta_update_resolv.pl" -delete:expression: "sudo /opt/vyatta/sbin/vyatta_update_resolv.pl" diff --git a/templates/system/domain-search/node.def b/templates/system/domain-search/node.def deleted file mode 100644 index 4bc32c52..00000000 --- a/templates/system/domain-search/node.def +++ /dev/null @@ -1,2 +0,0 @@ -priority: 400 -help: Domain Name Server (DNS) domain completion order diff --git a/templates/system/name-server/node.def b/templates/system/name-server/node.def deleted file mode 100644 index b2aadb4e..00000000 --- a/templates/system/name-server/node.def +++ /dev/null @@ -1,10 +0,0 @@ -multi: -priority: 400 -type: ipv4,ipv6 -help: Domain Name Server (DNS) -val_help: ipv4; Domain Name Server (DNS) address -val_help: ipv6; Domain Name Server (DNS) address - -create: sudo /opt/vyatta/sbin/vyatta-system-nameservers update $VAR(@) - -delete: sudo /opt/vyatta/sbin/vyatta-system-nameservers delete $VAR(@) -- cgit v1.2.3