diff options
author | Marat Nepomnyashy <marat@vyatta.com> | 2007-12-26 16:51:13 -0800 |
---|---|---|
committer | Marat Nepomnyashy <marat@vyatta.com> | 2007-12-26 16:51:13 -0800 |
commit | ea4c396e33bf34cb8272daa2e1b2177a962cffb1 (patch) | |
tree | d579efec109e9a94bc435864532c5d16c940c861 | |
parent | fa71dcd232351c123ac34dcd6622449f9193b0c5 (diff) | |
download | vyatta-cfg-system-ea4c396e33bf34cb8272daa2e1b2177a962cffb1.tar.gz vyatta-cfg-system-ea4c396e33bf34cb8272daa2e1b2177a962cffb1.zip |
Treat 'system domain-name $(@)' and 'system domain-search domain $(@)' as mutually exclusive. Generate an error message and refuse commit if both are specified. Bug 2256 fix.
-rwxr-xr-x | scripts/system/vyatta_update_resolv.pl | 30 | ||||
-rw-r--r-- | templates/system/domain-name/node.def | 10 |
2 files changed, 31 insertions, 9 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); diff --git a/templates/system/domain-name/node.def b/templates/system/domain-name/node.def index 111061cd..4e3902dc 100644 --- a/templates/system/domain-name/node.def +++ b/templates/system/domain-name/node.def @@ -1,11 +1,9 @@ type: txt help: "Configure system domain name" syntax: pattern $(@) "^[-a-zA-Z0-9.]{0,63}$" ; "invalid domain name $(@)" + # also add localhost line into /etc/hosts (see host-name template)? -update: "sudo sh -c \"if [ x$(@) == x ]; then exit 0; fi && \ -touch /etc/resolv.conf && \ -sed -i '/domain/d' /etc/resolv.conf && \ -echo \\\"domain\t $(@)\\\" >> /etc/resolv.conf\" " +update: "sudo /opt/vyatta/sbin/vyatta_update_resolv.pl" + # also update localhost line in /etc/hosts (see host-name template)? -delete: "sudo sh -c \"touch /etc/resolv.conf && \ -sed -i '/domain\\\\t $(@)/d' /etc/resolv.conf\" " +delete: "sudo /opt/vyatta/sbin/vyatta_update_resolv.pl" |