diff options
author | Guilhem Moulin <guilhem@fripost.org> | 2014-07-07 05:29:09 +0200 |
---|---|---|
committer | Guilhem Moulin <guilhem@fripost.org> | 2015-06-07 02:52:35 +0200 |
commit | 8fdaba4d764b9e534a0343746a3e30cf3f68852e (patch) | |
tree | 4aea0cc8d0aa6c99c3f08c1650e1e5d5a86ddab7 /roles/MX/files/usr | |
parent | 7c01a383fae4d84727d6a036d93117c761b98e10 (diff) |
Fix a corner case in reserved-alias.pl.
'if $l' is false when $l is 0, while 0@example.org is a perfectly valid
address.
Diffstat (limited to 'roles/MX/files/usr')
-rwxr-xr-x | roles/MX/files/usr/local/sbin/reserved-alias.pl | 11 |
1 files changed, 3 insertions, 8 deletions
diff --git a/roles/MX/files/usr/local/sbin/reserved-alias.pl b/roles/MX/files/usr/local/sbin/reserved-alias.pl index 2c86020..603d773 100755 --- a/roles/MX/files/usr/local/sbin/reserved-alias.pl +++ b/roles/MX/files/usr/local/sbin/reserved-alias.pl @@ -24,55 +24,50 @@ use Net::SMTP; if (!@ARGV or grep { $_ eq '-h' or $_ eq '--help' } @ARGV) { # Help print STDERR "Usage: $0 {original sender} {original recipient} [additional recipient ...]\n"; print STDERR "\n"; print STDERR "The message read from the standard input is redirected to 'additional recipient',\n"; print STDERR "and also forwarded to the domain owner if any. If the 'additional recipient' begins\n"; print STDERR "with '\@', the localpart of 'original recipient' is prepended.\n"; print STDERR "\n"; print STDERR "This is mostly useful to comply to RFC 822 section 6.3 and RFC 2142 section\n"; print STDERR "4 (to forward mails to 'admin\@' and 'postmaster\@' to the site admin in\n"; print STDERR "addition to the virtual domain manager).\n"; exit; } # The original sender my $sender = shift; # The original recipient my $orig = shift; -$orig =~ /^([^@]+)\@(.+)$/ +$orig =~ /^(.+)\@([^@]+)$/ or warn "Warning: Non fully qualified: $orig"; my ($local,$domain) = ($1,$2); # The new recipient (typically, the admin site) my @recipients = grep { $_ and $orig ne $_ } # add localparts to domain map { my $x = $_; if ($x =~ /^\@/) { - if ($local) { - $x = $local.$x; - } - else { - undef $x; - } + $x = (defined $local and $local ne '') ? $local.$x : undef; } $x } @ARGV; # Die if we can't deliver to site admins die "Error: Aborted delivery to '$orig' in attempt to break an alias expansion loop.\n" unless @recipients; if (defined $domain) { # Look for the domain owner or postmaster my $ldap = Net::LDAPI->new(); $ldap->bind( sasl => Authen::SASL->new(mechanism => 'EXTERNAL') ) or die "Error: Couldn't bind"; my @attrs = ( 'fripostPostmaster', 'fripostOwner' ); my $mesg = $ldap->search( base => 'fvd='.escape_dn_value($domain).',' .'ou=virtual,o=mailHosting,dc=fripost,dc=org' , scope => 'base' , deref => 'never' , filter => '(&(objectClass=FripostVirtualDomain)' @@ -80,37 +75,37 @@ if (defined $domain) { ')' , attrs => \@attrs ); if ($mesg->code) { warn "Warning: ".$mesg->error; } elsif ($mesg->count != 1) { # Note: this may happen for "$mydestination", but these mails # are unlikely. We'll get a harmless warning at worst. warn "Warning: Something weird happened when looking up domain '".$domain. "'. Check your ACL."; } else { my $entry = $mesg->pop_entry() // die "Error: Cannot pop entry."; foreach (@attrs) { my $v = $entry->get_value($_, asref => 1) or next; foreach my $dn (@$v) { my $dn2 = ldap_explode_dn($dn, casefold => 'lower'); my $l = $dn2->[0]->{fvl}; my $d = $dn2->[1]->{fvd}; - if ($l and $d) { + if ($l ne '' and $d ne '') { push @recipients, $l.'@'.$d; } else { warn "Warning: Invalid DN: $dn" } } } } $ldap->unbind; } my $smtp = Net::SMTP->new( 'localhost:25', Timeout => 1200 ); $smtp->mail($sender); $smtp->to(@recipients, { Notify => ['FAILURE','DELAY'], SkipBad => 1 }); $smtp->data(<STDIN>); $smtp->quit; |