aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSven Vermeulen <sven.vermeulen@siphos.be>2018-03-25 13:56:35 +0200
committerJason Zaman <jason@perfinion.com>2018-06-14 17:37:51 +0800
commitec003f77c768623d7ff75c797524ce69ffb8e54b (patch)
tree7a3a8b0498f0be53ed65e279dd335cadd9f8a9ac /support
parentcolord, dirmngr, gpg, portage, redis: Module version bump. (diff)
downloadhardened-refpolicy-ec003f77c768623d7ff75c797524ce69ffb8e54b.tar.gz
hardened-refpolicy-ec003f77c768623d7ff75c797524ce69ffb8e54b.tar.bz2
hardened-refpolicy-ec003f77c768623d7ff75c797524ce69ffb8e54b.zip
Add gentemplates.sh to extract template content
Some of the templates in the reference policy generate new booleans and tunables, based on the $1, $2, ... parameters passed on. To allow segenxml, which generates the necessary documentation on booleans, to keep track of template-generated booleans as well, we need to allow it to substitute template calls with the actual template content. The gentemplates.sh script is a helper script that will extract template code and store it as files (one file per template). These files are then later on used by the segenxml tool. Signed-off-by: Sven Vermeulen <sven.vermeulen@siphos.be>
Diffstat (limited to 'support')
-rwxr-xr-xsupport/gentemplates.sh62
1 files changed, 62 insertions, 0 deletions
diff --git a/support/gentemplates.sh b/support/gentemplates.sh
new file mode 100755
index 000000000..7f20505ee
--- /dev/null
+++ b/support/gentemplates.sh
@@ -0,0 +1,62 @@
+#!/bin/sh
+
+showHelp() {
+ echo "Usage: $(basename $0) --generate --sourcedir=<sourcedir> --targetdir=<targetdir>"
+ echo " $(basename $0) -g -s <sourcedir> -t <targetdir>"
+ echo "";
+ echo "The $(basename $0) script will fetch all template definitions from the interface files"
+ echo "located in the selected source directory, and write one file per template into the"
+ echo "target directory."
+ echo "";
+ echo "Supported options:"
+ echo " --generate (-g) Generate template files"
+ echo " --sourcedir=<sourcedir> (-s <sourcedir>)"
+ echo " Source directory to recursively search for interfaces/templates"
+ echo " --targetdir=<targetdir> (-t <targetdir>)"
+ echo " Target directory to store template definitions in"
+}
+
+flagGenerate=0;
+SOURCEDIR="";
+TARGETDIR="";
+
+params=$(getopt -n $(basename $0) -s sh -o gs:t: --long generate,sourcedir:,targetdir: -- "$@")
+if [ $? -ne 0 ] ; then
+ showHelp;
+ exit 1;
+fi
+
+eval set -- "${params}"
+while [ $# -gt 0 ] ; do
+ case "$1" in
+ (-g) flagGenerate=1;;
+ (-s) SOURCEDIR="$2"; shift;;
+ (-t) TARGETDIR="$2"; shift;;
+ (--) break;;
+ (-*) echo "$(basename $0): error: Unrecognized option $1" 1>&2; exit 1;;
+ (*) break;;
+ esac
+ shift;
+done
+
+if [ ${flagGenerate} -ne 1 ] || [ -z "${SOURCEDIR}" ] || [ -z "${TARGETDIR}" ] ; then
+ showHelp;
+ exit 1;
+fi
+
+if [ ! -d "${SOURCEDIR}" ] ; then
+ echo "Directory ${SOURCEDIR} does not exist"
+ exit 2;
+fi
+
+if [ ! -d "${TARGETDIR}" ] ; then
+ echo "Directory ${TARGETDIR} does not exist"
+ exit 3;
+fi
+
+for ifile in $(find ${SOURCEDIR} -type f -name '*.if'); do
+ for interface in $(grep -E '^template\(' ${ifile} | sed -e 's:^template(`\([^'\'']*\)'\''\s*,\s*`:\1:g'); do
+ # Generate the interface
+ sed -n "/^template(\`${interface}',\`/,/^')/p" ${ifile} | grep -v "^template" | grep -v "^')" > ${TARGETDIR}/${interface}.iftemplate;
+ done
+done