diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 03:50:42 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 03:50:42 +0000 |
commit | 78e9bb837c258ac0ec7712b3d612cc2f407e731e (patch) | |
tree | f515d16b6efd858a9aeb5b0ef5d6f90bf288283d /src/userdb/userdbctl.c | |
parent | Adding debian version 255.5-1. (diff) | |
download | systemd-78e9bb837c258ac0ec7712b3d612cc2f407e731e.tar.xz systemd-78e9bb837c258ac0ec7712b3d612cc2f407e731e.zip |
Merging upstream version 256.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/userdb/userdbctl.c')
-rw-r--r-- | src/userdb/userdbctl.c | 79 |
1 files changed, 38 insertions, 41 deletions
diff --git a/src/userdb/userdbctl.c b/src/userdb/userdbctl.c index 238a71d..1718419 100644 --- a/src/userdb/userdbctl.c +++ b/src/userdb/userdbctl.c @@ -169,24 +169,24 @@ static const struct { }, }; -static int table_add_uid_boundaries(Table *table, const UidRange *p) { +static int table_add_uid_boundaries(Table *table, const UIDRange *p) { int r; assert(table); - for (size_t i = 0; i < ELEMENTSOF(uid_range_table); i++) { + FOREACH_ELEMENT(i, uid_range_table) { _cleanup_free_ char *name = NULL, *comment = NULL; - if (!uid_range_covers(p, uid_range_table[i].first, uid_range_table[i].last - uid_range_table[i].first + 1)) + if (!uid_range_covers(p, i->first, i->last - i->first + 1)) continue; name = strjoin(special_glyph(SPECIAL_GLYPH_ARROW_DOWN), - " begin ", uid_range_table[i].name, " users ", + " begin ", i->name, " users ", special_glyph(SPECIAL_GLYPH_ARROW_DOWN)); if (!name) return log_oom(); - comment = strjoin("First ", uid_range_table[i].name, " user"); + comment = strjoin("First ", i->name, " user"); if (!comment) return log_oom(); @@ -195,9 +195,9 @@ static int table_add_uid_boundaries(Table *table, const UidRange *p) { TABLE_STRING, special_glyph(SPECIAL_GLYPH_TREE_TOP), TABLE_STRING, name, TABLE_SET_COLOR, ansi_grey(), - TABLE_STRING, user_disposition_to_string(uid_range_table[i].disposition), + TABLE_STRING, user_disposition_to_string(i->disposition), TABLE_SET_COLOR, ansi_grey(), - TABLE_UID, uid_range_table[i].first, + TABLE_UID, i->first, TABLE_SET_COLOR, ansi_grey(), TABLE_EMPTY, TABLE_STRING, comment, @@ -210,13 +210,13 @@ static int table_add_uid_boundaries(Table *table, const UidRange *p) { free(name); name = strjoin(special_glyph(SPECIAL_GLYPH_ARROW_UP), - " end ", uid_range_table[i].name, " users ", + " end ", i->name, " users ", special_glyph(SPECIAL_GLYPH_ARROW_UP)); if (!name) return log_oom(); free(comment); - comment = strjoin("Last ", uid_range_table[i].name, " user"); + comment = strjoin("Last ", i->name, " user"); if (!comment) return log_oom(); @@ -225,9 +225,9 @@ static int table_add_uid_boundaries(Table *table, const UidRange *p) { TABLE_STRING, special_glyph(SPECIAL_GLYPH_TREE_RIGHT), TABLE_STRING, name, TABLE_SET_COLOR, ansi_grey(), - TABLE_STRING, user_disposition_to_string(uid_range_table[i].disposition), + TABLE_STRING, user_disposition_to_string(i->disposition), TABLE_SET_COLOR, ansi_grey(), - TABLE_UID, uid_range_table[i].last, + TABLE_UID, i->last, TABLE_SET_COLOR, ansi_grey(), TABLE_EMPTY, TABLE_STRING, comment, @@ -301,7 +301,7 @@ static int add_unavailable_uid(Table *table, uid_t start, uid_t end) { static int table_add_uid_map( Table *table, - const UidRange *p, + const UIDRange *p, int (*add_unavailable)(Table *t, uid_t start, uid_t end)) { uid_t focus = 0; @@ -313,9 +313,7 @@ static int table_add_uid_map( if (!p) return 0; - for (size_t i = 0; p && i < p->n_entries; i++) { - UidRangeEntry *x = p->entries + i; - + FOREACH_ARRAY(x, p->entries, p->n_entries) { if (focus < x->start) { r = add_unavailable(table, focus, x->start-1); if (r < 0) @@ -428,10 +426,10 @@ static int display_user(int argc, char *argv[], void *userdata) { } if (table) { - _cleanup_(uid_range_freep) UidRange *uid_range = NULL; + _cleanup_(uid_range_freep) UIDRange *uid_range = NULL; int boundary_lines, uid_map_lines; - r = uid_range_load_userns(&uid_range, "/proc/self/uid_map"); + r = uid_range_load_userns(/* path = */ NULL, UID_RANGE_USERNS_INSIDE, &uid_range); if (r < 0) log_debug_errno(r, "Failed to load /proc/self/uid_map, ignoring: %m"); @@ -443,7 +441,7 @@ static int display_user(int argc, char *argv[], void *userdata) { if (uid_map_lines < 0) return uid_map_lines; - if (table_get_rows(table) > 1) { + if (!table_isempty(table)) { r = table_print_with_pager(table, arg_json_format_flags, arg_pager_flags, arg_legend); if (r < 0) return table_log_print_error(r); @@ -529,25 +527,24 @@ static int show_group(GroupRecord *gr, Table *table) { return 0; } -static int table_add_gid_boundaries(Table *table, const UidRange *p) { +static int table_add_gid_boundaries(Table *table, const UIDRange *p) { int r; assert(table); - for (size_t i = 0; i < ELEMENTSOF(uid_range_table); i++) { + FOREACH_ELEMENT(i, uid_range_table) { _cleanup_free_ char *name = NULL, *comment = NULL; - if (!uid_range_covers(p, uid_range_table[i].first, - uid_range_table[i].last - uid_range_table[i].first + 1)) + if (!uid_range_covers(p, i->first, i->last - i->first + 1)) continue; name = strjoin(special_glyph(SPECIAL_GLYPH_ARROW_DOWN), - " begin ", uid_range_table[i].name, " groups ", + " begin ", i->name, " groups ", special_glyph(SPECIAL_GLYPH_ARROW_DOWN)); if (!name) return log_oom(); - comment = strjoin("First ", uid_range_table[i].name, " group"); + comment = strjoin("First ", i->name, " group"); if (!comment) return log_oom(); @@ -556,9 +553,9 @@ static int table_add_gid_boundaries(Table *table, const UidRange *p) { TABLE_STRING, special_glyph(SPECIAL_GLYPH_TREE_TOP), TABLE_STRING, name, TABLE_SET_COLOR, ansi_grey(), - TABLE_STRING, user_disposition_to_string(uid_range_table[i].disposition), + TABLE_STRING, user_disposition_to_string(i->disposition), TABLE_SET_COLOR, ansi_grey(), - TABLE_GID, uid_range_table[i].first, + TABLE_GID, i->first, TABLE_SET_COLOR, ansi_grey(), TABLE_STRING, comment, TABLE_SET_COLOR, ansi_grey(), @@ -568,13 +565,13 @@ static int table_add_gid_boundaries(Table *table, const UidRange *p) { free(name); name = strjoin(special_glyph(SPECIAL_GLYPH_ARROW_UP), - " end ", uid_range_table[i].name, " groups ", + " end ", i->name, " groups ", special_glyph(SPECIAL_GLYPH_ARROW_UP)); if (!name) return log_oom(); free(comment); - comment = strjoin("Last ", uid_range_table[i].name, " group"); + comment = strjoin("Last ", i->name, " group"); if (!comment) return log_oom(); @@ -583,9 +580,9 @@ static int table_add_gid_boundaries(Table *table, const UidRange *p) { TABLE_STRING, special_glyph(SPECIAL_GLYPH_TREE_RIGHT), TABLE_STRING, name, TABLE_SET_COLOR, ansi_grey(), - TABLE_STRING, user_disposition_to_string(uid_range_table[i].disposition), + TABLE_STRING, user_disposition_to_string(i->disposition), TABLE_SET_COLOR, ansi_grey(), - TABLE_GID, uid_range_table[i].last, + TABLE_GID, i->last, TABLE_SET_COLOR, ansi_grey(), TABLE_STRING, comment, TABLE_SET_COLOR, ansi_grey(), @@ -732,10 +729,10 @@ static int display_group(int argc, char *argv[], void *userdata) { } if (table) { - _cleanup_(uid_range_freep) UidRange *gid_range = NULL; + _cleanup_(uid_range_freep) UIDRange *gid_range = NULL; int boundary_lines, gid_map_lines; - r = uid_range_load_userns(&gid_range, "/proc/self/gid_map"); + r = uid_range_load_userns(/* path = */ NULL, GID_RANGE_USERNS_INSIDE, &gid_range); if (r < 0) log_debug_errno(r, "Failed to load /proc/self/gid_map, ignoring: %m"); @@ -747,7 +744,7 @@ static int display_group(int argc, char *argv[], void *userdata) { if (gid_map_lines < 0) return gid_map_lines; - if (table_get_rows(table) > 1) { + if (!table_isempty(table)) { r = table_print_with_pager(table, arg_json_format_flags, arg_pager_flags, arg_legend); if (r < 0) return table_log_print_error(r); @@ -895,17 +892,17 @@ static int display_memberships(int argc, char *argv[], void *userdata) { } if (table) { - if (table_get_rows(table) > 1) { + if (!table_isempty(table)) { r = table_print_with_pager(table, arg_json_format_flags, arg_pager_flags, arg_legend); if (r < 0) return table_log_print_error(r); } if (arg_legend) { - if (table_get_rows(table) > 1) - printf("\n%zu memberships listed.\n", table_get_rows(table) - 1); - else + if (table_isempty(table)) printf("No memberships.\n"); + else + printf("\n%zu memberships listed.\n", table_get_rows(table) - 1); } } @@ -960,17 +957,17 @@ static int display_services(int argc, char *argv[], void *userdata) { return table_log_add_error(r); } - if (table_get_rows(t) > 1) { + if (!table_isempty(t)) { r = table_print_with_pager(t, arg_json_format_flags, arg_pager_flags, arg_legend); if (r < 0) return table_log_print_error(r); } if (arg_legend && arg_output != OUTPUT_JSON) { - if (table_get_rows(t) > 1) - printf("\n%zu services listed.\n", table_get_rows(t) - 1); - else + if (table_isempty(t)) printf("No services.\n"); + else + printf("\n%zu services listed.\n", table_get_rows(t) - 1); } return 0; |