From 436c81dad3fa3c99a88e62d6922833ee380d1672 Mon Sep 17 00:00:00 2001 From: Jonathan McDowell Date: Thu, 2 Nov 2006 12:37:06 +0000 Subject: [PATCH] Whitespace/line length cleanup Clean up lines longer than 80 chars and some spacing (eg around =s). git-archimport-id: noodles@earth.li--pie/autodns--mainline--1.0--patch-21 --- autodns.conf | 16 +++---- autodns.pl | 119 +++++++++++++++++++++++++++++---------------------- 2 files changed, 75 insertions(+), 60 deletions(-) diff --git a/autodns.conf b/autodns.conf index f221cc8..d2d3269 100644 --- a/autodns.conf +++ b/autodns.conf @@ -5,30 +5,30 @@ # # Who I should reply as. -$me="autodns\@earth.li"; +$me = "autodns\@earth.li"; # Who replies should be CCed to. -$ccreply="noodles\@earth.li"; +$ccreply = "noodles\@earth.li"; # Where to look for zones we're already hosting. -@cfgfiles=("/etc/bind/named.conf", +@cfgfiles = ("/etc/bind/named.conf", "/etc/bind/named.secondary.conf"); # The file we should add/delete domains from. -$conffile="/etc/bind/named.secondary.conf"; +$conffile = "/etc/bind/named.secondary.conf"; # The file that contains details of the authorized users. -$usersfile="/etc/bind/autodns.users"; +$usersfile = "/etc/bind/autodns.users"; # Base file name to for list of users domains. -$domainlistroot="/etc/bind/domains."; +$domainlistroot = "/etc/bind/domains."; # The lockfile we use to ensure we have exclusive access to the # $domainlistroot$user files and $conffile. -$lockfile="/etc/bind/autodns.lck"; +$lockfile = "/etc/bind/autodns.lck"; # The command to reload the nameserver domains list. -$reload_command="sudo ndc reconfig 2>&1"; +$reload_command = "sudo ndc reconfig 2>&1"; # When we consider a signature to have expired and so to be rejected. # Intended to help prevent reply attacks. Value is in seconds and the diff --git a/autodns.pl b/autodns.pl index edaf5fb..33983a4 100755 --- a/autodns.pl +++ b/autodns.pl @@ -16,7 +16,7 @@ use File::Temp qw(tempfile); use IPC::Open3; use MIME::Parser; -$ENV{'PATH'}="/usr/local/bin:/usr/bin:/bin:/usr/sbin"; +$ENV{'PATH'} = "/usr/local/bin:/usr/bin:/bin:/usr/sbin"; my ($from, $subject, $gpguser, $gpggood, $priv); my ($user, $server, $inprocess, $delcount, $addcount); @@ -25,7 +25,7 @@ my ($domain, @MAIL, @GPGERROR, @COMMANDS, %zones, $VERSION); use vars qw($me $ccreply $conffile $domainlistroot @cfgfiles $usersfile $lockfile $reload_command $expiry $zonefiledir); -$VERSION="0.0.8"; +$VERSION = "0.0.8"; # # Load our config @@ -100,7 +100,6 @@ sub fatalerror($) { close(LOCKFILE); unlink($lockfile); -# die $message; exit; } @@ -124,22 +123,25 @@ sub getuserinfo($) { foreach () { if (/^([^#.]+):$gpguser:(\d+):(.+)$/) { - $user=$1; - $privilege=$2; - $server=$3; + $user = $1; + $privilege = $2; + $server = $3; chomp $user; chomp $privilege; chomp $server; 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; } } @@ -182,17 +184,17 @@ sub addautodnsuser($$$$) { close(USERFILE); } -$delcount=$addcount=$inprocess=0; +$delcount = $addcount = $inprocess = 0; # Read in the mail from stdin. -@MAIL=<>; +@MAIL = <>; $subject = "Reply from AutoDNS"; # Now lets try to find out who it's from. foreach (@MAIL) { if (/^$/) { last; } - if (/^From: (.*)/i) { $from=$1; chomp $from;} - if (/^Subject:\s+(re:)?(.*)$/i) { $subject="Re: ".$2 if ($2);} + if (/^From: (.*)/i) { $from = $1; chomp $from;} + if (/^Subject:\s+(re:)?(.*)$/i) { $subject = "Re: ".$2 if ($2);} } if ((! defined($from)) || $from =~ /^$/ ) { @@ -201,7 +203,7 @@ if ((! defined($from)) || $from =~ /^$/ ) { die "From address is mailer-daemon, ignoring."; } -if (! defined($subject)) { $subject="Reply from AutoDNS"; }; +if (! defined($subject)) { $subject = "Reply from AutoDNS"; }; # We've got a from address. Start a reply. @@ -235,15 +237,14 @@ my $entity = $parser->parse_data(\@MAIL); # # Make sure locale is set to C so we get messages in English as we expect. # -$ENV{'LC_ALL'}="C"; +$ENV{'LC_ALL'} = "C"; if ($entity->parts) { # MIME my ($got_sig, $got_text) = (0, 0); - my ($sig_name,$sig_fh,$text_name,$text_fh); - ($sig_fh, $sig_name) = tempfile(); - ($text_fh, $text_name) = tempfile(); + my ($sig_fh, $sig_name) = tempfile(); + my ($text_fh, $text_name) = tempfile(); foreach my $subent ($entity->parts) { if ($subent->effective_type eq "text/plain") { @@ -287,8 +288,8 @@ if ($entity->parts) { close GPGIN; - @GPGERROR=; - my @GPGOUTPUT=; + @GPGERROR = ; + my @GPGOUTPUT = ; close GPGERR; close GPGOUT; waitpid $pid, 0; @@ -306,8 +307,8 @@ if ($entity->parts) { close GPGIN; # And grab what it has to say. - @GPGERROR=; - @COMMANDS=; + @GPGERROR = ; + @COMMANDS = ; @COMMANDS = split /\n/,$entity->bodyhandle->as_string; close GPGERR; close GPGOUT; @@ -321,7 +322,7 @@ foreach (@GPGERROR) { chomp; if (/Signature made (.*) using.*ID (.*)$/) { $sigtime = str2time($1); - $gpguser=$2; + $gpguser = $2; } elsif (/error/) { $gpggood = 0; print REPLY "Some errors ocurred\n"; @@ -410,9 +411,9 @@ foreach (@COMMANDS) { # Empty line, so ignore it. # } elsif (/^END$/) { - $inprocess=0; + $inprocess = 0; } elsif (/^BEGIN$/) { - $inprocess=1; + $inprocess = 1; } elsif ($inprocess && /^ADD\s+(.*)$/) { $domain = $1; @@ -420,12 +421,13 @@ foreach (@COMMANDS) { $domain =~ tr/[A-Z]/[a-z]/; if (! valid_domain($domain)) { $domain =~ s/[-a-z0-9.]//g; - print REPLY "Invalid character(s) in domain name: $domain\n"; + print REPLY "Invalid character(s) in domain name:", + " $domain\n"; } elsif (defined($zones{$domain}) && $zones{$domain}) { print REPLY "We already secondary $domain\n"; } else { print REPLY "Adding domain $domain\n"; - $zones{$domain}=1; + $zones{$domain} = 1; my $df = $domain; $df =~ tr,/,:,; @@ -456,40 +458,48 @@ zone \"$domain\" { $domain =~ tr/[A-Z]/[a-z]/; if (!valid_domain($domain)) { $domain =~ s/[-a-z0-9.]//g; - print REPLY "Invalid character(s) in domain name: $domain\n"; + print REPLY "Invalid character(s) in domain name:", + " $domain\n"; } elsif (!defined($zones{$domain}) || !$zones{$domain}) { print REPLY "$domain does not exist!\n"; } else { print REPLY "Deleting domain $domain\n"; - my (@newcfg,$found); + 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; if (scalar @cfg == scalar @newcfg) { - print REPLY "Didn't find $domain in $domainlistroot$user!\n"; - print REPLY "You are only allowed to delete your own domains that exist.\n"; + print REPLY "Didn't find $domain in ", + "$domainlistroot$user!\n"; + print REPLY "You are only allowed to delete", + " your own domains that exist.\n"; next; } 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=(); + $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 () { unless (/^\s*zone\s+"$domain"/) { push @newcfg, $_; } else { - $found=1; + $found = 1; if ($newcfg[-1] =~ /^###/) { # remove comment and \n pop @newcfg; @@ -499,12 +509,14 @@ zone \"$domain\" { } # end of paragraph eating if (!$found) { - print REPLY "Didn't find $domain in $conffile!\n"; + print REPLY "Didn't find $domain in", + " $conffile!\n"; next; } 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++; @@ -555,8 +567,8 @@ zone \"$domain\" { close GPGIN; # And grab what it has to say. - @GPGERROR=; - my @GPGOUTPUT=; + @GPGERROR = ; + my @GPGOUTPUT = ; close GPGERR; close GPGOUT; waitpid $pid, 0; @@ -566,18 +578,21 @@ zone \"$domain\" { print REPLY "ADDUSER parameter error.\n"; } } elsif ($inprocess && /^HELP$/) { - print REPLY "In order to use the service, you will need to send GPG signed\n"; - print REPLY "messages.\n\n"; - print REPLY "The format of the text in these messages is important, as they represent\n"; - print REPLY "commands to autodns. Commands are formatted one per line, and enclosed\n"; - print REPLY "by \"BEGIN\" and \"END\" commands (without the quotes).\n"; - print REPLY "Current valid commands are:\n"; - print REPLY "BEGIN - begin processing.\n"; - print REPLY "END - end processing.\n"; - print REPLY "HELP - display this message.\n"; - print REPLY "LIST - show all the zones currently held by you.\n"; - print REPLY "ADD - adds the domain for processing.\n"; - print REPLY "DEL - removes the domain if you own it.\n"; + print REPLY < - adds the domain for processing. +DEL - removes the domain if you own it. +EOF if (($priv & 1) == 1) { print REPLY "MASTER - set the nameserver". " we should slave off for subsequent ADD\ncommands.\n"; -- 2.39.2