diff options
author | Lennart Poettering <lennart@poettering.net> | 2024-11-22 16:06:01 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-22 16:06:01 +0100 |
commit | d209e197f89f8d70349e3b6cad5948d1b419b16f (patch) | |
tree | 2d5b248bb2a7fbc3bf4bdf723d27a0b8b69a46b1 /src | |
parent | tpm2-util: fix parameter name (diff) | |
parent | userdbctl: respect selected disposition also when showing gid boundaries (diff) | |
download | systemd-d209e197f89f8d70349e3b6cad5948d1b419b16f.tar.xz systemd-d209e197f89f8d70349e3b6cad5948d1b419b16f.zip |
userdbctl: two trivial fixlets (#35296)
Fixes: #35294
Diffstat (limited to 'src')
-rw-r--r-- | src/userdb/userdbctl.c | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/src/userdb/userdbctl.c b/src/userdb/userdbctl.c index cbbd9b10b5..bc69175b10 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,11 +182,12 @@ static const struct { .last = MAP_UID_MAX, .name = "mapped", .disposition = USER_REGULAR, + .test = test_show_mapped, }, }; static int table_add_uid_boundaries(Table *table, const UIDRange *p) { - int r; + int r, n_added = 0; assert(table); @@ -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)); @@ -249,9 +260,11 @@ static int table_add_uid_boundaries(Table *table, const UIDRange *p) { TABLE_INT, 1); /* sort after any other entry with the same UID */ if (r < 0) return table_log_add_error(r); + + n_added += 2; } - return ELEMENTSOF(uid_range_table) * 2; + return n_added; } static int add_unavailable_uid(Table *table, uid_t start, uid_t end) { @@ -565,16 +578,22 @@ static int show_group(GroupRecord *gr, Table *table) { } static int table_add_gid_boundaries(Table *table, const UIDRange *p) { - int r; + int r, n_added = 0; assert(table); FOREACH_ELEMENT(i, uid_range_table) { _cleanup_free_ char *name = NULL, *comment = NULL; + if (!FLAGS_SET(arg_disposition_mask, UINT64_C(1) << i->disposition)) + continue; + 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)); @@ -626,9 +645,11 @@ static int table_add_gid_boundaries(Table *table, const UIDRange *p) { TABLE_INT, 1); /* sort after any other entry with the same GID */ if (r < 0) return table_log_add_error(r); + + n_added += 2; } - return ELEMENTSOF(uid_range_table) * 2; + return n_added; } static int add_unavailable_gid(Table *table, uid_t start, uid_t end) { |