Fix some bugs for 8.2.4

This commit is contained in:
Samson-W 2019-05-21 17:45:51 +08:00
parent 3717ab1550
commit 25c083a731
1 changed files with 16 additions and 17 deletions

View File

@ -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 <<EOF
status=disabled
SYSLOG_BASEDIR='/etc'
EOF
}