summaryrefslogtreecommitdiff
path: root/source4/lib/ldb/tools
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2004-05-06 04:40:15 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 12:51:45 -0500
commitd8ce7c6a2acbf371509a23775470e7614bcb6027 (patch)
tree3b0d2157dc855a17a6e7f0ace37cddfb60dfdb04 /source4/lib/ldb/tools
parent3aa278b873c5d06a279e0e65a96d6e6b42b64583 (diff)
downloadsamba-d8ce7c6a2acbf371509a23775470e7614bcb6027.tar.gz
samba-d8ce7c6a2acbf371509a23775470e7614bcb6027.tar.bz2
samba-d8ce7c6a2acbf371509a23775470e7614bcb6027.zip
r502: modified ldb to allow the use of an external pool memory
allocator. The way to use this is to call ldb_set_alloc() with a function pointer to whatever memory allocator you like. It includes a context pointer to allow for pool based allocators. (This used to be commit 3955c482e6c2c9e975a4bb809ec8cb6068e48e34)
Diffstat (limited to 'source4/lib/ldb/tools')
-rw-r--r--source4/lib/ldb/tools/ldbadd.c4
-rw-r--r--source4/lib/ldb/tools/ldbedit.c17
-rw-r--r--source4/lib/ldb/tools/ldbmodify.c4
-rw-r--r--source4/lib/ldb/tools/ldbsearch.c26
-rw-r--r--source4/lib/ldb/tools/ldbtest.c4
5 files changed, 30 insertions, 25 deletions
diff --git a/source4/lib/ldb/tools/ldbadd.c b/source4/lib/ldb/tools/ldbadd.c
index 15febb76e7..6d89f67e0f 100644
--- a/source4/lib/ldb/tools/ldbadd.c
+++ b/source4/lib/ldb/tools/ldbadd.c
@@ -55,7 +55,7 @@ static int process_file(struct ldb_context *ldb, FILE *f)
struct ldb_ldif *ldif;
int ret, count=0;
- while ((ldif = ldif_read_file(f))) {
+ while ((ldif = ldif_read_file(ldb, f))) {
if (ldif->changetype != LDB_CHANGETYPE_ADD &&
ldif->changetype != LDB_CHANGETYPE_NONE) {
fprintf(stderr, "Only CHANGETYPE_ADD records allowed\n");
@@ -70,7 +70,7 @@ static int process_file(struct ldb_context *ldb, FILE *f)
} else {
count++;
}
- ldif_read_free(ldif);
+ ldif_read_free(ldb, ldif);
}
return count;
diff --git a/source4/lib/ldb/tools/ldbedit.c b/source4/lib/ldb/tools/ldbedit.c
index eb95ed3267..57c54cad40 100644
--- a/source4/lib/ldb/tools/ldbedit.c
+++ b/source4/lib/ldb/tools/ldbedit.c
@@ -60,7 +60,7 @@ static int modify_record(struct ldb_context *ldb,
continue;
}
- if (ldb_msg_add(&mod,
+ if (ldb_msg_add(ldb, &mod,
&msg2->elements[i],
el?LDB_FLAG_MOD_REPLACE:LDB_FLAG_MOD_ADD) != 0) {
return -1;
@@ -72,7 +72,7 @@ static int modify_record(struct ldb_context *ldb,
for (i=0;i<msg1->num_elements;i++) {
el = ldb_msg_find_element(msg2, msg1->elements[i].name);
if (!el) {
- if (ldb_msg_add_empty(&mod,
+ if (ldb_msg_add_empty(ldb, &mod,
msg1->elements[i].name,
LDB_FLAG_MOD_DELETE) != 0) {
return -1;
@@ -159,7 +159,8 @@ static int merge_edits(struct ldb_context *ldb,
/*
save a set of messages as ldif to a file
*/
-static int save_ldif(FILE *f, struct ldb_message **msgs, int count)
+static int save_ldif(struct ldb_context *ldb,
+ FILE *f, struct ldb_message **msgs, int count)
{
int i;
@@ -172,7 +173,7 @@ static int save_ldif(FILE *f, struct ldb_message **msgs, int count)
ldif.changetype = LDB_CHANGETYPE_NONE;
ldif.msg = *msgs[i];
- ldif_write_file(f, &ldif);
+ ldif_write_file(ldb, f, &ldif);
}
return 0;
@@ -211,13 +212,13 @@ static int do_edit(struct ldb_context *ldb, struct ldb_message **msgs1, int coun
return -1;
}
- if (save_ldif(f, msgs1, count1) != 0) {
+ if (save_ldif(ldb, f, msgs1, count1) != 0) {
return -1;
}
fclose(f);
- asprintf(&cmd, "%s %s", editor, template);
+ ldb_asprintf(ldb, &cmd, "%s %s", editor, template);
if (!cmd) {
unlink(template);
@@ -242,8 +243,8 @@ static int do_edit(struct ldb_context *ldb, struct ldb_message **msgs1, int coun
return -1;
}
- while ((ldif = ldif_read_file(f))) {
- msgs2 = realloc_p(msgs2, struct ldb_message *, count2+1);
+ while ((ldif = ldif_read_file(ldb, f))) {
+ msgs2 = ldb_realloc_p(ldb, msgs2, struct ldb_message *, count2+1);
if (!msgs2) {
fprintf(stderr, "out of memory");
return -1;
diff --git a/source4/lib/ldb/tools/ldbmodify.c b/source4/lib/ldb/tools/ldbmodify.c
index bc29369a5c..6ac8e366c7 100644
--- a/source4/lib/ldb/tools/ldbmodify.c
+++ b/source4/lib/ldb/tools/ldbmodify.c
@@ -54,7 +54,7 @@ static int process_file(struct ldb_context *ldb, FILE *f)
struct ldb_ldif *ldif;
int ret = -1, count = 0;
- while ((ldif = ldif_read_file(f))) {
+ while ((ldif = ldif_read_file(ldb, f))) {
switch (ldif->changetype) {
case LDB_CHANGETYPE_NONE:
case LDB_CHANGETYPE_ADD:
@@ -74,7 +74,7 @@ static int process_file(struct ldb_context *ldb, FILE *f)
} else {
count++;
}
- ldif_read_free(ldif);
+ ldif_read_free(ldb, ldif);
}
return count;
diff --git a/source4/lib/ldb/tools/ldbsearch.c b/source4/lib/ldb/tools/ldbsearch.c
index 541024dd2d..edda31b793 100644
--- a/source4/lib/ldb/tools/ldbsearch.c
+++ b/source4/lib/ldb/tools/ldbsearch.c
@@ -45,11 +45,11 @@ static void usage(void)
exit(1);
}
-static void do_search(struct ldb_context *ldb,
- const char *basedn,
- int scope,
- const char *expression,
- char * const *attrs)
+static int do_search(struct ldb_context *ldb,
+ const char *basedn,
+ int scope,
+ const char *expression,
+ char * const *attrs)
{
int ret, i;
struct ldb_message **msgs;
@@ -57,7 +57,7 @@ static void do_search(struct ldb_context *ldb,
ret = ldb_search(ldb, basedn, scope, expression, attrs, &msgs);
if (ret == -1) {
printf("search failed - %s\n", ldb_errstring(ldb));
- return;
+ return -1;
}
printf("# returned %d records\n", ret);
@@ -69,7 +69,7 @@ static void do_search(struct ldb_context *ldb,
ldif.changetype = LDB_CHANGETYPE_NONE;
ldif.msg = *msgs[i];
- ldif_write_file(stdout, &ldif);
+ ldif_write_file(ldb, stdout, &ldif);
}
if (ret > 0) {
@@ -79,6 +79,8 @@ static void do_search(struct ldb_context *ldb,
exit(1);
}
}
+
+ return 0;
}
int main(int argc, char * const argv[])
@@ -89,7 +91,7 @@ static void do_search(struct ldb_context *ldb,
const char *basedn = NULL;
int opt;
enum ldb_scope scope = LDB_SCOPE_SUBTREE;
- int interactive = 0;
+ int interactive = 0, ret=0;
ldb_url = getenv("LDB_URL");
@@ -150,12 +152,14 @@ static void do_search(struct ldb_context *ldb,
if (interactive) {
char line[1024];
while (fgets(line, sizeof(line), stdin)) {
- do_search(ldb, basedn, scope, line, attrs);
+ if (do_search(ldb, basedn, scope, line, attrs) == -1) {
+ ret = -1;
+ }
}
} else {
- do_search(ldb, basedn, scope, argv[0], attrs);
+ ret = do_search(ldb, basedn, scope, argv[0], attrs);
}
ldb_close(ldb);
- return 0;
+ return ret;
}
diff --git a/source4/lib/ldb/tools/ldbtest.c b/source4/lib/ldb/tools/ldbtest.c
index bcb8bdcb16..e7db767387 100644
--- a/source4/lib/ldb/tools/ldbtest.c
+++ b/source4/lib/ldb/tools/ldbtest.c
@@ -84,7 +84,7 @@ static void add_records(struct ldb_context *ldb,
el[2].name = "uid";
el[2].num_values = 1;
el[2].values = vals[2];
- vals[2][0].data = ldb_casefold(name);
+ vals[2][0].data = ldb_casefold(ldb, name);
vals[2][0].length = strlen(vals[2][0].data);
el[3].flags = 0;
@@ -121,7 +121,7 @@ static void add_records(struct ldb_context *ldb,
free(name);
free(msg.dn);
free(vals[1][0].data);
- free(vals[2][0].data);
+ ldb_free(ldb, vals[2][0].data);
free(vals[3][0].data);
}