Skip to content

Commit

Permalink
Support new u! command in sysusers files
Browse files Browse the repository at this point in the history
systemd 257 defines a new modifier ! for u entries that locks the
account by setting it as expired.

See systemd/systemd@2ec7977

Resolves: rpm-software-management#3450
  • Loading branch information
ffesti committed Dec 2, 2024
1 parent 71e88ec commit c065b98
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
2 changes: 1 addition & 1 deletion macros.in
Original file line number Diff line number Diff line change
Expand Up @@ -1364,7 +1364,7 @@ end
name = arg[2]
if arg[1] == 'g' then
type = 'group'
elseif arg[1] == 'u' then
elseif arg[1] == 'u' or arg[1] == 'u!' then
type = 'user'
elseif arg[1] == 'm' and #arg >=3 then
type = 'groupmember'
Expand Down
21 changes: 16 additions & 5 deletions scripts/sysusers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ user() {
local group="$4"
local home="$5"
local shell="$6"
local expire="$7"

[ "$desc" = '-' ] && desc=
{ [ "$home" = '-' ] || [ "$home" = '' ]; } && home=/
Expand All @@ -90,6 +91,10 @@ user() {
fi
fi
fi

if [[ $expire ]]; then
usermod -e 0 "${user}"
fi
}

group() {
Expand All @@ -109,27 +114,33 @@ addtogroup() {
local group="$2"

group "${group}" "-"
user "${user}" "-" "" "${group}" "" ""
user "${user}" "-" "" "${group}" "" "" ""

usermod -R "$ROOT" -a -G "${group}" "$user" || :
}

parse() {
local line arr
local line arr expire

while read -r line || [ -n "$line" ] ; do
{ [ "${line:0:1}" = '#' ] || [ "${line:0:1}" = ';' ]; } && continue
line="${line## *}"
[ -z "$line" ] && continue
mapfile -t arr < <(xargs -n1 <<<"$line")

expire=""

case "${arr[0]}" in
('u')
('u' | 'u!')
if [[ "${arr[0]}" == 'u!' ]]; then
expire="1";
fi

if [[ "${arr[2]}" == *":"* ]]; then
user "${arr[1]}" "${arr[2]%:*}" "${arr[3]}" "${arr[2]#*:}" "${arr[4]}" "${arr[5]}"
user "${arr[1]}" "${arr[2]%:*}" "${arr[3]}" "${arr[2]#*:}" "${arr[4]}" "${arr[5]}" $expire
else
group "${arr[1]}" "${arr[2]}"
user "${arr[1]}" "${arr[2]}" "${arr[3]}" "${arr[1]}" "${arr[4]}" "${arr[5]}"
user "${arr[1]}" "${arr[2]}" "${arr[3]}" "${arr[1]}" "${arr[4]}" "${arr[5]}" $expire
fi
;;
('g')
Expand Down
2 changes: 1 addition & 1 deletion tests/data/SPECS/klang.spec
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ EOF
cat << EOF > ${RPM_BUILD_ROOT}/%{_sysusersdir}/plong.conf

# Real life files have all sorts of anomalies
u plong - "Plong fu" /var/lib/plong /sbin/nologin
u! plong - "Plong fu" /var/lib/plong /sbin/nologin
#...such as empty lines

# and comments comments
Expand Down
8 changes: 6 additions & 2 deletions tests/rpmi.at
Original file line number Diff line number Diff line change
Expand Up @@ -1589,7 +1589,7 @@ group(klong) = ZyBrbG9uZyAt
group(plong)
groupmember(klangd/klong) = bSBrbGFuZ2Qga2xvbmcA
user(klangd) = dSBrbGFuZ2QgLSAiS2xhbmcgc2VydmVyIiAvdmFyL2xpYi9rbGFuZ2QgL3NiaW4vbm9sb2dpbgAA
user(plong) = dSBwbG9uZyAtICJQbG9uZyBmdSIgL3Zhci9saWIvcGxvbmcgL3NiaW4vbm9sb2dpbgAA
user(plong) = dSEgcGxvbmcgLSAiUGxvbmcgZnUiIC92YXIvbGliL3Bsb25nIC9zYmluL25vbG9naW4A
],
[warning: ignoring unsupported sysuser type: r
])
Expand Down Expand Up @@ -1618,7 +1618,7 @@ group(klong) = ZyBrbG9uZyAt
group(plong)
groupmember(klangd/klong) = bSBrbGFuZ2Qga2xvbmcA
user(klangd) = dSBrbGFuZ2QgLSAiS2xhbmcgc2VydmVyIiAvdmFyL2xpYi9rbGFuZ2QgL3NiaW4vbm9sb2dpbgAA
user(plong) = dSBwbG9uZyAtICJQbG9uZyBmdSIgL3Zhci9saWIvcGxvbmcgL3NiaW4vbm9sb2dpbgAA
user(plong) = dSEgcGxvbmcgLSAiUGxvbmcgZnUiIC92YXIvbGliL3Bsb25nIC9zYmluL25vbG9naW4A
],
[warning: ignoring unsupported sysuser type: r
])
Expand Down Expand Up @@ -1660,15 +1660,19 @@ runroot rpm -V ${VERIFYOPTS} klang-client klang-common
RPMTEST_CHECK([
runroot rpm -U /build/RPMS/noarch/klang-server-1.0-1.noarch.rpm
runroot_other grep ^klangd /etc/passwd | cut -f1 -d:
runroot_other chage -l klangd | grep "Account expires" | cut -f2 -d:
runroot_other grep ^klangd /etc/group | cut -f1 -d:
runroot_other grep ^plong /etc/passwd | cut -f1 -d:
runroot_other chage -l plong | grep "Account expires" | cut -f2 -d:
runroot_other grep ^klong /etc/group | cut -f4 -d:
runroot rpm -V ${VERIFYOPTS} klang-server
],
[0],
[klangd
never
klangd
plong
Jan 01, 1970
klangd
],
[ignore])
Expand Down

0 comments on commit c065b98

Please sign in to comment.