mirror of
https://github.com/CISOfy/lynis.git
synced 2025-07-31 01:34:23 +02:00
Added functions and variables for creation of temporary files
This commit is contained in:
parent
d5867762c6
commit
1cb90916ee
@ -148,6 +148,8 @@ unset LANG
|
|||||||
SSHKEYSCANFOUND=0
|
SSHKEYSCANFOUND=0
|
||||||
SYSLOGNGBINARY=""
|
SYSLOGNGBINARY=""
|
||||||
SYSTEMCTLBINARY=""
|
SYSTEMCTLBINARY=""
|
||||||
|
TEMP_FILE=""
|
||||||
|
TEMP_FILES=""
|
||||||
TEST_SKIP_ALWAYS=""
|
TEST_SKIP_ALWAYS=""
|
||||||
TESTS_CATEGORY_TO_PERFORM=""
|
TESTS_CATEGORY_TO_PERFORM=""
|
||||||
TESTS_EXECUTED=""
|
TESTS_EXECUTED=""
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
# AddSystemGroup Adds a system to a group
|
# AddSystemGroup Adds a system to a group
|
||||||
# CheckFilePermissions Check file permissions
|
# CheckFilePermissions Check file permissions
|
||||||
# CheckUpdates Determine if a new version of Lynis is available
|
# CheckUpdates Determine if a new version of Lynis is available
|
||||||
|
# CreateTempFile Create a temporary file
|
||||||
# counttests Count number of performed tests
|
# counttests Count number of performed tests
|
||||||
# Debug Display additional information on the screen (not suited for cronjob)
|
# Debug Display additional information on the screen (not suited for cronjob)
|
||||||
# DigitsOnly Return only the digits from a string
|
# DigitsOnly Return only the digits from a string
|
||||||
@ -47,6 +48,8 @@
|
|||||||
# ParseNginx Parse nginx configuration lines
|
# ParseNginx Parse nginx configuration lines
|
||||||
# Progress Show progress on screen
|
# Progress Show progress on screen
|
||||||
# RandomString Show a random string
|
# RandomString Show a random string
|
||||||
|
# RemovePIDFile Remove PID file
|
||||||
|
# RemoveTempFiles Remove temporary files
|
||||||
# Report Add string of data to report file
|
# Report Add string of data to report file
|
||||||
# ReportException Add an exception to the report file (for debugging purposes)
|
# ReportException Add an exception to the report file (for debugging purposes)
|
||||||
# ReportSuggestion Add a suggestion to report file
|
# ReportSuggestion Add a suggestion to report file
|
||||||
@ -167,6 +170,32 @@
|
|||||||
CTESTS_PERFORMED=`expr ${CTESTS_PERFORMED} + 1`
|
CTESTS_PERFORMED=`expr ${CTESTS_PERFORMED} + 1`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
# Name : CreateTempFile
|
||||||
|
# Description : Creates a temporary file
|
||||||
|
# Returns : TEMPFILE
|
||||||
|
################################################################################
|
||||||
|
|
||||||
|
CreateTempFile()
|
||||||
|
{
|
||||||
|
TEMPFILE=""
|
||||||
|
if [ "${OS}" = "AIX" ]; then
|
||||||
|
RANDOMSTRING1=`echo lynis-$(od -N4 -tu /dev/random | awk 'NR==1 {print $2} {}')`
|
||||||
|
TEMP_FILE="/tmp/${RANDOMSTRING1}"
|
||||||
|
touch ${TEMP_FILE}
|
||||||
|
else
|
||||||
|
TEMP_FILE=`mktemp /tmp/lynis.XXXXXXXXXX` || exit 1
|
||||||
|
fi
|
||||||
|
if [ ! "${TEMP_FILE}" = "" ]; then
|
||||||
|
logtext "Action: created temporary file ${TEMP_FILE}"
|
||||||
|
else
|
||||||
|
Fatal "Could not create a temporary file"
|
||||||
|
fi
|
||||||
|
# Add temporary file to queue for cleanup later
|
||||||
|
TEMP_FILES="${TEMP_FILES} ${TEMP_FILE}"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
# Determine if a directory exists
|
# Determine if a directory exists
|
||||||
DirectoryExists()
|
DirectoryExists()
|
||||||
{
|
{
|
||||||
@ -180,6 +209,7 @@
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# Name : Debug
|
# Name : Debug
|
||||||
# Description : Show additional information on screen
|
# Description : Show additional information on screen
|
||||||
@ -243,7 +273,7 @@
|
|||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "INVALID OPTION (Display): $1"
|
echo "INVALID OPTION (Display): $1"
|
||||||
exit 1
|
ExitFatal
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
# Go to next parameter
|
# Go to next parameter
|
||||||
@ -296,28 +326,38 @@
|
|||||||
ExitClean()
|
ExitClean()
|
||||||
{
|
{
|
||||||
RemovePIDFile
|
RemovePIDFile
|
||||||
|
RemoveTempFiles
|
||||||
|
LogText "${PROGRAM_NAME} ended successfully."
|
||||||
exit 0
|
exit 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# Clean exit with custom code
|
# Clean exit with custom code
|
||||||
ExitCustom()
|
ExitCustom()
|
||||||
{
|
{
|
||||||
RemovePIDFile
|
RemovePIDFile
|
||||||
|
RemoveTempFiles
|
||||||
# Exit with the exit code given, otherwise use 1
|
# Exit with the exit code given, otherwise use 1
|
||||||
if [ $# -eq 1 ]; then
|
if [ $# -eq 1 ]; then
|
||||||
|
LogText "${PROGRAM_NAME} ended with exit code $1."
|
||||||
exit $1
|
exit $1
|
||||||
else
|
else
|
||||||
|
LogText "${PROGRAM_NAME} ended with exit code 1."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# Clean exit (removing temp files, PID files), with error code 1
|
# Clean exit (removing temp files, PID files), with error code 1
|
||||||
ExitFatal()
|
ExitFatal()
|
||||||
{
|
{
|
||||||
RemovePIDFile
|
RemovePIDFile
|
||||||
|
RemoveTempFiles
|
||||||
|
LogText "${PROGRAM_NAME} ended with exit code 1."
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# Determine if a file exists
|
# Determine if a file exists
|
||||||
FileExists()
|
FileExists()
|
||||||
{
|
{
|
||||||
@ -953,15 +993,11 @@
|
|||||||
echo ""; echo "Interrupt detected."
|
echo ""; echo "Interrupt detected."
|
||||||
# Remove PID
|
# Remove PID
|
||||||
RemovePIDFile
|
RemovePIDFile
|
||||||
|
RemoveTempFiles
|
||||||
# Clean up temp files
|
|
||||||
if [ ! "${TMPFILE}" = "" ]; then if [ -f ${TMPFILE} ]; then rm -f ${TMPFILE}; fi; fi
|
|
||||||
if [ ! "${TMPFILE2}" = "" ]; then if [ -f ${TMPFILE2} ]; then rm -f ${TMPFILE2}; fi; fi
|
|
||||||
|
|
||||||
Display --text "Cleaning up..." --result DONE --color GREEN
|
Display --text "Cleaning up..." --result DONE --color GREEN
|
||||||
|
|
||||||
# Exit with exit code 1
|
ExitFatal
|
||||||
exit 1
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Parse nginx configuration lines
|
# Parse nginx configuration lines
|
||||||
@ -1305,6 +1341,33 @@
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# Remove any temporary files
|
||||||
|
RemoveTempFiles()
|
||||||
|
{
|
||||||
|
if [ ! "${TEMP_FILES}" = "" ]; then
|
||||||
|
LogText "Temporary files: ${TEMP_FILES}"
|
||||||
|
# Clean up temp files
|
||||||
|
for FILE in ${TEMP_FILES}; do
|
||||||
|
# Temporary files should be in /tmp
|
||||||
|
TMPFILE=`echo ${FILE} | egrep "^/tmp/lynis" | grep -v "\.\."`
|
||||||
|
if [ ! "${TMPFILE}" = "" ]; then
|
||||||
|
if [ -f ${TMPFILE} ]; then
|
||||||
|
LogText "Action: removing temporary file ${TMPFILE}"
|
||||||
|
rm -f ${TMPFILE}
|
||||||
|
else
|
||||||
|
LogText "Info: temporary file ${TMPFILE} was already removed"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
LogText "Found invalid temporary file (${FILE}), not removed. Check your /tmp directory."
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
else
|
||||||
|
LogText "No temporary files to be deleted"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
# Dump to report file
|
# Dump to report file
|
||||||
Report()
|
Report()
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user