nwrap: Correctly implement initgroups_dyn() for the modules
authorPavel Filipenský <pfilipensky@samba.org>
Tue, 17 Jan 2023 08:50:22 +0000 (09:50 +0100)
committerAndreas Schneider <asn@samba.org>
Tue, 24 Jan 2023 08:56:35 +0000 (09:56 +0100)
Signed-off-by: Pavel Filipenský <pfilipensky@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
src/nss_wrapper.c

index 1c81fc904bdb1d2bcf14f7c799e5ab25fb764622..030e5bd32680c89c01882c8daf6ed30a0c8fe617 100644 (file)
@@ -516,7 +516,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 +568,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);
@@ -608,6 +608,14 @@ struct nwrap_ops {
        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,
@@ -730,8 +738,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);
@@ -780,7 +794,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,
@@ -1826,7 +1840,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);
@@ -4587,24 +4601,26 @@ static void nwrap_module_endpwent(struct nwrap_backend *b)
        b->symbols->_nss_endpwent.f();
 }
 
-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)
 {
-       gid_t *groups;
-       long int start;
-       long int size;
-
-       if (b->symbols->_nss_initgroups.f == NULL) {
+       if (b->symbols->_nss_initgroups_dyn.f == NULL) {
                return NSS_STATUS_UNAVAIL;
        }
 
-       return b->symbols->_nss_initgroups.f(user,
+       return b->symbols->_nss_initgroups_dyn.f(user,
                                             group,
-                                            &start,
-                                            &size,
-                                            &groups,
-                                            0,
-                                            &errno);
+                                            start,
+                                            size,
+                                            groups,
+                                            limit,
+                                            errnop);
 }
 
 static struct group *nwrap_module_getgrnam(struct nwrap_backend *b,