diff options
| author | David M. Syzdek <syzdek@bindlebinaries.com> | 2017-12-20 14:10:24 -0900 |
|---|---|---|
| committer | David M. Syzdek <syzdek@bindlebinaries.com> | 2017-12-20 14:10:24 -0900 |
| commit | 7747e6fa2f63501c8972e641b6a5a05d9065bdd3 (patch) | |
| tree | 9fd243ea61bf24a356c5f77f7e5de4162ce0d37b /src | |
| parent | bef34a350b7c53cde01417585b0fed6888a82cb3 (diff) | |
| download | bbfw-7747e6fa2f63501c8972e641b6a5a05d9065bdd3.tar.gz bbfw-7747e6fa2f63501c8972e641b6a5a05d9065bdd3.tar.bz2 bbfw-7747e6fa2f63501c8972e641b6a5a05d9065bdd3.tar.xz bbfw-7747e6fa2f63501c8972e641b6a5a05d9065bdd3.zip | |
Updating rc.firewall.in to use explicit PATHs instead of explicit file names for commands
Diffstat (limited to 'src')
| -rwxr-xr-x | src/slack/rc.firewall.in | 94 |
1 files changed, 51 insertions, 43 deletions
diff --git a/src/slack/rc.firewall.in b/src/slack/rc.firewall.in index 69307fb..5ab54cf 100755 --- a/src/slack/rc.firewall.in +++ b/src/slack/rc.firewall.in | |||
| @@ -54,6 +54,14 @@ | |||
| 54 | # rc.firewall.globalsets | 54 | # rc.firewall.globalsets |
| 55 | # | 55 | # |
| 56 | 56 | ||
| 57 | ############### | ||
| 58 | # ENVIRONMENT # | ||
| 59 | ############### | ||
| 60 | |||
| 61 | PATH=/usr/bin:/bin:/usr/sbin:/sbin | ||
| 62 | export PATH | ||
| 63 | |||
| 64 | |||
| 57 | ########### | 65 | ########### |
| 58 | # LOGGING # | 66 | # LOGGING # |
| 59 | ########### | 67 | ########### |
| @@ -67,10 +75,10 @@ PACKAGE_BUGREPORT="$(echo '@PACKAGE_BUGREPORT@' |sed -e 's/[@].*[@]//g')" | |||
| 67 | 75 | ||
| 68 | # If possible, log events in /var/log/messages: | 76 | # If possible, log events in /var/log/messages: |
| 69 | PROG=rc.firewall | 77 | PROG=rc.firewall |
| 70 | if [ -f /var/run/syslogd.pid -a -x /usr/bin/logger ]; then | 78 | if [ -f /var/run/syslogd.pid -a -x logger ]; then |
| 71 | LOGGER="/usr/bin/logger -s -t ${PROG}[$$]" | 79 | LOGGER="logger -s -t ${PROG}[$$]" |
| 72 | else # output to stdout/stderr: | 80 | else # output to stdout/stderr: |
| 73 | LOGGER="/usr/bin/sed -e s/^/${PROG}:/g" | 81 | LOGGER="sed -e s/^/${PROG}:/g" |
| 74 | fi | 82 | fi |
| 75 | 83 | ||
| 76 | 84 | ||
| @@ -81,7 +89,7 @@ fi | |||
| 81 | clean_file() | 89 | clean_file() |
| 82 | { | 90 | { |
| 83 | DIRTY_FILE="${1}" | 91 | DIRTY_FILE="${1}" |
| 84 | /usr/bin/cut -d# -f1 "${DIRTY_FILE}" \ | 92 | cut -d# -f1 "${DIRTY_FILE}" \ |
| 85 | |sed -n 'H; ${ x; s/\\\n//; s/\n //g; p}' \ | 93 | |sed -n 'H; ${ x; s/\\\n//; s/\n //g; p}' \ |
| 86 | |sed -e 's/[[:space:]]{1,}/ /g' | 94 | |sed -e 's/[[:space:]]{1,}/ /g' |
| 87 | } | 95 | } |
| @@ -89,16 +97,16 @@ clean_file() | |||
| 89 | 97 | ||
| 90 | dump() | 98 | dump() |
| 91 | { | 99 | { |
| 92 | /usr/sbin/ipset list |sed -e "s/^/ipset: /g" | 100 | ipset list |sed -e "s/^/ipset: /g" |
| 93 | echo "" | 101 | echo "" |
| 94 | for TABLE in $(/usr/sbin/iptables-save |grep '^*' |sed -e 's/^*//g' |sort);do | 102 | for TABLE in $(iptables-save |grep '^*' |sed -e 's/^*//g' |sort);do |
| 95 | PREFIX="$(printf "%-9s" "${TABLE}:")" | 103 | PREFIX="$(printf "%-9s" "${TABLE}:")" |
| 96 | /usr/sbin/iptables -t ${TABLE} -L |sed -e "s/^/iptables ${PREFIX} /g" | 104 | iptables -t ${TABLE} -L |sed -e "s/^/iptables ${PREFIX} /g" |
| 97 | echo "" | 105 | echo "" |
| 98 | done | 106 | done |
| 99 | for TABLE in $(/usr/sbin/ip6tables-save |grep '^*' |sed -e 's/^*//g' |sort);do | 107 | for TABLE in $(ip6tables-save |grep '^*' |sed -e 's/^*//g' |sort);do |
| 100 | PREFIX="$(printf "%-9s" "${TABLE}:")" | 108 | PREFIX="$(printf "%-9s" "${TABLE}:")" |
| 101 | /usr/sbin/ip6tables -t ${TABLE} -L |sed -e "s/^/ip6tables ${PREFIX} /g" | 109 | ip6tables -t ${TABLE} -L |sed -e "s/^/ip6tables ${PREFIX} /g" |
| 102 | echo "" | 110 | echo "" |
| 103 | done | 111 | done |
| 104 | } | 112 | } |
| @@ -109,60 +117,60 @@ start() { | |||
| 109 | # create IP sets | 117 | # create IP sets |
| 110 | if test -f /etc/rc.d/rc.firewall.globalsets;then | 118 | if test -f /etc/rc.d/rc.firewall.globalsets;then |
| 111 | echo "adding global IP sets" | 119 | echo "adding global IP sets" |
| 112 | clean_file /etc/rc.d/rc.firewall.globalsets |/usr/sbin/ipset restore | 120 | clean_file /etc/rc.d/rc.firewall.globalsets |ipset restore |
| 113 | fi | 121 | fi |
| 114 | if test -f /etc/rc.d/rc.firewall.ipsets;then | 122 | if test -f /etc/rc.d/rc.firewall.ipsets;then |
| 115 | echo "adding local IP sets" | 123 | echo "adding local IP sets" |
| 116 | clean_file /etc/rc.d/rc.firewall.ipsets |/usr/sbin/ipset restore | 124 | clean_file /etc/rc.d/rc.firewall.ipsets |ipset restore |
| 117 | fi | 125 | fi |
| 118 | 126 | ||
| 119 | # apply host specific firewall rules | 127 | # apply host specific firewall rules |
| 120 | if test -f /etc/rc.d/rc.firewall.rules4;then | 128 | if test -f /etc/rc.d/rc.firewall.rules4;then |
| 121 | echo "adding IPv4 local rules" | 129 | echo "adding IPv4 local rules" |
| 122 | clean_file /etc/rc.d/rc.firewall.rules4 |/usr/sbin/iptables-restore -n | 130 | clean_file /etc/rc.d/rc.firewall.rules4 |iptables-restore -n |
| 123 | fi | 131 | fi |
| 124 | if test -f /etc/rc.d/rc.firewall.rules6;then | 132 | if test -f /etc/rc.d/rc.firewall.rules6;then |
| 125 | echo "adding IPv6 local rules" | 133 | echo "adding IPv6 local rules" |
| 126 | clean_file /etc/rc.d/rc.firewall.rules6 |/usr/sbin/ip6tables-restore -n | 134 | clean_file /etc/rc.d/rc.firewall.rules6 |ip6tables-restore -n |
| 127 | fi | 135 | fi |
| 128 | if test -f /etc/rc.d/rc.firewall.rules;then | 136 | if test -f /etc/rc.d/rc.firewall.rules;then |
| 129 | echo "adding IPv4/IPv6 local rules" | 137 | echo "adding IPv4/IPv6 local rules" |
| 130 | clean_file /etc/rc.d/rc.firewall.rules |/usr/sbin/iptables-restore -n | 138 | clean_file /etc/rc.d/rc.firewall.rules |iptables-restore -n |
| 131 | clean_file /etc/rc.d/rc.firewall.rules |/usr/sbin/ip6tables-restore -n | 139 | clean_file /etc/rc.d/rc.firewall.rules |ip6tables-restore -n |
| 132 | fi | 140 | fi |
| 133 | 141 | ||
| 134 | # apply company policy for firewall rules | 142 | # apply company policy for firewall rules |
| 135 | if test -f /etc/rc.d/rc.firewall.global4;then | 143 | if test -f /etc/rc.d/rc.firewall.global4;then |
| 136 | echo "adding IPv4 global rules" | 144 | echo "adding IPv4 global rules" |
| 137 | clean_file /etc/rc.d/rc.firewall.global4 |/usr/sbin/iptables-restore -n | 145 | clean_file /etc/rc.d/rc.firewall.global4 |iptables-restore -n |
| 138 | fi | 146 | fi |
| 139 | if test -f /etc/rc.d/rc.firewall.global6;then | 147 | if test -f /etc/rc.d/rc.firewall.global6;then |
| 140 | echo "adding IPv6 global rules" | 148 | echo "adding IPv6 global rules" |
| 141 | clean_file /etc/rc.d/rc.firewall.global6 |/usr/sbin/ip6tables-restore -n | 149 | clean_file /etc/rc.d/rc.firewall.global6 |ip6tables-restore -n |
| 142 | fi | 150 | fi |
| 143 | if test -f /etc/rc.d/rc.firewall.global;then | 151 | if test -f /etc/rc.d/rc.firewall.global;then |
| 144 | echo "adding IPv4/IPv6 global rules" | 152 | echo "adding IPv4/IPv6 global rules" |
| 145 | clean_file /etc/rc.d/rc.firewall.global |/usr/sbin/iptables-restore -n | 153 | clean_file /etc/rc.d/rc.firewall.global |iptables-restore -n |
| 146 | clean_file /etc/rc.d/rc.firewall.global |/usr/sbin/ip6tables-restore -n | 154 | clean_file /etc/rc.d/rc.firewall.global |ip6tables-restore -n |
| 147 | fi | 155 | fi |
| 148 | 156 | ||
| 149 | # Application rules | 157 | # Application rules |
| 150 | if test -d /etc/firewall.d;then | 158 | if test -d /etc/firewall.d;then |
| 151 | for FILE in $(find /etc/firewall.d/ -name '*.ipsets' -type f);do | 159 | for FILE in $(find /etc/firewall.d/ -name '*.ipsets' -type f);do |
| 152 | echo "adding IP sets (App: $(basename ${FILE})) ..." | 160 | echo "adding IP sets (App: $(basename ${FILE})) ..." |
| 153 | clean_file ${FILE} |/usr/sbin/ipset retore | 161 | clean_file ${FILE} |ipset retore |
| 154 | done | 162 | done |
| 155 | for FILE in $(find /etc/firewall.d/ -name '*.rules4' -type f);do | 163 | for FILE in $(find /etc/firewall.d/ -name '*.rules4' -type f);do |
| 156 | echo "adding IPv4 rules (App: $(basename ${FILE})) ..." | 164 | echo "adding IPv4 rules (App: $(basename ${FILE})) ..." |
| 157 | clean_file ${FILE} |/usr/sbin/iptables-restore -n | 165 | clean_file ${FILE} |iptables-restore -n |
| 158 | done | 166 | done |
| 159 | for FILE in $(find /etc/firewall.d/ -name '*.rules6' -type f);do | 167 | for FILE in $(find /etc/firewall.d/ -name '*.rules6' -type f);do |
| 160 | echo "adding IPv6 rules (App: $(basename ${FILE})) ..." | 168 | echo "adding IPv6 rules (App: $(basename ${FILE})) ..." |
| 161 | clean_file ${FILE} |/usr/sbin/ip6tables-restore -n | 169 | clean_file ${FILE} |ip6tables-restore -n |
| 162 | done | 170 | done |
| 163 | for FILE in $(find /etc/firewall.d/ -name '*.rules' -type f);do | 171 | for FILE in $(find /etc/firewall.d/ -name '*.rules' -type f);do |
| 164 | echo "adding IPv4/IPv6 rules (App: $(basename ${FILE})) ..." | 172 | echo "adding IPv4/IPv6 rules (App: $(basename ${FILE})) ..." |
| 165 | clean_file ${FILE} |/usr/sbin/ip6tables-restore -n | 173 | clean_file ${FILE} |ip6tables-restore -n |
| 166 | done | 174 | done |
| 167 | fi | 175 | fi |
| 168 | 176 | ||
| @@ -172,16 +180,16 @@ start() { | |||
| 172 | for LXC in `ls /var/lib/lxc/`;do | 180 | for LXC in `ls /var/lib/lxc/`;do |
| 173 | if test -f /var/lib/lxc/${LXC}/rc.d/rc.firewall.rules4;then | 181 | if test -f /var/lib/lxc/${LXC}/rc.d/rc.firewall.rules4;then |
| 174 | echo "adding IPv4 rules (LXC: ${LXC})" | 182 | echo "adding IPv4 rules (LXC: ${LXC})" |
| 175 | clean_file /var/lib/lxc/${LXC}/rc.d/rc.firewall.rules4 | /usr/sbin/iptables-restore -n | 183 | clean_file /var/lib/lxc/${LXC}/rc.d/rc.firewall.rules4 | iptables-restore -n |
| 176 | fi | 184 | fi |
| 177 | if test -f /var/lib/lxc/${LXC}/rc.d/rc.firewall.rules6;then | 185 | if test -f /var/lib/lxc/${LXC}/rc.d/rc.firewall.rules6;then |
| 178 | echo "adding IPv6 rules (LXC: ${LXC})" | 186 | echo "adding IPv6 rules (LXC: ${LXC})" |
| 179 | clean_file /var/lib/lxc/${LXC}/rc.d/rc.firewall.rules6 | /usr/sbin/ip6tables-restore -n | 187 | clean_file /var/lib/lxc/${LXC}/rc.d/rc.firewall.rules6 | ip6tables-restore -n |
| 180 | fi | 188 | fi |
| 181 | if test -f /var/lib/lxc/${LXC}/rc.d/rc.firewall.rules;then | 189 | if test -f /var/lib/lxc/${LXC}/rc.d/rc.firewall.rules;then |
| 182 | echo "adding IPv4/IPv6 rules (LXC: ${LXC})" | 190 | echo "adding IPv4/IPv6 rules (LXC: ${LXC})" |
| 183 | clean_file /var/lib/lxc/${LXC}/rc.d/rc.firewall.rules | /usr/sbin/iptables-restore -n | 191 | clean_file /var/lib/lxc/${LXC}/rc.d/rc.firewall.rules | iptables-restore -n |
| 184 | clean_file /var/lib/lxc/${LXC}/rc.d/rc.firewall.rules | /usr/sbin/ip6tables-restore -n | 192 | clean_file /var/lib/lxc/${LXC}/rc.d/rc.firewall.rules | ip6tables-restore -n |
| 185 | fi | 193 | fi |
| 186 | done | 194 | done |
| 187 | fi | 195 | fi |
| @@ -190,34 +198,34 @@ start() { | |||
| 190 | 198 | ||
| 191 | # Function to stop the network: | 199 | # Function to stop the network: |
| 192 | stop() { | 200 | stop() { |
| 193 | for TABLE in $(/usr/sbin/iptables-save |grep '^*' |sed -e 's/^*//g' |sort);do | 201 | for TABLE in $(iptables-save |grep '^*' |sed -e 's/^*//g' |sort);do |
| 194 | echo "Flushing rules from ${TABLE} table (IPv4)" | 202 | echo "Flushing rules from ${TABLE} table (IPv4)" |
| 195 | for CHAIN in $(/usr/sbin/iptables-save -t ${TABLE} |grep '^:' |cut -d: -f2 |grep -v ' - ' |cut -d\ -f1);do | 203 | for CHAIN in $(iptables-save -t ${TABLE} |grep '^:' |cut -d: -f2 |grep -v ' - ' |cut -d\ -f1);do |
| 196 | /usr/sbin/iptables -t ${TABLE} -P ${CHAIN} ACCEPT | 204 | iptables -t ${TABLE} -P ${CHAIN} ACCEPT |
| 197 | done | 205 | done |
| 198 | /usr/sbin/iptables -t ${TABLE} -F | 206 | iptables -t ${TABLE} -F |
| 199 | for CHAIN in $(/usr/sbin/iptables-save -t ${TABLE} |grep '^:' |cut -d: -f2 |grep ' - ' |cut -d\ -f1);do | 207 | for CHAIN in $(iptables-save -t ${TABLE} |grep '^:' |cut -d: -f2 |grep ' - ' |cut -d\ -f1);do |
| 200 | /usr/sbin/iptables -t ${TABLE} -X ${CHAIN} | 208 | iptables -t ${TABLE} -X ${CHAIN} |
| 201 | done | 209 | done |
| 202 | done 2> /dev/null | 210 | done 2> /dev/null |
| 203 | 211 | ||
| 204 | for TABLE in $(/usr/sbin/iptables-save |grep '^*' |sed -e 's/^*//g' |sort);do | 212 | for TABLE in $(iptables-save |grep '^*' |sed -e 's/^*//g' |sort);do |
| 205 | echo "Flushing rules from ${TABLE} table (IPv6)" | 213 | echo "Flushing rules from ${TABLE} table (IPv6)" |
| 206 | for CHAIN in $(/usr/sbin/ip6tables-save -t ${TABLE} |grep '^:' |cut -d: -f2 |grep -v ' - ' |cut -d\ -f1);do | 214 | for CHAIN in $(ip6tables-save -t ${TABLE} |grep '^:' |cut -d: -f2 |grep -v ' - ' |cut -d\ -f1);do |
| 207 | /usr/sbin/ip6tables -t ${TABLE} -P ${CHAIN} ACCEPT | 215 | ip6tables -t ${TABLE} -P ${CHAIN} ACCEPT |
| 208 | done | 216 | done |
| 209 | /usr/sbin/ip6tables -t ${TABLE} -F | 217 | ip6tables -t ${TABLE} -F |
| 210 | for CHAIN in $(/usr/sbin/ip6tables-save -t ${TABLE} |grep '^:' |cut -d: -f2 |grep ' - ' |cut -d\ -f1);do | 218 | for CHAIN in $(ip6tables-save -t ${TABLE} |grep '^:' |cut -d: -f2 |grep ' - ' |cut -d\ -f1);do |
| 211 | /usr/sbin/ip6tables -t ${TABLE} -X ${CHAIN} | 219 | ip6tables -t ${TABLE} -X ${CHAIN} |
| 212 | done | 220 | done |
| 213 | done 2> /dev/null | 221 | done 2> /dev/null |
| 214 | 222 | ||
| 215 | echo "Destroying all IP sets ..." | 223 | echo "Destroying all IP sets ..." |
| 216 | for SET in $(/usr/sbin/ipset save |grep '^create' |grep ' list:' |awk '{print$2}');do | 224 | for SET in $(ipset save |grep '^create' |grep ' list:' |awk '{print$2}');do |
| 217 | /usr/sbin/ipset destroy "${SET}" | 225 | ipset destroy "${SET}" |
| 218 | done | 226 | done |
| 219 | for SET in $(/usr/sbin/ipset save |grep '^create' |awk '{print$2}');do | 227 | for SET in $(ipset save |grep '^create' |awk '{print$2}');do |
| 220 | /usr/sbin/ipset destroy "${SET}" | 228 | ipset destroy "${SET}" |
| 221 | done | 229 | done |
| 222 | } | 230 | } |
| 223 | 231 | ||
