2011-03-09 20:50:13 +01:00
|
|
|
#!/bin/bash
|
|
|
|
set -e
|
|
|
|
|
|
|
|
PIDFILE=/var/run/qubes/qubes_firewall.pid
|
|
|
|
XENSTORE_IPTABLES=qubes_iptables
|
2011-07-29 16:50:12 +02:00
|
|
|
XENSTORE_IPTABLES_HEADER=qubes_iptables_header
|
2011-03-09 20:50:13 +01:00
|
|
|
XENSTORE_ERROR=qubes_iptables_error
|
|
|
|
OLD_RULES=""
|
|
|
|
# PIDfile handling
|
|
|
|
[[ -e $PIDFILE ]] && kill -s 0 $(<$PIDFILE) 2>/dev/null && exit 0
|
|
|
|
echo $$ >$PIDFILE
|
|
|
|
|
|
|
|
trap 'exit 0' SIGTERM
|
|
|
|
|
|
|
|
while true; do
|
|
|
|
# Wait for changes in xenstore file
|
2011-06-06 02:37:55 +02:00
|
|
|
/usr/bin/xenstore-watch-qubes $XENSTORE_IPTABLES
|
2011-07-29 16:50:12 +02:00
|
|
|
TRIGGER=$(/usr/bin/xenstore-read $XENSTORE_IPTABLES)
|
|
|
|
|
|
|
|
if ! [ "$TRIGGER" = "reload" ]; then continue ; fi
|
|
|
|
RULES=$(/usr/bin/xenstore-read $XENSTORE_IPTABLES_HEADER)
|
|
|
|
IPTABLES_SAVE=$(/sbin/iptables-save | sed '/^\*filter/,/^COMMIT/d')
|
|
|
|
OUT=`echo -e "$RULES\n$IPTABLES_SAVE" | /sbin/iptables-restore 2>&1 || :`
|
|
|
|
|
|
|
|
for i in $(xenstore-list qubes_iptables_domainrules) ; do
|
|
|
|
RULES=$(/usr/bin/xenstore-read qubes_iptables_domainrules/"$i")
|
|
|
|
ERRS=`echo -e "$RULES" | /sbin/iptables-restore -n 2>&1 || :`
|
|
|
|
OUT="$OUT""$ERRS"
|
|
|
|
done
|
|
|
|
/usr/bin/xenstore-write $XENSTORE_ERROR "$OUT"
|
|
|
|
if [ "$OUT" ]; then
|
|
|
|
DISPLAY=:0 /usr/bin/notify-send -t 3000 "Firewall loading error ($HOSTNAME)" "$OUT" || :
|
|
|
|
fi
|
2011-08-18 15:02:30 +02:00
|
|
|
|
|
|
|
# Check if user didn't define some custom rules to be applied as well...
|
|
|
|
[ -x /rw/config/qubes_firewall_user_script ] && /rw/config/qubes_firewall_user_script
|
2011-03-09 20:50:13 +01:00
|
|
|
done
|