Package: debconf
Version: 1.5.23
Severity: minor
Tags: patch

Hello,

Attached is a simple patch for the LDAP Db driver that does the
following:

1) Improve error reporting from LDAP driver:

 - Print the DN of the LDAP entry that had an error,
 - Correctly report whether Modify or Add action failed
   (previous code was always reporting that Modify failed).

2) Replace $entry_cn variable with $key for more uniform 
   look (cosmetic change).

3) Make search errors in KeyByKey mode non-fatal.
   (A search error normally indicates a non-recoverable problem, but
   in KeyByKey mode where entries are accessed individually, it is
   normal and completely expected case that some of the specific
   searched entries are not found).

Regards,
Davor Ocelic
Spinlock Solutions
http://www.spinlocksolutions.com/
--- debconf-1.5.23/Debconf/DbDriver/LDAP.pm     2008-04-28 23:41:47.000000000 
+0200
+++ /tmp/LDAP2.pm       2008-08-15 14:03:12.000000000 +0200
@@ -153,9 +153,10 @@
        }
        else {
                debug "db $this->{name}" => "getting database data";
-               my $data = $this->{ds}->search(base => $this->{basedn}, 
sizelimit => 0, timelimit => 0, filter => "(objectclass=debconfDbEntry)");
+               my $base = $this->{basedn};
+               my $data = $this->{ds}->search(base => $base, sizelimit => 0, 
timelimit => 0, filter => "(objectclass=debconfDbEntry)");
                if ($data->code) {
-                       $this->error("Search failed: ".$data->error);
+                       $this->error("Search failed for $base: ".$data->error);
                }
                        
                my $records = $data->as_struct();
@@ -256,17 +257,20 @@
                }
                
                my $rv="";
+               my $op;
                if ($this->{exists}->{$item}) {
+                       $op = 'Modify';
                        $rv = $this->{ds}->modify($entry_dn, replace => 
\%modify_data);
                } else {
+                       $op = 'Add';
                        $rv = $this->{ds}->add($entry_dn, attrs => $add_data);
                }
                if ($rv->code) {
-                       $this->error("Modify failed: ".$rv->error);
+                       $this->error("$op failed for $entry_dn: ".$rv->error);
                }
        }
 
-       $this->{ds}->unbind();
+       $this->{ds}->unbind;
 
        $this->SUPER::shutdown(@_);
 }
@@ -281,12 +285,12 @@
 sub load {
        my $this = shift;
        return unless $this->{keybykey};
-       my $entry_cn = shift;
+       my $key = shift;
 
-       my $records = $this->get_key($entry_cn);
+       my $records = $this->get_key($key);
        return unless $records;
                
-       debug "db $this->{name}" => "Read entry for $entry_cn";
+       debug "db $this->{name}" => "Read entry for $key";
 
        $this->parse_records($records);
 }
@@ -323,15 +327,23 @@
        my $this = shift;
        return unless $this->{keybykey};
        my $entry_cn = shift;
+       my $base = 'cn=' . $entry_cn . ',' . $this->{basedn};
 
        my $data = $this->{ds}->search(
-               base => 'cn=' . $entry_cn . ',' . $this->{basedn},
+               base => $base,
                sizelimit => 0,
                timelimit => 0,
                filter => "(objectclass=debconfDbEntry)");
 
        if ($data->code) {
-               $this->error("Search failed: ".$data->error);
+               # Failed search is not a fatal error in keybykey mode.
+               # It only means the specific entry requested was not found in 
the
+               # LDAP server, which is a regular thing to happen on first 
install
+               # of a package.
+               if ( !$this->{keybykey} ) {
+                       $this->error("Search failed for $base: ".$data->error);
+               }
+               return;
        }
 
        return unless $data->entries;

Reply via email to