Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions sysusers
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ add_group() {
}

add_user() {
# add_user <name> <uid> <gid> <gecos> <home>
# add_user <name> <uid> <gid> <gecos> <home> [locked]*
if ! id "$1" >/dev/null 2>&1; then
if [ "$2" = '-' ]; then
if [ "$3" = '-' ]; then
Expand All @@ -34,6 +34,12 @@ add_user() {
useradd --prefix "$root" -rc "$4" -u "$2" -g "$3" -d "$5" -s '/sbin/nologin' "$1"
fi
passwd --prefix "$root" -l "$1" >/dev/null 2>&1
while [ $# -gt 5 ]; do
case "$6" in
locked) usermod --prefix "$root" -e 1 "$1" ;;
esac
shift
done
fi
}

Expand Down Expand Up @@ -74,7 +80,8 @@ parse_string() {

#eval "set -- $1" # do not use eval, see CVE-2021-40084
set -- $1
type="$1" name="$2" id="$3" gecos="$4" home="$5"
suffix="${1#?}"
type="${1%%${suffix}}" name="$2" id="$3" gecos="$4" home="$5"

# and now set the GECOS field without eval
if [ "${type}" = u ]; then
Expand Down Expand Up @@ -106,7 +113,12 @@ parse_string() {
# No specific gid, create group for this user
add_group "${name}" "${id}"
fi
add_user "${name}" "${uid}" "${gid}" "${gecos}" "${home}"
case "${suffix}" in
'!') locked=1;;
'') ;;
*) warninvalid; return;;
esac
add_user "${name}" "${uid}" "${gid}" "${gecos}" "${home}" ${locked:+locked}
;;
g)
case "${id}" in 65535|4294967295) warninvalid; return; esac
Expand Down