summaryrefslogtreecommitdiff
path: root/source4/lib/ldb/tools/ldbedit.c
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2005-05-16 22:31:45 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:16:49 -0500
commit9a9cf9e0753c7cf040feecf670c0986a17c16dce (patch)
tree89c657285c82259658b90cfd54c3695070be7107 /source4/lib/ldb/tools/ldbedit.c
parent2cb07b0f1bab01a406d8d75d19d1039ce5ed3105 (diff)
downloadsamba-9a9cf9e0753c7cf040feecf670c0986a17c16dce.tar.gz
samba-9a9cf9e0753c7cf040feecf670c0986a17c16dce.tar.bz2
samba-9a9cf9e0753c7cf040feecf670c0986a17c16dce.zip
r6833: split out the routine that calculates the diff between two ldb messages from ldbedit,
so other progs can use it. (This used to be commit fa4f33558af3c65ff31424c01db16cb9d427503d)
Diffstat (limited to 'source4/lib/ldb/tools/ldbedit.c')
-rw-r--r--source4/lib/ldb/tools/ldbedit.c47
1 files changed, 4 insertions, 43 deletions
diff --git a/source4/lib/ldb/tools/ldbedit.c b/source4/lib/ldb/tools/ldbedit.c
index 4c41b6b19a..851eaeebdf 100644
--- a/source4/lib/ldb/tools/ldbedit.c
+++ b/source4/lib/ldb/tools/ldbedit.c
@@ -65,51 +65,12 @@ static int modify_record(struct ldb_context *ldb,
struct ldb_message *msg2)
{
struct ldb_message *mod;
- struct ldb_message_element *el;
- unsigned int i;
- int count = 0;
- 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) {
- fprintf(stderr, "Failed to canonicalise msg2\n");
+ mod = ldb_msg_diff(ldb, msg1, msg2);
+ if (mod == NULL) {
+ fprintf(stderr, "Failed to calculate message differences\n");
return -1;
}
-
- /* look in msg2 to find elements that need to be added
- or modified */
- for (i=0;i<msg2->num_elements;i++) {
- el = ldb_msg_find_element(msg1, msg2->elements[i].name);
-
- if (el && ldb_msg_element_compare(el, &msg2->elements[i]) == 0) {
- continue;
- }
-
- if (ldb_msg_add(ldb, mod,
- &msg2->elements[i],
- el?LDB_FLAG_MOD_REPLACE:LDB_FLAG_MOD_ADD) != 0) {
- return -1;
- }
- count++;
- }
-
- /* look in msg1 to find elements that need to be deleted */
- 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,
- msg1->elements[i].name,
- LDB_FLAG_MOD_DELETE) != 0) {
- return -1;
- }
- count++;
- }
- }
if (mod->num_elements == 0) {
return 0;
@@ -125,7 +86,7 @@ static int modify_record(struct ldb_context *ldb,
ldif_write_msg(ldb, stdout, LDB_CHANGETYPE_MODIFY, mod);
}
- return count;
+ return mod->num_elements;
}
/*