Fix bug for 8.2.4: when create file if dir is not, create file is fail.

This commit is contained in:
Samson-W 2019-04-16 03:57:53 +08:00
parent 449c818e22
commit f23c662b7c
2 changed files with 15 additions and 3 deletions

View File

@ -49,15 +49,16 @@ audit () {
# This function will be called if the script status is on enabled mode
apply () {
if [ $FNRET = 1 ]; then
does_file_exist "$SYSLOG_BASEDIR/syslog-ng.conf"
if [ $FNRET != 0 ]; then
warn "$SYSLOG_BASEDIR/syslog-ng.conf is not exist! "
else
FILES=$(grep "file(" $SYSLOG_BASEDIR/syslog-ng.conf | grep '"' | cut -d'"' -f 2)
for FILE in $FILES; do
does_file_exist $FILE
if [ $FNRET != 0 ]; then
info "$FILE does not exist"
touch $FILE
info "$FILE does not exist, create $FILE"
extend_touch_file $FILE
fi
has_file_correct_ownership $FILE $USER $GROUP
if [ $FNRET = 0 ]; then

View File

@ -822,3 +822,14 @@ check_input_with_established_is_accept()
fi
}
extend_touch_file()
{
NEWFILEALLPATH=$1
if [ ! -d $(dirname ${NEWFILEALLPATH}) ]; then
mkdir -p "$(dirname ${NEWFILEALLPATH})"
touch ${NEWFILEALLPATH}
else
touch ${NEWFILEALLPATH}
fi
}