From 1111c839cc62a69a9e69b342aa5f305448a17ef9745be40850e7a5829d78ee3a Mon Sep 17 00:00:00 2001 From: Thorsten Kukuk Date: Tue, 24 Mar 2020 11:54:36 +0000 Subject: [PATCH] Accepting request 787733 from home:favogt:nobash - Use eval set -- $LINE instead of read for parsing Fixes system-user-man. eval is evil though, so if there is a better idea, please tell OBS-URL: https://build.opensuse.org/request/show/787733 OBS-URL: https://build.opensuse.org/package/show/Base:System/sysuser-tools?expand=0&rev=24 --- sysuser-tools.changes | 5 +++++ sysusers2shadow.sh | 52 ++++++++++++++++++++++++------------------- 2 files changed, 34 insertions(+), 23 deletions(-) diff --git a/sysuser-tools.changes b/sysuser-tools.changes index 2c65dd1..86b90d3 100644 --- a/sysuser-tools.changes +++ b/sysuser-tools.changes @@ -1,3 +1,8 @@ +------------------------------------------------------------------- +Tue Mar 24 10:01:39 UTC 2020 - Fabian Vogt + +- Use eval set -- $LINE instead of read for parsing + ------------------------------------------------------------------- Fri Mar 20 10:08:43 UTC 2020 - Fabian Vogt diff --git a/sysusers2shadow.sh b/sysusers2shadow.sh index cc25eff..3c55131 100644 --- a/sysusers2shadow.sh +++ b/sysusers2shadow.sh @@ -11,16 +11,20 @@ run() { busybox= for i in /bin/busybox /usr/bin/busybox; do [ -x "$i" ] && busybox=$i; done -while read arg0 arg1 arg2 arg3 arg4 +while read LINE do - case "$arg0" in + eval set -- $LINE + case "${1-}" in + \#*|"") + ;; g) - ARGUMENTS="${arg1}" - if [ -n "${arg2}" -a "${arg2}" != "-" ]; then - ARGUMENTS="-g ${arg2} $ARGUMENTS" + shift + ARGUMENTS="$1" + if [ -n "${2-}" ] && [ "$2" != "-" ]; then + ARGUMENTS="-g $2 $ARGUMENTS" fi - if ! /usr/bin/getent group "${arg1}" >> /dev/null; then + if ! /usr/bin/getent group "$1" >> /dev/null; then if [ -x "/usr/sbin/groupadd" ]; then run /usr/sbin/groupadd -r $ARGUMENTS elif [ -x "$busybox" ]; then @@ -32,30 +36,31 @@ do fi ;; u) - ARGUMENTS="${arg1}" - if [ -n "${arg2}" ] && [ "${arg2}" != "-" ]; then - ARGUMENTS="-u ${arg2} $ARGUMENTS" + shift + ARGUMENTS="$1" + if [ -n "${2-}" ] && [ "$2" != "-" ]; then + ARGUMENTS="-u $2 $ARGUMENTS" fi - if [ -n "${arg4}" ] && [ "${arg4}" != "-" ]; then - ARGUMENTS="-d ${arg4} $ARGUMENTS" + if [ -n "${4-}" ] && [ "$4" != "-" ]; then + ARGUMENTS="-d $4 $ARGUMENTS" else ARGUMENTS="-d / $ARGUMENTS" fi if [ -x /usr/sbin/useradd ]; then - if ! /usr/bin/getent passwd "${arg1}" >> /dev/null; then + if ! /usr/bin/getent passwd "$1" >> /dev/null; then # this is useradd/shadow specific - ARGUMENTS="-g ${arg1} $ARGUMENTS" - /usr/bin/getent group "${arg1}" >> /dev/null || ARGUMENTS="-U $ARGUMENTS" + ARGUMENTS="-g $1 $ARGUMENTS" + /usr/bin/getent group "$1" >> /dev/null || ARGUMENTS="-U $ARGUMENTS" - run /usr/sbin/useradd -r -s /sbin/nologin -c "${arg3}" $ARGUMENTS + run /usr/sbin/useradd -r -s /sbin/nologin -c "$3" $ARGUMENTS fi elif [ -x "$busybox" ]; then - /usr/bin/getent group "${arg1}" >> /dev/null || $busybox addgroup "${arg1}" + /usr/bin/getent group "$1" >> /dev/null || $busybox addgroup "$1" - if ! /usr/bin/getent passwd ${arg1} >> /dev/null; then - ARGUMENTS="$(echo -G ${arg1} $ARGUMENTS | sed -e 's|-d|-h|g' -e 's|-g|-G|g')" - run $busybox adduser -S -H -s /sbin/nologin -g "${arg3}" $ARGUMENTS + if ! /usr/bin/getent passwd $1 >> /dev/null; then + ARGUMENTS="$(echo -G $1 $ARGUMENTS | sed -e 's|-d|-h|g' -e 's|-g|-G|g')" + run $busybox adduser -S -H -s /sbin/nologin -g "$3" $ARGUMENTS fi else echo "ERROR: neither useradd nor busybox found!" @@ -63,20 +68,21 @@ do fi ;; m) + shift if [ -x /usr/sbin/usermod ] ; then - run /usr/sbin/usermod -a -G ${arg2} ${arg1} + run /usr/sbin/usermod -a -G $2 $1 elif [ -x "$busybox" ]; then - run $busybox addgroup ${arg1} ${arg2} + run $busybox addgroup $1 $2 else echo "ERROR: neither usermod nor busybox found!" exit 1 fi ;; r) - echo "range option ignored: \"$arg0 $arg1 $arg2 $arg3\"" + echo "range option ignored: \"$LINE\"" ;; *) - echo "Syntax Error: \"$arg0\"" + echo "Syntax Error: \"$LINE\"" exit 1 ;; esac