From ebe37f771cb44daa216c34cefc41ba71e93413ee Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 12 Nov 2024 16:35:32 +0100 Subject: [PATCH] user-record: distinguish explicit and implicit empty modifiable lists case We now distinguish two cases: where the list of self modifiable fields is explicitly set to empty, and where the default is empty. Let's display them differently in the output. When set explicitly to empty let's mention the admin, otherwise just say "none". --- src/shared/user-record-show.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/shared/user-record-show.c b/src/shared/user-record-show.c index e6de0cd002f..4d8ffe1c35f 100644 --- a/src/shared/user-record-show.c +++ b/src/shared/user-record-show.c @@ -28,21 +28,28 @@ const char* user_record_state_color(const char *state) { return NULL; } -static void dump_self_modifiable(const char *heading, char **field, const char **value) { +static void dump_self_modifiable( + const char *heading, + char **field, + const char **value) { + assert(heading); /* Helper function for printing the various self_modifiable_* fields from the user record */ - if (strv_isempty((char**) value)) - /* Case 1: the array is explicitly set to be empty by the administrator */ - printf("%13s %sDisabled by Administrator%s\n", heading, ansi_highlight_red(), ansi_normal()); + if (!value) + /* Case 1: no value is set and no default either */ + printf("%13s %snone%s\n", heading, ansi_highlight(), ansi_normal()); + else if (strv_isempty((char**) value)) + /* Case 2: the array is explicitly set to empty by the administrator */ + printf("%13s %sdisabled by administrator%s\n", heading, ansi_highlight_red(), ansi_normal()); else if (!field) - /* Case 2: we have values, but the field is NULL. This means that we're using the defaults. + /* Case 3: we have values, but the field is NULL. This means that we're using the defaults. * We list them anyways, because they're security-sensitive to the administrator */ STRV_FOREACH(i, value) printf("%13s %s%s%s\n", i == value ? heading : "", ansi_grey(), *i, ansi_normal()); else - /* Case 3: we have a list provided by the administrator */ + /* Case 4: we have a list provided by the administrator */ STRV_FOREACH(i, value) printf("%13s %s\n", i == value ? heading : "", *i); }