595b88
diff -up shadow-4.6/man/getsubids.1.xml.getsubids shadow-4.6/man/getsubids.1.xml
595b88
--- shadow-4.6/man/getsubids.1.xml.getsubids	2021-12-09 10:40:50.730275761 +0100
595b88
+++ shadow-4.6/man/getsubids.1.xml	2021-12-09 10:40:50.730275761 +0100
595b88
@@ -0,0 +1,141 @@
595b88
+
595b88
+
595b88
+   Copyright (c) 2021 Iker Pedrosa
595b88
+   All rights reserved.
595b88
+
595b88
+   Redistribution and use in source and binary forms, with or without
595b88
+   modification, are permitted provided that the following conditions
595b88
+   are met:
595b88
+   1. Redistributions of source code must retain the above copyright
595b88
+      notice, this list of conditions and the following disclaimer.
595b88
+   2. Redistributions in binary form must reproduce the above copyright
595b88
+      notice, this list of conditions and the following disclaimer in the
595b88
+      documentation and/or other materials provided with the distribution.
595b88
+   3. The name of the copyright holders or contributors may not be used to
595b88
+      endorse or promote products derived from this software without
595b88
+      specific prior written permission.
595b88
+
595b88
+   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
595b88
+   ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
595b88
+   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
595b88
+   PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT
595b88
+   HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
595b88
+   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
595b88
+   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
595b88
+   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
595b88
+   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
595b88
+   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
595b88
+   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
595b88
+-->
595b88
+
595b88
+  "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
595b88
+
595b88
+]>
595b88
+
595b88
+<refentry id='getsubids.1'>
595b88
+  <refentryinfo>
595b88
+    <author>
595b88
+      <firstname>Iker</firstname>
595b88
+      <surname>Pedrosa</surname>
595b88
+      <contrib>Creation, 2021</contrib>
595b88
+    </author>
595b88
+  </refentryinfo>
595b88
+  <refmeta>
595b88
+    <refentrytitle>getsubids</refentrytitle>
595b88
+    <manvolnum>1</manvolnum>
595b88
+    <refmiscinfo class="sectdesc">User Commands</refmiscinfo>
595b88
+    <refmiscinfo class="source">shadow-utils</refmiscinfo>
595b88
+    <refmiscinfo class="version">&SHADOW_UTILS_VERSION;</refmiscinfo>
595b88
+  </refmeta>
595b88
+  <refnamediv id='name'>
595b88
+    <refname>getsubids</refname>
595b88
+    <refpurpose>get the subordinate id ranges for a user</refpurpose>
595b88
+  </refnamediv>
595b88
+
595b88
+  <refsynopsisdiv id='synopsis'>
595b88
+    <cmdsynopsis>
595b88
+      <command>getsubids</command>
595b88
+      <arg choice='opt'>
595b88
+        <replaceable>options</replaceable>
595b88
+      </arg>
595b88
+      <arg choice='plain'>
595b88
+        <replaceable>USER</replaceable>
595b88
+      </arg>
595b88
+    </cmdsynopsis>
595b88
+  </refsynopsisdiv>
595b88
+
595b88
+  <refsect1 id='description'>
595b88
+    <title>DESCRIPTION</title>
595b88
+    <para>
595b88
+      The <command>getsubids</command> command lists the subordinate user ID
595b88
+      ranges for a given user. The subordinate group IDs can be listed using
595b88
+      the <option>-g</option> option.
595b88
+    </para>
595b88
+  </refsect1>
595b88
+
595b88
+  <refsect1 id='options'>
595b88
+    <title>OPTIONS</title>
595b88
+    <para>
595b88
+      The options which apply to the <command>getsubids</command> command are:
595b88
+    </para>
595b88
+    <variablelist remap='IP'>
595b88
+      <varlistentry>
595b88
+        <term>
595b88
+          <option>-g</option>
595b88
+        </term>
595b88
+        <listitem>
595b88
+          <para>
595b88
+            List the subordinate group ID ranges.
595b88
+          </para>
595b88
+        </listitem>
595b88
+      </varlistentry>
595b88
+    </variablelist>
595b88
+  </refsect1>
595b88
+
595b88
+  <refsect1 id='example'>
595b88
+    <title>EXAMPLE</title>
595b88
+    <para>
595b88
+      For example, to obtain the subordinate UIDs of the testuser:
595b88
+    </para>
595b88
+    <para>
595b88
+<programlisting>
595b88
+$ getsubids testuser
595b88
+0: testuser 100000 65536
595b88
+</programlisting>
595b88
+    </para>
595b88
+    <para>
595b88
+      This command output provides (in order from left to right) the list
595b88
+      index, username, UID range start, and number of UIDs in range.
595b88
+    </para>
595b88
+  </refsect1>
595b88
+
595b88
+  <refsect1 id='see_also'>
595b88
+    <title>SEE ALSO</title>
595b88
+    <para>
595b88
+      <citerefentry>
595b88
+        <refentrytitle>login.defs</refentrytitle><manvolnum>5</manvolnum>
595b88
+      </citerefentry>,
595b88
+      <citerefentry>
595b88
+        <refentrytitle>newgidmap</refentrytitle><manvolnum>1</manvolnum>
595b88
+      </citerefentry>,
595b88
+      <citerefentry>
595b88
+        <refentrytitle>newuidmap</refentrytitle><manvolnum>1</manvolnum>
595b88
+      </citerefentry>,
595b88
+      <citerefentry>
595b88
+        <refentrytitle>subgid</refentrytitle><manvolnum>5</manvolnum>
595b88
+      </citerefentry>,
595b88
+      <citerefentry>
595b88
+        <refentrytitle>subuid</refentrytitle><manvolnum>5</manvolnum>
595b88
+      </citerefentry>,
595b88
+      <citerefentry>
595b88
+        <refentrytitle>useradd</refentrytitle><manvolnum>8</manvolnum>
595b88
+      </citerefentry>,
595b88
+      <citerefentry>
595b88
+        <refentrytitle>userdel</refentrytitle><manvolnum>8</manvolnum>
595b88
+      </citerefentry>.
595b88
+      <citerefentry>
595b88
+        <refentrytitle>usermod</refentrytitle><manvolnum>8</manvolnum>
595b88
+      </citerefentry>,
595b88
+    </para>
595b88
+  </refsect1>
595b88
+</refentry>
595b88
diff -up shadow-4.6/man/Makefile.am.getsubids shadow-4.6/man/Makefile.am
595b88
--- shadow-4.6/man/Makefile.am.getsubids	2018-04-29 18:42:37.000000000 +0200
595b88
+++ shadow-4.6/man/Makefile.am	2021-12-09 10:40:50.730275761 +0100
595b88
@@ -59,6 +59,7 @@ man_MANS += $(man_nopam)
595b88
 endif
595b88
 
595b88
 man_subids = \
595b88
+	man1/getsubids.1 \
595b88
 	man1/newgidmap.1 \
595b88
 	man1/newuidmap.1 \
595b88
 	man5/subgid.5 \
595b88
@@ -77,6 +78,7 @@ man_XMANS = \
595b88
 	expiry.1.xml \
595b88
 	faillog.5.xml \
595b88
 	faillog.8.xml \
595b88
+	getsubids.1.xml \
595b88
 	gpasswd.1.xml \
595b88
 	groupadd.8.xml \
595b88
 	groupdel.8.xml \
595b88
diff -up shadow-4.6/src/getsubids.c.getsubids shadow-4.6/src/getsubids.c
595b88
--- shadow-4.6/src/getsubids.c.getsubids	2021-12-09 10:40:50.730275761 +0100
595b88
+++ shadow-4.6/src/getsubids.c	2021-12-09 10:40:50.730275761 +0100
595b88
@@ -0,0 +1,46 @@
595b88
+#include <stdio.h>
595b88
+#include <string.h>
595b88
+#include <stdlib.h>
595b88
+#include "subid.h"
595b88
+#include "prototypes.h"
595b88
+
595b88
+const char *Prog;
595b88
+FILE *shadow_logfd = NULL;
595b88
+
595b88
+void usage(void)
595b88
+{
595b88
+	fprintf(stderr, "Usage: %s [-g] user\n", Prog);
595b88
+	fprintf(stderr, "    list subuid ranges for user\n");
595b88
+	fprintf(stderr, "    pass -g to list subgid ranges\n");
595b88
+	exit(EXIT_FAILURE);
595b88
+}
595b88
+
595b88
+int main(int argc, char *argv[])
595b88
+{
595b88
+	int i, count=0;
595b88
+	struct subid_range *ranges;
595b88
+	const char *owner;
595b88
+
595b88
+	Prog = Basename (argv[0]);
595b88
+	shadow_logfd = stderr;
595b88
+	if (argc < 2)
595b88
+		usage();
595b88
+	owner = argv[1];
595b88
+	if (argc == 3 && strcmp(argv[1], "-g") == 0) {
595b88
+		owner = argv[2];
595b88
+		count = get_subgid_ranges(owner, &ranges;;
595b88
+	} else if (argc == 2 && strcmp(argv[1], "-h") == 0) {
595b88
+		usage();
595b88
+	} else {
595b88
+		count = get_subuid_ranges(owner, &ranges;;
595b88
+	}
595b88
+	if (!ranges) {
595b88
+		fprintf(stderr, "Error fetching ranges\n");
595b88
+		exit(1);
595b88
+	}
595b88
+	for (i = 0; i < count; i++) {
595b88
+		printf("%d: %s %lu %lu\n", i, owner,
595b88
+			ranges[i].start, ranges[i].count);
595b88
+	}
595b88
+	return 0;
595b88
+}
595b88
diff -up shadow-4.6/src/Makefile.am.getsubids shadow-4.6/src/Makefile.am
595b88
--- shadow-4.6/src/Makefile.am.getsubids	2021-12-09 10:40:50.710275627 +0100
595b88
+++ shadow-4.6/src/Makefile.am	2021-12-09 10:45:04.465985510 +0100
595b88
@@ -140,8 +140,8 @@ if WITH_TCB
595b88
 endif
595b88
 
595b88
 if ENABLE_SUBIDS
595b88
-noinst_PROGRAMS += list_subid_ranges  \
595b88
-					get_subid_owners \
595b88
+bin_PROGRAMS    +=  getsubids
595b88
+noinst_PROGRAMS +=  get_subid_owners \
595b88
 					new_subid_range \
595b88
 					free_subid_range \
595b88
 					check_subid_range
595b88
@@ -156,13 +156,13 @@ MISCLIBS = \
595b88
 	$(LIBCRYPT) \
595b88
 	$(LIBTCB)
595b88
 
595b88
-list_subid_ranges_LDADD = \
595b88
+getsubids_LDADD = \
595b88
 	$(top_builddir)/lib/libshadow.la \
595b88
 	$(top_builddir)/libmisc/libmisc.la \
595b88
 	$(top_builddir)/libsubid/libsubid.la \
595b88
 	$(MISCLIBS) -ldl
595b88
 
595b88
-list_subid_ranges_CPPFLAGS = \
595b88
+getsubids_CPPFLAGS = \
595b88
 	-I$(top_srcdir)/lib \
595b88
 	-I$(top_srcdir)/libmisc \
595b88
 	-I$(top_srcdir)/libsubid