added namedGetForwarders written in shell (#176100)

This commit is contained in:
Martin Stransky 2007-01-04 14:37:49 +00:00
parent 4f2e75b9bf
commit 286aa4d78c
2 changed files with 131 additions and 92 deletions

View File

@ -17,7 +17,7 @@ Summary: The Berkeley Internet Name Domain (BIND) DNS (Domain Name System) serv
Name: bind Name: bind
License: BSD-like License: BSD-like
Version: 9.3.3 Version: 9.3.3
Release: 1%{?prever}%{?dist} Release: 2%{?prever}%{?dist}
Epoch: 31 Epoch: 31
Url: http://www.isc.org/products/BIND/ Url: http://www.isc.org/products/BIND/
Buildroot: %{_tmppath}/%{name}-root Buildroot: %{_tmppath}/%{name}-root
@ -777,6 +777,10 @@ rm -rf ${RPM_BUILD_ROOT}
:; :;
%changelog %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 * Sun Dec 10 2006 Martin Stransky <stransky@redhat.com> - 31:9.3.3-1
- update to 9.3.3 final - update to 9.3.3 final
- fix for #219069: file included twice in src.rpm - fix for #219069: file included twice in src.rpm

View File

@ -1,4 +1,4 @@
#!/usr/bin/perl #!/bin/sh
# #
# This script uses the named D-BUS support, which must be enabled in # 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 # 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. # 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 # -n : output forward zone statements for named.conf
# -r : output in resolv.conf format # -r : output in resolv.conf format
# : no -r or -n: just list the forwarders # : 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 # 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 # 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 # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
#
use Getopt::Std;
%opts=(); declare -a zones;
declare -a servers;
declare -a ports;
declare -a only;
getopts("rn",\%opts); output_format='plain';
zonecnt=0;
$zone = ''; function push () {
if ( $#ARGV >= 0 ) local array
{ array=( `echo $1` );
$zone = "string:'". join("' string:'",@ARGV)."'"; array[${#array[*]}]=$2;
}; echo ${array[@]};
}
@dn=(); function concat () {
local string
while [ $# -gt 0 ]; do
string=${string}$1;
shift;
done
echo $string;
}
open(DNS, if [ $# -ge 0 ]; then
'/bin/dbus-send --system --type=method_call --print-reply --reply-timeout=20000 ' if [ "$1" == "-r" ]; then
.'--dest=com.redhat.named /com/redhat/named com.redhat.named.text.GetForwarders ' output_format='resolv';
.$zone .'|' shift;
) || die("dbus-send failed: $?: $!"); elif [ "$1" == "-n" ]; then
output_format='named';
shift;
fi
zone="";
for arg in $*; do
zone=$(push "$zone" " string:'$arg'");
done
fi
while(<DNS>) 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`;
{
$_=~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);
if( exists($opts{'r'}) ) if [ $? -ne 0 ]; then
{ # resolv.conf style: echo -e "dbus-send failed: $? $!";
my %svrs=(); exit 1;
print 'search ', fi
join( ' ',
grep { !( $_ =~ /\.in-addr\.arpa$/) } IFS=$'\n'
map { ${$_}{'n'} }
@dn
),"\n", for line in $DNS; do
'nameserver ', 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"]);}' );
join( "\nnameserver ", match_port=$( echo "$line" | awk '{ match ($0, /\"([[:digit:]]+)\"$/, a); printf "%s", substr($0, a[1, "start"], a[1,"length"]);}' );
grep { exists ( $svrs{ $_ } ) ? undef : { $svrs{$_}=$_ } } match_string=$( echo "$line" | awk '{ match ($0, /string.+\"([^\"]+)\"$/, a); printf "%s", substr($0, a[1, "start"], a[1,"length"]);}' );
map { ${$_}{'a'} }
map { @{${$_}{'s'}} } @dn if [ "$match_ip" != "" ] && [ "$match_ip" != "..." ]; then
),"\n"; servers[$zonecnt]=$(push "${servers[$zonecnt]}" "$match_ip");
}elsif( exists($opts{'n'}) ) elif [ "$match_port" != "" ]; then
{ # named.conf style: ports[$zonecnt]=$(push "${ports[$zonecnt]}" "$match_port");
foreach $d (@dn) elif [ "$match_string" == "only" ]; then
{ only[$zonecnt]="1";
print 'zone "',${$d}{'n'},'." IN { type forward; forwarders { ', elif [ "$match_string" != "" ] && [ "$match_string" != "first" ]; then
join("; ", zonecnt=$((zonecnt + 1));
map { exists( ${$_}{'p'} ) zones[$zonecnt]="$match_string";
? ${$_}{'a'} . ' port ' . ${$_}{'p'} fi
: ${$_}{'a'}
} @{${$d}{'s'}} done
),
'; }; ', if [ "$output_format" == "resolv" ]; then
exists(${$d}{'o'}) ? ' forward only; ' : '', # resolv.conf style:
"};\n"; search_line='search';
}; nameserver_lines='';
}else for index in $(seq 1 $zonecnt); do
{ # just list: if [ "` echo ${zones[$index]} | awk ' /\.in-addr\.arpa$/ { print $0 }'`" == '' ]; then
foreach $d (@dn) search_line=$(push "$search_line" "${zones[$index]}");
{ fi
print ${$d}{'n'}, "\n\t", IFS=$' ';
(exists(${$d}{'o'}) ? "forward only\n\t" : ''), for ns in ${servers[$index]}; do
join( "\n\t", nameserver_lines=$(concat "$nameserver_lines" "\nnameserver " "$ns");
map { exists( ${$_}{'p'} ) done
? ${$_}{'a'} . ':' . ${$_}{'p'} done
: ${$_}{'a'} echo -n $search_line;
} @{${$d}{'s'}} echo -e $nameserver_lines;
),"\n"; 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