#!/bin/bash
. /usr/share/preupgrade/common.sh

#END GENERATED SECTION

mkdir -p "$POSTUPGRADE_DIR/openssh" \
 && cp fix_sshkeys.sh "$POSTUPGRADE_DIR/openssh/" \
 || {
   log_error "Cannot copy the postupgrade script to the right directory."
   exit_error
}

echo "Private server's SSH keys in the /etc/ssh/ directory have a different group and permissions
in Red Hat Enterprise Linux 7, but it is fixed by the postupgrade script." > solution.txt

line=$( grep  -nm 1 "^\s*Match" /etc/ssh/sshd_config | cut -d ":" -f 1 )

[[ $line == "" ]] && exit $RESULT_FIXED

lines=$[ $( wc -l /etc/ssh/sshd_config | cut -d " " -f 1 ) - $line ]
cat /etc/ssh/sshd_config | tail -n $lines | grep -q "^\s*AuthorizedKeysCommand"

[[ $? -ne 0 ]] && exit $RESULT_FIXED


log_medium_risk "The 'AuthorizedKeysCommand' or 'AuthorizedKeysCommandUser' options were detected in the Match section."

echo "The 'AuthorizedKeysCommand' or 'AuthorizedKeysCommandUser' options were
detected in the Match section. They might not be accepted inside
this section. Check it. The bug will be fixed in the future." >> solution.txt

exit $RESULT_FAIL

