]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
converted wizard to fully stateful
authorRuss Combs <rucombs@cisco.com>
Tue, 23 Sep 2014 16:50:25 +0000 (12:50 -0400)
committerRuss Combs <rucombs@cisco.com>
Tue, 23 Sep 2014 16:50:25 +0000 (12:50 -0400)
ChangeLog
src/managers/module_manager.cc
src/service_inspectors/wizard/hexes.cc
src/service_inspectors/wizard/magic.h
src/service_inspectors/wizard/spells.cc
src/service_inspectors/wizard/wizard.cc

index b47f85215cac138c6dabf9d0ac969238753fe1cb..45b522d967aa6ce240049cae2555d1201497ee16 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -3,6 +3,7 @@
 -- basic reload restoration
 -- support cmd() form of snort.cmd()
 -- misc FIXITs
+-- converted wizard to fully stateful
 
 120
 -- tweaked --help!
index 84022138d072c6a48597a65148bc3fd9d1a4096e..e2c96be0dd065623653ed474263a8f355b6531f4 100644 (file)
@@ -722,7 +722,8 @@ void ModuleManager::load_commands(SnortConfig* sc)
 // FIXIT-L currently no way to know whether a module was activated or not
 // so modules with common rules will cause duplicate sid warnings
 // eg http_inspect and nhttp_inspect both have 119:1-34
-// only to avoid that now is to not load plugins with common rules
+// only way to avoid that now is to not load plugins with common rules
+// (we don't want to suppress it because it could mean something is broken)
 void ModuleManager::load_rules(SnortConfig* sc)
 {
     // FIXIT-M callers of ParseConfigString() should not have to push parse loc
index 04c2990e20910fa1a55070a6eccf10dea159003e..abbf3b29102b6893b58c508e35b3a3971ef572d7 100644 (file)
@@ -125,8 +125,8 @@ bool HexBook::add_spell(const char* key, const char* val)
     return true;
 }
 
-MagicPage* HexBook::find_spell(
-    const uint8_t* s, unsigned n, MagicPage* p, unsigned i) const
+const MagicPage* HexBook::find_spell(
+    const uint8_t* s, unsigned n, const MagicPage* p, unsigned i) const
 {
     while ( i < n )
     {
@@ -136,7 +136,7 @@ MagicPage* HexBook::find_spell(
         {
             if ( p->any )
             {
-                if ( MagicPage* q = find_spell(s, n, p->next[c], i+1) )
+                if ( const MagicPage* q = find_spell(s, n, p->next[c], i+1) )
                     return q;
             }
             else
@@ -148,23 +148,22 @@ MagicPage* HexBook::find_spell(
         }
         if ( p->any )
         {
-            if ( MagicPage* q = find_spell(s, n, p->any, i+1) )
+            if ( const MagicPage* q = find_spell(s, n, p->any, i+1) )
                 return q;
         }
         break;
     }
-    if ( p->key.empty() )
-        return nullptr;
-    else
-        return p;
+    return p;
 }
 
-// FIXIT-H make this incremental based on last position
-const char* HexBook::find_spell(const uint8_t* data, unsigned len) const
+const char* HexBook::find_spell(
+    const uint8_t* data, unsigned len, const MagicPage*& p) const
 {
-    if ( MagicPage* p = find_spell(data, len, root) )
+    p = find_spell(data, len, p, 0);
+
+    if ( !p->value.empty() )
         return p->value.c_str();
-    else
-        return nullptr;
+
+    return nullptr;
 }
  
index 02ac9f1ec85cc2c3a9aedfab5482e91a89c0ee51..af32a212485771a4e0d756f69b26e60a7193802d 100644 (file)
@@ -48,7 +48,7 @@ public:
     virtual ~MagicBook();
 
     virtual bool add_spell(const char* key, const char* val) = 0;
-    virtual const char* find_spell(const uint8_t*, unsigned len) const = 0;
+    virtual const char* find_spell(const uint8_t*, unsigned len, const MagicPage*&) const = 0;
 
     const MagicPage* page1()
     { return root; };
@@ -70,12 +70,12 @@ public:
     ~SpellBook() { };
 
     bool add_spell(const char*, const char*);
-    const char* find_spell(const uint8_t*, unsigned len) const;
+    const char* find_spell(const uint8_t*, unsigned len, const MagicPage*&) const;
 
 private:
     bool translate(const char*, HexVector&);
     void add_spell(const char*, const char*, HexVector&, unsigned, MagicPage*);
-    MagicPage* find_spell(const uint8_t*, unsigned, MagicPage*, unsigned = 0) const;
+    const MagicPage* find_spell(const uint8_t*, unsigned, const MagicPage*, unsigned) const;
 };
 
 //-------------------------------------------------------------------------
@@ -90,12 +90,12 @@ public:
     ~HexBook() { };
 
     bool add_spell(const char*, const char*);
-    const char* find_spell(const uint8_t*, unsigned len) const;
+    const char* find_spell(const uint8_t*, unsigned len, const MagicPage*&) const;
 
 private:
     bool translate(const char*, HexVector&);
     void add_spell(const char*, const char*, HexVector&, unsigned, MagicPage*);
-    MagicPage* find_spell(const uint8_t*, unsigned, MagicPage*, unsigned = 0) const;
+    const MagicPage* find_spell(const uint8_t*, unsigned, const MagicPage*, unsigned) const;
 };
 
 #endif
index 2a98861a014166442b712279f648edd9093d4f8e..c2fd25ce461d659f56597e2b2e7bae25f9c98e3c 100644 (file)
@@ -114,8 +114,8 @@ bool SpellBook::add_spell(const char* key, const char* val)
     return true;
 }
 
-MagicPage* SpellBook::find_spell(
-    const uint8_t* s, unsigned n, MagicPage* p, unsigned i) const
+const MagicPage* SpellBook::find_spell(
+    const uint8_t* s, unsigned n, const MagicPage* p, unsigned i) const
 {
     while ( i < n )
     {
@@ -125,7 +125,7 @@ MagicPage* SpellBook::find_spell(
         {
             if ( p->any )
             {
-                if ( MagicPage* q = find_spell(s, n, p->next[c], i+1) )
+                if ( const MagicPage* q = find_spell(s, n, p->next[c], i+1) )
                     return q;
             }
             else
@@ -139,21 +139,18 @@ MagicPage* SpellBook::find_spell(
         {
             while ( i < n )
             {
-                if ( MagicPage* q = find_spell(s, n, p->any, i) )
+                if ( const MagicPage* q = find_spell(s, n, p->any, i) )
                     return q;
                 ++i;
             }
         }
         break;
     }
-    if ( p->key.empty() )
-        return nullptr;
-    else
-        return p;
+    return p;
 }
 
-// FIXIT-H make this incremental based on last position
-const char* SpellBook::find_spell(const uint8_t* data, unsigned len) const
+const char* SpellBook::find_spell(
+    const uint8_t* data, unsigned len, const MagicPage*& p) const
 {
     // FIXIT-L make configurable upper bound to limit globbing
     unsigned max = 16;
@@ -161,9 +158,11 @@ const char* SpellBook::find_spell(const uint8_t* data, unsigned len) const
     if ( len > max )
         len = max;
     
-    if ( MagicPage* p = find_spell(data, len, root) )
+    p = find_spell(data, len, p, 0);
+
+    if ( !p->value.empty() )
         return p->value.c_str();
-    else
-        return nullptr;
+
+    return nullptr;
 }
  
index 62c2add26bac987a3a42ed5c5b187c3deeac43ad..5b01fea0a3cc4f57f73b1f621f907ff59808bb18 100644 (file)
@@ -99,7 +99,7 @@ public:
 
     void reset(Wand&, bool tcp, bool c2s);
     bool cast_spell(Wand&, Flow*, const uint8_t*, unsigned);
-    bool spellbind(const MagicPage*, Flow*, const uint8_t*, unsigned);
+    bool spellbind(const MagicPage*&, Flow*, const uint8_t*, unsigned);
 
 public:
     MagicBook* c2s_hexes;
@@ -194,10 +194,9 @@ StreamSplitter* Wizard::get_splitter(bool c2s)
 }
 
 bool Wizard::spellbind(
-    const MagicPage* m, Flow* f, const uint8_t* data, unsigned len)
+    const MagicPage*& m, Flow* f, const uint8_t* data, unsigned len)
 {
-    // FIXIT-H convert to stateful find
-    f->service = m->book.find_spell(data, len);
+    f->service = m->book.find_spell(data, len, m);
     return f->service != nullptr;
 }