112 lines
4.8 KiB
Diff
112 lines
4.8 KiB
Diff
From 9a92c83a44c68511b52302058a95de89239cbf15 Mon Sep 17 00:00:00 2001
|
|
From: Erin Shepherd <erin.shepherd@e43.eu>
|
|
Date: Mon, 21 Jul 2025 19:29:53 +0000
|
|
Subject: [PATCH] userdbctl: add --uuid filtering option
|
|
|
|
This uses the new UUID-based filtering logic inside the userdb library
|
|
to return just the requested user/group record
|
|
|
|
(cherry picked from commit 466562c69b75cec197176f556b940a43bb8350f2)
|
|
|
|
Related: RHEL-143036
|
|
---
|
|
man/userdbctl.xml | 9 +++++++++
|
|
src/userdb/userdbctl.c | 15 +++++++++++++--
|
|
2 files changed, 22 insertions(+), 2 deletions(-)
|
|
|
|
diff --git a/man/userdbctl.xml b/man/userdbctl.xml
|
|
index 22d7da4d12..110b1c0f35 100644
|
|
--- a/man/userdbctl.xml
|
|
+++ b/man/userdbctl.xml
|
|
@@ -225,6 +225,15 @@
|
|
<xi:include href="version-info.xml" xpointer="v257"/></listitem>
|
|
</varlistentry>
|
|
|
|
+ <varlistentry>
|
|
+ <term><option>--uuid=</option></term>
|
|
+
|
|
+ <listitem><para>When used with the <command>user</command> or <command>group</command> command,
|
|
+ filters the output to the record with the specified UUID. If unspecified, no UUID-based filtering is applied.</para>
|
|
+
|
|
+ <xi:include href="version-info.xml" xpointer="v258"/></listitem>
|
|
+ </varlistentry>
|
|
+
|
|
<varlistentry>
|
|
<term><option>--boundaries=</option></term>
|
|
|
|
diff --git a/src/userdb/userdbctl.c b/src/userdb/userdbctl.c
|
|
index 074d9103af..cb9d2e1897 100644
|
|
--- a/src/userdb/userdbctl.c
|
|
+++ b/src/userdb/userdbctl.c
|
|
@@ -42,6 +42,7 @@ static bool arg_chain = false;
|
|
static uint64_t arg_disposition_mask = UINT64_MAX;
|
|
static uid_t arg_uid_min = 0;
|
|
static uid_t arg_uid_max = UID_INVALID-1;
|
|
+static sd_id128_t arg_uuid = SD_ID128_NULL;
|
|
static bool arg_fuzzy = false;
|
|
static bool arg_boundaries = true;
|
|
static sd_json_variant *arg_from_file = NULL;
|
|
@@ -381,7 +382,7 @@ static int display_user(int argc, char *argv[], void *userdata) {
|
|
int ret = 0, r;
|
|
|
|
if (arg_output < 0)
|
|
- arg_output = arg_from_file || (argc > 1 && !arg_fuzzy) ? OUTPUT_FRIENDLY : OUTPUT_TABLE;
|
|
+ arg_output = arg_from_file || (argc > 1 && !arg_fuzzy) || !sd_id128_is_null(arg_uuid) ? OUTPUT_FRIENDLY : OUTPUT_TABLE;
|
|
|
|
if (arg_output == OUTPUT_TABLE) {
|
|
table = table_new(" ", "name", "disposition", "uid", "gid", "realname", "home", "shell", "order");
|
|
@@ -401,6 +402,7 @@ static int display_user(int argc, char *argv[], void *userdata) {
|
|
.disposition_mask = arg_disposition_mask,
|
|
.uid_min = arg_uid_min,
|
|
.uid_max = arg_uid_max,
|
|
+ .uuid = arg_uuid,
|
|
};
|
|
|
|
if (arg_from_file) {
|
|
@@ -723,7 +725,7 @@ static int display_group(int argc, char *argv[], void *userdata) {
|
|
int ret = 0, r;
|
|
|
|
if (arg_output < 0)
|
|
- arg_output = arg_from_file || (argc > 1 && !arg_fuzzy) ? OUTPUT_FRIENDLY : OUTPUT_TABLE;
|
|
+ arg_output = arg_from_file || (argc > 1 && !arg_fuzzy) || !sd_id128_is_null(arg_uuid) ? OUTPUT_FRIENDLY : OUTPUT_TABLE;
|
|
|
|
if (arg_output == OUTPUT_TABLE) {
|
|
table = table_new(" ", "name", "disposition", "gid", "description", "order");
|
|
@@ -742,6 +744,7 @@ static int display_group(int argc, char *argv[], void *userdata) {
|
|
.disposition_mask = arg_disposition_mask,
|
|
.gid_min = arg_uid_min,
|
|
.gid_max = arg_uid_max,
|
|
+ .uuid = arg_uuid,
|
|
};
|
|
|
|
if (arg_from_file) {
|
|
@@ -1235,6 +1238,7 @@ static int parse_argv(int argc, char *argv[]) {
|
|
ARG_CHAIN,
|
|
ARG_UID_MIN,
|
|
ARG_UID_MAX,
|
|
+ ARG_UUID,
|
|
ARG_DISPOSITION,
|
|
ARG_BOUNDARIES,
|
|
};
|
|
@@ -1255,6 +1259,7 @@ static int parse_argv(int argc, char *argv[]) {
|
|
{ "chain", no_argument, NULL, ARG_CHAIN },
|
|
{ "uid-min", required_argument, NULL, ARG_UID_MIN },
|
|
{ "uid-max", required_argument, NULL, ARG_UID_MAX },
|
|
+ { "uuid", required_argument, NULL, ARG_UUID },
|
|
{ "fuzzy", no_argument, NULL, 'z' },
|
|
{ "disposition", required_argument, NULL, ARG_DISPOSITION },
|
|
{ "boundaries", required_argument, NULL, ARG_BOUNDARIES },
|
|
@@ -1450,6 +1455,12 @@ static int parse_argv(int argc, char *argv[]) {
|
|
return log_error_errno(r, "Failed to parse --uid-max= value: %s", optarg);
|
|
break;
|
|
|
|
+ case ARG_UUID:
|
|
+ r = sd_id128_from_string(optarg, &arg_uuid);
|
|
+ if (r < 0)
|
|
+ return log_error_errno(r, "Failed to parse --uuid= value: %s", optarg);
|
|
+ break;
|
|
+
|
|
case 'z':
|
|
arg_fuzzy = true;
|
|
break;
|