suricata
output-filestore.c
Go to the documentation of this file.
1 /* Copyright (C) 2018-2021 Open Information Security Foundation
2  *
3  * You can copy, redistribute or modify this Program under the terms of
4  * the GNU General Public License version 2 as published by the Free
5  * Software Foundation.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * version 2 along with this program; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15  * 02110-1301, USA.
16  */
17 
18 #include "suricata-common.h"
19 
20 #include "stream-tcp.h"
21 #include "app-layer-parser.h"
22 #include "app-layer-htp.h"
23 #include "app-layer-htp-xff.h"
24 #include "app-layer-smtp.h"
25 
26 #include "feature.h"
27 
28 #include "output.h"
29 #include "output-filestore.h"
30 #include "output-json-file.h"
31 
32 #include "util-print.h"
33 #include "util-misc.h"
34 
35 #define MODULE_NAME "OutputFilestore"
36 
37 /* Create a filestore specific PATH_MAX that is less than the system
38  * PATH_MAX to prevent newer gcc truncation warnings with snprint. */
39 #define SHA256_STRING_LEN (SC_SHA256_LEN * 2)
40 #define LEAF_DIR_MAX_LEN 4
41 #define FILESTORE_PREFIX_MAX (PATH_MAX - SHA256_STRING_LEN - LEAF_DIR_MAX_LEN)
42 
43 /* The default log directory, relative to the default log
44  * directory. */
45 static const char *default_log_dir = "filestore";
46 
47 /* Atomic counter of simultaneously open files. */
48 static SC_ATOMIC_DECLARE(uint32_t, filestore_open_file_cnt);
49 
50 typedef struct OutputFilestoreCtx_ {
53  bool fileinfo;
56 
57 typedef struct OutputFilestoreLogThread_ {
59  uint16_t counter_max_hits;
60  uint16_t fs_error_counter;
62 
63 /* For WARN_ONCE, a record of warnings that have already been
64  * issued. */
65 static thread_local bool once_errs[SC_ERR_MAX];
66 
67 #define WARN_ONCE(err_code, ...) do { \
68  if (!once_errs[err_code]) { \
69  once_errs[err_code] = true; \
70  SCLogWarning(err_code, __VA_ARGS__); \
71  } \
72  } while (0)
73 
74 static uint64_t OutputFilestoreOpenFilesCounter(void)
75 {
76  return SC_ATOMIC_GET(filestore_open_file_cnt);
77 }
78 
79 static uint32_t g_file_store_max_open_files = 0;
80 
81 static void FileSetMaxOpenFiles(uint32_t count)
82 {
83  g_file_store_max_open_files = count;
84 }
85 
86 static uint32_t FileGetMaxOpenFiles(void)
87 {
88  return g_file_store_max_open_files;
89 }
90 
91 static void PrintHexString(char *str, size_t size, uint8_t *buf, size_t buf_len)
92 {
93  int i = 0;
94  size_t x = 0;
95  for (i = 0, x = 0; x < buf_len; x++) {
96  i += snprintf(&str[i], size - i, "%02x", buf[x]);
97  }
98 }
99 
100 /**
101  * \brief Update the timestamps on a file to match those of another
102  * file.
103  *
104  * \param src_filename Filename to use as timestamp source.
105  * \param filename Filename to apply timestamps to.
106  */
107 static void OutputFilestoreUpdateFileTime(const char *src_filename,
108  const char *filename)
109 {
110  struct stat sb;
111  if (stat(src_filename, &sb) != 0) {
112  SCLogDebug("Failed to stat %s: %s", filename, strerror(errno));
113  return;
114  }
115  struct utimbuf utimbuf = {
116  .actime = sb.st_atime,
117  .modtime = sb.st_mtime,
118  };
119  if (utime(filename, &utimbuf) != 0) {
120  SCLogDebug("Failed to update file timestamps: %s: %s", filename,
121  strerror(errno));
122  }
123 }
124 
125 static void OutputFilestoreFinalizeFiles(ThreadVars *tv,
126  const OutputFilestoreLogThread *oft, const OutputFilestoreCtx *ctx,
127  const Packet *p, File *ff, uint8_t dir) {
128  /* Stringify the SHA256 which will be used in the final
129  * filename. */
130  char sha256string[(SC_SHA256_LEN * 2) + 1];
131  PrintHexString(sha256string, sizeof(sha256string), ff->sha256,
132  sizeof(ff->sha256));
133 
134  char tmp_filename[PATH_MAX] = "";
135  snprintf(tmp_filename, sizeof(tmp_filename), "%s/file.%u", ctx->tmpdir,
136  ff->file_store_id);
137 
138  char final_filename[PATH_MAX] = "";
139  snprintf(final_filename, sizeof(final_filename), "%s/%c%c/%s",
140  ctx->prefix, sha256string[0], sha256string[1], sha256string);
141 
142  if (SCPathExists(final_filename)) {
143  OutputFilestoreUpdateFileTime(tmp_filename, final_filename);
144  if (unlink(tmp_filename) != 0) {
147  "Failed to remove temporary file %s: %s", tmp_filename,
148  strerror(errno));
149  }
150  } else if (rename(tmp_filename, final_filename) != 0) {
152  WARN_ONCE(SC_WARN_RENAMING_FILE, "Failed to rename %s to %s: %s",
153  tmp_filename, final_filename, strerror(errno));
154  if (unlink(tmp_filename) != 0) {
155  /* Just increment, don't log as has_fs_errors would
156  * already be set above. */
158  }
159  return;
160  }
161 
162  if (ctx->fileinfo) {
163  char js_metadata_filename[PATH_MAX];
164  if (snprintf(js_metadata_filename, sizeof(js_metadata_filename),
165  "%s.%"PRIuMAX".%u.json", final_filename,
166  (uintmax_t)p->ts.tv_sec, ff->file_store_id)
167  == (int)sizeof(js_metadata_filename)) {
169  "Failed to write file info record. Output filename truncated.");
170  } else {
171  JsonBuilder *js_fileinfo =
172  JsonBuildFileInfoRecord(p, ff, true, dir, ctx->xff_cfg, NULL);
173  if (likely(js_fileinfo != NULL)) {
174  jb_close(js_fileinfo);
175  FILE *out = fopen(js_metadata_filename, "w");
176  if (out != NULL) {
177  size_t js_len = jb_len(js_fileinfo);
178  fwrite(jb_ptr(js_fileinfo), js_len, 1, out);
179  fclose(out);
180  }
181  jb_free(js_fileinfo);
182  }
183  }
184  }
185 }
186 
187 static int OutputFilestoreLogger(ThreadVars *tv, void *thread_data,
188  const Packet *p, File *ff, const uint8_t *data, uint32_t data_len,
189  uint8_t flags, uint8_t dir)
190 {
191  SCEnter();
193  OutputFilestoreCtx *ctx = aft->ctx;
194  char filename[PATH_MAX] = "";
195  int file_fd = -1;
196 
197  /* no flow, no files */
198  if (p->flow == NULL) {
200  }
201 
202  if (!(PKT_IS_IPV4(p) || PKT_IS_IPV6(p))) {
203  return 0;
204  }
205 
206  SCLogDebug("ff %p, data %p, data_len %u", ff, data, data_len);
207 
208  char base_filename[PATH_MAX] = "";
209  snprintf(base_filename, sizeof(base_filename), "%s/file.%u",
210  ctx->tmpdir, ff->file_store_id);
211  snprintf(filename, sizeof(filename), "%s", base_filename);
212 
214  file_fd = open(filename, O_CREAT | O_TRUNC | O_NOFOLLOW | O_WRONLY,
215  0644);
216  if (file_fd == -1) {
219  "Filestore (v2) failed to create %s: %s", filename,
220  strerror(errno));
221  return -1;
222  }
223 
224  if (SC_ATOMIC_GET(filestore_open_file_cnt) < FileGetMaxOpenFiles()) {
225  SC_ATOMIC_ADD(filestore_open_file_cnt, 1);
226  ff->fd = file_fd;
227  } else {
228  if (FileGetMaxOpenFiles() > 0) {
230  }
231  ff->fd = -1;
232  }
233  /* we can get called with a NULL ffd when we need to close */
234  } else if (data != NULL) {
235  if (ff->fd == -1) {
236  file_fd = open(filename, O_APPEND | O_NOFOLLOW | O_WRONLY);
237  if (file_fd == -1) {
240  "Filestore (v2) failed to open file %s: %s",
241  filename, strerror(errno));
242  return -1;
243  }
244  } else {
245  file_fd = ff->fd;
246  }
247  }
248 
249  if (file_fd != -1) {
250  ssize_t r = write(file_fd, (const void *)data, (size_t)data_len);
251  if (r == -1) {
254  "Filestore (v2) failed to write to %s: %s",
255  filename, strerror(errno));
256  if (ff->fd != -1) {
257  SC_ATOMIC_SUB(filestore_open_file_cnt, 1);
258  }
259  ff->fd = -1;
260  }
261  if (ff->fd == -1) {
262  close(file_fd);
263  }
264  }
265 
267  if (ff->fd != -1) {
268  close(ff->fd);
269  ff->fd = -1;
270  SC_ATOMIC_SUB(filestore_open_file_cnt, 1);
271  }
272  OutputFilestoreFinalizeFiles(tv, aft, ctx, p, ff, dir);
273  }
274 
275  return 0;
276 }
277 
278 static TmEcode OutputFilestoreLogThreadInit(ThreadVars *t, const void *initdata,
279  void **data)
280 {
282  if (unlikely(aft == NULL))
283  return TM_ECODE_FAILED;
284  memset(aft, 0, sizeof(OutputFilestoreLogThread));
285 
286  if (initdata == NULL) {
287  SCLogDebug("Error getting context for LogFileStore. \"initdata\" argument NULL");
288  SCFree(aft);
289  return TM_ECODE_FAILED;
290  }
291 
292  OutputFilestoreCtx *ctx = ((OutputCtx *)initdata)->data;
293  aft->ctx = ctx;
294 
295  aft->counter_max_hits =
296  StatsRegisterCounter("file_store.open_files_max_hit", t);
297 
298  /* File system type errors (open, write, rename) will only be
299  * logged once. But this stat will be incremented for every
300  * occurence. */
301  aft->fs_error_counter = StatsRegisterCounter("file_store.fs_errors", t);
302 
303  *data = (void *)aft;
304  return TM_ECODE_OK;
305 }
306 
307 static TmEcode OutputFilestoreLogThreadDeinit(ThreadVars *t, void *data)
308 {
310  if (aft == NULL) {
311  return TM_ECODE_OK;
312  }
313 
314  /* clear memory */
315  memset(aft, 0, sizeof(OutputFilestoreLogThread));
316 
317  SCFree(aft);
318  return TM_ECODE_OK;
319 }
320 
321 static void OutputFilestoreLogDeInitCtx(OutputCtx *output_ctx)
322 {
323  OutputFilestoreCtx *ctx = (OutputFilestoreCtx *)output_ctx->data;
324  if (ctx->xff_cfg != NULL) {
325  SCFree(ctx->xff_cfg);
326  }
327  SCFree(ctx);
328  SCFree(output_ctx);
329 }
330 
331 static void GetLogDirectory(const ConfNode *conf, char *out, size_t out_size)
332 {
333  const char *log_base_dir = ConfNodeLookupChildValue(conf, "dir");
334  if (log_base_dir == NULL) {
335  SCLogConfig("Filestore (v2) default log directory %s", default_log_dir);
336  log_base_dir = default_log_dir;
337  }
338  if (PathIsAbsolute(log_base_dir)) {
339  strlcpy(out, log_base_dir, out_size);
340  } else {
341  const char *default_log_prefix = ConfigGetLogDirectory();
342  snprintf(out, out_size, "%s/%s", default_log_prefix, log_base_dir);
343  }
344 }
345 
346 static bool InitFilestoreDirectory(const char *dir)
347 {
348  const uint8_t dir_count = 0xff;
349 
350  if (!SCPathExists(dir)) {
351  SCLogInfo("Filestore (v2) creating directory %s", dir);
352  if (SCCreateDirectoryTree(dir, true) != 0) {
354  "Filestore (v2) failed to create directory %s: %s", dir,
355  strerror(errno));
356  return false;
357  }
358  }
359 
360  for (int i = 0; i <= dir_count; i++) {
361  char leaf[PATH_MAX];
362  int n = snprintf(leaf, sizeof(leaf), "%s/%02x", dir, i);
363  if (n < 0 || n >= PATH_MAX) {
365  "Filestore (v2) failed to create leaf directory: "
366  "path too long");
367  return false;
368  }
369  if (!SCPathExists(leaf)) {
370  SCLogInfo("Filestore (v2) creating directory %s", leaf);
371  if (SCDefaultMkDir(leaf) != 0) {
373  "Filestore (v2) failed to create directory %s: %s",
374  leaf, strerror(errno));
375  return false;
376  }
377  }
378  }
379 
380  /* Make sure the tmp directory exists. */
381  char tmpdir[PATH_MAX];
382  int n = snprintf(tmpdir, sizeof(tmpdir), "%s/tmp", dir);
383  if (n < 0 || n >= PATH_MAX) {
385  "Filestore (v2) failed to create tmp directory: path too long");
386  return false;
387  }
388  if (!SCPathExists(tmpdir)) {
389  SCLogInfo("Filestore (v2) creating directory %s", tmpdir);
390  if (SCDefaultMkDir(tmpdir) != 0) {
392  "Filestore (v2) failed to create directory %s: %s", tmpdir,
393  strerror(errno));
394  return false;
395  }
396  }
397 
398  return true;
399 }
400 
401 /** \brief Create a new http log OutputFilestoreCtx.
402  * \param conf Pointer to ConfNode containing this loggers configuration.
403  * \return NULL if failure, OutputFilestoreCtx* to the file_ctx if succesful
404  * */
405 static OutputInitResult OutputFilestoreLogInitCtx(ConfNode *conf)
406 {
407  OutputInitResult result = { NULL, false };
408 
409  intmax_t version = 0;
410  if (!ConfGetChildValueInt(conf, "version", &version) || version < 2) {
412  "File-store v1 been removed. Please update to file-store v2.");
413  return result;
414  }
415 
418  "A file data logger is already enabled. Filestore (v2) "
419  "will not be enabled.");
420  return result;
421  }
422 
423  char log_directory[PATH_MAX] = "";
424  GetLogDirectory(conf, log_directory, sizeof(log_directory));
425  if (!InitFilestoreDirectory(log_directory)) {
426  return result;
427  }
428 
429  OutputFilestoreCtx *ctx = SCCalloc(1, sizeof(*ctx));
430  if (unlikely(ctx == NULL)) {
431  return result;
432  }
433 
434  strlcpy(ctx->prefix, log_directory, sizeof(ctx->prefix));
435  int written = snprintf(ctx->tmpdir, sizeof(ctx->tmpdir) - 1, "%s/tmp",
436  log_directory);
437  if (written == sizeof(ctx->tmpdir)) {
438  SCLogError(SC_ERR_SPRINTF, "File-store output directory overflow.");
439  SCFree(ctx);
440  return result;
441  }
442 
443  ctx->xff_cfg = SCCalloc(1, sizeof(HttpXFFCfg));
444  if (ctx->xff_cfg != NULL) {
445  HttpXFFGetCfg(conf, ctx->xff_cfg);
446  }
447 
448  OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
449  if (unlikely(output_ctx == NULL)) {
450  SCFree(ctx);
451  return result;
452  }
453 
454  output_ctx->data = ctx;
455  output_ctx->DeInit = OutputFilestoreLogDeInitCtx;
456 
457  const char *write_fileinfo = ConfNodeLookupChildValue(conf,
458  "write-fileinfo");
459  if (write_fileinfo != NULL && ConfValIsTrue(write_fileinfo)) {
460  SCLogConfig("Filestore (v2) will output fileinfo records.");
461  ctx->fileinfo = true;
462  }
463 
464  const char *force_filestore = ConfNodeLookupChildValue(conf,
465  "force-filestore");
466  if (force_filestore != NULL && ConfValIsTrue(force_filestore)) {
468  SCLogInfo("forcing filestore of all files");
469  }
470 
471  const char *force_magic = ConfNodeLookupChildValue(conf, "force-magic");
472  if (force_magic != NULL && ConfValIsTrue(force_magic)) {
474  SCLogConfig("Filestore (v2) forcing magic lookup for stored files");
475  }
476 
477  FileForceHashParseCfg(conf);
478 
479  /* The new filestore requires SHA256. */
481 
483 
484  const char *stream_depth_str = ConfNodeLookupChildValue(conf,
485  "stream-depth");
486  if (stream_depth_str != NULL && strcmp(stream_depth_str, "no")) {
487  uint32_t stream_depth = 0;
488  if (ParseSizeStringU32(stream_depth_str,
489  &stream_depth) < 0) {
490  SCLogError(SC_ERR_SIZE_PARSE, "Error parsing "
491  "file-store.stream-depth "
492  "from conf file - %s. Killing engine",
493  stream_depth_str);
494  exit(EXIT_FAILURE);
495  }
496  if (stream_depth) {
497  if (stream_depth <= stream_config.reassembly_depth) {
499  "file-store.stream-depth value %" PRIu32 " has "
500  "no effect since it's less than stream.reassembly.depth "
501  "value.", stream_depth);
502  } else {
503  FileReassemblyDepthEnable(stream_depth);
504  }
505  }
506  }
507 
508  const char *file_count_str = ConfNodeLookupChildValue(conf,
509  "max-open-files");
510  if (file_count_str != NULL) {
511  uint32_t file_count = 0;
512  if (ParseSizeStringU32(file_count_str,
513  &file_count) < 0) {
514  SCLogError(SC_ERR_SIZE_PARSE, "Error parsing "
515  "file-store.max-open-files "
516  "from conf file - %s. Killing engine",
517  file_count_str);
518  exit(EXIT_FAILURE);
519  } else {
520  if (file_count != 0) {
521  FileSetMaxOpenFiles(file_count);
522  SCLogConfig("Filestore (v2) will keep a max of %d "
523  "simultaneously open files", file_count);
524  }
525  }
526  }
527 
528  result.ctx = output_ctx;
529  result.ok = true;
530  SCReturnCT(result, "OutputInitResult");
531 }
532 
534 {
536  OutputFilestoreLogInitCtx, OutputFilestoreLogger,
537  OutputFilestoreLogThreadInit, OutputFilestoreLogThreadDeinit,
538  NULL);
539 
540  SC_ATOMIC_INIT(filestore_open_file_cnt);
541  SC_ATOMIC_SET(filestore_open_file_cnt, 0);
542 }
543 
545 {
546  StatsRegisterGlobalCounter("file_store.open_files", OutputFilestoreOpenFilesCounter);
547 }
SC_ERR_FWRITE
@ SC_ERR_FWRITE
Definition: util-error.h:129
ConfGetChildValueInt
int ConfGetChildValueInt(const ConfNode *base, const char *name, intmax_t *val)
Definition: conf.c:468
OutputFilestoreCtx_::prefix
char prefix[FILESTORE_PREFIX_MAX]
Definition: output-filestore.c:51
O_NOFOLLOW
#define O_NOFOLLOW
Definition: win32-misc.h:30
StatsIncr
void StatsIncr(ThreadVars *tv, uint16_t id)
Increments the local counter.
Definition: counters.c:169
SC_ATOMIC_INIT
#define SC_ATOMIC_INIT(name)
wrapper for initializing an atomic variable.
Definition: util-atomic.h:315
FileReassemblyDepthEnable
void FileReassemblyDepthEnable(uint32_t size)
Definition: util-file.c:128
PKT_IS_IPV6
#define PKT_IS_IPV6(p)
Definition: decode.h:260
stream-tcp.h
unlikely
#define unlikely(expr)
Definition: util-optimize.h:35
SC_ATOMIC_SET
#define SC_ATOMIC_SET(name, val)
Set the value for the atomic variable.
Definition: util-atomic.h:387
SCLogDebug
#define SCLogDebug(...)
Definition: util-debug.h:298
OutputFilestoreCtx_::tmpdir
char tmpdir[FILESTORE_PREFIX_MAX]
Definition: output-filestore.c:52
StatsRegisterGlobalCounter
uint16_t StatsRegisterGlobalCounter(const char *name, uint64_t(*Func)(void))
Registers a counter, which represents a global value.
Definition: counters.c:1000
SC_ERR_NOT_SUPPORTED
@ SC_ERR_NOT_SUPPORTED
Definition: util-error.h:257
OutputFilestoreCtx_::fileinfo
bool fileinfo
Definition: output-filestore.c:53
OutputFilestoreLogThread_::fs_error_counter
uint16_t fs_error_counter
Definition: output-filestore.c:60
TcpStreamCnf_::reassembly_depth
uint32_t reassembly_depth
Definition: stream-tcp.h:60
SC_ATOMIC_ADD
#define SC_ATOMIC_ADD(name, val)
add a value to our atomic variable
Definition: util-atomic.h:333
File_::file_store_id
uint32_t file_store_id
Definition: util-file.h:79
SC_ERR_CREATE_DIRECTORY
@ SC_ERR_CREATE_DIRECTORY
Definition: util-error.h:338
FileForceMagicEnable
void FileForceMagicEnable(void)
Definition: util-file.c:99
OutputFilestoreCtx_::xff_cfg
HttpXFFCfg * xff_cfg
Definition: output-filestore.c:54
stream_config
TcpStreamCnf stream_config
Definition: stream-tcp.c:119
TM_ECODE_FAILED
@ TM_ECODE_FAILED
Definition: tm-threads-common.h:81
OutputFilestoreCtx_
Definition: output-filestore.c:50
OUTPUT_FILEDATA_FLAG_CLOSE
#define OUTPUT_FILEDATA_FLAG_CLOSE
Definition: output-filedata.h:33
ConfValIsTrue
int ConfValIsTrue(const char *val)
Check if a value is true.
Definition: conf.c:565
OutputCtx_::data
void * data
Definition: tm-modules.h:81
TM_ECODE_OK
@ TM_ECODE_OK
Definition: tm-threads-common.h:80
SCDefaultMkDir
int SCDefaultMkDir(const char *path)
Wrapper around SCMkDir with default mode arguments.
Definition: util-path.c:110
OutputCtx_
Definition: tm-modules.h:78
app-layer-htp-xff.h
strlcpy
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition: util-strlcpyu.c:43
OutputFilestoreLogThread_
Definition: output-filestore.c:57
SC_ERR_SIZE_PARSE
@ SC_ERR_SIZE_PARSE
Definition: util-error.h:230
app-layer-htp.h
feature.h
OutputFilestoreCtx
struct OutputFilestoreCtx_ OutputFilestoreCtx
SC_SHA256_LEN
#define SC_SHA256_LEN
Definition: rust.h:31
OutputInitResult_::ctx
OutputCtx * ctx
Definition: output.h:44
File_::fd
int fd
Definition: util-file.h:80
output-json-file.h
util-print.h
SCEnter
#define SCEnter(...)
Definition: util-debug.h:300
ThreadVars_
Per thread variable structure.
Definition: threadvars.h:58
OutputInitResult_::ok
bool ok
Definition: output.h:45
app-layer-parser.h
SC_WARN_RENAMING_FILE
@ SC_WARN_RENAMING_FILE
Definition: util-error.h:336
SC_WARN_DEPRECATED
@ SC_WARN_DEPRECATED
Definition: util-error.h:235
OutputFilestoreRegister
void OutputFilestoreRegister(void)
Definition: output-filestore.c:533
SC_ATOMIC_SUB
#define SC_ATOMIC_SUB(name, val)
sub a value from our atomic variable
Definition: util-atomic.h:342
SC_ATOMIC_DECLARE
#define SC_ATOMIC_DECLARE(type, name)
wrapper for declaring atomic variables.
Definition: util-atomic.h:281
Packet_
Definition: decode.h:414
SC_ERR_SPRINTF
@ SC_ERR_SPRINTF
Definition: util-error.h:42
TmEcode
TmEcode
Definition: tm-threads-common.h:79
HttpXFFCfg_
Definition: app-layer-htp-xff.h:41
SC_WARN_REMOVE_FILE
@ SC_WARN_REMOVE_FILE
Definition: util-error.h:325
OutputFilestoreLogThread_::counter_max_hits
uint16_t counter_max_hits
Definition: output-filestore.c:59
SCLogInfo
#define SCLogInfo(...)
Macro used to log INFORMATIONAL messages.
Definition: util-debug.h:217
FILESTORE_PREFIX_MAX
#define FILESTORE_PREFIX_MAX
Definition: output-filestore.c:41
JsonBuildFileInfoRecord
JsonBuilder * JsonBuildFileInfoRecord(const Packet *p, const File *ff, const bool stored, uint8_t dir, HttpXFFCfg *xff_cfg, OutputJsonCtx *eve_ctx)
Definition: output-json-file.c:84
SCPathExists
bool SCPathExists(const char *path)
Check if a path exists.
Definition: util-path.c:170
File_
Definition: util-file.h:72
OutputInitResult_
Definition: output.h:43
Packet_::flow
struct Flow_ * flow
Definition: decode.h:451
FEATURE_OUTPUT_FILESTORE
#define FEATURE_OUTPUT_FILESTORE
Definition: feature.h:28
OutputRegisterFiledataModule
void OutputRegisterFiledataModule(LoggerId id, const char *name, const char *conf_name, OutputInitFunc InitFunc, FiledataLogger FiledataLogFunc, ThreadInitFunc ThreadInit, ThreadDeinitFunc ThreadDeinit, ThreadExitPrintStatsFunc ThreadExitPrintStats)
Register a file data output module.
Definition: output.c:506
WARN_ONCE
#define WARN_ONCE(err_code,...)
Definition: output-filestore.c:67
flags
uint8_t flags
Definition: decode-gre.h:0
Packet_::ts
struct timeval ts
Definition: decode.h:457
suricata-common.h
FileForceFilestoreEnable
void FileForceFilestoreEnable(void)
Definition: util-file.c:93
OutputCtx_::DeInit
void(* DeInit)(struct OutputCtx_ *)
Definition: tm-modules.h:84
OUTPUT_FILEDATA_FLAG_OPEN
#define OUTPUT_FILEDATA_FLAG_OPEN
Definition: output-filedata.h:32
FileForceHashParseCfg
void FileForceHashParseCfg(ConfNode *conf)
Function to parse forced file hashing configuration.
Definition: util-file.c:171
PathIsAbsolute
int PathIsAbsolute(const char *path)
Check if a path is absolute.
Definition: util-path.c:45
SCLogError
#define SCLogError(err_code,...)
Macro used to log ERROR messages.
Definition: util-debug.h:257
version
uint8_t version
Definition: decode-gre.h:1
output-filestore.h
tv
ThreadVars * tv
Definition: fuzz_decodepcapfile.c:29
File_::sha256
uint8_t sha256[SC_SHA256_LEN]
Definition: util-file.h:92
ParseSizeStringU32
int ParseSizeStringU32(const char *size, uint32_t *res)
Definition: util-misc.c:183
SCMalloc
#define SCMalloc(sz)
Definition: util-mem.h:47
SCLogConfig
struct SCLogConfig_ SCLogConfig
Holds the config state used by the logging api.
MODULE_NAME
#define MODULE_NAME
Definition: output-filestore.c:35
str
#define str(s)
Definition: suricata-common.h:268
ConfigGetLogDirectory
const char * ConfigGetLogDirectory()
Definition: util-conf.c:35
SCLogWarning
#define SCLogWarning(err_code,...)
Macro used to log WARNING messages.
Definition: util-debug.h:244
SCFree
#define SCFree(p)
Definition: util-mem.h:61
ConfNode_
Definition: conf.h:32
OutputFilestoreLogThread
struct OutputFilestoreLogThread_ OutputFilestoreLogThread
SC_ERR_MAX
@ SC_ERR_MAX
Definition: util-error.h:373
LOGGER_FILE_STORE
@ LOGGER_FILE_STORE
Definition: suricata-common.h:475
ProvidesFeature
void ProvidesFeature(const char *feature_name)
Definition: feature.c:109
SCReturnCT
#define SCReturnCT(x, type)
Definition: util-debug.h:314
OutputFilestoreLogThread_::ctx
OutputFilestoreCtx * ctx
Definition: output-filestore.c:58
HttpXFFGetCfg
void HttpXFFGetCfg(ConfNode *conf, HttpXFFCfg *result)
Function to return XFF configuration from a configuration node.
Definition: app-layer-htp-xff.c:202
likely
#define likely(expr)
Definition: util-optimize.h:32
RunModeOutputFiledataEnabled
int RunModeOutputFiledataEnabled(void)
Definition: runmodes.c:499
OutputFilestoreRegisterGlobalCounters
void OutputFilestoreRegisterGlobalCounters(void)
Definition: output-filestore.c:544
SC_WARN_FILESTORE_CONFIG
@ SC_WARN_FILESTORE_CONFIG
Definition: util-error.h:364
app-layer-smtp.h
FileForceSha256Enable
void FileForceSha256Enable(void)
Definition: util-file.c:117
SC_ATOMIC_GET
#define SC_ATOMIC_GET(name)
Get the value from the atomic variable.
Definition: util-atomic.h:376
util-misc.h
StatsRegisterCounter
uint16_t StatsRegisterCounter(const char *name, struct ThreadVars_ *tv)
Registers a normal, unqualified counter.
Definition: counters.c:942
SCCalloc
#define SCCalloc(nm, sz)
Definition: util-mem.h:53
SCReturnInt
#define SCReturnInt(x)
Definition: util-debug.h:304
PKT_IS_IPV4
#define PKT_IS_IPV4(p)
Definition: decode.h:259
SC_ERR_OPENING_FILE
@ SC_ERR_OPENING_FILE
Definition: util-error.h:70
output.h
SCCreateDirectoryTree
int SCCreateDirectoryTree(const char *path, const bool final)
Recursively create a directory.
Definition: util-path.c:124
ConfNodeLookupChildValue
const char * ConfNodeLookupChildValue(const ConfNode *node, const char *name)
Lookup the value of a child configuration node by name.
Definition: conf.c:842