userlogrotate: Ensure we use a valid group name

Use user's primary group when user's name is not an existing group.
This commit is contained in:
Alexis Ben Miloud--Josselin 2024-02-01 11:06:21 +01:00
parent d67e2b122f
commit 4c9e4a30cc
2 changed files with 7 additions and 0 deletions

View file

@ -67,6 +67,7 @@ The **patch** part changes is incremented if multiple releases happen the same m
* vrrpd: variable to force update the switch script (default: false)
* webapps/nextcloud: Add Ceph volume to fstab
* webapps/nextcloud: Set home directory's mode
* userlogrotate: Use user's primary group when user's name is not an existing group
### Fixed

View file

@ -73,6 +73,9 @@ for path in ${SYSTEM_LOGS_SEARCH_PATHS[@]}; do
for file in ${log_paths}; do
user="$(user_for "${file}")"
group="$(group_for "${file}")"
if ! getent group "${user}" > /dev/null 2> /dev/null; then
group="$(id -gn "${user}")"
fi
rotate "${file}" "${group}":"${user}"
delete_old "$(dirname "${file}")"
done
@ -85,6 +88,9 @@ for path in ${APPLICATIVE_LOGS_SEARCH_PATHS[@]}; do
for file in ${log_paths}; do
user="$(user_for "${file}")"
group="$(group_for "${file}")"
if ! getent group "${user}" > /dev/null 2> /dev/null; then
group="$(id -gn "${user}")"
fi
rotate "${file}" "${group}":"${user}"
delete_old "$(dirname "${file}")"
done