X-Git-Url: https://the.earth.li/gitweb/?a=blobdiff_plain;f=autodns.pl;h=8e1e20bbfc8c105119adb0422daf14be61031db8;hb=eff7c09ed93bdb9e1c6d631e29aad730926bbae4;hp=4ddd2af4bf98ce30dbd8f2f723c3b31979e03881;hpb=0f0b714329f21d32e30c0e4856602181f4b70d64;p=autodns.git diff --git a/autodns.pl b/autodns.pl index 4ddd2af..8e1e20b 100755 --- a/autodns.pl +++ b/autodns.pl @@ -1,16 +1,18 @@ #!/usr/bin/perl -Tw -# autodns 0.0.6 -# Copyright 1999-2003 Project Purple. Written by Jonathan McDowell +# autodns 0.0.8 +# Copyright 1999-2005 Project Purple. Written by Jonathan McDowell # See ACKNOWLEDGEMENTS file for full details of contributors. # http://www.earth.li/projectpurple/progs/autodns.html # Released under the GPL. # -# $Id: autodns.pl,v 1.3 2004/04/08 10:45:44 noodles Exp $ +# $Id: autodns.pl,v 1.9 2005/04/13 17:24:40 noodles Exp $ # use strict; -use IPC::Open3; use Fcntl qw(:flock); +use File::Temp qw(tempfile); +use IPC::Open3; +use MIME::Parser; $ENV{'PATH'}="/usr/local/bin:/usr/bin:/bin:/usr/sbin"; @@ -19,39 +21,18 @@ my ($user, $server, $inprocess, $delcount, $addcount, $reload_command); my ($domain, @MAIL, @GPGERROR, @COMMANDS, %zones); my ($me, $ccreply, $conffile, $domainlistroot, @cfgfiles, $VERSION); -$VERSION="0.0.6"; +$VERSION="0.0.8"; # -# Local configuration here (until it gets moved to a config file). +# Load our config # -# These are sort of suitable for a Debian setup. -# - -# Who I should reply as. -$me="autodns\@earth.li"; - -# Who replies should be CCed to. -$ccreply="noodles\@earth.li"; - -# Where to look for zones we're already hosting. -@cfgfiles=("/etc/bind/named.conf", - "/etc/bind/named.secondary.conf"); - -# The file we should add/delete domains from. -$conffile="/etc/bind/named.secondary.conf"; - -# The file that contains details of the authorized users. -$usersfile="/etc/bind/autodns.users"; - -# Base file name to for list of users 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"; - -# The command to reload the nameserver domains list. -$reload_command="sudo ndc reconfig 2>&1"; +my $file = '/etc/bind/autodns.conf'; +unless (my $ret = do $file) { + warn "Couldn't parse $file\n" if $@; + warn "Couldn't do $file\n" unless defined $ret; + warn "Couldn't run $file\n" unless $ret; + die "Problem reading config file!\n"; +} ### ### There should be no need to edit anything below (unless you're not @@ -205,27 +186,81 @@ print REPLY <output_to_core(1); # No temporary files +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"; -open3(\*GPGIN, \*GPGOUT, \*GPGERR, "gpg --batch"); -# Feed it the mail. -print GPGIN @MAIL; -close GPGIN; +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(); + + foreach my $subent ($entity->parts) { + if ($subent->effective_type eq "text/plain") { + @COMMANDS = split /\n/,$subent->bodyhandle->as_string; + + my $str = $subent->as_string; + $str =~ s/=\n$//; + $str =~ s/\n/\r\n/g; + print $text_fh $str; + close($text_fh); + $got_text++; + } elsif ($subent->effective_type eq + "application/pgp-signature") { + print $sig_fh $subent->as_string; + close($sig_fh); + $got_sig++; + } + } + + if ($got_sig && $got_text) { + my $pid = open3(\*GPGIN, \*GPGOUT, \*GPGERR, + "gpg --batch --verify ". + $sig_name." ".$text_name); + + close GPGIN; + + @GPGERROR=; + my @GPGOUTPUT=; + close GPGERR; + close GPGOUT; + waitpid $pid, 0; + + unlink($text_name); + unlink($sig_name); + } +} else { + # Clear text. -# And grab what it has to say. -@GPGERROR=; -@COMMANDS=; -close GPGERR; -close GPGOUT; + my $pid = open3(\*GPGIN, \*GPGOUT, \*GPGERR, "gpg --batch"); + + # Feed it the mail. + print GPGIN @MAIL; + close GPGIN; + + # And grab what it has to say. + @GPGERROR=; + @COMMANDS=; + close GPGERR; + close GPGOUT; + waitpid $pid, 0; +} # Check who it's from and if the signature was a good one. $gpggood=1; @@ -283,6 +318,13 @@ foreach my $cfgfile (@cfgfiles) { getzones($cfgfile); } +# Force existance of the $domainlistroot$user file +if (! -e $domainlistroot.$user) { + open (DOMAINLIST, ">>$domainlistroot$user") or + &fatalerror("Couldn't create domains file.\n"); + close DOMAINLIST; +} + foreach (@COMMANDS) { # Remove trailing CRs and leading/trailing whitespace chomp;