]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
files: open files with track id only
authorVictor Julien <victor@inliniac.net>
Fri, 3 May 2019 10:10:14 +0000 (12:10 +0200)
committerVictor Julien <victor@inliniac.net>
Fri, 3 May 2019 10:35:36 +0000 (12:35 +0200)
src/app-layer-ftp.c
src/app-layer-htp-file.c
src/app-layer-htp.h
src/app-layer-smtp.c
src/app-layer-smtp.h
src/util-file.c
src/util-file.h

index 67a7c41a23f27aa4a1382bed879ef5c036e4d48c..a26258ed639965fe06d984457818671764f43d27 100644 (file)
@@ -821,10 +821,12 @@ static int FTPDataParse(Flow *f, FtpDataState *ftpdata_state,
                 break;
         }
 
-        if (FileOpenFile(ftpdata_state->files, &sbcfg,
-                         (uint8_t *) ftpdata_state->file_name,
+        /* open with fixed track_id 0 as we can have just one
+         * file per ftp-data flow. */
+        if (FileOpenFileWithId(ftpdata_state->files, &sbcfg,
+                         0ULL, (uint8_t *) ftpdata_state->file_name,
                          ftpdata_state->file_len,
-                         input, input_len, flags) == NULL) {
+                         input, input_len, flags) != 0) {
             SCLogDebug("Can't open file");
             ret = -1;
         }
index ce5599381e9269b348af2bc280202dd1389c58b8..16574cf369379dfd022dce544e3589f9f7b22913 100644 (file)
@@ -137,8 +137,9 @@ int HTPFileOpen(HtpState *s, const uint8_t *filename, uint16_t filename_len,
         sbcfg = &s->cfg->request.sbcfg;
     }
 
-    if (FileOpenFile(files, sbcfg, filename, filename_len,
-                data, data_len, flags) == NULL)
+    if (FileOpenFileWithId(files, sbcfg, s->file_track_id++,
+                filename, filename_len,
+                data, data_len, flags) != 0)
     {
         retval = -1;
     }
index 8e1430771270902d1116a315f91416d09c8b85f0..17dcc84e54e9e86d33e101d654e0b24c38166fa1 100644 (file)
@@ -235,6 +235,7 @@ typedef struct HtpState_ {
     uint16_t flags;
     uint16_t events;
     uint16_t htp_messages_offset; /**< offset into conn->messages list */
+    uint32_t file_track_id;             /**< used to assign file track ids to files */
     uint64_t last_request_data_stamp;
     uint64_t last_response_data_stamp;
 } HtpState;
index 318264f23e9586e937da383bdde4e74a4fdcdcf8..a8cf94b93a60bce79a170a37c055fcd2dbb3f9b3 100644 (file)
@@ -461,8 +461,9 @@ int SMTPProcessDataChunk(const uint8_t *chunk, uint32_t len,
                 flags |= FILE_STORE;
             }
 
-            if (FileOpenFile(files, &smtp_config.sbcfg, (uint8_t *) entity->filename, entity->filename_len,
-                    (uint8_t *) chunk, len, flags) == NULL) {
+            if (FileOpenFileWithId(files, &smtp_config.sbcfg, smtp_state->file_track_id++,
+                        (uint8_t *) entity->filename, entity->filename_len,
+                        (uint8_t *) chunk, len, flags) != 0) {
                 ret = MIME_DEC_ERR_DATA;
                 SCLogDebug("FileOpenFile() failed");
             }
@@ -1207,10 +1208,12 @@ static int SMTPProcessRequest(SMTPState *state, Flow *f,
                     TAILQ_INSERT_TAIL(&state->tx_list, tx, next);
                     tx->tx_id = state->tx_cnt++;
                 }
-                FileOpenFile(state->files_ts, &smtp_config.sbcfg,
+                if (FileOpenFileWithId(state->files_ts, &smtp_config.sbcfg,
+                        state->file_track_id++,
                         (uint8_t*) msgname, strlen(msgname), NULL, 0,
-                        FILE_NOMD5|FILE_NOMAGIC);
-                FlagDetectStateNewFile(state->curr_tx);
+                        FILE_NOMD5|FILE_NOMAGIC) == 0) {
+                    FlagDetectStateNewFile(state->curr_tx);
+                }
             } else if (smtp_config.decode_mime) {
                 if (tx->mime_state) {
                     /* We have 2 chained mails and did not detect the end
index 35dd72c2e3d6a61c3a2398db95d0af23fe196782..f244d625cb9d54fc2ed40bff541779d41a42264f 100644 (file)
@@ -159,13 +159,14 @@ typedef struct SMTPState_ {
      *  handler */
     uint16_t cmds_idx;
 
+    /* HELO of HELO message content */
+    uint16_t helo_len;
+    uint8_t *helo;
+
     /* SMTP Mime decoding and file extraction */
     /** the list of files sent to the server */
     FileContainer *files_ts;
-
-    /* HELO of HELO message content */
-    uint8_t *helo;
-    uint16_t helo_len;
+    uint32_t file_track_id;
 } SMTPState;
 
 /* Create SMTP config structure */
index f322970e72a52f2d319375c1b22f60c21592fd37..305044f8b60c94396760828ecc54830ad8986b75 100644 (file)
@@ -775,7 +775,7 @@ int FileSetRange(FileContainer *ffc, uint64_t start, uint64_t end)
  *
  *  \note filename is not a string, so it's not nul terminated.
  */
-File *FileOpenFile(FileContainer *ffc, const StreamingBufferConfig *sbcfg,
+static File *FileOpenFile(FileContainer *ffc, const StreamingBufferConfig *sbcfg,
         const uint8_t *name, uint16_t name_len,
         const uint8_t *data, uint32_t data_len, uint16_t flags)
 {
index 01bff145b2af4354daf1892e977e519a25ecc42a..ef8b03401871d2c9cd9e78d466a21d1f42aa3380 100644 (file)
@@ -129,9 +129,6 @@ void FileContainerAdd(FileContainer *, File *);
  *  It's the responsibility of the API user to make sure this tracker is
  *  properly updated.
  */
-File *FileOpenFile(FileContainer *, const StreamingBufferConfig *,
-        const uint8_t *name, uint16_t name_len,
-        const uint8_t *data, uint32_t data_len, uint16_t flags);
 int FileOpenFileWithId(FileContainer *, const StreamingBufferConfig *,
         uint32_t track_id, const uint8_t *name, uint16_t name_len,
         const uint8_t *data, uint32_t data_len, uint16_t flags);