Debian Codegraph @

plugins/async/dns_whitelist_soft

raw
1 #!perl -w
2
3 use Qpsmtpd::Plugin::Async::DNSBLBase;
4
5 sub init {
6 my $self = shift;
7 my $class = ref $self;
8
9 no strict 'refs';
10 push @{"${class}::ISA"}, 'Qpsmtpd::Plugin::Async::DNSBLBase';
11 }
12
13 sub hook_connect {
14 my ($self, $transaction) = @_;
15 my $class = ref $self;
16
17 my %whitelist_zones =
18 map { (split /\s+/, $_, 2)[0, 1] } $self->qp->config('whitelist_zones');
19
20 return DECLINED unless %whitelist_zones;
21
22 my $remote_ip = $self->connection->remote_ip;
23 my $reversed_ip = join(".", reverse(split(/\./, $remote_ip)));
24
25 # type TXT lookup only
26 return DECLINED
27 unless $class->lookup($self->qp, [],
28 [map { "$reversed_ip.$_" } keys %whitelist_zones],
29 );
30
31 return YIELD;
32 }
33
34 sub process_txt_result {
35 my ($class, $qp, $result, $query) = @_;
36
37 my $connection = $qp->connection;
38 $connection->notes('whitelisthost', $result)
39 unless $connection->notes('whitelisthost');
40 }
41
42 sub hook_rcpt {
43 my ($self, $transaction, $rcpt) = @_;
44 my $connection = $self->qp->connection;
45
46 if (my $note = $connection->notes('whitelisthost')) {
47 my $ip = $connection->remote_ip;
48 $self->log(LOGNOTICE, "Host $ip is whitelisted: $note");
49 }
50 return DECLINED;
51 }
52
53 =head1 NAME
54
55 dns_whitelist_soft - dns-based whitelist override for other qpsmtpd plugins
56
57 =head1 DESCRIPTION
58
59 The dns_whitelist_soft plugin allows selected host to be whitelisted as
60 exceptions to later plugin processing. It is most suitable for multisite
61 installations, so that the whitelist is stored in one location and available
62 from all.
63
64 =head1 CONFIGURATION
65
66 To enable the plugin, add it to the ~qpsmtpd/config/plugins file as usual.
67 It should precede any plugins whose rejections you wish to override. You may
68 have to alter those plugins to check the appropriate notes field.
69
70 Several configuration files are supported, corresponding to different
71 parts of the SMTP conversation:
72
73 =over 4
74
75 =item whitelist_zones
76
77 Any IP address listed in the whitelist_zones file is queried using
78 the connecting MTA's IP address. Any A or TXT answer means that the
79 remote HOST address can be selectively exempted at other stages by plugins
80 testing for a 'whitelisthost' connection note.
81
82 =back
83
84 NOTE: in contrast to the non-async version, the other 'connect' hooks
85 fired after the 'connect' hook of this plugin will see the 'whitelisthost'
86 connection note, if set by this plugin.
87
88 =cut