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

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