Skip to content

Commit

Permalink
Fixed the remediation for rsyslog_files_permissions
Browse files Browse the repository at this point in the history
- Stripped quotes and brackets from extracted paths.
- Dropped apparent config files from extracted list of logfile paths.
  • Loading branch information
matejak committed Oct 7, 2019
1 parent a396559 commit c369b98
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,19 @@ do
# From each of these files extract just particular log file path(s), thus:
# * Ignore lines starting with space (' '), comment ('#"), or variable syntax ('$') characters,
# * Ignore empty lines,
# * Strip quotes and closing brackets from paths.
# * Ignore paths that match /etc.*\.conf, as those are paths, but likely not log files
# * From the remaining valid rows select only fields constituting a log file path
# Text file column is understood to represent a log file path if and only if all of the following are met:
# * it contains at least one slash '/' character,
# * it doesn't contain space (' '), colon (':'), and semicolon (';') characters
# Search log file for path(s) only in case it exists!
if [[ -f "${LOG_FILE}" ]]
then
MATCHED_ITEMS=$(sed -e "/^[[:space:]|#|$]/d ; s/[^\/]*[[:space:]]*\([^:;[:space:]]*\)/\1/g ; /^$/d" "${LOG_FILE}")
NORMALIZED_CONFIG_FILE_LINES=$(sed -e "/^[[:space:]|#|$]/d" "${LOG_FILE}")
ROUGH_EXTRACTED_PATHS=$(sed -e "s/[^\/]*[[:space:]]*\([^:;[:space:]]*\)/\1/g" <<< "${NORMALIZED_CONFIG_FILE_LINES}")
CLEANED_PATHS=$(sed -e "s/[\"')]//g; /\\/etc.*\.conf/d" <<< "${ROUGH_EXTRACTED_PATHS}")
MATCHED_ITEMS=$(sed -e "/^$/d" <<< "${CLEANED_PATHS}")
# Since above sed command might return more than one item (delimited by newline), split the particular
# matches entries into new array specific for this log file
readarray -t ARRAY_FOR_LOG_FILE <<< "$MATCHED_ITEMS"
Expand Down

0 comments on commit c369b98

Please sign in to comment.