Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/CISOfy/lynis.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Boelen <michael.boelen@cisofy.com>2019-06-29 20:34:12 +0300
committerMichael Boelen <michael.boelen@cisofy.com>2019-06-29 20:34:12 +0300
commit08e8e59197e76f177457b4e1850236224e605fa0 (patch)
treeee49e54812e2cf6cc03207d43e7b2080a40a07fc /include/functions
parent81c8f1f2a6a4c2b554853ca15fda2ee2cf2e52d2 (diff)
New function: SafeInput
Diffstat (limited to 'include/functions')
-rw-r--r--include/functions32
1 files changed, 32 insertions, 0 deletions
diff --git a/include/functions b/include/functions
index 6f067761..3d43f7c1 100644
--- a/include/functions
+++ b/include/functions
@@ -86,6 +86,7 @@
# ReportSuggestion Add a suggestion to report file
# ReportWarning Add a warning and priority to report file
# SafePerms Check if a file has safe permissions
+# SafeInput Test provided string to see if it contains unwanted characters
# SearchItem Search a string in a file
# ShowComplianceFinding Display a particular finding regarding compliance or a security standard
# ShowSymlinkPath Show a path behind a symlink
@@ -2511,6 +2512,37 @@
################################################################################
+ # Name : SafeInput()
+ # Description : Test provided string to see if it contains unwanted characters
+ #
+ # Input : string + optional class (parameter 2)
+ # Returns : 0 (input considered to be safe) or 1 (validation failed)
+ ################################################################################
+
+ SafeInput() {
+ exitcode=1
+ # By default remove only control characters
+ if [ $# -eq 1 ]; then
+ input="$1"
+ cleaned=$(echo ${input} | tr -d '[:cntrl:]')
+ # If know what to test against, then see if input matches the specified class
+ elif [ $# -eq 2 ]; then
+ input="$1"
+ testchars="$2"
+ cleaned=$(echo $1 | tr -cd "${testchars}")
+ else
+ ExitFatal "No argument or too many arguments provided to SafeInput()"
+ fi
+
+ if [ "${cleaned}" = "${input}" ]; then
+ exitcode=0
+ fi
+ return ${exitcode}
+ }
+
+
+
+ ################################################################################
# Name : SafePerms()
# Return : 0 (file OK) or break
################################################################################