Bug 2146 - Overriding globals when using SQL database
Summary: Overriding globals when using SQL database
Status: RESOLVED WONTFIX
Alias: None
Product: Spamassassin
Classification: Unclassified
Component: Libraries (show other bugs)
Version: 2.55
Hardware: All Linux
: P5 enhancement
Target Milestone: 3.0.0
Assignee: SpamAssassin Developer Mailing List
URL:
Whiteboard:
Keywords:
Depends on: 1908
Blocks:
  Show dependency tree
 
Reported: 2003-06-28 12:33 UTC by Uros Gaber
Modified: 2004-02-28 05:01 UTC (History)
0 users



Attachment Type Modified Status Actions Submitter/CLA Status
patch for described enhancement patch None Uros Gaber [NoCLA]

Note You need to log in before you can comment on or make changes to this bug.
Description Uros Gaber 2003-06-28 12:33:43 UTC
When using SQL database for user preferences @GLOBAL will by default override 
user specified settings.
With this patch you can choose if you wish to override @GLOBALs with user 
settings or vice-versa.
So when the globals_override are active then the prefs lookup will be first 
executed with username and then if the users prefs will not be found then the 
@GLOBALs will be searched. Buf by default first @GLOBALs will be searchs and 
if not found then prefs will be searched by username.

While applying this patch you have an extra directive in config file 
(i.e. /etc/mail/spamassassin/local.cf):
globals_override { 0 | 1 } default is 0

----- patch file -----
*** Conf.pm.original	Sat Jun 28 21:12:09 2003
--- Conf.pm	Sat Jun 28 21:12:21 2003
***************
*** 110,115 ****
--- 110,117 ----
    $self->{terse_report_template} = '';
    $self->{spamtrap_template} = '';
  
+   $self->{globals_override} = '';
+ 
    # What different RBLs consider a dialup IP -- Marc
    $self->{dialup_codes} = { 
  			    "dialups.mail-abuse.org." => "127.0.0.3",
***************
*** 509,514 ****
--- 511,528 ----
        $self->{required_hits} = $1+0.0; next;
      }
  
+ =item globals_override { 0 | 1 }        (default: 0)
+ 
+ By default, the GLOBAL prefs override users prefs.
+ If you enable this directive then users prefs will override GLOBAL prefs.
+ 
+ =cut
+ 
+     if (/^globals_override\s+(\d+)$/) {
+       $self->{globals_override} = $1+0; next;
+     }
+ 
+ 
  =item score SYMBOLIC_TEST_NAME n.nn [ n.nn n.nn n.nn ]
  
  Assign scores (the number of points for a hit) to a given test. Scores can
*** ConfSourceSQL.pm.original	Sat Jun 28 21:12:17 2003
--- ConfSourceSQL.pm	Sat Jun 28 21:12:21 2003
***************
*** 103,131 ****
     my $dbh = DBI->connect($dsn, $dbuser, $dbpass, {'PrintError' => 0});
  
     if($dbh) {
!       my $sql = "select $f_preference, $f_value  from $f_table where ". 
!         "$f_username = ".$dbh->quote($username).
!         " or $f_username = 'GLOBAL'".
!         " or $f_username = '\@GLOBAL' order by $f_username asc";
! 
!       my $sth = $dbh->prepare($sql);
!       if($sth) {
!          my $rv  = $sth->execute();
!          if($rv) {
!             dbg("retrieving prefs for $username from SQL server");
!             my @row;
!             my $text = '';
!             while(@row = $sth->fetchrow_array()) {
!                $text .= "$row[0]\t$row[1]\n";
!             }
!             if($text ne '') {
!             	$main->{conf}->parse_scores_only(join('',$text));
!             }
!             $sth->finish();
!          } else { warn "SQL Error: $sql\n".$sth->errstr."\n"; }
!       } else { warn "SQL Error: " . $dbh->errstr . "\n"; }
!    $dbh->disconnect();
!    } else { warn "SQL Error: " . DBI->errstr . "\n"; }
  }
  
  ###########################################################################
--- 103,156 ----
     my $dbh = DBI->connect($dsn, $dbuser, $dbpass, {'PrintError' => 0});
  
     if($dbh) {
!       my $sql_first = "";
!       my $sql_second = "";
!       if ($main->{conf}->{globals_override} == 1) {
!         $sql_first = "select $f_preference, $f_value from $f_table where ".
!                      "$f_username = ".$dbh->quote($username);
!         $sql_second = "select $f_preference, $f_value from $f_table where ".
!                       "$f_username = '\@GLOBAL' ".
!                       "or $f_username = 'GLOBAL'";
!       } else {
!         $sql_first = "select $f_preference, $f_value from $f_table where ".
!                      "$f_username = '\@GLOBAL' ".
!                      "or $f_username = 'GLOBAL'";
!         $sql_second = "select $f_preference, $f_value from $f_table where ".
!                       "$f_username = ".$dbh->quote($username);
!       }
!       dbg("trying to retreive 1st prefs");
!       my $sth = $dbh->prepare($sql_first);
!       if ($sth) {
!         my $rv = $sth->execute();
!         if ($sth->rows <= 0) {
!           dbg("1st prefs were not found, let's try to 2nd prefs");
!           $sth->finish;
!           $sth = $dbh->prepare($sql_second);
!           if ($sth) {
!             $rv = $sth->execute();
!           }
!         }
!         if($rv) {
!           dbg("retrieving prefs for $username from SQL server");
!           my @row;
!           my $text = '';
!           while(@row = $sth->fetchrow_array()) {
!              $text .= "$row[0]\t$row[1]\n";
!           }
!           if($text ne '') {
!             $main->{conf}->parse_scores_only(join('',$text));
!           }
!           $sth->finish();
!       } else { 
!         warn "SQL Error: ".$sth->errstr."\n"; 
!       }
!     } else { 
!       warn "SQL Error: " . $dbh->errstr . "\n"; 
!     }
!     $dbh->disconnect();
!    } else { 
!      warn "SQL Error: " . DBI->errstr . "\n"; 
!    }
  }
  
  ########################################################################### 
----- end of patch file -----
Comment 1 Daniel Quinlan 2003-06-28 12:51:48 UTC
Please attach the patch instead of cut-and-paste.  Use the "Create a New
Attachment" link on this page.

Also, please use unified diffs ("diff -u").
Comment 2 Uros Gaber 2003-06-28 13:03:04 UTC
Created attachment 1104 [details]
patch for described enhancement
Comment 3 Justin Mason 2004-02-28 14:01:17 UTC
more correctly, bug 1908 will simply fix this.   Globals should always be
overridden by user prefs, there's no need for a setting.