prelude-correlator/master: Introduce version checking for Unpickled elements

[email protected] Fri, 26 Feb 2010 15:45:52 +0100 (CET)
Newsgroups gmane.comp.security.ids.prelude.cvs
Message-ID <[email protected]>
commit bba0e398a994fc3a59674dadc192f3423ff86475
Author: Yoann Vandoorselaere <[email protected]>
Date:   Tue Feb 9 16:04:16 2010 +0100

    Introduce version checking for Unpickled elements
    
    This introduce version compatibility check when unpickling a context, if
    the Context implementation version has changed, then the old Context won't
    be restaured. This avoid runtime exception if/when Context attributes changes.


========================================

 PreludeCorrelator/context.py |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)

========================================

diff --git a/PreludeCorrelator/context.py b/PreludeCorrelator/context.py
index 34ad74f..6bc8f2f 100644
--- a/PreludeCorrelator/context.py
+++ b/PreludeCorrelator/context.py
@@ -75,6 +75,8 @@ class Timer:
 
 
 class Context(IDMEF, Timer):
+        FORMAT_VERSION = 0.1
+
         def __setstate__(self, dict):
                 Timer.__setstate__(self, dict)
                 IDMEF.__setstate__(self, dict)
@@ -84,6 +86,7 @@ class Context(IDMEF, Timer):
                 if already_initialized is True:
                         return
 
+                self._version = self.FORMAT_VERSION
                 self._options = { "threshold": -1, "expire": 0, "alert_on_expire": False }
                 IDMEF.__init__(self)
                 Timer.__init__(self, 0)
@@ -132,6 +135,10 @@ class Context(IDMEF, Timer):
 
                 self.destroy()
 
+        def isVersionCompatible(self):
+                version = self.__dict__.get("_version", None)
+                return self.FORMAT_VERSION == version
+
         def update(self, options={}, idmef=None):
                 self._update_count += 1
 
@@ -214,6 +221,10 @@ def load():
                 except EOFError:
                         return
 
+                for ctx in _CONTEXT_TABLE.values():
+                        if not ctx.isVersionCompatible():
+                                ctx.destroy()
+
 def wakeup(now):
         for timer in _TIMER_LIST:
                 timer.check(now)
_______________________________________________
Prelude-cvslog site list
[email protected]
http://lists.prelude-technologies.com/mailman/listinfo/prelude-cvslog