aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorDavid M. Syzdek <syzdek@bindlebinaries.com>2019-07-29 13:04:45 -0800
committerDavid M. Syzdek <syzdek@bindlebinaries.com>2019-07-29 13:17:51 -0800
commitcad847792846d88248e22e96ceb94750962fc342 (patch)
tree821a7771b7571a64aa3222b177c559e8e75edef3
parent5584e1f6d273fbd30a2e8c6b46e8abf00ac53563 (diff)
downloadbbfw-cad847792846d88248e22e96ceb94750962fc342.tar.gz
bbfw-cad847792846d88248e22e96ceb94750962fc342.tar.bz2
bbfw-cad847792846d88248e22e96ceb94750962fc342.tar.xz
bbfw-cad847792846d88248e22e96ceb94750962fc342.zip
Adding initial support for bbfw.conf
-rw-r--r--Makefile.am6
-rw-r--r--src/bbfw.conf-example.in37
-rwxr-xr-xsrc/bbfw.in93
3 files changed, 107 insertions, 29 deletions
diff --git a/Makefile.am b/Makefile.am
index 2935dc7..17d604b 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -91,6 +91,7 @@ EXTRA_DIST = \
91 doc/slack-desc \ 91 doc/slack-desc \
92 src/bbfw.in \ 92 src/bbfw.in \
93 src/bbfw-log.in \ 93 src/bbfw-log.in \
94 src/bbfw.conf-example.in \
94 src/firewall.d/global.d/rules-example \ 95 src/firewall.d/global.d/rules-example \
95 src/firewall.d/global.d/rules4-example \ 96 src/firewall.d/global.d/rules4-example \
96 src/firewall.d/global.d/rules6-example \ 97 src/firewall.d/global.d/rules6-example \
@@ -107,6 +108,7 @@ CLEANFILES = \
107 config.h.in~ $(srcdir)/config.h.in~ \ 108 config.h.in~ $(srcdir)/config.h.in~ \
108 $(man_MANS) \ 109 $(man_MANS) \
109 $(pkgdata_DATA) \ 110 $(pkgdata_DATA) \
111 $(sysconf_DATA) \
110 $(bin_SCRIPTS) \ 112 $(bin_SCRIPTS) \
111 $(sbin_SCRIPTS) \ 113 $(sbin_SCRIPTS) \
112 $(slackrcd_SCRIPTS) \ 114 $(slackrcd_SCRIPTS) \
@@ -126,6 +128,7 @@ DISTCHECK_CONFIGURE_FLAGS = \
126 128
127# conditional targets for slackware 129# conditional targets for slackware
128if ENABLE_EXAMPLES 130if ENABLE_EXAMPLES
131sysconf_DATA = src/bbfw.conf-example
129firewallglobal_DATA = src/firewall.d/global.d/rules-example \ 132firewallglobal_DATA = src/firewall.d/global.d/rules-example \
130 src/firewall.d/global.d/rules4-example \ 133 src/firewall.d/global.d/rules4-example \
131 src/firewall.d/global.d/rules6-example \ 134 src/firewall.d/global.d/rules6-example \
@@ -160,6 +163,9 @@ include $(srcdir)/@bindletools_srcdir@/build-aux/makefile-version.am
160src/bbfw: Makefile src/bbfw.in 163src/bbfw: Makefile src/bbfw.in
161 @$(do_subst_fn) 164 @$(do_subst_fn)
162 165
166src/bbfw.conf-example: Makefile src/bbfw.conf-example.in
167 @$(do_subst_dt)
168
163src/bbfw-log: Makefile src/bbfw-log.in 169src/bbfw-log: Makefile src/bbfw-log.in
164 @$(do_subst_fn) 170 @$(do_subst_fn)
165 171
diff --git a/src/bbfw.conf-example.in b/src/bbfw.conf-example.in
new file mode 100644
index 0000000..ec70086
--- /dev/null
+++ b/src/bbfw.conf-example.in
@@ -0,0 +1,37 @@
1#
2# Bindle Binaries Linux Firewall
3# Copyright (c) 2019 David M. Syzdek <david@syzdek.net>.
4#
5# Redistribution and use in source and binary forms, with or without
6# modification, are permitted provided that the following conditions are
7# met:
8#
9# * Redistributions of source code must retain the above copyright
10# notice, this list of conditions and the following disclaimer.
11# * Redistributions in binary form must reproduce the above copyright
12# notice, this list of conditions and the following disclaimer in the
13# documentation and/or other materials provided with the distribution.
14# * Neither the name of David M. Syzdek nor the
15# names of its contributors may be used to endorse or promote products
16# derived from this software without specific prior written permission.
17#
18# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
19# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DAVID M. SYZDEK BE LIABLE FOR
22# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28# SUCH DAMAGE.
29
30
31# The `firewall_dir` option overrides the default directory used to store
32# firewall rules, ipset files, and pre/post hooks. Uncomment the line below
33# to change the default location of the firewall rules.
34# firewall_dir = @sysconfdir@/firewall.d
35
36
37# end of configuration
diff --git a/src/bbfw.in b/src/bbfw.in
index fbd561b..60ea7b1 100755
--- a/src/bbfw.in
+++ b/src/bbfw.in
@@ -79,6 +79,7 @@ export PATH
79 79
80# determine prefix of conf files 80# determine prefix of conf files
81FW_PREFIX=@sysconfdir@/firewall.d/ 81FW_PREFIX=@sysconfdir@/firewall.d/
82FW_CONF=@sysconfdir@/bbfw.conf
82 83
83 84
84########### 85###########
@@ -113,6 +114,29 @@ clean_file()
113} 114}
114 115
115 116
117config_option()
118{
119 if test ! -f "${FW_CONF}";then
120 return 0
121 fi
122 TMP_STR="$(
123 egrep \
124 -i \
125 "^[[:space:]]{0,}${1}[[:space:]]{0,}=" \
126 "${FW_CONF}" \
127 |sed \
128 -e "s/^[[:space:]]\{0,\}${1}[[:space:]]\{0,\}=[[:space:]]\{0,\}//g" \
129 -e "s/[[:space:]]\{0,\}$//g" \
130 |tr "${3:-0}" "${4:-0}"
131 )"
132 if test -z "${TMP_STR}";then
133 echo "${2}"
134 else
135 echo "${TMP_STR}"
136 fi
137}
138
139
116dump() 140dump()
117{ 141{
118 ipset list |sed -e "s/^/ipset: /g" 142 ipset list |sed -e "s/^/ipset: /g"
@@ -139,9 +163,9 @@ name_appfile()
139find_appfile() 163find_appfile()
140{ 164{
141 find -L \ 165 find -L \
142 /etc/firewall.d/apps.d/ \ 166 ${FW_PREFIX}/apps.d/ \
143 -regextype posix-extended \ 167 -regextype posix-extended \
144 -regex "^/etc/firewall.d/apps.d/[-.a-zA-Z0-9]+[./]${1}$" \ 168 -regex "^${FW_PREFIX}/apps.d/[-.a-zA-Z0-9]+[./]${1}$" \
145 -type f \ 169 -type f \
146 2> /dev/null 170 2> /dev/null
147} 171}
@@ -191,20 +215,20 @@ load()
191# Function to start the network: 215# Function to start the network:
192start() { 216start() {
193 # run pre-hooks 217 # run pre-hooks
194 run_hook start ${FW_PREFIX}global.d/pre-hook "running global pre-hook start ..." 218 run_hook start ${FW_PREFIX}/global.d/pre-hook "running global pre-hook start ..."
195 for FILE in $( find_appfile pre-hook );do 219 for FILE in $( find_appfile pre-hook );do
196 run_hook start ${FILE} "running app pre-hook start (App: $(name_appfile ${FILE})) ..." 220 run_hook start ${FILE} "running app pre-hook start (App: $(name_appfile ${FILE})) ..."
197 done 221 done
198 run_hook start ${FW_PREFIX}cluster.d/pre-hook "running cluster pre-hook start ..." 222 run_hook start ${FW_PREFIX}/cluster.d/pre-hook "running cluster pre-hook start ..."
199 run_hook start ${FW_PREFIX}pre-hook "running local pre-hook start ..." 223 run_hook start ${FW_PREFIX}/pre-hook "running local pre-hook start ..."
200 224
201 # create IP sets 225 # create IP sets
202 load ipset ${FW_PREFIX}global.d/ipsets "adding global IP sets" 226 load ipset ${FW_PREFIX}/global.d/ipsets "adding global IP sets"
203 for FILE in $( find_appfile ipsets );do 227 for FILE in $( find_appfile ipsets );do
204 load ipset ${FILE} "adding IP sets (App: $(name_appfile ${FILE})) ..." 228 load ipset ${FILE} "adding IP sets (App: $(name_appfile ${FILE})) ..."
205 done 229 done
206 load ipset ${FW_PREFIX}cluster.d/ipsets "adding cluster IP sets" 230 load ipset ${FW_PREFIX}/cluster.d/ipsets "adding cluster IP sets"
207 load ipset ${FW_PREFIX}ipsets "adding local IP sets" 231 load ipset ${FW_PREFIX}/ipsets "adding local IP sets"
208 232
209 # Application rules 233 # Application rules
210 for FILE in $( find_appfile rules4 );do 234 for FILE in $( find_appfile rules4 );do
@@ -219,42 +243,42 @@ start() {
219 done 243 done
220 244
221 # apply host specific firewall rules 245 # apply host specific firewall rules
222 load iptables ${FW_PREFIX}rules4 "adding IPv4 local rules" 246 load iptables ${FW_PREFIX}/rules4 "adding IPv4 local rules"
223 load ip6tables ${FW_PREFIX}rules6 "adding IPv6 local rules" 247 load ip6tables ${FW_PREFIX}/rules6 "adding IPv6 local rules"
224 load iptables ${FW_PREFIX}rules "adding IPv4/IPv6 local rules" 248 load iptables ${FW_PREFIX}/rules "adding IPv4/IPv6 local rules"
225 load ip6tables ${FW_PREFIX}rules 249 load ip6tables ${FW_PREFIX}/rules
226 250
227 # apply cluster specific firewall rules 251 # apply cluster specific firewall rules
228 load iptables ${FW_PREFIX}cluster.d/rules4 "adding IPv4 cluster rules" 252 load iptables ${FW_PREFIX}/cluster.d/rules4 "adding IPv4 cluster rules"
229 load ip6tables ${FW_PREFIX}cluster.d/rules6 "adding IPv6 cluster rules" 253 load ip6tables ${FW_PREFIX}/cluster.d/rules6 "adding IPv6 cluster rules"
230 load iptables ${FW_PREFIX}cluster.d/rules "adding IPv4/IPv6 cluster rules" 254 load iptables ${FW_PREFIX}/cluster.d/rules "adding IPv4/IPv6 cluster rules"
231 load ip6tables ${FW_PREFIX}cluster.d/rules 255 load ip6tables ${FW_PREFIX}/cluster.d/rules
232 256
233 # apply company policy for firewall rules 257 # apply company policy for firewall rules
234 load iptables ${FW_PREFIX}global.d/rules4 "adding IPv4 global rules" 258 load iptables ${FW_PREFIX}/global.d/rules4 "adding IPv4 global rules"
235 load ip6tables ${FW_PREFIX}global.d/rules6 "adding IPv6 global rules" 259 load ip6tables ${FW_PREFIX}/global.d/rules6 "adding IPv6 global rules"
236 load iptables ${FW_PREFIX}global.d/rules "adding IPv4/IPv6 global rules" 260 load iptables ${FW_PREFIX}/global.d/rules "adding IPv4/IPv6 global rules"
237 load ip6tables ${FW_PREFIX}global.d/rules 261 load ip6tables ${FW_PREFIX}/global.d/rules
238 262
239 # run post-hooks 263 # run post-hooks
240 run_hook start ${FW_PREFIX}global.d/post-hook "running global post-hook start ..." 264 run_hook start ${FW_PREFIX}/global.d/post-hook "running global post-hook start ..."
241 for FILE in $( find_appfile post-hook );do 265 for FILE in $( find_appfile post-hook );do
242 run_hook start ${FILE} "running app post-hook start (App: $(name_appfile ${FILE})) ..." 266 run_hook start ${FILE} "running app post-hook start (App: $(name_appfile ${FILE})) ..."
243 done 267 done
244 run_hook start ${FW_PREFIX}cluster.d/post-hook "running cluster post-hook start ..." 268 run_hook start ${FW_PREFIX}/cluster.d/post-hook "running cluster post-hook start ..."
245 run_hook start ${FW_PREFIX}post-hook "running local post-hook start ..." 269 run_hook start ${FW_PREFIX}/post-hook "running local post-hook start ..."
246} 270}
247 271
248 272
249# Function to stop the network: 273# Function to stop the network:
250stop() { 274stop() {
251 # run pre-hooks 275 # run pre-hooks
252 run_hook stop ${FW_PREFIX}global.d/pre-hook "running global pre-hook stop ..." 276 run_hook stop ${FW_PREFIX}/global.d/pre-hook "running global pre-hook stop ..."
253 for FILE in $( find_appfile pre-hook );do 277 for FILE in $( find_appfile pre-hook );do
254 run_hook stop ${FILE} "running app pre-hook stop (App: $(name_appfile ${FILE})) ..." 278 run_hook stop ${FILE} "running app pre-hook stop (App: $(name_appfile ${FILE})) ..."
255 done 279 done
256 run_hook stop ${FW_PREFIX}cluster.d/pre-hook "running cluster pre-hook stop ..." 280 run_hook stop ${FW_PREFIX}/cluster.d/pre-hook "running cluster pre-hook stop ..."
257 run_hook stop ${FW_PREFIX}pre-hook "running local pre-hook stop ..." 281 run_hook stop ${FW_PREFIX}/pre-hook "running local pre-hook stop ..."
258 282
259 for TABLE in $(iptables-save |grep '^*' |sed -e 's/^*//g' |sort);do 283 for TABLE in $(iptables-save |grep '^*' |sed -e 's/^*//g' |sort);do
260 echo "Flushing rules from ${TABLE} table (IPv4)" 284 echo "Flushing rules from ${TABLE} table (IPv4)"
@@ -287,12 +311,12 @@ stop() {
287 done 311 done
288 312
289 # run post-hooks 313 # run post-hooks
290 run_hook stop ${FW_PREFIX}global.d/post-hook "running global post-hook stop ..." 314 run_hook stop ${FW_PREFIX}/global.d/post-hook "running global post-hook stop ..."
291 for FILE in $( find_appfile post-hook );do 315 for FILE in $( find_appfile post-hook );do
292 run_hook stop ${FILE} "running app post-hook stop (App: $(name_appfile ${FILE})) ..." 316 run_hook stop ${FILE} "running app post-hook stop (App: $(name_appfile ${FILE})) ..."
293 done 317 done
294 run_hook stop ${FW_PREFIX}cluster.d/post-hook "running cluster post-hook stop ..." 318 run_hook stop ${FW_PREFIX}/cluster.d/post-hook "running cluster post-hook stop ..."
295 run_hook stop ${FW_PREFIX}post-hook "running local post-hook stop ..." 319 run_hook stop ${FW_PREFIX}/post-hook "running local post-hook stop ..."
296} 320}
297 321
298 322
@@ -300,6 +324,17 @@ stop() {
300### MAIN ### 324### MAIN ###
301############ 325############
302 326
327# sets options from configuration file
328FW_PREFIX="$( config_option firewall_dir "${FW_PREFIX}" )"
329
330
331# checks and normalizes options
332if test ! -d "${FW_PREFIX}";then
333 echo "${PROGRAM_NAME}: ${FW_PREFIX}: firewall directory does not exist" 1>&2
334 exit 1
335fi
336
337
303case "$1" in 338case "$1" in
304 -h|--help) 339 -h|--help)
305 echo "Usage: ${PROGRAM_NAME} [ start | stop | restart | dump ]" 340 echo "Usage: ${PROGRAM_NAME} [ start | stop | restart | dump ]"