Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/CISOfy/lynis.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Boelen <michael.boelen@cisofy.com>2021-07-08 15:54:49 +0300
committerMichael Boelen <michael.boelen@cisofy.com>2021-07-08 15:54:49 +0300
commit5d96098a82939995dd852380c759771c7c2dd928 (patch)
tree5328609fd1553b891ea0aa67dc74b423752e4ad3
parent46b5ecea2fe85fac93c3e2a44648e80b91da6a27 (diff)
Switched order for interface detection on Linux
-rw-r--r--include/functions38
1 files changed, 19 insertions, 19 deletions
diff --git a/include/functions b/include/functions
index cdb0c786..f4fc6218 100644
--- a/include/functions
+++ b/include/functions
@@ -990,9 +990,23 @@
;;
"Linux")
+ # Try fetching information from /sys in case 'ip' is not available or does not give expected results
+ if IsEmpty "${FIND}" -a -d /sys/class/net ]; then
+ NET_INTERFACES=$(${FINDBINARY} /sys/class/net ! -type d -exec realpath {} \; 2> /dev/null | sort | awk -F'/' '!/virtual/ && /devices/ {for (x=1;x<=NF;x++) if ($x~"net") print $(x+1)}')
+ for INTERFACE in ${NET_INTERFACES}; do
+ if grep -q -s 'up' "/sys/class/net/${INTERFACE}/operstate"; then
+ LogText "Interface '${INTERFACE}' is up, fetching MAC address"
+ FIND=$(head -1 "/sys/class/net/${INTERFACE}/address" | tr '[:upper:]' '[:lower:]')
+ if HasData "${FIND}"; then
+ HOSTID_GEN="linux-sys-interface-up"
+ break
+ fi
+ fi
+ done
+ fi
- # First try ip, as it is available to most modern Linux distributions
- if [ -n "${IPBINARY}" ]; then
+ # Next is to try ip, as it is available to most modern Linux distributions
+ if IsEmpty "${FIND}" && [ -n "${IPBINARY}" ]; then
LogText "Info: trying output from 'ip' to generate HostID"
# Determine if we have the common available eth0 interface. If so, give that priority.
# Note: apply sorting in case there would be multiple MAC addresses linked to increase predictable end result
@@ -1022,21 +1036,7 @@
fi
fi
- # Try fetching information from /sys in case 'ip' is not available or does not give expected results
- if IsEmpty "${FIND}" && [ ${PRIVILEGED} -eq 1 -a -d /sys/class/net ]; then
- NET_INTERFACES=$(${FINDBINARY} /sys/class/net ! -type d -exec realpath {} \; 2> /dev/null | sort | awk -F'/' '!/virtual/ && /devices/ {for (x=1;x<=NF;x++) if ($x~"net") print $(x+1)}')
- for INTERFACE in ${NET_INTERFACES}; do
- if grep -s 'up' "/sys/class/net/${INTERFACE}/operstate"; then
- LogText "Interface '${INTERFACE}' is up, fetching MAC address"
- FIND=$(head -1 "/sys/class/net/${INTERFACE}/address" | tr '[:upper:]' '[:lower:]')
- if HasData "${FIND}"; then
- HOSTID_GEN="linux-sys-interface-up"
- break
- fi
- fi
- done
- fi
-
+ # Finally try ifconfig
if IsEmpty "${FIND}" && [ -n "${IFCONFIGBINARY}" ]; then
LogText "Info: no information found from 'ip' or in /sys, trying output from 'ifconfig'"
# Determine if we have the eth0 interface (not all Linux distributions have this, e.g. Arch)
@@ -1073,9 +1073,9 @@
fi
fi
- # Check if we found a HostID
+ # Check if we found a MAC address to generate the HostID
if HasData "${FIND}"; then
- LogText "Info: using hardware address ${FIND} to create HostID"
+ LogText "Info: using hardware address '${FIND}' to create HostID"
HOSTID=$(echo ${FIND} | ${SHA1SUMBINARY} | awk '{ print $1 }')
LogText "Result: Found HostID: ${HOSTID}"
else