From 7e62bd076202062d951a58e0f0a31b1ae902e0de Mon Sep 17 00:00:00 2001 From: Zbigniew Jędrzejewski-Szmek Date: Apr 26 2023 11:27:07 +0000 Subject: sysusers.generate-pre.sh: properly escape quotes in description strings ... (rhbz#2104141) In the first version, I wanted to use POSIX quotes with $''. But that required 'printf %q', which brings in a dependency on coreutils. Following mcr0mmand's suggestion, ${foo@Q} is used instead, which should work equivalently, and does not require anything new. Tested with 'sysusers.generate-pre.sh /usr/lib/sysusers.d/*conf'. The output is the same before and after, apart from the dovecot user with a quote. --- diff --git a/sysusers.generate-pre.sh b/sysusers.generate-pre.sh index 6bc0ca6..4a87d53 100755 --- a/sysusers.generate-pre.sh +++ b/sysusers.generate-pre.sh @@ -20,15 +20,15 @@ user() { if [ "$uid" = '-' ] || [ "$uid" = '' ]; then cat <<-EOF getent passwd '$user' >/dev/null || \\ - useradd -r -g '$group' -d '$home' -s '$shell' -c '$desc' '$user' || : + useradd -r -g ${group@Q} -d ${home@Q} -s ${shell@Q} -c ${desc@Q} ${user@Q} || : EOF else cat <<-EOF - if ! getent passwd '$user' >/dev/null; then - if ! getent passwd '$uid' >/dev/null; then - useradd -r -u '$uid' -g '$group' -d '$home' -s '$shell' -c '$desc' '$user' || : + if ! getent passwd ${user@Q} >/dev/null; then + if ! getent passwd ${uid@Q} >/dev/null; then + useradd -r -u ${uid@Q} -g ${group@Q} -d ${home@Q} -s ${shell@Q} -c ${desc@Q} ${user@Q} || : else - useradd -r -g '$group' -d '$home' -s '$shell' -c '$desc' '$user' || : + useradd -r -g ${group@Q} -d ${home@Q} -s ${shell@Q} -c ${desc@Q} ${user@Q} || : fi fi @@ -42,11 +42,11 @@ group() { if [ "$gid" = '-' ]; then cat <<-EOF - getent group '$group' >/dev/null || groupadd -r '$group' || : + getent group ${group@Q} >/dev/null || groupadd -r ${group@Q} || : EOF else cat <<-EOF - getent group '$group' >/dev/null || groupadd -f -g '$gid' -r '$group' || : + getent group ${group@Q} >/dev/null || groupadd -f -g ${gid@Q} -r ${group@Q} || : EOF fi } @@ -56,8 +56,8 @@ usermod() { group="$2" cat <<-EOF - if getent group '$group' >/dev/null; then - usermod -a -G '$group' '$user' || : + if getent group ${group@Q} >/dev/null; then + usermod -a -G ${group@Q} '$user' || : fi EOF }