]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
fix ftp cmd conf
authorRuss Combs <rucombs@cisco.com>
Wed, 9 Jul 2014 16:05:31 +0000 (12:05 -0400)
committerRuss Combs <rucombs@cisco.com>
Wed, 9 Jul 2014 16:05:31 +0000 (12:05 -0400)
src/service_inspectors/ftp_telnet/ftp_module.cc
src/service_inspectors/ftp_telnet/ftp_module.h
src/service_inspectors/rpc_decode/rpc_decode.cc

index f603130eb36a7280463e8495c55dcaaf049df7b9..b0df34cf0bcc69cc51fec0919f25d036601e5b66 100644 (file)
@@ -158,19 +158,26 @@ bool FtpClientModule::end(const char* fqn, int, SnortConfig*)
 // server stuff
 //-------------------------------------------------------------------------
 
-FtpCmd::FtpCmd(std::string& key, uint32_t flg, unsigned num)
+FtpCmd::FtpCmd(std::string& key, uint32_t flg, int num)
 {
     name = key;
     flags = flg;
     number = num;
 }
 
-FtpCmd::FtpCmd(std::string& key, std::string& fmt)
+FtpCmd::FtpCmd(std::string& key, std::string& fmt, int num)
 {
     name = key;
     format = fmt;
+
     flags = CMD_VALID;
     number = 0;
+
+    if ( num >= 0 )
+    {
+        number = num;
+        flags |= CMD_LEN;
+    }
 }
 
 //-------------------------------------------------------------------------
@@ -234,17 +241,6 @@ static const char* DEFAULT_FTP_CONF[] =
 
 //-------------------------------------------------------------------------
 
-static const Parameter ftp_server_alt_max_params[] =
-{
-    { "commands", Parameter::PT_STRING, nullptr, nullptr,
-      "list of commands" },
-
-    { "length", Parameter::PT_INT, "0:", "0",
-      "specify non-default maximum for command" },
-
-    { nullptr, Parameter::PT_MAX, nullptr, nullptr, nullptr }
-};
-
 static const Parameter ftp_server_validity_params[] =
 {
     { "command", Parameter::PT_STRING, nullptr, nullptr,
@@ -253,6 +249,9 @@ static const Parameter ftp_server_validity_params[] =
     { "format", Parameter::PT_STRING, nullptr, nullptr,
       "format specification" },
 
+    { "length", Parameter::PT_INT, "0:", "0",
+      "specify non-default maximum for command" },
+
     { nullptr, Parameter::PT_MAX, nullptr, nullptr, nullptr }
 };
 
@@ -269,9 +268,6 @@ static const Parameter ftp_directory_params[] =
 
 static const Parameter ftp_server_params[] =
 {
-    { "alt_max_param", Parameter::PT_LIST, ftp_server_alt_max_params, nullptr,
-      "specify non-default maximum command lengths" },
-
     { "chk_str_fmt", Parameter::PT_STRING, nullptr, nullptr,
       "check the formatting of the given commands" },
 
@@ -361,7 +357,7 @@ FtpServerModule::~FtpServerModule()
 }
 
 void FtpServerModule::add_commands(
-    Value& v, uint32_t flags, unsigned num)
+    Value& v, uint32_t flags, int num)
 {
     string tok;
     v.set_first_token();
@@ -378,6 +374,13 @@ const FtpCmd* FtpServerModule::get_cmd(unsigned idx)
         return nullptr;
 }
 
+FTP_SERVER_PROTO_CONF* FtpServerModule::get_data()
+{   
+    FTP_SERVER_PROTO_CONF* tmp = conf;
+    conf = nullptr;
+    return tmp;
+}
+
 //-------------------------------------------------------------------------
 
 bool FtpServerModule::set(const char*, Value& v, SnortConfig*)
@@ -391,6 +394,9 @@ bool FtpServerModule::set(const char*, Value& v, SnortConfig*)
     else if ( v.is("command") )
         names = v.get_string();
 
+    else if ( v.is("commands") )
+        names = v.get_string();
+
     else if ( v.is("data_chan_cmds") )
         add_commands(v, CMD_DATA);
 
@@ -442,32 +448,19 @@ bool FtpServerModule::set(const char*, Value& v, SnortConfig*)
     else if ( v.is("telnet_cmds") )
         conf->telnet_cmds = v.get_bool();
 
+    else
+        return false;
+
     return true;
 }
 
 //-------------------------------------------------------------------------
 
-FTP_SERVER_PROTO_CONF* FtpServerModule::get_data()
-{   
-    FTP_SERVER_PROTO_CONF* tmp = conf;
-    conf = nullptr;
-    return tmp;
-}
-
-bool FtpServerModule::begin(const char* fqn, int, SnortConfig*)
+bool FtpServerModule::begin(const char*, int, SnortConfig*)
 {
-    if ( strcmp(fqn, FTP_SERVER) )
-    {
-        names.clear();
-        format.clear();
-        number = 0;
-        return true;
-    }
-
-    for ( auto p : cmds )
-        delete p;
-
-    cmds.clear();
+    names.clear();
+    format.clear();
+    number = -1;
 
     if ( !conf )
         conf = new FTP_SERVER_PROTO_CONF;
@@ -475,24 +468,19 @@ bool FtpServerModule::begin(const char* fqn, int, SnortConfig*)
     return true;
 }
 
-bool FtpServerModule::end(const char* fqn, int, SnortConfig*)
+bool FtpServerModule::end(const char* fqn, int idx, SnortConfig*)
 {
+    if ( !idx )
+        return true;
+
     if ( !strcmp(fqn, "ftp_server.cmd_validity") )
-        cmds.push_back(new FtpCmd(names, format));
+        cmds.push_back(new FtpCmd(names, format, number));
 
-    else if ( !strcmp(fqn, "ftp_server.alt_max_param") )
-    {
-        Value v(names.c_str());
-        add_commands(v, CMD_LEN, number);
-    }
-    else if ( !strcmp(fqn, "ftp_server.dir_cmds") )
+    else if ( !strcmp(fqn, "ftp_server.directory_cmds") )
     {
         Value v(names.c_str());
         add_commands(v, CMD_DIR, number);
     }
-    else if ( strcmp(fqn, FTP_SERVER) )
-        return false;
-
     return true;
 }
 
index be3182a65da099a4333f0ae606819a5cbcb7d107..0ffb38ceb9daccc603dde3e5cad4d5c35c2378d1 100644 (file)
@@ -95,8 +95,8 @@ struct FtpCmd
     uint32_t flags;
     unsigned number;
 
-    FtpCmd(std::string&, uint32_t, unsigned);
-    FtpCmd(std::string&, std::string&);
+    FtpCmd(std::string&, uint32_t, int);
+    FtpCmd(std::string&, std::string&, int);
 };
 
 class FtpServerModule : public Module
@@ -116,14 +116,14 @@ public:
     const FtpCmd* get_cmd(unsigned idx);
 
 private:
-    void add_commands(Value&, uint32_t flags, unsigned num = 0);
+    void add_commands(Value&, uint32_t flags, int num = 0);
 
 private:
     FTP_SERVER_PROTO_CONF* conf;
     std::vector<FtpCmd*> cmds;
     std::string names;
     std::string format;
-    unsigned number;
+    int number;
 };
 
 #endif
index 4554970429d7e19ba03f6c104337addfc03efd72..6247c8a8a3af8a567c7462acc44ceb9561c5e1eb 100644 (file)
@@ -1107,7 +1107,6 @@ void RpcDecode::eval(Packet *p)
     RpcPreprocEvent(&config, rsdata, ConvertRPC(&config, rsdata, p));
 
     PREPROC_PROFILE_END(rpcdecodePerfStats);
-    return;
 }
 
 //-------------------------------------------------------------------------