summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Stransky <stransky@fedoraproject.org>2007-01-04 14:37:49 +0000
committerMartin Stransky <stransky@fedoraproject.org>2007-01-04 14:37:49 +0000
commitace34f3df1c89504ca167156119f4830a2b43b7b (patch)
treeda2dbf4685e61b5151ca12801f849569d4725920
parent98bf92bceca838293b9aaee46cf7bb41b8e61590 (diff)
downloadbind-ace34f3df1c89504ca167156119f4830a2b43b7b.tar.gz
bind-ace34f3df1c89504ca167156119f4830a2b43b7b.tar.xz
bind-ace34f3df1c89504ca167156119f4830a2b43b7b.zip
added namedGetForwarders written in shell (#176100)
-rw-r--r--bind.spec8
-rwxr-xr-xnamedGetForwarders217
2 files changed, 132 insertions, 93 deletions
diff --git a/bind.spec b/bind.spec
index 01763fb..0325c60 100644
--- a/bind.spec
+++ b/bind.spec
@@ -17,7 +17,7 @@ Summary: The Berkeley Internet Name Domain (BIND) DNS (Domain Name System) serv
Name: bind
License: BSD-like
Version: 9.3.3
-Release: 1%{?prever}%{?dist}
+Release: 2%{?prever}%{?dist}
Epoch: 31
Url: http://www.isc.org/products/BIND/
Buildroot: %{_tmppath}/%{name}-root
@@ -448,7 +448,7 @@ for f in my.internal.zone.db slaves/my.slave.internal.zone.db slaves/my.ddns.int
echo '@ in soa localhost. root 1 3H 15M 1W 1D
ns localhost.' > sample/var/named/$f;
done
-/usr/bin/tail -n '+'`/bin/egrep -n '\\$Id: bind.spec,v 1.149 2006/12/10 23:52:53 stransky Exp $/+1/' | bc` bin/rndc/rndc.conf | sed '/Sample rndc configuration file./{p;i\
+/usr/bin/tail -n '+'`/bin/egrep -n '\\$Id: bind.spec,v 1.150 2007/01/04 14:37:49 stransky Exp $/+1/' | bc` bin/rndc/rndc.conf | sed '/Sample rndc configuration file./{p;i\
*\
* NOTE: you only need to create this file if it is to\
* differ from the following default contents:
@@ -777,6 +777,10 @@ rm -rf ${RPM_BUILD_ROOT}
:;
%changelog
+* Thu Jan 4 2007 Martin Stransky <stransky@redhat.com> - 31:9.3.3-2
+- added namedGetForwarders written in shell (#176100),
+ created by Baris Cicek <baris@nerd.com.tr>.
+
* Sun Dec 10 2006 Martin Stransky <stransky@redhat.com> - 31:9.3.3-1
- update to 9.3.3 final
- fix for #219069: file included twice in src.rpm
diff --git a/namedGetForwarders b/namedGetForwarders
index 4646e03..69bc06d 100755
--- a/namedGetForwarders
+++ b/namedGetForwarders
@@ -1,4 +1,4 @@
-#!/usr/bin/perl
+#!/bin/sh
#
# This script uses the named D-BUS support, which must be enabled in
# the running named with the named '-D' option, to get and print the
@@ -9,12 +9,14 @@
#
# If no zone argument is specified, all forwarding zones will be listed.
#
-# Usage: GetForwarders [-n -r] [ <zone> ]
+# Usage: namedGetForwarders [-n -r] [ <zone> ]
# -n : output forward zone statements for named.conf
# -r : output in resolv.conf format
# : no -r or -n: just list the forwarders
#
-# Copyright(C) Jason Vas Dias<jvdias@redhat.com> Red Hat Inc. 2005
+# This script is based on perl script of Jason Vas Dias <jvdias@redhat.com>.
+#
+# Copyright(C) Baris Cicek <baris@nerd.com.tr> Nerd Software. 2007
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -26,98 +28,131 @@
# 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.
-#
-use Getopt::Std;
-%opts=();
+declare -a zones;
+declare -a servers;
+declare -a ports;
+declare -a only;
+
+output_format='plain';
+zonecnt=0;
+
+function push () {
+ local array
+ array=( `echo $1` );
+ array[${#array[*]}]=$2;
+ echo ${array[@]};
+}
+
+function concat () {
+ local string
+ while [ $# -gt 0 ]; do
+ string=${string}$1;
+ shift;
+ done
+ echo $string;
+}
+
+if [ $# -ge 0 ]; then
+ if [ "$1" == "-r" ]; then
+ output_format='resolv';
+ shift;
+ elif [ "$1" == "-n" ]; then
+ output_format='named';
+ shift;
+ fi
+ zone="";
+ for arg in $*; do
+ zone=$(push "$zone" " string:'$arg'");
+ done
+fi
-getopts("rn",\%opts);
+DNS=`/bin/dbus-send --system --type=method_call --print-reply --reply-timeout=20000 --dest=com.redhat.named /com/redhat/named com.redhat.named.text.GetForwarders $zone`;
-$zone = '';
-if ( $#ARGV >= 0 )
-{
- $zone = "string:'". join("' string:'",@ARGV)."'";
-};
+if [ $? -ne 0 ]; then
+ echo -e "dbus-send failed: $? $!";
+ exit 1;
+fi
-@dn=();
+IFS=$'\n'
-open(DNS,
- '/bin/dbus-send --system --type=method_call --print-reply --reply-timeout=20000 '
- .'--dest=com.redhat.named /com/redhat/named com.redhat.named.text.GetForwarders '
- .$zone .'|'
- ) || die("dbus-send failed: $?: $!");
-while(<DNS>)
-{
- $_=~s/[\s\r\n]+$//;
- if ( /(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/ )
- { # nameserver address
- push @{${$dn[-1]}{'s'}}, { 'a' => "$1.$2.$3.$4" };
- }elsif
- ( /\"(\d+)\"$/ )
- { # port
- if ( $1 != 53 )
- {
- ${@{${$dn[-1]}{'s'}}[-1]}{'p'} = $1;
- };
- }elsif
- ( /string\s+\"([^\"]+)\"$/ )
- {
- if ( ($1 eq 'first') || ($1 eq 'only') )
- { # policy
- if( $1 eq 'only' )
- { # not default
- ${$dn[-1]}{'o'} = 1;
- }
- }else
- { # new DN - "zone"
- push @dn, {'n'=>$1,'s'=>[]};
- };
- };
-};
-close(DNS);
+for line in $DNS; do
+ match_ip=$( echo "$line" | awk --re-interval '{ match ($0, /([[:digit:]]{1,3})\.([[:digit:]]{1,3})\.([[:digit:]]{1,3})\.([[:digit:]]{1,3})/, a); printf "%s.%s.%s.%s", substr($0, a[1, "start"], a[1, "length"]), substr($0, a[2, "start"], a[2, "length"]), substr($0, a[3, "start"], a[3, "length"]), substr($0, a[4, "start"], a[4, "length"]);}' );
+ match_port=$( echo "$line" | awk '{ match ($0, /\"([[:digit:]]+)\"$/, a); printf "%s", substr($0, a[1, "start"], a[1,"length"]);}' );
+ match_string=$( echo "$line" | awk '{ match ($0, /string.+\"([^\"]+)\"$/, a); printf "%s", substr($0, a[1, "start"], a[1,"length"]);}' );
+
+ if [ "$match_ip" != "" ] && [ "$match_ip" != "..." ]; then
+ servers[$zonecnt]=$(push "${servers[$zonecnt]}" "$match_ip");
+ elif [ "$match_port" != "" ]; then
+ ports[$zonecnt]=$(push "${ports[$zonecnt]}" "$match_port");
+ elif [ "$match_string" == "only" ]; then
+ only[$zonecnt]="1";
+ elif [ "$match_string" != "" ] && [ "$match_string" != "first" ]; then
+ zonecnt=$((zonecnt + 1));
+ zones[$zonecnt]="$match_string";
+ fi
+
+done
-if( exists($opts{'r'}) )
-{ # resolv.conf style:
- my %svrs=();
- print 'search ',
- join( ' ',
- grep { !( $_ =~ /\.in-addr\.arpa$/) }
- map { ${$_}{'n'} }
- @dn
- ),"\n",
- 'nameserver ',
- join( "\nnameserver ",
- grep { exists ( $svrs{ $_ } ) ? undef : { $svrs{$_}=$_ } }
- map { ${$_}{'a'} }
- map { @{${$_}{'s'}} } @dn
- ),"\n";
-}elsif( exists($opts{'n'}) )
-{ # named.conf style:
- foreach $d (@dn)
- {
- print 'zone "',${$d}{'n'},'." IN { type forward; forwarders { ',
- join("; ",
- map { exists( ${$_}{'p'} )
- ? ${$_}{'a'} . ' port ' . ${$_}{'p'}
- : ${$_}{'a'}
- } @{${$d}{'s'}}
- ),
- '; }; ',
- exists(${$d}{'o'}) ? ' forward only; ' : '',
- "};\n";
- };
-}else
-{ # just list:
- foreach $d (@dn)
- {
- print ${$d}{'n'}, "\n\t",
- (exists(${$d}{'o'}) ? "forward only\n\t" : ''),
- join( "\n\t",
- map { exists( ${$_}{'p'} )
- ? ${$_}{'a'} . ':' . ${$_}{'p'}
- : ${$_}{'a'}
- } @{${$d}{'s'}}
- ),"\n";
- };
-};
+if [ "$output_format" == "resolv" ]; then
+# resolv.conf style:
+ search_line='search';
+ nameserver_lines='';
+ for index in $(seq 1 $zonecnt); do
+ if [ "` echo ${zones[$index]} | awk ' /\.in-addr\.arpa$/ { print $0 }'`" == '' ]; then
+ search_line=$(push "$search_line" "${zones[$index]}");
+ fi
+ IFS=$' ';
+ for ns in ${servers[$index]}; do
+ nameserver_lines=$(concat "$nameserver_lines" "\nnameserver " "$ns");
+ done
+ done
+ echo -n $search_line;
+ echo -e $nameserver_lines;
+elif [ "$output_format" == "named" ]; then
+# named.conf style:
+ zone_lines='';
+ for index in $(seq 1 $zonecnt); do
+ zone_line=$(concat 'zone "' "${zones[$index]}" '." IN { type forward; forwarders { ');
+ srvcnt=1;
+ IFS=$' ';
+ for ns in ${servers[$index]}; do
+ srvport=$(eval "echo ${ports[$index]} | awk '{ print \$${srvcnt} }'");
+ if [ "$srvport" != "53" ]; then
+ zone_line=$(concat "$zone_line" " $ns port $srvport;");
+ else
+ zone_line=$(concat "$zone_line" " $ns;");
+ fi
+ srvcnt=$((srvcnt+1));
+ done
+ zone_line=$(concat "$zone_line" " };");
+ if [ "${only[$index]}" == '1' ]; then
+ zone_line=$(concat "$zone_line" " forward only;");
+ fi
+ zone_line=$(concat "$zone_line" " };");
+ zone_lines=$(concat "$zone_lines" "$zone_line\n");
+ done
+ echo -e ${zone_lines%\\n};
+elif [ "$output_format" == "plain" ]; then
+# just list:
+ output='';
+ for index in $(seq 1 $zonecnt); do
+ output=$(concat "$output" "${zones[$index]}" "\n");
+ if [ "${only[$index]}" == "1" ]; then
+ output=$(concat "$output" "\t" "forward only" "\n");
+ fi
+ srvcnt=1;
+ IFS=$' ';
+ for ns in ${servers[$index]}; do
+ srvport=$(eval "echo ${ports[$index]} | awk '{ print \$${srvcnt} }'");
+ if [ "$srvport" != "53" ]; then
+ output=$(concat "$output" "\t" "$ns:$srvport" "\n");
+ else
+ output=$(concat "$output" "\t" "$ns" "\n");
+ fi
+ srvcnt=$((srvcnt+1));
+ done
+ done
+ echo -e ${output%\\n};
+fi