|
|
9ed61c |
diff -up shadow-4.6/configure.ac.libsubid_creation shadow-4.6/configure.ac
|
|
|
9ed61c |
--- shadow-4.6/configure.ac.libsubid_creation 2021-10-19 16:12:02.663748272 +0200
|
|
|
9ed61c |
+++ shadow-4.6/configure.ac 2021-10-19 16:13:07.194697194 +0200
|
|
|
9ed61c |
@@ -1,11 +1,21 @@
|
|
|
9ed61c |
dnl Process this file with autoconf to produce a configure script.
|
|
|
9ed61c |
-AC_PREREQ([2.64])
|
|
|
9ed61c |
+AC_PREREQ([2.69])
|
|
|
9ed61c |
+m4_define([libsubid_abi_major], 1)
|
|
|
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 |
AC_INIT([shadow], [4.6], [pkg-shadow-devel@lists.alioth.debian.org], [],
|
|
|
9ed61c |
[https://github.com/shadow-maint/shadow])
|
|
|
9ed61c |
AM_INIT_AUTOMAKE([1.11 foreign dist-xz])
|
|
|
9ed61c |
+AC_CONFIG_MACRO_DIRS([m4])
|
|
|
9ed61c |
AM_SILENT_RULES([yes])
|
|
|
9ed61c |
AC_CONFIG_HEADERS([config.h])
|
|
|
9ed61c |
|
|
|
9ed61c |
+AC_SUBST([LIBSUBID_ABI_MAJOR], [libsubid_abi_major])
|
|
|
9ed61c |
+AC_SUBST([LIBSUBID_ABI_MINOR], [libsubid_abi_minor])
|
|
|
9ed61c |
+AC_SUBST([LIBSUBID_ABI_MICRO], [libsubid_abi_micro])
|
|
|
9ed61c |
+AC_SUBST([LIBSUBID_ABI], [libsubid_abi])
|
|
|
9ed61c |
+
|
|
|
9ed61c |
dnl Some hacks...
|
|
|
9ed61c |
test "$prefix" = "NONE" && prefix="/usr"
|
|
|
9ed61c |
test "$prefix" = "/usr" && exec_prefix=""
|
|
|
9ed61c |
@@ -22,8 +22,8 @@ test "$prefix" = "/usr" && exec_prefix=""
|
|
|
9ed61c |
|
|
|
9ed61c |
AC_GNU_SOURCE
|
|
|
9ed61c |
|
|
|
9ed61c |
-AM_DISABLE_SHARED
|
|
|
9ed61c |
AM_ENABLE_STATIC
|
|
|
9ed61c |
+AM_ENABLE_SHARED
|
|
|
9ed61c |
|
|
|
9ed61c |
AM_MAINTAINER_MODE
|
|
|
9ed61c |
|
|
|
9ed61c |
@@ -725,6 +725,7 @@ AC_CONFIG_FILES([
|
|
|
9ed61c |
man/zh_TW/Makefile
|
|
|
9ed61c |
libmisc/Makefile
|
|
|
9ed61c |
lib/Makefile
|
|
|
9ed61c |
+ libsubid/Makefile
|
|
|
9ed61c |
src/Makefile
|
|
|
9ed61c |
contrib/Makefile
|
|
|
9ed61c |
etc/Makefile
|
|
|
9ed61c |
diff -up shadow-4.6/libsubid/api.c.libsubid_creation shadow-4.6/libsubid/api.c
|
|
|
9ed61c |
--- shadow-4.6/libsubid/api.c.libsubid_creation 2021-10-19 16:12:02.661748243 +0200
|
|
|
9ed61c |
+++ shadow-4.6/libsubid/api.c 2021-10-19 16:12:02.661748243 +0200
|
|
|
9ed61c |
@@ -0,0 +1,231 @@
|
|
|
9ed61c |
+/*
|
|
|
9ed61c |
+ * Copyright (c) 2020 Serge Hallyn
|
|
|
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 |
+#include <config.h>
|
|
|
9ed61c |
+#include <fcntl.h>
|
|
|
9ed61c |
+#include <stdio.h>
|
|
|
9ed61c |
+#include <errno.h>
|
|
|
9ed61c |
+#include <stdlib.h>
|
|
|
9ed61c |
+#include <pwd.h>
|
|
|
9ed61c |
+#include <stdbool.h>
|
|
|
9ed61c |
+#include "subordinateio.h"
|
|
|
9ed61c |
+#include "idmapping.h"
|
|
|
9ed61c |
+#include "api.h"
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+static struct subordinate_range **get_subid_ranges(const char *owner, enum subid_type id_type)
|
|
|
9ed61c |
+{
|
|
|
9ed61c |
+ struct subordinate_range **ranges = NULL;
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+ switch (id_type) {
|
|
|
9ed61c |
+ case ID_TYPE_UID:
|
|
|
9ed61c |
+ if (!sub_uid_open(O_RDONLY)) {
|
|
|
9ed61c |
+ return NULL;
|
|
|
9ed61c |
+ }
|
|
|
9ed61c |
+ break;
|
|
|
9ed61c |
+ case ID_TYPE_GID:
|
|
|
9ed61c |
+ if (!sub_gid_open(O_RDONLY)) {
|
|
|
9ed61c |
+ return NULL;
|
|
|
9ed61c |
+ }
|
|
|
9ed61c |
+ break;
|
|
|
9ed61c |
+ default:
|
|
|
9ed61c |
+ return NULL;
|
|
|
9ed61c |
+ }
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+ ranges = list_owner_ranges(owner, id_type);
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+ if (id_type == ID_TYPE_UID)
|
|
|
9ed61c |
+ sub_uid_close();
|
|
|
9ed61c |
+ else
|
|
|
9ed61c |
+ sub_gid_close();
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+ return ranges;
|
|
|
9ed61c |
+}
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+struct subordinate_range **get_subuid_ranges(const char *owner)
|
|
|
9ed61c |
+{
|
|
|
9ed61c |
+ return get_subid_ranges(owner, ID_TYPE_UID);
|
|
|
9ed61c |
+}
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+struct subordinate_range **get_subgid_ranges(const char *owner)
|
|
|
9ed61c |
+{
|
|
|
9ed61c |
+ return get_subid_ranges(owner, ID_TYPE_GID);
|
|
|
9ed61c |
+}
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+void subid_free_ranges(struct subordinate_range **ranges)
|
|
|
9ed61c |
+{
|
|
|
9ed61c |
+ return free_subordinate_ranges(ranges);
|
|
|
9ed61c |
+}
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+int get_subid_owner(unsigned long id, uid_t **owner, enum subid_type id_type)
|
|
|
9ed61c |
+{
|
|
|
9ed61c |
+ int ret = -1;
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+ switch (id_type) {
|
|
|
9ed61c |
+ case ID_TYPE_UID:
|
|
|
9ed61c |
+ if (!sub_uid_open(O_RDONLY)) {
|
|
|
9ed61c |
+ return -1;
|
|
|
9ed61c |
+ }
|
|
|
9ed61c |
+ break;
|
|
|
9ed61c |
+ case ID_TYPE_GID:
|
|
|
9ed61c |
+ if (!sub_gid_open(O_RDONLY)) {
|
|
|
9ed61c |
+ return -1;
|
|
|
9ed61c |
+ }
|
|
|
9ed61c |
+ break;
|
|
|
9ed61c |
+ default:
|
|
|
9ed61c |
+ return -1;
|
|
|
9ed61c |
+ }
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+ ret = find_subid_owners(id, owner, id_type);
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+ if (id_type == ID_TYPE_UID)
|
|
|
9ed61c |
+ sub_uid_close();
|
|
|
9ed61c |
+ else
|
|
|
9ed61c |
+ sub_gid_close();
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+ return ret;
|
|
|
9ed61c |
+}
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+int get_subuid_owners(uid_t uid, uid_t **owner)
|
|
|
9ed61c |
+{
|
|
|
9ed61c |
+ return get_subid_owner((unsigned long)uid, owner, ID_TYPE_UID);
|
|
|
9ed61c |
+}
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+int get_subgid_owners(gid_t gid, uid_t **owner)
|
|
|
9ed61c |
+{
|
|
|
9ed61c |
+ return get_subid_owner((unsigned long)gid, owner, ID_TYPE_GID);
|
|
|
9ed61c |
+}
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+bool grant_subid_range(struct subordinate_range *range, bool reuse,
|
|
|
9ed61c |
+ enum subid_type id_type)
|
|
|
9ed61c |
+{
|
|
|
9ed61c |
+ bool ret;
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+ switch (id_type) {
|
|
|
9ed61c |
+ case ID_TYPE_UID:
|
|
|
9ed61c |
+ if (!sub_uid_lock()) {
|
|
|
9ed61c |
+ printf("Failed loging subuids (errno %d)\n", errno);
|
|
|
9ed61c |
+ return false;
|
|
|
9ed61c |
+ }
|
|
|
9ed61c |
+ if (!sub_uid_open(O_CREAT | O_RDWR)) {
|
|
|
9ed61c |
+ printf("Failed opening subuids (errno %d)\n", errno);
|
|
|
9ed61c |
+ sub_uid_unlock();
|
|
|
9ed61c |
+ return false;
|
|
|
9ed61c |
+ }
|
|
|
9ed61c |
+ break;
|
|
|
9ed61c |
+ case ID_TYPE_GID:
|
|
|
9ed61c |
+ if (!sub_gid_lock()) {
|
|
|
9ed61c |
+ printf("Failed loging subgids (errno %d)\n", errno);
|
|
|
9ed61c |
+ return false;
|
|
|
9ed61c |
+ }
|
|
|
9ed61c |
+ if (!sub_gid_open(O_CREAT | O_RDWR)) {
|
|
|
9ed61c |
+ printf("Failed opening subgids (errno %d)\n", errno);
|
|
|
9ed61c |
+ sub_gid_unlock();
|
|
|
9ed61c |
+ return false;
|
|
|
9ed61c |
+ }
|
|
|
9ed61c |
+ break;
|
|
|
9ed61c |
+ default:
|
|
|
9ed61c |
+ return false;
|
|
|
9ed61c |
+ }
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+ ret = new_subid_range(range, id_type, reuse);
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+ if (id_type == ID_TYPE_UID) {
|
|
|
9ed61c |
+ sub_uid_close();
|
|
|
9ed61c |
+ sub_uid_unlock();
|
|
|
9ed61c |
+ } else {
|
|
|
9ed61c |
+ sub_gid_close();
|
|
|
9ed61c |
+ sub_gid_unlock();
|
|
|
9ed61c |
+ }
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+ return ret;
|
|
|
9ed61c |
+}
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+bool grant_subuid_range(struct subordinate_range *range, bool reuse)
|
|
|
9ed61c |
+{
|
|
|
9ed61c |
+ return grant_subid_range(range, reuse, ID_TYPE_UID);
|
|
|
9ed61c |
+}
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+bool grant_subgid_range(struct subordinate_range *range, bool reuse)
|
|
|
9ed61c |
+{
|
|
|
9ed61c |
+ return grant_subid_range(range, reuse, ID_TYPE_GID);
|
|
|
9ed61c |
+}
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+bool free_subid_range(struct subordinate_range *range, enum subid_type id_type)
|
|
|
9ed61c |
+{
|
|
|
9ed61c |
+ bool ret;
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+ switch (id_type) {
|
|
|
9ed61c |
+ case ID_TYPE_UID:
|
|
|
9ed61c |
+ if (!sub_uid_lock()) {
|
|
|
9ed61c |
+ printf("Failed loging subuids (errno %d)\n", errno);
|
|
|
9ed61c |
+ return false;
|
|
|
9ed61c |
+ }
|
|
|
9ed61c |
+ if (!sub_uid_open(O_CREAT | O_RDWR)) {
|
|
|
9ed61c |
+ printf("Failed opening subuids (errno %d)\n", errno);
|
|
|
9ed61c |
+ sub_uid_unlock();
|
|
|
9ed61c |
+ return false;
|
|
|
9ed61c |
+ }
|
|
|
9ed61c |
+ break;
|
|
|
9ed61c |
+ case ID_TYPE_GID:
|
|
|
9ed61c |
+ if (!sub_gid_lock()) {
|
|
|
9ed61c |
+ printf("Failed loging subgids (errno %d)\n", errno);
|
|
|
9ed61c |
+ return false;
|
|
|
9ed61c |
+ }
|
|
|
9ed61c |
+ if (!sub_gid_open(O_CREAT | O_RDWR)) {
|
|
|
9ed61c |
+ printf("Failed opening subgids (errno %d)\n", errno);
|
|
|
9ed61c |
+ sub_gid_unlock();
|
|
|
9ed61c |
+ return false;
|
|
|
9ed61c |
+ }
|
|
|
9ed61c |
+ break;
|
|
|
9ed61c |
+ default:
|
|
|
9ed61c |
+ return false;
|
|
|
9ed61c |
+ }
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+ ret = release_subid_range(range, id_type);
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+ if (id_type == ID_TYPE_UID) {
|
|
|
9ed61c |
+ sub_uid_close();
|
|
|
9ed61c |
+ sub_uid_unlock();
|
|
|
9ed61c |
+ } else {
|
|
|
9ed61c |
+ sub_gid_close();
|
|
|
9ed61c |
+ sub_gid_unlock();
|
|
|
9ed61c |
+ }
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+ return ret;
|
|
|
9ed61c |
+}
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+bool free_subuid_range(struct subordinate_range *range)
|
|
|
9ed61c |
+{
|
|
|
9ed61c |
+ return free_subid_range(range, ID_TYPE_UID);
|
|
|
9ed61c |
+}
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+bool free_subgid_range(struct subordinate_range *range)
|
|
|
9ed61c |
+{
|
|
|
9ed61c |
+ return free_subid_range(range, ID_TYPE_GID);
|
|
|
9ed61c |
+}
|
|
|
9ed61c |
diff -up shadow-4.6/libsubid/api.h.libsubid_creation shadow-4.6/libsubid/api.h
|
|
|
9ed61c |
--- shadow-4.6/libsubid/api.h.libsubid_creation 2021-10-19 16:12:02.661748243 +0200
|
|
|
9ed61c |
+++ shadow-4.6/libsubid/api.h 2021-10-19 16:12:02.662748257 +0200
|
|
|
9ed61c |
@@ -0,0 +1,17 @@
|
|
|
9ed61c |
+#include "subid.h"
|
|
|
9ed61c |
+#include <stdbool.h>
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+struct subordinate_range **get_subuid_ranges(const char *owner);
|
|
|
9ed61c |
+struct subordinate_range **get_subgid_ranges(const char *owner);
|
|
|
9ed61c |
+void subid_free_ranges(struct subordinate_range **ranges);
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+int get_subuid_owners(uid_t uid, uid_t **owner);
|
|
|
9ed61c |
+int get_subgid_owners(gid_t gid, uid_t **owner);
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+/* range should be pre-allocated with owner and count filled in, start is
|
|
|
9ed61c |
+ * ignored, can be 0 */
|
|
|
9ed61c |
+bool grant_subuid_range(struct subordinate_range *range, bool reuse);
|
|
|
9ed61c |
+bool grant_subgid_range(struct subordinate_range *range, bool reuse);
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+bool free_subuid_range(struct subordinate_range *range);
|
|
|
9ed61c |
+bool free_subgid_range(struct subordinate_range *range);
|
|
|
9ed61c |
diff -up shadow-4.6/libsubid/Makefile.am.libsubid_creation shadow-4.6/libsubid/Makefile.am
|
|
|
9ed61c |
--- shadow-4.6/libsubid/Makefile.am.libsubid_creation 2021-10-19 16:12:02.661748243 +0200
|
|
|
9ed61c |
+++ shadow-4.6/libsubid/Makefile.am 2021-10-19 16:12:02.662748257 +0200
|
|
|
9ed61c |
@@ -0,0 +1,24 @@
|
|
|
9ed61c |
+lib_LTLIBRARIES = libsubid.la
|
|
|
9ed61c |
+libsubid_la_LDFLAGS = -Wl,-soname,libsubid.so.@LIBSUBID_ABI@ \
|
|
|
9ed61c |
+ -shared -version-info @LIBSUBID_ABI_MAJOR@
|
|
|
9ed61c |
+libsubid_la_SOURCES = api.c
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+MISCLIBS = \
|
|
|
9ed61c |
+ $(LIBAUDIT) \
|
|
|
9ed61c |
+ $(LIBSELINUX) \
|
|
|
9ed61c |
+ $(LIBSEMANAGE) \
|
|
|
9ed61c |
+ $(LIBCRYPT_NOPAM) \
|
|
|
9ed61c |
+ $(LIBSKEY) \
|
|
|
9ed61c |
+ $(LIBMD) \
|
|
|
9ed61c |
+ $(LIBCRYPT) \
|
|
|
9ed61c |
+ $(LIBTCB)
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+libsubid_la_LIBADD = \
|
|
|
9ed61c |
+ $(top_srcdir)/lib/libshadow.la \
|
|
|
9ed61c |
+ $(MISCLIBS) \
|
|
|
9ed61c |
+ $(top_srcdir)/libmisc/libmisc.a
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+AM_CPPFLAGS = \
|
|
|
9ed61c |
+ -I${top_srcdir}/lib \
|
|
|
9ed61c |
+ -I${top_srcdir}/libmisc \
|
|
|
9ed61c |
+ -DLOCALEDIR=\"$(datadir)/locale\"
|
|
|
9ed61c |
diff -up shadow-4.6/libsubid/subid.h.libsubid_creation shadow-4.6/libsubid/subid.h
|
|
|
9ed61c |
--- shadow-4.6/libsubid/subid.h.libsubid_creation 2021-10-19 16:12:02.661748243 +0200
|
|
|
9ed61c |
+++ shadow-4.6/libsubid/subid.h 2021-10-19 16:12:02.661748243 +0200
|
|
|
9ed61c |
@@ -0,0 +1,17 @@
|
|
|
9ed61c |
+#include <sys/types.h>
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+#ifndef SUBID_RANGE_DEFINED
|
|
|
9ed61c |
+#define SUBID_RANGE_DEFINED 1
|
|
|
9ed61c |
+struct subordinate_range {
|
|
|
9ed61c |
+ const char *owner;
|
|
|
9ed61c |
+ unsigned long start;
|
|
|
9ed61c |
+ unsigned long count;
|
|
|
9ed61c |
+};
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+enum subid_type {
|
|
|
9ed61c |
+ ID_TYPE_UID = 1,
|
|
|
9ed61c |
+ ID_TYPE_GID = 2
|
|
|
9ed61c |
+};
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+#define SUBID_NFIELDS 3
|
|
|
9ed61c |
+#endif
|
|
|
9ed61c |
diff -up shadow-4.6/lib/subordinateio.c.libsubid_creation shadow-4.6/lib/subordinateio.c
|
|
|
9ed61c |
--- shadow-4.6/lib/subordinateio.c.libsubid_creation 2021-10-19 16:12:02.654748139 +0200
|
|
|
9ed61c |
+++ shadow-4.6/lib/subordinateio.c 2021-10-19 16:12:02.661748243 +0200
|
|
|
9ed61c |
@@ -13,14 +13,7 @@
|
|
|
9ed61c |
#include "subordinateio.h"
|
|
|
9ed61c |
#include <sys/types.h>
|
|
|
9ed61c |
#include <pwd.h>
|
|
|
9ed61c |
-
|
|
|
9ed61c |
-struct subordinate_range {
|
|
|
9ed61c |
- const char *owner;
|
|
|
9ed61c |
- unsigned long start;
|
|
|
9ed61c |
- unsigned long count;
|
|
|
9ed61c |
-};
|
|
|
9ed61c |
-
|
|
|
9ed61c |
-#define NFIELDS 3
|
|
|
9ed61c |
+#include <ctype.h>
|
|
|
9ed61c |
|
|
|
9ed61c |
/*
|
|
|
9ed61c |
* subordinate_dup: create a duplicate range
|
|
|
9ed61c |
@@ -78,7 +71,7 @@ static void *subordinate_parse (const ch
|
|
|
9ed61c |
static char rangebuf[1024];
|
|
|
9ed61c |
int i;
|
|
|
9ed61c |
char *cp;
|
|
|
9ed61c |
- char *fields[NFIELDS];
|
|
|
9ed61c |
+ char *fields[SUBID_NFIELDS];
|
|
|
9ed61c |
|
|
|
9ed61c |
/*
|
|
|
9ed61c |
* Copy the string to a temporary buffer so the substrings can
|
|
|
9ed61c |
@@ -93,7 +86,7 @@ static void *subordinate_parse (const ch
|
|
|
9ed61c |
* field. The fields are converted into NUL terminated strings.
|
|
|
9ed61c |
*/
|
|
|
9ed61c |
|
|
|
9ed61c |
- for (cp = rangebuf, i = 0; (i < NFIELDS) && (NULL != cp); i++) {
|
|
|
9ed61c |
+ for (cp = rangebuf, i = 0; (i < SUBID_NFIELDS) && (NULL != cp); i++) {
|
|
|
9ed61c |
fields[i] = cp;
|
|
|
9ed61c |
while (('\0' != *cp) && (':' != *cp)) {
|
|
|
9ed61c |
cp++;
|
|
|
9ed61c |
@@ -108,10 +101,10 @@ static void *subordinate_parse (const ch
|
|
|
9ed61c |
}
|
|
|
9ed61c |
|
|
|
9ed61c |
/*
|
|
|
9ed61c |
- * There must be exactly NFIELDS colon separated fields or
|
|
|
9ed61c |
+ * There must be exactly SUBID_NFIELDS colon separated fields or
|
|
|
9ed61c |
* the entry is invalid. Also, fields must be non-blank.
|
|
|
9ed61c |
*/
|
|
|
9ed61c |
- if (i != NFIELDS || *fields[0] == '\0' || *fields[1] == '\0' || *fields[2] == '\0')
|
|
|
9ed61c |
+ if (i != SUBID_NFIELDS || *fields[0] == '\0' || *fields[1] == '\0' || *fields[2] == '\0')
|
|
|
9ed61c |
return NULL;
|
|
|
9ed61c |
range.owner = fields[0];
|
|
|
9ed61c |
if (getulong (fields[1], &range.start) == 0)
|
|
|
9ed61c |
@@ -319,6 +312,39 @@ 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 |
+{
|
|
|
9ed61c |
+ struct subordinate_range *tmp;
|
|
|
9ed61c |
+ if (!*ranges) {
|
|
|
9ed61c |
+ *ranges = malloc(2 * sizeof(struct subordinate_range **));
|
|
|
9ed61c |
+ if (!*ranges)
|
|
|
9ed61c |
+ return false;
|
|
|
9ed61c |
+ } else {
|
|
|
9ed61c |
+ struct subordinate_range **new;
|
|
|
9ed61c |
+ new = realloc(*ranges, (n + 2) * (sizeof(struct subordinate_range **)));
|
|
|
9ed61c |
+ if (!new)
|
|
|
9ed61c |
+ return false;
|
|
|
9ed61c |
+ *ranges = new;
|
|
|
9ed61c |
+ }
|
|
|
9ed61c |
+ (*ranges)[n] = (*ranges)[n+1] = NULL;
|
|
|
9ed61c |
+ tmp = subordinate_dup(new);
|
|
|
9ed61c |
+ if (!tmp)
|
|
|
9ed61c |
+ return false;
|
|
|
9ed61c |
+ (*ranges)[n] = tmp;
|
|
|
9ed61c |
+ return true;
|
|
|
9ed61c |
+}
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+void free_subordinate_ranges(struct subordinate_range **ranges)
|
|
|
9ed61c |
+{
|
|
|
9ed61c |
+ int i;
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+ if (!ranges)
|
|
|
9ed61c |
+ return;
|
|
|
9ed61c |
+ for (i = 0; ranges[i]; i++)
|
|
|
9ed61c |
+ subordinate_free(ranges[i]);
|
|
|
9ed61c |
+ free(ranges);
|
|
|
9ed61c |
+}
|
|
|
9ed61c |
+
|
|
|
9ed61c |
/*
|
|
|
9ed61c |
* subordinate_range_cmp: compare uid ranges
|
|
|
9ed61c |
*
|
|
|
9ed61c |
@@ -697,6 +723,160 @@ gid_t sub_gid_find_free_range(gid_t min,
|
|
|
9ed61c |
start = find_free_range (&subordinate_gid_db, min, max, count);
|
|
|
9ed61c |
return start == ULONG_MAX ? (gid_t) -1 : start;
|
|
|
9ed61c |
}
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+/*
|
|
|
9ed61c |
+ struct subordinate_range **list_owner_ranges(const char *owner, enum subid_type id_type)
|
|
|
9ed61c |
+ *
|
|
|
9ed61c |
+ * @owner: username
|
|
|
9ed61c |
+ * @id_type: UID or GUID
|
|
|
9ed61c |
+ *
|
|
|
9ed61c |
+ * Returns the subuid or subgid ranges which are owned by the specified
|
|
|
9ed61c |
+ * user. Username may be a username or a string representation of a
|
|
|
9ed61c |
+ * UID number. If id_type is UID, then subuids are returned, else
|
|
|
9ed61c |
+ * subgids are returned. If there is an error, < 0 is returned.
|
|
|
9ed61c |
+ *
|
|
|
9ed61c |
+ * The caller must free the subordinate range list.
|
|
|
9ed61c |
+ */
|
|
|
9ed61c |
+struct subordinate_range **list_owner_ranges(const char *owner, enum subid_type id_type)
|
|
|
9ed61c |
+{
|
|
|
9ed61c |
+ // TODO - need to handle owner being either uid or username
|
|
|
9ed61c |
+ const struct subordinate_range *range;
|
|
|
9ed61c |
+ struct subordinate_range **ranges = NULL;
|
|
|
9ed61c |
+ struct commonio_db *db;
|
|
|
9ed61c |
+ int size = 0;
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+ if (id_type == ID_TYPE_UID)
|
|
|
9ed61c |
+ db = &subordinate_uid_db;
|
|
|
9ed61c |
+ else
|
|
|
9ed61c |
+ db = &subordinate_gid_db;
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+ commonio_rewind(db);
|
|
|
9ed61c |
+ while ((range = commonio_next(db)) != NULL) {
|
|
|
9ed61c |
+ if (0 == strcmp(range->owner, owner)) {
|
|
|
9ed61c |
+ if (!append_range(&ranges, range, size++)) {
|
|
|
9ed61c |
+ free_subordinate_ranges(ranges);
|
|
|
9ed61c |
+ return NULL;
|
|
|
9ed61c |
+ }
|
|
|
9ed61c |
+ }
|
|
|
9ed61c |
+ }
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+ return ranges;
|
|
|
9ed61c |
+}
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+static bool all_digits(const char *str)
|
|
|
9ed61c |
+{
|
|
|
9ed61c |
+ int i;
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+ for (i = 0; str[i] != '\0'; i++)
|
|
|
9ed61c |
+ if (!isdigit(str[i]))
|
|
|
9ed61c |
+ return false;
|
|
|
9ed61c |
+ return true;
|
|
|
9ed61c |
+}
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+static int append_uids(uid_t **uids, const char *owner, int n)
|
|
|
9ed61c |
+{
|
|
|
9ed61c |
+ uid_t owner_uid;
|
|
|
9ed61c |
+ uid_t *ret;
|
|
|
9ed61c |
+ int i;
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+ if (all_digits(owner)) {
|
|
|
9ed61c |
+ i = sscanf(owner, "%d", &owner_uid);
|
|
|
9ed61c |
+ if (i != 1) {
|
|
|
9ed61c |
+ // should not happen
|
|
|
9ed61c |
+ free(*uids);
|
|
|
9ed61c |
+ *uids = NULL;
|
|
|
9ed61c |
+ return -1;
|
|
|
9ed61c |
+ }
|
|
|
9ed61c |
+ } else {
|
|
|
9ed61c |
+ struct passwd *pwd = getpwnam(owner);
|
|
|
9ed61c |
+ if (NULL == pwd) {
|
|
|
9ed61c |
+ /* Username not defined in /etc/passwd, or error occured during lookup */
|
|
|
9ed61c |
+ free(*uids);
|
|
|
9ed61c |
+ *uids = NULL;
|
|
|
9ed61c |
+ return -1;
|
|
|
9ed61c |
+ }
|
|
|
9ed61c |
+ owner_uid = pwd->pw_uid;
|
|
|
9ed61c |
+ }
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+ for (i = 0; i < n; i++) {
|
|
|
9ed61c |
+ if (owner_uid == (*uids)[i])
|
|
|
9ed61c |
+ return n;
|
|
|
9ed61c |
+ }
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+ ret = realloc(*uids, (n + 1) * sizeof(uid_t));
|
|
|
9ed61c |
+ if (!ret) {
|
|
|
9ed61c |
+ free(*uids);
|
|
|
9ed61c |
+ return -1;
|
|
|
9ed61c |
+ }
|
|
|
9ed61c |
+ ret[n] = owner_uid;
|
|
|
9ed61c |
+ *uids = ret;
|
|
|
9ed61c |
+ return n+1;
|
|
|
9ed61c |
+}
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+int find_subid_owners(unsigned long id, uid_t **uids, enum subid_type id_type)
|
|
|
9ed61c |
+{
|
|
|
9ed61c |
+ const struct subordinate_range *range;
|
|
|
9ed61c |
+ struct commonio_db *db;
|
|
|
9ed61c |
+ int n = 0;
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+ *uids = NULL;
|
|
|
9ed61c |
+ if (id_type == ID_TYPE_UID)
|
|
|
9ed61c |
+ db = &subordinate_uid_db;
|
|
|
9ed61c |
+ else
|
|
|
9ed61c |
+ db = &subordinate_gid_db;
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+ commonio_rewind(db);
|
|
|
9ed61c |
+ while ((range = commonio_next(db)) != NULL) {
|
|
|
9ed61c |
+ if (id >= range->start && id < range->start + range-> count) {
|
|
|
9ed61c |
+ n = append_uids(uids, range->owner, n);
|
|
|
9ed61c |
+ if (n < 0)
|
|
|
9ed61c |
+ break;
|
|
|
9ed61c |
+ }
|
|
|
9ed61c |
+ }
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+ return n;
|
|
|
9ed61c |
+}
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+bool new_subid_range(struct subordinate_range *range, enum subid_type id_type, bool reuse)
|
|
|
9ed61c |
+{
|
|
|
9ed61c |
+ struct commonio_db *db;
|
|
|
9ed61c |
+ const struct subordinate_range *r;
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+ if (id_type == ID_TYPE_UID)
|
|
|
9ed61c |
+ db = &subordinate_uid_db;
|
|
|
9ed61c |
+ else
|
|
|
9ed61c |
+ db = &subordinate_gid_db;
|
|
|
9ed61c |
+ commonio_rewind(db);
|
|
|
9ed61c |
+ if (reuse) {
|
|
|
9ed61c |
+ while ((r = commonio_next(db)) != NULL) {
|
|
|
9ed61c |
+ // TODO account for username vs uid_t
|
|
|
9ed61c |
+ if (0 != strcmp(r->owner, range->owner))
|
|
|
9ed61c |
+ continue;
|
|
|
9ed61c |
+ if (r->count >= range->count) {
|
|
|
9ed61c |
+ range->count = r->count;
|
|
|
9ed61c |
+ range->start = r->start;
|
|
|
9ed61c |
+ return true;
|
|
|
9ed61c |
+ }
|
|
|
9ed61c |
+ }
|
|
|
9ed61c |
+ }
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+ range->start = find_free_range(db, range->start, ULONG_MAX, range->count);
|
|
|
9ed61c |
+ if (range->start == ULONG_MAX)
|
|
|
9ed61c |
+ return false;
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+ return add_range(db, range->owner, range->start, range->count) == 1;
|
|
|
9ed61c |
+}
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+bool release_subid_range(struct subordinate_range *range, enum subid_type id_type)
|
|
|
9ed61c |
+{
|
|
|
9ed61c |
+ struct commonio_db *db;
|
|
|
9ed61c |
+ if (id_type == ID_TYPE_UID)
|
|
|
9ed61c |
+ db = &subordinate_uid_db;
|
|
|
9ed61c |
+ else
|
|
|
9ed61c |
+ db = &subordinate_gid_db;
|
|
|
9ed61c |
+ return remove_range(db, range->owner, range->start, range->count) == 1;
|
|
|
9ed61c |
+}
|
|
|
9ed61c |
+
|
|
|
9ed61c |
#else /* !ENABLE_SUBIDS */
|
|
|
9ed61c |
extern int errno; /* warning: ANSI C forbids an empty source file */
|
|
|
9ed61c |
#endif /* !ENABLE_SUBIDS */
|
|
|
9ed61c |
diff -up shadow-4.6/lib/subordinateio.h.libsubid_creation shadow-4.6/lib/subordinateio.h
|
|
|
9ed61c |
--- shadow-4.6/lib/subordinateio.h.libsubid_creation 2018-04-29 18:42:37.000000000 +0200
|
|
|
9ed61c |
+++ shadow-4.6/lib/subordinateio.h 2021-10-19 16:12:02.661748243 +0200
|
|
|
9ed61c |
@@ -11,6 +11,8 @@
|
|
|
9ed61c |
|
|
|
9ed61c |
#include <sys/types.h>
|
|
|
9ed61c |
|
|
|
9ed61c |
+#include "../libsubid/subid.h"
|
|
|
9ed61c |
+
|
|
|
9ed61c |
extern int sub_uid_close(void);
|
|
|
9ed61c |
extern bool have_sub_uids(const char *owner, uid_t start, unsigned long count);
|
|
|
9ed61c |
extern bool sub_uid_file_present (void);
|
|
|
9ed61c |
@@ -23,6 +25,11 @@ 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 struct subordinate_range **list_owner_ranges(const char *owner, enum subid_type id_type);
|
|
|
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, uid_t **uids, enum subid_type id_type);
|
|
|
9ed61c |
+extern void free_subordinate_ranges(struct subordinate_range **ranges);
|
|
|
9ed61c |
|
|
|
9ed61c |
extern int sub_gid_close(void);
|
|
|
9ed61c |
extern bool have_sub_gids(const char *owner, gid_t start, unsigned long count);
|
|
|
9ed61c |
diff -up shadow-4.6/Makefile.am.libsubid_creation shadow-4.6/Makefile.am
|
|
|
9ed61c |
--- shadow-4.6/Makefile.am.libsubid_creation 2018-04-29 18:42:37.000000000 +0200
|
|
|
9ed61c |
+++ shadow-4.6/Makefile.am 2021-10-19 16:12:02.660748228 +0200
|
|
|
9ed61c |
@@ -2,5 +2,14 @@
|
|
|
9ed61c |
|
|
|
9ed61c |
EXTRA_DIST = NEWS README TODO shadow.spec.in
|
|
|
9ed61c |
|
|
|
9ed61c |
-SUBDIRS = po man libmisc lib src \
|
|
|
9ed61c |
- contrib doc etc
|
|
|
9ed61c |
+SUBDIRS = libmisc lib
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+if ENABLE_SUBIDS
|
|
|
9ed61c |
+SUBDIRS += libsubid
|
|
|
9ed61c |
+endif
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+SUBDIRS += src po contrib doc etc
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+if ENABLE_REGENERATE_MAN
|
|
|
9ed61c |
+SUBDIRS += man
|
|
|
9ed61c |
+endif
|
|
|
9ed61c |
diff -up shadow-4.6/src/free_subid_range.c.libsubid_creation shadow-4.6/src/free_subid_range.c
|
|
|
9ed61c |
--- shadow-4.6/src/free_subid_range.c.libsubid_creation 2021-10-19 16:12:02.661748243 +0200
|
|
|
9ed61c |
+++ shadow-4.6/src/free_subid_range.c 2021-10-19 16:12:02.661748243 +0200
|
|
|
9ed61c |
@@ -0,0 +1,50 @@
|
|
|
9ed61c |
+#include <stdio.h>
|
|
|
9ed61c |
+#include <unistd.h>
|
|
|
9ed61c |
+#include "api.h"
|
|
|
9ed61c |
+#include "stdlib.h"
|
|
|
9ed61c |
+#include "prototypes.h"
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+/* Test program for the subid freeing routine */
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+const char *Prog;
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+void usage(void)
|
|
|
9ed61c |
+{
|
|
|
9ed61c |
+ fprintf(stderr, "Usage: %s [-g] user start count\n", Prog);
|
|
|
9ed61c |
+ fprintf(stderr, " Release a user's subuid (or with -g, subgid) range\n");
|
|
|
9ed61c |
+ exit(EXIT_FAILURE);
|
|
|
9ed61c |
+}
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+int main(int argc, char *argv[])
|
|
|
9ed61c |
+{
|
|
|
9ed61c |
+ int c;
|
|
|
9ed61c |
+ bool ok;
|
|
|
9ed61c |
+ struct subordinate_range range;
|
|
|
9ed61c |
+ bool group = false; // get subuids by default
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+ Prog = Basename (argv[0]);
|
|
|
9ed61c |
+ while ((c = getopt(argc, argv, "g")) != EOF) {
|
|
|
9ed61c |
+ switch(c) {
|
|
|
9ed61c |
+ case 'g': group = true; break;
|
|
|
9ed61c |
+ default: usage();
|
|
|
9ed61c |
+ }
|
|
|
9ed61c |
+ }
|
|
|
9ed61c |
+ argv = &argv[optind];
|
|
|
9ed61c |
+ argc = argc - optind;
|
|
|
9ed61c |
+ if (argc < 3)
|
|
|
9ed61c |
+ usage();
|
|
|
9ed61c |
+ range.owner = argv[0];
|
|
|
9ed61c |
+ range.start = atoi(argv[1]);
|
|
|
9ed61c |
+ range.count = atoi(argv[2]);
|
|
|
9ed61c |
+ if (group)
|
|
|
9ed61c |
+ ok = free_subgid_range(&range);
|
|
|
9ed61c |
+ else
|
|
|
9ed61c |
+ ok = free_subuid_range(&range);
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+ if (!ok) {
|
|
|
9ed61c |
+ fprintf(stderr, "Failed freeing id range\n");
|
|
|
9ed61c |
+ exit(EXIT_FAILURE);
|
|
|
9ed61c |
+ }
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+ return 0;
|
|
|
9ed61c |
+}
|
|
|
9ed61c |
diff -up shadow-4.6/src/get_subid_owners.c.libsubid_creation shadow-4.6/src/get_subid_owners.c
|
|
|
9ed61c |
--- shadow-4.6/src/get_subid_owners.c.libsubid_creation 2021-10-19 16:12:02.661748243 +0200
|
|
|
9ed61c |
+++ shadow-4.6/src/get_subid_owners.c 2021-10-19 16:12:02.661748243 +0200
|
|
|
9ed61c |
@@ -0,0 +1,40 @@
|
|
|
9ed61c |
+#include <stdio.h>
|
|
|
9ed61c |
+#include "api.h"
|
|
|
9ed61c |
+#include "stdlib.h"
|
|
|
9ed61c |
+#include "prototypes.h"
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+const char *Prog;
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+void usage(void)
|
|
|
9ed61c |
+{
|
|
|
9ed61c |
+ fprintf(stderr, "Usage: [-g] %s subuid\n", Prog);
|
|
|
9ed61c |
+ fprintf(stderr, " list uids who own the given subuid\n");
|
|
|
9ed61c |
+ fprintf(stderr, " pass -g to query a subgid\n");
|
|
|
9ed61c |
+ exit(EXIT_FAILURE);
|
|
|
9ed61c |
+}
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+int main(int argc, char *argv[])
|
|
|
9ed61c |
+{
|
|
|
9ed61c |
+ int i, n;
|
|
|
9ed61c |
+ uid_t *uids;
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+ Prog = Basename (argv[0]);
|
|
|
9ed61c |
+ if (argc < 2) {
|
|
|
9ed61c |
+ usage();
|
|
|
9ed61c |
+ }
|
|
|
9ed61c |
+ if (argc == 3 && strcmp(argv[1], "-g") == 0)
|
|
|
9ed61c |
+ n = get_subgid_owners(atoi(argv[2]), &uids);
|
|
|
9ed61c |
+ else if (argc == 2 && strcmp(argv[1], "-h") == 0)
|
|
|
9ed61c |
+ usage();
|
|
|
9ed61c |
+ else
|
|
|
9ed61c |
+ n = get_subuid_owners(atoi(argv[1]), &uids);
|
|
|
9ed61c |
+ if (n < 0) {
|
|
|
9ed61c |
+ fprintf(stderr, "No owners found\n");
|
|
|
9ed61c |
+ exit(1);
|
|
|
9ed61c |
+ }
|
|
|
9ed61c |
+ for (i = 0; i < n; i++) {
|
|
|
9ed61c |
+ printf("%d\n", uids[i]);
|
|
|
9ed61c |
+ }
|
|
|
9ed61c |
+ free(uids);
|
|
|
9ed61c |
+ return 0;
|
|
|
9ed61c |
+}
|
|
|
9ed61c |
diff -up shadow-4.6/src/list_subid_ranges.c.libsubid_creation shadow-4.6/src/list_subid_ranges.c
|
|
|
9ed61c |
--- shadow-4.6/src/list_subid_ranges.c.libsubid_creation 2021-10-19 16:12:02.661748243 +0200
|
|
|
9ed61c |
+++ shadow-4.6/src/list_subid_ranges.c 2021-10-19 16:12:02.661748243 +0200
|
|
|
9ed61c |
@@ -0,0 +1,41 @@
|
|
|
9ed61c |
+#include <stdio.h>
|
|
|
9ed61c |
+#include "api.h"
|
|
|
9ed61c |
+#include "stdlib.h"
|
|
|
9ed61c |
+#include "prototypes.h"
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+const char *Prog;
|
|
|
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;
|
|
|
9ed61c |
+ struct subordinate_range **ranges;
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+ Prog = Basename (argv[0]);
|
|
|
9ed61c |
+ if (argc < 2) {
|
|
|
9ed61c |
+ usage();
|
|
|
9ed61c |
+ }
|
|
|
9ed61c |
+ if (argc == 3 && strcmp(argv[1], "-g") == 0)
|
|
|
9ed61c |
+ ranges = get_subgid_ranges(argv[2]);
|
|
|
9ed61c |
+ else if (argc == 2 && strcmp(argv[1], "-h") == 0)
|
|
|
9ed61c |
+ usage();
|
|
|
9ed61c |
+ else
|
|
|
9ed61c |
+ ranges = get_subuid_ranges(argv[1]);
|
|
|
9ed61c |
+ if (!ranges) {
|
|
|
9ed61c |
+ fprintf(stderr, "Error fetching ranges\n");
|
|
|
9ed61c |
+ exit(1);
|
|
|
9ed61c |
+ }
|
|
|
9ed61c |
+ for (i = 0; ranges[i]; i++) {
|
|
|
9ed61c |
+ printf("%d: %s %lu %lu\n", i, ranges[i]->owner,
|
|
|
9ed61c |
+ ranges[i]->start, ranges[i]->count);
|
|
|
9ed61c |
+ }
|
|
|
9ed61c |
+ subid_free_ranges(ranges);
|
|
|
9ed61c |
+ return 0;
|
|
|
9ed61c |
+}
|
|
|
9ed61c |
diff -up shadow-4.6/src/new_subid_range.c.libsubid_creation shadow-4.6/src/new_subid_range.c
|
|
|
9ed61c |
--- shadow-4.6/src/new_subid_range.c.libsubid_creation 2021-10-19 16:12:02.661748243 +0200
|
|
|
9ed61c |
+++ shadow-4.6/src/new_subid_range.c 2021-10-19 16:12:02.661748243 +0200
|
|
|
9ed61c |
@@ -0,0 +1,57 @@
|
|
|
9ed61c |
+#include <stdio.h>
|
|
|
9ed61c |
+#include <unistd.h>
|
|
|
9ed61c |
+#include "api.h"
|
|
|
9ed61c |
+#include "stdlib.h"
|
|
|
9ed61c |
+#include "prototypes.h"
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+/* Test program for the subid creation routine */
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+const char *Prog;
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+void usage(void)
|
|
|
9ed61c |
+{
|
|
|
9ed61c |
+ fprintf(stderr, "Usage: %s [-g] [-n] user count\n", Prog);
|
|
|
9ed61c |
+ fprintf(stderr, " Find a subuid (or with -g, subgid) range for user\n");
|
|
|
9ed61c |
+ fprintf(stderr, " If -n is given, a new range will be created even if one exists\n");
|
|
|
9ed61c |
+ fprintf(stderr, " count defaults to 65536\n");
|
|
|
9ed61c |
+ exit(EXIT_FAILURE);
|
|
|
9ed61c |
+}
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+int main(int argc, char *argv[])
|
|
|
9ed61c |
+{
|
|
|
9ed61c |
+ int c;
|
|
|
9ed61c |
+ struct subordinate_range range;
|
|
|
9ed61c |
+ bool makenew = false; // reuse existing by default
|
|
|
9ed61c |
+ bool group = false; // get subuids by default
|
|
|
9ed61c |
+ bool ok;
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+ Prog = Basename (argv[0]);
|
|
|
9ed61c |
+ while ((c = getopt(argc, argv, "gn")) != EOF) {
|
|
|
9ed61c |
+ switch(c) {
|
|
|
9ed61c |
+ case 'n': makenew = true; break;
|
|
|
9ed61c |
+ case 'g': group = true; break;
|
|
|
9ed61c |
+ default: usage();
|
|
|
9ed61c |
+ }
|
|
|
9ed61c |
+ }
|
|
|
9ed61c |
+ argv = &argv[optind];
|
|
|
9ed61c |
+ argc = argc - optind;
|
|
|
9ed61c |
+ if (argc == 0)
|
|
|
9ed61c |
+ usage();
|
|
|
9ed61c |
+ range.owner = argv[0];
|
|
|
9ed61c |
+ range.start = 0;
|
|
|
9ed61c |
+ range.count = 65536;
|
|
|
9ed61c |
+ if (argc > 1)
|
|
|
9ed61c |
+ range.count = atoi(argv[1]);
|
|
|
9ed61c |
+ if (group)
|
|
|
9ed61c |
+ ok = grant_subgid_range(&range, !makenew);
|
|
|
9ed61c |
+ else
|
|
|
9ed61c |
+ ok = grant_subuid_range(&range, !makenew);
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+ if (!ok) {
|
|
|
9ed61c |
+ fprintf(stderr, "Failed creating new id range\n");
|
|
|
9ed61c |
+ exit(EXIT_FAILURE);
|
|
|
9ed61c |
+ }
|
|
|
9ed61c |
+ printf("Subuid range %lu:%lu\n", range.start, range.count);
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+ return 0;
|
|
|
9ed61c |
+}
|
|
|
9ed61c |
diff -up shadow-4.6/tests/libsubid/01_list_ranges/config/etc/subgid.libsubid_creation shadow-4.6/tests/libsubid/01_list_ranges/config/etc/subgid
|
|
|
9ed61c |
--- shadow-4.6/tests/libsubid/01_list_ranges/config/etc/subgid.libsubid_creation 2021-10-19 16:12:02.662748257 +0200
|
|
|
9ed61c |
+++ shadow-4.6/tests/libsubid/01_list_ranges/config/etc/subgid 2021-10-19 16:12:02.662748257 +0200
|
|
|
9ed61c |
@@ -0,0 +1,2 @@
|
|
|
9ed61c |
+foo:200000:10000
|
|
|
9ed61c |
+root:500000:1000
|
|
|
9ed61c |
diff -up shadow-4.6/tests/libsubid/01_list_ranges/config/etc/subuid.libsubid_creation shadow-4.6/tests/libsubid/01_list_ranges/config/etc/subuid
|
|
|
9ed61c |
--- shadow-4.6/tests/libsubid/01_list_ranges/config/etc/subuid.libsubid_creation 2021-10-19 16:12:02.662748257 +0200
|
|
|
9ed61c |
+++ shadow-4.6/tests/libsubid/01_list_ranges/config/etc/subuid 2021-10-19 16:12:02.662748257 +0200
|
|
|
9ed61c |
@@ -0,0 +1,3 @@
|
|
|
9ed61c |
+foo:300000:10000
|
|
|
9ed61c |
+foo:400000:10000
|
|
|
9ed61c |
+root:500000:1000
|
|
|
9ed61c |
diff -up shadow-4.6/tests/libsubid/01_list_ranges/config.txt.libsubid_creation shadow-4.6/tests/libsubid/01_list_ranges/config.txt
|
|
|
9ed61c |
diff -up shadow-4.6/tests/libsubid/01_list_ranges/list_ranges.test.libsubid_creation shadow-4.6/tests/libsubid/01_list_ranges/list_ranges.test
|
|
|
9ed61c |
--- shadow-4.6/tests/libsubid/01_list_ranges/list_ranges.test.libsubid_creation 2021-10-19 16:12:02.662748257 +0200
|
|
|
9ed61c |
+++ shadow-4.6/tests/libsubid/01_list_ranges/list_ranges.test 2021-10-19 16:12:02.662748257 +0200
|
|
|
9ed61c |
@@ -0,0 +1,38 @@
|
|
|
9ed61c |
+#!/bin/sh
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+set -e
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+cd $(dirname $0)
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+. ../../common/config.sh
|
|
|
9ed61c |
+. ../../common/log.sh
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+log_start "$0" "list_ranges shows subid ranges"
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+save_config
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+# restore the files on exit
|
|
|
9ed61c |
+trap 'log_status "$0" "FAILURE"; restore_config' 0
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+change_config
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+echo -n "list foo's ranges..."
|
|
|
9ed61c |
+${build_path}/src/list_subid_ranges foo > /tmp/subuidlistout
|
|
|
9ed61c |
+${build_path}/src/list_subid_ranges -g foo > /tmp/subgidlistout
|
|
|
9ed61c |
+echo "OK"
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+echo -n "Check the subuid ranges..."
|
|
|
9ed61c |
+[ $(wc -l /tmp/subuidlistout | awk '{ print $1 }') -eq 2 ]
|
|
|
9ed61c |
+grep "0: foo 300000 10000" /tmp/subuidlistout
|
|
|
9ed61c |
+grep "1: foo 400000 10000" /tmp/subuidlistout
|
|
|
9ed61c |
+echo "OK"
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+echo -n "Check the subgid ranges..."
|
|
|
9ed61c |
+[ $(wc -l /tmp/subgidlistout | awk '{ print $1 }') -eq 1 ]
|
|
|
9ed61c |
+grep "0: foo 200000 10000" /tmp/subgidlistout
|
|
|
9ed61c |
+echo "OK"
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+log_status "$0" "SUCCESS"
|
|
|
9ed61c |
+restore_config
|
|
|
9ed61c |
+trap '' 0
|
|
|
9ed61c |
+
|
|
|
9ed61c |
diff -up shadow-4.6/tests/libsubid/02_get_subid_owners/config/etc/passwd.libsubid_creation shadow-4.6/tests/libsubid/02_get_subid_owners/config/etc/passwd
|
|
|
9ed61c |
--- shadow-4.6/tests/libsubid/02_get_subid_owners/config/etc/passwd.libsubid_creation 2021-10-19 16:12:02.662748257 +0200
|
|
|
9ed61c |
+++ shadow-4.6/tests/libsubid/02_get_subid_owners/config/etc/passwd 2021-10-19 16:12:02.662748257 +0200
|
|
|
9ed61c |
@@ -0,0 +1,20 @@
|
|
|
9ed61c |
+root:x:0:0:root:/root:/bin/bash
|
|
|
9ed61c |
+daemon:x:1:1:daemon:/usr/sbin:/bin/sh
|
|
|
9ed61c |
+bin:x:2:2:bin:/bin:/bin/sh
|
|
|
9ed61c |
+sys:x:3:3:sys:/dev:/bin/sh
|
|
|
9ed61c |
+sync:x:4:65534:sync:/bin:/bin/sync
|
|
|
9ed61c |
+games:x:5:60:games:/usr/games:/bin/sh
|
|
|
9ed61c |
+man:x:6:12:man:/var/cache/man:/bin/sh
|
|
|
9ed61c |
+lp:x:7:7:lp:/var/spool/lpd:/bin/sh
|
|
|
9ed61c |
+mail:x:8:8:mail:/var/mail:/bin/sh
|
|
|
9ed61c |
+news:x:9:9:news:/var/spool/news:/bin/sh
|
|
|
9ed61c |
+uucp:x:10:10:uucp:/var/spool/uucp:/bin/sh
|
|
|
9ed61c |
+proxy:x:13:13:proxy:/bin:/bin/sh
|
|
|
9ed61c |
+www-data:x:33:33:www-data:/var/www:/bin/sh
|
|
|
9ed61c |
+backup:x:34:34:backup:/var/backups:/bin/sh
|
|
|
9ed61c |
+list:x:38:38:Mailing List Manager:/var/list:/bin/sh
|
|
|
9ed61c |
+irc:x:39:39:ircd:/var/run/ircd:/bin/sh
|
|
|
9ed61c |
+gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/bin/sh
|
|
|
9ed61c |
+nobody:x:65534:65534:nobody:/nonexistent:/bin/sh
|
|
|
9ed61c |
+Debian-exim:x:102:102::/var/spool/exim4:/bin/false
|
|
|
9ed61c |
+foo:x:1000:1000::/home/foo:/bin/false
|
|
|
9ed61c |
diff -up shadow-4.6/tests/libsubid/02_get_subid_owners/config/etc/subgid.libsubid_creation shadow-4.6/tests/libsubid/02_get_subid_owners/config/etc/subgid
|
|
|
9ed61c |
--- shadow-4.6/tests/libsubid/02_get_subid_owners/config/etc/subgid.libsubid_creation 2021-10-19 16:12:02.662748257 +0200
|
|
|
9ed61c |
+++ shadow-4.6/tests/libsubid/02_get_subid_owners/config/etc/subgid 2021-10-19 16:12:02.662748257 +0200
|
|
|
9ed61c |
@@ -0,0 +1,2 @@
|
|
|
9ed61c |
+foo:200000:10000
|
|
|
9ed61c |
+root:500000:1000
|
|
|
9ed61c |
diff -up shadow-4.6/tests/libsubid/02_get_subid_owners/config/etc/subuid.libsubid_creation shadow-4.6/tests/libsubid/02_get_subid_owners/config/etc/subuid
|
|
|
9ed61c |
--- shadow-4.6/tests/libsubid/02_get_subid_owners/config/etc/subuid.libsubid_creation 2021-10-19 16:12:02.662748257 +0200
|
|
|
9ed61c |
+++ shadow-4.6/tests/libsubid/02_get_subid_owners/config/etc/subuid 2021-10-19 16:12:02.662748257 +0200
|
|
|
9ed61c |
@@ -0,0 +1,4 @@
|
|
|
9ed61c |
+foo:300000:10000
|
|
|
9ed61c |
+foo:400000:10000
|
|
|
9ed61c |
+foo:500000:10000
|
|
|
9ed61c |
+root:500000:1000
|
|
|
9ed61c |
diff -up shadow-4.6/tests/libsubid/02_get_subid_owners/config.txt.libsubid_creation shadow-4.6/tests/libsubid/02_get_subid_owners/config.txt
|
|
|
9ed61c |
diff -up shadow-4.6/tests/libsubid/02_get_subid_owners/get_subid_owners.test.libsubid_creation shadow-4.6/tests/libsubid/02_get_subid_owners/get_subid_owners.test
|
|
|
9ed61c |
--- shadow-4.6/tests/libsubid/02_get_subid_owners/get_subid_owners.test.libsubid_creation 2021-10-19 16:12:02.662748257 +0200
|
|
|
9ed61c |
+++ shadow-4.6/tests/libsubid/02_get_subid_owners/get_subid_owners.test 2021-10-19 16:12:02.662748257 +0200
|
|
|
9ed61c |
@@ -0,0 +1,52 @@
|
|
|
9ed61c |
+#!/bin/sh
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+set -e
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+cd $(dirname $0)
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+. ../../common/config.sh
|
|
|
9ed61c |
+. ../../common/log.sh
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+log_start "$0" "get subid owners"
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+save_config
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+# restore the files on exit
|
|
|
9ed61c |
+trap 'log_status "$0" "FAILURE"; restore_config' 0
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+change_config
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+echo -n "Noone owns 0 as a subid..."
|
|
|
9ed61c |
+[ -z "$(${build_path}/src/get_subid_owners 0)" ]
|
|
|
9ed61c |
+echo "OK"
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+echo -n "foo owns subuid 300000..."
|
|
|
9ed61c |
+[ "$(${build_path}/src/get_subid_owners 300000)" = "1000" ]
|
|
|
9ed61c |
+echo "OK"
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+echo -n "foo owns subgid 200000..."
|
|
|
9ed61c |
+[ "$(${build_path}/src/get_subid_owners -g 200000)" = "1000" ]
|
|
|
9ed61c |
+echo "OK"
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+echo -n "Noone owns subuid 200000..."
|
|
|
9ed61c |
+[ -z "$(${build_path}/src/get_subid_owners -g 300000)" ]
|
|
|
9ed61c |
+echo "OK"
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+echo -n "Noone owns subgid 300000..."
|
|
|
9ed61c |
+[ -z "$(${build_path}/src/get_subid_owners -g 300000)" ]
|
|
|
9ed61c |
+echo "OK"
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+echo -n "Both foo and root own subuid 500000..."
|
|
|
9ed61c |
+cat > /tmp/expected << EOF
|
|
|
9ed61c |
+1000
|
|
|
9ed61c |
+0
|
|
|
9ed61c |
+EOF
|
|
|
9ed61c |
+${build_path}/src/get_subid_owners 500000 > /tmp/actual
|
|
|
9ed61c |
+diff /tmp/expected /tmp/actual
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+echo "OK"
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+log_status "$0" "SUCCESS"
|
|
|
9ed61c |
+restore_config
|
|
|
9ed61c |
+trap '' 0
|
|
|
9ed61c |
+
|
|
|
9ed61c |
diff -up shadow-4.6/tests/libsubid/03_add_remove/add_remove_subids.test.libsubid_creation shadow-4.6/tests/libsubid/03_add_remove/add_remove_subids.test
|
|
|
9ed61c |
--- shadow-4.6/tests/libsubid/03_add_remove/add_remove_subids.test.libsubid_creation 2021-10-19 16:12:02.662748257 +0200
|
|
|
9ed61c |
+++ shadow-4.6/tests/libsubid/03_add_remove/add_remove_subids.test 2021-10-19 16:12:02.662748257 +0200
|
|
|
9ed61c |
@@ -0,0 +1,59 @@
|
|
|
9ed61c |
+#!/bin/sh
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+set -e
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+cd $(dirname $0)
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+. ../../common/config.sh
|
|
|
9ed61c |
+. ../../common/log.sh
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+log_start "$0" "add and remove subid ranges"
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+save_config
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+# restore the files on exit
|
|
|
9ed61c |
+trap 'log_status "$0" "FAILURE"; restore_config' 0
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+change_config
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+echo -n "Existing ranges returned when possible..."
|
|
|
9ed61c |
+res=$(${build_path}/src/new_subid_range foo 500)
|
|
|
9ed61c |
+echo "debug"
|
|
|
9ed61c |
+echo "res is $res"
|
|
|
9ed61c |
+echo "wanted Subuid range 300000:10000"
|
|
|
9ed61c |
+echo "end debug"
|
|
|
9ed61c |
+[ "$res" = "Subuid range 300000:10000" ]
|
|
|
9ed61c |
+[ $(grep -c foo /etc/subuid) -eq 1 ]
|
|
|
9ed61c |
+echo "OK"
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+echo -n "New range returned if requested..."
|
|
|
9ed61c |
+res=$(${build_path}/src/new_subid_range foo 500 -n)
|
|
|
9ed61c |
+[ "$res" = "Subuid range 310000:500" ]
|
|
|
9ed61c |
+[ $(grep -c foo /etc/subuid) -eq 2 ]
|
|
|
9ed61c |
+echo "OK"
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+echo -n "Free works..."
|
|
|
9ed61c |
+res=$(${build_path}/src/free_subid_range foo 310000 500)
|
|
|
9ed61c |
+[ $(grep -c foo /etc/subuid) -eq 1 ]
|
|
|
9ed61c |
+echo "OK"
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+echo -n "Subgids work too..."
|
|
|
9ed61c |
+res=$(${build_path}/src/new_subid_range -g foo 100000)
|
|
|
9ed61c |
+echo "DEBUG: res is ${res}"
|
|
|
9ed61c |
+[ "$res" = "Subuid range 501000:100000" ]
|
|
|
9ed61c |
+echo "DEBUG: subgid is:"
|
|
|
9ed61c |
+cat /etc/subgid
|
|
|
9ed61c |
+[ $(grep -c foo /etc/subgid) -eq 2 ]
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+echo -n "Subgid free works..."
|
|
|
9ed61c |
+res=$(${build_path}/src/free_subid_range -g foo 501000 100000)
|
|
|
9ed61c |
+echo "DEBUG: res is ${res}"
|
|
|
9ed61c |
+echo "DEBUG: subgid is:"
|
|
|
9ed61c |
+cat /etc/subgid
|
|
|
9ed61c |
+[ $(grep -c foo /etc/subgid) -eq 1 ]
|
|
|
9ed61c |
+echo "OK"
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+log_status "$0" "SUCCESS"
|
|
|
9ed61c |
+restore_config
|
|
|
9ed61c |
+trap '' 0
|
|
|
9ed61c |
+
|
|
|
9ed61c |
diff -up shadow-4.6/tests/libsubid/03_add_remove/config/etc/passwd.libsubid_creation shadow-4.6/tests/libsubid/03_add_remove/config/etc/passwd
|
|
|
9ed61c |
--- shadow-4.6/tests/libsubid/03_add_remove/config/etc/passwd.libsubid_creation 2021-10-19 16:12:02.662748257 +0200
|
|
|
9ed61c |
+++ shadow-4.6/tests/libsubid/03_add_remove/config/etc/passwd 2021-10-19 16:12:02.662748257 +0200
|
|
|
9ed61c |
@@ -0,0 +1,20 @@
|
|
|
9ed61c |
+root:x:0:0:root:/root:/bin/bash
|
|
|
9ed61c |
+daemon:x:1:1:daemon:/usr/sbin:/bin/sh
|
|
|
9ed61c |
+bin:x:2:2:bin:/bin:/bin/sh
|
|
|
9ed61c |
+sys:x:3:3:sys:/dev:/bin/sh
|
|
|
9ed61c |
+sync:x:4:65534:sync:/bin:/bin/sync
|
|
|
9ed61c |
+games:x:5:60:games:/usr/games:/bin/sh
|
|
|
9ed61c |
+man:x:6:12:man:/var/cache/man:/bin/sh
|
|
|
9ed61c |
+lp:x:7:7:lp:/var/spool/lpd:/bin/sh
|
|
|
9ed61c |
+mail:x:8:8:mail:/var/mail:/bin/sh
|
|
|
9ed61c |
+news:x:9:9:news:/var/spool/news:/bin/sh
|
|
|
9ed61c |
+uucp:x:10:10:uucp:/var/spool/uucp:/bin/sh
|
|
|
9ed61c |
+proxy:x:13:13:proxy:/bin:/bin/sh
|
|
|
9ed61c |
+www-data:x:33:33:www-data:/var/www:/bin/sh
|
|
|
9ed61c |
+backup:x:34:34:backup:/var/backups:/bin/sh
|
|
|
9ed61c |
+list:x:38:38:Mailing List Manager:/var/list:/bin/sh
|
|
|
9ed61c |
+irc:x:39:39:ircd:/var/run/ircd:/bin/sh
|
|
|
9ed61c |
+gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/bin/sh
|
|
|
9ed61c |
+nobody:x:65534:65534:nobody:/nonexistent:/bin/sh
|
|
|
9ed61c |
+Debian-exim:x:102:102::/var/spool/exim4:/bin/false
|
|
|
9ed61c |
+foo:x:1000:1000::/home/foo:/bin/false
|
|
|
9ed61c |
diff -up shadow-4.6/tests/libsubid/03_add_remove/config/etc/subgid.libsubid_creation shadow-4.6/tests/libsubid/03_add_remove/config/etc/subgid
|
|
|
9ed61c |
--- shadow-4.6/tests/libsubid/03_add_remove/config/etc/subgid.libsubid_creation 2021-10-19 16:12:02.662748257 +0200
|
|
|
9ed61c |
+++ shadow-4.6/tests/libsubid/03_add_remove/config/etc/subgid 2021-10-19 16:12:02.662748257 +0200
|
|
|
9ed61c |
@@ -0,0 +1,2 @@
|
|
|
9ed61c |
+foo:200000:10000
|
|
|
9ed61c |
+root:500000:1000
|
|
|
9ed61c |
diff -up shadow-4.6/tests/libsubid/03_add_remove/config/etc/subuid.libsubid_creation shadow-4.6/tests/libsubid/03_add_remove/config/etc/subuid
|
|
|
9ed61c |
--- shadow-4.6/tests/libsubid/03_add_remove/config/etc/subuid.libsubid_creation 2021-10-19 16:12:02.662748257 +0200
|
|
|
9ed61c |
+++ shadow-4.6/tests/libsubid/03_add_remove/config/etc/subuid 2021-10-19 16:12:02.662748257 +0200
|
|
|
9ed61c |
@@ -0,0 +1 @@
|
|
|
9ed61c |
+foo:300000:10000
|
|
|
9ed61c |
diff -up shadow-4.6/tests/libsubid/03_add_remove/config.txt.libsubid_creation shadow-4.6/tests/libsubid/03_add_remove/config.txt
|
|
|
9ed61c |
diff -up shadow-4.6/tests/run_some.libsubid_creation shadow-4.6/tests/run_some
|
|
|
9ed61c |
--- shadow-4.6/tests/run_some.libsubid_creation 2021-10-19 16:12:02.662748257 +0200
|
|
|
9ed61c |
+++ shadow-4.6/tests/run_some 2021-10-19 16:12:02.662748257 +0200
|
|
|
9ed61c |
@@ -0,0 +1,136 @@
|
|
|
9ed61c |
+#!/bin/sh
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+set -e
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+export LC_ALL=C
|
|
|
9ed61c |
+unset LANG
|
|
|
9ed61c |
+unset LANGUAGE
|
|
|
9ed61c |
+. common/config.sh
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+USE_PAM="yes"
|
|
|
9ed61c |
+FAILURE_TESTS="yes"
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+succeeded=0
|
|
|
9ed61c |
+failed=0
|
|
|
9ed61c |
+failed_tests=""
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+run_test()
|
|
|
9ed61c |
+{
|
|
|
9ed61c |
+ [ -f RUN_TEST.STOP ] && exit 1
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+ if $1 > $1.log
|
|
|
9ed61c |
+ then
|
|
|
9ed61c |
+ succeeded=$((succeeded+1))
|
|
|
9ed61c |
+ echo -n "+"
|
|
|
9ed61c |
+ else
|
|
|
9ed61c |
+ failed=$((failed+1))
|
|
|
9ed61c |
+ failed_tests="$failed_tests $1"
|
|
|
9ed61c |
+ echo -n "-"
|
|
|
9ed61c |
+ fi
|
|
|
9ed61c |
+ cat $1.log >> testsuite.log
|
|
|
9ed61c |
+ [ -f /etc/passwd.lock ] && echo $1 /etc/passwd.lock || true
|
|
|
9ed61c |
+ [ -f /etc/group.lock ] && echo $1 /etc/group.lock || true
|
|
|
9ed61c |
+ [ -f /etc/shadow.lock ] && echo $1 /etc/shadow.lock || true
|
|
|
9ed61c |
+ [ -f /etc/gshadow.lock ] && echo $1 /etc/gshadow.lock || true
|
|
|
9ed61c |
+ if [ "$(stat -c"%G" /etc/shadow)" != "shadow" ]
|
|
|
9ed61c |
+ then
|
|
|
9ed61c |
+ echo $1
|
|
|
9ed61c |
+ ls -l /etc/shadow
|
|
|
9ed61c |
+ chgrp shadow /etc/shadow
|
|
|
9ed61c |
+ fi
|
|
|
9ed61c |
+ if [ -d /nonexistent ]
|
|
|
9ed61c |
+ then
|
|
|
9ed61c |
+ echo $1 /nonexistent
|
|
|
9ed61c |
+ rmdir /nonexistent
|
|
|
9ed61c |
+ fi
|
|
|
9ed61c |
+}
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+echo "+: test passed"
|
|
|
9ed61c |
+echo "-: test failed"
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+# Empty the complete log.
|
|
|
9ed61c |
+> testsuite.log
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+find ${build_path} -name "*.gcda" -delete
|
|
|
9ed61c |
+run_test ./su/01/su_root.test
|
|
|
9ed61c |
+run_test ./su/01/su_user.test
|
|
|
9ed61c |
+find ${build_path} -name "*.gcda" -exec chmod a+rw {} \;
|
|
|
9ed61c |
+run_test ./su/02/env_FOO-options_--login
|
|
|
9ed61c |
+run_test ./su/02/env_FOO-options_--login_bash
|
|
|
9ed61c |
+run_test ./su/02/env_FOO-options_--preserve-environment
|
|
|
9ed61c |
+run_test ./su/02/env_FOO-options_--preserve-environment_bash
|
|
|
9ed61c |
+run_test ./su/02/env_FOO-options_-
|
|
|
9ed61c |
+run_test ./su/02/env_FOO-options_-_bash
|
|
|
9ed61c |
+run_test ./su/02/env_FOO-options_-l-m
|
|
|
9ed61c |
+run_test ./su/02/env_FOO-options_-l-m_bash
|
|
|
9ed61c |
+run_test ./su/02/env_FOO-options_-l
|
|
|
9ed61c |
+run_test ./su/02/env_FOO-options_-l_bash
|
|
|
9ed61c |
+run_test ./su/02/env_FOO-options_-m_bash
|
|
|
9ed61c |
+run_test ./su/02/env_FOO-options_-m
|
|
|
9ed61c |
+run_test ./su/02/env_FOO-options_-p
|
|
|
9ed61c |
+run_test ./su/02/env_FOO-options_-p_bash
|
|
|
9ed61c |
+run_test ./su/02/env_FOO-options__bash
|
|
|
9ed61c |
+run_test ./su/02/env_FOO-options_
|
|
|
9ed61c |
+run_test ./su/02/env_FOO-options_-p-
|
|
|
9ed61c |
+run_test ./su/02/env_FOO-options_-p-_bash
|
|
|
9ed61c |
+run_test ./su/02/env_special-options_-l-p
|
|
|
9ed61c |
+run_test ./su/02/env_special-options_-l
|
|
|
9ed61c |
+run_test ./su/02/env_special-options_-l-p_bash
|
|
|
9ed61c |
+run_test ./su/02/env_special-options_-l_bash
|
|
|
9ed61c |
+run_test ./su/02/env_special-options_-p
|
|
|
9ed61c |
+run_test ./su/02/env_special-options_-p_bash
|
|
|
9ed61c |
+run_test ./su/02/env_special-options_
|
|
|
9ed61c |
+run_test ./su/02/env_special-options__bash
|
|
|
9ed61c |
+run_test ./su/02/env_special_root-options_-l-p
|
|
|
9ed61c |
+run_test ./su/02/env_special_root-options_-l-p_bash
|
|
|
9ed61c |
+run_test ./su/02/env_special_root-options_-l
|
|
|
9ed61c |
+run_test ./su/02/env_special_root-options_-l_bash
|
|
|
9ed61c |
+run_test ./su/02/env_special_root-options_-p
|
|
|
9ed61c |
+run_test ./su/02/env_special_root-options_-p_bash
|
|
|
9ed61c |
+run_test ./su/02/env_special_root-options_
|
|
|
9ed61c |
+run_test ./su/02/env_special_root-options__bash
|
|
|
9ed61c |
+run_test ./su/03/su_run_command01.test
|
|
|
9ed61c |
+run_test ./su/03/su_run_command02.test
|
|
|
9ed61c |
+run_test ./su/03/su_run_command03.test
|
|
|
9ed61c |
+run_test ./su/03/su_run_command04.test
|
|
|
9ed61c |
+run_test ./su/03/su_run_command05.test
|
|
|
9ed61c |
+run_test ./su/03/su_run_command06.test
|
|
|
9ed61c |
+run_test ./su/03/su_run_command07.test
|
|
|
9ed61c |
+run_test ./su/03/su_run_command08.test
|
|
|
9ed61c |
+run_test ./su/03/su_run_command09.test
|
|
|
9ed61c |
+run_test ./su/03/su_run_command10.test
|
|
|
9ed61c |
+run_test ./su/03/su_run_command11.test
|
|
|
9ed61c |
+run_test ./su/03/su_run_command12.test
|
|
|
9ed61c |
+run_test ./su/03/su_run_command13.test
|
|
|
9ed61c |
+run_test ./su/03/su_run_command14.test
|
|
|
9ed61c |
+run_test ./su/03/su_run_command15.test
|
|
|
9ed61c |
+run_test ./su/03/su_run_command16.test
|
|
|
9ed61c |
+run_test ./su/03/su_run_command17.test
|
|
|
9ed61c |
+run_test ./su/04/su_wrong_user.test
|
|
|
9ed61c |
+run_test ./su/04/su_user_wrong_passwd.test
|
|
|
9ed61c |
+run_test ./su/04/su_user_wrong_passwd_syslog.test
|
|
|
9ed61c |
+run_test ./su/05/su_user_wrong_passwd_syslog.test
|
|
|
9ed61c |
+run_test ./su/06/su_user_syslog.test
|
|
|
9ed61c |
+run_test ./su/07/su_user_syslog.test
|
|
|
9ed61c |
+run_test ./su/08/env_special-options_
|
|
|
9ed61c |
+run_test ./su/08/env_special_root-options_
|
|
|
9ed61c |
+run_test ./su/09/env_special-options_
|
|
|
9ed61c |
+run_test ./su/09/env_special_root-options_
|
|
|
9ed61c |
+run_test ./su/10_su_sulog_success/su.test
|
|
|
9ed61c |
+run_test ./su/11_su_sulog_failure/su.test
|
|
|
9ed61c |
+run_test ./su/12_su_child_failure/su.test
|
|
|
9ed61c |
+run_test ./su/13_su_child_success/su.test
|
|
|
9ed61c |
+run_test ./libsubid/01_list_ranges/list_ranges.test
|
|
|
9ed61c |
+run_test ./libsubid/02_get_subid_owners/get_subid_owners.test
|
|
|
9ed61c |
+run_test ./libsubid/03_add_remove/add_remove_subids.test
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+echo
|
|
|
9ed61c |
+echo "$succeeded test(s) passed"
|
|
|
9ed61c |
+echo "$failed test(s) failed"
|
|
|
9ed61c |
+echo "log written in 'testsuite.log'"
|
|
|
9ed61c |
+if [ "$failed" != "0" ]
|
|
|
9ed61c |
+then
|
|
|
9ed61c |
+ echo "the following tests failed:"
|
|
|
9ed61c |
+ echo $failed_tests
|
|
|
9ed61c |
+fi
|
|
|
9ed61c |
+
|
|
|
9ed61c |
diff -up shadow-4.6/src/Makefile.am.libsubid_creation shadow-4.6/src/Makefile.am
|
|
|
9ed61c |
--- shadow-4.6/src/Makefile.am.bp 2021-10-19 13:13:14.132503541 +0200
|
|
|
9ed61c |
+++ shadow-4.6/src/Makefile.am 2021-10-19 13:14:40.055871030 +0200
|
|
|
9ed61c |
@@ -138,3 +138,64 @@
|
|
|
9ed61c |
chmod $(sgidperms) $(DESTDIR)$(ubindir)/$$i; \
|
|
|
9ed61c |
done
|
|
|
9ed61c |
endif
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+if ENABLE_SUBIDS
|
|
|
9ed61c |
+noinst_PROGRAMS += list_subid_ranges \
|
|
|
9ed61c |
+ get_subid_owners \
|
|
|
9ed61c |
+ new_subid_range \
|
|
|
9ed61c |
+ free_subid_range
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+MISCLIBS = \
|
|
|
9ed61c |
+ $(LIBAUDIT) \
|
|
|
9ed61c |
+ $(LIBSELINUX) \
|
|
|
9ed61c |
+ $(LIBSEMANAGE) \
|
|
|
9ed61c |
+ $(LIBCRYPT_NOPAM) \
|
|
|
9ed61c |
+ $(LIBSKEY) \
|
|
|
9ed61c |
+ $(LIBMD) \
|
|
|
9ed61c |
+ $(LIBCRYPT) \
|
|
|
9ed61c |
+ $(LIBTCB)
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+list_subid_ranges_LDADD = \
|
|
|
9ed61c |
+ $(top_builddir)/lib/libshadow.la \
|
|
|
9ed61c |
+ $(top_builddir)/libmisc/libmisc.a \
|
|
|
9ed61c |
+ $(top_builddir)/libsubid/libsubid.la \
|
|
|
9ed61c |
+ $(MISCLIBS)
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+list_subid_ranges_CPPFLAGS = \
|
|
|
9ed61c |
+ -I$(top_srcdir)/lib \
|
|
|
9ed61c |
+ -I$(top_srcdir)/libmisc \
|
|
|
9ed61c |
+ -I$(top_srcdir)/libsubid
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+get_subid_owners_LDADD = \
|
|
|
9ed61c |
+ $(top_builddir)/lib/libshadow.la \
|
|
|
9ed61c |
+ $(top_builddir)/libmisc/libmisc.a \
|
|
|
9ed61c |
+ $(top_builddir)/libsubid/libsubid.la \
|
|
|
9ed61c |
+ $(MISCLIBS)
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+get_subid_owners_CPPFLAGS = \
|
|
|
9ed61c |
+ -I$(top_srcdir)/lib \
|
|
|
9ed61c |
+ -I$(top_srcdir)/libmisc \
|
|
|
9ed61c |
+ -I$(top_srcdir)/libsubid
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+new_subid_range_CPPFLAGS = \
|
|
|
9ed61c |
+ -I$(top_srcdir)/lib \
|
|
|
9ed61c |
+ -I$(top_srcdir)/libmisc \
|
|
|
9ed61c |
+ -I$(top_srcdir)/libsubid
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+new_subid_range_LDADD = \
|
|
|
9ed61c |
+ $(top_builddir)/lib/libshadow.la \
|
|
|
9ed61c |
+ $(top_builddir)/libmisc/libmisc.a \
|
|
|
9ed61c |
+ $(top_builddir)/libsubid/libsubid.la \
|
|
|
9ed61c |
+ $(MISCLIBS)
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+free_subid_range_CPPFLAGS = \
|
|
|
9ed61c |
+ -I$(top_srcdir)/lib \
|
|
|
9ed61c |
+ -I$(top_srcdir)/libmisc \
|
|
|
9ed61c |
+ -I$(top_srcdir)/libsubid
|
|
|
9ed61c |
+
|
|
|
9ed61c |
+free_subid_range_LDADD = \
|
|
|
9ed61c |
+ $(top_builddir)/lib/libshadow.la \
|
|
|
9ed61c |
+ $(top_builddir)/libmisc/libmisc.a \
|
|
|
9ed61c |
+ $(top_builddir)/libsubid/libsubid.la \
|
|
|
9ed61c |
+ $(MISCLIBS)
|
|
|
9ed61c |
+endif
|