]> the.earth.li Git - autodns.git/blobdiff - autodns.pl
cscvs to tla changeset 11
[autodns.git] / autodns.pl
index 67377a3025ee36bcb4cc875361b95a55e4ca2774..6f14bd35efe3ba46266b45135e4996ac164ae9af 100755 (executable)
@@ -1,11 +1,11 @@
 #!/usr/bin/perl -Tw
-# autodns 0.0.7
-# Copyright 1999-2004 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.5 2005/03/21 15:11:01 noodles Exp $
+# $Id: autodns.pl,v 1.11 2005/05/16 17:26:47 noodles Exp $
 #
 
 use strict;
@@ -16,44 +16,25 @@ use MIME::Parser;
 
 $ENV{'PATH'}="/usr/local/bin:/usr/bin:/bin:/usr/sbin";
 
-my ($from, $subject, $gpguser, $gpggood, $usersfile, $lockfile, $priv);
-my ($user, $server, $inprocess, $delcount, $addcount, $reload_command);
-my ($domain, @MAIL, @GPGERROR, @COMMANDS, %zones);
-my ($me, $ccreply, $conffile, $domainlistroot, @cfgfiles, $VERSION);
+my ($from, $subject, $gpguser, $gpggood, $priv);
+my ($user, $server, $inprocess, $delcount, $addcount);
+my ($domain, @MAIL, @GPGERROR, @COMMANDS, %zones, $VERSION);
 
-$VERSION="0.0.7";
+use vars qw($me $ccreply $conffile $domainlistroot @cfgfiles $usersfile
+       $lockfile $reload_command);
+
+$VERSION="0.0.8";
 
 #
-# Local configuration here (until it gets moved to a config file).
-#
-# These are sort of suitable for a Debian setup.
+# Load our config
 #
-
-# 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
@@ -251,7 +232,8 @@ if ($entity->parts) {
        }
 
        if ($got_sig && $got_text) {
-               open3(\*GPGIN, \*GPGOUT, \*GPGERR, "gpg --batch --verify ".
+               my $pid = open3(\*GPGIN, \*GPGOUT, \*GPGERR,
+                       "gpg --batch --verify ".
                        $sig_name." ".$text_name);
 
                close GPGIN;
@@ -260,6 +242,7 @@ if ($entity->parts) {
                my @GPGOUTPUT=<GPGOUT>;
                close GPGERR;
                close GPGOUT;
+               waitpid $pid, 0;
 
                unlink($text_name);
                unlink($sig_name);
@@ -267,7 +250,7 @@ if ($entity->parts) {
 } else {
        # Clear text.
 
-       open3(\*GPGIN, \*GPGOUT, \*GPGERR, "gpg --batch");
+       my $pid = open3(\*GPGIN, \*GPGOUT, \*GPGERR, "gpg --batch");
 
        # Feed it the mail.
        print GPGIN @MAIL;
@@ -278,6 +261,7 @@ if ($entity->parts) {
        @COMMANDS=<GPGOUT>;
        close GPGERR;
        close GPGOUT;
+       waitpid $pid, 0;
 }
 
 # Check who it's from and if the signature was a good one.
@@ -336,6 +320,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;
@@ -467,6 +458,17 @@ zone \"$domain\" {
                } else {
                        print REPLY "Couldn't open $domainlistroot$user: $!\n";
                }
+       } elsif ($inprocess && /^MASTER\s(.*)$/) {
+               if (($priv & 1) != 1) {
+                       print REPLY "You're not authorised to use the MASTER ",
+                               "command.\n";
+               } elsif ($1 =~ /^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})$/) {
+                       $server = $1;
+                       print REPLY "Set master IP address to $1\n";
+               } else {
+                       print REPLY "$1 doesn't look like a valid IPv4 ",
+                               "address to me.\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";