diff options
author | Simon Rettberg | 2024-02-01 23:05:43 +0100 |
---|---|---|
committer | Simon Rettberg | 2024-02-01 23:05:43 +0100 |
commit | 534b9739cda14a07fc5ffe3f2334e92a0b87b979 (patch) | |
tree | 51c80eb07f30c01fa36d2ae2f48c4f4895c3826f /core/includes/useradd.inc | |
parent | [vbox-src] Need bash (diff) | |
download | mltk-534b9739cda14a07fc5ffe3f2334e92a0b87b979.tar.gz mltk-534b9739cda14a07fc5ffe3f2334e92a0b87b979.tar.xz mltk-534b9739cda14a07fc5ffe3f2334e92a0b87b979.zip |
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...
Diffstat (limited to 'core/includes/useradd.inc')
-rw-r--r-- | core/includes/useradd.inc | 8 |
1 files changed, 5 insertions, 3 deletions
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" } |