Blame SOURCES/shadow-4.6-libsubid_simplify_ranges_variable.patch

9ed61c
diff -up shadow-4.8.1/configure.ac.libsubid_simplify_ranges_variable shadow-4.8.1/configure.ac
9ed61c
--- shadow-4.8.1/configure.ac.libsubid_simplify_ranges_variable	2021-05-24 15:02:56.165917066 +0200
9ed61c
+++ shadow-4.8.1/configure.ac	2021-05-24 15:02:56.184917324 +0200
9ed61c
@@ -1,6 +1,6 @@
9ed61c
 dnl Process this file with autoconf to produce a configure script.
9ed61c
 AC_PREREQ([2.69])
9ed61c
-m4_define([libsubid_abi_major], 2)
9ed61c
+m4_define([libsubid_abi_major], 3)
9ed61c
 m4_define([libsubid_abi_minor], 0)
9ed61c
 m4_define([libsubid_abi_micro], 0)
9ed61c
 m4_define([libsubid_abi], [libsubid_abi_major.libsubid_abi_minor.libsubid_abi_micro])
9ed61c
diff -up shadow-4.8.1/lib/prototypes.h.libsubid_simplify_ranges_variable shadow-4.8.1/lib/prototypes.h
9ed61c
--- shadow-4.8.1/lib/prototypes.h.libsubid_simplify_ranges_variable	2021-05-24 15:02:56.184917324 +0200
9ed61c
+++ shadow-4.8.1/lib/prototypes.h	2021-05-24 16:38:57.610619467 +0200
9ed61c
@@ -309,16 +309,15 @@ struct subid_nss_ops {
9ed61c
 	 *
9ed61c
 	 * @owner - string representing username being queried
9ed61c
 	 * @id_type - subuid or subgid
9ed61c
-	 * @ranges - pointer to an array of struct subordinate_range pointers, or
9ed61c
-	 *           NULL.  The returned array of struct subordinate_range and its
9ed61c
-	 *           members must be freed by the caller.
9ed61c
+	 * @ranges - pointer to an array of struct subid_range, or NULL.  The
9ed61c
+	 *           returned array must be freed by the caller.
9ed61c
 	 * @count - pointer to an integer into which the number of returned ranges
9ed61c
 	 *          is written.
9ed61c
 
9ed61c
 	 * returns success if the module was able to determine an answer,
9ed61c
 	 * else an error status.
9ed61c
 	 */
9ed61c
-	enum subid_status (*list_owner_ranges)(const char *owner, enum subid_type id_type, struct subordinate_range ***ranges, int *count);
9ed61c
+	enum subid_status (*list_owner_ranges)(const char *owner, enum subid_type id_type, struct subid_range **ranges, int *count);
9ed61c
 
9ed61c
 	/*
9ed61c
 	 * nss_find_subid_owners: find uids who own a given subuid or subgid.
9ed61c
diff -up shadow-4.8.1/libsubid/api.c.libsubid_simplify_ranges_variable shadow-4.8.1/libsubid/api.c
9ed61c
--- shadow-4.8.1/libsubid/api.c.libsubid_simplify_ranges_variable	2021-05-24 15:03:01.467989079 +0200
9ed61c
+++ shadow-4.8.1/libsubid/api.c	2021-05-24 16:42:32.091584531 +0200
9ed61c
@@ -68,26 +68,21 @@ bool libsubid_init(const char *progname,
9ed61c
 }
9ed61c
 
9ed61c
 static
9ed61c
-int get_subid_ranges(const char *owner, enum subid_type id_type, struct subordinate_range ***ranges)
9ed61c
+int get_subid_ranges(const char *owner, enum subid_type id_type, struct subid_range **ranges)
9ed61c
 {
9ed61c
 	return list_owner_ranges(owner, id_type, ranges);
9ed61c
 }
9ed61c
 
9ed61c
-int get_subuid_ranges(const char *owner, struct subordinate_range ***ranges)
9ed61c
+int get_subuid_ranges(const char *owner, struct subid_range **ranges)
9ed61c
 {
9ed61c
 	return get_subid_ranges(owner, ID_TYPE_UID, ranges);
9ed61c
 }
9ed61c
 
9ed61c
-int get_subgid_ranges(const char *owner, struct subordinate_range ***ranges)
9ed61c
+int get_subgid_ranges(const char *owner, struct subid_range **ranges)
9ed61c
 {
9ed61c
 	return get_subid_ranges(owner, ID_TYPE_GID, ranges);
9ed61c
 }
9ed61c
 
9ed61c
-void subid_free_ranges(struct subordinate_range **ranges, int count)
9ed61c
-{
9ed61c
-	return free_subordinate_ranges(ranges, count);
9ed61c
-}
9ed61c
-
9ed61c
 static
9ed61c
 int get_subid_owner(unsigned long id, enum subid_type id_type, uid_t **owner)
9ed61c
 {
9ed61c
diff -up shadow-4.8.1/libsubid/subid.h.libsubid_simplify_ranges_variable shadow-4.8.1/libsubid/subid.h
9ed61c
--- shadow-4.8.1/libsubid/subid.h.libsubid_simplify_ranges_variable	2021-05-24 15:03:01.468989093 +0200
9ed61c
+++ shadow-4.8.1/libsubid/subid.h	2021-05-24 16:43:49.697657383 +0200
9ed61c
@@ -3,6 +3,15 @@
9ed61c
 
9ed61c
 #ifndef SUBID_RANGE_DEFINED
9ed61c
 #define SUBID_RANGE_DEFINED 1
9ed61c
+
9ed61c
+/* subid_range is just a starting point and size of a range */
9ed61c
+struct subid_range {
9ed61c
+	unsigned long start;
9ed61c
+	unsigned long count;
9ed61c
+};
9ed61c
+
9ed61c
+/* subordinage_range is a subid_range plus an owner, representing
9ed61c
+ * a range in /etc/subuid or /etc/subgid */
9ed61c
 struct subordinate_range {
9ed61c
 	const char *owner;
9ed61c
 	unsigned long start;
9ed61c
@@ -41,32 +50,27 @@ bool libsubid_init(const char *progname,
9ed61c
  * get_subuid_ranges: return a list of UID ranges for a user
9ed61c
  *
9ed61c
  * @owner: username being queried
9ed61c
- * @ranges: a pointer to a subordinate range ** in which the result will be
9ed61c
- *          returned.
9ed61c
+ * @ranges: a pointer to an array of subid_range structs in which the result
9ed61c
+ *          will be returned.
9ed61c
+ *
9ed61c
+ * The caller must free(ranges) when done.
9ed61c
  *
9ed61c
  * returns: number of ranges found, ir < 0 on error.
9ed61c
  */
9ed61c
-int get_subuid_ranges(const char *owner, struct subordinate_range ***ranges);
9ed61c
+int get_subuid_ranges(const char *owner, struct subid_range **ranges);
9ed61c
 
9ed61c
 /*
9ed61c
  * get_subgid_ranges: return a list of GID ranges for a user
9ed61c
  *
9ed61c
  * @owner: username being queried
9ed61c
- * @ranges: a pointer to a subordinate range ** in which the result will be
9ed61c
- *          returned.
9ed61c
+ * @ranges: a pointer to an array of subid_range structs in which the result
9ed61c
+ *          will be returned.
9ed61c
  *
9ed61c
- * returns: number of ranges found, ir < 0 on error.
9ed61c
- */
9ed61c
-int get_subgid_ranges(const char *owner, struct subordinate_range ***ranges);
9ed61c
-
9ed61c
-/*
9ed61c
- * subid_free_ranges: free an array of subordinate_ranges returned by either
9ed61c
- *                    get_subuid_ranges() or get_subgid_ranges().
9ed61c
+ * The caller must free(ranges) when done.
9ed61c
  *
9ed61c
- * @ranges: the ranges to free
9ed61c
- * @count: the number of ranges in @ranges
9ed61c
+ * returns: number of ranges found, ir < 0 on error.
9ed61c
  */
9ed61c
-void subid_free_ranges(struct subordinate_range **ranges, int count);
9ed61c
+int get_subgid_ranges(const char *owner, struct subid_range **ranges);
9ed61c
 
9ed61c
 /*
9ed61c
  * get_subuid_owners: return a list of uids to which the given uid has been
9ed61c
diff -up shadow-4.8.1/lib/subordinateio.c.libsubid-simplify shadow-4.8.1/lib/subordinateio.c
9ed61c
--- shadow-4.8.1/lib/subordinateio.c.libsubid-simplify	2021-05-24 17:27:38.721035241 +0200
9ed61c
+++ shadow-4.8.1/lib/subordinateio.c	2021-05-24 17:28:06.481420946 +0200
9ed61c
@@ -11,6 +11,7 @@
9ed61c
 #include <stdio.h>
9ed61c
 #include "commonio.h"
9ed61c
 #include "subordinateio.h"
9ed61c
+#include "../libsubid/subid.h"
9ed61c
 #include <sys/types.h>
9ed61c
 #include <pwd.h>
9ed61c
 #include <ctype.h>
9ed61c
@@ -308,25 +309,21 @@ static bool have_range(struct commonio_d
9ed61c
 	return false;
9ed61c
 }
9ed61c
 
9ed61c
-static bool append_range(struct subordinate_range ***ranges, const struct subordinate_range *new, int n)
9ed61c
+static bool append_range(struct subid_range **ranges, const struct subordinate_range *new, int n)
9ed61c
 {
9ed61c
-	struct subordinate_range *tmp;
9ed61c
 	if (!*ranges) {
9ed61c
-		*ranges = malloc(sizeof(struct subordinate_range *));
9ed61c
+		*ranges = malloc(sizeof(struct subid_range));
9ed61c
 		if (!*ranges)
9ed61c
 			return false;
9ed61c
 	} else {
9ed61c
-		struct subordinate_range **new;
9ed61c
-		new = realloc(*ranges, (n + 1) * (sizeof(struct subordinate_range *)));
9ed61c
-		if (!new)
9ed61c
+		struct subid_range *alloced;
9ed61c
+		alloced = realloc(*ranges, (n + 1) * (sizeof(struct subid_range)));
9ed61c
+		if (!alloced)
9ed61c
 			return false;
9ed61c
-		*ranges = new;
9ed61c
+		*ranges = alloced;
9ed61c
 	}
9ed61c
-	(*ranges)[n] = NULL;
9ed61c
-	tmp = subordinate_dup(new);
9ed61c
-	if (!tmp)
9ed61c
-		return false;
9ed61c
-	(*ranges)[n] = tmp;
9ed61c
+	(*ranges)[n].start = new->start;
9ed61c
+	(*ranges)[n].count = new->count;
9ed61c
 	return true;
9ed61c
 }
9ed61c
 
9ed61c
@@ -785,10 +782,10 @@ gid_t sub_gid_find_free_range(gid_t min,
9ed61c
  *
9ed61c
  * The caller must free the subordinate range list.
9ed61c
  */
9ed61c
-int list_owner_ranges(const char *owner, enum subid_type id_type, struct subordinate_range ***in_ranges)
9ed61c
+int list_owner_ranges(const char *owner, enum subid_type id_type, struct subid_range **in_ranges)
9ed61c
 {
9ed61c
 	// TODO - need to handle owner being either uid or username
9ed61c
-	struct subordinate_range **ranges = NULL;
9ed61c
+	struct subid_range *ranges = NULL;
9ed61c
 	const struct subordinate_range *range;
9ed61c
 	struct commonio_db *db;
9ed61c
 	enum subid_status status;
9ed61c
@@ -826,7 +823,7 @@ int list_owner_ranges(const char *owner,
9ed61c
 	while ((range = commonio_next(db)) != NULL) {
9ed61c
 		if (0 == strcmp(range->owner, owner)) {
9ed61c
 			if (!append_range(&ranges, range, count++)) {
9ed61c
-				free_subordinate_ranges(ranges, count-1);
9ed61c
+				free(ranges);
9ed61c
 				ranges = NULL;
9ed61c
 				count = -1;
9ed61c
 				goto out;
9ed61c
diff -up shadow-4.8.1/lib/subordinateio.h.libsubid_simplify_ranges_variable shadow-4.8.1/lib/subordinateio.h
9ed61c
--- shadow-4.8.1/lib/subordinateio.h.libsubid_simplify_ranges_variable	2021-05-24 15:03:01.467989079 +0200
9ed61c
+++ shadow-4.8.1/lib/subordinateio.h	2021-05-24 16:40:56.978269647 +0200
9ed61c
@@ -25,7 +25,7 @@ extern int sub_uid_unlock (void);
9ed61c
 extern int sub_uid_add (const char *owner, uid_t start, unsigned long count);
9ed61c
 extern int sub_uid_remove (const char *owner, uid_t start, unsigned long count);
9ed61c
 extern uid_t sub_uid_find_free_range(uid_t min, uid_t max, unsigned long count);
9ed61c
-extern int list_owner_ranges(const char *owner, enum subid_type id_type, struct subordinate_range ***ranges);
9ed61c
+extern int list_owner_ranges(const char *owner, enum subid_type id_type, struct subid_range **ranges);
9ed61c
 extern bool new_subid_range(struct subordinate_range *range, enum subid_type id_type, bool reuse);
9ed61c
 extern bool release_subid_range(struct subordinate_range *range, enum subid_type id_type);
9ed61c
 extern int find_subid_owners(unsigned long id, enum subid_type id_type, uid_t **uids);
9ed61c
diff -up shadow-4.8.1/src/list_subid_ranges.c.libsubid_simplify_ranges_variable shadow-4.8.1/src/list_subid_ranges.c
9ed61c
--- shadow-4.8.1/src/list_subid_ranges.c.libsubid_simplify_ranges_variable	2021-05-24 15:03:01.468989093 +0200
9ed61c
+++ shadow-4.8.1/src/list_subid_ranges.c	2021-05-24 16:45:10.884779740 +0200
9ed61c
@@ -17,27 +17,29 @@ void usage(void)
9ed61c
 int main(int argc, char *argv[])
9ed61c
 {
9ed61c
 	int i, count=0;
9ed61c
-	struct subordinate_range **ranges;
9ed61c
+	struct subid_range *ranges;
9ed61c
+	const char *owner;
9ed61c
 
9ed61c
 	Prog = Basename (argv[0]);
9ed61c
 	shadow_logfd = stderr;
9ed61c
-	if (argc < 2) {
9ed61c
+	if (argc < 2)
9ed61c
 		usage();
9ed61c
-	}
9ed61c
-	if (argc == 3 && strcmp(argv[1], "-g") == 0)
9ed61c
-		count = get_subgid_ranges(argv[2], &ranges;;
9ed61c
-	else if (argc == 2 && strcmp(argv[1], "-h") == 0)
9ed61c
+	owner = argv[1];
9ed61c
+	if (argc == 3 && strcmp(argv[1], "-g") == 0) {
9ed61c
+		owner = argv[2];
9ed61c
+		count = get_subgid_ranges(owner, &ranges;;
9ed61c
+	} else if (argc == 2 && strcmp(argv[1], "-h") == 0) {
9ed61c
 		usage();
9ed61c
-	else
9ed61c
-		count = get_subuid_ranges(argv[1], &ranges;;
9ed61c
+	} else {
9ed61c
+		count = get_subuid_ranges(owner, &ranges;;
9ed61c
+	}
9ed61c
 	if (!ranges) {
9ed61c
 		fprintf(stderr, "Error fetching ranges\n");
9ed61c
 		exit(1);
9ed61c
 	}
9ed61c
 	for (i = 0; i < count; i++) {
9ed61c
-		printf("%d: %s %lu %lu\n", i, ranges[i]->owner,
9ed61c
-			ranges[i]->start, ranges[i]->count);
9ed61c
+		printf("%d: %s %lu %lu\n", i, owner,
9ed61c
+			ranges[i].start, ranges[i].count);
9ed61c
 	}
9ed61c
-	subid_free_ranges(ranges, count);
9ed61c
 	return 0;
9ed61c
 }
9ed61c
diff -up shadow-4.8.1/tests/libsubid/04_nss/libsubid_zzz.c.libsubid_simplify_ranges_variable shadow-4.8.1/tests/libsubid/04_nss/libsubid_zzz.c
9ed61c
--- shadow-4.8.1/tests/libsubid/04_nss/libsubid_zzz.c.libsubid_simplify_ranges_variable	2021-05-24 15:02:56.166917079 +0200
9ed61c
+++ shadow-4.8.1/tests/libsubid/04_nss/libsubid_zzz.c	2021-05-24 15:03:01.469989106 +0200
9ed61c
@@ -113,7 +113,7 @@ enum subid_status shadow_subid_list_owne
9ed61c
 	if (strcmp(owner, "conn") == 0)
9ed61c
 		return SUBID_STATUS_ERROR_CONN;
9ed61c
 
9ed61c
-	*ranges = NULL;
9ed61c
+	*in_ranges = NULL;
9ed61c
 	if (strcmp(owner, "user1") != 0 && strcmp(owner, "ubuntu") != 0 &&
9ed61c
 	    strcmp(owner, "group1") != 0)
9ed61c
 		return SUBID_STATUS_SUCCESS;