Skip to content

Commit 1191cc3

Browse files
poetteringbluca
authored andcommitted
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. (cherry picked from commit e412fc5) (cherry picked from commit aed4e90) (cherry picked from commit 421c23f) (cherry picked from commit de65927)
1 parent 2625c00 commit 1191cc3

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/userdb/userdbctl.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "user-util.h"
2424
#include "userdb.h"
2525
#include "verbs.h"
26+
#include "virt.h"
2627

2728
static enum {
2829
OUTPUT_CLASSIC,
@@ -130,10 +131,16 @@ static int show_user(UserRecord *ur, Table *table) {
130131
return 0;
131132
}
132133

134+
static bool test_show_mapped(void) {
135+
/* Show mapped user range only in environments where user mapping is a thing. */
136+
return running_in_userns() > 0;
137+
}
138+
133139
static const struct {
134140
uid_t first, last;
135141
const char *name;
136142
UserDisposition disposition;
143+
bool (*test)(void);
137144
} uid_range_table[] = {
138145
{
139146
.first = 1,
@@ -166,6 +173,7 @@ static const struct {
166173
.last = MAP_UID_MAX,
167174
.name = "mapped",
168175
.disposition = USER_REGULAR,
176+
.test = test_show_mapped,
169177
},
170178
};
171179

@@ -180,6 +188,9 @@ static int table_add_uid_boundaries(Table *table, const UidRange *p) {
180188
if (!uid_range_covers(p, uid_range_table[i].first, uid_range_table[i].last - uid_range_table[i].first + 1))
181189
continue;
182190

191+
if (uid_range_table[i].test && !uid_range_table[i].test())
192+
continue;
193+
183194
name = strjoin(special_glyph(SPECIAL_GLYPH_ARROW_DOWN),
184195
" begin ", uid_range_table[i].name, " users ",
185196
special_glyph(SPECIAL_GLYPH_ARROW_DOWN));
@@ -541,6 +552,9 @@ static int table_add_gid_boundaries(Table *table, const UidRange *p) {
541552
uid_range_table[i].last - uid_range_table[i].first + 1))
542553
continue;
543554

555+
if (uid_range_table[i].test && !uid_range_table[i].test())
556+
continue;
557+
544558
name = strjoin(special_glyph(SPECIAL_GLYPH_ARROW_DOWN),
545559
" begin ", uid_range_table[i].name, " groups ",
546560
special_glyph(SPECIAL_GLYPH_ARROW_DOWN));

0 commit comments

Comments
 (0)