|
|
@ -38,6 +38,11 @@
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
static int g_file_force_magic = 0;
|
|
|
|
static int g_file_force_magic = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** \brief switch to force md5 calculation on all files
|
|
|
|
|
|
|
|
* regardless of the rules.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int g_file_force_md5 = 0;
|
|
|
|
|
|
|
|
|
|
|
|
/* prototypes */
|
|
|
|
/* prototypes */
|
|
|
|
static void FileFree(File *);
|
|
|
|
static void FileFree(File *);
|
|
|
|
static void FileDataFree(FileData *);
|
|
|
|
static void FileDataFree(FileData *);
|
|
|
@ -46,10 +51,18 @@ void FileForceMagicEnable(void) {
|
|
|
|
g_file_force_magic = 1;
|
|
|
|
g_file_force_magic = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void FileForceMd5Enable(void) {
|
|
|
|
|
|
|
|
g_file_force_md5 = 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int FileForceMagic(void) {
|
|
|
|
int FileForceMagic(void) {
|
|
|
|
return g_file_force_magic;
|
|
|
|
return g_file_force_magic;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int FileForceMd5(void) {
|
|
|
|
|
|
|
|
return g_file_force_md5;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int FileMagicSize(void) {
|
|
|
|
int FileMagicSize(void) {
|
|
|
|
/** \todo make this size configurable */
|
|
|
|
/** \todo make this size configurable */
|
|
|
|
return 512;
|
|
|
|
return 512;
|
|
|
@ -79,6 +92,8 @@ static int FileAppendFileDataFilePtr(File *ff, FileData *ffd) {
|
|
|
|
ff->chunks_cnt_max = ff->chunks_cnt;
|
|
|
|
ff->chunks_cnt_max = ff->chunks_cnt;
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (ff->md5_ctx)
|
|
|
|
|
|
|
|
HASH_Update(ff->md5_ctx, ffd->data, ffd->len);
|
|
|
|
SCReturnInt(0);
|
|
|
|
SCReturnInt(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -272,6 +287,12 @@ static File *FileAlloc(uint8_t *name, uint16_t name_len) {
|
|
|
|
new->name_len = name_len;
|
|
|
|
new->name_len = name_len;
|
|
|
|
memcpy(new->name, name, name_len);
|
|
|
|
memcpy(new->name, name, name_len);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (g_file_force_md5) {
|
|
|
|
|
|
|
|
new->md5_ctx = HASH_Create(HASH_AlgMD5);
|
|
|
|
|
|
|
|
if (new->md5_ctx != NULL) {
|
|
|
|
|
|
|
|
HASH_Begin(new->md5_ctx);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
return new;
|
|
|
|
return new;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -296,6 +317,9 @@ static void FileFree(File *ff) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (ff->md5_ctx)
|
|
|
|
|
|
|
|
HASH_Destroy(ff->md5_ctx);
|
|
|
|
|
|
|
|
|
|
|
|
SCLogDebug("ff chunks_cnt %"PRIu64", chunks_cnt_max %"PRIu64,
|
|
|
|
SCLogDebug("ff chunks_cnt %"PRIu64", chunks_cnt_max %"PRIu64,
|
|
|
|
ff->chunks_cnt, ff->chunks_cnt_max);
|
|
|
|
ff->chunks_cnt, ff->chunks_cnt_max);
|
|
|
|
SCFree(ff);
|
|
|
|
SCFree(ff);
|
|
|
@ -508,6 +532,12 @@ static int FileCloseFilePtr(File *ff, uint8_t *data,
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
ff->state = FILE_STATE_CLOSED;
|
|
|
|
ff->state = FILE_STATE_CLOSED;
|
|
|
|
SCLogDebug("flowfile state transitioned to FILE_STATE_CLOSED");
|
|
|
|
SCLogDebug("flowfile state transitioned to FILE_STATE_CLOSED");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (ff->md5_ctx) {
|
|
|
|
|
|
|
|
unsigned int len = 0;
|
|
|
|
|
|
|
|
HASH_End(ff->md5_ctx, ff->md5, &len, sizeof(ff->md5));
|
|
|
|
|
|
|
|
ff->flags |= FILE_MD5;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SCReturnInt(0);
|
|
|
|
SCReturnInt(0);
|
|
|
|