summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2020-08-06 17:35:34 +0200
committerLennart Poettering <lennart@poettering.net>2020-08-07 08:39:18 +0200
commit0bb4308014d587354d4dbd1cc3a122f0751974b2 (patch)
treea29c30ffbb90920b720fcbc1168fedf868284336
parentupdate TODO (diff)
downloadsystemd-0bb4308014d587354d4dbd1cc3a122f0751974b2.tar.xz
systemd-0bb4308014d587354d4dbd1cc3a122f0751974b2.zip
userdb: add "description" field to group records
User records have the realname/gecos fields, groups never had that, but it would really be useful to have it, hence let's add it with similar semantics. We enforce the same syntax as for GECOS, since it's better to start with strict rules and losen them later instead of the opposite.
-rw-r--r--src/shared/group-record-show.c3
-rw-r--r--src/shared/group-record.c2
-rw-r--r--src/shared/group-record.h2
-rw-r--r--src/shared/user-record.c2
-rw-r--r--src/shared/user-record.h1
-rw-r--r--src/userdb/userdbctl.c6
6 files changed, 13 insertions, 3 deletions
diff --git a/src/shared/group-record-show.c b/src/shared/group-record-show.c
index d0300e483c..8b59f919fa 100644
--- a/src/shared/group-record-show.c
+++ b/src/shared/group-record-show.c
@@ -68,6 +68,9 @@ void group_record_show(GroupRecord *gr, bool show_full_user_info) {
}
}
+ if (gr->description && !streq(gr->description, gr->group_name))
+ printf(" Description: %s\n", gr->description);
+
if (!strv_isempty(gr->hashed_password))
printf(" Passwords: %zu\n", strv_length(gr->hashed_password));
diff --git a/src/shared/group-record.c b/src/shared/group-record.c
index 3c9520693d..d999ff95f8 100644
--- a/src/shared/group-record.c
+++ b/src/shared/group-record.c
@@ -28,6 +28,7 @@ static GroupRecord *group_record_free(GroupRecord *g) {
free(g->group_name);
free(g->realm);
free(g->group_name_and_realm_auto);
+ free(g->description);
strv_free(g->members);
free(g->service);
@@ -192,6 +193,7 @@ int group_record_load(
static const JsonDispatch group_dispatch_table[] = {
{ "groupName", JSON_VARIANT_STRING, json_dispatch_user_group_name, offsetof(GroupRecord, group_name), JSON_RELAX},
{ "realm", JSON_VARIANT_STRING, json_dispatch_realm, offsetof(GroupRecord, realm), 0 },
+ { "description", JSON_VARIANT_STRING, json_dispatch_gecos, offsetof(GroupRecord, description), 0 },
{ "disposition", JSON_VARIANT_STRING, json_dispatch_user_disposition, offsetof(GroupRecord, disposition), 0 },
{ "service", JSON_VARIANT_STRING, json_dispatch_string, offsetof(GroupRecord, service), JSON_SAFE },
{ "lastChangeUSec", JSON_VARIANT_UNSIGNED, json_dispatch_uint64, offsetof(GroupRecord, last_change_usec), 0 },
diff --git a/src/shared/group-record.h b/src/shared/group-record.h
index b72a43e50d..85c91eb1f5 100644
--- a/src/shared/group-record.h
+++ b/src/shared/group-record.h
@@ -13,6 +13,8 @@ typedef struct GroupRecord {
char *realm;
char *group_name_and_realm_auto;
+ char *description;
+
UserDisposition disposition;
uint64_t last_change_usec;
diff --git a/src/shared/user-record.c b/src/shared/user-record.c
index 16edaa45fa..801de19774 100644
--- a/src/shared/user-record.c
+++ b/src/shared/user-record.c
@@ -203,7 +203,7 @@ int json_dispatch_realm(const char *name, JsonVariant *variant, JsonDispatchFlag
return 0;
}
-static int json_dispatch_gecos(const char *name, JsonVariant *variant, JsonDispatchFlags flags, void *userdata) {
+int json_dispatch_gecos(const char *name, JsonVariant *variant, JsonDispatchFlags flags, void *userdata) {
char **s = userdata;
const char *n;
int r;
diff --git a/src/shared/user-record.h b/src/shared/user-record.h
index 1bfd095d27..39580b6b76 100644
--- a/src/shared/user-record.h
+++ b/src/shared/user-record.h
@@ -388,6 +388,7 @@ int user_record_test_password_change_required(UserRecord *h);
/* The following six are user by group-record.c, that's why we export them here */
int json_dispatch_realm(const char *name, JsonVariant *variant, JsonDispatchFlags flags, void *userdata);
+int json_dispatch_gecos(const char *name, JsonVariant *variant, JsonDispatchFlags flags, void *userdata);
int json_dispatch_user_group_list(const char *name, JsonVariant *variant, JsonDispatchFlags flags, void *userdata);
int json_dispatch_user_disposition(const char *name, JsonVariant *variant, JsonDispatchFlags flags, void *userdata);
diff --git a/src/userdb/userdbctl.c b/src/userdb/userdbctl.c
index c973ee9c01..12c6943ebd 100644
--- a/src/userdb/userdbctl.c
+++ b/src/userdb/userdbctl.c
@@ -232,6 +232,7 @@ static int show_group(GroupRecord *gr, Table *table) {
TABLE_STRING, gr->group_name,
TABLE_STRING, user_disposition_to_string(group_record_disposition(gr)),
TABLE_GID, gr->gid,
+ TABLE_STRING, gr->description,
TABLE_INT, (int) group_record_disposition(gr));
if (r < 0)
return table_log_add_error(r);
@@ -255,13 +256,14 @@ static int display_group(int argc, char *argv[], void *userdata) {
arg_output = argc > 1 ? OUTPUT_FRIENDLY : OUTPUT_TABLE;
if (arg_output == OUTPUT_TABLE) {
- table = table_new("name", "disposition", "gid", "disposition-numeric");
+ table = table_new("name", "disposition", "gid", "description", "disposition-numeric");
if (!table)
return log_oom();
(void) table_set_align_percent(table, table_get_cell(table, 0, 2), 100);
+ (void) table_set_empty_string(table, "-");
(void) table_set_sort(table, (size_t) 3, (size_t) 2, (size_t) -1);
- (void) table_set_display(table, (size_t) 0, (size_t) 1, (size_t) 2, (size_t) -1);
+ (void) table_set_display(table, (size_t) 0, (size_t) 1, (size_t) 2, (size_t) 3, (size_t) -1);
}
if (argc > 1) {