Index: scripts/rootsshaccess.sh =================================================================== diff -u -r7d194844bb325200b78da21ae7457bb7f7543ec7 -rb743e6d20c409d112cfe5a82366dbdf79460203c --- scripts/rootsshaccess.sh (.../rootsshaccess.sh) (revision 7d194844bb325200b78da21ae7457bb7f7543ec7) +++ scripts/rootsshaccess.sh (.../rootsshaccess.sh) (revision b743e6d20c409d112cfe5a82366dbdf79460203c) @@ -15,31 +15,36 @@ # ############################################################################ + +# Description +# Sets SSH Access and Root Login and return current configuration +# Parameters +# Configuration for SSH Access and Root Login +# Retruns +# Set configuration + +# sources +. ./_errors_ +. ./_functions_ + +# variables SSHD_CONFIG="/etc/default/dropbear" SSH_SERVICE="system-dropbear.slice" -ERR_EXECUTION=201 +PARAM_COUNT=1 _enable=1 _disable=0 -#TODO Move to globals.sh -function check_num() { - if [[ $1 != 0 ]]; then - # echo "execution failed $1" - exit $ERR_EXECUTION - fi -} - +# functions function sshd_set() { if [[ $_enable == $1 ]]; then sudo systemctl start $SSH_SERVICE - check_num $? ", started" else # stop the ssh service sudo systemctl stop $SSH_SERVICE - check_num $? ", stopped" fi + check_result "$?" "$ERR_CMDFAIL_SSH_SERVICE" } function sshd_get() { @@ -48,20 +53,21 @@ else echo $_disable fi + check_result "$?" "$ERR_CMDFAIL_SSH_STATUS" } function root_set() { if [[ $_enable == $1 ]]; then # Remove -w from DROPBEAR_EXTRA_ARGS if present sudo sed -i 's/-w//g' $SSHD_CONFIG - check_num $? " enabled" + check_result "$?" "$ERR_CMDFAIL_ROOT_LOGIN_ENABLED" else # Add -w if not already present if ! grep -q '\-w' $SSHD_CONFIG; then # Append to DROPBEAR_EXTRA_ARGS sudo sed -i '/^DROPBEAR_EXTRA_ARGS=/ s/"$/ -w"/' $SSHD_CONFIG fi - check_num $? " disabled" + check_result "$?" "$ERR_CMDFAIL_ROOT_LOGIN_DISABLED" fi } @@ -72,6 +78,7 @@ else echo $_enable fi + check_result "$?" "$ERR_CMDFAIL_ROOT_LOGIN_STATUS" } function handleCommand() { @@ -111,6 +118,10 @@ esac } +# checks +check_param_count "$#" "$PARAM_COUNT" + +# main case "$#" in 0) echo $(toCheckState) @@ -121,5 +132,6 @@ ;; esac +# exit gracefully echo "" exit 0