diff options
author | Gerald Carter <jerry@samba.org> | 2004-04-20 01:24:47 +0000 |
---|---|---|
committer | Gerald Carter <jerry@samba.org> | 2004-04-20 01:24:47 +0000 |
commit | b50287e95930285d94f8a0d3bfb8719b479a246f (patch) | |
tree | 2b10d95631c912466fa43923bffaa2ed4790ed2a /source/lib | |
parent | 66ef6938ab937066b4a522c2314c625661c2de6a (diff) | |
download | samba-b50287e95930285d94f8a0d3bfb8719b479a246f.tar.gz samba-b50287e95930285d94f8a0d3bfb8719b479a246f.tar.xz samba-b50287e95930285d94f8a0d3bfb8719b479a246f.zip |
r288: combination of BUG 1081 and patch from J. Klinger -- added remove_duplicate_gids() to smbd and winbindd
Diffstat (limited to 'source/lib')
-rw-r--r-- | source/lib/system_smbd.c | 5 | ||||
-rw-r--r-- | source/lib/util_getent.c | 45 |
2 files changed, 50 insertions, 0 deletions
diff --git a/source/lib/system_smbd.c b/source/lib/system_smbd.c index 73c910e631d..7edc7ca98f9 100644 --- a/source/lib/system_smbd.c +++ b/source/lib/system_smbd.c @@ -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; diff --git a/source/lib/util_getent.c b/source/lib/util_getent.c index 3544c1678cc..4431d6a2a47 100644 --- a/source/lib/util_getent.c +++ b/source/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; +} |