From 90620cb64fc2b8490be359fe005af8d129c6e8e7 Mon Sep 17 00:00:00 2001 From: Jon Tourville Date: Thu, 14 Oct 2021 12:38:27 -0500 Subject: [PATCH] Generate af_names.h similar to cap_names.h --- .gitignore | 1 + parser/Makefile | 18 ++++++++++++----- parser/base_af_names.h | 45 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 5 deletions(-) create mode 100644 parser/base_af_names.h diff --git a/.gitignore b/.gitignore index ca08bffd9..78a06fdf9 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,7 @@ parser/po/*.mo parser/af_names.h parser/cap_names.h parser/generated_cap_names.h +parser/generated_af_names.h parser/tst_lib parser/tst_misc parser/tst_regex diff --git a/parser/Makefile b/parser/Makefile index 7871a9d9b..d7966a14b 100644 --- a/parser/Makefile +++ b/parser/Makefile @@ -307,10 +307,18 @@ parser_version.h: Makefile # as well as the filtering that occurs for network protocols that # apparmor should not mediate. -af_names.h: ../common/list_af_names.sh - ../common/list_af_names.sh | LC_ALL=C sed -n -e 's/[ \t]\?AF_MAX[ \t]\+[0-9]\+,//g' -e 's/[ \t]\+\?AF_\([A-Z0-9_]\+\)[ \t]\+\([0-9]\+\),/#ifndef AF_\1\n# define AF_\1 \2\n#endif\nAA_GEN_NET_ENT("\L\1", \UAF_\1)\n/pg' > $@ - ../common/list_af_names.sh | LC_ALL=C sed -n -e 's/AF_MAX[ \t]\+\([0-9]\+\),\?.*/\n#define AA_AF_MAX \1\n/p' >> $@ - # cat $@ +generated_af_names.h: ../common/list_af_names.sh + ../common/list_af_names.sh > $@ + +af_names.h: generated_af_names.h base_af_names.h + cat base_af_names.h | diff -u - generated_af_names.h | grep -v '^.AF_MAX' | grep '^\+[^+]' ; \ + if [ $$? -eq 1 ] ; then \ + cat base_af_names.h | LC_ALL=C sed -n -e 's/[ \t]\?AF_MAX[ \t]\+[0-9]\+,//g' -e 's/[ \t]\+\?AF_\([A-Z0-9_]\+\)[ \t]\+\([0-9]\+\),/#ifndef AF_\1\n# define AF_\1 \2\n#endif\nAA_GEN_NET_ENT("\L\1", \UAF_\1)\n/pg' > $@ ; \ + cat base_af_names.h | LC_ALL=C sed -n -e 's/AF_MAX[ \t]\+\([0-9]\+\),\?.*/\n#define AA_AF_MAX \1\n/p' >> $@ ; \ + else \ + echo "Error: new AF names detected; please update base_af_names.h with values from generated_af_names.h" ; \ + exit 1 ; \ + fi generated_cap_names.h: /usr/include/linux/capability.h ../common/list_capabilities.sh | LC_ALL=C sed -n -e "s/[ \\t]\\?CAP_\\([A-Z0-9_]\\+\\)/\{\"\\L\\1\", \\UCAP_\\1, NO_BACKMAP_CAP, CAPFLAG_BASE_FEATURE\},\\n/pg" > $@ @@ -434,7 +442,7 @@ clean: pod_clean rm -f $(YACC_C_FILES) rm -f parser_version.h rm -f $(NAME)*.tar.gz $(NAME)*.tgz - rm -f af_names.h + rm -f af_names.h generated_af_names.h rm -f cap_names.h generated_cap_names.h rm -rf techdoc.aux techdoc.out techdoc.log techdoc.pdf techdoc.toc techdoc.txt techdoc/ $(MAKE) -s -C $(AAREDIR) clean diff --git a/parser/base_af_names.h b/parser/base_af_names.h new file mode 100644 index 000000000..32e1ca758 --- /dev/null +++ b/parser/base_af_names.h @@ -0,0 +1,45 @@ +AF_UNSPEC 0, +AF_UNIX 1, +AF_INET 2, +AF_AX25 3, +AF_IPX 4, +AF_APPLETALK 5, +AF_NETROM 6, +AF_BRIDGE 7, +AF_ATMPVC 8, +AF_X25 9, +AF_INET6 10, +AF_ROSE 11, +AF_NETBEUI 13, +AF_SECURITY 14, +AF_KEY 15, +AF_NETLINK 16, +AF_PACKET 17, +AF_ASH 18, +AF_ECONET 19, +AF_ATMSVC 20, +AF_RDS 21, +AF_SNA 22, +AF_IRDA 23, +AF_PPPOX 24, +AF_WANPIPE 25, +AF_LLC 26, +AF_IB 27, +AF_MPLS 28, +AF_CAN 29, +AF_TIPC 30, +AF_BLUETOOTH 31, +AF_IUCV 32, +AF_RXRPC 33, +AF_ISDN 34, +AF_PHONET 35, +AF_IEEE802154 36, +AF_CAIF 37, +AF_ALG 38, +AF_NFC 39, +AF_VSOCK 40, +AF_KCM 41, +AF_QIPCRTR 42, +AF_SMC 43, +AF_XDP 44, +AF_MAX 45,