files: open files with track id only

pull/3826/head
Victor Julien 7 years ago
parent 3b31bad855
commit 9132e4032a

@ -821,10 +821,12 @@ static int FTPDataParse(Flow *f, FtpDataState *ftpdata_state,
break; break;
} }
if (FileOpenFile(ftpdata_state->files, &sbcfg, /* open with fixed track_id 0 as we can have just one
(uint8_t *) ftpdata_state->file_name, * file per ftp-data flow. */
if (FileOpenFileWithId(ftpdata_state->files, &sbcfg,
0ULL, (uint8_t *) ftpdata_state->file_name,
ftpdata_state->file_len, ftpdata_state->file_len,
input, input_len, flags) == NULL) { input, input_len, flags) != 0) {
SCLogDebug("Can't open file"); SCLogDebug("Can't open file");
ret = -1; ret = -1;
} }

@ -137,8 +137,9 @@ int HTPFileOpen(HtpState *s, const uint8_t *filename, uint16_t filename_len,
sbcfg = &s->cfg->request.sbcfg; sbcfg = &s->cfg->request.sbcfg;
} }
if (FileOpenFile(files, sbcfg, filename, filename_len, if (FileOpenFileWithId(files, sbcfg, s->file_track_id++,
data, data_len, flags) == NULL) filename, filename_len,
data, data_len, flags) != 0)
{ {
retval = -1; retval = -1;
} }

@ -235,6 +235,7 @@ typedef struct HtpState_ {
uint16_t flags; uint16_t flags;
uint16_t events; uint16_t events;
uint16_t htp_messages_offset; /**< offset into conn->messages list */ 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_request_data_stamp;
uint64_t last_response_data_stamp; uint64_t last_response_data_stamp;
} HtpState; } HtpState;

@ -461,8 +461,9 @@ int SMTPProcessDataChunk(const uint8_t *chunk, uint32_t len,
flags |= FILE_STORE; flags |= FILE_STORE;
} }
if (FileOpenFile(files, &smtp_config.sbcfg, (uint8_t *) entity->filename, entity->filename_len, if (FileOpenFileWithId(files, &smtp_config.sbcfg, smtp_state->file_track_id++,
(uint8_t *) chunk, len, flags) == NULL) { (uint8_t *) entity->filename, entity->filename_len,
(uint8_t *) chunk, len, flags) != 0) {
ret = MIME_DEC_ERR_DATA; ret = MIME_DEC_ERR_DATA;
SCLogDebug("FileOpenFile() failed"); SCLogDebug("FileOpenFile() failed");
} }
@ -1207,10 +1208,12 @@ static int SMTPProcessRequest(SMTPState *state, Flow *f,
TAILQ_INSERT_TAIL(&state->tx_list, tx, next); TAILQ_INSERT_TAIL(&state->tx_list, tx, next);
tx->tx_id = state->tx_cnt++; 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, (uint8_t*) msgname, strlen(msgname), NULL, 0,
FILE_NOMD5|FILE_NOMAGIC); FILE_NOMD5|FILE_NOMAGIC) == 0) {
FlagDetectStateNewFile(state->curr_tx); FlagDetectStateNewFile(state->curr_tx);
}
} else if (smtp_config.decode_mime) { } else if (smtp_config.decode_mime) {
if (tx->mime_state) { if (tx->mime_state) {
/* We have 2 chained mails and did not detect the end /* We have 2 chained mails and did not detect the end

@ -159,13 +159,14 @@ typedef struct SMTPState_ {
* handler */ * handler */
uint16_t cmds_idx; uint16_t cmds_idx;
/* HELO of HELO message content */
uint16_t helo_len;
uint8_t *helo;
/* SMTP Mime decoding and file extraction */ /* SMTP Mime decoding and file extraction */
/** the list of files sent to the server */ /** the list of files sent to the server */
FileContainer *files_ts; FileContainer *files_ts;
uint32_t file_track_id;
/* HELO of HELO message content */
uint8_t *helo;
uint16_t helo_len;
} SMTPState; } SMTPState;
/* Create SMTP config structure */ /* Create SMTP config structure */

@ -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. * \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 *name, uint16_t name_len,
const uint8_t *data, uint32_t data_len, uint16_t flags) const uint8_t *data, uint32_t data_len, uint16_t flags)
{ {

@ -129,9 +129,6 @@ void FileContainerAdd(FileContainer *, File *);
* It's the responsibility of the API user to make sure this tracker is * It's the responsibility of the API user to make sure this tracker is
* properly updated. * 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 *, int FileOpenFileWithId(FileContainer *, const StreamingBufferConfig *,
uint32_t track_id, const uint8_t *name, uint16_t name_len, uint32_t track_id, const uint8_t *name, uint16_t name_len,
const uint8_t *data, uint32_t data_len, uint16_t flags); const uint8_t *data, uint32_t data_len, uint16_t flags);

Loading…
Cancel
Save