diff options
author | Andrew Bartlett <abartlet@samba.org> | 2008-01-11 13:15:49 +1100 |
---|---|---|
committer | Andrew Bartlett <abartlet@samba.org> | 2008-01-11 13:15:49 +1100 |
commit | f5277a3e2129f713cba3f63ffa96b1706f8d802f (patch) | |
tree | b1ab5acab37fe0118d4336d15c99c08a65ef3836 /source4/lib/ldb/tools | |
parent | 3dab82394ef950148f3da55c7d3179b0c9c05cc2 (diff) | |
download | samba-f5277a3e2129f713cba3f63ffa96b1706f8d802f.tar.gz samba-f5277a3e2129f713cba3f63ffa96b1706f8d802f.tar.bz2 samba-f5277a3e2129f713cba3f63ffa96b1706f8d802f.zip |
Rework ldbsearch to avoid segfault when remote LDAP server returns
referrals.
Andrew Bartlett
(This used to be commit 8099facff99dab4de27ea6f857d0e8f5eaa3db5a)
Diffstat (limited to 'source4/lib/ldb/tools')
-rw-r--r-- | source4/lib/ldb/tools/ldbsearch.c | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/source4/lib/ldb/tools/ldbsearch.c b/source4/lib/ldb/tools/ldbsearch.c index dba0549b44..24ceb30963 100644 --- a/source4/lib/ldb/tools/ldbsearch.c +++ b/source4/lib/ldb/tools/ldbsearch.c @@ -61,6 +61,7 @@ struct search_context { int sort; int num_stored; struct ldb_message **store; + int refs_stored; char **refs_store; int entries; @@ -87,15 +88,15 @@ static int store_message(struct ldb_message *msg, struct search_context *sctx) { static int store_referral(char *referral, struct search_context *sctx) { - sctx->refs_store = talloc_realloc(sctx, sctx->refs_store, char *, sctx->refs + 2); + sctx->refs_store = talloc_realloc(sctx, sctx->refs_store, char *, sctx->refs_stored + 2); if (!sctx->refs_store) { fprintf(stderr, "talloc_realloc failed while storing referrals\n"); return -1; } - sctx->refs_store[sctx->refs] = talloc_move(sctx->refs_store, &referral); - sctx->refs++; - sctx->refs_store[sctx->refs] = NULL; + sctx->refs_store[sctx->refs_stored] = talloc_move(sctx->refs_store, &referral); + sctx->refs_stored++; + sctx->refs_store[sctx->refs_stored] = NULL; return 0; } @@ -199,6 +200,7 @@ static int do_search(struct ldb_context *ldb, sctx->sort = options->sorted; sctx->num_stored = 0; + sctx->refs_stored = 0; sctx->store = NULL; sctx->req_ctrls = ldb_parse_control_strings(ldb, sctx, (const char **)options->controls); if (options->controls != NULL && sctx->req_ctrls== NULL) { @@ -244,19 +246,15 @@ again: if (sctx->sort && (sctx->num_stored != 0 || sctx->refs != 0)) { int i; - ldb_qsort(sctx->store, sctx->num_stored, sizeof(struct ldb_message *), - ldb, (ldb_qsort_cmp_fn_t)do_compare_msg); - - if (ret != 0) { - fprintf(stderr, "An error occurred while sorting messages\n"); - exit(1); + if (sctx->num_stored) { + ldb_qsort(sctx->store, sctx->num_stored, sizeof(struct ldb_message *), + ldb, (ldb_qsort_cmp_fn_t)do_compare_msg); } - for (i = 0; i < sctx->num_stored; i++) { display_message(ldb, sctx->store[i], sctx); } - for (i = 0; i < sctx->refs; i++) { + for (i = 0; i < sctx->refs_stored; i++) { display_referral(sctx->refs_store[i], sctx); } } |