From 75e8bf19d808079edfd8d66c69f2ae64af398c370adf2a46812cd19a19b631bf Mon Sep 17 00:00:00 2001 From: Thorsten Kukuk Date: Fri, 15 Jan 2021 10:59:15 +0000 Subject: [PATCH] Accepting request 863306 from home:kukuk:etc - Use systemd-sysusers as default to create and update the user account. Fixes the problem that a modified sysusers config file get's ignored by useradd and adduser [bsc#1180549]. OBS-URL: https://build.opensuse.org/request/show/863306 OBS-URL: https://build.opensuse.org/package/show/Base:System/sysuser-tools?expand=0&rev=34 --- sysuser-tools.changes | 7 +++ sysuser-tools.spec | 4 +- sysusers2shadow.sh | 106 +++++++++++++++++++++++------------------- 3 files changed, 66 insertions(+), 51 deletions(-) diff --git a/sysuser-tools.changes b/sysuser-tools.changes index fa98239..b23c333 100644 --- a/sysuser-tools.changes +++ b/sysuser-tools.changes @@ -1,3 +1,10 @@ +------------------------------------------------------------------- +Thu Jan 14 14:30:20 UTC 2021 - Thorsten Kukuk + +- Use systemd-sysusers as default to create and update the user + account. Fixes the problem that a modified sysusers config file + get's ignored by useradd and adduser [bsc#1180549]. + ------------------------------------------------------------------- Fri Dec 4 10:54:00 UTC 2020 - Ludwig Nussel diff --git a/sysuser-tools.spec b/sysuser-tools.spec index 0914189..0a9f429 100644 --- a/sysuser-tools.spec +++ b/sysuser-tools.spec @@ -1,7 +1,7 @@ # # spec file for package sysuser-tools # -# Copyright (c) 2020 SUSE LLC +# Copyright (c) 2021 SUSE LLC # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed @@ -38,7 +38,7 @@ Generate auto provides for system users. %package -n sysuser-shadow Summary: Tool to execute sysusers.d with shadow utilities Group: System/Packages -PreReq: useradd_or_adduser_dep +Requires(pre): (/usr/sbin/useradd or busybox or /usr/bin/systemd-sysusers) # prefer original shadow over busybox by default Suggests: shadow diff --git a/sysusers2shadow.sh b/sysusers2shadow.sh index 6440475..492e461 100644 --- a/sysusers2shadow.sh +++ b/sysusers2shadow.sh @@ -7,85 +7,93 @@ run() { "$@" } -# Absolute path to busybox, if found -busybox= -for i in /bin/busybox /usr/bin/busybox; do [ -x "$i" ] && busybox=$i; done +if [ -x /usr/bin/systemd-sysusers ]; then -while read LINE -do + # Use systemd-sysusers and let it read the input directly from stdin + /usr/bin/systemd-sysusers - + +else + + # Absolute path to busybox, if found + busybox= + for i in /bin/busybox /usr/bin/busybox; do [ -x "$i" ] && busybox=$i; done + + while read LINE + do # "eval set" to do proper splitting while respecting quotes eval set -- $LINE case "${1-}" in - \#*|"") - ;; - g) + \#*|"") + ;; + g) shift ARGUMENTS="$1" if [ -n "${2-}" ] && [ "$2" != "-" ]; then - ARGUMENTS="-g $2 $ARGUMENTS" + ARGUMENTS="-g $2 $ARGUMENTS" fi 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 - run $busybox addgroup -S $ARGUMENTS - else - echo "ERROR: neither groupadd nor busybox found!" - exit 1 - fi + if [ -x "/usr/sbin/groupadd" ]; then + run /usr/sbin/groupadd -r $ARGUMENTS + elif [ -x "$busybox" ]; then + run $busybox addgroup -S $ARGUMENTS + else + echo "ERROR: neither groupadd nor busybox found!" + exit 1 + fi fi ;; - u) + u) shift ARGUMENTS="$1" if [ -n "${2-}" ] && [ "$2" != "-" ]; then - ARGUMENTS="-u $2 $ARGUMENTS" + ARGUMENTS="-u $2 $ARGUMENTS" fi homedir="/" # If null, empty or '-' if [ "${4:--}" != "-" ]; then - homedir="$4" + homedir="$4" fi if [ -x /usr/sbin/useradd ]; then - if ! /usr/bin/getent passwd "$1" >> /dev/null; then - # this is useradd/shadow specific - 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" -d "${homedir}" $ARGUMENTS + if ! /usr/bin/getent passwd "$1" >> /dev/null; then + # this is useradd/shadow specific + if /usr/bin/getent group "$1" >> /dev/null; then + ARGUMENTS="-g $1 $ARGUMENTS" + else + ARGUMENTS="-U $ARGUMENTS" fi - elif [ -x "$busybox" ]; then - /usr/bin/getent group "$1" >> /dev/null || $busybox addgroup -S "$1" - 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 + 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 -S "$1" + + 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!" - exit 1 + echo "ERROR: neither useradd nor busybox found!" + exit 1 fi - ;; - m) + ;; + m) shift if [ -x /usr/sbin/usermod ] ; then - run /usr/sbin/usermod -a -G $2 $1 + run /usr/sbin/usermod -a -G $2 $1 elif [ -x "$busybox" ]; then - run $busybox addgroup $1 $2 + run $busybox addgroup $1 $2 else - echo "ERROR: neither usermod nor busybox found!" - exit 1 + echo "ERROR: neither usermod nor busybox found!" + exit 1 fi - ;; - r) + ;; + r) echo "range option ignored: \"$LINE\"" ;; - *) - echo "Syntax Error: \"$LINE\"" - exit 1 - ;; + *) + echo "Syntax Error: \"$LINE\"" + exit 1 + ;; esac -done + done +fi