From 534b9739cda14a07fc5ffe3f2334e92a0b87b979 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Thu, 1 Feb 2024 23:05:43 +0100 Subject: Make useradd and groupadd return 0 These functions will perror on error, so make sure on success we return 0, even though checking the return value is useless... --- core/includes/useradd.inc | 8 +++++--- core/modules/dnbd3-proxy-mode/module.build | 3 +-- 2 files changed, 6 insertions(+), 5 deletions(-) (limited to 'core') diff --git a/core/includes/useradd.inc b/core/includes/useradd.inc index d47b43b9..348c5ecd 100644 --- a/core/includes/useradd.inc +++ b/core/includes/useradd.inc @@ -102,8 +102,9 @@ useradd () { [ "$pw" != "#" ] && usr_setpw "$name" "$pw" return 0 # Nothing to do fi - command useradd "${_USER_EXTRA_OPTS[@]}" "${opts[@]}" || perror "useradd failed" + command useradd "${_USER_EXTRA_OPTS[@]}" "${opts[@]}" || perror "useradd ${opts[*]} failed" [ "$pw" != "#" ] && usr_setpw "$name" "$pw" + true } groupadd () { @@ -135,7 +136,8 @@ groupadd () { (( sys == 0 && _ngid < 1000 )) && perror "$name: Already exists with system id $_ngid" return 0 fi - command groupadd "${_USER_EXTRA_OPTS[@]}" "${opts[@]}" || perror "groupadd failed" + command groupadd "${_USER_EXTRA_OPTS[@]}" "${opts[@]}" || perror "groupadd ${opts[*]} failed" + true } # Add user to given group. Not entirely safe as we don't wait for a lock, @@ -144,7 +146,7 @@ groupadd () { add_to_group () { ua_set_vars grep -qP "^${2}:.*:.*[:,]${1}(,|$)" "$_GROUP" && return 0 - grep -q "^${2}:" "$_GROUP" || return 1 + grep -q "^${2}:" "$_GROUP" || perror "Cannot add '$1' to '$2' - no such group" sed -i -r "s/^${2}:[^:]*:[^:]*:.+$/&,$1/;s/^${2}:[^:]*:[^:]*:$/&$1/" "$_GROUP" } diff --git a/core/modules/dnbd3-proxy-mode/module.build b/core/modules/dnbd3-proxy-mode/module.build index 6027ceeb..9a920069 100644 --- a/core/modules/dnbd3-proxy-mode/module.build +++ b/core/modules/dnbd3-proxy-mode/module.build @@ -8,6 +8,5 @@ build() { } post_copy() { - useradd --system --user-group --no-create-home --groups "fuse" "dnbd3" \ - || perror "Cannot create user dnbd3 with supp. group fuse" + useradd --system --user-group --no-create-home --groups "fuse" "dnbd3" } -- cgit v1.2.3-55-g7522