diff options
author | Lennart Poettering <lennart@poettering.net> | 2024-11-22 09:34:56 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2024-11-22 11:28:17 +0100 |
commit | e412fc5e042b8f642bcba42f5c175124583e05ae (patch) | |
tree | c6d4e1ad82971db120a9617035c10aa33c56b90b /src | |
parent | bash-completion: add --list-devices to systemd-cryptenroll (diff) | |
download | systemd-e412fc5e042b8f642bcba42f5c175124583e05ae.tar.xz systemd-e412fc5e042b8f642bcba42f5c175124583e05ae.zip |
userbdctl: show 'mapped' user range only inside of userns
Outside of userns the concept makes no sense, there cannot be users
mapped from further outside.
Diffstat (limited to 'src')
-rw-r--r-- | src/userdb/userdbctl.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/userdb/userdbctl.c b/src/userdb/userdbctl.c index cbbd9b10b5..6028a87827 100644 --- a/src/userdb/userdbctl.c +++ b/src/userdb/userdbctl.c @@ -23,6 +23,7 @@ #include "user-util.h" #include "userdb.h" #include "verbs.h" +#include "virt.h" static enum { OUTPUT_CLASSIC, @@ -139,10 +140,16 @@ static int show_user(UserRecord *ur, Table *table) { return 0; } +static bool test_show_mapped(void) { + /* Show mapped user range only in environments where user mapping is a thing. */ + return running_in_userns() > 0; +} + static const struct { uid_t first, last; const char *name; UserDisposition disposition; + bool (*test)(void); } uid_range_table[] = { { .first = 1, @@ -175,6 +182,7 @@ static const struct { .last = MAP_UID_MAX, .name = "mapped", .disposition = USER_REGULAR, + .test = test_show_mapped, }, }; @@ -192,6 +200,9 @@ static int table_add_uid_boundaries(Table *table, const UIDRange *p) { if (!uid_range_covers(p, i->first, i->last - i->first + 1)) continue; + if (i->test && !i->test()) + continue; + name = strjoin(special_glyph(SPECIAL_GLYPH_ARROW_DOWN), " begin ", i->name, " users ", special_glyph(SPECIAL_GLYPH_ARROW_DOWN)); @@ -575,6 +586,9 @@ static int table_add_gid_boundaries(Table *table, const UIDRange *p) { if (!uid_range_covers(p, i->first, i->last - i->first + 1)) continue; + if (i->test && !i->test()) + continue; + name = strjoin(special_glyph(SPECIAL_GLYPH_ARROW_DOWN), " begin ", i->name, " groups ", special_glyph(SPECIAL_GLYPH_ARROW_DOWN)); |