aboutsummaryrefslogtreecommitdiff
path: root/nss
diff options
context:
space:
mode:
authorArjun Shankar <arjun@redhat.com>2023-10-02 14:55:15 +0200
committerArjun Shankar <arjun@redhat.com>2023-10-24 12:30:59 +0200
commitb121fdc552f392cd86b21f159dd3e3b998de91a3 (patch)
treeeee235f1a10c6ce5d1b4d5a760c4a00d1d86e24d /nss
parent83d13972f23546758b600ba940e0d53248dd0339 (diff)
downloadglibc-b121fdc552f392cd86b21f159dd3e3b998de91a3.tar.xz
glibc-b121fdc552f392cd86b21f159dd3e3b998de91a3.zip
Remove 'grp' and merge into 'nss' and 'posix'
The majority of grp routines are entry points for nss functionality. This commit removes the 'grp' subdirectory and moves all nss-relevant functionality and all tests to 'nss', and the 'setgroups' stub into 'posix' (alongside the 'getgroups' stub). References to grp/ are accordingly changed. In addition, compat-initgroups.c, a fallback implementation of initgroups is renamed to initgroups-fallback.c so that the build system does not confuse it for nss_compat/compat-initgroups.c. Build time improves very slightly; e.g. down from an average of 45.5s to 44.5s on an 8-thread mobile x86_64 CPU. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Diffstat (limited to 'nss')
-rw-r--r--nss/Makefile43
-rw-r--r--nss/Versions30
-rw-r--r--nss/fgetgrent.c87
-rw-r--r--nss/fgetgrent_r.c65
-rw-r--r--nss/getgrent.c28
-rw-r--r--nss/getgrent_r.c28
-rw-r--r--nss/getgrgid.c28
-rw-r--r--nss/getgrgid_r.c31
-rw-r--r--nss/getgrnam.c28
-rw-r--r--nss/getgrnam_r.c31
-rw-r--r--nss/grp-merge.c200
-rw-r--r--nss/grp-merge.h35
-rw-r--r--nss/grp.h207
-rw-r--r--nss/initgroups-fallback.c116
-rw-r--r--nss/initgroups.c218
-rw-r--r--nss/putgrent.c76
-rw-r--r--nss/testgrp.c41
-rw-r--r--nss/tst-initgroups1.c56
-rw-r--r--nss/tst-initgroups1.root/etc/group7
-rw-r--r--nss/tst-initgroups1.root/etc/nsswitch.conf1
-rw-r--r--nss/tst-initgroups1.root/etc/passwd1
-rw-r--r--nss/tst-initgroups2.c21
-rw-r--r--nss/tst-initgroups2.root/etc/group7
-rw-r--r--nss/tst-initgroups2.root/etc/nsswitch.conf2
-rw-r--r--nss/tst-initgroups2.root/etc/passwd1
-rw-r--r--nss/tst-putgrent.c167
-rw-r--r--nss/tst_fgetgrent.c126
-rw-r--r--nss/tst_fgetgrent.sh40
28 files changed, 1720 insertions, 1 deletions
diff --git a/nss/Makefile b/nss/Makefile
index 32764b74c0..baf7d9d0ab 100644
--- a/nss/Makefile
+++ b/nss/Makefile
@@ -23,6 +23,7 @@ subdir := nss
include ../Makeconfig
headers := \
+ grp.h \
nss.h \
# headers
@@ -50,6 +51,34 @@ routines = \
valid_list_field \
# routines
+# grp routines:
+routines += \
+ fgetgrent \
+ fgetgrent_r \
+ getgrent \
+ getgrent_r \
+ getgrgid \
+ getgrgid_r \
+ getgrnam \
+ getgrnam_r \
+ grp-merge \
+ initgroups \
+ putgrent \
+ # routines
+
+ifeq ($(have-thread-library),yes)
+CFLAGS-fgetgrent.c += -fexceptions
+CFLAGS-fgetgrent_r.c += -fexceptions $(libio-mtsafe)
+CFLAGS-getgrent.c += -fexceptions
+CFLAGS-getgrent_r.c += -fexceptions
+CFLAGS-getgrgid.c += -fexceptions
+CFLAGS-getgrgid_r.c += -fexceptions
+CFLAGS-getgrnam.c += -fexceptions
+CFLAGS-getgrnam_r.c += -fexceptions
+CFLAGS-initgroups.c += -fexceptions
+CFLAGS-putgrent.c += -fexceptions $(libio-mtsafe)
+endif
+
# These are the databases that go through nss dispatch.
# Caution: if you add a database here, you must add its real name
# in databases.def, too.
@@ -88,6 +117,7 @@ tests := \
bug17079 \
test-digits-dots \
test-netdb \
+ testgrp \
tst-nss-getpwent \
tst-nss-hash \
tst-nss-test1 \
@@ -95,11 +125,14 @@ tests := \
tst-nss-test4 \
tst-nss-test5 \
tst-nss-test_errno \
+ tst-putgrent \
# tests
xtests = bug-erange
tests-container := \
+ tst-initgroups1 \
+ tst-initgroups2 \
tst-nss-compat1 \
tst-nss-db-endgrent \
tst-nss-db-endpwent \
@@ -112,13 +145,21 @@ tests-container := \
tst-reload2 \
# tests-container
-# Tests which need libdl
ifeq (yes,$(build-shared))
+# Tests which need libdl
tests += tst-nss-files-hosts-erange
tests += tst-nss-files-hosts-multi
tests += tst-nss-files-hosts-getent
tests += tst-nss-files-alias-leak
tests += tst-nss-files-alias-truncated
+# tst_fgetgrent currently only works with shared libraries
+test-srcs := tst_fgetgrent
+ifeq ($(run-built-tests),yes)
+tests-special += $(objpfx)tst_fgetgrent.out
+$(objpfx)tst_fgetgrent.out: tst_fgetgrent.sh $(objpfx)tst_fgetgrent
+ $(SHELL) $< $(common-objpfx) '$(test-program-prefix)'; \
+ $(evaluate-test)
+endif
endif
# If we have a thread library then we can test cancellation against
diff --git a/nss/Versions b/nss/Versions
index e551524aa9..5401829911 100644
--- a/nss/Versions
+++ b/nss/Versions
@@ -5,10 +5,38 @@ libc {
# Functions exported as no-op compat symbols.
__nss_passwd_lookup; __nss_group_lookup; __nss_hosts_lookup; __nss_next;
__nss_database_lookup;
+
+ # e*
+ endgrent;
+
+ # f*
+ fgetgrent; fgetgrent_r;
+
+ # g*
+ getgrent; getgrent_r; getgrgid; getgrgid_r; getgrnam; getgrnam_r;
+ getgroups;
+
+ # i*
+ initgroups;
+
+ # s*
+ setgrent;
+ }
+ GLIBC_2.1 {
+ # p*
+ putgrent;
+ }
+ GLIBC_2.1.2 {
+ # g*
+ getgrent_r; getgrgid_r; getgrnam_r;
}
GLIBC_2.2.2 {
__nss_hostname_digits_dots;
}
+ GLIBC_2.2.4 {
+ # g*
+ getgrouplist;
+ }
GLIBC_2.27 {
}
GLIBC_PRIVATE {
@@ -107,6 +135,8 @@ libc {
_nss_files_initgroups_dyn;
_nss_files_init;
+
+ __merge_grp; __copy_grp;
}
}
diff --git a/nss/fgetgrent.c b/nss/fgetgrent.c
new file mode 100644
index 0000000000..2e7c7fe5fb
--- /dev/null
+++ b/nss/fgetgrent.c
@@ -0,0 +1,87 @@
+/* Copyright (C) 1991-2023 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+#include <errno.h>
+#include <grp.h>
+#include <libc-lock.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <set-freeres.h>
+
+
+/* We need to protect the dynamic buffer handling. */
+__libc_lock_define_initialized (static, lock);
+
+static char *buffer;
+
+/* Read one entry from the given stream. */
+struct group *
+fgetgrent (FILE *stream)
+{
+ static size_t buffer_size;
+ static struct group resbuf;
+ fpos_t pos;
+ struct group *result;
+ int save;
+
+ if (__builtin_expect (fgetpos (stream, &pos), 0) != 0)
+ return NULL;
+
+ /* Get lock. */
+ __libc_lock_lock (lock);
+
+ /* Allocate buffer if not yet available. */
+ if (buffer == NULL)
+ {
+ buffer_size = NSS_BUFLEN_GROUP;
+ buffer = malloc (buffer_size);
+ }
+
+ while (buffer != NULL
+ && (__fgetgrent_r (stream, &resbuf, buffer, buffer_size, &result)
+ == ERANGE))
+ {
+ char *new_buf;
+ buffer_size += NSS_BUFLEN_GROUP;
+ new_buf = realloc (buffer, buffer_size);
+ if (__glibc_unlikely (new_buf == NULL))
+ {
+ /* We are out of memory. Free the current buffer so that the
+ process gets a chance for a normal termination. */
+ save = errno;
+ free (buffer);
+ __set_errno (save);
+ }
+ buffer = new_buf;
+
+ /* Reset the stream. */
+ if (fsetpos (stream, &pos) != 0)
+ buffer = NULL;
+ }
+
+ if (buffer == NULL)
+ result = NULL;
+
+ /* Release lock. Preserve error value. */
+ save = errno;
+ __libc_lock_unlock (lock);
+ __set_errno (save);
+
+ return result;
+}
+
+weak_alias (buffer, __libc_fgetgrent_freemem_ptr)
diff --git a/nss/fgetgrent_r.c b/nss/fgetgrent_r.c
new file mode 100644
index 0000000000..5ce70230f1
--- /dev/null
+++ b/nss/fgetgrent_r.c
@@ -0,0 +1,65 @@
+/* Copyright (C) 1991-2023 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+#include <ctype.h>
+#include <errno.h>
+#include <grp.h>
+#include <stdio.h>
+
+/* Define a line parsing function using the common code
+ used in the nss_files module. */
+
+#define STRUCTURE group
+#define ENTNAME grent
+struct grent_data {};
+
+#define TRAILING_LIST_MEMBER gr_mem
+#define TRAILING_LIST_SEPARATOR_P(c) ((c) == ',')
+#include <nss/nss_files/files-parse.c>
+LINE_PARSER
+(,
+ STRING_FIELD (result->gr_name, ISCOLON, 0);
+ if (line[0] == '\0'
+ && (result->gr_name[0] == '+' || result->gr_name[0] == '-'))
+ {
+ result->gr_passwd = NULL;
+ result->gr_gid = 0;
+ }
+ else
+ {
+ STRING_FIELD (result->gr_passwd, ISCOLON, 0);
+ if (result->gr_name[0] == '+' || result->gr_name[0] == '-')
+ INT_FIELD_MAYBE_NULL (result->gr_gid, ISCOLON, 0, 10, , 0)
+ else
+ INT_FIELD (result->gr_gid, ISCOLON, 0, 10,)
+ }
+ )
+
+
+/* Read one entry from the given stream. */
+int
+__fgetgrent_r (FILE *stream, struct group *resbuf, char *buffer, size_t buflen,
+ struct group **result)
+{
+ int ret = __nss_fgetent_r (stream, resbuf, buffer, buflen, parse_line);
+ if (ret == 0)
+ *result = resbuf;
+ else
+ *result = NULL;
+ return ret;
+}
+weak_alias (__fgetgrent_r, fgetgrent_r)
diff --git a/nss/getgrent.c b/nss/getgrent.c
new file mode 100644
index 0000000000..6e09987318
--- /dev/null
+++ b/nss/getgrent.c
@@ -0,0 +1,28 @@
+/* Copyright (C) 1996-2023 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+#include <grp.h>
+
+
+#define LOOKUP_TYPE struct group
+#define SETFUNC_NAME setgrent
+#define GETFUNC_NAME getgrent
+#define ENDFUNC_NAME endgrent
+#define DATABASE_NAME group
+#define BUFLEN NSS_BUFLEN_GROUP
+
+#include "../nss/getXXent.c"
diff --git a/nss/getgrent_r.c b/nss/getgrent_r.c
new file mode 100644
index 0000000000..ea3d0e89c1
--- /dev/null
+++ b/nss/getgrent_r.c
@@ -0,0 +1,28 @@
+/* Copyright (C) 1996-2023 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+#include <grp.h>
+
+
+#define LOOKUP_TYPE struct group
+#define SETFUNC_NAME setgrent
+#define GETFUNC_NAME getgrent
+#define ENDFUNC_NAME endgrent
+#define DATABASE_NAME group
+#define BUFLEN NSS_BUFLEN_GROUP
+
+#include "../nss/getXXent_r.c"
diff --git a/nss/getgrgid.c b/nss/getgrgid.c
new file mode 100644
index 0000000000..db50f8fdac
--- /dev/null
+++ b/nss/getgrgid.c
@@ -0,0 +1,28 @@
+/* Copyright (C) 1996-2023 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+#include <grp.h>
+
+
+#define LOOKUP_TYPE struct group
+#define FUNCTION_NAME getgrgid
+#define DATABASE_NAME group
+#define ADD_PARAMS gid_t gid
+#define ADD_VARIABLES gid
+#define BUFLEN NSS_BUFLEN_GROUP
+
+#include "../nss/getXXbyYY.c"
diff --git a/nss/getgrgid_r.c b/nss/getgrgid_r.c
new file mode 100644
index 0000000000..dab5f85ef3
--- /dev/null
+++ b/nss/getgrgid_r.c
@@ -0,0 +1,31 @@
+/* Copyright (C) 1996-2023 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+#include <grp.h>
+
+#include <grp-merge.h>
+
+#define LOOKUP_TYPE struct group
+#define FUNCTION_NAME getgrgid
+#define DATABASE_NAME group
+#define ADD_PARAMS gid_t gid
+#define ADD_VARIABLES gid
+#define BUFLEN NSS_BUFLEN_GROUP
+#define DEEPCOPY_FN __copy_grp
+#define MERGE_FN __merge_grp
+
+#include <nss/getXXbyYY_r.c>
diff --git a/nss/getgrnam.c b/nss/getgrnam.c
new file mode 100644
index 0000000000..98d637b2bc
--- /dev/null
+++ b/nss/getgrnam.c
@@ -0,0 +1,28 @@
+/* Copyright (C) 1996-2023 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+#include <grp.h>
+
+
+#define LOOKUP_TYPE struct group
+#define FUNCTION_NAME getgrnam
+#define DATABASE_NAME group
+#define ADD_PARAMS const char *name
+#define ADD_VARIABLES name
+#define BUFLEN NSS_BUFLEN_GROUP
+
+#include "../nss/getXXbyYY.c"
diff --git a/nss/getgrnam_r.c b/nss/getgrnam_r.c
new file mode 100644
index 0000000000..ed5649c8d8
--- /dev/null
+++ b/nss/getgrnam_r.c
@@ -0,0 +1,31 @@
+/* Copyright (C) 1996-2023 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+#include <grp.h>
+
+#include <grp-merge.h>
+
+#define LOOKUP_TYPE struct group
+#define FUNCTION_NAME getgrnam
+#define DATABASE_NAME group
+#define ADD_PARAMS const char *name
+#define ADD_VARIABLES name
+
+#define DEEPCOPY_FN __copy_grp
+#define MERGE_FN __merge_grp
+
+#include <nss/getXXbyYY_r.c>
diff --git a/nss/grp-merge.c b/nss/grp-merge.c
new file mode 100644
index 0000000000..991abf0252
--- /dev/null
+++ b/nss/grp-merge.c
@@ -0,0 +1,200 @@