From 25c083a731a3170ee9c5a0fd83729db61b225c62 Mon Sep 17 00:00:00 2001 From: Samson-W Date: Tue, 21 May 2019 17:45:51 +0800 Subject: [PATCH] Fix some bugs for 8.2.4 --- .../8.2.4_set_logfile_perm_cfg_rsyslog.sh | 33 +++++++++---------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/bin/hardening/8.2.4_set_logfile_perm_cfg_rsyslog.sh b/bin/hardening/8.2.4_set_logfile_perm_cfg_rsyslog.sh index 45a6452..b8e615d 100755 --- a/bin/hardening/8.2.4_set_logfile_perm_cfg_rsyslog.sh +++ b/bin/hardening/8.2.4_set_logfile_perm_cfg_rsyslog.sh @@ -24,8 +24,8 @@ OWNER_USER_KEY='$FileOwner' OWNER_GROUP_KEY='$FileGroup' PERMIS_KEY='$FileCreateMode' -FILE='$SYSLOG_BASEDIR/rsyslog.conf' -FILE_WIDE='$SYSLOG_BASEDIR/rsyslog.d/*.conf' +FILE='/etc/rsyslog.conf' +FILE_WIDE='/etc/rsyslog.d/*.conf' # This function will be called if the script status is on enabled / audit mode audit () { @@ -37,22 +37,22 @@ audit () { if [ $FNRET != 0 ]; then crit "$FILE is not exist! " else - does_pattern_exist_in_file "$FILE" "$OWNER_USER_KEY" + does_pattern_exist_in_file "$FILE" "^\\$OWNER_USER_KEY" if [ $FNRET != 0 ]; then crit "$OWNER_USER_KEY is not exist in $FILE" else - OWNER_USER_NAME=$(grep "$OWNER_USER_KEY" $FILE $FILE_WIDE 2>>/dev/null | awk -F: '{print $2}' | awk '{print $2}') + OWNER_USER_NAME=$(grep "^\\$OWNER_USER_KEY" $FILE $FILE_WIDE 2>>/dev/null | awk -F: '{print $2}' | awk '{print $2}') if [ "$OWNER_USER_NAME" != "$USER" ]; then crit "File owner not set is root!" else ok "File owner set is root!" fi fi - does_pattern_exist_in_file "$FILE" "$OWNER_GROUP_KEY" + does_pattern_exist_in_file "$FILE" "^\\$OWNER_GROUP_KEY" if [ $FNRET != 0 ]; then crit "$OWNER_GROUP_KEY is not exist in $FILE" else - OWNER_GROUP_NAME=$(grep "$OWNER_GROUP_KEY" $FILE $FILE_WIDE 2>>/dev/null | awk -F: '{print $2}' | awk '{print $2}') + OWNER_GROUP_NAME=$(grep "^\\$OWNER_GROUP_KEY" $FILE $FILE_WIDE 2>>/dev/null | awk -F: '{print $2}' | awk '{print $2}') if [ "$OWNER_GROUP_NAME" != "$GROUP" ]; then crit "File group not set is $GROUP!" else @@ -60,12 +60,12 @@ audit () { fi fi - does_pattern_exist_in_file "$FILE" "$PERMIS_KEY" + does_pattern_exist_in_file "$FILE" "^\\$PERMIS_KEY" if [ $FNRET != 0 ]; then crit "$PERMIS_KEY is not exist in $FILE" else - PERMIS_KEY_NAME=$(grep "$PERMIS_KEY" $FILE $FILE_WIDE 2>>/dev/null | awk -F: '{print $2}' | awk '{print $2}') - if [ "$PERMIS_KEY_NAME" != "$PERMISSIONS" ]; then + PERMIS_KEY_NAME=$(grep "^\\$PERMIS_KEY" $FILE $FILE_WIDE 2>>/dev/null | awk -F: '{print $2}' | awk '{print $2}') + if [ "$PERMIS_KEY_NAME" != "$PERMISSIONS" -a "$PERMIS_KEY_NAME" != "0$PERMISSIONS" ]; then crit "File permissions not set is $PERMISSIONS!" else ok "File permissions set is $PERMISSIONS!" @@ -85,12 +85,12 @@ apply () { if [ $FNRET != 0 ]; then crit "$FILE is not exist! Please check." else - does_pattern_exist_in_file "$FILE" "$OWNER_USER_KEY" + does_pattern_exist_in_file "$FILE" "^\\$OWNER_USER_KEY" if [ $FNRET != 0 ]; then warn "$OWNER_USER_KEY is not exist in $FILE, add it" add_end_of_file $FILE "$OWNER_USER_KEY $USER" else - OWNER_USER_NAME=$(grep "$OWNER_USER_KEY" $FILE $FILE_WIDE 2>>/dev/null | awk -F: '{print $2}' | awk '{print $2}') + OWNER_USER_NAME=$(grep "^\\$OWNER_USER_KEY" $FILE $FILE_WIDE 2>>/dev/null | awk -F: '{print $2}' | awk '{print $2}') if [ "$OWNER_USER_NAME" != "$USER" ]; then warn "File owner not set is $USER! Reset it" replace_in_file $FILE "$OWNER_USER_KEY.*" "$OWNER_USER_KEY $USER" @@ -98,12 +98,12 @@ apply () { ok "File owner set is $USER!" fi fi - does_pattern_exist_in_file "$FILE" "$OWNER_GROUP_KEY" + does_pattern_exist_in_file "$FILE" "^\\$OWNER_GROUP_KEY" if [ $FNRET != 0 ]; then warn "$OWNER_GROUP_KEY is not exist in $FILE, add it" add_end_of_file $FILE "$OWNER_GROUP_KEY $GROUP" else - OWNER_GROUP_NAME=$(grep "$OWNER_GROUP_KEY" $FILE $FILE_WIDE 2>>/dev/null | awk -F: '{print $2}' | awk '{print $2}') + OWNER_GROUP_NAME=$(grep "^\\$OWNER_GROUP_KEY" $FILE $FILE_WIDE 2>>/dev/null | awk -F: '{print $2}' | awk '{print $2}') if [ "$OWNER_GROUP_NAME" != "$GROUP" ]; then warn "File group not set is $GROUP! Reset it" replace_in_file $FILE "$OWNER_GROUP_KEY.*" "$OWNER_GROUP_KEY $GROUP" @@ -112,13 +112,13 @@ apply () { fi fi - does_pattern_exist_in_file "$FILE" "$PERMIS_KEY" + does_pattern_exist_in_file "$FILE" "^\\$PERMIS_KEY" if [ $FNRET != 0 ]; then warn "$PERMIS_KEY is not exist in $FILE, add it" add_end_of_file $FILE "$PERMIS_KEY $PERMISSIONS" else - PERMIS_KEY_NAME=$(grep "$PERMIS_KEY" $FILE $FILE_WIDE 2>>/dev/null | awk -F: '{print $2}' | awk '{print $2}') - if [ "$PERMIS_KEY_NAME" != "$PERMISSIONS" ]; then + PERMIS_KEY_NAME=$(grep "^\\$PERMIS_KEY" $FILE $FILE_WIDE 2>>/dev/null | awk -F: '{print $2}' | awk '{print $2}') + if [ "$PERMIS_KEY_NAME" != "$PERMISSIONS" -a "$PERMIS_KEY_NAME" != "0$PERMISSIONS" ]; then warn "File permissions not set is $PERMISSIONS! Reset it" replace_in_file $FILE "$PERMIS_KEY.*" "$PERMIS_KEY $PERMISSIONS" else @@ -133,7 +133,6 @@ apply () { create_config() { cat <