Skip to content

Commit

Permalink
add validation to some file configs
Browse files Browse the repository at this point in the history
  • Loading branch information
ogabriel committed Jun 28, 2024
1 parent e42c7b3 commit 539eefc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/config_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ user_files_dir=$config_dir/user/

function UserFile() {
ValidateFunctionParams 1 $# $FUNCNAME
ValidateFileName $1

local from_file=$user_files_dir$1

Expand All @@ -257,6 +258,7 @@ function UserFile() {

function UserFileFromTo() {
ValidateExactFunctionParams 2 $# $FUNCNAME
ValidateFileName $1

local from_file=$user_files_dir$1

Expand All @@ -269,6 +271,7 @@ function UserFileFromTo() {

function UserDirectory() {
ValidateFunctionParams 1 $# $FUNCNAME
ValidateFileName $1

local from_directory=$user_files_dir$1

Expand All @@ -281,6 +284,7 @@ function UserDirectory() {

function UserDirectoryFromTo() {
ValidateExactFunctionParams 2 $# $FUNCNAME
ValidateFileName $1

local from_directory=$user_files_dir$1

Expand All @@ -299,6 +303,7 @@ function SSHGenKey() {
shift
while [[ $# -gt 0 ]]; do
if [[ "$1" =~ --file=.+ ]]; then
ValidateFileName ${1#--file=}
shift
elif [[ "$1" =~ --comment=.+ ]]; then
shift
Expand All @@ -312,6 +317,7 @@ function SSHGenKey() {

function SSHAddKey() {
ValidateExactFunctionParams 1 $# $FUNCNAME
ValidateFileName $1

ssh_add_keys+=($1)
}
Expand Down
8 changes: 8 additions & 0 deletions lib/helper_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,11 @@ function ValidateExactFunctionParams() {
fi
fi
}

function ValidateFileName() {
if [[ $1 == $HOME* ]] || [[ $1 == "~/"* ]]; then
Error "File $1 starts with the some directory, remove '~/' or \$HOME from the path"
elif [[ $1 == "/"* ]]; then
Error "File $1 starts with a '/', remove it"
fi
}

0 comments on commit 539eefc

Please sign in to comment.