All checks were successful
🛡️ Shell Script Linting / 🛡️ Shell Script Linting (push) Successful in 53s
Signed-off-by: Marc S. Weidner <msw@coresecret.dev>
59 lines
1.9 KiB
Bash
59 lines
1.9 KiB
Bash
#!/bin/bash
|
|
# SPDX-Version: 3.0
|
|
# SPDX-CreationInfo: 2025-06-17; WEIDNER, Marc S.; <msw@coresecret.dev>
|
|
# SPDX-ExternalRef: GIT https://git.coresecret.dev/msw/CISS.debian.installer.git
|
|
# SPDX-FileContributor: WEIDNER, Marc S.; Centurion Intelligence Consulting Agency
|
|
# SPDX-FileCopyrightText: 2024-2025; WEIDNER, Marc S.; <msw@coresecret.dev>
|
|
# SPDX-FileType: SOURCE
|
|
# SPDX-License-Identifier: EUPL-1.2 OR LicenseRef-CCLA-1.0
|
|
# SPDX-LicenseComment: This file is part of the CISS.debian.installer.secure framework.
|
|
# SPDX-PackageName: CISS.debian.installer
|
|
# SPDX-Security-Contact: security@coresecret.eu
|
|
set -Ceuo pipefail
|
|
|
|
#######################################
|
|
# Password expiration hook to run inside chroot.
|
|
# Globals:
|
|
# ary_users_to_update
|
|
# var_max_days
|
|
# var_user
|
|
# Arguments:
|
|
# None
|
|
# Returns:
|
|
# 0: on success
|
|
#######################################
|
|
main() {
|
|
### Declare Arrays, HashMaps, and Variables.
|
|
declare -a ary_users_to_update=()
|
|
declare -i var_max_days=16384
|
|
declare var_user=""
|
|
|
|
printf "Chroot hook: [%s] starting ... \n" "${0}"
|
|
|
|
# shellcheck disable=SC2312
|
|
mapfile -t ary_users_to_update < <( awk -F: '$2 !~ /^[!*]/ { print $1 }' /etc/shadow )
|
|
|
|
if [[ ${#ary_users_to_update[@]} -eq 0 ]]; then
|
|
printf "No enabled-login accounts found in [/etc/shadow]. Exiting hook ... \n"
|
|
printf "Chroot hook: [%s] applied successfully. \n" "${0}"
|
|
exit 0
|
|
fi
|
|
|
|
for var_user in "${ary_users_to_update[@]}"; do
|
|
printf "Setting max password age for user: [%s] to: [%s] days. \n" "${var_user}" "${var_max_days}"
|
|
chage --maxdays "${var_max_days}" "${var_user}"
|
|
done
|
|
|
|
unset var_max_days var_user ary_users_to_update
|
|
|
|
awk -F: '$2 !~ /^\$[0-9]/ && length($2)==13 { print $1,$2 }' /etc/shadow
|
|
|
|
printf "All applicable accounts have been updated. \n"
|
|
printf "Chroot hook: [%s] applied successfully. \n" "${0}"
|
|
|
|
exit 0
|
|
}
|
|
|
|
main "$@"
|
|
# vim: number et ts=2 sw=2 sts=2 ai tw=128 ft=sh
|