diff options
author | Andrew Bartlett <abartlet@samba.org> | 2007-12-17 05:56:42 +0100 |
---|---|---|
committer | Stefan Metzmacher <metze@samba.org> | 2007-12-21 05:50:45 +0100 |
commit | dfc27ff863baa7fff6f0c039f48c9a336a0632fc (patch) | |
tree | bd7c62c5f5016633ab7b7f649ff21c6a6f3e8473 /source4 | |
parent | 70cea01a9ec0be4ef9fd141a16b52e8141a1c94a (diff) | |
download | samba-dfc27ff863baa7fff6f0c039f48c9a336a0632fc.tar.gz samba-dfc27ff863baa7fff6f0c039f48c9a336a0632fc.tar.bz2 samba-dfc27ff863baa7fff6f0c039f48c9a336a0632fc.zip |
r26488: Implement tests for the ranged_results module.
Untested code is broken code, so rework the module until it passes...
It turns out that AD puts search attributes onto the wire in the
reverse order to what Samba does. This complicates exact value
matching, so this is skipped for now.
Andrew Bartlett
(This used to be commit 91bcb60d31d54e52128d5bd107df4ceb87389889)
Diffstat (limited to 'source4')
-rw-r--r-- | source4/dsdb/samdb/ldb_modules/ranged_results.c | 62 |
1 files changed, 34 insertions, 28 deletions
diff --git a/source4/dsdb/samdb/ldb_modules/ranged_results.c b/source4/dsdb/samdb/ldb_modules/ranged_results.c index 8f368b6f14..affc01d413 100644 --- a/source4/dsdb/samdb/ldb_modules/ranged_results.c +++ b/source4/dsdb/samdb/ldb_modules/ranged_results.c @@ -60,9 +60,10 @@ static int rr_search_callback(struct ldb_context *ldb, void *context, struct ldb if (strncasecmp(p, ";range=", strlen(";range=")) != 0) { continue; } - if (sscanf(p, ";range=%u-*", &start) == 1) { + if (sscanf(p, ";range=%u-%u", &start, &end) == 2) { + } else if (sscanf(p, ";range=%u-*", &start) == 1) { end = (unsigned int)-1; - } else if (sscanf(p, ";range=%u-%u", &start, &end) != 2) { + } else { continue; } new_attr = talloc_strndup(orig_req, @@ -82,39 +83,44 @@ static int rr_search_callback(struct ldb_context *ldb, void *context, struct ldb ldb_asprintf_errstring(ldb, "range request error: start must not be greater than end"); return LDB_ERR_UNWILLING_TO_PERFORM; } - if (end >= el->num_values) { + if (end >= (el->num_values - 1)) { /* Need to leave the requested attribute in * there (so add an empty one to match) */ end_str = "*"; - end = el->num_values; - ret = ldb_msg_add_empty(ares->message, orig_req->op.search.attrs[i], - 0, NULL); - if (ret != LDB_SUCCESS) { - return ret; - } + end = el->num_values - 1; } else { end_str = talloc_asprintf(el, "%u", end); + if (!end_str) { + ldb_oom(ldb); + return LDB_ERR_OPERATIONS_ERROR; + } } - orig_values = el->values; - orig_num_values = el->num_values; - - if ((start + end < start) || (start + end < end)) { - ldb_asprintf_errstring(ldb, "range request error: start or end would overflow!"); - return LDB_ERR_UNWILLING_TO_PERFORM; - } - - el->values = talloc_array(el, struct ldb_val, end - start); - el->num_values = 0; - - if (!el->values) { - ldb_oom(ldb); - return LDB_ERR_OPERATIONS_ERROR; - } - for (j=start; j < end; j++) { - el->values[el->num_values] = orig_values[j]; - el->num_values++; + /* If start is greater then where we noe find the end to be */ + if (start > end) { + el->num_values = 0; + el->values = NULL; + } else { + orig_values = el->values; + orig_num_values = el->num_values; + + if ((start + end < start) || (start + end < end)) { + ldb_asprintf_errstring(ldb, "range request error: start or end would overflow!"); + return LDB_ERR_UNWILLING_TO_PERFORM; + } + + el->num_values = 0; + + el->values = talloc_array(el, struct ldb_val, (end - start) + 1); + if (!el->values) { + ldb_oom(ldb); + return LDB_ERR_OPERATIONS_ERROR; + } + for (j=start; j <= end; j++) { + el->values[el->num_values] = orig_values[j]; + el->num_values++; + } } - el->name = talloc_asprintf(el, "%s;Range=%u-%s", el->name, start, end_str); + el->name = talloc_asprintf(el, "%s;range=%u-%s", el->name, start, end_str); if (!el->name) { ldb_oom(ldb); return LDB_ERR_OPERATIONS_ERROR; |