exiacl.pl
changeset 22 e73bf6df70f0
parent 21 2dbba4511409
child 24 a7a73cba1342
--- a/exiacl.pl	Thu Nov 02 21:40:09 2006 +0000
+++ b/exiacl.pl	Fri Nov 10 01:36:47 2006 +0000
@@ -6,7 +6,7 @@
 !ME! [options] [-- exim native options] 
 
     --[no]log	show the log output	[!$Cf->log!]
-    --[no]debug	show debug debug output	[!$Cf->debug!]
+    --[no]debug	show debug output	[!$Cf->debug!]
 
     --from=s	from:			[!$Cf->from!]
     --to=s	to:			[!$Cf->to!]
@@ -18,9 +18,12 @@
     --src=s	src ip/name		[!$Cf->src!]
     --dst=s	dst ip/name		[!$Cf->dst!]
 
+    --au	user (-oMai)		[!$Cf->oMai!]
+    --aa	authenticator (-oMaa)	[!$Cf->oMaa!]
+    
     --exim=s	exim binary		[!$Cf->exim!]
     --config=s	exim config file	[!$Cf->config!]
-    
+
     --[no]callout			[!$Cf->callout!]
 
     Environment used: $EXIM		[!$ENV{EXIM}!]
@@ -50,12 +53,13 @@
 sub hostname() { chomp (my $h = `hostname -f`); return $h;  }
 
 sub which($) { (map { -x "$_/$_[0]" && "$_/$_[0]" || () } split /:/, $ENV{PATH})[0] }
-sub findExim() { which("exim") || which("exim4") }
-sub guessConfig($) { qx/$_[0] "-bV"/ =~ /^Configuration.*\sis\s+(\S+)/mi and return $1 }
+sub findExim() { $ENV{EXIM} || which("exim") || which("exim4") || undef }
+sub guessConfig() { $_ = findExim(); qx/$_ "-bV"/ =~ /^Configuration.*\sis\s+(\S+)/mi and return $1 }
 
 use constant ME => basename $0;
 use constant HOSTNAME => hostname;
-use constant CONFIG => (
+
+my $Cf = new AppConfig (
     { CASE => 1 },
 
     log	    => { ARGS => "!",  DEFAULT => 1 },
@@ -71,19 +75,17 @@
     src	    => { ARGS => "=s", DEFAULT => "172.20.1.8"  },
     dst	    => { ARGS => "=s"  },		    # exim primary_hostname
 
-    exim    => { ARGS => "=s", DEFAULT => $ENV{EXIM} || findExim },
-    config  => { ARGS => "=s", DEFAULT => $ENV{EXIM_CONF} || guessConfig(findExim()),
-		 ALIAS => "C" },
+    au	    => { ARGS => "=s" },
+    aa	    => { ARGS => "=s" },
+
+    exim    => { ARGS => "=s", DEFAULT => findExim() },
+    config  => { ARGS => "=s", DEFAULT => guessConfig(), ALIAS => "C" },
 
     callout =>	{ ARGS => "!", DEFAULT => 1 },
-    help    => { ARGS => "!" },
-
-);
+    help    =>	{ ARGS => "!" },
 
-
+) or die;
 
-my $Cf;
-$Cf = new AppConfig CONFIG or die;
     $Cf->exim				    or die "No exim binary found\n";
     $Cf->dst(addr(exim_option("primary_hostname")));
     #$Cf->getopt(qw(pass_through no_ignore_case)) or die $@;
@@ -96,15 +98,20 @@
 	unless $Cf->Helo;
     $Cf->dst(addr(HOSTNAME))		    unless $Cf->dst;
 
+    $Cf->aa("LOGIN")			    unless $Cf->aa || !$Cf->au;
+
 
 
 MAIN: {
     die "Config file for exim not readable ".$Cf->config.": $!\n" if not -r $Cf->config;
 
+
     my ($w, $r);
     my @cmd = ($Cf->exim, 
 	    -C => $Cf->config, 
 	    -oMi => addr($Cf->dst),
+	    ($Cf->au ? (-oMai => $Cf->au) : ()),
+	    ($Cf->aa ? (-oMaa => $Cf->aa) : ()),
 	    ($Cf->callout? "-bhc" : "-bh" ) => addr($Cf->src),
 	    @ARGV);		    # remaining args are exim native
 
@@ -119,11 +126,12 @@
     }
     die ME.": Missing values: $@\n" if $@;
 
-    my $s = new IO::Select;
+    # my $s = new IO::Select;
 
     print "**> @cmd\n";
 
-    open3($w, $r, undef, @cmd) or die "Can't run @cmd: $!\n";
+    $SIG{PIPE} = sub { exit };
+    my $pid = open3($w, $r, undef, @cmd) or die "Can't run @cmd: $!\n";
 
      read_exim $r;
     write_exim $w, "EHLO ".$Cf->Helo."\n";
@@ -161,7 +169,7 @@
     } continue {
 	last if /^\d\d\d\s/;
     }
-    exit if /^5/;
+    exit if defined and /^[54]/;
 }
 
 sub write_exim($@) {