Hi,
        postgresql packages installed are shown below. These work with
 libdbd-pg-perl_1.32-2_i386. Now, if version 1.42-2 can't work with
 postgresql 7.x, why does it not conflict with that version? Or depend
 on the newer version of postgres?

        Lacking the conflict with the old, or dependency on the new,
 this upgrade breaks working installations.

        manoj

,----[ posgres version installed ]
|         
| 
| ii  postgresql             7.5.8          object-relational SQL database 
management system (transitional)
| ii  postgresql-7.4         7.4.8-14       object-relational SQL database, 
version 7.4 server
| ii  postgresql-autodoc     1.25-1         utility to create system tables 
overview in HTML, DOT and XML
| ii  postgresql-client      7.5.8          front-end programs for PostgreSQL 
(transitional package)
| ii  postgresql-client-7.4  7.4.8-14       front-end programs for PostgreSQL 
7.4
| ii  postgresql-common      23             manager for PostgreSQL database 
clusters
| ii  postgresql-contrib     7.5.8          additional facilities for 
PostgreSQL (transitional package)
| ii  postgresql-contrib-7.4 7.4.8-14       additional facilities for PostgreSQL
| ii  postgresql-doc         7.5.8          documentation for the PostgreSQL 
RDBMS (transitional package)
| ii  postgresql-doc-7.4     7.4.8-14       documentation for the PostgreSQL 
database management system
`----


,----[ Code that uses the DB ]
| 
| #our $greylist_dbname   = 'DBI:Pg:database=mimedefang';
| our $greylist_dbname   = 
'DBI:Pg:database=mimedefang;host=localhost;port=5432;';
| our $greylist_username = 'defang';
| our $greylist_password = 'PASSWD';
| 
| use DBI;
| use Date::Manip;
| 
| 
| # Initialize database used for greylisting
| sub init_db {
|   # code to bring up $dbh
|   # prep SQL handles, etc.
|   my $current_handle ;
|   eval {
|     $current_handle =
|       DBI->connect_cached($greylist_dbname,
|                           $greylist_username,
|                           $greylist_password,
|                           {
|                            PrintError => 0,
|                            RaiseError => 1,
|                            AutoCommit => 0
|                           })
|         or die $DBI::errstr;
|   };
|   if ($@) {
|     md_syslog('warning', "greylist: Could not connect to DB:$@");
|     return undef;
|   }
|   $dbh = $current_handle;
|   return $dbh;
| }
| 
| 
| my %SQL_Commands =
|   (
|    'Select' => qq{
| SELECT id, create_time,last_update,record_expires,block_expires,passed_count
| FROM triplets
| WHERE relay_ip=?
|   AND mail_from=?
|   AND rcpt_to=?;
| },
|    'Insert' => qq{
| INSERT INTO triplets (relay_ip,mail_from,rcpt_to,block_expires,record_expires,
|                       create_time,last_update)
| values (inet ?, ?, ?,
|         timestamp ? + interval ?,
|         timestamp ? + interval ?,
|         timestamp ?, timestamp ?);
| },
|    'Blocked' => qq {
| UPDATE triplets
| SET blocked_count=blocked_count+1, last_update=timestamp ?
| WHERE id=?;
| },
|    'Success' => qq {
| UPDATE triplets
| SET passed_count=passed_count+1,
|     record_expires=timestamp ? + interval ?,
|     last_update=timestamp ?
| WHERE id=?;
| },
|    'Old' => qq{
| UPDATE triplets
| SET blocked_count=blocked_count+1,
|     block_expires=timestamp  ? + interval ?,
|     record_expires=timestamp ? + interval ?,
|     last_update=timestamp ?
| WHERE id=?;
| },
|    'Reset' => qq{
| UPDATE triplets
| SET blocked_count=1,
|     block_expires=timestamp  ? + interval ?,
|     record_expires=timestamp ? + interval ?,
|     last_update=timestamp ?
| WHERE id=?;
| },
|    'Reset_IP' => qq{
| UPDATE triplets
| SET blocked_count=1,
|     block_expires=timestamp  ? + interval ?,
|     record_expires=timestamp ? + interval ?,
|     last_update=timestamp ?
| WHERE relay_ip=inet ?;
| },
|    'Whitelist' => qq {
| UPDATE triplets
| SET blocked_count=0, passed_count=1,
|     block_expires=timestamp  ?,
|     record_expires=timestamp ? + interval ?,
|     last_update=timestamp ?
| WHERE id=?;
| },
|   );
| 
| my %Handles;
| 
| # Checks if a triplet is in the grey-list.
| # Returns seconds until the triplet will be accepted, or -1 for error.
| sub greylist_check($$$) {
|   my ($ip,$sender,$recipient) = greylist_strip_triplet(@_);
|   my $result = -1;
| 
|   my $now = scalar localtime();
| 
|   my $ret = init_db() unless $dbh and $dbh->ping;
|   if (! defined $dbh) {
|     $result = 0;                # accept if we can't connect to the DB
|     $event = 'unknown';
|   }
|   elsif ($dbh) {
|     my $event = "";
|     my $safe_from = $dbh->quote($sender);
|     my $safe_to   = $dbh->quote($recipient);
| 
|     for my $sql (keys %SQL_Commands) {
|       $Handles{$sql} = $dbh->prepare($SQL_Commands{ $sql});
|     }
|     $Handles{Select}->execute($ip, $sender, $recipient);
| 
|     my ($rid,$create_time,$last_update,$record_expires,$block_expires,
|         $passed_count);
|     $Handles{Select}->bind_columns( undef, \$rid, \$create_time,
|                                      \$last_update, \$record_expires,
|                                      \$block_expires, \$passed_count );
| 
|     if (!$Handles{Select}->fetch()) {
|       # insert new row in database
|       $Handles{Select}->finish;
|       $Handles{Insert}->execute($ip, $sender, $recipient, $now,
|                                 "$greylist_black seconds", $now,
|                                 "$greylist_grey seconds", $now, $now);
|       $dbh->commit();
|       $result = $greylist_black;
|       $event = 'new';
|     }
|     else {
|       $Handles{Select}->finish;
|       if (Date_Cmp($now, $block_expires)   < 0 ) { #$now <= $block_expires
|         # At this point they are retrying under their blacklist window
|         $result = UnixDate($block_expires,"%s")-UnixDate($now,"%s");
|         $event = 'black';
|         #Log a note that they retried under our window
|         $Handles{Blocked}->execute($now, $rid);
|         $dbh->commit();
|         $Handles{Blocked}->finish;
|       }
|       elsif (Date_Cmp($now, $record_expires) < 0) { #$now <= $record_expires
|         # At this point they are retrying past the blacklist window,
|         # but inside their expiration window.
|         $result = 0;
|         $event = 'white';
| 
|         # Log a note that they retried sucessfully, and make sure they are
|         # updated to the whitelist window
|         $Handles{Success}->execute($now,"$greylist_white seconds", $now, 
$rid);
|         $dbh->commit();
|         $Handles{Success}->finish;
|       }
|       else {                  #$now > $record_expires
|         # At this point they are retrying past their expiration
|         $Handles{Old}->execute($now, "$greylist_black seconds", $now,
|                                "$greylist_grey seconds", $now, $rid);
|         $dbh->commit();
|         $Handles{Old}->finish;
|         $result = $greylist_black;
|         $event = 'old';
|       }
|     }
|   }
| 
|   md_syslog('info', "greylist: $event; $result; $ip; $sender; $recipient")
|     if $greylist_log;
| 
|   return $result;
| }
`----

-- 
Meade's Maxim: Always remember that you are absolutely unique, just
like everyone else.
Manoj Srivastava     <[EMAIL PROTECTED]>    <http://www.golden-gryphon.com/>
1024D/BF24424C print 4966 F272 D093 B493 410B  924B 21BA DABB BF24 424C


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to