summaryrefslogtreecommitdiff
path: root/source4/lib/ldb/tools
diff options
context:
space:
mode:
authorSimo Sorce <idra@samba.org>2005-11-08 00:11:45 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:45:53 -0500
commit5c9590587197dcb95007fdc54318187d5716c7c6 (patch)
treed5161aa628d8a4bc4f11bf849d76a451ff44522c /source4/lib/ldb/tools
parent14b59bcbec1a288810efee5c9442dff30f1a474a (diff)
downloadsamba-5c9590587197dcb95007fdc54318187d5716c7c6.tar.gz
samba-5c9590587197dcb95007fdc54318187d5716c7c6.tar.bz2
samba-5c9590587197dcb95007fdc54318187d5716c7c6.zip
r11567: Ldb API change patch.
This patch changes the way lsb_search is called and the meaning of the returned integer. The last argument of ldb_search is changed from struct ldb_message to struct ldb_result which contains a pointer to a struct ldb_message list and a count of the number of messages. The return is not the count of messages anymore but instead it is an ldb error value. I tryed to keep the patch as tiny as possible bu as you can guess I had to change a good amount of places. I also tried to double check all my changes being sure that the calling functions would still behave as before. But this patch is big enough that I fear some bug may have been introduced anyway even if it passes the test suite. So if you are currently working on any file being touched please give it a deep look and blame me for any error. Simo. (This used to be commit 22c8c97e6fb466b41859e090e959d7f1134be780)
Diffstat (limited to 'source4/lib/ldb/tools')
-rw-r--r--source4/lib/ldb/tools/ldbdel.c9
-rw-r--r--source4/lib/ldb/tools/ldbedit.c15
-rw-r--r--source4/lib/ldb/tools/ldbsearch.c17
-rw-r--r--source4/lib/ldb/tools/ldbtest.c24
4 files changed, 35 insertions, 30 deletions
diff --git a/source4/lib/ldb/tools/ldbdel.c b/source4/lib/ldb/tools/ldbdel.c
index bd40fccbdb..6da8d0269f 100644
--- a/source4/lib/ldb/tools/ldbdel.c
+++ b/source4/lib/ldb/tools/ldbdel.c
@@ -34,6 +34,7 @@
#include "includes.h"
#include "ldb/include/ldb.h"
+#include "ldb/include/ldb_errors.h"
#include "ldb/include/ldb_private.h"
#include "ldb/tools/cmdline.h"
@@ -45,13 +46,13 @@ static int ldb_delete_recursive(struct ldb_context *ldb, const struct ldb_dn *dn
{
int ret, i, total=0;
const char *attrs[] = { NULL };
- struct ldb_message **res;
+ struct ldb_result *res;
ret = ldb_search(ldb, dn, LDB_SCOPE_SUBTREE, "distinguishedName=*", attrs, &res);
- if (ret <= 0) return -1;
+ if (ret != LDB_SUCCESS) return -1;
- for (i=0;i<ret;i++) {
- if (ldb_delete(ldb, res[i]->dn) == 0) {
+ for (i = 0; i < res->count; i++) {
+ if (ldb_delete(ldb, res->msgs[i]->dn) == 0) {
total++;
}
}
diff --git a/source4/lib/ldb/tools/ldbedit.c b/source4/lib/ldb/tools/ldbedit.c
index bc629fef93..570179c2e1 100644
--- a/source4/lib/ldb/tools/ldbedit.c
+++ b/source4/lib/ldb/tools/ldbedit.c
@@ -34,6 +34,7 @@
#include "includes.h"
#include "ldb/include/ldb.h"
+#include "ldb/include/ldb_errors.h"
#include "ldb/include/ldb_private.h"
#include "ldb/tools/cmdline.h"
@@ -280,7 +281,7 @@ static void usage(void)
int main(int argc, const char **argv)
{
struct ldb_context *ldb;
- struct ldb_message **msgs;
+ struct ldb_result *result = NULL;
struct ldb_dn *basedn = NULL;
int ret;
const char *expression = "(|(objectclass=*)(distinguishedName=*))";
@@ -310,21 +311,21 @@ static void usage(void)
}
}
- ret = ldb_search(ldb, basedn, options->scope, expression, attrs, &msgs);
- if (ret == -1) {
+ ret = ldb_search(ldb, basedn, options->scope, expression, attrs, &result);
+ if (ret != LDB_SUCCESS) {
printf("search failed - %s\n", ldb_errstring(ldb));
exit(1);
}
- if (ret == 0) {
+ if (result->count == 0) {
printf("no matching records - cannot edit\n");
return 0;
}
- do_edit(ldb, msgs, ret, options->editor);
+ do_edit(ldb, result->msgs, result->count, options->editor);
- if (ret > 0) {
- ret = talloc_free(msgs);
+ if (result) {
+ ret = talloc_free(result);
if (ret == -1) {
fprintf(stderr, "talloc_free failed\n");
exit(1);
diff --git a/source4/lib/ldb/tools/ldbsearch.c b/source4/lib/ldb/tools/ldbsearch.c
index 4abc7269d5..f8c06f0fa4 100644
--- a/source4/lib/ldb/tools/ldbsearch.c
+++ b/source4/lib/ldb/tools/ldbsearch.c
@@ -34,6 +34,7 @@
#include "includes.h"
#include "ldb/include/ldb.h"
+#include "ldb/include/ldb_errors.h"
#include "ldb/include/ldb_private.h"
#include "ldb/tools/cmdline.h"
@@ -71,10 +72,10 @@ static int do_search(struct ldb_context *ldb,
const char * const *attrs)
{
int ret, i;
- struct ldb_message **msgs;
+ struct ldb_result *result = NULL;
- ret = ldb_search(ldb, basedn, scope, expression, attrs, &msgs);
- if (ret == -1) {
+ ret = ldb_search(ldb, basedn, scope, expression, attrs, &result);
+ if (ret != LDB_SUCCESS) {
printf("search failed - %s\n", ldb_errstring(ldb));
return -1;
}
@@ -83,16 +84,16 @@ static int do_search(struct ldb_context *ldb,
ldbsearch_ldb = ldb;
if (sort_attribs) {
- qsort(msgs, ret, sizeof(struct ldb_message *),
+ qsort(result->msgs, ret, sizeof(struct ldb_message *),
(comparison_fn_t)do_compare_msg);
}
- for (i=0;i<ret;i++) {
+ for (i = 0; i < result->count; i++) {
struct ldb_ldif ldif;
printf("# record %d\n", i+1);
ldif.changetype = LDB_CHANGETYPE_NONE;
- ldif.msg = msgs[i];
+ ldif.msg = result->msgs[i];
if (sort_attribs) {
/*
@@ -106,8 +107,8 @@ static int do_search(struct ldb_context *ldb,
ldb_ldif_write_file(ldb, stdout, &ldif);
}
- if (ret > 0) {
- ret = talloc_free(msgs);
+ if (result) {
+ ret = talloc_free(result);
if (ret == -1) {
fprintf(stderr, "talloc_free failed\n");
exit(1);
diff --git a/source4/lib/ldb/tools/ldbtest.c b/source4/lib/ldb/tools/ldbtest.c
index cda912c9b2..7abc1bfcef 100644
--- a/source4/lib/ldb/tools/ldbtest.c
+++ b/source4/lib/ldb/tools/ldbtest.c
@@ -34,6 +34,7 @@
#include "includes.h"
#include "ldb/include/ldb.h"
+#include "ldb/include/ldb_errors.h"
#include "ldb/include/ldb_private.h"
#include "ldb/tools/cmdline.h"
@@ -228,29 +229,26 @@ static void search_uid(struct ldb_context *ldb, struct ldb_dn *basedn, int nreco
for (i=0;i<nsearches;i++) {
int uid = (i * 700 + 17) % (nrecords * 2);
char *expr;
- struct ldb_message **res;
+ struct ldb_result *res = NULL;
int ret;
asprintf(&expr, "(uid=TEST%d)", uid);
ret = ldb_search(ldb, basedn, LDB_SCOPE_SUBTREE, expr, NULL, &res);
- if (uid < nrecords && ret != 1) {
+ if (ret != LDB_SUCCESS || (uid < nrecords && res->count != 1)) {
printf("Failed to find %s - %s\n", expr, ldb_errstring(ldb));
exit(1);
}
- if (uid >= nrecords && ret > 0) {
+ if (uid >= nrecords && res->count > 0) {
printf("Found %s !? - %d\n", expr, ret);
exit(1);
}
- if (ret > 0) {
- talloc_free(res);
- }
-
- printf("testing uid %d/%d - %d \r", i, uid, ret);
+ printf("testing uid %d/%d - %d \r", i, uid, res->count);
fflush(stdout);
+ talloc_free(res);
free(expr);
}
@@ -295,7 +293,7 @@ be indexed
static void start_test_index(struct ldb_context **ldb)
{
struct ldb_message *msg;
- struct ldb_message **res;
+ struct ldb_result *res = NULL;
struct ldb_dn *indexlist;
struct ldb_dn *basedn;
int ret;
@@ -349,8 +347,12 @@ static void start_test_index(struct ldb_context **ldb)
}
ret = ldb_search(*ldb, basedn, LDB_SCOPE_SUBTREE, "uid=test", NULL, &res);
- if (ret != 1) {
- printf("Should have found 1 record - found %d\n", ret);
+ if (ret != LDB_SUCCESS) {
+ printf("Search with (uid=test) filter failed!\n");
+ exit(1);
+ }
+ if(res->count != 1) {
+ printf("Should have found 1 record - found %d\n", res->count);
exit(1);
}