forked from ComplianceAsCode/content
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
40 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 3 additions & 2 deletions
5
...ing/ensure_rsyslog_log_file_configuration/rsyslog_remote_access_monitoring/bash/shared.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,26 @@ | ||
# platform = multi_platform_all | ||
|
||
declare -A REMOTE_METHODS=( ['auth.*']='^[^#]*auth\.\*.*$' ['authpriv.*']='^[^#]*authpriv\.\*.*$' ['daemon.*']='^[^#]*daemon\.\*.*$' ) | ||
declare -A LOCATIONS=( ['auth.*']='/var/log/secure' ['authpriv.*']='/var/log/secure' ['daemon.*']='/var/log/messages' ) | ||
|
||
if [[ ! -f /etc/rsyslog.conf ]]; then | ||
# Something is not right, create the file | ||
touch /etc/rsyslog.conf | ||
fi | ||
|
||
APPEND_LINE=$(sed -rn '/^\S+\s+\/var\/log\/secure$/p' /etc/rsyslog.conf) | ||
|
||
# Loop through the remote methods associative array | ||
for K in "${!REMOTE_METHODS[@]}" | ||
do | ||
# Check to see if selector/value exists | ||
if ! grep -rq "${REMOTE_METHODS[$K]}" /etc/rsyslog.*; then | ||
APPEND_LINE=$(sed -rn "/^\S+\s+\${LOCATIONS[$K]}$/p" /etc/rsyslog.conf) | ||
# Make sure we have a line to insert after, otherwise append to end | ||
if [[ ! -z ${APPEND_LINE} ]]; then | ||
# Add selector to file | ||
sed -r -i "0,/^(\S+\s+\/var\/log\/secure$)/s//\1\n${K} \/var\/log\/secure/" /etc/rsyslog.conf | ||
else | ||
echo "${K} /var/log/secure" >> /etc/rsyslog.conf | ||
echo "${K} ${LOCATIONS[$K]}" >> /etc/rsyslog.conf | ||
fi | ||
fi | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
...slog_log_file_configuration/rsyslog_remote_access_monitoring/tests/differnt_files.pass.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/bin/bash | ||
# platform = multi_platform_all | ||
|
||
declare -A REMOTE_METHODS=( ['auth.*']='^.*auth\.\*.*$' ['authpriv.*']='^.*authpriv\.\*.*$' ['daemon.*']='^.*daemon\.\*.*$' ) | ||
RSYSLOG_CONF='/etc/rsyslog.conf' | ||
RSYSLOG_D_FOLDER='/etc/rsyslog.d' | ||
RSYSLOG_D_FILES='/etc/rsyslog.d/*' | ||
|
||
|
||
# clean up .d conf files (if applicable) | ||
if [[ -d ${RSYSLOG_D_FOLDER} ]]; then | ||
for rsyslog_d_file in ${RSYSLOG_D_FILES} | ||
do | ||
for K in ${!REMOTE_METHODS[@]} | ||
do | ||
if grep -q "${REMOTE_METHODS[$K]}" ${rsyslog_d_file}; then | ||
sed -i "/${REMOTE_METHODS[$K]}/d" ${rsyslog_d_file} | ||
fi | ||
done | ||
done | ||
fi | ||
|
||
if [[ ! -f /etc/rsyslog.conf ]]; then | ||
# Something is not right, create the file | ||
touch /etc/rsyslog.conf | ||
fi | ||
|
||
echo "auth.*,authpriv.* /var/log/secure" >> $RSYSLOG_CONF | ||
echo "daemon.* /var/log/messages" >> $RSYSLOG_CONF |