Blame SOURCES/shadow-4.9-subordinateio-compare-owner-ID.patch

2d3122
From 3ec32f9975f262073f8fbdecd2bfaee4a1d3db48 Mon Sep 17 00:00:00 2001
2d3122
From: Iker Pedrosa <ipedrosa@redhat.com>
2d3122
Date: Wed, 13 Jul 2022 09:55:14 +0200
2d3122
Subject: [PATCH] subordinateio: also compare the owner ID
2d3122
2d3122
IDs already populate /etc/subuid and /etc/subgid files so it's necessary
2d3122
not only to check for the owner name but also for the owner ID of a
2d3122
given range.
2d3122
2d3122
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2093311
2d3122
2d3122
Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2d3122
---
2d3122
 lib/subordinateio.c | 50 +++++++++++++++++++++++++++++++++++++++++++++
2d3122
 1 file changed, 50 insertions(+)
2d3122
2d3122
diff --git a/lib/subordinateio.c b/lib/subordinateio.c
2d3122
index 9ca70b8b..6bc45283 100644
2d3122
--- a/lib/subordinateio.c
2d3122
+++ b/lib/subordinateio.c
2d3122
@@ -17,6 +17,8 @@
2d3122
 #include <ctype.h>
2d3122
 #include <fcntl.h>
2d3122
 
2d3122
+#define ID_SIZE 31
2d3122
+
2d3122
 /*
2d3122
  * subordinate_dup: create a duplicate range
2d3122
  *
2d3122
@@ -745,6 +747,40 @@ gid_t sub_gid_find_free_range(gid_t min, gid_t max, unsigned long count)
2d3122
 	return start == ULONG_MAX ? (gid_t) -1 : start;
2d3122
 }
2d3122
 
2d3122
+static bool get_owner_id(const char *owner, enum subid_type id_type, char *id)
2d3122
+{
2d3122
+	struct passwd *pw;
2d3122
+	struct group *gr;
2d3122
+	int ret = 0;
2d3122
+
2d3122
+	switch (id_type) {
2d3122
+	case ID_TYPE_UID:
2d3122
+		pw = getpwnam(owner);
2d3122
+		if (pw == NULL) {
2d3122
+			return false;
2d3122
+		}
2d3122
+		ret = snprintf(id, ID_SIZE, "%u", pw->pw_uid);
2d3122
+		if (ret < 0 || ret >= ID_SIZE) {
2d3122
+			return false;
2d3122
+		}
2d3122
+		break;
2d3122
+	case ID_TYPE_GID:
2d3122
+		gr = getgrnam(owner);
2d3122
+		if (gr == NULL) {
2d3122
+			return false;
2d3122
+		}
2d3122
+		ret = snprintf(id, ID_SIZE, "%u", gr->gr_gid);
2d3122
+		if (ret < 0 || ret >= ID_SIZE) {
2d3122
+			return false;
2d3122
+		}
2d3122
+		break;
2d3122
+	default:
2d3122
+		return false;
2d3122
+	}
2d3122
+
2d3122
+	return true;
2d3122
+}
2d3122
+
2d3122
 /*
2d3122
  * int list_owner_ranges(const char *owner, enum subid_type id_type, struct subordinate_range ***ranges)
2d3122
  *
2d3122
@@ -770,6 +806,8 @@ int list_owner_ranges(const char *owner, enum subid_type id_type, struct subid_r
2d3122
 	enum subid_status status;
2d3122
 	int count = 0;
2d3122
 	struct subid_nss_ops *h;
2d3122
+	char id[ID_SIZE];
2d3122
+	bool have_owner_id;
2d3122
 
2d3122
 	*in_ranges = NULL;
2d3122
 
2d3122
@@ -798,6 +836,8 @@ int list_owner_ranges(const char *owner, enum subid_type id_type, struct subid_r
2d3122
 		return -1;
2d3122
 	}
2d3122
 
2d3122
+	have_owner_id = get_owner_id(owner, id_type, id);
2d3122
+
2d3122
 	commonio_rewind(db);
2d3122
 	while ((range = commonio_next(db)) != NULL) {
2d3122
 		if (0 == strcmp(range->owner, owner)) {
2d3122
@@ -808,6 +848,16 @@ int list_owner_ranges(const char *owner, enum subid_type id_type, struct subid_r
2d3122
 				goto out;
2d3122
 			}
2d3122
 		}
2d3122
+
2d3122
+		// Let's also compare with the ID
2d3122
+		if (have_owner_id == true && 0 == strcmp(range->owner, id)) {
2d3122
+			if (!append_range(&ranges, range, count++)) {
2d3122
+				free(ranges);
2d3122
+				ranges = NULL;
2d3122
+				count = -1;
2d3122
+				goto out;
2d3122
+			}
2d3122
+		}
2d3122
 	}
2d3122
 
2d3122
 out:
2d3122
-- 
2d3122
2.36.1
2d3122