From dc1a70f2b6880c968d49aa8223afac31480d3ef552e7a90436f14088ca63bf76 Mon Sep 17 00:00:00 2001 From: Thorsten Kukuk Date: Fri, 26 Jul 2019 11:29:41 +0000 Subject: [PATCH] Accepting request 718841 from home:kukuk:container - Use suggest shadow to prefer that over busybox in normal systems - Add support for busybox adduser/addgroup - Change requirements from shadow to useradd_or_adduser_dep OBS-URL: https://build.opensuse.org/request/show/718841 OBS-URL: https://build.opensuse.org/package/show/Base:System/sysuser-tools?expand=0&rev=17 --- macros.sysusers | 3 ++- sysuser-tools.changes | 11 +++++++++++ sysuser-tools.spec | 4 ++-- sysusers2shadow.sh | 39 ++++++++++++++++++++++++++++++++------- 4 files changed, 47 insertions(+), 10 deletions(-) diff --git a/macros.sysusers b/macros.sysusers index c539c06..cb25e94 100644 --- a/macros.sysusers +++ b/macros.sysusers @@ -14,7 +14,8 @@ ### # This is for useradd/usermod/groupadd -%sysusers_requires Requires(pre): shadow sysuser-shadow +%sysusers_requires Requires(pre): useradd_or_adduser_dep sysuser-shadow \ +Suggest: shadow %sysusers_generate_pre() \ %{_prefix}/lib/rpm/sysusers-generate-pre "%1" > "%2".pre diff --git a/sysuser-tools.changes b/sysuser-tools.changes index cbea59f..4cf9299 100644 --- a/sysuser-tools.changes +++ b/sysuser-tools.changes @@ -1,3 +1,14 @@ +------------------------------------------------------------------- +Fri Jul 26 13:28:27 CEST 2019 - kukuk@suse.de + +- Use suggest shadow to prefer that over busybox in normal systems + +------------------------------------------------------------------- +Thu Jul 25 16:00:35 CEST 2019 - kukuk@suse.de + +- Add support for busybox adduser/addgroup +- Change requirements from shadow to useradd_or_adduser_dep + ------------------------------------------------------------------- Thu May 9 13:23:56 CEST 2019 - kukuk@suse.de diff --git a/sysuser-tools.spec b/sysuser-tools.spec index aed912f..8ae0cdb 100644 --- a/sysuser-tools.spec +++ b/sysuser-tools.spec @@ -17,7 +17,7 @@ Name: sysuser-tools -Version: 2.0 +Version: 3.0 Release: 0 Summary: Auto provides for system users License: MIT @@ -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 -Requires: shadow +Requires: useradd_or_adduser_dep %description -n sysuser-shadow This package contians a tool, which expects as input a sysusers.d diff --git a/sysusers2shadow.sh b/sysusers2shadow.sh index 8a12163..2ebda19 100644 --- a/sysusers2shadow.sh +++ b/sysusers2shadow.sh @@ -11,8 +11,16 @@ do if [ ! -z "${arr[2]}" -a "${arr[2]}" != "-" ]; then ARGUMENTS="-g ${arr[2]} $ARGUMENTS" fi - echo "groupadd -r $ARGUMENTS" - /usr/bin/getent group "${arr[1]}" >> /dev/null || /usr/sbin/groupadd -r $ARGUMENTS || exit $? + if [ -x /usr/sbin/groupadd ]; then + echo "groupadd -r $ARGUMENTS" + /usr/bin/getent group "${arr[1]}" >> /dev/null || /usr/sbin/groupadd -r $ARGUMENTS || exit $? + elif [ -x /usr/bin/busybox ]; then + echo "addgroup -S $ARGUMENTS" + /usr/bin/getent group "${arr[1]}" >> /dev/null || /usr/bin/busybox addgroup -S $ARGUMENTS || exit $? + else + echo "ERROR: neither groupadd nor busybox found!" + exit 1 + fi ;; u*) eval arr=( $LINE ) @@ -25,19 +33,36 @@ do else ARGUMENTS="-d / $ARGUMENTS" fi - /usr/bin/getent group ${arr[1]} >> /dev/null + /usr/bin/getent group ${arr[1]} >> /dev/null if [ $? -eq 0 ]; then ARGUMENTS="-g ${arr[1]} $ARGUMENTS" else ARGUMENTS="-U $ARGUMENTS" fi - echo "useradd -r -s /sbin/nologin -c \"${arr[3]}\" $ARGUMENTS" - /usr/bin/getent passwd ${arr[1]} >> /dev/null || /usr/sbin/useradd -r -s /sbin/nologin -c "${arr[3]}" $ARGUMENTS || exit $? + if [ -x /usr/sbin/useradd ]; then + echo "useradd -r -s /sbin/nologin -c \"${arr[3]}\" $ARGUMENTS" + /usr/bin/getent passwd ${arr[1]} >> /dev/null || /usr/sbin/useradd -r -s /sbin/nologin -c "${arr[3]}" $ARGUMENTS || exit $? + elif [ -x /usr/bin/busybox ]; then + ARGUMENTS=`echo $ARGUMENTS | sed -e 's|-d|-h|g' -e 's|-g|-G|g'` + echo "adduser -S -s /sbin/nologin -g \"${arr[3]}\" $ARGUMENTS" + /usr/bin/getent passwd ${arr[1]} >> /dev/null || /usr/bin/busybox adduser -S -s /sbin/nologin -g "${arr[3]}" $ARGUMENTS || exit $? + else + echo "ERROR: neither useradd nor busybox found!" + exit 1 + fi ;; m*) eval arr=( $LINE ) - echo "usermod -a -G ${arr[2]} ${arr[1]}" - /usr/sbin/usermod -a -G ${arr[2]} ${arr[1]} || exit $? + if [ -x /usr/sbin/usermod ] ; then + echo "usermod -a -G ${arr[2]} ${arr[1]}" + /usr/sbin/usermod -a -G ${arr[2]} ${arr[1]} || exit $? + elif [ -x /usr/bin/busybox ]; then + echo "addgroup ${arr[1]} ${arr[2]}" + /usr/bin/busybox addgroup ${arr[1]} ${arr[2]} || exit $? + else + echo "ERROR: neither usermod nor busybox found!" + exit 1 + fi ;; r*) echo "range option ignored: \"$LINE\""