-- basic reload restoration
-- support cmd() form of snort.cmd()
-- misc FIXITs
+-- converted wizard to fully stateful
120
-- tweaked --help!
// 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
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 )
{
{
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
}
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;
}
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; };
~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;
};
//-------------------------------------------------------------------------
~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
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 )
{
{
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
{
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;
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;
}
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;
}
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;
}