From d7b80fccdd9be987758e49af219c99c3269bb8fb34d069cc14dd41de096e820f Mon Sep 17 00:00:00 2001 From: Thorsten Kukuk Date: Wed, 25 Mar 2020 10:07:14 +0000 Subject: [PATCH] Accepting request 788085 from home:favogt:nobash - Fix bug introduced by simplification of check for useradd -g - Refactor use of sed away OBS-URL: https://build.opensuse.org/request/show/788085 OBS-URL: https://build.opensuse.org/package/show/Base:System/sysuser-tools?expand=0&rev=25 --- sysuser-tools.changes | 6 ++++++ sysusers2shadow.sh | 21 +++++++++++---------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/sysuser-tools.changes b/sysuser-tools.changes index 86b90d3..e40311e 100644 --- a/sysuser-tools.changes +++ b/sysuser-tools.changes @@ -1,3 +1,9 @@ +------------------------------------------------------------------- +Wed Mar 25 07:53:55 UTC 2020 - Fabian Vogt + +- Fix bug introduced by simplification of check for useradd -g +- Refactor use of sed away + ------------------------------------------------------------------- Tue Mar 24 10:01:39 UTC 2020 - Fabian Vogt diff --git a/sysusers2shadow.sh b/sysusers2shadow.sh index 3c55131..c91c9ac 100644 --- a/sysusers2shadow.sh +++ b/sysusers2shadow.sh @@ -41,26 +41,27 @@ do if [ -n "${2-}" ] && [ "$2" != "-" ]; then ARGUMENTS="-u $2 $ARGUMENTS" fi - if [ -n "${4-}" ] && [ "$4" != "-" ]; then - ARGUMENTS="-d $4 $ARGUMENTS" - else - ARGUMENTS="-d / $ARGUMENTS" + homedir="/" # If null, empty or '-' + if [ "${4:--}" != "-" ]; then + homedir="$4" fi if [ -x /usr/sbin/useradd ]; then if ! /usr/bin/getent passwd "$1" >> /dev/null; then # this is useradd/shadow specific - ARGUMENTS="-g $1 $ARGUMENTS" - /usr/bin/getent group "$1" >> /dev/null || ARGUMENTS="-U $ARGUMENTS" + if /usr/bin/getent group "$1" >> /dev/null; then + ARGUMENTS="-g $1 $ARGUMENTS" + else + ARGUMENTS="-U $ARGUMENTS" + fi - run /usr/sbin/useradd -r -s /sbin/nologin -c "$3" $ARGUMENTS + run /usr/sbin/useradd -r -s /sbin/nologin -c "$3" -d "${homedir}" $ARGUMENTS fi elif [ -x "$busybox" ]; then /usr/bin/getent group "$1" >> /dev/null || $busybox addgroup "$1" - 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 + if ! /usr/bin/getent passwd "$1" >> /dev/null; then + run $busybox adduser -S -H -s /sbin/nologin -g "$3" -G "$1" -h "${homedir}" $ARGUMENTS fi else echo "ERROR: neither useradd nor busybox found!"