about summary refs log tree commit diff
path: root/hesiod/nss_hesiod/hesiod-grp.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2000-07-24 01:26:01 +0000
committerUlrich Drepper <drepper@redhat.com>2000-07-24 01:26:01 +0000
commitcf9e9ad98feb55d11f93aa4e069c81ee06c2a6a3 (patch)
tree2da802067a7b55b2580a49786505794ace48ac0c /hesiod/nss_hesiod/hesiod-grp.c
parent945b22ed04767342dac1654f7e92ad5f8870361b (diff)
downloadglibc-cf9e9ad98feb55d11f93aa4e069c81ee06c2a6a3.tar.gz
glibc-cf9e9ad98feb55d11f93aa4e069c81ee06c2a6a3.tar.xz
glibc-cf9e9ad98feb55d11f93aa4e069c81ee06c2a6a3.zip
Update.
	* grp/initgroups.c (initgroups): Don't limit the possible number
	of groups to NGROUPS_MAX.  Allow dynamic resizing.  Loop around
	the setgroups call while the call fails and descrease the number
	of groups each round.
	The name of the initgroups function in the NSS modules changed.
	(compat_call): Adapt for dynamic resizing.
	* hesiod/nss_hesiod/hesiod-grp.c (_nss_hesiod_initgroups_dyn):
	Implement dynamic resizing.
	* nis/nss_compat/compat-initgroups.c (_nss_compat_initgroups_dyn):
	Likewise.
	* nis/nss_nis/compat-initgroups.c (_nss_nis_initgroups_dyn): Likewise.
	* hesiod/Versions: Change exported interface name.
	* nis/Versions: Change exported interface name.

2000-07-23  Ulrich Drepper  <drepper@redhat.com>
Diffstat (limited to 'hesiod/nss_hesiod/hesiod-grp.c')
-rw-r--r--hesiod/nss_hesiod/hesiod-grp.c41
1 files changed, 34 insertions, 7 deletions
diff --git a/hesiod/nss_hesiod/hesiod-grp.c b/hesiod/nss_hesiod/hesiod-grp.c
index 2d5b96b7f9..a89ed4edaf 100644
--- a/hesiod/nss_hesiod/hesiod-grp.c
+++ b/hesiod/nss_hesiod/hesiod-grp.c
@@ -164,14 +164,14 @@ internal_gid_from_group (void *context, const char *groupname, gid_t *group)
 }
 
 enum nss_status
-_nss_hesiod_initgroups (const char *user, gid_t group, long int *start,
-                        long int *size, gid_t *groups, long int limit,
-                        int *errnop)
+_nss_hesiod_initgroups_dyn (const char *user, gid_t group, long int *start,
+			    long int *size, gid_t **groupsp, int *errnop)
 {
   enum nss_status status = NSS_STATUS_SUCCESS;
   char **list = NULL;
   char *p;
   void *context;
+  gid_t *groups = *groupsp;
 
   context = _nss_hesiod_init ();
   if (context == NULL)
@@ -185,11 +185,24 @@ _nss_hesiod_initgroups (const char *user, gid_t group, long int *start,
       return errno == ENOENT ? NSS_STATUS_NOTFOUND : NSS_STATUS_UNAVAIL;
     }
 
-  if (!internal_gid_in_list (groups, group, *start) && *start < limit)
-    groups[(*start)++] = group;
+  if (!internal_gid_in_list (groups, group, *start))
+    {
+      if (__builtin_expect (*start == *size, 0))
+	{
+	  /* Need a bigger buffer.  */
+	  gid_t *newgroups;
+	  newgroups = realloc (groups, 2 * *size * sizeof (*groups));
+	  if (newgroups == NULL)
+	    goto done;
+	  *groupsp = groups = newgroups;
+	  *size *= 2;
+	}
+
+      groups[(*start)++] = group;
+    }
 
   p = *list;
-  while (*p != '\0' && *start < limit)
+  while (*p != '\0')
     {
       char *endp;
       char *q;
@@ -214,12 +227,26 @@ _nss_hesiod_initgroups (const char *user, gid_t group, long int *start,
 
 	  if (status == NSS_STATUS_SUCCESS
 	      && !internal_gid_in_list (groups, group, *start))
-	    groups[(*start)++] = group;
+	    {
+	      if (__builtin_expect (*start == *size, 0))
+		{
+		  /* Need a bigger buffer.  */
+		  gid_t *newgroups;
+		  newgroups = realloc (groups, 2 * *size * sizeof (*groups));
+		  if (newgroups == NULL)
+		    goto done;
+		  *groupsp = groups = newgroups;
+		  *size *= 2;
+		}
+
+	      groups[(*start)++] = group;
+	    }
 	}
 
       p = q;
     }
 
+ done:
   hesiod_free_list (context, list);
   hesiod_end (context);