/src/detect-file-data.c

https://github.com/decanio/suricata-tilera · C · 84 lines · 38 code · 10 blank · 36 comment · 3 complexity · 3b895c0a4136b9b02c6eeee7a597864a MD5 · raw file

  1. /* Copyright (C) 2007-2011 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. * \file
  19. *
  20. * \author Victor Julien <victor@inliniac.net>
  21. *
  22. */
  23. #include "suricata-common.h"
  24. #include "threads.h"
  25. #include "debug.h"
  26. #include "decode.h"
  27. #include "detect.h"
  28. #include "detect-parse.h"
  29. #include "detect-engine.h"
  30. #include "detect-engine-mpm.h"
  31. #include "detect-engine-state.h"
  32. #include "flow.h"
  33. #include "flow-var.h"
  34. #include "flow-util.h"
  35. #include "util-debug.h"
  36. #include "util-spm-bm.h"
  37. #include "util-unittest.h"
  38. #include "util-unittest-helper.h"
  39. static int DetectFiledataSetup (DetectEngineCtx *, Signature *, char *);
  40. /**
  41. * \brief Registration function for keyword: file_data
  42. */
  43. void DetectFiledataRegister(void) {
  44. sigmatch_table[DETECT_FILE_DATA].name = "file_data";
  45. sigmatch_table[DETECT_FILE_DATA].desc = "make content keywords match on HTTP response body";
  46. sigmatch_table[DETECT_FILE_DATA].url = "https://redmine.openinfosecfoundation.org/projects/suricata/wiki/HTTP-keywords#file_data";
  47. sigmatch_table[DETECT_FILE_DATA].Match = NULL;
  48. sigmatch_table[DETECT_FILE_DATA].AppLayerMatch = NULL;
  49. sigmatch_table[DETECT_FILE_DATA].alproto = ALPROTO_HTTP;
  50. sigmatch_table[DETECT_FILE_DATA].Setup = DetectFiledataSetup;
  51. sigmatch_table[DETECT_FILE_DATA].Free = NULL;
  52. sigmatch_table[DETECT_FILE_DATA].RegisterTests = NULL;
  53. }
  54. /**
  55. * \brief this function is used to parse filedata options
  56. * \brief into the current signature
  57. *
  58. * \param de_ctx pointer to the Detection Engine Context
  59. * \param s pointer to the Current Signature
  60. * \param str pointer to the user provided "filestore" option
  61. *
  62. * \retval 0 on Success
  63. * \retval -1 on Failure
  64. */
  65. static int DetectFiledataSetup (DetectEngineCtx *de_ctx, Signature *s, char *str)
  66. {
  67. SCEnter();
  68. if ((s->init_flags & SIG_FLAG_INIT_FLOW) && (s->flags & SIG_FLAG_TOSERVER) && !(s->flags & SIG_FLAG_TOCLIENT)) {
  69. SCLogError(SC_ERR_INVALID_SIGNATURE, "Can't use file_data with flow:to_server or from_client with http.");
  70. return -1;
  71. }
  72. s->init_flags |= SIG_FLAG_INIT_FILE_DATA;
  73. return 0;
  74. }