r288: combination of BUG 1081 and patch from J. Klinger -- added remove_duplicate_gid...
authorGerald Carter <jerry@samba.org>
Tue, 20 Apr 2004 01:24:47 +0000 (01:24 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 15:51:16 +0000 (10:51 -0500)
(This used to be commit 95c68103ea9dbd02651e26fcaa15dd054b157529)

source3/lib/system_smbd.c
source3/lib/util_getent.c
source3/nsswitch/winbindd_group.c

index 73c910e631d2e261317ba3d8f44acbc0a1b9b5cc..7edc7ca98f9e9bc50bf48064271524fe28f313dd 100644 (file)
@@ -99,6 +99,11 @@ static int getgrouplist_internals(const char *user, gid_t gid, gid_t *groups, in
                free(gids_saved);
                return -1;
        }
+       
+       /* this will remove any duplicates gids in the list and 
+          update the group counter */
+          
+       remove_duplicate_gids( grpcnt, groups );
 
        free(gids_saved);
        return ret;
index 3544c1678cca05b16a9bfe5e0f8e077978e45c46..4431d6a2a476603edcb110b09ba546d6573079fd 100644 (file)
@@ -304,3 +304,48 @@ void free_userlist(struct sys_userlist *list_head)
                SAFE_FREE(old_head);
        }
 }
+
+/****************************************************************
+****************************************************************/
+
+static int int_compare( int *a, int *b ) 
+{
+       if ( *a == *b )
+               return 0;
+       else if ( *a < *b )
+               return -1;
+       else 
+               return 1;
+}
+
+void remove_duplicate_gids( int *num_groups, gid_t *groups )
+{
+       int i;
+       int count = *num_groups;
+
+       if ( *num_groups <= 0 || !groups )
+               return;
+
+       
+       DEBUG(8,("remove_duplicate_gids: Enter %d gids\n", *num_groups));
+
+       qsort( groups, *num_groups, sizeof(gid_t), QSORT_CAST int_compare );
+
+       for ( i=1; i<count; ) {
+               if ( groups[i-1] == groups[i] ) {
+                       memmove( &groups[i-1], &groups[i], (count - i + 1)*sizeof(gid_t) );
+
+                       /* decrement the total number of groups and do not increment 
+                          the loop counter */
+                       count--;
+                       continue;
+               }
+               i++;
+       }
+
+       *num_groups = count;
+
+       DEBUG(8,("remove_duplicate_gids: Exit %d gids\n", *num_groups));
+
+       return;
+}
index f9b6df1aed968af4c583995328f02222da428133..8f5306321accd5af84253c4a59962466d154c274 100644 (file)
@@ -1118,6 +1118,8 @@ enum winbindd_result winbindd_getgroups(struct winbindd_cli_state *state)
                }
        }
 
+       remove_duplicate_gids( &num_gids, gid_list );
+
        /* Send data back to client */
 
        state->response.data.num_entries = num_gids;