homework: add new helper call that can shift home dir UID/GID ranges
authorLennart Poettering <lennart@poettering.net>
Wed, 20 Oct 2021 20:12:16 +0000 (22:12 +0200)
committerLennart Poettering <lennart@poettering.net>
Wed, 27 Oct 2021 15:37:14 +0000 (17:37 +0200)
commitc7bf079bbc19e3b409acc0c7acc3e14749211fe2
tree8d00d60d3503d65f3f8a0a9c1c6d7b719f9b23fa
parent2ba38f78c3048f9c117b45111791fef4c603455e
homework: add new helper call that can shift home dir UID/GID ranges

This new helper is not used yet, but it's useful for apply UID/GID
shifts so that the underlying home dir can use an arbitrary UID (for
example "nobody") and we'll still make it appear as owned by the target
UID.

This operates roughly like this:

1. The relevant underlying UID is mapped to the target UID
2. Everything in the homed UID range except for the target UID is left
   unmapped (and thus will appear as "nobody")
3. Everything in the 16bit UID range outside of the homed UID
   range/target UID/nobody user is mapped to itself
4. Everything else is left unmapped (in particular everything outside of
   the 16 bit range).

Why do it like this?

The 2nd rule done to ensure that any files from homed's managed UID
range that do not match the user's own UID will be shown as "unmapped"
basically. Of course, IRL this should never happen, except if people
managed to manipulate the underlying fs directly.

The 3rd rule is to allow that if devs untar an OS image it more or
less just works as before: 16bit UIDs outside of the homed range will
be mapped onto themselves: you can untar things and tar it back up and
things will just work.
src/home/homework-mount.c
src/home/homework-mount.h