summaryrefslogtreecommitdiff
path: root/source4/lib/ldb/tools/ldbedit.c
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2005-01-02 07:49:29 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:07:55 -0500
commit1a988ec9af7960616fb4661b20d86ff05146d836 (patch)
tree725eb92b6b97133b23972215f5c69117e29c339c /source4/lib/ldb/tools/ldbedit.c
parent65f96eba32b93ced0717c2639007bba59da55fa4 (diff)
downloadsamba-1a988ec9af7960616fb4661b20d86ff05146d836.tar.gz
samba-1a988ec9af7960616fb4661b20d86ff05146d836.tar.bz2
samba-1a988ec9af7960616fb4661b20d86ff05146d836.zip
r4474: - converted ldb to use talloc internally
- added gcov flags to Makefile.ldb - expanded ldb test suite to get more coverage (This used to be commit 0ab98f50a7e0fe15347a99e5c29a6590a87729a0)
Diffstat (limited to 'source4/lib/ldb/tools/ldbedit.c')
-rw-r--r--source4/lib/ldb/tools/ldbedit.c28
1 files changed, 15 insertions, 13 deletions
diff --git a/source4/lib/ldb/tools/ldbedit.c b/source4/lib/ldb/tools/ldbedit.c
index 6cd6ef041b..66b684f4d5 100644
--- a/source4/lib/ldb/tools/ldbedit.c
+++ b/source4/lib/ldb/tools/ldbedit.c
@@ -48,7 +48,7 @@ static void ldif_write_msg(struct ldb_context *ldb,
{
struct ldb_ldif ldif;
ldif.changetype = changetype;
- ldif.msg = *msg;
+ ldif.msg = msg;
ldb_ldif_write_file(ldb, f, &ldif);
}
@@ -60,14 +60,16 @@ static int modify_record(struct ldb_context *ldb,
struct ldb_message *msg1,
struct ldb_message *msg2)
{
- struct ldb_message mod;
+ struct ldb_message *mod;
struct ldb_message_element *el;
unsigned int i;
int count = 0;
- mod.dn = msg1->dn;
- mod.num_elements = 0;
- mod.elements = NULL;
+ mod = ldb_msg_new(ldb);
+
+ mod->dn = msg1->dn;
+ mod->num_elements = 0;
+ mod->elements = NULL;
msg2 = ldb_msg_canonicalize(ldb, msg2);
if (msg2 == NULL) {
@@ -84,7 +86,7 @@ static int modify_record(struct ldb_context *ldb,
continue;
}
- if (ldb_msg_add(ldb, &mod,
+ if (ldb_msg_add(ldb, mod,
&msg2->elements[i],
el?LDB_FLAG_MOD_REPLACE:LDB_FLAG_MOD_ADD) != 0) {
return -1;
@@ -96,7 +98,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(ldb, &mod,
+ if (ldb_msg_add_empty(ldb, mod,
msg1->elements[i].name,
LDB_FLAG_MOD_DELETE) != 0) {
return -1;
@@ -105,18 +107,18 @@ static int modify_record(struct ldb_context *ldb,
}
}
- if (mod.num_elements == 0) {
+ if (mod->num_elements == 0) {
return 0;
}
- if (ldb_modify(ldb, &mod) != 0) {
+ if (ldb_modify(ldb, mod) != 0) {
fprintf(stderr, "failed to modify %s - %s\n",
msg1->dn, ldb_errstring(ldb));
return -1;
}
if (verbose > 0) {
- ldif_write_msg(ldb, stdout, LDB_CHANGETYPE_MODIFY, &mod);
+ ldif_write_msg(ldb, stdout, LDB_CHANGETYPE_MODIFY, mod);
}
return count;
@@ -205,7 +207,7 @@ static int save_ldif(struct ldb_context *ldb,
fprintf(f, "# record %d\n", i+1);
ldif.changetype = LDB_CHANGETYPE_NONE;
- ldif.msg = *msgs[i];
+ ldif.msg = msgs[i];
ldb_ldif_write_file(ldb, f, &ldif);
}
@@ -278,12 +280,12 @@ static int do_edit(struct ldb_context *ldb, struct ldb_message **msgs1, int coun
}
while ((ldif = ldb_ldif_read_file(ldb, f))) {
- msgs2 = ldb_realloc_p(ldb, msgs2, struct ldb_message *, count2+1);
+ msgs2 = talloc_realloc_p(ldb, msgs2, struct ldb_message *, count2+1);
if (!msgs2) {
fprintf(stderr, "out of memory");
return -1;
}
- msgs2[count2++] = &ldif->msg;
+ msgs2[count2++] = ldif->msg;
}
fclose(f);