File: check_relay

package info (click to toggle)
qpsmtpd 0.32-6
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 860 kB
  • ctags: 237
  • sloc: perl: 4,219; sh: 592; makefile: 54
file content (26 lines) | stat: -rw-r--r-- 785 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# this plugin checks the relayclients config file and
# $ENV{RELAYCLIENT} to see if relaying is allowed.
#

sub hook_connect {
  my ($self, $transaction) = @_;
  my $connection = $self->qp->connection;

  # Check if this IP is allowed to relay
  my @relay_clients = $self->qp->config("relayclients");
  my $more_relay_clients = $self->qp->config("morerelayclients", "map");
  my %relay_clients = map { $_ => 1 } @relay_clients;
  my $client_ip = $self->qp->connection->remote_ip;
  while ($client_ip) {
    if (exists($ENV{RELAYCLIENT}) or
        exists($relay_clients{$client_ip}) or
        exists($more_relay_clients->{$client_ip}))
    {
      $connection->relay_client(1);
      last;
    }
    $client_ip =~ s/\d+\.?$//; # strip off another 8 bits
  }
  
  return (DECLINED);
}