(_nss_compat_initgroups_dyn): Implement dynamic resizing.
authordrepper <drepper>
Mon, 24 Jul 2000 01:23:55 +0000 (01:23 +0000)
committerdrepper <drepper>
Mon, 24 Jul 2000 01:23:55 +0000 (01:23 +0000)
nis/nss_compat/compat-initgroups.c

index 6051a1a..4d14615 100644 (file)
@@ -588,15 +588,15 @@ internal_getgrent_r (struct group *gr, ent_t *ent, char *buffer,
 }
 
 enum nss_status
-_nss_compat_initgroups (const char *user, gid_t group, long int *start,
-                       long int *size, gid_t *groups, long int limit,
-                       int *errnop)
+_nss_compat_initgroups_dyn (const char *user, gid_t group, long int *start,
+                           long int *size, gid_t **groupsp, int *errnop)
 {
   struct group grpbuf, *g;
   size_t buflen = sysconf (_SC_GETPW_R_SIZE_MAX);
   char *tmpbuf;
   enum nss_status status;
   ent_t intern = {0, 0, NULL, 0, NULL, NULL, {NULL, 0, 0}};
+  gid_t *groups = *groupsp;
 
   status = internal_setgrent (&intern);
   if (status != NSS_STATUS_SUCCESS)
@@ -627,22 +627,20 @@ _nss_compat_initgroups (const char *user, gid_t group, long int *start,
             if (strcmp (*m, user) == 0)
               {
                 /* Matches user.  Insert this group.  */
-                if (*start == *size && limit <= 0)
+                if (*start == *size)
                   {
                     /* Need a bigger buffer.  */
-                    groups = realloc (groups, 2 * *size * sizeof (*groups));
-                    if (groups == NULL)
+                   gid_t *newgroups;
+                    newgroups = realloc (groups, 2 * *size * sizeof (*groups));
+                    if (newgroups == NULL)
                       goto done;
+                   *groupsp = groups = newgroups;
                     *size *= 2;
                   }
 
                 groups[*start] = g->gr_gid;
                 *start += 1;
 
-                if (*start == limit)
-                  /* Can't take any more groups; stop searching.  */
-                  goto done;
-
                 break;
               }
         }