forked from extern/shorewall_code
Allow non-root to run many 'show' commands
Signed-off-by: Tom Eastep <teastep@shorewall.net>
This commit is contained in:
parent
c9b58e203b
commit
d8a22d13dd
@ -42,11 +42,15 @@ fi
|
|||||||
# Issue an error message and die
|
# Issue an error message and die
|
||||||
#
|
#
|
||||||
startup_error() {
|
startup_error() {
|
||||||
echo " ERROR: $@" >&2
|
echo " ERROR: $@" >&21
|
||||||
kill $$
|
kill $$
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
only_root() {
|
||||||
|
[ "$(id -u)" != 0 ] && fatal_error "The '$COMMAND' command may only be run by root"
|
||||||
|
}
|
||||||
|
|
||||||
#
|
#
|
||||||
# Display a chain if it exists
|
# Display a chain if it exists
|
||||||
#
|
#
|
||||||
@ -1203,6 +1207,7 @@ show_command() {
|
|||||||
show_macro() {
|
show_macro() {
|
||||||
foo=`grep 'This macro' $macro | sed 's/This macro //'`
|
foo=`grep 'This macro' $macro | sed 's/This macro //'`
|
||||||
if [ -n "$foo" ]; then
|
if [ -n "$foo" ]; then
|
||||||
|
macro=$(basename $macro)
|
||||||
macro=${macro#*.}
|
macro=${macro#*.}
|
||||||
foo=${foo%.*}
|
foo=${foo%.*}
|
||||||
if [ ${#macro} -gt 5 ]; then
|
if [ ${#macro} -gt 5 ]; then
|
||||||
@ -1297,37 +1302,47 @@ show_command() {
|
|||||||
|
|
||||||
[ -n "$g_debugging" ] && set -x
|
[ -n "$g_debugging" ] && set -x
|
||||||
|
|
||||||
|
COMMAND="$COMMAND $1"
|
||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
connections)
|
connections)
|
||||||
|
only_root
|
||||||
eval show_connections $@ $g_pager
|
eval show_connections $@ $g_pager
|
||||||
;;
|
;;
|
||||||
nat)
|
nat)
|
||||||
|
only_root
|
||||||
[ $# -gt 1 ] && too_many_arguments $2
|
[ $# -gt 1 ] && too_many_arguments $2
|
||||||
eval show_nat $g_pager
|
eval show_nat $g_pager
|
||||||
;;
|
;;
|
||||||
raw)
|
raw)
|
||||||
|
only_root
|
||||||
[ $# -gt 1 ] && too_many_arguments $2
|
[ $# -gt 1 ] && too_many_arguments $2
|
||||||
eval show_raw $g_pager
|
eval show_raw $g_pager
|
||||||
;;
|
;;
|
||||||
tos|mangle)
|
tos|mangle)
|
||||||
|
only_root
|
||||||
[ $# -gt 1 ] && too_many_arguments $2
|
[ $# -gt 1 ] && too_many_arguments $2
|
||||||
eval show_mangle $g_pager
|
eval show_mangle $g_pager
|
||||||
;;
|
;;
|
||||||
log)
|
log)
|
||||||
[ $# -gt 2 ] && too_many_arguments $2
|
[ $# -gt 2 ] && too_many_arguments $2
|
||||||
|
|
||||||
|
only_root
|
||||||
setup_logread
|
setup_logread
|
||||||
eval show_log $g_pager
|
eval show_log $g_pager
|
||||||
;;
|
;;
|
||||||
tc)
|
tc)
|
||||||
|
only_root
|
||||||
[ $# -gt 2 ] && too_many_arguments $2
|
[ $# -gt 2 ] && too_many_arguments $2
|
||||||
eval show_tc $@ $g_pager
|
eval show_tc $@ $g_pager
|
||||||
;;
|
;;
|
||||||
classifiers|filters)
|
classifiers|filters)
|
||||||
|
only_root
|
||||||
[ $# -gt 1 ] && too_many_arguments $2
|
[ $# -gt 1 ] && too_many_arguments $2
|
||||||
eval show_classifiers_command $g_pager
|
eval show_classifiers_command $g_pager
|
||||||
;;
|
;;
|
||||||
zones)
|
zones)
|
||||||
|
only_root
|
||||||
[ $# -gt 1 ] && too_many_arguments $2
|
[ $# -gt 1 ] && too_many_arguments $2
|
||||||
if [ -f ${VARDIR}/zones ]; then
|
if [ -f ${VARDIR}/zones ]; then
|
||||||
echo "$g_product $SHOREWALL_VERSION Zones at $g_hostname - $(date)"
|
echo "$g_product $SHOREWALL_VERSION Zones at $g_hostname - $(date)"
|
||||||
@ -1351,6 +1366,7 @@ show_command() {
|
|||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
capabilities)
|
capabilities)
|
||||||
|
only_root
|
||||||
[ $# -gt 1 ] && too_many_arguments $2
|
[ $# -gt 1 ] && too_many_arguments $2
|
||||||
determine_capabilities
|
determine_capabilities
|
||||||
VERBOSITY=2
|
VERBOSITY=2
|
||||||
@ -1387,6 +1403,7 @@ show_command() {
|
|||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
chain)
|
chain)
|
||||||
|
only_root
|
||||||
shift
|
shift
|
||||||
eval show_chain $@ $g_pager
|
eval show_chain $@ $g_pager
|
||||||
;;
|
;;
|
||||||
@ -1394,26 +1411,31 @@ show_command() {
|
|||||||
echo $VARDIR;
|
echo $VARDIR;
|
||||||
;;
|
;;
|
||||||
policies)
|
policies)
|
||||||
|
only_root
|
||||||
[ $# -gt 1 ] && too_many_arguments $2
|
[ $# -gt 1 ] && too_many_arguments $2
|
||||||
eval show_policies $g_pager
|
eval show_policies $g_pager
|
||||||
;;
|
;;
|
||||||
ipa)
|
ipa)
|
||||||
|
only_root
|
||||||
[ $g_family -eq 4 ] || fatal_error "'show ipa' is now available in $g_product"
|
[ $g_family -eq 4 ] || fatal_error "'show ipa' is now available in $g_product"
|
||||||
[ $# -gt 1 ] && too_many_arguments $2
|
[ $# -gt 1 ] && too_many_arguments $2
|
||||||
eval show_ipa $g_pager
|
eval show_ipa $g_pager
|
||||||
;;
|
;;
|
||||||
marks)
|
marks)
|
||||||
[ $# -gt 1 ] && too_many_arguments $2
|
[ $# -gt 1 ] && too_many_arguments $2
|
||||||
|
only_root
|
||||||
echo "$g_product $SHOREWALL_VERSION Mark Layout at $g_hostname - $(date)"
|
echo "$g_product $SHOREWALL_VERSION Mark Layout at $g_hostname - $(date)"
|
||||||
echo
|
echo
|
||||||
[ -f ${VARDIR}/marks ] && cat ${VARDIR}/marks;
|
[ -f ${VARDIR}/marks ] && cat ${VARDIR}/marks;
|
||||||
;;
|
;;
|
||||||
nfacct)
|
nfacct)
|
||||||
[ $# -gt 1 ] && too_many_arguments $2
|
[ $# -gt 1 ] && too_many_arguments $2
|
||||||
|
only_root
|
||||||
eval show_nfacct_command $g_pager
|
eval show_nfacct_command $g_pager
|
||||||
;;
|
;;
|
||||||
arptables)
|
arptables)
|
||||||
[ $# -gt 1 ] && too_many_arguments $2
|
[ $# -gt 1 ] && too_many_arguments $2
|
||||||
|
only_root
|
||||||
resolve_arptables
|
resolve_arptables
|
||||||
if [ -n "$arptables" -a -x $arptables ]; then
|
if [ -n "$arptables" -a -x $arptables ]; then
|
||||||
eval show_arptables $g_pager
|
eval show_arptables $g_pager
|
||||||
@ -1423,6 +1445,7 @@ show_command() {
|
|||||||
;;
|
;;
|
||||||
event)
|
event)
|
||||||
[ $# -gt 1 ] || too_many_arguments $2
|
[ $# -gt 1 ] || too_many_arguments $2
|
||||||
|
only_root
|
||||||
echo "$g_product $SHOREWALL_VERSION events at $g_hostname - $(date)"
|
echo "$g_product $SHOREWALL_VERSION events at $g_hostname - $(date)"
|
||||||
echo
|
echo
|
||||||
shift
|
shift
|
||||||
@ -1430,14 +1453,17 @@ show_command() {
|
|||||||
;;
|
;;
|
||||||
events)
|
events)
|
||||||
[ $# -gt 1 ] && too_many_arguments $2
|
[ $# -gt 1 ] && too_many_arguments $2
|
||||||
|
only_root
|
||||||
eval show_events_command $g_pager
|
eval show_events_command $g_pager
|
||||||
;;
|
;;
|
||||||
bl|blacklists)
|
bl|blacklists)
|
||||||
[ $# -gt 1 ] && too_many_arguments $2
|
[ $# -gt 1 ] && too_many_arguments $2
|
||||||
|
only_root
|
||||||
eval show_blacklists $g_pager
|
eval show_blacklists $g_pager
|
||||||
;;
|
;;
|
||||||
opens)
|
opens)
|
||||||
[ $# -gt 1 ] && too_many_arguments $2
|
[ $# -gt 1 ] && too_many_arguments $2
|
||||||
|
only_root
|
||||||
echo "$g_product $SHOREWALL_VERSION Temporarily opened connections at $g_hostname - $(date)"
|
echo "$g_product $SHOREWALL_VERSION Temporarily opened connections at $g_hostname - $(date)"
|
||||||
|
|
||||||
if chain_exists dynamic; then
|
if chain_exists dynamic; then
|
||||||
@ -1448,6 +1474,7 @@ show_command() {
|
|||||||
;;
|
;;
|
||||||
ipsec)
|
ipsec)
|
||||||
[ $# -gt 1 ] && too_many_arguments $2
|
[ $# -gt 1 ] && too_many_arguments $2
|
||||||
|
only_root
|
||||||
eval show_ipsec_command $g_pager
|
eval show_ipsec_command $g_pager
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
@ -1496,6 +1523,8 @@ show_command() {
|
|||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
only_root
|
||||||
|
|
||||||
if [ $# -gt 0 ]; then
|
if [ $# -gt 0 ]; then
|
||||||
if [ $1 = dynamic -a $# -gt 1 ]; then
|
if [ $1 = dynamic -a $# -gt 1 ]; then
|
||||||
shift
|
shift
|
||||||
@ -4585,12 +4614,14 @@ shorewall_cli() {
|
|||||||
|
|
||||||
case "$COMMAND" in
|
case "$COMMAND" in
|
||||||
start)
|
start)
|
||||||
|
only_root
|
||||||
get_config Yes Yes
|
get_config Yes Yes
|
||||||
shift
|
shift
|
||||||
start_command $@
|
start_command $@
|
||||||
;;
|
;;
|
||||||
stop|clear)
|
stop|clear)
|
||||||
[ $# -ne 1 ] && too_many_arguments $2
|
[ $# -ne 1 ] && too_many_arguments $2
|
||||||
|
only_root
|
||||||
get_config
|
get_config
|
||||||
[ -x $g_firewall ] || fatal_error "$g_product has never been started"
|
[ -x $g_firewall ] || fatal_error "$g_product has never been started"
|
||||||
[ -n "$g_nolock" ] || mutex_on
|
[ -n "$g_nolock" ] || mutex_on
|
||||||
@ -4598,6 +4629,7 @@ shorewall_cli() {
|
|||||||
[ -n "$g_nolock" ] || mutex_off
|
[ -n "$g_nolock" ] || mutex_off
|
||||||
;;
|
;;
|
||||||
reset)
|
reset)
|
||||||
|
only_root
|
||||||
get_config
|
get_config
|
||||||
shift
|
shift
|
||||||
[ -n "$g_nolock" ] || mutex_on
|
[ -n "$g_nolock" ] || mutex_on
|
||||||
@ -4606,11 +4638,13 @@ shorewall_cli() {
|
|||||||
[ -n "$g_nolock" ] || mutex_off
|
[ -n "$g_nolock" ] || mutex_off
|
||||||
;;
|
;;
|
||||||
reload|restart)
|
reload|restart)
|
||||||
|
only_root
|
||||||
get_config Yes Yes
|
get_config Yes Yes
|
||||||
shift
|
shift
|
||||||
restart_command $@
|
restart_command $@
|
||||||
;;
|
;;
|
||||||
disable|enable|reenable)
|
disable|enable|reenable)
|
||||||
|
only_root
|
||||||
get_config Yes
|
get_config Yes
|
||||||
if product_is_started; then
|
if product_is_started; then
|
||||||
run_it ${VARDIR}/firewall $g_debugging $@
|
run_it ${VARDIR}/firewall $g_debugging $@
|
||||||
@ -4619,6 +4653,7 @@ shorewall_cli() {
|
|||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
blacklist)
|
blacklist)
|
||||||
|
onlyroot
|
||||||
get_config Yes
|
get_config Yes
|
||||||
shift
|
shift
|
||||||
[ -n "$g_nolock" ] || mutex_on
|
[ -n "$g_nolock" ] || mutex_on
|
||||||
@ -4627,6 +4662,7 @@ shorewall_cli() {
|
|||||||
;;
|
;;
|
||||||
run)
|
run)
|
||||||
[ $# -gt 1 ] || fatal_error "Missing function name"
|
[ $# -gt 1 ] || fatal_error "Missing function name"
|
||||||
|
only_root
|
||||||
get_config Yes
|
get_config Yes
|
||||||
run_command $@
|
run_command $@
|
||||||
;;
|
;;
|
||||||
@ -4636,18 +4672,20 @@ shorewall_cli() {
|
|||||||
show_command $@
|
show_command $@
|
||||||
;;
|
;;
|
||||||
status)
|
status)
|
||||||
[ "$(id -u)" != 0 ] && fatal_error "The status command may only be run by root"
|
only_root
|
||||||
get_config
|
get_config
|
||||||
shift
|
shift
|
||||||
status_command $@
|
status_command $@
|
||||||
;;
|
;;
|
||||||
dump)
|
dump)
|
||||||
|
only_root
|
||||||
get_config Yes No Yes
|
get_config Yes No Yes
|
||||||
shift
|
shift
|
||||||
dump_command $@
|
dump_command $@
|
||||||
;;
|
;;
|
||||||
hits)
|
hits)
|
||||||
[ $g_family -eq 6 ] && fatal_error "$g_product does not support the hits command"
|
[ $g_family -eq 6 ] && fatal_error "$g_product does not support the hits command"
|
||||||
|
only_root
|
||||||
get_config Yes No Yes
|
get_config Yes No Yes
|
||||||
[ -n "$g_debugging" ] && set -x
|
[ -n "$g_debugging" ] && set -x
|
||||||
shift
|
shift
|
||||||
@ -4658,53 +4696,63 @@ shorewall_cli() {
|
|||||||
version_command $@
|
version_command $@
|
||||||
;;
|
;;
|
||||||
logwatch)
|
logwatch)
|
||||||
|
only_root
|
||||||
get_config Yes Yes Yes
|
get_config Yes Yes Yes
|
||||||
banner="${g_product}-$SHOREWALL_VERSION Logwatch at $g_hostname -"
|
banner="${g_product}-$SHOREWALL_VERSION Logwatch at $g_hostname -"
|
||||||
logwatch_command $@
|
logwatch_command $@
|
||||||
;;
|
;;
|
||||||
drop)
|
drop)
|
||||||
|
only_root
|
||||||
get_config
|
get_config
|
||||||
[ -n "$g_debugging" ] && set -x
|
[ -n "$g_debugging" ] && set -x
|
||||||
[ $# -eq 1 ] && missing_argument
|
[ $# -eq 1 ] && missing_argument
|
||||||
drop_command $@
|
drop_command $@
|
||||||
;;
|
;;
|
||||||
logdrop)
|
logdrop)
|
||||||
|
only_root
|
||||||
get_config
|
get_config
|
||||||
[ -n "$g_debugging" ] && set -x
|
[ -n "$g_debugging" ] && set -x
|
||||||
[ $# -eq 1 ] && missing_argument
|
[ $# -eq 1 ] && missing_argument
|
||||||
logdrop_command $@
|
logdrop_command $@
|
||||||
;;
|
;;
|
||||||
reject|logreject)
|
reject|logreject)
|
||||||
|
only_root
|
||||||
get_config
|
get_config
|
||||||
[ -n "$g_debugging" ] && set -x
|
[ -n "$g_debugging" ] && set -x
|
||||||
[ $# -eq 1 ] && missing_argument
|
[ $# -eq 1 ] && missing_argument
|
||||||
reject_command $@
|
reject_command $@
|
||||||
;;
|
;;
|
||||||
open|close)
|
open|close)
|
||||||
|
only_root
|
||||||
get_config
|
get_config
|
||||||
shift
|
shift
|
||||||
open_close_command $@
|
open_close_command $@
|
||||||
;;
|
;;
|
||||||
allow)
|
allow)
|
||||||
|
only_root
|
||||||
get_config
|
get_config
|
||||||
allow_command $@
|
allow_command $@
|
||||||
;;
|
;;
|
||||||
add)
|
add)
|
||||||
|
only_root
|
||||||
get_config
|
get_config
|
||||||
shift
|
shift
|
||||||
add_command $@
|
add_command $@
|
||||||
;;
|
;;
|
||||||
delete)
|
delete)
|
||||||
|
only_root
|
||||||
get_config
|
get_config
|
||||||
shift
|
shift
|
||||||
delete_command $@
|
delete_command $@
|
||||||
;;
|
;;
|
||||||
save)
|
save)
|
||||||
|
only_root
|
||||||
get_config
|
get_config
|
||||||
[ -n "$g_debugging" ] && set -x
|
[ -n "$g_debugging" ] && set -x
|
||||||
save_command $@
|
save_command $@
|
||||||
;;
|
;;
|
||||||
forget)
|
forget)
|
||||||
|
only_root
|
||||||
get_config
|
get_config
|
||||||
forget_command $@
|
forget_command $@
|
||||||
;;
|
;;
|
||||||
@ -4721,11 +4769,13 @@ shorewall_cli() {
|
|||||||
ipdecimal_command $@
|
ipdecimal_command $@
|
||||||
;;
|
;;
|
||||||
restore)
|
restore)
|
||||||
|
only_root
|
||||||
get_config
|
get_config
|
||||||
shift
|
shift
|
||||||
restore_command $@
|
restore_command $@
|
||||||
;;
|
;;
|
||||||
call)
|
call)
|
||||||
|
only_root
|
||||||
get_config
|
get_config
|
||||||
[ -n "$g_debugging" ] && set -x
|
[ -n "$g_debugging" ] && set -x
|
||||||
#
|
#
|
||||||
@ -4763,17 +4813,20 @@ shorewall_cli() {
|
|||||||
usage
|
usage
|
||||||
;;
|
;;
|
||||||
iptrace)
|
iptrace)
|
||||||
|
only_root
|
||||||
get_config
|
get_config
|
||||||
shift
|
shift
|
||||||
iptrace_command $@
|
iptrace_command $@
|
||||||
;;
|
;;
|
||||||
noiptrace)
|
noiptrace)
|
||||||
|
only_root
|
||||||
get_config
|
get_config
|
||||||
shift
|
shift
|
||||||
noiptrace_command $@
|
noiptrace_command $@
|
||||||
;;
|
;;
|
||||||
savesets)
|
savesets)
|
||||||
[ $# -eq 1 ] || too_many_arguments $2
|
[ $# -eq 1 ] || too_many_arguments $2
|
||||||
|
only_root
|
||||||
get_config
|
get_config
|
||||||
[ -n "$g_debugging" ] && set -x
|
[ -n "$g_debugging" ] && set -x
|
||||||
savesets1
|
savesets1
|
||||||
|
@ -47,11 +47,10 @@ get_config() {
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$(id -u)" -eq 0 ]; then
|
if [ -n "$g_shorewalldir" ]; then
|
||||||
config=$(find_file ${PRODUCT}.conf)
|
|
||||||
else
|
|
||||||
[ -n "$g_shorewalldir" ] || fatal_error "Ordinary users may not $COMMAND the $CONFDIR/$PRODUCT configuration"
|
|
||||||
config="$g_shorewalldir/$PRODUCT.conf"
|
config="$g_shorewalldir/$PRODUCT.conf"
|
||||||
|
else
|
||||||
|
config=$(find_file ${PRODUCT}.conf)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -f $config ]; then
|
if [ -f $config ]; then
|
||||||
@ -363,6 +362,17 @@ get_config() {
|
|||||||
[ -f $lib ] && . $lib
|
[ -f $lib ] && . $lib
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Ensure that the effective UID is 0 or that we are dealing with a private configuration
|
||||||
|
#
|
||||||
|
ensure_root() {
|
||||||
|
if [ $(id -u) -ne 0 ]; then
|
||||||
|
if [ -z "$g_shorewalldir" -o "$g_shorewalldir" = $CONFDIR/$PRODUCT ]; then
|
||||||
|
startup_error "Ordinary users may not $COMMAND the $CONFDIR/$PRODUCT configuration"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
#
|
#
|
||||||
# Determine if there are config files newer than the passed object
|
# Determine if there are config files newer than the passed object
|
||||||
#
|
#
|
||||||
@ -413,11 +423,7 @@ compiler() {
|
|||||||
|
|
||||||
pc=${LIBEXECDIR}/shorewall/compiler.pl
|
pc=${LIBEXECDIR}/shorewall/compiler.pl
|
||||||
|
|
||||||
if [ $(id -u) -ne 0 ]; then
|
ensure_root
|
||||||
if [ -z "$g_shorewalldir" -o "$g_shorewalldir" = $CONFDIR/$PRODUCT ]; then
|
|
||||||
startup_error "Ordinary users may not $COMMAND the $CONFDIR/$PRODUCT configuration"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
#
|
#
|
||||||
# We've now set g_shorewalldir so recalculate CONFIG_PATH
|
# We've now set g_shorewalldir so recalculate CONFIG_PATH
|
||||||
#
|
#
|
||||||
@ -1741,6 +1747,7 @@ compiler_command() {
|
|||||||
compile_command $@
|
compile_command $@
|
||||||
;;
|
;;
|
||||||
refresh)
|
refresh)
|
||||||
|
only_root
|
||||||
get_config Yes Yes
|
get_config Yes Yes
|
||||||
shift
|
shift
|
||||||
refresh_command $@
|
refresh_command $@
|
||||||
@ -1762,11 +1769,13 @@ compiler_command() {
|
|||||||
export_command $@
|
export_command $@
|
||||||
;;
|
;;
|
||||||
try)
|
try)
|
||||||
|
only_root
|
||||||
get_config Yes
|
get_config Yes
|
||||||
shift
|
shift
|
||||||
try_command $@
|
try_command $@
|
||||||
;;
|
;;
|
||||||
safe-reload|safe-restart|safe-start)
|
safe-reload|safe-restart|safe-start)
|
||||||
|
only_root
|
||||||
get_config Yes
|
get_config Yes
|
||||||
shift
|
shift
|
||||||
safe_commands $@
|
safe_commands $@
|
||||||
|
Loading…
Reference in New Issue
Block a user