This commit is contained in:
Maciej Żok 2026-02-20 22:51:27 -08:00 committed by GitHub
commit 2d90ee2bfb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 22 additions and 11 deletions

View file

@ -69,7 +69,8 @@
LogText "Result: hostnamed is defined and not longer than 63 characters"
fi
# Test valid characters (normally a dot should not be in the name, but we can't be 100% sure we have short name)
FIND=$(echo "${HOSTNAME}" | ${TRBINARY} -d '[:alnum:]\.\-')
# (we are NOT using [:alnum:] to support BusyBox's tr on devices with limited resources)
FIND=$(echo "${HOSTNAME}" | ${TRBINARY} -d '[a-zA-Z0-9]\.\-')
if [ -z "${FIND}" ]; then
LogText "Result: good, no unexpected characters discovered in hostname"
if IsVerbose; then Display --indent 2 --text "- Hostname (allowed characters)" --result "${STATUS_OK}" --color GREEN; fi

30
lynis
View file

@ -514,22 +514,32 @@ ${NORMAL}
. ${INCLUDEDIR}/osdetection
Display --indent 2 --text "- Detecting OS... " --result "${STATUS_DONE}" --color GREEN
# Check hostname and get timestamp
# Detect hostname and domain
FQDN=$(hostname 2> /dev/null)
case ${OS} in
HP-UX)
HOSTNAME=$(hostname) ;;
HOSTNAME=$(hostname) ;;
Linux)
if [ "${LINUX_VERSION}" = "OpenWrt" ]; then
HOSTNAME=$(uname -n)
FQDN="${HOSTNAME:+$HOSTNAME.}$(uci -q get dhcp.@dnsmasq[0].domain)"
else
HOSTNAME=$(hostname -s 2> /dev/null)
if [ -z "${HOSTNAME}" ]; then
HOSTNAME="${FQDN:-no-hostname}"
fi
if [ "${HOSTNAME}" = "${FQDN}" ]; then
FQDN=$(hostname -f 2> /dev/null)
fi
fi
;;
Solaris)
HOSTNAME=$(uname -n) ;;
HOSTNAME=$(uname -n) ;;
*)
HOSTNAME=$(hostname -s 2> /dev/null) ;;
HOSTNAME=$(hostname -s 2> /dev/null) ;;
esac
if [ -z "${HOSTNAME}" ]; then
HOSTNAME=$(hostname 2> /dev/null)
if [ -z "${HOSTNAME}" ]; then HOSTNAME="no-hostname"; fi
fi
FQDN=$(hostname 2> /dev/null)
if [ "${OS}" = "Linux" -a "${HOSTNAME}" = "${FQDN}" ]; then
FQDN=$(hostname -f 2> /dev/null)
HOSTNAME="${FQDN:-no-hostname}"
fi
#
#################################################################################