[pkg-kolab] r1008 - in libkolab-perl/trunk/debian: . patches

mparent-guest at alioth.debian.org mparent-guest at alioth.debian.org
Wed Nov 26 21:27:36 UTC 2008


Author: mparent-guest
Date: 2008-11-26 21:27:36 +0000 (Wed, 26 Nov 2008)
New Revision: 1008

Modified:
   libkolab-perl/trunk/debian/changelog
   libkolab-perl/trunk/debian/patches/50-sync-ldap-backend.diff
Log:
update to current syncrepl patch


Modified: libkolab-perl/trunk/debian/changelog
===================================================================
--- libkolab-perl/trunk/debian/changelog	2008-11-26 21:06:11 UTC (rev 1007)
+++ libkolab-perl/trunk/debian/changelog	2008-11-26 21:27:36 UTC (rev 1008)
@@ -1,3 +1,9 @@
+libkolab-perl (1:2.2.0-3) UNRELEASED; urgency=low
+
+  * update to current syncrepl patch
+
+ -- Mathieu Parent <math.parent at gmail.com>  Wed, 26 Nov 2008 22:21:14 +0100
+
 libkolab-perl (1:2.2.0-2) unstable; urgency=medium
 
   * Setting urgency as medium as previous upload was missing syncrepl LDAP

Modified: libkolab-perl/trunk/debian/patches/50-sync-ldap-backend.diff
===================================================================
--- libkolab-perl/trunk/debian/patches/50-sync-ldap-backend.diff	2008-11-26 21:06:11 UTC (rev 1007)
+++ libkolab-perl/trunk/debian/patches/50-sync-ldap-backend.diff	2008-11-26 21:27:36 UTC (rev 1008)
@@ -5,10 +5,11 @@
 ## DP: which is not activated by default
 
 @DPATCH@
-diff -urNad libkolab-perl-2.2.0~/lib/Kolab/LDAP/Backend/syncrepl.pm libkolab-perl-2.2.0/lib/Kolab/LDAP/Backend/syncrepl.pm
---- libkolab-perl-2.2.0~/lib/Kolab/LDAP/Backend/syncrepl.pm	1970-01-01 01:00:00.000000000 +0100
-+++ libkolab-perl-2.2.0/lib/Kolab/LDAP/Backend/syncrepl.pm	2008-08-02 01:06:03.000000000 +0200
-@@ -0,0 +1,318 @@
+Index: b/lib/Kolab/LDAP/Backend/syncrepl.pm
+===================================================================
+--- /dev/null
++++ b/lib/Kolab/LDAP/Backend/syncrepl.pm
+@@ -0,0 +1,324 @@
 +package Kolab::LDAP::Backend::syncrepl;
 +
 +##
@@ -32,11 +33,15 @@
 +use warnings;
 +use Kolab;
 +use Kolab::LDAP;
-+use Net::LDAP;
++use Net::LDAP qw(
++	LDAP_USER_CANCELED
++	LDAP_SYNC_REFRESH_ONLY
++	LDAP_SYNC_REFRESH_AND_PERSIST
++);
 +use Net::LDAP::Control;
++use Net::LDAP::Control::SyncRequest;
 +use Net::LDAP::Entry;
-+use vars qw($ldap $cookie $disconnected);
-+my $cookie = '';
++use vars qw($ldap $disconnected);
 +my $disconnected = 1;
 +
 +require Exporter;
@@ -56,97 +61,41 @@
 +    
 +);
 +
-+our $VERSION = '0.1';
++our $VERSION = '0.3';
 +
-+# LDAP Content Synchronization Operation -- RFC 4533
-+use constant LDAP_SYNC_OID => "1.3.6.1.4.1.4203.1.9.1";
-+use constant {
-+	LDAP_CONTROL_SYNC => LDAP_SYNC_OID.".1",
-+	LDAP_CONTROL_SYNC_STATE => LDAP_SYNC_OID.".2",
-+	LDAP_CONTROL_SYNC_DONE => LDAP_SYNC_OID.".3",
-+	LDAP_SYNC_INFO => LDAP_SYNC_OID.".4",
-+
-+	LDAP_SYNC_NONE => 0x00,
-+	LDAP_SYNC_REFRESH_ONLY => 0x01,
-+	LDAP_SYNC_RESERVED => 0x02,
-+	LDAP_SYNC_REFRESH_AND_PERSIST => 0x03,
-+
-+	LDAP_SYNC_REFRESH_PRESENTS => 0,
-+	LDAP_SYNC_REFRESH_DELETES => 1,
-+
-+	LDAP_TAG_SYNC_NEW_COOKIE => 0x80,
-+	LDAP_TAG_SYNC_REFRESH_DELETE => 0xa1,
-+	LDAP_TAG_SYNC_REFRESH_PRESENT => 0xa2,
-+	LDAP_TAG_SYNC_ID_SET => 0xa3,
-+
-+	LDAP_TAG_SYNC_COOKIE => 0x04,
-+	LDAP_TAG_REFRESHDELETES => 0x01,
-+	LDAP_TAG_REFRESHDONE => 0x01,
-+	LDAP_TAG_RELOAD_HINT => 0x01,
-+
-+	LDAP_SYNC_PRESENT => 0,
-+	LDAP_SYNC_ADD => 1,
-+	LDAP_SYNC_MODIFY => 2,
-+	LDAP_SYNC_DELETE => 3,
-+};
-+
-+use Convert::ASN1;
-+use Data::Dumper;
-+
-+my $asn = Convert::ASN1->new;
-+
-+$asn->prepare(<<'LDAP_ASN') or die $asn->error;
-+syncUUID ::= OCTET STRING -- (SIZE(16))
-+
-+syncCookie ::= OCTET STRING
-+
-+syncRequestValue ::= SEQUENCE {
-+    mode ENUMERATED {
-+        -- 0 unused
-+        refreshOnly       (1),
-+        -- 2 reserved
-+        refreshAndPersist (3)
-+    }
-+    cookie     syncCookie OPTIONAL,
-+    reloadHint BOOLEAN -- DEFAULT FALSE
++sub mode { 
++  LDAP_SYNC_REFRESH_ONLY;
++  #LDAP_SYNC_REFRESH_AND_PERSIST;
 +}
 +
-+syncStateValue ::= SEQUENCE {
-+    state ENUMERATED {
-+        present (0),
-+        add (1),
-+        modify (2),
-+        delete (3)
++# calling without args means: get,
++# giving an argument means: set
++sub cookie {
++  my($cookie) = @_;
++  if(defined($cookie)) {
++    if(!open(COOKIE_FILE, '>', $Kolab::config{'syncrepl_cookie_file'})) {
++        Kolab::log("SYNCREPL', 'Cannot open file `".$Kolab::config{'syncrepl_cookie_file'}.
++        "' for writing", KOLAB_DEBUG);
++        &abort;
 +    }
-+    entryUUID syncUUID,
-+    cookie    syncCookie OPTIONAL
++    Kolab::log("SYNCREPL', 'Writing cookie to file: ".$cookie, KOLAB_DEBUG);
++    print COOKIE_FILE $cookie;
++    close(COOKIE_FILE);
++    return $cookie;
++  } else {
++    if(!open(COOKIE_FILE, '+<', $Kolab::config{'syncrepl_cookie_file'})) {
++        Kolab::log("SYNCREPL', 'Cannot open file `".$Kolab::config{'syncrepl_cookie_file'}.
++        "' for reading", KOLAB_DEBUG);
++        &abort;
++    }
++    read COOKIE_FILE, $cookie, 1024, 0;
++    close COOKIE_FILE;
++    #an empty file means no cookie:
++    $cookie = undef if !$cookie;
++    return $cookie;
++  }
 +}
 +
-+syncDoneValue ::= SEQUENCE {
-+    cookie          syncCookie OPTIONAL,
-+    refreshDeletes  BOOLEAN -- DEFAULT FALSE
-+}
-+
-+syncInfoValue ::= CHOICE {
-+      newcookie      [0] syncCookie,
-+      refreshDelete  [1] SEQUENCE {
-+          refreshDeleteCookie         syncCookie OPTIONAL,
-+          refreshDeleteDone    BOOLEAN -- DEFAULT TRUE
-+      }
-+      refreshPresent [2] SEQUENCE {
-+          refreshDeletecookie         syncCookie OPTIONAL,
-+          refreshDeleteDone    BOOLEAN -- DEFAULT TRUE
-+      }
-+      syncIdSet      [3] SEQUENCE {
-+          cookie         syncCookie OPTIONAL,
-+          refreshDeletes BOOLEAN, -- DEFAULT FALSE
-+          syncUUIDs      SET OF syncUUID
-+      }
-+}
-+
-+LDAP_ASN
-+
-+
 +sub startup { 1; }
 +
 +sub shutdown
@@ -195,22 +144,17 @@
 +    Kolab::LDAP::ensureAsync($ldap);
 +    Kolab::log('SYNCREPL', 'Async checked', KOLAB_DEBUG);
 +
-+    Kolab::log('SYNCREPL', "Cookie: $cookie", KOLAB_DEBUG);
++    while($ldap and not $disconnected) {
++      my $ctrl = Net::LDAP::Control::SyncRequest->new(
++        mode       => Kolab::LDAP::Backend::syncrepl::mode(),
++        cookie     => Kolab::LDAP::Backend::syncrepl::cookie(),
++        reloadHint => 0);
++      Kolab::log('SYNCREPL', 'Control created: mode='.$ctrl->mode().
++      	'; cookie='.$ctrl->cookie().
++      	'; reloadHint='.$ctrl->reloadHint(), KOLAB_DEBUG);
 +
-+    while($ldap and not $disconnected) {
-+	    #sync control
-+      my $asn_syncRequestValue = $asn->find('syncRequestValue');
-+	    my $ctrl = Net::LDAP::Control->new(type  => LDAP_CONTROL_SYNC, 
-+		                                     value => $asn_syncRequestValue->encode(mode       => LDAP_SYNC_REFRESH_ONLY,
-+                                                                                cookie     => $cookie,
-+                                                                                reloadHint => 0
-+                                                                               ),
-+                                         critical   => 0
-+	                                      );
-+      Kolab::log('SYNCREPL', 'Control created', KOLAB_DEBUG);
-+    
-+	    #search
-+	    my $mesg = $ldap->search(base     => $Kolab::config{'base_dn'},
++      #search
++      my $mesg = $ldap->search(base     => $Kolab::config{'base_dn'},
 +                               scope    => 'sub',
 +                               control  => [ $ctrl ],
 +                               callback => \&searchCallback, # call for each entry
@@ -221,7 +165,7 @@
 +                                             $Kolab::config{'user_field_quota'},
 +                                             $Kolab::config{'user_field_deleted'},
 +                                           ],
-+				                      );
++                              );
 +      Kolab::log('SYNCREPL', 'Search created', KOLAB_DEBUG);
 +      $mesg->sync;
 +      Kolab::log('SYNCREPL', "Finished Net::LDAP::Search::sync sleeping 10s", KOLAB_DEBUG);
@@ -234,46 +178,109 @@
 +#search callback
 +sub searchCallback {
 +  my $mesg = shift;
-+  my $entry = shift;
-+  my $issearch = $mesg->isa("Net::LDAP::Search");
++  my $param2 = shift; # might be entry or intermediate
 +  my @controls = $mesg->control;
-+  if(not $issearch) {
-+    Kolab::log('SYNCREPL', 'mesg is not a search object, testing code...', KOLAB_DEBUG);
-+    if ($mesg->code == 88) {
-+        Kolab::log('SYNCREPL', 'searchCallback() -> Exit code received, returning', KOLAB_DEBUG);
-+        return;
-+    } elsif ($mesg->code) {
-+        Kolab::log('SYNCREPL', "Not a search: mesg->code = `" . $mesg->code . "', mesg->msg = `" . $mesg->error . "'", KOLAB_DEBUG);
-+        &abort;
-+    }   
-+  } elsif(@controls == 0) {
-+    if ($mesg->code == 1) {
-+        Kolab::log('SYNCREPL', 'No control: Communications Error: disconnecting', KOLAB_DEBUG);
-+        $disconnected = 1;
-+        return;
-+    } elsif ($mesg->code) {
-+      Kolab::log('SYNCREPL', "No control: mesg->code = `" . $mesg->code . "', mesg->msg = `" . $mesg->error . "'", KOLAB_DEBUG);
-+        &abort;
-+    }   
-+  } elsif($controls[0]->type eq LDAP_CONTROL_SYNC_STATE) {
-+    Kolab::log('SYNCREPL', 'Received Sync State Control', KOLAB_DEBUG);
-+    Kolab::log('SYNCREPL', "Entry (".$entry->changetype."): ".$entry->dn(), KOLAB_DEBUG);
-+  } elsif($controls[0]->type eq LDAP_CONTROL_SYNC_DONE) {
-+    Kolab::log('SYNCREPL', 'Received Sync Done Control', KOLAB_DEBUG);
-+    my $asn_syncDoneValue = $asn->find('syncDoneValue');
-+    my $out = $asn_syncDoneValue->decode($controls[0]->value);
-+	  #we have a new cookie
-+	  if(defined($out->{cookie}) and not $out->{cookie} eq '' and not $out->{cookie} eq $cookie) {
-+		  $cookie = $out->{cookie};
-+		  Kolab::log('SYNCREPL', "New cookie: $cookie", KOLAB_DEBUG);
++  my @sync_controls = ();
++  if($param2 && $param2->isa("Net::LDAP::Entry")) {
++    Kolab::log('SYNCREPL', 'Received Search Entry', KOLAB_DEBUG);
++    #retrieve Sync State Control
++    foreach my $ctrl (@controls) {
++      push(@sync_controls, $ctrl)
++        if $ctrl->isa('Net::LDAP::Control::SyncState');
++    }
++    if(@sync_controls>1) {
++      Kolab::log('SYNCREPL', 'Got search entry with multiple Sync State controls',
++        KOLAB_DEBUG);
++      return;
++    }
++    if(!@sync_controls) {
++      Kolab::log('SYNCREPL', 'Got search entry without Sync State control',
++        KOLAB_DEBUG);
++      return;
++    }
++    if(!$sync_controls[0]->entryUUID) {
++      Kolab::log('SYNCREPL', 'Got empty entryUUID', KOLAB_DEBUG);
++      return;
++    }
++    Kolab::log('SYNCREPL', 'Search Entry has Sync State Control: '.
++      'state='.$sync_controls[0]->state().
++      '; entryUUID='.unpack("H*",$sync_controls[0]->entryUUID()).
++      '; cookie='.(defined($sync_controls[0]->cookie()) ? $sync_controls[0]->cookie() : 'UNDEF')
++	, KOLAB_DEBUG);
++    if(defined($sync_controls[0]->cookie)) {
++      Kolab::LDAP::Backend::syncrepl::cookie($sync_controls[0]->cookie);
++      Kolab::log('SYNCREPL',"New cookie: ".Kolab::LDAP::Backend::syncrepl::cookie(),
++        KOLAB_DEBUG);
++    }
++    Kolab::log('SYNCREPL', "Entry (".$param2->changetype."): ".$param2->dn(), KOLAB_DEBUG);
++  } elsif($param2 && $param2->isa("Net::LDAP::Reference")) {
++    Kolab::log('SYNCREPL', 'Received Search Reference', KOLAB_DEBUG);
++    return;
++  #if it not first control?
++  } elsif($controls[0] and $controls[0]->isa('Net::LDAP::Control::SyncDone')) {
++    Kolab::log('SYNCREPL', 'Received Sync Done Control: '.
++      'cookie='.(defined($controls[0]->cookie()) ? $controls[0]->cookie() : 'UNDEF').
++      '; refreshDeletes='.$controls[0]->refreshDeletes(), KOLAB_DEBUG);
++    #we have a new cookie
++    if(defined($controls[0]->cookie())
++        and not $controls[0]->cookie() eq '' 
++        and not $controls[0]->cookie() eq Kolab::LDAP::Backend::syncrepl::cookie()) {
++      Kolab::LDAP::Backend::syncrepl::cookie($controls[0]->cookie());
++      Kolab::log('SYNCREPL', "New cookie: ".
++        Kolab::LDAP::Backend::syncrepl::cookie(), KOLAB_DEBUG);
 +      Kolab::log('SYNCREPL', "Calling Kolab::LDAP::sync", KOLAB_DEBUG);
 +      Kolab::LDAP::sync;
-+      system($Kolab::config{'kolabconf_script'}) == 0 || Kolab::log('SD', "Failed to run kolabconf: $?", KOLAB_ERROR);
++      system($Kolab::config{'kolabconf_script'}) == 0
++        || Kolab::log('SD', "Failed to run kolabconf: $?", KOLAB_ERROR);
 +      Kolab::log('SYNCREPL', "Finished Kolab::LDAP::sync sleeping 1s", KOLAB_DEBUG);
 +      sleep 1; # we get too many bogus change notifications!
 +	  } 
++  } elsif($param2 && $param2->isa("Net::LDAP::Intermediate")) {
++    Kolab::log('SYNCREPL', 'Received Intermediate Message', KOLAB_DEBUG);
++    my $attrs = $param2->{asn};
++    if($attrs->{newcookie}) {
++      Kolab::LDAP::Backend::syncrepl::cookie($attrs->{newcookie});
++      Kolab::log('SYNCREPL', "New cookie: ".
++        Kolab::LDAP::Backend::syncrepl::cookie(), KOLAB_DEBUG);
++    } elsif(my $refreshInfos = ($attrs->{refreshDelete} || $attrs->{refreshPresent})) {
++      Kolab::LDAP::Backend::syncrepl::cookie($refreshInfos->{cookie})
++        if defined($refreshInfos->{cookie});
++      Kolab::log('SYNCREPL', 
++        (defined($refreshInfos->{cookie}) ? 'New ' : 'Empty ').
++        "cookie from ".
++        ($attrs->{refreshDelete} ? 'refreshDelete' : 'refreshPresent').
++        " (refreshDone=".$refreshInfos->{refreshDone}."): ".
++        Kolab::LDAP::Backend::syncrepl::cookie(), KOLAB_DEBUG);
++    } elsif(my $syncIdSetInfos = $attrs->{syncIdSet}) {
++      Kolab::LDAP::Backend::syncrepl::cookie($syncIdSetInfos->{cookie})
++        if defined($syncIdSetInfos->{cookie});
++      Kolab::log('SYNCREPL', 
++        (defined($syncIdSetInfos->{cookie}) ? 'Empty ' : 'New ').
++        "cookie from syncIdSet".
++        " (refreshDeletes=".$syncIdSetInfos->{refreshDeletes}."): ".
++        Kolab::LDAP::Backend::syncrepl::cookie(), KOLAB_DEBUG);
++      foreach my $syncUUID ($syncIdSetInfos->{syncUUIDs}) {
++        Kolab::log('SYNCREPL', 'entryUUID='.
++          unpack("H*",$syncUUID), KOLAB_DEBUG);
++      }
++    }
++  } elsif($mesg->code) {
++    if ($mesg->code == 1) {
++      Kolab::log('SYNCREPL', 'Communication Error: disconnecting', KOLAB_DEBUG);
++      $disconnected = 1;
++      return 0;
++    } elsif ($mesg->code == LDAP_USER_CANCELED) {
++        Kolab::log('SYNCREPL', 'searchCallback() -> Exit code received, returning', KOLAB_DEBUG);
++        return;
++    } elsif ($mesg->code == 4096) {
++        Kolab::log('SYNCREPL', 'Refresh required', KOLAB_DEBUG);
++        Kolab::LDAP::Backend::syncrepl::cookie('');
++    } else {
++        Kolab::log('SYNCREPL', "searchCallback: mesg->code = `" . $mesg->code . "', mesg->msg = `" . $mesg->error . "'", KOLAB_DEBUG);
++        &abort;
++    }   
 +  } else {
-+    Kolab::log('SYNCREPL', 'Received unknown control: '.$controls[0]->type, KOLAB_DEBUG);
++    Kolab::log('SYNCREPL', 'Received something else', KOLAB_DEBUG);
 +  }
 +  return 0;
 +}




More information about the pkg-kolab-devel mailing list