sysusers/provides: parse and output static IDs

This adds support for parsing static UIDs and GIDs from sysusers.d
fragments, and automatically forwarding them to the generated
'Provides' entries.
It will allow inspecting users/groups with static IDs directly
from package metadata:
```
$ rpm --query --provides --package gdm-41.0-3.fc36.x86_64.rpm
[...]
group(gdm) = 42
user(gdm) = 42
```
This commit is contained in:
Luca BRUNO 2021-11-16 16:36:58 +00:00
parent 2d54326a8c
commit 21ca64d8e0
No known key found for this signature in database
GPG Key ID: A9834A2252078E4E

View File

@ -1,5 +1,40 @@
#!/bin/bash #!/bin/bash
process_u() {
if [ ! -z "${2##*[!0-9]*}" ]; then
# Single shared static ID.
echo "user($1) = $2"
echo "group($1) = $2"
elif [[ $2 == *:* ]]; then
# UID:<group>.
uid=$(echo $2 | cut -d':' -f1 -)
group=$(echo $2 | cut -d':' -f2 -)
if [ ! -z "${group##*[!0-9]*}" ]; then
# UID:GID.
echo "user($1) = ${uid}"
echo "group($1) = ${group}"
else
# UID:<groupname>.
echo "user($1) = ${uid}"
echo "group(${group})"
fi
else
# Dynamic (or something else uninteresting).
echo "user($1)"
echo "group($1)"
fi
}
process_g() {
if [ ! -z "${2##*[!0-9]*}" ]; then
# Static GID.
echo "group($1) = $2"
else
# Dynamic (or something else uninteresting).
echo "group($1)"
fi
}
parse() { parse() {
while read line; do while read line; do
[ "${line:0:1}" = '#' -o "${line:0:1}" = ';' ] && continue [ "${line:0:1}" = '#' -o "${line:0:1}" = ';' ] && continue
@ -8,12 +43,10 @@ parse() {
set -- $line set -- $line
case "$1" in case "$1" in
('u') ('u')
echo "user($2)" process_u "$2" "$3"
echo "group($2)"
# TODO: user:group support
;; ;;
('g') ('g')
echo "group($2)" process_g "$2" "$3"
;; ;;
('m') ('m')
echo "user($2)" echo "user($2)"