diff options
author | Gerald Carter <jerry@samba.org> | 2004-04-20 01:24:47 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 10:51:16 -0500 |
commit | ae2e6490743c0fd89e11c85cd72d549f39be7674 (patch) | |
tree | 499689b37b255f8cebeb3b524807c93b30b13363 /source3/lib/util_getent.c | |
parent | 335b10ef10f9825ad52501c77bc6b77cdad39067 (diff) | |
download | samba-ae2e6490743c0fd89e11c85cd72d549f39be7674.tar.gz samba-ae2e6490743c0fd89e11c85cd72d549f39be7674.tar.bz2 samba-ae2e6490743c0fd89e11c85cd72d549f39be7674.zip |
r288: combination of BUG 1081 and patch from J. Klinger -- added remove_duplicate_gids() to smbd and winbindd
(This used to be commit 95c68103ea9dbd02651e26fcaa15dd054b157529)
Diffstat (limited to 'source3/lib/util_getent.c')
-rw-r--r-- | source3/lib/util_getent.c | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/source3/lib/util_getent.c b/source3/lib/util_getent.c index 3544c1678c..4431d6a2a4 100644 --- a/source3/lib/util_getent.c +++ b/source3/lib/util_getent.c @@ -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; +} |