Blame SOURCES/shadow-4.6-getsubids.patch

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