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
8 changes: 8 additions & 0 deletions config/uac.conf
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ exclude_name_pattern: []
# running kernel.
exclude_file_system: [9p, afs, autofs, cifs, davfs, fuse, kernfs, nfs, nfs4, rpc_pipefs, smbfs, sysfs]

# Exclude any file systems with more than this much space *used* (root file
# system will never be excluded).
# File systems will be excluded from find, file, hash and stat collectors.
# Valid units are b|c (bytes), k (kilobytes), and M,G,T for mega-, giga-,
# and tera-bytes respectively. Value is assumed to be bytes if no unit given.
# Set to zero to disable.
exclude_mount_size: 0

# Hash algorithms
# Used by the hash collector.
# Accepted values: md5, sha1 and sha256
Expand Down
58 changes: 58 additions & 0 deletions lib/convert_size_to_kb.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/bin/sh
# SPDX-License-Identifier: Apache-2.0
# shellcheck disable=SC2006,SC2005,SC2003

# Take a string like "10T" and convert to a number representing kilobytes.
# Valid units are b|c (bytes), k (kilobytes), and M,G,T for mega-, giga-,
# and tera-bytes respectively. Null unit specifier means bytes.
# Arguments:
# string like "10T"
# Returns:
# integer number of kilobytes
# returns zero on any errors
_convert_size_to_kb()
{
__cs_arg="${1:-0}"

# return error if format not recognized
if ! echo "${__cs_arg}" | grep -q -E '^[0-9]*[bckMGT]?$'; then
echo 0
return 1
fi

__cs_number="`echo "${__cs_arg}" | sed 's/[^0-9]//g'`"

# short circuit for lunatics who enter things like "0T"
if [ "${__cs_number}" -eq 0 ]; then
echo 0
return 0
fi

__cs_unit="`echo "${__cs_arg}" | tr -d 0-9`"

# if the unit is "c" or empty, convert the unit to "b"
[ -n "${__cs_unit}" ] || __cs_unit='b'
[ "${__cs_unit}" = "c" ] && __cs_unit='b'

# If they enter a number of bytes less than 1024, expr will round down
# to zero kilobytes, which is surely not what the user intended.
# Set exclude size to 1kb.
[ "${__cs_unit}" = "b" ] && [ "${__cs_number}" -lt 1024 ] && __cs_number=1024

case "${__cs_unit}" in
b) echo "`expr "${__cs_number}" / 1024`"
;;
k) echo "${__cs_number}"
;;
M) echo "`expr "${__cs_number}" \* 1024`"
;;
G) echo "`expr "${__cs_number}" \* 1024 \* 1024`"
;;
T) echo "`expr "${__cs_number}" \* 1024 \* 1024 \* 1024`"
;;
*) echo 0
return 1
;;
esac
return 0
}
24 changes: 24 additions & 0 deletions lib/get_large_file_systems.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/sh
# SPDX-License-Identifier: Apache-2.0
#

# Returns a pipe delimited list of file systems that are using more than
# ${__UAC_CONF_EXCLUDE_MOUNT_SIZE} kilobytes. Root file system will always
# be ignored.
#
# Arguments:
# none
# Returns:
# pipe delimited string, may be empty
_get_large_file_systems()
{
[ "${__UAC_CONF_EXCLUDE_MOUNT_SIZE}" -gt 0 ] || return 0

# shellcheck disable=SC2162
df | while read __gl_dev __gl_size __gl_used __gl_avail __gl_pct __gl_mtpt
do
echo "${__gl_used}" | grep -q -E '^[0-9]*$' || continue
[ "${__gl_used}" -gt "${__UAC_CONF_EXCLUDE_MOUNT_SIZE}" ] && [ "${__gl_mtpt}" != '/' ] && echo "${__gl_mtpt}"
done | tr \\n \| | sed 's/|$//'
return 0
}
10 changes: 9 additions & 1 deletion lib/load_config_file.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ _load_config_file()
__UAC_CONF_EXCLUDE_PATH_PATTERN="${__UAC_CONF_EXCLUDE_PATH_PATTERN:-}"
__UAC_CONF_EXCLUDE_NAME_PATTERN="${__UAC_CONF_EXCLUDE_NAME_PATTERN:-}"
__UAC_CONF_EXCLUDE_FILE_SYSTEM="${__UAC_CONF_EXCLUDE_FILE_SYSTEM:-9p|afs|autofs|cifs|davfs|fuse|kernfs|nfs|nfs4|rpc_pipefs|smbfs|sysfs}"
__UAC_CONF_EXCLUDE_MOUNT_SIZE="${__UAC_CONF_EXCLUDE_MOUNT_SIZE:-0}"
__UAC_CONF_HASH_ALGORITHM="${__UAC_CONF_HASH_ALGORITHM:-md5|sha1}"
__UAC_CONF_MAX_DEPTH="${__UAC_CONF_MAX_DEPTH:-0}"
__UAC_CONF_ENABLE_FIND_MTIME="${__UAC_CONF_ENABLE_FIND_MTIME:-true}"
Expand Down Expand Up @@ -63,6 +64,13 @@ _load_config_file()
__UAC_CONF_EXCLUDE_FILE_SYSTEM=`echo "${__lc_value}" | _array_to_psv 2>/dev/null`
fi

# load exclude_mount_size option
if echo "${__lc_config_file_content}" | grep -q "exclude_mount_size:"; then
__lc_value=`echo "${__lc_config_file_content}" | sed -n -e 's|exclude_mount_size\: *\(.*\)|\1|p'`
__UAC_CONF_EXCLUDE_MOUNT_SIZE=`_convert_size_to_kb "${__lc_value}"`
fi


# load hash_algorithm option
if echo "${__lc_config_file_content}" | grep -q "hash_algorithm:"; then
__lc_value=`echo "${__lc_config_file_content}" | sed -n -e 's|hash_algorithm\: *\(.*\)|\1|p'`
Expand Down Expand Up @@ -119,4 +127,4 @@ _load_config_file()
__UAC_CONF_ENABLE_FIND_CTIME="${__lc_value}"
fi

}
}
2 changes: 2 additions & 0 deletions lib/load_libraries.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
. "${__UAC_DIR}/lib/build_find_command.sh"
. "${__UAC_DIR}/lib/command_collector.sh"
. "${__UAC_DIR}/lib/command_exists.sh"
. "${__UAC_DIR}/lib/convert_size_to_kb.sh"
. "${__UAC_DIR}/lib/copy_data.sh"
. "${__UAC_DIR}/lib/create_acquisition_log.sh"
. "${__UAC_DIR}/lib/error_msg.sh"
Expand All @@ -22,6 +23,7 @@
. "${__UAC_DIR}/lib/get_days_since_date_until_now.sh"
. "${__UAC_DIR}/lib/get_epoch_date.sh"
. "${__UAC_DIR}/lib/get_hostname.sh"
. "${__UAC_DIR}/lib/get_large_file_systems.sh"
. "${__UAC_DIR}/lib/get_mount_point_by_file_system.sh"
. "${__UAC_DIR}/lib/get_operating_system.sh"
. "${__UAC_DIR}/lib/get_profile_by_name.sh"
Expand Down
8 changes: 7 additions & 1 deletion uac
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,6 @@ _log_msg INF "PATH: ${PATH}"
_log_msg INF "Loading configuration file(s)"
_log_msg INF "Exclude path pattern: ${__UAC_CONF_EXCLUDE_PATH_PATTERN}"
_log_msg INF "Exclude name pattern: ${__UAC_CONF_EXCLUDE_NAME_PATTERN}"
_log_msg INF "Exclude file system: ${__UAC_CONF_EXCLUDE_FILE_SYSTEM}"
_log_msg INF "Hash algorithm: ${__UAC_CONF_HASH_ALGORITHM}"
_log_msg INF "Max depth: ${__UAC_CONF_MAX_DEPTH}"
_log_msg INF "Enable find mtime: ${__UAC_CONF_ENABLE_FIND_MTIME}"
Expand All @@ -382,6 +381,12 @@ if [ -n "${__UAC_CONF_EXCLUDE_FILE_SYSTEM}" ]; then
__UAC_EXCLUDE_MOUNT_POINTS=`_get_mount_point_by_file_system "${__UAC_CONF_EXCLUDE_FILE_SYSTEM}" "${__UAC_OPERATING_SYSTEM}"`
fi

# add in file systems excluded by size
if [ "${__UAC_CONF_EXCLUDE_MOUNT_SIZE}" -gt 0 ]; then
__ua_large_mounts=`_get_large_file_systems`
__UAC_EXCLUDE_MOUNT_POINTS=`echo "${__UAC_EXCLUDE_MOUNT_POINTS}|${__ua_large_mounts}" | sed 's/^|//; s/|$//'`
fi

# check whether temp data dir's file system supports symlink creation.
if ln -s "${__UAC_DIR}/uac" "${__UAC_TEMP_DATA_DIR}/uac-symlink-support-test.tmp" >/dev/null; then
__UAC_TEMP_DATA_DIR_NO_SYMLINK_SUPPORT=false
Expand Down Expand Up @@ -436,6 +441,7 @@ if ${__UAC_TEMP_DATA_DIR_NO_SYMLINK_SUPPORT}; then
else
_log_msg INF "Temp directory symlink creation support: true"
fi
_log_msg INF "Exclude file system size: ${__UAC_CONF_EXCLUDE_MOUNT_SIZE} kb"
_log_msg INF "Exclude mount points: ${__UAC_EXCLUDE_MOUNT_POINTS}"

_verbose_msg "Building artifact list..."
Expand Down