From: Jonathan McDowell Date: Wed, 15 Jun 2005 10:41:54 +0000 (+0000) Subject: cscvs to tla changeset 12 X-Git-Url: https://the.earth.li/gitweb/?a=commitdiff_plain;h=5f0439a6a86532cb421881271a37539d224aaafd;p=autodns.git cscvs to tla changeset 12 Author: noodles Date: 2005/05/31 12:20:23 Clean up subroutine calls - drop & and add parameter details. git-archimport-id: noodles@earth.li--pie/autodns--mainline--1.0--patch-11 --- diff --git a/autodns.pl b/autodns.pl index 6f14bd3..11f6b31 100755 --- a/autodns.pl +++ b/autodns.pl @@ -5,7 +5,7 @@ # http://www.earth.li/projectpurple/progs/autodns.html # Released under the GPL. # -# $Id: autodns.pl,v 1.11 2005/05/16 17:26:47 noodles Exp $ +# $Id: autodns.pl,v 1.12 2005/05/31 12:20:23 noodles Exp $ # use strict; @@ -47,13 +47,13 @@ unless (my $ret = do $file) { # # Call with the name of a config file to read: # -# &getzones("/etc/named.conf"); +# getzones("/etc/named.conf"); # -sub getzones { - my ($namedfile) = @_; +sub getzones($) { + my $namedfile = shift; open (NAMEDCONF, "< $namedfile") or - &fatalerror("Can't open $namedfile"); + fatalerror("Can't open $namedfile"); while () { if (/^\s*zone\s*"([^"]+)"/) { @@ -69,9 +69,10 @@ sub getzones { # # These are: a-z, 0-9, - or . # -sub valid_domain { +sub valid_domain($) { my $domain = shift; $domain = lc $domain; + if ($domain =~ /^(?:[a-z0-9-]+\.)+[a-z]{2,4}$/) { return 1; } elsif ($domain =~ /^(?:[0-9\/-]+\.)+in-addr.arpa$/) { @@ -87,7 +88,7 @@ sub valid_domain { # # fatalerror("I'm melting!"); # -sub fatalerror { +sub fatalerror($) { my $message = shift; print REPLY $message; @@ -110,14 +111,14 @@ sub fatalerror { # # Priviledge level is not currently used. # -# ($user, $priv, $server) = &getuserinfo("5B430367"); +# ($user, $priv, $server) = getuserinfo("5B430367"); # -sub getuserinfo { +sub getuserinfo($) { my $gpguser = shift; my ($user, $priviledge, $server); open (CONFIGFILE, "< $usersfile") or - &fatalerror("Couldn't open user configuration file."); + fatalerror("Couldn't open user configuration file."); foreach () { if (/^([^#.]+):$gpguser:(\d+):(.+)$/) { @@ -130,13 +131,13 @@ sub getuserinfo { if ($user !~ /^.+$/) { close(CONFIGFILE); - &fatalerror("Error in user configuration file: Can't get username.\n"); + fatalerror("Error in user configuration file: Can't get username.\n"); } if ($server !~ /^(\d{1,3}\.){3}\d{1,3}$/) { $server =~ s/\d\.]//g; close(CONFIGFILE); - &fatalerror("Error in user configuration file: Invalid primary server IP address ($server)\n"); + fatalerror("Error in user configuration file: Invalid primary server IP address ($server)\n"); exit; } } @@ -144,7 +145,7 @@ sub getuserinfo { close(CONFIGFILE); if ($user =~ /^$/) { - &fatalerror("User not found.\n"); + fatalerror("User not found.\n"); } return ($user, $priviledge, $server); @@ -299,7 +300,7 @@ if ($gpggood) { } # Now let's check if we know this person. -($user, $priv, $server) = &getuserinfo($gpguser); +($user, $priv, $server) = getuserinfo($gpguser); if (! defined($user) || ! $user) { print REPLY "Unknown user.\n"; @@ -312,8 +313,8 @@ print REPLY "Got user '$user'\n"; # Right. We know this is a valid user. Get a lock to ensure we have exclusive # access to the configs from here on in. open (LOCKFILE,">$lockfile") || - &fatalerror("Couldn't open lock file\n"); -&fatalerror("Couldn't get lock\n") unless(flock(LOCKFILE,LOCK_EX)); + fatalerror("Couldn't open lock file\n"); +fatalerror("Couldn't get lock\n") unless(flock(LOCKFILE,LOCK_EX)); # Ok, now we should figure out what domains we already know about. foreach my $cfgfile (@cfgfiles) { @@ -323,7 +324,7 @@ foreach my $cfgfile (@cfgfiles) { # Force existance of the $domainlistroot$user file if (! -e $domainlistroot.$user) { open (DOMAINLIST, ">>$domainlistroot$user") or - &fatalerror("Couldn't create domains file.\n"); + fatalerror("Couldn't create domains file.\n"); close DOMAINLIST; } @@ -377,7 +378,7 @@ zone \"$domain\" { close DOMAINSFILE; open (DOMAINLIST, ">>$domainlistroot$user") or - &fatalerror("Couldn't open file.\n"); + fatalerror("Couldn't open file.\n"); print DOMAINLIST "$domain\n"; close DOMAINLIST; $addcount++; @@ -397,7 +398,7 @@ zone \"$domain\" { my (@newcfg,$found); open (DOMAINLIST, "<$domainlistroot$user") or - &fatalerror("Couldn't open file $domainlistroot$user for reading: $!.\n"); + fatalerror("Couldn't open file $domainlistroot$user for reading: $!.\n"); my @cfg = ; close(DOMAINLIST); @newcfg = grep { ! /^$domain$/ } @cfg; @@ -408,14 +409,14 @@ zone \"$domain\" { } open (DOMAINLIST, ">$domainlistroot$user") or - &fatalerror("Couldn't open file $domainlistroot$user for writing: $!.\n"); + fatalerror("Couldn't open file $domainlistroot$user for writing: $!.\n"); print DOMAINLIST @newcfg; close DOMAINLIST; $found=0; @newcfg=(); open (DOMAINSFILE, "<$conffile") or - &fatalerror("Couldn't open file $conffile for reading: $!\n"); + fatalerror("Couldn't open file $conffile for reading: $!\n"); { local $/ = ''; # eat whole paragraphs while () { @@ -437,7 +438,7 @@ zone \"$domain\" { } open (DOMAINSFILE, ">$conffile") or - &fatalerror("Couldn't open $conffile for writing: $!\n"); + fatalerror("Couldn't open $conffile for writing: $!\n"); print DOMAINSFILE @newcfg; close DOMAINSFILE; $delcount++;