]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Fix s390{,x} build. grouplist fixes from Ulrich.
authorJakub Jelinek <jakub@redhat.com>
Tue, 5 Oct 2004 11:23:19 +0000 (11:23 +0000)
committerJakub Jelinek <jakub@redhat.com>
Tue, 5 Oct 2004 11:23:19 +0000 (11:23 +0000)
ChangeLog
grp/compat-initgroups.c
grp/initgroups.c
nscd/initgrcache.c
sysdeps/unix/sysv/linux/s390/s390-32/sysdep.h
sysdeps/unix/sysv/linux/s390/s390-64/sysdep.h

index 8f3248f77315e76735f18235dabaa638f9846355..ea4be8811c8e03f4c77a7f0d623f493347f69432 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2004-10-05  Jakub Jelinek  <jakub@redhat.com>
 
+       * sysdeps/unix/sysv/linux/s390/s390-32/sysdep.h: Include dl-sysdep.h.
+       * sysdeps/unix/sysv/linux/s390/s390-64/sysdep.h: Likewise.
+
        * sysdeps/unix/sysv/linux/i386/sysconf.c: Include hp-timing.h.
        (__sysconf): Return -1 for _SC_CPUTIME or _SC_THREAD_CPUTIME if
        !HP_TIMING_AVAIL.
index 585c4aecbbcc600aa80fd43da4caebbc21b92c7c..efd875a6897ab4affb3ff12c5a4c511eedce3a12 100644 (file)
@@ -58,31 +58,42 @@ compat_call (service_user *nip, const char *user, gid_t group, long int *start,
           for (m = grpbuf.gr_mem; *m != NULL; ++m)
             if (strcmp (*m, user) == 0)
               {
-                /* Matches user.  Insert this group.  */
-                if (__builtin_expect (*start == *size, 0))
-                  {
-                    /* Need a bigger buffer.  */
-                   gid_t *newgroups;
-                   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 = newsize;
-                  }
-
-                groups[*start] = grpbuf.gr_gid;
-                *start += 1;
+               /* Check whether the group is already on the list.  */
+               long int cnt;
+               for (cnt = 0; cnt < *start; ++cnt)
+                 if (groups[cnt] == grpbuf.gr_gid)
+                   break;
+
+               if (cnt == *start)
+                 {
+                   /* Matches user and not yet on the list.  Insert
+                      this group.  */
+                   if (__builtin_expect (*start == *size, 0))
+                     {
+                       /* Need a bigger buffer.  */
+                       gid_t *newgroups;
+                       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 = newsize;
+                     }
+
+                   groups[*start] = grpbuf.gr_gid;
+                   *start += 1;
+                 }
 
                 break;
               }
index 9e79273f3ef3f0c5813bbc82aa05f5f209aed7da..f86f5c63f45cb6286b12a31ebec329a16c3b6394 100644 (file)
@@ -73,7 +73,7 @@ internal_getgrouplist (const char *user, gid_t group, long int *size,
   /* Start is one, because we have the first group as parameter.  */
   long int start = 1;
 
-  *groupsp[0] = group;
+  (*groupsp)[0] = group;
 
   if (__nss_group_database != NULL)
     {
@@ -86,6 +86,8 @@ internal_getgrouplist (const char *user, gid_t group, long int *size,
 
   while (! no_more)
     {
+      long int prev_start = start;
+
       fct = __nss_lookup_function (nip, "initgroups_dyn");
 
       if (fct == NULL)
@@ -100,6 +102,21 @@ internal_getgrouplist (const char *user, gid_t group, long int *size,
        status = DL_CALL_FCT (fct, (user, group, &start, size, groupsp,
                                    limit, &errno));
 
+      /* Remove duplicates.  */
+      long int cnt = prev_start;
+      while (cnt < start)
+       {
+         long int inner;
+         for (inner = 0; inner < prev_start; ++inner)
+           if ((*groupsp)[inner] == (*groups)[cnt])
+             break;
+
+         if (inner < prev_start)
+           ++cnt;
+         else
+           (*groupsp)[cnt] = (*groupsp)[--start];
+       }
+
       /* This is really only for debugging.  */
       if (NSS_STATUS_TRYAGAIN > status || status > NSS_STATUS_RETURN)
        __libc_fatal ("illegal status in internal_getgrouplist");
index 124b4bae626bc04fec25104f9a5d0eaf8fe3362c..9ba7b89bdf1db5ba188cce3929c0f67b7952d97f 100644 (file)
@@ -117,6 +117,7 @@ addinitgroupsX (struct database_dyn *db, int fd, request_header *req,
   /* Nothing added yet.  */
   while (! no_more)
     {
+      long int prev_start = start;
       enum nss_status status;
       initgroups_dyn_function fct;
       fct = __nss_lookup_function (nip, "initgroups_dyn");
@@ -133,6 +134,21 @@ addinitgroupsX (struct database_dyn *db, int fd, request_header *req,
        status = DL_CALL_FCT (fct, (key, -1, &start, &size, &groups,
                                    limit, &errno));
 
+      /* Remove duplicates.  */
+      long int cnt = prev_start;
+      while (cnt < start)
+       {
+         long int inner;
+         for (inner = 0; inner < prev_start; ++inner)
+           if ((*groupsp)[inner] == (*groups)[cnt])
+             break;
+
+         if (inner < prev_start)
+           ++cnt;
+         else
+           (*groupsp)[cnt] = (*groupsp)[--start];
+       }
+
       if (status != NSS_STATUS_TRYAGAIN)
        all_tryagain = false;
 
index ad3cde6a66112d812c4e91cd12f14ba180118a98..43b1b951d580b9774eb2042444ad72ab22b1d832 100644 (file)
@@ -22,6 +22,7 @@
 
 #include <sysdeps/s390/s390-32/sysdep.h>
 #include <sysdeps/unix/sysdep.h>
+#include <dl-sysdep.h> /* For RTLD_PRIVATE_ERRNO.  */
 
 /* For Linux we can use the system call table in the header file
        /usr/include/asm/unistd.h
index 45e701e7a463ff6d530f367ce0a65b5ba8a8afa3..154bc068039deee558589aff74abeef2a29a9cf5 100644 (file)
@@ -23,6 +23,7 @@
 
 #include <sysdeps/s390/s390-64/sysdep.h>
 #include <sysdeps/unix/sysdep.h>
+#include <dl-sysdep.h> /* For RTLD_PRIVATE_ERRNO.  */
 
 /* For Linux we can use the system call table in the header file
        /usr/include/asm/unistd.h