--- rpms/smeserver-qpsmtpd/sme9/smeserver-qpsmtpd-2.4.0-allow_relayclients_wo_authentications.patch 2014/12/02 23:45:49 1.2 +++ rpms/smeserver-qpsmtpd/sme9/smeserver-qpsmtpd-2.4.0-allow_relayclients_wo_authentications.patch 2014/12/03 23:53:41 1.3 @@ -1,41 +1,41 @@ diff -Nur smeserver-qpsmtpd-2.4.0/root/etc/e-smith/templates/var/service/qpsmtpd/config/relayclients/60myAppliances smeserver-qpsmtpd-2.4.0.bz8704/root/etc/e-smith/templates/var/service/qpsmtpd/config/relayclients/60myAppliances --- smeserver-qpsmtpd-2.4.0/root/etc/e-smith/templates/var/service/qpsmtpd/config/relayclients/60myAppliances 1970-01-01 01:00:00.000000000 +0100 -+++ smeserver-qpsmtpd-2.4.0.bz8704/root/etc/e-smith/templates/var/service/qpsmtpd/config/relayclients/60myAppliances 2014-12-03 00:42:56.346024376 +0100 ++++ smeserver-qpsmtpd-2.4.0.bz8704/root/etc/e-smith/templates/var/service/qpsmtpd/config/relayclients/60myAppliances 2014-12-04 00:41:19.363852378 +0100 @@ -0,0 +1,37 @@ +{ -+ use esmith::util::network qw( isValidIP ); -+ use Net::IPv4Addr qw( ipv4_in_network ); ++ use esmith::util::network qw(isValidIP); ++ use Net::IPv4Addr qw(ipv4_in_network ipv4_parse); + -+ my @relayclients = split /[,:]/, ${qpsmtpd}{UnauthenticatedRelayClients} || ''; -+ return "# No relay clients are defined" unless (scalar @relayclients); ++ my $relayclients = ${qpsmtpd}{UnauthenticatedRelayClients} || return; ++ my @relayclients = split /[,:]/, $relayclients; + -+ foreach my $relayclients (@relayclients) -+ { -+ #start to find the local network range + my $ndb = esmith::NetworksDB->open_ro(); -+ my @localAccess; + -+ foreach ($ndb->local_access_spec()) ++ sub convert_to_cidr ++ { ++ $_ = shift; ++ return "$_/32" unless m!/!; ++ my ($ip,$bits) = ipv4_parse($_); ++ return "$ip/$bits"; ++ } ++ ++ my @localAccess = map { ++ convert_to_cidr($_) ++ } $ndb->local_access_spec(); ++ ++ foreach my $relayclient (@relayclients) ++ { ++ if (!isValidIP($relayclient)) + { -+ # If there's a / in the network string -+ # then convert to CIDR notation -+ if (m!/!) -+ { -+ my ($ip,$bits) = Net::IPv4Addr::ipv4_parse($_); -+ push (@localAccess,"$ip/$bits"); -+ } ++ $OUT .= "## $relayclient is not an IP\n"; + } -+ -+ foreach my $localAccess (@localAccess) ++ elsif (grep { ipv4_in_network($_, $relayclient) } @localAccess) + { -+ if (isValidIP($relayclients) && ipv4_in_network ("$localAccess",$relayclients)) -+ { -+ $OUT .= "$relayclients\n"; -+ } ++ $OUT .= "$relayclient\n"; ++ } + else -+ { -+ $OUT .= "## $relayclients is not an IP or not in the localnetwork\n"; -+ } ++ { ++ $OUT .= "## $relayclient is not in any local network\n"; + } + } +}