From 60cd0cc77a6312a260ed06e73e62d8de942dcb79 Mon Sep 17 00:00:00 2001 From: Erin Shepherd Date: Tue, 8 Apr 2025 12:07:46 +0000 Subject: [PATCH] userdb: add support for printing the UUID from user and group records --- src/shared/group-record.c | 1 + src/shared/group-record.h | 1 + src/shared/user-record-show.c | 6 ++++++ src/shared/user-record.c | 1 + src/shared/user-record.h | 1 + 5 files changed, 10 insertions(+) diff --git a/src/shared/group-record.c b/src/shared/group-record.c index d4acc1a2620..db3b96d3ec1 100644 --- a/src/shared/group-record.c +++ b/src/shared/group-record.c @@ -174,6 +174,7 @@ int group_record_load( static const sd_json_dispatch_field group_dispatch_table[] = { { "groupName", SD_JSON_VARIANT_STRING, json_dispatch_user_group_name, offsetof(GroupRecord, group_name), SD_JSON_RELAX }, { "realm", SD_JSON_VARIANT_STRING, json_dispatch_realm, offsetof(GroupRecord, realm), 0 }, + { "uuid", SD_JSON_VARIANT_STRING, sd_json_dispatch_id128, offsetof(GroupRecord, uuid), 0 }, { "description", SD_JSON_VARIANT_STRING, json_dispatch_gecos, offsetof(GroupRecord, description), 0 }, { "disposition", SD_JSON_VARIANT_STRING, json_dispatch_user_disposition, offsetof(GroupRecord, disposition), 0 }, { "service", SD_JSON_VARIANT_STRING, sd_json_dispatch_string, offsetof(GroupRecord, service), SD_JSON_STRICT }, diff --git a/src/shared/group-record.h b/src/shared/group-record.h index 95e70cf2694..54a08f99ead 100644 --- a/src/shared/group-record.h +++ b/src/shared/group-record.h @@ -13,6 +13,7 @@ typedef struct GroupRecord { char *group_name; char *realm; char *group_name_and_realm_auto; + sd_id128_t uuid; char *description; diff --git a/src/shared/user-record-show.c b/src/shared/user-record-show.c index ad0c345bd97..4f0678bed49 100644 --- a/src/shared/user-record-show.c +++ b/src/shared/user-record-show.c @@ -259,6 +259,9 @@ void user_record_show(UserRecord *hr, bool show_full_group_info) { } } + if (!sd_id128_is_null(hr->uuid)) + printf(" UUID: " SD_ID128_UUID_FORMAT_STR "\n", SD_ID128_FORMAT_VAL(hr->uuid)); + if (hr->real_name && !streq(hr->real_name, hr->user_name)) printf(" Real Name: %s\n", hr->real_name); @@ -670,6 +673,9 @@ void group_record_show(GroupRecord *gr, bool show_full_user_info) { if (gid_is_valid(gr->gid)) printf(" GID: " GID_FMT "\n", gr->gid); + if (!sd_id128_is_null(gr->uuid)) + printf(" UUID: " SD_ID128_UUID_FORMAT_STR "\n", SD_ID128_FORMAT_VAL(gr->uuid)); + if (show_full_user_info) { _cleanup_(userdb_iterator_freep) UserDBIterator *iterator = NULL; diff --git a/src/shared/user-record.c b/src/shared/user-record.c index 63d47ec9b1b..d99da34654c 100644 --- a/src/shared/user-record.c +++ b/src/shared/user-record.c @@ -1611,6 +1611,7 @@ int user_record_load(UserRecord *h, sd_json_variant *v, UserRecordLoadFlags load { "userName", SD_JSON_VARIANT_STRING, json_dispatch_user_group_name, offsetof(UserRecord, user_name), SD_JSON_RELAX }, { "aliases", SD_JSON_VARIANT_ARRAY, json_dispatch_user_group_list, offsetof(UserRecord, aliases), SD_JSON_RELAX }, { "realm", SD_JSON_VARIANT_STRING, json_dispatch_realm, offsetof(UserRecord, realm), 0 }, + { "uuid", SD_JSON_VARIANT_STRING, sd_json_dispatch_id128, offsetof(UserRecord, uuid), 0 }, { "blobDirectory", SD_JSON_VARIANT_STRING, json_dispatch_path, offsetof(UserRecord, blob_directory), SD_JSON_STRICT }, { "blobManifest", SD_JSON_VARIANT_OBJECT, dispatch_blob_manifest, offsetof(UserRecord, blob_manifest), 0 }, { "realName", SD_JSON_VARIANT_STRING, json_dispatch_gecos, offsetof(UserRecord, real_name), 0 }, diff --git a/src/shared/user-record.h b/src/shared/user-record.h index 75f50ae347e..725feba699b 100644 --- a/src/shared/user-record.h +++ b/src/shared/user-record.h @@ -269,6 +269,7 @@ typedef struct UserRecord { char *realm; char *user_name_and_realm_auto; /* the user_name field concatenated with '@' and the realm, if the latter is defined */ char **aliases; + sd_id128_t uuid; char *real_name; char *email_address; char *password_hint; -- 2.47.3