From: Russ Combs Date: Thu, 21 Aug 2014 03:17:14 +0000 (-0400) Subject: refactored cmd line parsing X-Git-Tag: 3.0.0-233~1419^2~35 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=4b9776ebb71c8f8aebcc276fc786d06a7abd7344;p=thirdparty%2Fsnort3.git refactored cmd line parsing --- diff --git a/ChangeLog b/ChangeLog index 5c98e6358..eee88a359 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,7 @@ 115 -- remove share.h -- misc FIXITs +-- refactored cmd line parsing and moved options to SnortModule 114 -- more FIXIT cleanup diff --git a/src/detection/detection_util.cc b/src/detection/detection_util.cc index 30ef68d37..f698ab7cf 100644 --- a/src/detection/detection_util.cc +++ b/src/detection/detection_util.cc @@ -24,7 +24,7 @@ #include #include "snort.h" -#include "sf_textlog.h" +#include "log/text_log.h" #include "actions/actions.h" THREAD_LOCAL uint32_t http_mask; diff --git a/src/filters/sfthd.cc b/src/filters/sfthd.cc index 62cb955cd..68bce11f5 100644 --- a/src/filters/sfthd.cc +++ b/src/filters/sfthd.cc @@ -627,16 +627,17 @@ the current event should be logged or dropped. --- Local and Global Thresholding is setup here --- */ -int sfthd_create_threshold(SnortConfig *sc, - ThresholdObjects *thd_objs, - unsigned gen_id, - unsigned sig_id, - int tracking, - int type, - int priority, - int count, - int seconds, - sfip_var_t* ip_address) +int sfthd_create_threshold( + SnortConfig *sc, + ThresholdObjects *thd_objs, + unsigned gen_id, + unsigned sig_id, + int tracking, + int type, + int priority, + int count, + int seconds, + sfip_var_t* ip_address) { //allocate memory fpr sfthd_array if needed. PolicyId policyId = get_network_policy()->policy_id; diff --git a/src/framework/module.h b/src/framework/module.h index df19baabc..94e547580 100644 --- a/src/framework/module.h +++ b/src/framework/module.h @@ -19,6 +19,7 @@ // module.h author Russ Combs // FIXIT +// -- add lua module default // -- add set_default method // -- add trace param(s) // -- add memcap related @@ -121,8 +122,8 @@ public: virtual void reset_stats(); protected: - Module(const char* s); - Module(const char* s, const Parameter* p, bool is_list = false); + Module(const char*); + Module(const char*, const Parameter*, bool is_list = false); private: friend class ModuleManager; diff --git a/src/framework/parameter.cc b/src/framework/parameter.cc index 02fae34c0..85e5959cd 100644 --- a/src/framework/parameter.cc +++ b/src/framework/parameter.cc @@ -348,3 +348,14 @@ const char* Parameter::get_type() const return pt2str[type]; } +const Parameter* Parameter::find(const Parameter* p, const char* s) +{ + while ( p->name ) + { + if ( !strcmp(p->name, s) || !strcmp(p->name, "*") ) + return p; + ++p; + } + return nullptr; +} + diff --git a/src/framework/parameter.h b/src/framework/parameter.h index 2aba31a7f..148e2c82f 100644 --- a/src/framework/parameter.h +++ b/src/framework/parameter.h @@ -56,6 +56,11 @@ struct Parameter const char* get_type() const; bool validate(class Value&) const; + + bool is_positional() const + { return ( name && *name == '~' ); }; + + static const Parameter* find(const Parameter*, const char*); }; #endif diff --git a/src/log/CMakeLists.txt b/src/log/CMakeLists.txt index 1555236e2..0123be83e 100644 --- a/src/log/CMakeLists.txt +++ b/src/log/CMakeLists.txt @@ -13,8 +13,8 @@ add_library ( log STATIC messages.cc obfuscation.cc obfuscation.h - sf_textlog.cc - sf_textlog.h + text_log.cc + text_log.h ) set_default_visibility_compile_flag( log ) diff --git a/src/log/Makefile.am b/src/log/Makefile.am index 8759febbf..a53080127 100644 --- a/src/log/Makefile.am +++ b/src/log/Makefile.am @@ -10,13 +10,13 @@ obfuscation.h liblog_a_SOURCES = \ log.cc \ +log.h \ log_text.cc \ +log_text.h \ messages.cc \ obfuscation.cc \ -sf_textlog.cc \ -log.h \ -log_text.h \ -sf_textlog.h +text_log.cc \ +text_log.h liblog_a_CXXFLAGS = $(AM_CXXFLAGS) -fvisibility=default diff --git a/src/log/log_text.cc b/src/log/log_text.cc index f213a036e..67b920ae8 100644 --- a/src/log/log_text.cc +++ b/src/log/log_text.cc @@ -43,7 +43,7 @@ #include "util_net.h" #include "protocols/packet.h" #include "snort.h" -#include "sf_textlog.h" +#include "log/text_log.h" #include "snort_bounds.h" #include "obfuscation.h" #include "detection_util.h" diff --git a/src/log/log_text.h b/src/log/log_text.h index 8d7af0903..21d73e7b3 100644 --- a/src/log/log_text.h +++ b/src/log/log_text.h @@ -38,7 +38,7 @@ #endif #include -#include "sf_textlog.h" +#include "log/text_log.h" struct Packet; diff --git a/src/log/sf_textlog.cc b/src/log/text_log.cc similarity index 99% rename from src/log/sf_textlog.cc rename to src/log/text_log.cc index 0a7d45749..63e85dac2 100644 --- a/src/log/sf_textlog.cc +++ b/src/log/text_log.cc @@ -21,14 +21,14 @@ ****************************************************************************/ /** - * @file sf_textlog.c + * @file log/text_log.c * @author Russ Combs * @date * * @brief implements buffered text stream for logging */ -#include "sf_textlog.h" +#include "text_log.h" #include #include diff --git a/src/log/sf_textlog.h b/src/log/text_log.h similarity index 97% rename from src/log/sf_textlog.h rename to src/log/text_log.h index f4576e4ac..7bfb7f4ef 100644 --- a/src/log/sf_textlog.h +++ b/src/log/text_log.h @@ -1,6 +1,6 @@ /**************************************************************************** * -** Copyright (C) 2014 Cisco and/or its affiliates. All rights reserved. + * Copyright (C) 2014 Cisco and/or its affiliates. All rights reserved. * Copyright (C) 2003-2013 Sourcefire, Inc. * * This program is free software; you can redistribute it and/or modify @@ -21,7 +21,7 @@ ****************************************************************************/ /** - * @file sf_textlog.h + * @file text_log.h * @author Russ Combs * @date Fri Jun 27 10:34:37 2003 * diff --git a/src/loggers/alert_csv.cc b/src/loggers/alert_csv.cc index 454b0a8d8..a0f09c9d2 100644 --- a/src/loggers/alert_csv.cc +++ b/src/loggers/alert_csv.cc @@ -39,8 +39,8 @@ #include "util.h" #include "log.h" #include "snort.h" -#include "sf_textlog.h" -#include "log_text.h" +#include "log/text_log.h" +#include "log/log_text.h" #define LOG_BUFFER (4*K_BYTES) diff --git a/src/loggers/alert_fast.cc b/src/loggers/alert_fast.cc index 6da897147..1fe276265 100644 --- a/src/loggers/alert_fast.cc +++ b/src/loggers/alert_fast.cc @@ -54,9 +54,8 @@ #include "util.h" #include "mstring.h" #include "packet_io/active.h" -#include "sf_textlog.h" -#include "log_text.h" -#include "sf_textlog.h" +#include "log/text_log.h" +#include "log/log_text.h" #include "snort.h" #include "packet_io/sfdaq.h" #include "packet_io/intf.h" diff --git a/src/loggers/alert_full.cc b/src/loggers/alert_full.cc index 7cd5eb22a..1c8b576a8 100644 --- a/src/loggers/alert_full.cc +++ b/src/loggers/alert_full.cc @@ -53,8 +53,8 @@ #include "util.h" #include "mstring.h" #include "snort.h" -#include "sf_textlog.h" -#include "log_text.h" +#include "log/text_log.h" +#include "log/log_text.h" #include "packet_io/sfdaq.h" #include "packet_io/intf.h" diff --git a/src/loggers/alert_test.cc b/src/loggers/alert_test.cc index 83da6a9d0..37af2e82b 100644 --- a/src/loggers/alert_test.cc +++ b/src/loggers/alert_test.cc @@ -37,7 +37,7 @@ #include "parser.h" #include "util.h" #include "log/log_text.h" -#include "log/sf_textlog.h" +#include "log/text_log.h" #include "mstring.h" #include "snort.h" diff --git a/src/main/CMakeLists.txt b/src/main/CMakeLists.txt index c8a5cd4db..f138321d1 100644 --- a/src/main/CMakeLists.txt +++ b/src/main/CMakeLists.txt @@ -9,6 +9,8 @@ add_library (main STATIC analyzer.h analyzer.cc build.h + help.cc + help.h modules.cc modules.h policy.h @@ -20,6 +22,8 @@ add_library (main STATIC snort_debug.cc snort_config.h snort_config.cc + snort_module.h + snort_module.cc thread.cc ${INCLUDES} ) diff --git a/src/main/Makefile.am b/src/main/Makefile.am index 426d2c2b0..67e4e47a1 100644 --- a/src/main/Makefile.am +++ b/src/main/Makefile.am @@ -13,6 +13,8 @@ libmain_a_SOURCES = \ analyzer.cc \ analyzer.h \ build.h \ +help.cc \ +help.h \ modules.cc \ modules.h \ policy.cc \ @@ -24,6 +26,8 @@ snort.h \ snort_config.cc \ snort_config.h \ snort_debug.cc \ +snort_module.cc \ +snort_module.h \ thread.cc AM_CXXFLAGS = @AM_CXXFLAGS@ diff --git a/src/main/help.cc b/src/main/help.cc new file mode 100644 index 000000000..a192cade7 --- /dev/null +++ b/src/main/help.cc @@ -0,0 +1,271 @@ +/* +** Copyright (C) 2014 Cisco and/or its affiliates. All rights reserved. +** Copyright (C) 2013-2013 Sourcefire, Inc. +** +** This program is free software; you can redistribute it and/or modify +** it under the terms of the GNU General Public License Version 2 as +** published by the Free Software Foundation. You may not use, modify or +** distribute this program under any other version of the GNU General +** Public License. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include "help.h" + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +using namespace std; + +#include "config_file.h" +#include "parser.h" +#include "vars.h" +#include "detection/detect.h" +#include "helpers/process.h" +#include "main/analyzer.h" +#include "main/shell.h" +#include "main/snort_module.h" +#include "managers/event_manager.h" +#include "managers/so_manager.h" +#include "managers/inspector_manager.h" +#include "managers/module_manager.h" +#include "managers/plugin_manager.h" +#include "packet_io/trough.h" +#include "packet_io/sfdaq.h" +#include "packet_io/intf.h" +#include "parser/parser.h" +#include "utils/util.h" +#include "helpers/markup.h" +#include "framework/module.h" +#include "framework/parameter.h" + +static const char* snort_help = +"Snort has several options to get more help:\n" +"\n" +"--help this overview of help\n" +"--help-builtin [] output matching builtin rules\n" +"--help-buffers output available inspection buffers\n" +"--help-commands [] output matching commands\n" +"--help-config [] output matching config options\n" +"--help-gids [] output matching generators\n" +"--help-module output description of given module\n" +"--help-options [