Include limit in interface as it was before.
authordrepper <drepper>
Mon, 24 Jul 2000 01:45:36 +0000 (01:45 +0000)
committerdrepper <drepper>
Mon, 24 Jul 2000 01:45:36 +0000 (01:45 +0000)
grp/initgroups.c
hesiod/nss_hesiod/hesiod-grp.c
nis/nss_compat/compat-initgroups.c
nis/nss_nis/nis-initgroups.c

index 950ebfe..a74a703 100644 (file)
@@ -49,7 +49,7 @@ extern service_user *__nss_group_database;
 
 static enum nss_status
 compat_call (service_user *nip, const char *user, gid_t group, long int *start,
-            long int *size, gid_t **groupsp, int *errnop)
+            long int *size, gid_t **groupsp, long int limit, int *errnop)
 {
   struct group grpbuf;
   size_t buflen = __sysconf (_SC_GETGR_R_SIZE_MAX);
@@ -102,11 +102,22 @@ compat_call (service_user *nip, const char *user, gid_t group, long int *start,
                   {
                     /* Need a bigger buffer.  */
                    gid_t *newgroups;
-                    newgroups = realloc (groups, 2 * *size * sizeof (*groups));
+                   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 *= 2;
+                    *size = newsize;
                   }
 
                 groups[*start] = grpbuf.gr_gid;
@@ -147,10 +158,12 @@ initgroups (user, group)
   /* Start is one, because we have the first group as parameter.  */
   long int start = 1;
   long int size;
+  long int limit;
   gid_t *groups;
   int result;
 #ifdef NGROUPS_MAX
   size = NGROUPS_MAX;
+  limit = -1;
 #else
   long int limit = __sysconf (_SC_NGROUPS_MAX);
 
@@ -184,14 +197,14 @@ initgroups (user, group)
       if (fct == NULL)
        {
          status = compat_call (nip, user, group, &start, &size, &groups,
-                               &errno);
+                               limit, &errno);
 
          if (nss_next_action (nip, NSS_STATUS_UNAVAIL) != NSS_ACTION_CONTINUE)
            break;
        }
       else
        status = DL_CALL_FCT (fct, (user, group, &start, &size, &groups,
-                                   &errno));
+                                   limit, &errno));
 
       /* This is really only for debugging.  */
       if (NSS_STATUS_TRYAGAIN > status || status > NSS_STATUS_RETURN)
index a89ed4e..5551d7d 100644 (file)
@@ -25,6 +25,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <sys/param.h>
 
 #include "nss_hesiod.h"
 
@@ -165,7 +166,8 @@ internal_gid_from_group (void *context, const char *groupname, gid_t *group)
 
 enum nss_status
 _nss_hesiod_initgroups_dyn (const char *user, gid_t group, long int *start,
-                           long int *size, gid_t **groupsp, int *errnop)
+                           long int *size, gid_t **groupsp, long int limit,
+                           int *errnop)
 {
   enum nss_status status = NSS_STATUS_SUCCESS;
   char **list = NULL;
@@ -191,11 +193,22 @@ _nss_hesiod_initgroups_dyn (const char *user, gid_t group, long int *start,
        {
          /* Need a bigger buffer.  */
          gid_t *newgroups;
-         newgroups = realloc (groups, 2 * *size * sizeof (*groups));
+         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 *= 2;
+         *size = newsize;
        }
 
       groups[(*start)++] = group;
@@ -232,11 +245,22 @@ _nss_hesiod_initgroups_dyn (const char *user, gid_t group, long int *start,
                {
                  /* Need a bigger buffer.  */
                  gid_t *newgroups;
-                 newgroups = realloc (groups, 2 * *size * sizeof (*groups));
+                 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 *= 2;
+                 *size = newsize;
                }
 
              groups[(*start)++] = group;
index 4d14615..558433e 100644 (file)
@@ -27,6 +27,7 @@
 #include <rpcsvc/yp.h>
 #include <rpcsvc/ypclnt.h>
 #include <rpcsvc/nis.h>
+#include <sys/param.h>
 #include <nsswitch.h>
 
 #include "nss-nis.h"
@@ -589,7 +590,8 @@ internal_getgrent_r (struct group *gr, ent_t *ent, char *buffer,
 
 enum nss_status
 _nss_compat_initgroups_dyn (const char *user, gid_t group, long int *start,
-                           long int *size, gid_t **groupsp, int *errnop)
+                           long int *size, gid_t **groupsp, long int limit,
+                           int *errnop)
 {
   struct group grpbuf, *g;
   size_t buflen = sysconf (_SC_GETPW_R_SIZE_MAX);
@@ -631,11 +633,22 @@ _nss_compat_initgroups_dyn (const char *user, gid_t group, long int *start,
                   {
                     /* Need a bigger buffer.  */
                    gid_t *newgroups;
-                    newgroups = realloc (groups, 2 * *size * sizeof (*groups));
+                   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 *= 2;
+                    *size = newsize;
                   }
 
                 groups[*start] = g->gr_gid;
index ec13dbd..cf666a4 100644 (file)
@@ -25,6 +25,7 @@
 #include <unistd.h>
 #include <rpcsvc/yp.h>
 #include <rpcsvc/ypclnt.h>
+#include <sys/param.h>
 
 #include "nss-nis.h"
 
@@ -138,7 +139,8 @@ internal_getgrent_r (struct group *grp, char *buffer, size_t buflen,
 
 enum nss_status
 _nss_nis_initgroups_dyn (const char *user, gid_t group, long int *start,
-                        long int *size, gid_t **groupsp, int *errnop)
+                        long int *size, gid_t **groupsp, long int limit,
+                        int *errnop)
 {
   struct group grpbuf, *g;
   size_t buflen = sysconf (_SC_GETPW_R_SIZE_MAX);
@@ -181,11 +183,22 @@ _nss_nis_initgroups_dyn (const char *user, gid_t group, long int *start,
                   {
                     /* Need a bigger buffer.  */
                    gid_t *newgroups;
-                   newgroups = realloc (groups, 2 * *size * sizeof (*groups));
+                   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 *= 2;
+                    *size = newsize;
                   }
 
                 groups[*start] = g->gr_gid;