Skip to content

Commit 9b94bbf

Browse files
committed
Sec: Fix input validation in v-restart-service and add logging
added new 'service' global validation format - restart arg must be bool if used
1 parent 5ffb61c commit 9b94bbf

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

bin/v-restart-service

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
# Argument definition
1313
service=$1
14-
force=$2
14+
restart=$2
1515

1616
# Includes
1717
source $HESTIA/func/main.sh
@@ -23,6 +23,7 @@ PATH="$PATH:/usr/local/sbin:/sbin:/usr/sbin:/root/bin"
2323
#----------------------------------------------------------#
2424

2525
check_args '1' "$#" 'SERVICE'
26+
is_format_valid 'service' 'restart'
2627

2728
#----------------------------------------------------------#
2829
# Action #
@@ -32,7 +33,7 @@ if [ "$service" = "iptables" ]; then
3233
# Run the restart rules for iptables firewall
3334
$BIN/v-stop-firewall
3435
$BIN/v-update-firewall
35-
elif [ -z "$force" -o "$force" = "no" ] && [ \
36+
elif [ -z "$restart" -o "$restart" = "no" ] && [ \
3637
"$service" = "nginx" -o \
3738
"$service" = "apache2" -o \
3839
"$service" = "exim4" -o \
@@ -64,4 +65,7 @@ if [ $? -ne 0 ]; then
6465
log_history "Restart of $service failed."
6566
fi
6667

68+
# Logging
69+
log_event "$OK" "$ARGUMENTS"
70+
6771
exit

func/main.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,14 @@ is_format_valid_shell() {
836836
exit $E_INVALID
837837
fi
838838
}
839+
840+
# Service name validator
841+
is_service_format_valid() {
842+
if ! [[ "$1" =~ ^[[:alnum:]][-|\.|_[:alnum:]]{0,64}$ ]]; then
843+
check_result $E_INVALID "invalid $2 format :: $1"
844+
fi
845+
}
846+
839847
# Format validation controller
840848
is_format_valid() {
841849
for arg_name in $*; do
@@ -902,6 +910,7 @@ is_format_valid() {
902910
restart) is_boolean_format_valid "$arg" 'restart' ;;
903911
rtype) is_dns_type_format_valid "$arg" ;;
904912
rule) is_int_format_valid "$arg" "rule id" ;;
913+
service) is_service_format_valid "$arg" "$arg_name" ;;
905914
soa) is_domain_format_valid "$arg" 'SOA' ;;
906915
#missing command: is_format_valid_shell
907916
shell) is_format_valid_shell "$arg" ;;

0 commit comments

Comments
 (0)