<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/usr/bin/perl -W

#----------------------------------------------------------------------
# copyright (C) 2001 Florin Grad
# 
# This is a really silly program that is supposed to generate a new key 
# and update the existing one in /etc/rndc.conf or /etc/named.conf
# 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
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#       
# 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.
#       
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
#------------------------------------------------------------------------

my $key ="";

#generate the key
system ("dns-keygen &gt; /etc/rndc.key") ;
open (KEY, "&lt; /etc/rndc.key") or die "Can't open the/etc/rdnc.key_file file for reading";
while (&lt;KEY&gt;) {
	chomp($_);
	my @list = $_;
	$key = $list[0];
}
close(KEY);
system ("rm -rf /etc/rndc.key");

#update the /etc/rndc.conf file
my $conf_file = "/etc/rndc.conf";
my $conf_file_backup = $conf_file.".backup";

open (CONF, "&lt; $conf_file") or die "Can't open the $conf_file file for reading";
open (CONF_new, "&gt; $conf_file_backup") or die "Can't open the $conf_file_backup file for writing";
while (&lt;CONF&gt;) {
	chomp($_);
	my @line = split (/\s+|\t+/,$_) ;
	if ($line[1] &amp;&amp; ($line[1] eq "secret") &amp;&amp; $line[2] &amp;&amp; ($line[2] ne "must")) {
		print CONF_new "\tsecret \"".$key."\";\n";
		next;
	};
	print CONF_new "$_\n";
};
close (CONF_new);
close (CONF);
rename ("$conf_file","$conf_file".".orig");
rename ("$conf_file_backup","$conf_file");

#update the /etc/.named file
$conf_file = "/etc/named.conf";
$conf_file_backup = $conf_file.".backup";

open (CONF, "&lt; $conf_file") or die "Can't open the $conf_file file for reading";
open (CONF_new, "&gt; $conf_file_backup") or die "Can't open the $conf_file_backup file for writing";
while (&lt;CONF&gt;) {
	chomp($_);
	my @line = split (/\s+|\t+/,$_) ;
	if ($line[1] &amp;&amp; ($line[1] eq "secret") &amp;&amp; $line[2] &amp;&amp; ($line[2] ne "must")) {
		print CONF_new "\tsecret \"".$key."\";\n";
		next;
	};
	print CONF_new "$_\n";
};
close (CONF_new);
close (CONF);
rename ("$conf_file","$conf_file".".orig");
rename ("$conf_file_backup","$conf_file");

#fix permissions
system "chmod 0600 /etc/rndc.conf /etc/named.conf";
system "chown named.named /etc/rndc.conf /etc/named.conf";


</pre></body></html>