summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Bos <richard@radoeka.nl>2008-10-19 10:25:05 (GMT)
committerRichard Bos <richard@radoeka.nl>2008-10-19 10:25:05 (GMT)
commit507156520b7236165f9007603b0065c55cabd869 (patch)
tree679294e8445e7a7b875f4b56588c3f6c32afca38
parent645bd715ab4b9d627d5022fd40653ea72701fe7a (diff)
downloadperl-Kolab-507156520b7236165f9007603b0065c55cabd869.tar.gz
keep syncrepl cookie on disk between sessions (kolab/issue3152)
-rw-r--r--ChangeLog5
-rw-r--r--lib/Kolab/LDAP/Backend/syncrepl.pm85
2 files changed, 65 insertions, 25 deletions
diff --git a/ChangeLog b/ChangeLog
index ac47314..ade98b8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2008-10-19 Richard Bos <richard@radoeka.nl>
+
+ * lib/Kolab/LDAP/Backend/syncrepl.pm: keep syncrepl cookie on disk
+ between sessions (kolab/issue3152)
+
2008-10-16 Richard Bos <richard@radoeka.nl>
* lib/Kolab/LDAP/Backend/syncrepl.pm: updated. Updates provided by
diff --git a/lib/Kolab/LDAP/Backend/syncrepl.pm b/lib/Kolab/LDAP/Backend/syncrepl.pm
index 0a78c48..0e38bb9 100644
--- a/lib/Kolab/LDAP/Backend/syncrepl.pm
+++ b/lib/Kolab/LDAP/Backend/syncrepl.pm
@@ -29,8 +29,7 @@ use Net::LDAP qw(
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;
@@ -50,13 +49,41 @@ our @EXPORT = qw(
);
-our $VERSION = '0.2';
+our $VERSION = '0.3';
sub mode {
LDAP_SYNC_REFRESH_ONLY;
#LDAP_SYNC_REFRESH_AND_PERSIST;
}
+# 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;
+ }
+ 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;
+ }
+}
+
sub startup { 1; }
sub shutdown
@@ -107,8 +134,8 @@ sub run {
while($ldap and not $disconnected) {
my $ctrl = Net::LDAP::Control::SyncRequest->new(
- mode => Kolab::LDAP::Backend::syncrepl::mode,
- cookie => $cookie,
+ 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().
@@ -160,8 +187,7 @@ sub searchCallback {
return;
}
if(!$sync_controls[0]->entryUUID) {
- Kolab::log('SYNCREPL', 'Got empty entryUUID',
- KOLAB_DEBUG);
+ Kolab::log('SYNCREPL', 'Got empty entryUUID', KOLAB_DEBUG);
return;
}
Kolab::log('SYNCREPL', 'Search Entry has Sync State Control: '.
@@ -170,8 +196,9 @@ sub searchCallback {
'; cookie='.(defined($sync_controls[0]->cookie()) ? $sync_controls[0]->cookie() : 'UNDEF')
, KOLAB_DEBUG);
if(defined($sync_controls[0]->cookie)) {
- $cookie = $sync_controls[0]->cookie;
- Kolab::log('SYNCREPL',"New cookie: $cookie", KOLAB_DEBUG);
+ 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")) {
@@ -180,16 +207,19 @@ sub searchCallback {
#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 $cookie) {
- $cookie = $controls[0]->cookie();
- Kolab::log('SYNCREPL', "New cookie: $cookie", KOLAB_DEBUG);
+ '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!
}
@@ -197,21 +227,26 @@ sub searchCallback {
Kolab::log('SYNCREPL', 'Received Intermediate Message', KOLAB_DEBUG);
my $attrs = $param2->{asn};
if($attrs->{newcookie}) {
- $cookie = $attrs->{newcookie};
- Kolab::log('SYNCREPL', "New cookie: $cookie", KOLAB_DEBUG);
+ 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})) {
- $cookie = $refreshInfos->{cookie} if defined($refreshInfos->{cookie});
+ 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}."): $cookie", KOLAB_DEBUG);
+ " (refreshDone=".$refreshInfos->{refreshDone}."): ".
+ Kolab::LDAP::Backend::syncrepl::cookie(), KOLAB_DEBUG);
} elsif(my $syncIdSetInfos = $attrs->{syncIdSet}) {
- $cookie = $syncIdSetInfos->{cookie} if defined($syncIdSetInfos->{cookie});
+ 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}."): $cookie", KOLAB_DEBUG);
+ " (refreshDeletes=".$syncIdSetInfos->{refreshDeletes}."): ".
+ Kolab::LDAP::Backend::syncrepl::cookie(), KOLAB_DEBUG);
foreach my $syncUUID ($syncIdSetInfos->{syncUUIDs}) {
Kolab::log('SYNCREPL', 'entryUUID='.
unpack("H*",$syncUUID), KOLAB_DEBUG);
@@ -227,7 +262,7 @@ sub searchCallback {
return;
} elsif ($mesg->code == 4096) {
Kolab::log('SYNCREPL', 'Refresh required', KOLAB_DEBUG);
- $cookie = '';
+ Kolab::LDAP::Backend::syncrepl::cookie('');
} else {
Kolab::log('SYNCREPL', "searchCallback: mesg->code = `" . $mesg->code . "', mesg->msg = `" . $mesg->error . "'", KOLAB_DEBUG);
&abort;
@@ -286,4 +321,4 @@ However (quoting from RFC, page 21):
-=cut \ No newline at end of file
+=cut