diff --git a/include/tests_networking b/include/tests_networking index fcf408025..c7c3a180e 100644 --- a/include/tests_networking +++ b/include/tests_networking @@ -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 diff --git a/lynis b/lynis index e2de13e13..0a9969df5 100755 --- a/lynis +++ b/lynis @@ -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 # #################################################################################