Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion include/tests_networking
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 20 additions & 10 deletions lynis
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
#################################################################################
Expand Down