Fix some bug for 10.1.1

This commit is contained in:
Samson-W 2020-01-15 03:34:31 +08:00
parent 13ae52fb76
commit 490ee96c94

View File

@ -1,7 +1,7 @@
#!/bin/bash #!/bin/bash
# #
# harbian audit 7/8/9 Hardening # harbian audit 7/8/9 or CentOS8 Hardening
# #
# #
@ -14,45 +14,31 @@ set -u # One variable unset, it's over
HARDENING_LEVEL=3 HARDENING_LEVEL=3
PACKAGE='login'
OPTIONS='PASS_MAX_DAYS=90' OPTIONS='PASS_MAX_DAYS=90'
FILE='/etc/login.defs' FILE='/etc/login.defs'
SHA_FILE='/etc/shadow' SHA_FILE='/etc/shadow'
# This function will be called if the script status is on enabled / audit mode # This function will be called if the script status is on enabled / audit mode
audit () { audit () {
is_pkg_installed $PACKAGE SSH_PARAM=$(echo $OPTIONS | cut -d= -f 1)
if [ $FNRET != 0 ]; then SSH_VALUE=$(echo $OPTIONS | cut -d= -f 2)
crit "$PACKAGE is not installed!" PATTERN="^$SSH_PARAM[[:space:]]*$SSH_VALUE"
else does_pattern_exist_in_file $FILE "$PATTERN"
ok "$PACKAGE is installed" if [ $FNRET = 0 ]; then
SSH_PARAM=$(echo $OPTIONS | cut -d= -f 1) ok "$PATTERN is present in $FILE"
SSH_VALUE=$(echo $OPTIONS | cut -d= -f 2) else
PATTERN="^$SSH_PARAM[[:space:]]*$SSH_VALUE" crit "$PATTERN is not present in $FILE"
does_pattern_exist_in_file $FILE "$PATTERN" fi
if [ $FNRET = 0 ]; then
ok "$PATTERN is present in $FILE"
else
crit "$PATTERN is not present in $FILE"
fi
if [ $(egrep ^[^:]+:[^\!*] $SHA_FILE | awk -F: '$5 > "'$SSH_VALUE'" {print $1}' | wc -l) -gt 0 ]; then if [ $(egrep ^[^:]+:[^\!*] $SHA_FILE | awk -F: '$5 > "'$SSH_VALUE'" {print $1}' | wc -l) -gt 0 ]; then
crit "Have least user's maxinum password lifttime is greater than $SSH_VALUE day" crit "Have least user's maxinum password lifttime is greater than $SSH_VALUE day"
else else
ok "All user's maxinum password lifttime is equal or less than $SSH_VALUE day" ok "All user's maxinum password lifttime is equal or less than $SSH_VALUE day"
fi fi
fi
} }
# This function will be called if the script status is on enabled mode # This function will be called if the script status is on enabled mode
apply () { apply () {
is_pkg_installed $PACKAGE
if [ $FNRET = 0 ]; then
ok "$PACKAGE is installed"
else
crit "$PACKAGE is absent, installing it"
install_package $PACKAGE
fi
SSH_PARAM=$(echo $OPTIONS | cut -d= -f 1) SSH_PARAM=$(echo $OPTIONS | cut -d= -f 1)
SSH_VALUE=$(echo $OPTIONS | cut -d= -f 2) SSH_VALUE=$(echo $OPTIONS | cut -d= -f 2)
PATTERN="^$SSH_PARAM[[:space:]]*$SSH_VALUE" PATTERN="^$SSH_PARAM[[:space:]]*$SSH_VALUE"