template: fix setup detect script

pull/2900/head
Victor Julien 9 years ago
parent 05d3a4db90
commit 7783847467

@ -7,15 +7,16 @@ set -e
function usage() { function usage() {
cat <<EOF cat <<EOF
usage: $0 <protocol name> usage: $0 <protocol name> <buffer name>
This script will provision content inspection for app-layer decoded This script will provision content inspection for app-layer decoded
buffers. buffers.
Examples: Examples:
$0 DNP3 $0 Gopher Buffer
$0 Gopher $0 DNP3 Buffer
$0 Http Etag
EOF EOF
} }
@ -35,110 +36,33 @@ function copy_template_file() {
echo "Creating ${dst}." echo "Creating ${dst}."
sed -e '/TEMPLATE_START_REMOVE/,/TEMPLATE_END_REMOVE/d' \ 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/${protoname_upper}/g" \
-e "s/template-buffer/${protoname_lower}-${buffername_lower}/g" \
-e "s/template/${protoname_lower}/g" \ -e "s/template/${protoname_lower}/g" \
-e "s/TemplateBuffer/${protoname}${buffername}/g" \
-e "s/Template/${protoname}/g" \ -e "s/Template/${protoname}/g" \
> ${dst} < ${src} > ${dst} < ${src}
} }
function copy_templates() { function copy_templates() {
detect_h_dst="src/detect-${protoname_lower}-buffer.h" detect_h_dst="src/detect-${protoname_lower}-${buffername_lower}.h"
detect_c_dst="src/detect-${protoname_lower}-buffer.c" detect_c_dst="src/detect-${protoname_lower}-${buffername_lower}.c"
detect_engine_h_dst="src/detect-engine-${protoname_lower}.h"
detect_engine_c_dst="src/detect-engine-${protoname_lower}.c"
fail_if_exists ${detect_h_dst} fail_if_exists ${detect_h_dst}
fail_if_exists ${detect_c_dst} fail_if_exists ${detect_c_dst}
fail_if_exists ${detect_engine_h_dst}
fail_if_exists ${detect_engine_c_dst}
copy_template_file "src/detect-template-buffer.h" ${detect_h_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/detect-template-buffer.c" ${detect_c_dst}
copy_template_file "src/detect-engine-template.h" ${detect_engine_h_dst}
copy_template_file "src/detect-engine-template.c" ${detect_engine_c_dst}
} }
function patch_makefile_am() { function patch_makefile_am() {
filename="src/Makefile.am" filename="src/Makefile.am"
echo "Patching ${filename}." echo "Patching ${filename}."
ed -s ${filename} > /dev/null <<EOF ed -s ${filename} > /dev/null <<EOF
/^detect-engine-template.c
t-
s/template/${protoname_lower}/g
/^detect-template-buffer.c /^detect-template-buffer.c
t- t-
s/template/${protoname_lower}/g s/template-buffer/${protoname_lower}-${buffername_lower}/g
w
EOF
}
function patch_detect_engine_content_inspection_h() {
filename="src/detect-engine-content-inspection.h"
echo "Patching ${filename}."
ed -s ${filename} > /dev/null <<EOF
/DETECT_ENGINE_CONTENT_INSPECTION_MODE_TEMPLATE_BUFFER
t-
s/TEMPLATE/${protoname_upper}/
w
EOF
}
function patch_detect_engine_state_h() {
filename="src/detect-engine-state.h"
echo "Patching ${filename}."
ed -s ${filename} > /dev/null <<EOF
/#define DE_STATE_FLAG_TEMPLATE_BUFFER_INSPECT
t-
s/TEMPLATE/${protoname_upper}/
w
EOF
}
function patch_detect_engine_c() {
filename="src/detect-engine.c"
echo "Patching ${filename}."
ed -s ${filename} > /dev/null <<EOF
/#include "detect-engine-template.h"
t-
s/template/${protoname_lower}/
w
/ALPROTO_TEMPLATE
-2
.,+6t-
-6
.,+6s/Template/${protoname}/g
-6
.,+6s/TEMPLATE/${protoname_upper}/g
+6
/ALPROTO_TEMPLATE
-2
.,+6t-
-6
.,+6s/Template/${protoname}/g
-6
.,+6s/TEMPLATE/${protoname_upper}/g
w
EOF
ed -s ${filename} > /dev/null <<EOF
/case DETECT_SM_LIST_TEMPLATE_BUFFER_MATCH
.,+1t-
-
s/TEMPLATE/${protoname_upper}/g
+
s/template/${protoname_lower}/g
w
EOF
}
function patch_detect_parse_c() {
filename="src/detect-parse.c"
echo "Patching ${filename}."
ed -s ${filename} > /dev/null <<EOF
/\/\* Template\. \*\/
.,+4t-
-4s/Template/${protoname}/g
+1s/TEMPLATE/${protoname_upper}/g
w w
EOF EOF
} }
@ -149,7 +73,7 @@ function patch_detect_c() {
ed -s ${filename} > /dev/null <<EOF ed -s ${filename} > /dev/null <<EOF
/#include "detect-template-buffer.h" /#include "detect-template-buffer.h"
t- t-
s/template/${protoname_lower}/ s/template-buffer/${protoname_lower}-${buffername_lower}/
/case ALPROTO_TEMPLATE /case ALPROTO_TEMPLATE
.,+3t- .,+3t-
-3 -3
@ -171,7 +95,7 @@ s/template/${protoname_lower}/g
s/TEMPLATE/${protoname_upper}/g s/TEMPLATE/${protoname_upper}/g
/DetectTemplateBufferRegister /DetectTemplateBufferRegister
t- t-
s/Template/${protoname}/ s/TemplateBuffer/${protoname}${buffername}/
w w
EOF EOF
} }
@ -179,36 +103,37 @@ EOF
function patch_detect_h() { function patch_detect_h() {
filename="src/detect.h" filename="src/detect.h"
echo "Patching ${filename}." echo "Patching ${filename}."
ed -s ${filename} > /dev/null <<EOF if [ $(grep -c SIG_MASK_REQUIRE_${protoname_upper}_STATE ${filename}) -eq 0 ]; then
/DETECT_SM_LIST_TEMPLATE_BUFFER_MATCH ed -s ${filename} > /dev/null <<EOF
t-
s/TEMPLATE/${protoname_upper}/
/SIG_MASK_REQUIRE_TEMPLATE_STATE /SIG_MASK_REQUIRE_TEMPLATE_STATE
t- t-
s/TEMPLATE/${protoname_upper}/ s/TEMPLATE/${protoname_upper}/
w
EOF
fi
ed -s ${filename} > /dev/null <<EOF
/DETECT_AL_TEMPLATE_BUFFER /DETECT_AL_TEMPLATE_BUFFER
t- t-
s/TEMPLATE/${protoname_upper}/ s/TEMPLATE_BUFFER/${protoname_upper}_${buffername_upper}/
w w
EOF EOF
} }
protoname="$1" protoname="$1"
buffername="$2"
if [ "${protoname}" = "" ]; then if [ "${protoname}" = "" ] || [ "${buffername}" = "" ]; then
usage usage
exit 1 exit 1
fi fi
protoname_lower=$(printf ${protoname} | tr '[:upper:]' '[:lower:]') protoname_lower=$(printf ${protoname} | tr '[:upper:]' '[:lower:]')
protoname_upper=$(printf ${protoname} | tr '[:lower:]' '[:upper:]') protoname_upper=$(printf ${protoname} | tr '[:lower:]' '[:upper:]')
buffername_lower=$(printf ${buffername} | tr '[:upper:]' '[:lower:]')
buffername_upper=$(printf ${buffername} | tr '[:lower:]' '[:upper:]')
copy_templates copy_templates
patch_makefile_am patch_makefile_am
patch_detect_engine_content_inspection_h
patch_detect_engine_state_h
patch_detect_engine_c
patch_detect_parse_c
patch_detect_c patch_detect_c
patch_detect_h patch_detect_h
@ -216,17 +141,9 @@ cat <<EOF
The following files have been created and linked into the build: The following files have been created and linked into the build:
detect-${protoname_lower}-buffer.h detect-${protoname_lower}-buffer.c detect-${protoname_lower}-${buffername_lower}.h detect-${protoname_lower}-${buffername_lower}.c
The setup for the content inspection modifier keyword.
detect-engine-${protoname_lower}.h detect-engine-${protoname_lower}.c
The content inspection engine.
Please fix in src/detect-engine-state.h the values for: The setup for the content inspection sticky buffer keyword.
DE_STATE_FLAG_${protoname_upper}_BUFFER_INSPECT
DE_STATE_FLAG_TEMPLATE_BUFFER_INSPECT
Please fix in src/detect.h the values for: Please fix in src/detect.h the values for:
SIG_MASK_REQUIRE_${protoname_upper}_STATE SIG_MASK_REQUIRE_${protoname_upper}_STATE

Loading…
Cancel
Save