#! /usr/bin/env bash # # Script to provision a new application layer detector and parser. set -e # Fail if "ed" is not available. if ! which ed > /dev/null 2>&1; then echo "error: the program \"ed\" is required for this script" exit 1 fi function usage() { cat < This script will provision content inspection for app-layer decoded buffers. Examples: $0 Gopher Buffer $0 DNP3 Buffer $0 Http Etag EOF } # Make sure we are running from the correct directory. set_dir() { if [ -e ./suricata.c ]; then cd .. elif [ -e ./src/suricata.c ]; then # Do nothing. true else echo "error: this does not appear to be a suricata source directory." exit 1 fi } fail_if_exists() { path="$1" if test -e "${path}"; then echo "error: ${path} already exists." exit 1 fi } function copy_template_file() { src="$1" dst="$2" echo "Creating ${dst}." sed -e '/TEMPLATE_START_REMOVE/,/TEMPLATE_END_REMOVE/d' \ -e "s/TEMPLATE_BUFFER/${protoname_upper}_${buffername_upper}/g" \ -e "s/TEMPLATE/${protoname_upper}/g" \ -e "s/template-buffer/${protoname_lower}-${buffername_lower}/g" \ -e "s/template/${protoname_lower}/g" \ -e "s/TemplateBuffer/${protoname}${buffername}/g" \ -e "s/Template/${protoname}/g" \ > ${dst} < ${src} } function copy_templates() { detect_h_dst="src/detect-${protoname_lower}-${buffername_lower}.h" detect_c_dst="src/detect-${protoname_lower}-${buffername_lower}.c" tests_detect_c_dst="src/tests/detect-${protoname_lower}-${buffername_lower}.c" fail_if_exists ${detect_h_dst} fail_if_exists ${detect_c_dst} fail_if_exists ${tests_detect_c_dst} copy_template_file "src/detect-template-buffer.h" ${detect_h_dst} copy_template_file "src/detect-template-buffer.c" ${detect_c_dst} copy_template_file "src/tests/detect-template-buffer.c" ${tests_detect_c_dst} } function patch() { filename="src/Makefile.am" echo "Patching ${filename}." ed -s ${filename} > /dev/null < /dev/null < /dev/null < /dev/null <