View | Details | Raw Unified | Return to bug 1222
Collapse All | Expand All

(-)Mail-SpamAssassin-2.43.stock/lib/Mail/SpamAssassin/ConfSourceSQL.pm (-6 / +9 lines)
Lines 50-68 Link Here
50
   my $dsn = $self->{main}->{conf}->{user_scores_dsn};
50
   my $dsn = $self->{main}->{conf}->{user_scores_dsn};
51
   if(!defined($dsn) || $dsn eq '') {
51
   if(!defined($dsn) || $dsn eq '') {
52
     dbg ("No DSN defined; skipping sql");
52
     dbg ("No DSN defined; skipping sql");
53
     return;
53
     return 1;
54
   }
54
   }
55
55
56
   eval {
56
   eval {
57
     # make sure we can see croak messages from DBI
57
     # make sure we can see croak messages from DBI
58
     local $SIG{'__DIE__'} = sub { warn "$_[0]"; };
58
     local $SIG{'__DIE__'} = sub { die "$_[0]"; };
59
     require DBI;
59
     require DBI;
60
     load_with_dbi($self, $username, $dsn);
60
     load_with_dbi($self, $username, $dsn);
61
   };
61
   };
62
62
63
   if ($@) {
63
   if ($@) {
64
     warn "failed to load user scores from SQL database, ignored\n";
64
     warn "failed to load user scores from SQL database: $@\n";
65
     return 0;
65
   }
66
   }
67
68
   return 1;
66
}
69
}
67
70
68
sub load_with_dbi {
71
sub load_with_dbi {
Lines 95-104 Link Here
95
            	$main->{conf}->parse_scores_only(join('',$text));
98
            	$main->{conf}->parse_scores_only(join('',$text));
96
            }
99
            }
97
            $sth->finish();
100
            $sth->finish();
98
         } else { warn "SQL Error: $sql\n".$sth->errstr."\n"; }
101
         } else { die "SQL Error: $sql\n".$sth->errstr."\n"; }
99
      } else { warn "SQL Error: " . $dbh->errstr . "\n"; }
102
      } else { die "SQL Error: " . $dbh->errstr . "\n"; }
100
   $dbh->disconnect();
103
   $dbh->disconnect();
101
   } else { warn "SQL Error: " . DBI->errstr . "\n"; }
104
   } else { die "SQL Error: " . DBI->errstr . "\n"; }
102
}
105
}
103
106
104
sub dbg { Mail::SpamAssassin::dbg (@_); }
107
sub dbg { Mail::SpamAssassin::dbg (@_); }
(-)Mail-SpamAssassin-2.43.stock/lib/Mail/SpamAssassin.pm (-1 / +5 lines)
Lines 597-603 Link Here
597
  my ($self, $username) = @_;
597
  my ($self, $username) = @_;
598
598
599
  my $src = Mail::SpamAssassin::ConfSourceSQL->new ($self);
599
  my $src = Mail::SpamAssassin::ConfSourceSQL->new ($self);
600
  $src->load($username);
600
  if (!$src->load($username)) {
601
    return 0;
602
  }
603
604
  return 1;
601
}
605
}
602
606
603
607
(-)Mail-SpamAssassin-2.43.stock/spamd/spamd.raw (-30 / +55 lines)
Lines 337-361 Link Here
337
                    # We'll run handle user unless we've been told not
337
                    # We'll run handle user unless we've been told not
338
                    # to process per-user config files.  Otherwise
338
                    # to process per-user config files.  Otherwise
339
                    # we'll check and see if we need to try SQL
339
                    # we'll check and see if we need to try SQL
340
                    # lookups.  If $opt{'user-config'} is true, we need to try
340
                    # lookups. If $opt{'user-config'} IS NOT true, we
341
                    # their config file and then do the SQL lookup.
341
                    # skip the conf file and only need to do the SQL
342
                    # If $opt{'user-config'} IS NOT true, we skip the conf file and
342
                    # lookup if $opt{'sql-config'} IS true.  (I got that
343
                    # only need to do the SQL lookup if $opt{'sql-config'} IS
343
                    # wrong the first time.)
344
                    # true.  (I got that wrong the first time.)
345
344
346
                    if (/^User: (.*)\r\n/)
345
                    if (/^User: (.*)\r\n/)
347
                    {
346
                    {
348
                        $current_user = $1;
347
                        $current_user = $1;
349
                        if (!$opt{'user-config'})
348
                        if (!$opt{'user-config'})
350
                        {
349
                        {
351
			               if ($opt{'sql-config'}) {
350
                            if ($opt{'sql-config'}) {
352
				              handle_user_sql($current_user);
351
                                if (!handle_user_sql($current_user)) {
353
			               } elsif ($opt{'virtual-config'}) {
352
                                    if ($method eq 'REPORT_IFSPAM') {
354
				              handle_virtual_user($current_user);
353
                                        print 'SPAMD/1.1 ' . $resphash{'EX_OK'} . " EX_OK\r\n"
355
			               }
354
                                              . 'X-Spam-Status: No, hits=0.0 required=0.0 tests='
356
                        }
355
                                              . ' version=' . Mail::SpamAssassin::Version()
357
               			else
356
                                              . "\r\n\r\n";
358
                        {
357
                                    }
358
                                    else
359
                                    {
360
                                        print 'SPAMD/1.1 ' . $resphash{'EX_OK'}  . " EX_OK\r\n"
361
                                              . "Spam: False ; 0.0 / 0.0\r\n\r\n";
362
                                    }
363
                                    exit;
364
                                }
365
                            } elsif ($opt{'virtual-config'}) {
366
                                handle_virtual_user($current_user);
367
                            }
368
                        } else {
359
                            handle_user($current_user);
369
                            handle_user($current_user);
360
                        }
370
                        }
361
                    }
371
                    }
Lines 480-505 Link Here
480
490
481
                    # We'll run handle user unless we've been told not
491
                    # We'll run handle user unless we've been told not
482
                    # to process per-user config files.  Otherwise
492
                    # to process per-user config files.  Otherwise
483
                    # we'll check and see if we need to try SQL
493
                    # we'll (later) check and see if we need to try SQL
484
                    # lookups.  If $opt{'user-config'} is true, we need to try
494
                    # lookups. If $opt{'user-config'} IS NOT true, we skip
485
                    # their config file and then do the SQL lookup.
495
                    # the conf file and only need to do the SQL lookup if
486
                    # If $opt{'user-config'} IS NOT true, we skip the conf file and
496
                    # $opt{'sql-config'} IS true.  (I got that wrong the
487
                    # only need to do the SQL lookup if $opt{'sql-config'} IS
497
                    # first time.)
488
                    # true.  (I got that wrong the first time.)
489
498
490
                    if (/^User: (.*)\r\n/)
499
                    if (/^User: (.*)\r\n/)
491
                    {
500
                    {
492
                        $current_user = $1;
501
                        $current_user = $1;
493
                        if (!$opt{'user-config'})
502
                        if ($opt{'user-config'}) {
494
                        {
495
			    if ($opt{'sql-config'}) {
496
				handle_user_sql($current_user);
497
			    } elsif ($opt{'virtual-config'}) {
498
				handle_virtual_user($current_user);
499
			    }
500
                        }
501
			else
502
                        {
503
                            handle_user($current_user);
503
                            handle_user($current_user);
504
                        }
504
                        }
505
                    }
505
                    }
Lines 562-567 Link Here
562
		if($actual_length != $expected_length) { protocol_error ("(Content-length mismatch: $expected_length vs. $actual_length)"); return 1; }
562
		if($actual_length != $expected_length) { protocol_error ("(Content-length mismatch: $expected_length vs. $actual_length)"); return 1; }
563
	    }
563
	    }
564
564
565
            if (!$opt{'user-config'}) {
566
                if ($opt{'sql-config'}) {
567
                    if (!handle_user_sql($current_user)) {
568
                        my $msg_resp = join '',$mail->header,"\n",@{$mail->body};
569
                        my $msg_resp_length = length($msg_resp);
570
                        if($version >= 1.2) # Spamc protocol 1.2 means it accepts content-length
571
                        {
572
                            print "SPAMD/1.1 $resphash{$resp} $resp\r\n",
573
                                  "Content-length: $msg_resp_length\r\n\r\n",
574
                                  $msg_resp;
575
                        }
576
                        else # Earlier than 1.2 didn't accept content-length
577
                        {
578
                            print "SPAMD/1.0 $resphash{$resp} $resp\r\n",
579
                                  $msg_resp;
580
                        }
581
                        exit;
582
                    }
583
                } elsif ($opt{'virtual-config'}) {
584
                    handle_virtual_user($current_user);
585
                }
586
            }
587
565
	    # Now use copy-on-writed (hopefully) SA object
588
	    # Now use copy-on-writed (hopefully) SA object
566
	    my $status = $spamtest->check($mail);
589
	    my $status = $spamtest->check($mail);
567
	    $status->rewrite_mail; #if $status->is_spam;
590
	    $status->rewrite_mail; #if $status->is_spam;
Lines 738-744 Link Here
738
sub handle_user_sql
761
sub handle_user_sql
739
{
762
{
740
    my $username = shift;
763
    my $username = shift;
741
    $spamtest->load_scoreonly_sql ($username);
764
    if (!$spamtest->load_scoreonly_sql ($username)) {
765
        return 0;
766
    }
742
    return 1;
767
    return 1;
743
}
768
}
744
769
(-)Mail-SpamAssassin-2.43.stock/sql/README (-4 / +8 lines)
Lines 33-44 Link Here
33
Would tell SpamAssassin to connect to the database named spamassassin using
33
Would tell SpamAssassin to connect to the database named spamassassin using
34
MySQL on the local server, and since <port> is omitted, the driver will use the
34
MySQL on the local server, and since <port> is omitted, the driver will use the
35
default port number.  The other two required options tells SpamAssassin to use 
35
default port number.  The other two required options tells SpamAssassin to use 
36
the defined username and password to establish the connection.
36
the defined username and password to establish the connection. Note that this
37
will NOT look for test rules, only local scores, whitelist_from(s),
38
required_hits, and auto_report_threshold.
37
39
38
If the user_scores_dsn option does not exist, SpamAssassin will not attempt
40
If the user_scores_dsn option does not exist, SpamAssassin will not attempt
39
to use an SQL for retrieving users' preferences. Note that this will NOT look
41
to use an SQL for retrieving users' preferences.
40
for test rules, only local scores, whitelist_from(s), required_hits, and
42
41
auto_report_threshold.
43
If spamd can't connect using user_scores_dsn, or an error occurs when
44
querying the SQL server during message filtering, spam checking will not be
45
performed on that message.
42
46
43
Requirements
47
Requirements
44
------------
48
------------

Return to bug 1222