From 652e07ced7cfbd8bc895384bdd8dacabeb25d2b6 Mon Sep 17 00:00:00 2001 From: Scott Kitterman Date: Thu, 26 Jul 2018 03:06:18 -0400 Subject: [PATCH] Non-working attempt at config file for relay exemption --- postfix-policyd-spf-perl | 41 ++++++++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/postfix-policyd-spf-perl b/postfix-policyd-spf-perl index 3491f00..0e2da49 100755 --- a/postfix-policyd-spf-perl +++ b/postfix-policyd-spf-perl @@ -78,8 +78,9 @@ my $VERBOSE = 0; my $DEFAULT_RESPONSE = 'DUNNO'; -# Read in exempt domains list +# Read in exemption lists my $exempt_domains = get_exempt_domains( "/etc/postfix/exempt_spf_domains" ); +my $relay_addresses = get_exempt_address("/etc/postfix/exempt_spf_addresses"); # # Syslogging options for verbose mode and for fatal errors. @@ -97,11 +98,6 @@ use constant localhost_addresses => map( qw( 127.0.0.0/8 ::ffff:127.0.0.0/104 ::1 ) ); # Does Postfix ever say "client_address=::ffff:"? -use constant relay_addresses => map( - NetAddr::IP->new($_), - qw( ) -); # add addresses to qw ( ) above separated by spaces using CIDR notation. - # Fully qualified hostname, if available, for use in authentication results # headers now provided by the localhost and whitelist checks. my $host = hostname_long; @@ -195,6 +191,7 @@ while () { # ---------------------------------------------------------- # handler: domain exemption # ---------------------------------------------------------- + sub get_exempt_domains { my ( $file ) = @_; @@ -255,6 +252,38 @@ sub exempt_localhost { # handler: relay exemption # ---------------------------------------------------------- +sub get_exempt_address { + my ( $file ) = @_; + + my $list = {}; + + # Return nothing if file not found + if ( ! -r $file ) { + return $list; + } + + # Read the file into one variable, split on space or comma (or all) + open ( FILE, $file ) or die "Can't open $file: $!\n"; + my $text = ""; + while ( my $tmp = ) { + $text .= $tmp; + } + close( FILE ); + + #$list => map( + # NetAddr::IP->new($_), + # qw( $text ) + #); # add addresses to qw ( ) above separated by spaces using CIDR notation. + + foreach my $addr ( split( /[\s,]+/, $text ) ) { + map( + NetAddr::IP->new($list), + qw( $addr ) + ); + } + return $list; +} + sub exempt_relay { my %options = @_; my $attr = $options{attr};