Skip to content
This repository
Browse code

connection consistency

-  $self->qp->connection->notes
+  $self->connection->notes

and all tests pass.
  • Loading branch information...
commit 0a16621f024d078223159671129023cdded49d39 1 parent 9e239fd
Matt Simerson authored June 02, 2012
4  docs/advanced.pod
Source Rendered
@@ -69,8 +69,8 @@ should be configured to run I<last>, like B<rcpt_ok>.
69 69
       unless (($rc == DENY) and $self->{_count_relay_max});
70 70
 
71 71
    my $count = 
72  
-     ($self->qp->connection->notes('count_relay_attempts') || 0) + 1;
73  
-   $self->qp->connection->notes('count_relay_attempts', $count);
  72
+     ($self->connection->notes('count_relay_attempts') || 0) + 1;
  73
+   $self->connection->notes('count_relay_attempts', $count);
74 74
 
75 75
    return ($rc, @msg) unless ($count > $self->{_count_relay_max});
76 76
    return Qpsmtpd::DSN->relaying_denied(DENY_DISCONNECT, 
3  plugins/async/check_earlytalker
@@ -116,8 +116,7 @@ sub read_now {
116 116
 sub check_talker_post {
117 117
   my ($self, $transaction) = @_;
118 118
 
119  
-  my $conn = $self->qp->connection;
120  
-  return DECLINED unless $conn->notes('earlytalker');
  119
+  return DECLINED unless $self->connection->notes('earlytalker');
121 120
   return DECLINED if $self->{'defer-reject'};
122 121
   return (DENY,$MSG) if $self->{_args}->{'action'} eq 'deny';
123 122
   return (DENYSOFT,$MSG) if $self->{_args}->{'action'} eq 'denysoft';
8  plugins/async/dnsbl
@@ -64,21 +64,21 @@ sub process_a_result {
64 64
     my ($class, $qp, $result, $query) = @_;
65 65
 
66 66
     my $conn = $qp->connection;
67  
-    return if $conn->notes('dnsbl');
  67
+    return if $class->connection->notes('dnsbl');
68 68
 
69  
-    my $templates = $conn->notes('dnsbl_templates');
  69
+    my $templates = $class->connection->notes('dnsbl_templates');
70 70
     my $ip        = $conn->remote_ip;
71 71
 
72 72
     my $template = $templates->{$query};
73 73
     $template =~ s/%IP%/$ip/g;
74 74
 
75  
-    $conn->notes('dnsbl', $template);
  75
+    $class->connection->notes('dnsbl', $template);
76 76
 }
77 77
 
78 78
 sub process_txt_result {
79 79
     my ($class, $qp, $result, $query) = @_;
80 80
 
81  
-    my $conn = $qp->connection;
  81
+    my $conn = $class->connection;
82 82
     $conn->notes('dnsbl', $result) unless $conn->notes('dnsbl');
83 83
 }
84 84
 
4  plugins/async/require_resolvable_fromhost
@@ -27,7 +27,7 @@ sub hook_mail_start {
27 27
     my ( $self, $transaction, $sender ) = @_;
28 28
     
29 29
     return DECLINED
30  
-      if ( $self->qp->connection->notes('whitelisthost') );
  30
+      if ( $self->connection->notes('whitelisthost') );
31 31
 
32 32
     if ( $sender ne "<>" ) {
33 33
         
@@ -55,7 +55,7 @@ sub hook_mail_done {
55 55
     my ( $self, $transaction, $sender ) = @_;
56 56
     
57 57
     return DECLINED
58  
-      if ( $self->qp->connection->notes('whitelisthost') );
  58
+      if ( $self->connection->notes('whitelisthost') );
59 59
 
60 60
     if ( $sender ne "<>" && !$transaction->notes('resolvable_fromhost') ) {
61 61
         # default of temp_resolver_failed is DENYSOFT
2  plugins/check_basicheaders
@@ -165,7 +165,7 @@ sub is_immune {
165 165
         return 1;
166 166
     };
167 167
 
168  
-    if ( $self->qp->connection->notes('whitelisthost') ) {
  168
+    if ( $self->connection->notes('whitelisthost') ) {
169 169
         $self->log(LOGINFO, "skip: whitelisted host");
170 170
         return 1;
171 171
     };
14  plugins/check_earlytalker
@@ -106,7 +106,7 @@ sub apr_connect_handler {
106 106
     my ($self, $transaction) = @_;
107 107
 
108 108
     return DECLINED unless $self->{_args}{'check-at'}{CONNECT};
109  
-    return DECLINED if ($self->qp->connection->notes('whitelisthost'));
  109
+    return DECLINED if ($self->connection->notes('whitelisthost'));
110 110
     my $ip = $self->qp->connection->remote_ip;
111 111
 
112 112
     my $c = $self->qp->{conn};
@@ -117,7 +117,7 @@ sub apr_connect_handler {
117 117
     if ($rc == APR::Const::SUCCESS()) {
118 118
         $self->log(LOGNOTICE, "remote host started talking before we said hello [$ip]");
119 119
         if ($self->{_args}->{'defer-reject'}) {
120  
-            $self->qp->connection->notes('earlytalker', 1);
  120
+            $self->connection->notes('earlytalker', 1);
121 121
         }
122 122
         else {
123 123
             my $msg = 'Connecting host started transmitting before SMTP greeting';
@@ -134,7 +134,7 @@ sub apr_data_handler {
134 134
     my ($self, $transaction) = @_;
135 135
 
136 136
     return DECLINED unless $self->{_args}{'check-at'}{DATA};
137  
-    return DECLINED if ($self->qp->connection->notes('whitelisthost'));
  137
+    return DECLINED if ($self->connection->notes('whitelisthost'));
138 138
     my $ip = $self->qp->connection->remote_ip;
139 139
 
140 140
     my $c = $self->qp->{conn};
@@ -160,13 +160,13 @@ sub connect_handler {
160 160
 
161 161
   return DECLINED unless $self->{_args}{'check-at'}{CONNECT};
162 162
   return DECLINED
163  
-      if ($self->qp->connection->notes('whitelisthost'));
  163
+      if ($self->connection->notes('whitelisthost'));
164 164
 
165 165
   $in->add(\*STDIN) || return DECLINED;
166 166
   if ($in->can_read($self->{_args}->{'wait'})) {
167 167
     $self->log(LOGNOTICE, "remote host started talking before we said hello [$ip]");
168 168
     if ($self->{_args}->{'defer-reject'}) {
169  
-        $self->qp->connection->notes('earlytalker', 1);
  169
+        $self->connection->notes('earlytalker', 1);
170 170
     } else {
171 171
       my $msg = 'Connecting host started transmitting before SMTP greeting';
172 172
       return (DENY,$msg) if $self->{_args}->{'action'} eq 'deny';
@@ -185,7 +185,7 @@ sub data_handler {
185 185
 
186 186
   return DECLINED unless $self->{_args}{'check-at'}{DATA};
187 187
   return DECLINED
188  
-      if ($self->qp->connection->notes('whitelisthost'));
  188
+      if ($self->connection->notes('whitelisthost'));
189 189
 
190 190
   $in->add(\*STDIN) || return DECLINED;
191 191
   if ($in->can_read($self->{_args}->{'wait'})) {
@@ -204,7 +204,7 @@ sub mail_handler {
204 204
   my ($self, $transaction) = @_;
205 205
   my $msg = 'Connecting host started transmitting before SMTP greeting';
206 206
 
207  
-  return DECLINED unless $self->qp->connection->notes('earlytalker');
  207
+  return DECLINED unless $self->connection->notes('earlytalker');
208 208
   return (DENY,$msg) if $self->{_args}->{'action'} eq 'deny';
209 209
   return (DENYSOFT,$msg) if $self->{_args}->{'action'} eq 'denysoft';
210 210
   return DECLINED;
6  plugins/count_unrecognized_commands
@@ -34,7 +34,7 @@ sub register {
34 34
 sub hook_connect {
35 35
   my $self = shift;
36 36
 
37  
-  $self->qp->connection->notes('unrec_cmd_count', 0);
  37
+  $self->connection->notes('unrec_cmd_count', 0);
38 38
   return DECLINED;
39 39
 }
40 40
 
@@ -44,8 +44,8 @@ sub hook_unrecognized_command {
44 44
   $self->log(LOGINFO, "Unrecognized command '$cmd'");
45 45
 
46 46
   my $badcmdcount = 
47  
-    $self->qp->connection->notes( 'unrec_cmd_count',
48  
-        ($self->qp->connection->notes('unrec_cmd_count') || 0) + 1
  47
+    $self->connection->notes( 'unrec_cmd_count',
  48
+        ($self->connection->notes('unrec_cmd_count') || 0) + 1
49 49
     );
50 50
 
51 51
   if ($badcmdcount >= $self->{_unrec_cmd_max}) {
4  plugins/dns_whitelist_soft
@@ -71,7 +71,7 @@ sub hook_connect {
71 71
     $sel->add($res->bgsend("$reversed_ip.$dnsbl", "TXT"));
72 72
   }
73 73
 
74  
-  $self->qp->connection->notes('whitelist_sockets', $sel);
  74
+  $self->connection->notes('whitelist_sockets', $sel);
75 75
 
76 76
   return DECLINED;
77 77
 }
@@ -79,7 +79,7 @@ sub hook_connect {
79 79
 sub process_sockets {
80 80
   my ($self) = @_;
81 81
 
82  
-  my $conn = $self->qp->connection;
  82
+  my $conn = $self->connection;
83 83
 
84 84
   return $conn->notes('whitelisthost') 
85 85
     if $conn->notes('whitelisthost');
12  plugins/dnsbl
@@ -170,8 +170,8 @@ sub hook_connect {
170 170
     }
171 171
   }
172 172
 
173  
-  $self->qp->connection->notes('dnsbl_sockets', $sel);
174  
-  $self->qp->connection->notes('dnsbl_domains', $dom);
  173
+  $self->connection->notes('dnsbl_sockets', $sel);
  174
+  $self->connection->notes('dnsbl_domains', $dom);
175 175
 
176 176
   return DECLINED;
177 177
 }
@@ -199,7 +199,7 @@ sub ip_whitelisted {
199 199
     my ($self) = @_;
200 200
 
201 201
     my $remote_ip = $self->qp->connection->remote_ip;
202  
-    my $white = $self->qp->connection->notes('whitelisthost');
  202
+    my $white = $self->connection->notes('whitelisthost');
203 203
     if ( $white ) {
204 204
         $self->log(LOGDEBUG, "skip: whitelist overrode blacklist: $white");
205 205
         return 1;
@@ -219,7 +219,7 @@ sub ip_whitelisted {
219 219
 sub process_sockets {
220 220
   my ($self) = @_;
221 221
 
222  
-  my $conn = $self->qp->connection;
  222
+  my $conn = $self->connection;
223 223
 
224 224
   return $conn->notes('dnsbl') if $conn->notes('dnsbl');
225 225
 
@@ -334,13 +334,15 @@ sub hook_rcpt {
334 334
 sub hook_disconnect {
335 335
   my ($self, $transaction) = @_;
336 336
 
337  
-  $self->qp->connection->notes('dnsbl_sockets', undef);
  337
+  $self->connection->notes('dnsbl_sockets', undef);
338 338
 
339 339
   return DECLINED;
340 340
 }
341 341
 
342 342
 sub get_reject_type {
343 343
     my $self = shift;
  344
+    my $default = shift || DENY;
  345
+    my $deny = $self->{_args}{reject_type} or return $default;
344 346
 
345 347
     return   $self->{_args}{reject_type} eq 'temp'       ? DENYSOFT
346 348
            : $self->{_args}{reject_type} eq 'disconnect' ? DENY_DISCONNECT
2  plugins/greylisting
@@ -324,7 +324,7 @@ sub is_immune {
324 324
         $self->log(LOGINFO, "skip: relay client");
325 325
         return 1;
326 326
     };
327  
-    if ( $self->qp->connection->notes('whitelisthost') ) {
  327
+    if ( $self->connection->notes('whitelisthost') ) {
328 328
         $self->log(LOGINFO, "skip: whitelisted host");
329 329
         return 1;
330 330
     };
4  plugins/ident/geoip
@@ -46,10 +46,10 @@ sub connect_handler {
46 46
 
47 47
     my $c_name = $geoip->country_name_by_addr( $remote_ip );
48 48
     if ( $c_name ) {
49  
-        $self->qp->connection->notes('geoip_country_name', $c_name);
  49
+        $self->connection->notes('geoip_country_name', $c_name);
50 50
     };
51 51
 
52  
-    $self->qp->connection->notes('geoip_country', $c_code);
  52
+    $self->connection->notes('geoip_country', $c_code);
53 53
 
54 54
     my $message  = $c_code;
55 55
        $message .= ", $c_name" if $c_name;
4  plugins/ident/p0f
@@ -328,7 +328,7 @@ sub store_v2_results {
328 328
         uptime   => $uptime,
329 329
     };
330 330
 
331  
-    $self->qp->connection->notes('p0f', $p0f);
  331
+    $self->connection->notes('p0f', $p0f);
332 332
     $self->log(LOGINFO, $genre." (".$detail.")");
333 333
     $self->log(LOGERROR,"error: $@") if $@;
334 334
     return $p0f;
@@ -354,7 +354,7 @@ sub store_v3_results {
354 354
         $r{uptime} = $r{uptime_min} if $r{uptime_min};
355 355
     };
356 356
 
357  
-    $self->qp->connection->notes('p0f', \%r);
  357
+    $self->connection->notes('p0f', \%r);
358 358
     $self->log(LOGINFO, "$r{os_name} $r{os_flavor}");
359 359
     $self->log(LOGDEBUG, join(' ', @values ));
360 360
     $self->log(LOGERROR,"error: $@") if $@;
22  plugins/milter
@@ -49,11 +49,11 @@ sub register {
49 49
 sub hook_disconnect {
50 50
     my ($self) = @_;
51 51
 
52  
-    my $milter = $self->qp->connection->notes('milter') || return DECLINED;
  52
+    my $milter = $self->connection->notes('milter') || return DECLINED;
53 53
     $milter->send_quit();
54 54
     
55  
-    $self->qp->connection->notes('spam', undef);
56  
-    $self->qp->connection->notes('milter', undef);
  55
+    $self->connection->notes('spam', undef);
  56
+    $self->connection->notes('milter', undef);
57 57
 
58 58
     return DECLINED;
59 59
 }
@@ -97,9 +97,9 @@ sub hook_connect {
97 97
     $milter->open($self->{host}, $self->{port}, 'tcp');
98 98
     $milter->protocol_negotiation();
99 99
 
100  
-    $self->qp->connection->notes(milter => $milter);
  100
+    $self->connection->notes(milter => $milter);
101 101
 
102  
-    $self->qp->connection->notes(
  102
+    $self->connection->notes(
103 103
         milter_header_changes => { add => [], delete => [], replace => [], }
104 104
     );    
105 105
     my $remote_ip = $self->qp->connection->remote_ip;
@@ -110,7 +110,7 @@ sub hook_connect {
110 110
         $self->check_results($transaction, "connection",
111 111
             $milter->send_connect($remote_host, 'tcp4', 0, $remote_ip));
112 112
     };
113  
-    $self->qp->connection->notes('spam', $@) if $@;
  113
+    $self->connection->notes('spam', $@) if $@;
114 114
 
115 115
     return DECLINED;
116 116
 }
@@ -118,11 +118,11 @@ sub hook_connect {
118 118
 sub hook_helo {
119 119
     my ($self, $transaction) = @_;
120 120
 
121  
-    if (my $txt = $self->qp->connection->notes('spam')) {
  121
+    if (my $txt = $self->connection->notes('spam')) {
122 122
         return DENY, $txt;
123 123
     }
124 124
     
125  
-    my $milter = $self->qp->connection->notes('milter');
  125
+    my $milter = $self->connection->notes('milter');
126 126
     
127 127
     my $helo = $self->qp->connection->hello;
128 128
     my $host = $self->qp->connection->hello_host;
@@ -139,7 +139,7 @@ sub hook_helo {
139 139
 sub hook_mail {
140 140
     my ($self, $transaction, $address, %param) = @_;
141 141
     
142  
-    my $milter = $self->qp->connection->notes('milter');
  142
+    my $milter = $self->connection->notes('milter');
143 143
 
144 144
     $self->log(LOGDEBUG, "milter $self->{name} checking MAIL FROM " . $address->format);
145 145
     eval { $self->check_results($transaction, "MAIL FROM",
@@ -152,7 +152,7 @@ sub hook_mail {
152 152
 sub hook_rcpt {
153 153
     my ($self, $transaction, $address, %param) = @_;
154 154
     
155  
-    my $milter = $self->qp->connection->notes('milter');
  155
+    my $milter = $self->connection->notes('milter');
156 156
 
157 157
     $self->log(LOGDEBUG, "milter $self->{name} checking RCPT TO " . $address->format);
158 158
 
@@ -166,7 +166,7 @@ sub hook_rcpt {
166 166
 sub hook_data_post {
167 167
     my ($self, $transaction) = @_;
168 168
 
169  
-    my $milter = $self->qp->connection->notes('milter');
  169
+    my $milter = $self->connection->notes('milter');
170 170
 
171 171
     $self->log(LOGDEBUG, "milter $self->{name} checking headers");
172 172
 
6  plugins/random_error
@@ -16,7 +16,7 @@ of messages.  The default is 1. Use a negative number to disable.
16 16
 
17 17
 For use with other plugins, scribble the revised failure rate to
18 18
 
19  
-   $self->qp->connection->notes('random_fail_%');
  19
+   $self->connection->notes('random_fail_%');
20 20
 
21 21
 =cut
22 22
 
@@ -31,7 +31,7 @@ sub register {
31 31
 sub NEXT() { DECLINED }
32 32
 
33 33
 sub random_fail {
34  
-        my $fpct = $_[0]->qp->connection->notes('random_fail_%');
  34
+        my $fpct = $_[0]->connection->notes('random_fail_%');
35 35
 
36 36
 =head1 calculating the probability of failure
37 37
 
@@ -55,7 +55,7 @@ or
55 55
 
56 56
 
57 57
 sub hook_connect {
58  
-    $_[0]->qp->connection->notes('random_fail_%', $_[0]->{__PACKAGE__.'_how'});
  58
+    $_[0]->connection->notes('random_fail_%', $_[0]->{__PACKAGE__.'_how'});
59 59
     goto &random_fail
60 60
 }
61 61
 
3  plugins/require_resolvable_fromhost
@@ -11,8 +11,7 @@ my $has_ipv6 = Qpsmtpd::TcpServer::has_ipv6();
11 11
 sub hook_mail {
12 12
   my ($self, $transaction, $sender, %param) = @_;
13 13
 
14  
-  return DECLINED
15  
-        if ($self->qp->connection->notes('whitelisthost'));
  14
+  return DECLINED if $self->connection->notes('whitelisthost');
16 15
 
17 16
   foreach my $i ($self->qp->config("invalid_resolvable_fromhost")) {
18 17
     $i =~ s/^\s*//;
4  plugins/tls
@@ -305,8 +305,8 @@ sub event_read {
305 305
     if (defined $sock) {
306 306
         $qp->connection( $qp->connection->clone );
307 307
         $qp->reset_transaction;
308  
-        $qp->connection->notes('tls_socket', $sock);
309  
-        $qp->connection->notes('tls_enabled', 1);
  308
+        $self->connection->notes('tls_socket', $sock);
  309
+        $self->connection->notes('tls_enabled', 1);
310 310
         $qp->watch_read(1);
311 311
         return 1;
312 312
     }
6  t/plugin_tests/count_unrecognized_commands
@@ -15,17 +15,17 @@ sub test_hook_unrecognized_command {
15 15
     my $self = shift;
16 16
 
17 17
     $self->{_unrec_cmd_max} = 2;
18  
-    $self->qp->connection->notes( 'unrec_cmd_count', 0 );
  18
+    $self->connection->notes( 'unrec_cmd_count', 0 );
19 19
 
20 20
     my ($code, $mess) = $self->hook_unrecognized_command(undef,'hiya');
21 21
     cmp_ok( $code, '==', DECLINED, "good" );
22 22
 
23  
-    $self->qp->connection->notes( 'unrec_cmd_count', 2 );
  23
+    $self->connection->notes( 'unrec_cmd_count', 2 );
24 24
     ($code, $mess) = $self->hook_unrecognized_command(undef,'snookums');
25 25
     cmp_ok( $code, '==', DENY_DISCONNECT, "limit" );
26 26
 
27 27
     ($code, $mess) = $self->hook_unrecognized_command(undef,'wtf');
28 28
     cmp_ok( $code, '==', DENY_DISCONNECT, "over limit" );
29 29
 
30  
-    cmp_ok( $self->qp->connection->notes( 'unrec_cmd_count'), '==', 4, "correct increment" );
  30
+    cmp_ok( $self->connection->notes( 'unrec_cmd_count'), '==', 4, "correct increment" );
31 31
 };
14  t/plugin_tests/dnsbl
@@ -27,9 +27,9 @@ sub test_ip_whitelisted {
27 27
     $self->qp->connection->relay_client(0);
28 28
     ok( ! $self->ip_whitelisted('10.1.1.1'), "no, -");
29 29
 
30  
-    $self->qp->connection->notes('whitelisthost', 'hello honey!');
  30
+    $self->connection->notes('whitelisthost', 'hello honey!');
31 31
     ok( $self->ip_whitelisted('10.1.1.1'), "yes, +");
32  
-    $self->qp->connection->notes('whitelisthost', undef);
  32
+    $self->connection->notes('whitelisthost', undef);
33 33
 };
34 34
 
35 35
 sub test_is_set_rblsmtpd {
@@ -51,15 +51,15 @@ sub test_is_set_rblsmtpd {
51 51
 sub test_hook_connect {
52 52
     my $self = shift;
53 53
 
54  
-    my $connection = $self->qp->connection;
55  
-    $connection->relay_client(0);        # other tests may leave it enabled
56  
-    $connection->remote_ip('127.0.0.2'); # standard dnsbl test value
  54
+    my $conn = $self->qp->connection;
  55
+    $conn->relay_client(0);        # other tests may leave it enabled
  56
+    $conn->remote_ip('127.0.0.2'); # standard dnsbl test value
57 57
 
58 58
     cmp_ok( DECLINED, '==', $self->hook_connect($self->qp->transaction),
59 59
         "connect +");
60 60
 
61  
-    ok($connection->notes('dnsbl_sockets'), "sockets +");
62  
-    ok($connection->notes('dnsbl_domains'), "domains +");
  61
+    ok($self->connection->notes('dnsbl_sockets'), "sockets +");
  62
+    ok($self->connection->notes('dnsbl_domains'), "domains +");
63 63
 }
64 64
 
65 65
 sub test_hook_rcpt {
6  t/plugin_tests/greylisting
@@ -63,9 +63,9 @@ sub test_is_immune {
63 63
     ok( ! $self->is_immune(), "nope -" );
64 64
 
65 65
     foreach ( qw/ whitelisthost / ) {
66  
-        $self->qp->connection->notes($_, 1);
  66
+        $self->connection->notes($_, 1);
67 67
         ok( $self->is_immune(), $_);
68  
-        $self->qp->connection->notes($_, undef);
  68
+        $self->connection->notes($_, undef);
69 69
     };
70 70
 
71 71
     foreach ( qw/ whitelistsender tls_enabled / ) {
@@ -186,7 +186,7 @@ sub _reset_transaction {
186 186
 
187 187
     $self->qp->connection->relay_client(0);
188 188
     $self->qp->transaction->notes('whitelistsender',0);
189  
-    $self->qp->connection->notes('whitelisthost',0);
  189
+    $self->connection->notes('whitelisthost',0);
190 190
     $self->qp->transaction->notes('tls_enabled',0);
191 191
     $self->{_args}{p0f} = undef;
192 192
     $self->{_args}{geoip} = undef;
2  t/plugin_tests/ident/geoip
@@ -23,7 +23,7 @@ sub test_geoip_lookup {
23 23
     $self->qp->connection->remote_ip('24.24.24.24');
24 24
     cmp_ok( $self->connect_handler(), '==', DECLINED, "exit code");
25 25
 
26  
-    cmp_ok( $self->qp->connection->notes('geoip_country'), 'eq', 'US', "note");
  26
+    cmp_ok( $self->connection->notes('geoip_country'), 'eq', 'US', "note");
27 27
 };
28 28
 
29 29
 

0 notes on commit 0a16621

Please sign in to comment.
Something went wrong with that request. Please try again.