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.
This commit is contained in:
parent
fdc6c4f49c
commit
0bb4308014
|
@ -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));
|
||||
|
||||
|
|
|
@ -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 },
|
||||
|
|
|
@ -13,6 +13,8 @@ typedef struct GroupRecord {
|
|||
char *realm;
|
||||
char *group_name_and_realm_auto;
|
||||
|
||||
char *description;
|
||||
|
||||
UserDisposition disposition;
|
||||
uint64_t last_change_usec;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue