systemd/0596-userdb-add-support-for-printing-the-UUID-from-user-a.patch
2026-05-19 20:15:00 -04:00

90 lines
5.2 KiB
Diff

From eee22e76c180f9afb5401c8c5e9dcee55cd70c43 Mon Sep 17 00:00:00 2001
From: Erin Shepherd <erin.shepherd@e43.eu>
Date: Tue, 8 Apr 2025 12:07:46 +0000
Subject: [PATCH] userdb: add support for printing the UUID from user and group
records
(cherry picked from commit 60cd0cc77a6312a260ed06e73e62d8de942dcb79)
Related: RHEL-143036
---
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 07bce7056d..99e1148447 100644
--- a/src/shared/group-record.c
+++ b/src/shared/group-record.c
@@ -173,6 +173,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 5705fe2511..1a81b006ce 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 754895c787..dab75d1f79 100644
--- a/src/shared/user-record-show.c
+++ b/src/shared/user-record-show.c
@@ -239,6 +239,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);
@@ -644,6 +647,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 e984f6d24c..3b2194a9de 100644
--- a/src/shared/user-record.c
+++ b/src/shared/user-record.c
@@ -1541,6 +1541,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 91402f38b9..a7a3f5e924 100644
--- a/src/shared/user-record.h
+++ b/src/shared/user-record.h
@@ -242,6 +242,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;