Skip to content

Commit 427e392

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) (cherry picked from commit 1191cc3)
1 parent c5abedd commit 427e392

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
@@ -22,6 +22,7 @@
2222
#include "user-util.h"
2323
#include "userdb.h"
2424
#include "verbs.h"
25+
#include "virt.h"
2526

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

133+
static bool test_show_mapped(void) {
134+
/* Show mapped user range only in environments where user mapping is a thing. */
135+
return running_in_userns() > 0;
136+
}
137+
132138
static const struct {
133139
uid_t first, last;
134140
const char *name;
135141
UserDisposition disposition;
142+
bool (*test)(void);
136143
} uid_range_table[] = {
137144
{
138145
.first = 1,
@@ -165,6 +172,7 @@ static const struct {
165172
.last = MAP_UID_MAX,
166173
.name = "mapped",
167174
.disposition = USER_REGULAR,
175+
.test = test_show_mapped,
168176
},
169177
};
170178

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

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

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

0 commit comments

Comments
 (0)