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