summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Adam <obnox@samba.org>2008-10-30 16:38:07 +0100
committerMichael Adam <obnox@samba.org>2008-11-02 22:29:17 +0100
commit17218df56714237d319673c17ddd2c75795d6285 (patch)
tree25d2e4c5921a1c323dd26ffb90e5ce0b30d4a364
parentf3e638bc9fad7d3a54a9b41de8857c126c656f5c (diff)
downloadsamba-17218df56714237d319673c17ddd2c75795d6285.tar.gz
samba-17218df56714237d319673c17ddd2c75795d6285.tar.bz2
samba-17218df56714237d319673c17ddd2c75795d6285.zip
[s3]winbindd: speed up fill_grent_mem (i.e. winbindd_getgrent) a lot.
With large groups, getgrent ran into timeouts because after each single user that was added to the expanded group list, the list was sorted and made unique. Now the list is sorted just once after all members have been added. Michael
-rw-r--r--source3/winbindd/winbindd_group.c33
1 files changed, 20 insertions, 13 deletions
diff --git a/source3/winbindd/winbindd_group.c b/source3/winbindd/winbindd_group.c
index f2b6fbefb5..8e56138bb5 100644
--- a/source3/winbindd/winbindd_group.c
+++ b/source3/winbindd/winbindd_group.c
@@ -382,6 +382,24 @@ static int namecmp( const void *a, const void *b )
return StrCaseCmp( * (char * const *) a, * (char * const *) b);
}
+static void sort_unique_list(char ***list, uint32 *n_list)
+{
+ uint32_t i;
+
+ /* search for duplicates for sorting and looking for matching
+ neighbors */
+
+ qsort(*list, *n_list, sizeof(char*), QSORT_CAST namecmp);
+
+ for (i=1; i < *n_list; i++) {
+ if (strcmp((*list)[i-1], (*list)[i]) == 0) {
+ memmove(&((*list)[i-1]), &((*list)[i]),
+ sizeof(char*)*((*n_list)-i));
+ (*n_list)--;
+ }
+ }
+}
+
static NTSTATUS add_names_to_list( TALLOC_CTX *ctx,
char ***list, uint32 *n_list,
char **names, uint32 n_names )
@@ -414,19 +432,6 @@ static NTSTATUS add_names_to_list( TALLOC_CTX *ctx,
new_list[i] = talloc_strdup( new_list, names[j] );
}
- /* search for duplicates for sorting and looking for matching
- neighbors */
-
- qsort( new_list, n_new_list, sizeof(char*), QSORT_CAST namecmp );
-
- for ( i=1; i<n_new_list; i++ ) {
- if ( strcmp( new_list[i-1], new_list[i] ) == 0 ) {
- memmove( &new_list[i-1], &new_list[i],
- sizeof(char*)*(n_new_list-i) );
- n_new_list--;
- }
- }
-
*list = new_list;
*n_list = n_new_list;
@@ -663,6 +668,8 @@ static bool fill_grent_mem(struct winbindd_domain *domain,
}
TALLOC_FREE( glist );
+ sort_unique_list(&names, &num_names);
+
DEBUG(10, ("looked up %d names\n", num_names));
again: