]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
ftp: use switch for ftp commands for style
authorPhilippe Antoine <contact@catenacyber.fr>
Mon, 16 Mar 2020 13:52:32 +0000 (14:52 +0100)
committerJeff Lucovsky <jeff@lucovsky.org>
Wed, 22 Apr 2020 12:02:40 +0000 (08:02 -0400)
(cherry picked from commit fef124b92dbabe64c6f1580113a251fae639857f)

src/app-layer-ftp.c

index 782ea691b1e5a61f2e6749b435330432a0243444..de1a0838344c69c1e4cfce8be3f5dab7223d5f0c 100644 (file)
@@ -760,45 +760,53 @@ static int FTPParseResponse(Flow *f, void *ftp_state, AppLayerParserState *pstat
         }
     }
 
-    if (state->command == FTP_COMMAND_EPRT) {
-        uint16_t dyn_port = rs_ftp_active_eprt(state->port_line, state->port_line_len);
-        if (dyn_port == 0) {
-            retcode = 0;
-            goto tx_complete;
-        }
-        state->dyn_port = dyn_port;
-        state->active = true;
-        tx->dyn_port = dyn_port;
-        tx->active = true;
-        SCLogDebug("FTP active mode (v6): dynamic port %"PRIu16"", dyn_port);
-    }
-
-    if (state->command == FTP_COMMAND_PORT) {
-        if ((flags & STREAM_TOCLIENT)) {
-            uint16_t dyn_port = rs_ftp_active_port(state->port_line, state->port_line_len);
-            if (dyn_port == 0) {
-                retcode = 0;
-                goto tx_complete;
-            }
-            state->dyn_port = dyn_port;
-            state->active = true;
-            tx->dyn_port = state->dyn_port;
-            tx->active = true;
-            SCLogDebug("FTP active mode (v4): dynamic port %"PRIu16"", dyn_port);
-        }
-    }
+        state->curr_tx = tx;
+        uint16_t dyn_port;
+        switch (state->command) {
+            case FTP_COMMAND_AUTH_TLS:
+                if (state->current_line_len >= 4 && SCMemcmp("234 ", state->current_line, 4) == 0) {
+                    AppLayerRequestProtocolTLSUpgrade(f);
+                }
+                break;
 
-    if (state->command == FTP_COMMAND_PASV) {
-        if (state->current_line_len >= 4 && SCMemcmp("227 ", state->current_line, 4) == 0) {
-            FTPParsePassiveResponse(f, ftp_state, state->current_line, state->current_line_len);
-        }
-    }
+            case FTP_COMMAND_EPRT:
+                dyn_port = rs_ftp_active_eprt(state->port_line, state->port_line_len);
+                if (dyn_port == 0) {
+                    goto tx_complete;
+                }
+                state->dyn_port = dyn_port;
+                state->active = true;
+                tx->dyn_port = dyn_port;
+                tx->active = true;
+                SCLogDebug("FTP active mode (v6): dynamic port %"PRIu16"", dyn_port);
+                break;
 
-    if (state->command == FTP_COMMAND_EPSV) {
-        if (state->current_line_len >= 4 && SCMemcmp("229 ", state->current_line, 4) == 0) {
-            FTPParsePassiveResponseV6(f, ftp_state, state->current_line, state->current_line_len);
+            case FTP_COMMAND_PORT:
+                dyn_port = rs_ftp_active_port(state->port_line, state->port_line_len);
+                if (dyn_port == 0) {
+                    goto tx_complete;
+                }
+                state->dyn_port = dyn_port;
+                state->active = true;
+                tx->dyn_port = state->dyn_port;
+                tx->active = true;
+                SCLogDebug("FTP active mode (v4): dynamic port %"PRIu16"", dyn_port);
+                break;
+
+            case FTP_COMMAND_PASV:
+                if (state->current_line_len >= 4 && SCMemcmp("227 ", state->current_line, 4) == 0) {
+                    FTPParsePassiveResponse(f, ftp_state, state->current_line, state->current_line_len);
+                }
+                break;
+
+            case FTP_COMMAND_EPSV:
+                if (state->current_line_len >= 4 && SCMemcmp("229 ", state->current_line, 4) == 0) {
+                    FTPParsePassiveResponseV6(f, ftp_state, state->current_line, state->current_line_len);
+                }
+                break;
+            default:
+                break;
         }
-    }
 
     if (likely(state->current_line_len)) {
         FTPString *response = FTPStringAlloc();