aboutsummaryrefslogtreecommitdiff
path: root/grp
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 /grp
parent83d13972f23546758b600ba940e0d53248dd0339 (diff)
downloadglibc-b121fdc552f392cd86b21f159dd3e3b998de91a3.zip
glibc-b121fdc552f392cd86b21f159dd3e3b998de91a3.tar.gz
glibc-b121fdc552f392cd86b21f159dd3e3b998de91a3.tar.bz2
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 'grp')
-rw-r--r--grp/Makefile70
-rw-r--r--grp/Versions34
-rw-r--r--grp/compat-initgroups.c116
-rw-r--r--grp/fgetgrent.c87
-rw-r--r--grp/fgetgrent_r.c65
-rw-r--r--grp/getgrent.c28
-rw-r--r--grp/getgrent_r.c28
-rw-r--r--grp/getgrgid.c28
-rw-r--r--grp/getgrgid_r.c31
-rw-r--r--grp/getgrnam.c28
-rw-r--r--grp/getgrnam_r.c31
-rw-r--r--grp/grp-merge.c200
-rw-r--r--grp/grp-merge.h35
-rw-r--r--grp/grp.h207
-rw-r--r--grp/initgroups.c218
-rw-r--r--grp/putgrent.c76
-rw-r--r--grp/setgroups.c31
-rw-r--r--grp/testgrp.c41
-rw-r--r--grp/tst-initgroups1.c56
-rw-r--r--grp/tst-initgroups1.root/etc/group7
-rw-r--r--grp/tst-initgroups1.root/etc/nsswitch.conf1
-rw-r--r--grp/tst-initgroups1.root/etc/passwd1
-rw-r--r--grp/tst-initgroups2.c21
-rw-r--r--grp/tst-initgroups2.root/etc/group7
-rw-r--r--grp/tst-initgroups2.root/etc/nsswitch.conf2
-rw-r--r--grp/tst-initgroups2.root/etc/passwd1
-rw-r--r--grp/tst-putgrent.c167
-rw-r--r--grp/tst_fgetgrent.c126
-rw-r--r--grp/tst_fgetgrent.sh40
29 files changed, 0 insertions, 1783 deletions
diff --git a/grp/Makefile b/grp/Makefile
deleted file mode 100644
index 38006fb..0000000
--- a/grp/Makefile
+++ /dev/null
@@ -1,70 +0,0 @@
-# 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/>.
-
-#
-# Sub-makefile for grp portion of the library.
-#
-subdir := grp
-
-include ../Makeconfig
-
-headers := grp.h
-
-routines := fgetgrent initgroups setgroups \
- getgrent getgrgid getgrnam putgrent \
- getgrent_r getgrgid_r getgrnam_r fgetgrent_r \
- grp-merge
-
-tests := testgrp tst-putgrent
-
-tests-container = \
- tst-initgroups1 \
- tst-initgroups2
-
-ifeq (yes,$(build-shared))
-test-srcs := tst_fgetgrent
-ifeq ($(run-built-tests),yes)
-tests-special += $(objpfx)tst_fgetgrent.out
-endif
-endif
-
-
-include ../Rules
-
-ifeq ($(have-thread-library),yes)
-
-CFLAGS-getgrgid_r.c += -fexceptions
-CFLAGS-getgrnam_r.c += -fexceptions
-CFLAGS-getgrent_r.c += -fexceptions
-CFLAGS-getgrent.c += -fexceptions
-CFLAGS-fgetgrent.c += -fexceptions
-CFLAGS-fgetgrent_r.c += -fexceptions $(libio-mtsafe)
-CFLAGS-putgrent.c += -fexceptions $(libio-mtsafe)
-CFLAGS-initgroups.c += -fexceptions
-CFLAGS-getgrgid.c += -fexceptions
-
-endif
-
-ifeq ($(run-built-tests),yes)
-# tst_fgetgrent currently only works with shared libraries
-ifeq (yes,$(build-shared))
-$(objpfx)tst_fgetgrent.out: tst_fgetgrent.sh $(objpfx)tst_fgetgrent
- $(SHELL) $< $(common-objpfx) '$(test-program-prefix)'; \
- $(evaluate-test)
-
-endif
-endif
diff --git a/grp/Versions b/grp/Versions
deleted file mode 100644
index 096caa4..0000000
--- a/grp/Versions
+++ /dev/null
@@ -1,34 +0,0 @@
-libc {
- GLIBC_2.0 {
- # e*
- endgrent;
-
- # f*
- fgetgrent; fgetgrent_r;
-
- # g*
- getgrent; getgrent_r; getgrgid; getgrgid_r; getgrnam; getgrnam_r;
- getgroups;
-
- # i*
- initgroups;
-
- # s*
- setgrent; setgroups;
- }
- GLIBC_2.1 {
- # p*
- putgrent;
- }
- GLIBC_2.1.2 {
- # g*
- getgrent_r; getgrgid_r; getgrnam_r;
- }
- GLIBC_2.2.4 {
- # g*
- getgrouplist;
- }
- GLIBC_PRIVATE {
- __merge_grp; __copy_grp;
- }
-}
diff --git a/grp/compat-initgroups.c b/grp/compat-initgroups.c
deleted file mode 100644
index 9df9407..0000000
--- a/grp/compat-initgroups.c
+++ /dev/null
@@ -1,116 +0,0 @@
-/* Prototype for the setgrent functions we use here. */
-typedef enum nss_status (*set_function) (void);
-
-/* Prototype for the endgrent functions we use here. */
-typedef enum nss_status (*end_function) (void);
-
-/* Prototype for the setgrent functions we use here. */
-typedef enum nss_status (*get_function) (struct group *, char *,
- size_t, int *);
-
-
-static enum nss_status
-compat_call (nss_action_list nip, const char *user, gid_t group, long int *start,
- long int *size, gid_t **groupsp, long int limit, int *errnop)
-{
- struct group grpbuf;
- enum nss_status status;
- set_function setgrent_fct;
- get_function getgrent_fct;
- end_function endgrent_fct;
- gid_t *groups = *groupsp;
-
- getgrent_fct = __nss_lookup_function (nip, "getgrent_r");
- if (getgrent_fct == NULL)
- return NSS_STATUS_UNAVAIL;
-
- setgrent_fct = __nss_lookup_function (nip, "setgrent");
- if (setgrent_fct)
- {
- status = DL_CALL_FCT (setgrent_fct, ());
- if (status != NSS_STATUS_SUCCESS)
- return status;
- }
-
- endgrent_fct = __nss_lookup_function (nip, "endgrent");
-
- struct scratch_buffer tmpbuf;
- scratch_buffer_init (&tmpbuf);
- enum nss_status result = NSS_STATUS_SUCCESS;
-
- do
- {
- while ((status = DL_CALL_FCT (getgrent_fct,
- (&grpbuf, tmpbuf.data, tmpbuf.length,
- errnop)),
- status == NSS_STATUS_TRYAGAIN)
- && *errnop == ERANGE)
- {
- if (!scratch_buffer_grow (&tmpbuf))
- {
- result = NSS_STATUS_TRYAGAIN;
- goto done;
- }
- }
-
- if (status != NSS_STATUS_SUCCESS)
- goto done;
-
- if (grpbuf.gr_gid != group)
- {
- char **m;
-
- for (m = grpbuf.gr_mem; *m != NULL; ++m)
- if (strcmp (*m, user) == 0)
- {
- /* Check whether the group is already on the list. */
- long int cnt;
- for (cnt = 0; cnt < *start; ++cnt)
- if (groups[cnt] == grpbuf.gr_gid)
- break;
-
- if (cnt == *start)
- {
- /* Matches user and not yet on the list. Insert
- this group. */
- if (__glibc_unlikely (*start == *size))
- {
- /* Need a bigger buffer. */
- gid_t *newgroups;
- long int newsize;
-
- if (limit > 0 && *size == limit)
- /* We reached the maximum. */
- goto done;
-
- if (limit <= 0)
- newsize = 2 * *size;
- else
- newsize = MIN (limit, 2 * *size);
-
- newgroups = realloc (groups,
- newsize * sizeof (*groups));
- if (newgroups == NULL)
- goto done;
- *groupsp = groups = newgroups;
- *size = newsize;
- }
-
- groups[*start] = grpbuf.gr_gid;
- *start += 1;
- }
-
- break;
- }
- }
- }
- while (status == NSS_STATUS_SUCCESS);
-
- done:
- scratch_buffer_free (&tmpbuf);
-
- if (endgrent_fct)
- DL_CALL_FCT (endgrent_fct, ());
-
- return result;
-}
diff --git a/grp/fgetgrent.c b/grp/fgetgrent.c
deleted file mode 100644
index 2e7c7fe..0000000
--- a/grp/fgetgrent.c
+++ /dev/null
@@ -1,87 +0,0 @@
-/* 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/grp/fgetgrent_r.c b/grp/fgetgrent_r.c
deleted file mode 100644
index 5ce7023..0000000
--- a/grp/fgetgrent_r.c
+++ /dev/null
@@ -1,65 +0,0 @@
-/* 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/grp/getgrent.c b/grp/getgrent.c
deleted file mode 100644
index 6e09987..0000000
--- a/grp/getgrent.c
+++ /dev/null
@@ -1,28 +0,0 @@
-/* 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/grp/getgrent_r.c b/grp/getgrent_r.c
deleted file mode 100644
index ea3d0e8..0000000
--- a/grp/getgrent_r.c
+++ /dev/null
@@ -1,28 +0,0 @@
-/* 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/grp/getgrgid.c b/grp/getgrgid.c
deleted file mode 100644
index db50f8f..0000000
--- a/grp/getgrgid.c
+++ /dev/null
@@ -1,28 +0,0 @@
-/* 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/grp/getgrgid_r.c b/grp/getgrgid_r.c
deleted file mode 100644
index dab5f85..0000000
--- a/grp/getgrgid_r.c
+++ /dev/null
@@ -1,31 +0,0 @@
-/* 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/grp/getgrnam.c b/grp/getgrnam.c
deleted file mode 100644
index 98d637b..0000000
--- a/grp/getgrnam.c
+++ /dev/null
@@ -1,28 +0,0 @@
-/* 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/grp/getgrnam_r.c b/grp/getgrnam_r.c
deleted file mode 100644
index ed5649c..0000000
--- a/grp/getgrnam_r.c
+++ /dev/null
@@ -1,31 +0,0 @@
-/* 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/grp/grp-merge.c b/grp/grp-merge.c
deleted file mode 100644
index 991abf0..0000000
--- a/grp/grp-merge.c
+++ /dev/null
@@ -1,200 +0,0 @@
-/* Group merging implementation.
- Copyright (C) 2016-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 <stdlib.h>
-#include <string.h>
-#include <grp.h>
-#include <grp-merge.h>
-
-#define BUFCHECK(size) \
- ({ \
- do \
- { \
- if (c + (size) > buflen) \
- { \
- free (members); \
- return ERANGE; \
- } \
- } \
- while (0); \
- })
-
-int
-__copy_grp (const struct group srcgrp, const size_t buflen,
- struct group *destgrp, char *destbuf, char **endptr)
-{
- size_t i;
- size_t c = 0;
- size_t len;
- size_t memcount;
- char **members = NULL;
-
- /* Copy the GID. */
- destgrp->gr_gid = srcgrp.gr_gid;
-
- /* Copy the name. */
- len = strlen (srcgrp.gr_name) + 1;
- BUFCHECK (len);
- memcpy (&destbuf[c], srcgrp.gr_name, len);
- destgrp->gr_name = &destbuf[c];
- c += len;
-
- /* Copy the password. */
- len = strlen (srcgrp.gr_passwd) + 1;
- BUFCHECK (len);
- memcpy (&destbuf[c], srcgrp.gr_passwd, len);
- destgrp->gr_passwd = &destbuf[c];
- c += len;
-
- /* Count all of the members. */
- for (memcount = 0; srcgrp.gr_mem[memcount]; memcount++)
- ;
-
- /* Allocate a temporary holding area for the pointers to the member
- contents, including space for a NULL-terminator. */
- members = malloc (sizeof (char *) * (memcount + 1));
- if (members == NULL)
- return ENOMEM;
-
- /* Copy all of the group members to destbuf and add a pointer to each of
- them into the 'members' array. */
- for (i = 0; srcgrp.gr_mem[i]; i++)
- {
- len = strlen (srcgrp.gr_mem[i]) + 1;
- BUFCHECK (len);
- memcpy (&destbuf[c], srcgrp.gr_mem[i], len);
- members[i] = &destbuf[c];
- c += len;
- }
- members[i] = NULL;
-
- /* Align for pointers. We can't simply align C because we need to
- align destbuf[c]. */
- if ((((uintptr_t)destbuf + c) & (__alignof__(char **) - 1)) != 0)
- {
- uintptr_t mis_align = ((uintptr_t)destbuf + c) & (__alignof__(char **) - 1);
- c += __alignof__(char **) - mis_align;
- }
-
- /* Copy the pointers from the members array into the buffer and assign them
- to the gr_mem member of destgrp. */
- destgrp->gr_mem = (char **) &destbuf[c];
- len = sizeof (char *) * (memcount + 1);
- BUFCHECK (len);
- memcpy (&destbuf[c], members, len);
- c += len;
- free (members);
- members = NULL;
-
- /* Save the count of members at the end. */
- BUFCHECK (sizeof (size_t));
- memcpy (&destbuf[c], &memcount, sizeof (size_t));
- c += sizeof (size_t);
-
- if (endptr)
- *endptr = destbuf + c;
- return 0;
-}
-libc_hidden_def (__copy_grp)
-
-/* Check that the name, GID and passwd fields match, then
- copy in the gr_mem array. */
-int
-__merge_grp (struct group *savedgrp, char *savedbuf, char *savedend,
- size_t buflen, struct group *mergegrp, char *mergebuf)
-{
- size_t c, i, len;
- size_t savedmemcount;
- size_t memcount;
- size_t membersize;
- char **members = NULL;
-
- /* We only support merging members of groups with identical names and
- GID values. If we hit this case, we need to overwrite the current
- buffer with the saved one (which is functionally equivalent to
- treating the new lookup as NSS_STATUS_NOTFOUND). */
- if (mergegrp->gr_gid != savedgrp->gr_gid
- || strcmp (mergegrp->gr_name, savedgrp->gr_name))
- return __copy_grp (*savedgrp, buflen, mergegrp, mergebuf, NULL);
-
- /* Get the count of group members from the last sizeof (size_t) bytes in the
- mergegrp buffer. */
- savedmemcount = *(size_t *) (savedend - sizeof (size_t));
-
- /* Get the count of new members to add. */
- for (memcount = 0; mergegrp->gr_mem[memcount]; memcount++)
- ;
-
- /* Create a temporary array to hold the pointers to the member values from
- both the saved and merge groups. */
- membersize = savedmemcount + memcount + 1;
- members = malloc (sizeof (char *) * membersize);
- if (members == NULL)
- return ENOMEM;
-
- /* Copy in the existing member pointers from the saved group
- Note: this is not NULL-terminated yet. */
- memcpy (members, savedgrp->gr_mem, sizeof (char *) * savedmemcount);
-
- /* Back up into the savedbuf until we get back to the NULL-terminator of the
- group member list. (This means walking back savedmemcount + 1 (char *) pointers
- and the member count value.
- The value of c is going to be the used length of the buffer backed up by
- the member count and further backed up by the size of the pointers. */
- c = savedend - savedbuf
- - sizeof (size_t)
- - sizeof (char *) * (savedmemcount + 1);
-
- /* Add all the new group members, overwriting the old NULL-terminator while
- adding the new pointers to the temporary array. */
- for (i = 0; mergegrp->gr_mem[i]; i++)
- {
- len = strlen (mergegrp->gr_mem[i]) + 1;
- BUFCHECK (len);
- memcpy (&savedbuf[c], mergegrp->gr_mem[i], len);
- members[savedmemcount + i] = &savedbuf[c];
- c += len;
- }
- /* Add the NULL-terminator. */
- members[savedmemcount + memcount] = NULL;
-
- /* Align for pointers. We can't simply align C because we need to
- align savedbuf[c]. */
- if ((((uintptr_t)savedbuf + c) & (__alignof__(char **) - 1)) != 0)
- {
- uintptr_t mis_align = ((uintptr_t)savedbuf + c) & (__alignof__(char **) - 1);
- c += __alignof__(char **) - mis_align;
- }
-
- /* Copy the member array back into the buffer after the member list and free
- the member array. */
- savedgrp->gr_mem = (char **) &savedbuf[c];
- len = sizeof (char *) * membersize;
- BUFCHECK (len);
- memcpy (&savedbuf[c], members, len);
- c += len;
-
- free (members);
- members = NULL;
-
- /* Finally, copy the results back into mergebuf, since that's the buffer
- that we were provided by the caller. */
- return __copy_grp (*savedgrp, buflen, mergegrp, mergebuf, NULL);
-}
-libc_hidden_def (__merge_grp)
diff --git a/grp/grp-merge.h b/grp/grp-merge.h
deleted file mode 100644
index 9e1f75c..0000000
--- a/grp/grp-merge.h
+++ /dev/null
@@ -1,35 +0,0 @@
-/* Group merging implementation.
- Copyright (C) 2016-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/>. */
-
-#ifndef _GRP_MERGE_H
-#define _GRP_MERGE_H 1
-
-#include <grp.h>
-
-/* Duplicate a grp struct (and its members). When no longer needed, the
- calling function must free(newbuf). */
-int
-__copy_grp (const struct group srcgrp, const size_t buflen,
- struct group *destgrp, char *destbuf, char **endptr);
-
-/* Merge the member lists of two grp structs together. */
-int
-__merge_grp (struct group *savedgrp, char *savedbuf, char *savedend,
- size_t buflen, struct group *mergegrp, char *mergebuf);
-
-#endif /* _GRP_MERGE_H */
diff --git a/grp/grp.h b/grp/grp.h
deleted file mode 100644
index c889647..0000000
--- a/grp/grp.h
+++ /dev/null
@@ -1,207 +0,0 @@
-/* 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/>. */
-
-/*
- * POSIX Standard: 9.2.1 Group Database Access <grp.h>
- */
-
-#ifndef _GRP_H
-#define _GRP_H 1
-
-#include <features.h>
-
-__BEGIN_DECLS
-
-#include <bits/types.h>
-
-#define __need_size_t
-#include <stddef.h>
-
-
-/* For the Single Unix specification we must define this type here. */
-#if (defined __USE_XOPEN || defined __USE_XOPEN2K) && !defined __gid_t_defined
-typedef __gid_t gid_t;
-# define __gid_t_defined
-#endif
-
-/* The group structure. */
-struct group
- {
- char *gr_name; /* Group name. */
- char *gr_passwd; /* Password. */
- __gid_t gr_gid; /* Group ID. */
- char **gr_mem; /* Member list. */
- };
-
-
-#ifdef __USE_MISC
-# include <bits/types/FILE.h>
-#endif
-
-
-#if defined __USE_MISC || defined __USE_XOPEN_EXTENDED
-/* Rewind the group-file stream.
-
- This function is a possible cancellation point and therefore not
- marked with __THROW. */
-extern void setgrent (void);
-
-/* Close the group-file stream.
-
- This function is a possible cancellation point and therefore not
- marked with __THROW. */
-extern void endgrent (void);
-
-/* Read an entry from the group-file stream, opening it if necessary.
-
- This function is a possible cancellation point and therefore not
- marked with __THROW. */
-extern struct group *getgrent (void);
-#endif
-
-#ifdef __USE_MISC
-/* Read a group entry from STREAM.
-
- This function is not part of POSIX and therefore no official
- cancellation point. But due to similarity with an POSIX interface
- or due to the implementation it is a cancellation point and
- therefore not marked with __THROW. */
-extern struct group *fgetgrent (FILE *__stream);
-#endif
-
-#ifdef __USE_GNU
-/* Write the given entry onto the given stream.
-
- This function is not part of POSIX and therefore no official
- cancellation point. But due to similarity with an POSIX interface
- or due to the implementation it is a cancellation point and
- therefore not marked with __THROW. */
-extern int putgrent (const struct group *__restrict __p,
- FILE *__restrict __f);
-#endif
-
-/* Search for an entry with a matching group ID.
-
- This function is a possible cancellation point and therefore not
- marked with __THROW. */
-extern struct group *getgrgid (__gid_t __gid);
-
-/* Search for an entry with a matching group name.
-
- This function is a possible cancellation point and therefore not
- marked with __THROW. */
-extern struct group *getgrnam (const char *__name);
-
-#ifdef __USE_POSIX
-
-# ifdef __USE_MISC
-/* Reasonable value for the buffer sized used in the reentrant
- functions below. But better use `sysconf'. */
-# define NSS_BUFLEN_GROUP 1024
-# endif
-
-/* Reentrant versions of some of the functions above.
-
- PLEASE NOTE: the `getgrent_r' function is not (yet) standardized.
- The interface may change in later versions of this library. But
- the interface is designed following the principals used for the
- other reentrant functions so the chances are good this is what the
- POSIX people would choose.
-
- This function is not part of POSIX and therefore no official
- cancellation point. But due to similarity with an POSIX interface
- or due to the implementation it is a cancellation point and
- therefore not marked with __THROW. */
-
-# ifdef __USE_GNU
-extern int getgrent_r (struct group *__restrict __resultbuf,
- char *__restrict __buffer, size_t __buflen,
- struct group **__restrict __result)
- __attr_access ((__write_only__, 2, 3));
-# endif
-
-/* Search for an entry with a matching group ID.
-
- This function is a possible cancellation point and therefore not
- marked with __THROW. */
-extern int getgrgid_r (__gid_t __gid, struct group *__restrict __resultbuf,
- char *__restrict __buffer, size_t __buflen,
- struct group **__restrict __result)
- __attr_access ((__write_only__, 3, 4));
-
-/* Search for an entry with a matching group name.
-
- This function is a possible cancellation point and therefore not
- marked with __THROW. */
-extern int getgrnam_r (const char *__restrict __name,
- struct group *__restrict __resultbuf,
- char *__restrict __buffer, size_t __buflen,
- struct group **__restrict __result)
- __attr_access ((__write_only__, 3, 4));
-
-# ifdef __USE_MISC
-/* Read a group entry from STREAM. This function is not standardized
- an probably never will.
-
- This function is not part of POSIX and therefore no official
- cancellation point. But due to similarity with an POSIX interface
- or due to the implementation it is a cancellation point and
- therefore not marked with __THROW. */
-extern int fgetgrent_r (FILE *__restrict __stream,
- struct group *__restrict __resultbuf,
- char *__restrict __buffer, size_t __buflen,
- struct group **__restrict __result)
- __attr_access ((__write_only__, 3, 4));
-# endif
-
-#endif /* POSIX or reentrant */
-
-
-#ifdef __USE_MISC
-
-# define __need_size_t
-# include <stddef.h>
-
-/* Set the group set for the current user to GROUPS (N of them). */
-extern int setgroups (size_t __n, const __gid_t *__groups) __THROW;
-
-/* Store at most *NGROUPS members of the group set for USER into
- *GROUPS. Also include GROUP. The actual number of groups found is
- returned in *NGROUPS. Return -1 if the if *NGROUPS is too small.
-
- This function is not part of POSIX and therefore no official
- cancellation point. But due to similarity with an POSIX interface
- or due to the implementation it is a cancellation point and
- therefore not marked with __THROW. */
-extern int getgrouplist (const char *__user, __gid_t __group,
- __gid_t *__groups, int *__ngroups);
-
-/* Initialize the group set for the current user
- by reading the group database and using all groups
- of which USER is a member. Also include GROUP.
-
- This function is not part of POSIX and therefore no official
- cancellation point. But due to similarity with an POSIX interface
- or due to the implementation it is a cancellation point and
- therefore not marked with __THROW. */
-extern int initgroups (const char *__user, __gid_t __group);
-
-#endif /* Use misc. */
-
-__END_DECLS
-
-#endif /* grp.h */
diff --git a/grp/initgroups.c b/grp/initgroups.c
deleted file mode 100644
index 2ebd623..0000000
--- a/grp/initgroups.c
+++ /dev/null
@@ -1,218 +0,0 @@
-/* Copyright (C) 1989, 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 <assert.h>
-#include <errno.h>
-#include <grp.h>
-#include <limits.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <sys/param.h>
-#include <sys/types.h>
-#include <nsswitch.h>
-#include <scratch_buffer.h>
-#include <config.h>
-
-#include "../nscd/nscd-client.h"
-#include "../nscd/nscd_proto.h"
-
-/* Type of the lookup function. */
-typedef enum nss_status (*initgroups_dyn_function) (const char *, gid_t,
- long int *, long int *,
- gid_t **, long int, int *);
-
-static bool use_initgroups_entry;
-
-
-#include "compat-initgroups.c"
-
-
-static int
-internal_getgrouplist (const char *user, gid_t group, long int *size,
- gid_t **groupsp, long int limit)
-{
-#ifdef USE_NSCD
- if (__nss_not_use_nscd_group > 0
- && ++__nss_not_use_nscd_group > NSS_NSCD_RETRY)
- __nss_not_use_nscd_group = 0;
- if (!__nss_not_use_nscd_group
- && !__nss_database_custom[NSS_DBSIDX_group])
- {
- int n = __nscd_getgrouplist (user, group, size, groupsp, limit);
- if (n >= 0)
- return n;
-
- /* nscd is not usable. */
- __nss_not_use_nscd_group = 1;
- }
-#endif
-
- enum nss_status status = NSS_STATUS_UNAVAIL;
-
- /* Never store more than the starting *SIZE number of elements. */
- assert (*size > 0);
- (*groupsp)[0] = group;
- /* Start is one, because we have the first group as parameter. */
- long int start = 1;
-
- nss_action_list nip;
-
- if (__nss_database_get (nss_database_initgroups, &nip)
- && nip != NULL)
- {
- use_initgroups_entry = true;
- }
- else if (__nss_database_get (nss_database_group, &nip)
- && nip != NULL)
- {
- use_initgroups_entry = false;
- }
- else
- {
- nip = __nss_action_parse ("files");
- use_initgroups_entry = false;
- }
-
- while (nip && nip->module)
- {
- long int prev_start = start;
-
- initgroups_dyn_function fct = __nss_lookup_function (nip,
- "initgroups_dyn");
- if (fct == NULL)
- status = compat_call (nip, user, group, &start, size, groupsp,
- limit, &errno);
- else
- status = DL_CALL_FCT (fct, (user, group, &start, size, groupsp,
- limit, &errno));
-
- /* Remove duplicates. */
- long int cnt = prev_start;
- while (cnt < start)
- {
- long int inner;
- for (inner = 0; inner < prev_start; ++inner)
- if ((*groupsp)[inner] == (*groupsp)[cnt])
- break;
-
- if (inner < prev_start)
- (*groupsp)[cnt] = (*groupsp)[--start];
- else
- ++cnt;
- }
-
- /* This is really only for debugging. */
- if (NSS_STATUS_TRYAGAIN > status || status > NSS_STATUS_RETURN)
- __libc_fatal ("Illegal status in internal_getgrouplist.\n");
-
- /* For compatibility reason we will continue to look for more
- entries using the next service even though data has already
- been found if the nsswitch.conf file contained only a 'groups'
- line and no 'initgroups' line. If the latter is available
- we always respect the status. This means that the default
- for successful lookups is to return. */
- if ((use_initgroups_entry || status != NSS_STATUS_SUCCESS)
- && nss_next_action (nip, status) == NSS_ACTION_RETURN)
- break;
-
- nip++;
- }
-
- return start;
-}
-
-/* Store at most *NGROUPS members of the group set for USER into
- *GROUPS. Also include GROUP. The actual number of groups found is
- returned in *NGROUPS. Return -1 if the if *NGROUPS is too small. */
-int
-getgrouplist (const char *user, gid_t group, gid_t *groups, int *ngroups)
-{
- long int size = MAX (1, *ngroups);
-
- gid_t *newgroups = (gid_t *) malloc (size * sizeof (gid_t));
- if (__glibc_unlikely (newgroups == NULL))
- /* No more memory. */
- // XXX This is wrong. The user provided memory, we have to use
- // XXX it. The internal functions must be called with the user
- // XXX provided buffer and not try to increase the size if it is
- // XXX too small. For initgroups a flag could say: increase size.
- return -1;
-
- int total = internal_getgrouplist (user, group, &size, &newgroups, -1);
-
- memcpy (groups, newgroups, MIN (*ngroups, total) * sizeof (gid_t));
-
- free (newgroups);
-
- int retval = total > *ngroups ? -1 : total;
- *ngroups = total;
-
- return retval;
-}
-
-nss_interface_function (getgrouplist)
-
-/* Initialize the group set for the current user
- by reading the group database and using all groups
- of which USER is a member. Also include GROUP. */
-int
-initgroups (const char *user, gid_t group)
-{
-#if defined NGROUPS_MAX && NGROUPS_MAX == 0
-
- /* No extra groups allowed. */
- return 0;
-
-#else
-
- long int size;
- gid_t *groups;
- int ngroups;
- int result;
-
- /* We always use sysconf even if NGROUPS_MAX is defined. That way, the
- limit can be raised in the kernel configuration without having to
- recompile libc. */
- long int limit = __sysconf (_SC_NGROUPS_MAX);
-
- if (limit > 0)
- /* We limit the size of the initially allocated array. */
- size = MIN (limit, 64);
- else
- /* No fixed limit on groups. Pick a starting buffer size. */
- size = 16;
-
- groups = (gid_t *) malloc (size * sizeof (gid_t));
- if (__glibc_unlikely (groups == NULL))
- /* No more memory. */
- return -1;
-
- ngroups = internal_getgrouplist (user, group, &size, &groups, limit);
-
- /* Try to set the maximum number of groups the kernel can handle. */
- do
- result = setgroups (ngroups, groups);
- while (result == -1 && errno == EINVAL && --ngroups > 0);
-
- free (groups);
-
- return result;
-#endif
-}
-
-nss_interface_function (initgroups)
diff --git a/grp/putgrent.c b/grp/putgrent.c
deleted file mode 100644
index 93caea5..0000000
--- a/grp/putgrent.c
+++ /dev/null
@@ -1,76 +0,0 @@
-/* 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 <nss.h>
-#include <stdio.h>
-#include <string.h>
-#include <grp.h>
-
-#define flockfile(s) _IO_flockfile (s)
-#define funlockfile(s) _IO_funlockfile (s)
-
-#define _S(x) x ? x : ""
-
-/* Write an entry to the given stream.
- This must know the format of the group file. */
-int
-putgrent (const struct group *gr, FILE *stream)
-{
- int retval;
-
- if (__glibc_unlikely (gr == NULL) || __glibc_unlikely (stream == NULL)
- || gr->gr_name == NULL || !__nss_valid_field (gr->gr_name)
- || !__nss_valid_field (gr->gr_passwd)
- || !__nss_valid_list_field (gr->gr_mem))
- {
- __set_errno (EINVAL);
- return -1;
- }
-
- flockfile (stream);
-
- if (gr->gr_name[0] == '+' || gr->gr_name[0] == '-')
- retval = fprintf (stream, "%s:%s::",
- gr->gr_name, _S (gr->gr_passwd));
- else
- retval = fprintf (stream, "%s:%s:%lu:",
- gr->gr_name, _S (gr->gr_passwd),
- (unsigned long int) gr->gr_gid);
- if (__builtin_expect (retval, 0) < 0)
- {
- funlockfile (stream);
- return -1;
- }
-
- if (gr->gr_mem != NULL)
- {
- for (size_t i = 0; gr->gr_mem[i] != NULL; i++)
- if (fprintf (stream, i == 0 ? "%s" : ",%s", gr->gr_mem[i]) < 0)
- {
- /* What else can we do? */
- funlockfile (stream);
- return -1;
- }
- }
-
- retval = fputc_unlocked ('\n', stream);
-
- funlockfile (stream);
-
- return retval < 0 ? -1 : 0;
-}
diff --git a/grp/setgroups.c b/grp/setgroups.c
deleted file mode 100644
index d988866..0000000
--- a/grp/setgroups.c
+++ /dev/null
@@ -1,31 +0,0 @@
-/* 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 <sys/types.h>
-#include <grp.h>
-
-/* Set the group set for the current user to GROUPS (N of them). */
-int
-setgroups (size_t n, const gid_t *groups)
-{
- __set_errno (ENOSYS);
- return -1;
-}
-libc_hidden_def (setgroups)
-
-stub_warning (setgroups)
diff --git a/grp/testgrp.c b/grp/testgrp.c
deleted file mode 100644
index 892cfaa..0000000
--- a/grp/testgrp.c
+++ /dev/null
@@ -1,41 +0,0 @@
-#include <grp.h>
-#include <pwd.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <stdio.h>
-
-int
-main (int argc, char *argv[])
-{
- uid_t me;
- struct passwd *my_passwd;
- struct group *my_group = NULL;
- char **members;
-
- me = getuid ();
- my_passwd = getpwuid (me);
- if (my_passwd == NULL)
- printf ("Cannot find user entry for UID %d\n", me);
- else
- {
- printf ("My login name is %s.\n", my_passwd->pw_name);
- printf ("My uid is %d.\n", (int)(my_passwd->pw_uid));
- printf ("My home directory is %s.\n", my_passwd->pw_dir);
- printf ("My default shell is %s.\n", my_passwd->pw_shell);
-
- my_group = getgrgid (my_passwd->pw_gid);
- if (my_group == NULL)
- printf ("No data for group %d found\n", my_passwd->pw_gid);
- else
- {
- printf ("My default group is %s (%d).\n",
- my_group->gr_name, (int)(my_passwd->pw_gid));
- printf ("The members of this group are:\n");
- for (members = my_group->gr_mem; *members != NULL; ++members)
- printf (" %s\n", *members);
- }
- }
-
- return my_passwd && my_group ? EXIT_SUCCESS : EXIT_FAILURE;
-}
diff --git a/grp/tst-initgroups1.c b/grp/tst-initgroups1.c
deleted file mode 100644
index 3f12388..0000000
--- a/grp/tst-initgroups1.c
+++ /dev/null
@@ -1,56 +0,0 @@
-/* Test that initgroups works.
- Copyright (C) 2020-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 <nss.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/types.h>
-#include <errno.h>
-#include <unistd.h>
-#include <grp.h>
-
-#include <support/support.h>
-#include <support/check.h>
-
-/* Test that initgroups includes secondary groups.
- https://bugzilla.redhat.com/show_bug.cgi?id=1906066 */
-
-/* This version uses the wrapper around the groups module. */
-
-#define EXPECTED_N_GROUPS 4
-static gid_t expected_groups[] =
- { 20, 30, 50, 51 };
-
-static int
-do_test (void)
-{
- gid_t mygroups [50];
- int i, n;
-
- n = 50;
- getgrouplist ("dj", 20, mygroups, &n);
-
- TEST_COMPARE (n, EXPECTED_N_GROUPS);
- for (i=0; i<n; i++)
- TEST_COMPARE (mygroups[i], expected_groups[i]);
-
- return 0;
-}
-
-#include <support/test-driver.c>
diff --git a/grp/tst-initgroups1.root/etc/group b/grp/tst-initgroups1.root/etc/group
deleted file mode 100644
index 0dac1cc..0000000
--- a/grp/tst-initgroups1.root/etc/group
+++ /dev/null
@@ -1,7 +0,0 @@
-abc:x:10:
-def:x:20:
-ghi:x:30:dj
-jkl:x:40:
-m:x:50:not,dj
-n:x:51:dj,not
-np:x:60:djx
diff --git a/grp/tst-initgroups1.root/etc/nsswitch.conf b/grp/tst-initgroups1.root/etc/nsswitch.conf
deleted file mode 100644
index 8d0a1ae..0000000
--- a/grp/tst-initgroups1.root/etc/nsswitch.conf
+++ /dev/null
@@ -1 +0,0 @@
-group : files
diff --git a/grp/tst-initgroups1.root/etc/passwd b/grp/tst-initgroups1.root/etc/passwd
deleted file mode 100644
index 5e3a2a5..0000000
--- a/grp/tst-initgroups1.root/etc/passwd
+++ /dev/null
@@ -1 +0,0 @@
-dj:x:84:20:DJ:/:/bin/sh
diff --git a/grp/tst-initgroups2.c b/grp/tst-initgroups2.c
deleted file mode 100644
index 4e8b8c5..0000000
--- a/grp/tst-initgroups2.c
+++ /dev/null
@@ -1,21 +0,0 @@
-/* Test that initgroups works.
- Copyright (C) 2020-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 "tst-initgroups1.c"
-
-/* This version uses the initgroups built in to the files module. */
diff --git a/grp/tst-initgroups2.root/etc/group b/grp/tst-initgroups2.root/etc/group
deleted file mode 100644
index 0dac1cc..0000000
--- a/grp/tst-initgroups2.root/etc/group
+++ /dev/null
@@ -1,7 +0,0 @@
-abc:x:10:
-def:x:20:
-ghi:x:30:dj
-jkl:x:40:
-m:x:50:not,dj
-n:x:51:dj,not
-np:x:60:djx
diff --git a/grp/tst-initgroups2.root/etc/nsswitch.conf b/grp/tst-initgroups2.root/etc/nsswitch.conf
deleted file mode 100644
index c61f362..0000000
--- a/grp/tst-initgroups2.root/etc/nsswitch.conf
+++ /dev/null
@@ -1,2 +0,0 @@
-initgroups : files
-group : notfiles
diff --git a/grp/tst-initgroups2.root/etc/passwd b/grp/tst-initgroups2.root/etc/passwd
deleted file mode 100644
index 5e3a2a5..0000000
--- a/grp/tst-initgroups2.root/etc/passwd
+++ /dev/null
@@ -1 +0,0 @@
-dj:x:84:20:DJ:/:/bin/sh
diff --git a/grp/tst-putgrent.c b/grp/tst-putgrent.c
deleted file mode 100644
index 79c1486..0000000
--- a/grp/tst-putgrent.c
+++ /dev/null
@@ -1,167 +0,0 @@
-/* Test for processing of invalid group entries. [BZ #18724]
- Copyright (C) 2015-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 <stdbool.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-static bool errors;
-
-static void
-check (struct group e, const char *expected)
-{
- char *buf;
- size_t buf_size;
- FILE *f = open_memstream (&buf, &buf_size);
-
- if (f == NULL)
- {
- printf ("open_memstream: %m\n");
- errors = true;
- return;
- }
-
- int ret = putgrent (&e, f);
-
- if (expected == NULL)
- {
- if (ret == -1)
- {
- if (errno != EINVAL)
- {
- printf ("putgrent: unexpected error code: %m\n");
- errors = true;
- }
- }
- else
- {
- printf ("putgrent: unexpected success (\"%s\", \"%s\")\n",
- e.gr_name, e.gr_passwd);
- errors = true;
- }
- }
- else
- {
- /* Expect success. */
- size_t expected_length = strlen (expected);
- if (ret == 0)
- {
- long written = ftell (f);
-
- if (written <= 0 || fflush (f) < 0)
- {
- printf ("stream error: %m\n");
- errors = true;
- }
- else if (buf[written - 1] != '\n')
- {
- printf ("FAILED: \"%s\" without newline\n", expected);
- errors = true;
- }
- else if (strncmp (buf, expected, written - 1) != 0
- || written - 1 != expected_length)
- {
- buf[written - 1] = '\0';
- printf ("FAILED: \"%s\" (%ld), expected \"%s\" (%zu)\n",
- buf, written - 1, expected, expected_length);
- errors = true;
- }
- }
- else
- {
- printf ("FAILED: putgrent (expected \"%s\"): %m\n", expected);
- errors = true;
- }
- }
-
- fclose (f);
- free (buf);
-}
-
-static int
-do_test (void)
-{
- check ((struct group) {
- .gr_name = (char *) "root",
- },
- "root::0:");
- check ((struct group) {
- .gr_name = (char *) "root",
- .gr_passwd = (char *) "password",
- .gr_gid = 1234,
- .gr_mem = (char *[2]) {(char *) "member1", NULL}
- },
- "root:password:1234:member1");
- check ((struct group) {
- .gr_name = (char *) "root",
- .gr_passwd = (char *) "password",
- .gr_gid = 1234,
- .gr_mem = (char *[3]) {(char *) "member1", (char *) "member2", NULL}
- },
- "root:password:1234:member1,member2");
-
- /* Bad values. */
- {
- static const char *const bad_strings[] = {
- ":",
- "\n",
- ":bad",
- "\nbad",
- "b:ad",
- "b\nad",
- "bad:",
- "bad\n",
- "b:a\nd"
- ",",
- "\n,",
- ":,",
- ",bad",
- "b,ad",
- "bad,",
- NULL
- };
- for (const char *const *bad = bad_strings; *bad != NULL; ++bad)
- {
- char *members[]
- = {(char *) "first", (char *) *bad, (char *) "last", NULL};
- if (strpbrk (*bad, ":\n") != NULL)
- {
- check ((struct group) {
- .gr_name = (char *) *bad,
- }, NULL);
- check ((struct group) {
- .gr_name = (char *) "root",
- .gr_passwd = (char *) *bad,
- }, NULL);
- }
- check ((struct group) {
- .gr_name = (char *) "root",
- .gr_passwd = (char *) "password",
- .gr_mem = members,
- }, NULL);
- }
- }
-
- return errors;
-}
-
-#define TEST_FUNCTION do_test ()
-#include "../test-skeleton.c"
diff --git a/grp/tst_fgetgrent.c b/grp/tst_fgetgrent.c
deleted file mode 100644
index be41191..0000000
--- a/grp/tst_fgetgrent.c
+++ /dev/null
@@ -1,126 +0,0 @@
-/* Copyright (C) 1999-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 <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/types.h>
-#include <unistd.h>
-
-static int errors;
-
-static void
-write_users (FILE *f, int large_pos, int pos)
-{
- int i;
-
- if (pos == large_pos)
- {
- if (large_pos == 3)
- fprintf (f, ":three");
-
- /* we need more than 2048 bytes for proper testing. */
- for (i = 0; i < 500; i++)
- fprintf (f, ",user%03d", i);
- }
- fprintf (f, "\n");
-
-}
-
-static void
-write_group (const char *filename, int pos)
-{
- FILE *f;
-
- f = fopen (filename, "w");
- fprintf (f, "one:x:1:one");
- write_users (f, pos, 1);
- fprintf (f, "two:x:2:two");
- write_users (f, pos, 2);
- fprintf (f, "three:x:3");
- write_users (f, pos, 3);
- fclose (f);
-}
-
-static void
-test_entry (const char *name, gid_t gid, struct group *g)
-{
- if (!g)
- {
- printf ("Error: Entry is empty\n");
- errors++;
- return;
- }
-
- if ((g->gr_gid == gid) && (strcmp (g->gr_name, name) == 0))
- printf ("Ok: %s: %d\n", g->gr_name, g->gr_gid);
- else
- {
- printf ("Error: %s: %d should be: %s: %d\n", g->gr_name, g->gr_gid,
- name, gid);
- errors++;
- }
-}
-
-
-static void
-test_fgetgrent (const char *filename)
-{
- struct group *g;
- FILE *f;
-
- f = fopen (filename,"r");
-
- g = fgetgrent (f);
- test_entry ("one", 1, g);
- g = fgetgrent (f);
- test_entry ("two", 2, g);
- g = fgetgrent (f);
- test_entry ("three", 3, g);
- fclose (f);
-}
-
-
-int
-main (int argc, char *argv[])
-{
- char file[] = "/tmp/tst_fgetgrent.XXXXXX";
- int fd = mkstemp (file);
- if (fd == -1)
- {
- printf ("mkstemp failed: %m\n");
- return 1;
- }
- close (fd);
- int i = 0;
-
- if (argc > 1)
- i = atoi (argv[1]);
- if (i > 3)
- i = 3;
- if (i)
- printf ("Large group is group: %d\n", i);
- else
- printf ("Not using a large group\n");
- write_group (file, i);
- test_fgetgrent (file);
-
- remove (file);
-
- return (errors != 0);
-}
diff --git a/grp/tst_fgetgrent.sh b/grp/tst_fgetgrent.sh
deleted file mode 100644
index 1775a6b..0000000
--- a/grp/tst_fgetgrent.sh
+++ /dev/null
@@ -1,40 +0,0 @@
-#!/bin/sh
-# Copyright (C) 1999-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/>.
-
-set -e
-
-common_objpfx=$1; shift
-test_program_prefix=$1; shift
-
-testout=${common_objpfx}/grp/tst_fgetgrent.out
-
-result=0
-
-${test_program_prefix} \
-${common_objpfx}grp/tst_fgetgrent 0 > ${testout} || result=1
-
-${test_program_prefix} \
-${common_objpfx}grp/tst_fgetgrent 1 >> ${testout} || result=1
-
-${test_program_prefix} \
-${common_objpfx}grp/tst_fgetgrent 2 >> ${testout} || result=1
-
-${test_program_prefix} \
-${common_objpfx}grp/tst_fgetgrent 3 >> ${testout} || result=1
-
-exit $result