The branch, master has been updated
       via  b33232f tests: Add test_initgroups
       via  91974ea tests: Add more groups and groups members
       via  0c90c43 tests: Implement _nss_nwrap_initgroups_dyn(), 
_nss_nwrap_getgrent_r(), _nss_nwrap_getgrnam_r() and _nss_nwrap_getgrgid_r()
       via  1a010f2 nwrap,tests: Use nwrap_gr_copy_r() from lib nss_utils
       via  e60ad71 nwrap: Create library nss_utils
       via  34a6808 nwrap: Implement initgroups() using nwrap_getgrouplist()
       via  01b66b0 nwrap: Implement getgrouplist() correctly
       via  5b60119 nwrap: Implement nwrap_files_initgroups_dyn()
       via  666bd92 nwrap: Add MIN(), MAX() macros
       via  cce021a nwrap: Correctly implement initgroups_dyn() for the modules
       via  24c7064 nwrap: Remove incorrect implementation of nwrap_initgroups()
       via  5243f74 Add clang-format definitions
      from  25a5a11 Avoid dclose(RTLD_NEXT)

https://git.samba.org/?p=nss_wrapper.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit b33232ff661cc377a0bb75b40dd5ea6b1754e4fb
Author: Pavel Filipenský <pfilipen...@samba.org>
Date:   Thu Jan 19 22:35:00 2023 +0100

    tests: Add test_initgroups
    
    Signed-off-by: Pavel Filipenský <pfilipen...@samba.org>
    Reviewed-by: Andreas Schneider <a...@samba.org>

commit 91974ea4b6985febe58aadaf9924bc62cdcbcbc4
Author: Pavel Filipenský <pfilipen...@samba.org>
Date:   Mon Jan 16 21:30:46 2023 +0100

    tests: Add more groups and groups members
    
    Signed-off-by: Pavel Filipenský <pfilipen...@samba.org>
    Reviewed-by: Andreas Schneider <a...@samba.org>

commit 0c90c4380a52615460c5e98b3aed09f7e14de907
Author: Pavel Filipenský <pfilipen...@samba.org>
Date:   Mon Jan 16 21:27:05 2023 +0100

    tests: Implement _nss_nwrap_initgroups_dyn(), _nss_nwrap_getgrent_r(), 
_nss_nwrap_getgrnam_r() and _nss_nwrap_getgrgid_r()
    
    Signed-off-by: Pavel Filipenský <pfilipen...@samba.org>
    Reviewed-by: Andreas Schneider <a...@samba.org>

commit 1a010f2c9de81e0ee2dc9b3e660ad65bcdddf7bd
Author: Pavel Filipenský <pfilipen...@samba.org>
Date:   Tue Jan 17 11:50:08 2023 +0100

    nwrap,tests: Use nwrap_gr_copy_r() from lib nss_utils
    
    nss_utils must be added to both nwrap,tests at the same time
    
    Signed-off-by: Pavel Filipenský <pfilipen...@samba.org>
    Reviewed-by: Andreas Schneider <a...@samba.org>

commit e60ad71576352995d91036f2555f672291837591
Author: Pavel Filipenský <pfilipen...@samba.org>
Date:   Tue Jan 17 11:48:12 2023 +0100

    nwrap: Create library nss_utils
    
    Will be used to share function nwrap_gr_copy_r among src and test
    
    Signed-off-by: Pavel Filipenský <pfilipen...@samba.org>
    Reviewed-by: Andreas Schneider <a...@samba.org>

commit 34a6808f34f5ce805ec39ffea3657901434479d2
Author: Pavel Filipenský <pfilipen...@samba.org>
Date:   Mon Jan 16 20:58:17 2023 +0100

    nwrap: Implement initgroups() using nwrap_getgrouplist()
    
    Signed-off-by: Pavel Filipenský <pfilipen...@samba.org>
    Reviewed-by: Andreas Schneider <a...@samba.org>

commit 01b66b0a51deb538cfc5a31230053cc5128b0a46
Author: Pavel Filipenský <pfilipen...@samba.org>
Date:   Mon Jan 16 20:52:45 2023 +0100

    nwrap: Implement getgrouplist() correctly
    
    The main job is done in nwrap_getgrouplist() that will be used also by
    initgroups() next.
    
    Signed-off-by: Pavel Filipenský <pfilipen...@samba.org>
    Reviewed-by: Andreas Schneider <a...@samba.org>

commit 5b601190c87f768f1bf77fd8b993f6b3ad98ac24
Author: Pavel Filipenský <pfilipen...@samba.org>
Date:   Tue Jan 17 09:51:08 2023 +0100

    nwrap: Implement nwrap_files_initgroups_dyn()
    
    This implements the initgroups_dyn() for the files part correctly. We need 
to
    reimplement initgroups() later.
    
    Signed-off-by: Pavel Filipenský <pfilipen...@samba.org>
    Reviewed-by: Andreas Schneider <a...@samba.org>

commit 666bd92a7f40c4930cb2b20bd81a8c66effad090
Author: Pavel Filipenský <pfilipen...@samba.org>
Date:   Tue Jan 17 07:21:34 2023 +0100

    nwrap: Add MIN(), MAX() macros
    
    Signed-off-by: Pavel Filipenský <pfilipen...@samba.org>
    Reviewed-by: Andreas Schneider <a...@samba.org>

commit cce021aed6ab893eb131e6a47879d7333ff01d69
Author: Pavel Filipenský <pfilipen...@samba.org>
Date:   Tue Jan 17 09:50:22 2023 +0100

    nwrap: Correctly implement initgroups_dyn() for the modules
    
    Signed-off-by: Pavel Filipenský <pfilipen...@samba.org>
    Reviewed-by: Andreas Schneider <a...@samba.org>

commit 24c7064e7bfc8288028708af973cb793d6a1bba0
Author: Pavel Filipenský <pfilipen...@samba.org>
Date:   Tue Jan 17 09:43:45 2023 +0100

    nwrap: Remove incorrect implementation of nwrap_initgroups()
    
    This will be correctly implemented later. The backends actually don't have 
an
    initgroups() function but initgroups_dyn().
    
    Signed-off-by: Pavel Filipenský <pfilipen...@samba.org>
    Reviewed-by: Andreas Schneider <a...@samba.org>

commit 5243f743db1e43f8607403700c159a833eeef25a
Author: Pavel Filipenský <pfilipen...@samba.org>
Date:   Tue Jan 17 09:34:50 2023 +0100

    Add clang-format definitions
    
    Signed-off-by: Pavel Filipenský <pfilipen...@samba.org>
    Reviewed-by: Andreas Schneider <a...@samba.org>

-----------------------------------------------------------------------

Summary of changes:
 .clang-format           |  26 +++
 src/CMakeLists.txt      |   3 +-
 src/nss_utils.c         | 131 ++++++++++++++++
 src/nss_utils.h         |  46 ++++++
 src/nss_wrapper.c       | 409 ++++++++++++++++++++++--------------------------
 tests/CMakeLists.txt    |  19 ++-
 tests/group.in          |   3 +-
 tests/nss_nwrap.c       | 191 +++++++++++++++++-----
 tests/test_initgroups.c |  52 ++++++
 9 files changed, 618 insertions(+), 262 deletions(-)
 create mode 100644 .clang-format
 create mode 100644 src/nss_utils.c
 create mode 100644 src/nss_utils.h
 create mode 100644 tests/test_initgroups.c


Changeset truncated at 500 lines:

diff --git a/.clang-format b/.clang-format
new file mode 100644
index 0000000..5385807
--- /dev/null
+++ b/.clang-format
@@ -0,0 +1,26 @@
+# https://clang.llvm.org/docs/ClangFormatStyleOptions.html
+BasedOnStyle: LLVM
+IndentWidth: 8
+ContinuationIndentWidth: 8
+UseTab: true
+BreakBeforeBraces: Custom
+BraceWrapping:
+    AfterEnum: false
+    AfterFunction: true
+    AfterStruct: false
+    AfterUnion: false
+    AfterExternBlock: true
+    BeforeElse: false
+    BeforeWhile: false
+AllowShortIfStatementsOnASingleLine: false
+ColumnLimit: 80
+IndentCaseLabels: false
+AlignAfterOpenBracket: Align
+BinPackParameters: false
+BinPackArguments: false
+AllowAllParametersOfDeclarationOnNextLine: false
+AllowAllArgumentsOnNextLine: false
+AllowShortFunctionsOnASingleLine: Empty
+AlwaysBreakAfterReturnType: None
+AlignEscapedNewlines: Left
+SortIncludes: false
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 2103a0c..f56aad5 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1,5 +1,6 @@
 project(libnss_wrapper C)
 
+add_library(nss_utils STATIC nss_utils.c)
 add_library(nss_wrapper SHARED nss_wrapper.c)
 target_compile_options(nss_wrapper
                        PRIVATE
@@ -12,7 +13,7 @@ endif()
 target_include_directories(nss_wrapper
                            PRIVATE
                                ${CMAKE_BINARY_DIR})
-target_link_libraries(nss_wrapper ${NWRAP_REQUIRED_LIBRARIES} 
${CMAKE_THREAD_LIBS_INIT})
+target_link_libraries(nss_wrapper nss_utils ${NWRAP_REQUIRED_LIBRARIES} 
${CMAKE_THREAD_LIBS_INIT})
 
 set_target_properties(
   nss_wrapper
diff --git a/src/nss_utils.c b/src/nss_utils.c
new file mode 100644
index 0000000..1d0a3d0
--- /dev/null
+++ b/src/nss_utils.c
@@ -0,0 +1,131 @@
+/*
+ * BSD 3-Clause License
+ *
+ * Copyright (c) 2007,      Stefan Metzmacher <me...@samba.org>
+ * Copyright (c) 2009,      Guenther Deschner <g...@samba.org>
+ * Copyright (c) 2014-2015, Michael Adam <ob...@samba.org>
+ * Copyright (c) 2015,      Robin Hack <hack.ro...@gmail.com>
+ * Copyright (c) 2013-2018, Andreas Schneider <a...@samba.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the author nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <errno.h>
+#include <grp.h>
+#include <string.h>
+#include <stdint.h>
+
+#include "nss_utils.h"
+
+int nwrap_gr_copy_r(const struct group *src, struct group *dst,
+                   char *buf, size_t buflen, struct group **dstp)
+{
+       char *p = NULL;
+       uintptr_t align = 0;
+       unsigned int gr_mem_cnt = 0;
+       unsigned i;
+       size_t total_len;
+       size_t gr_name_len = strlen(src->gr_name) + 1;
+       size_t gr_passwd_len = strlen(src->gr_passwd) + 1;
+       union {
+               char *ptr;
+               char **data;
+       } g_mem;
+
+       for (i = 0; src->gr_mem[i] != NULL; i++) {
+               gr_mem_cnt++;
+       }
+
+       /* Align the memory for storing pointers */
+       align = __alignof__(char *) - ((p - (char *)0) % __alignof__(char *));
+       total_len = align +
+                   (1 + gr_mem_cnt) * sizeof(char *) +
+                   gr_name_len + gr_passwd_len;
+
+       if (total_len > buflen) {
+               errno = ERANGE;
+               return -1;
+       }
+       buflen -= total_len;
+
+       /* gr_mem */
+       p = buf + align;
+       g_mem.ptr = p;
+       dst->gr_mem = g_mem.data;
+
+       /* gr_name */
+       p += (1 + gr_mem_cnt) * sizeof(char *);
+       dst->gr_name = p;
+
+       /* gr_passwd */
+       p += gr_name_len;
+       dst->gr_passwd = p;
+
+       /* gr_mem[x] */
+       p += gr_passwd_len;
+
+       /* gr_gid */
+       dst->gr_gid = src->gr_gid;
+
+       memcpy(dst->gr_name, src->gr_name, gr_name_len);
+
+       memcpy(dst->gr_passwd, src->gr_passwd, gr_passwd_len);
+
+       /* Set the terminating entry */
+       dst->gr_mem[gr_mem_cnt] = NULL;
+
+       /* Now add the group members content */
+       total_len = 0;
+       for (i = 0; i < gr_mem_cnt; i++) {
+               size_t len = strlen(src->gr_mem[i]) + 1;
+
+               dst->gr_mem[i] = p;
+               total_len += len;
+               p += len;
+       }
+
+       if (total_len > buflen) {
+               errno = ERANGE;
+               return -1;
+       }
+
+       for (i = 0; i < gr_mem_cnt; i++) {
+               size_t len = strlen(src->gr_mem[i]) + 1;
+
+               memcpy(dst->gr_mem[i],
+                      src->gr_mem[i],
+                      len);
+       }
+
+       if (dstp != NULL) {
+               *dstp = dst;
+       }
+
+       return 0;
+}
diff --git a/src/nss_utils.h b/src/nss_utils.h
new file mode 100644
index 0000000..6a9c478
--- /dev/null
+++ b/src/nss_utils.h
@@ -0,0 +1,46 @@
+/*
+ * BSD 3-Clause License
+ *
+ * Copyright (c) 2007,      Stefan Metzmacher <me...@samba.org>
+ * Copyright (c) 2009,      Guenther Deschner <g...@samba.org>
+ * Copyright (c) 2014-2015, Michael Adam <ob...@samba.org>
+ * Copyright (c) 2015,      Robin Hack <hack.ro...@gmail.com>
+ * Copyright (c) 2013-2018, Andreas Schneider <a...@samba.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the author nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef NSS_UTILS_H
+#define NSS_UTILS_H
+#include <grp.h>
+
+int nwrap_gr_copy_r(const struct group *src, struct group *dst,
+                   char *buf, size_t buflen, struct group **dstp);
+
+#endif //NSS_UTILS_H
diff --git a/src/nss_wrapper.c b/src/nss_wrapper.c
index 0b2066c..3399f06 100644
--- a/src/nss_wrapper.c
+++ b/src/nss_wrapper.c
@@ -54,12 +54,14 @@
 #include <string.h>
 #include <unistd.h>
 #include <ctype.h>
+#include <limits.h>
 
 #include <netinet/in.h>
 
 #include <search.h>
 #include <assert.h>
 
+#include "nss_utils.h"
 /*
  * Defining _POSIX_PTHREAD_SEMANTICS before including pwd.h and grp.h  gives us
  * the posix getpwnam_r(), getpwuid_r(), getgrnam_r and getgrgid_r calls on
@@ -177,6 +179,9 @@ typedef nss_status_t NSS_STATUS;
 #define NWRAP_INET_ADDRSTRLEN INET_ADDRSTRLEN
 #endif
 
+#define MAX(a,b) ((a) < (b) ? (b) : (a))
+#define MIN(a,b) ((a) > (b) ? (b) : (a))
+
 static bool nwrap_initialized = false;
 static pthread_mutex_t nwrap_initialized_mutex = PTHREAD_MUTEX_INITIALIZER;
 
@@ -516,7 +521,7 @@ typedef NSS_STATUS (*__nss_getpwent_r)(struct passwd 
*result,
                                       size_t buflen,
                                       int *errnop);
 typedef NSS_STATUS (*__nss_endpwent)(void);
-typedef NSS_STATUS (*__nss_initgroups)(const char *user,
+typedef NSS_STATUS (*__nss_initgroups_dyn)(const char *user,
                                       gid_t group,
                                       long int *start,
                                       long int *size,
@@ -568,7 +573,7 @@ struct nwrap_nss_module_symbols {
        NWRAP_NSS_MODULE_SYMBOL_ENTRY(getpwent_r);
        NWRAP_NSS_MODULE_SYMBOL_ENTRY(endpwent);
 
-       NWRAP_NSS_MODULE_SYMBOL_ENTRY(initgroups);
+       NWRAP_NSS_MODULE_SYMBOL_ENTRY(initgroups_dyn);
        NWRAP_NSS_MODULE_SYMBOL_ENTRY(getgrnam_r);
        NWRAP_NSS_MODULE_SYMBOL_ENTRY(getgrgid_r);
        NWRAP_NSS_MODULE_SYMBOL_ENTRY(setgrent);
@@ -606,8 +611,14 @@ struct nwrap_ops {
                                         struct passwd *pwdst, char *buf,
                                         size_t buflen, struct passwd **pwdstp);
        void            (*nw_endpwent)(struct nwrap_backend *b);
-       int             (*nw_initgroups)(struct nwrap_backend *b,
-                                        const char *user, gid_t group);
+       int             (*nw_initgroups_dyn)(struct nwrap_backend *b,
+                                            const char *user,
+                                            gid_t group,
+                                            long int *start,
+                                            long int *size,
+                                            gid_t **groups,
+                                            long int limit,
+                                            int *errnop);
        struct group *  (*nw_getgrnam)(struct nwrap_backend *b,
                                       const char *name);
        int             (*nw_getgrnam_r)(struct nwrap_backend *b,
@@ -663,8 +674,14 @@ static int nwrap_files_getpwent_r(struct nwrap_backend *b,
                                  struct passwd *pwdst, char *buf,
                                  size_t buflen, struct passwd **pwdstp);
 static void nwrap_files_endpwent(struct nwrap_backend *b);
-static int nwrap_files_initgroups(struct nwrap_backend *b,
-                                 const char *user, gid_t group);
+static int nwrap_files_initgroups_dyn(struct nwrap_backend *b,
+                                     const char *user,
+                                     gid_t group,
+                                     long int *start,
+                                     long int *size,
+                                     gid_t **groups,
+                                     long int limit,
+                                     int *errnop);
 static struct group *nwrap_files_getgrnam(struct nwrap_backend *b,
                                          const char *name);
 static int nwrap_files_getgrnam_r(struct nwrap_backend *b,
@@ -730,8 +747,14 @@ static int nwrap_module_getgrgid_r(struct nwrap_backend *b,
                                   char *buf, size_t buflen, struct group 
**grdstp);
 static void nwrap_module_setgrent(struct nwrap_backend *b);
 static void nwrap_module_endgrent(struct nwrap_backend *b);
-static int nwrap_module_initgroups(struct nwrap_backend *b,
-                                  const char *user, gid_t group);
+static int nwrap_module_initgroups_dyn(struct nwrap_backend *b,
+                                      const char *user,
+                                      gid_t group,
+                                      long int *start,
+                                      long int *size,
+                                      gid_t **groups,
+                                      long int limit,
+                                      int *errnop);
 static struct hostent *nwrap_module_gethostbyaddr(struct nwrap_backend *b,
                                                  const void *addr,
                                                  socklen_t len, int type);
@@ -754,7 +777,7 @@ struct nwrap_ops nwrap_files_ops = {
        .nw_getpwent    = nwrap_files_getpwent,
        .nw_getpwent_r  = nwrap_files_getpwent_r,
        .nw_endpwent    = nwrap_files_endpwent,
-       .nw_initgroups  = nwrap_files_initgroups,
+       .nw_initgroups_dyn      = nwrap_files_initgroups_dyn,
        .nw_getgrnam    = nwrap_files_getgrnam,
        .nw_getgrnam_r  = nwrap_files_getgrnam_r,
        .nw_getgrgid    = nwrap_files_getgrgid,
@@ -780,7 +803,7 @@ struct nwrap_ops nwrap_module_ops = {
        .nw_getpwent    = nwrap_module_getpwent,
        .nw_getpwent_r  = nwrap_module_getpwent_r,
        .nw_endpwent    = nwrap_module_endpwent,
-       .nw_initgroups  = nwrap_module_initgroups,
+       .nw_initgroups_dyn      = nwrap_module_initgroups_dyn,
        .nw_getgrnam    = nwrap_module_getgrnam,
        .nw_getgrnam_r  = nwrap_module_getgrnam_r,
        .nw_getgrgid    = nwrap_module_getgrgid,
@@ -820,6 +843,14 @@ static int nwrap_convert_he_ai(const struct hostent *he,
                               struct addrinfo **pai,
                               bool skip_canonname);
 
+#ifdef HAVE_GETGROUPLIST
+static int nwrap_getgrouplist(const char *user,
+                             gid_t group,
+                             long int *size,
+                             gid_t **groupsp,
+                             long int limit);
+#endif
+
 /*
  * VECTORS
  */
@@ -1826,7 +1857,7 @@ nwrap_bind_nss_module_symbols(struct nwrap_backend *b)
        nwrap_nss_module_bind_symbol(setpwent);
        nwrap_nss_module_bind_symbol(getpwent_r);
        nwrap_nss_module_bind_symbol(endpwent);
-       nwrap_nss_module_bind_symbol2(initgroups, initgroups_dyn);
+       nwrap_nss_module_bind_symbol(initgroups_dyn);
        nwrap_nss_module_bind_symbol(getgrnam_r);
        nwrap_nss_module_bind_symbol(getgrgid_r);
        nwrap_nss_module_bind_symbol(setgrent);
@@ -2983,93 +3014,6 @@ static void nwrap_gr_unload(struct nwrap_cache *nwrap)
        nwrap_gr->idx = 0;
 }
 
-static int nwrap_gr_copy_r(const struct group *src, struct group *dst,
-                          char *buf, size_t buflen, struct group **dstp)
-{
-       char *p = NULL;
-       uintptr_t align = 0;
-       unsigned int gr_mem_cnt = 0;
-       unsigned i;
-       size_t total_len;
-       size_t gr_name_len = strlen(src->gr_name) + 1;
-       size_t gr_passwd_len = strlen(src->gr_passwd) + 1;
-       union {
-               char *ptr;
-               char **data;
-       } g_mem;
-
-       for (i = 0; src->gr_mem[i] != NULL; i++) {
-               gr_mem_cnt++;
-       }
-
-       /* Align the memory for storing pointers */
-       align = __alignof__(char *) - ((p - (char *)0) % __alignof__(char *));
-       total_len = align +
-                   (1 + gr_mem_cnt) * sizeof(char *) +
-                   gr_name_len + gr_passwd_len;
-
-       if (total_len > buflen) {
-               errno = ERANGE;
-               return -1;
-       }
-       buflen -= total_len;
-
-       /* gr_mem */
-       p = buf + align;
-       g_mem.ptr = p;
-       dst->gr_mem = g_mem.data;
-
-       /* gr_name */
-       p += (1 + gr_mem_cnt) * sizeof(char *);
-       dst->gr_name = p;
-
-       /* gr_passwd */
-       p += gr_name_len;
-       dst->gr_passwd = p;
-
-       /* gr_mem[x] */
-       p += gr_passwd_len;
-
-       /* gr_gid */
-       dst->gr_gid = src->gr_gid;
-
-       memcpy(dst->gr_name, src->gr_name, gr_name_len);
-
-       memcpy(dst->gr_passwd, src->gr_passwd, gr_passwd_len);
-
-       /* Set the terminating entry */
-       dst->gr_mem[gr_mem_cnt] = NULL;
-
-       /* Now add the group members content */
-       total_len = 0;
-       for (i = 0; i < gr_mem_cnt; i++) {
-               size_t len = strlen(src->gr_mem[i]) + 1;
-
-               dst->gr_mem[i] = p;
-               total_len += len;
-               p += len;
-       }
-
-       if (total_len > buflen) {
-               errno = ERANGE;
-               return -1;
-       }
-
-       for (i = 0; i < gr_mem_cnt; i++) {
-               size_t len = strlen(src->gr_mem[i]) + 1;
-
-               memcpy(dst->gr_mem[i],
-                      src->gr_mem[i],
-                      len);
-       }
-
-       if (dstp != NULL) {
-               *dstp = dst;
-       }
-
-       return 0;
-}
-
 static struct nwrap_entlist *nwrap_entlist_init(struct nwrap_entdata *ed)
 {
        struct nwrap_entlist *el;
@@ -3691,27 +3635,21 @@ static struct spwd *nwrap_files_getspnam(const char 
*name)
 #endif /* defined(HAVE_SHADOW_H) && defined(HAVE_GETSPNAM) */
 
 /* misc functions */
-static int nwrap_files_initgroups(struct nwrap_backend *b,
-                                 const char *user,
-                                 gid_t group)
+static int nwrap_files_initgroups_dyn(struct nwrap_backend *b,
+                                     const char *user,
+                                     gid_t group,
+                                     long int *start,
+                                     long int *size,
+                                     gid_t **groups,
+                                     long int limit,
+                                     int *errnop)
 {
        struct group *grp;
-       gid_t *groups;
-       int size = 1;
-       int rc;
-
-       groups = (gid_t *)malloc(size * sizeof(gid_t));
-       if (groups == NULL) {
-               NWRAP_LOG(NWRAP_LOG_ERROR, "Out of memory");
-               errno = ENOMEM;


-- 
NSS Wrapper Repository

Reply via email to