From 03d4a7832cd3670a8166820a1b9b4aaf2307bd1a Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 17 Sep 2004 10:42:33 +0000 Subject: [PATCH] r2381: added a -v debugging option to ldbedit --- source/lib/ldb/tools/ldbedit.c | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/source/lib/ldb/tools/ldbedit.c b/source/lib/ldb/tools/ldbedit.c index 90a6f947501..b97c40ff1ae 100644 --- a/source/lib/ldb/tools/ldbedit.c +++ b/source/lib/ldb/tools/ldbedit.c @@ -34,6 +34,22 @@ #include "includes.h" +static int verbose; + +/* + debug routine +*/ +static void ldif_write_msg(struct ldb_context *ldb, + FILE *f, + enum ldb_changetype changetype, + struct ldb_message *msg) +{ + struct ldb_ldif ldif; + ldif.changetype = changetype; + ldif.msg = *msg; + ldb_ldif_write_file(ldb, f, &ldif); +} + /* modify a database record so msg1 becomes msg2 returns the number of modified elements @@ -91,6 +107,10 @@ static int modify_record(struct ldb_context *ldb, return -1; } + if (verbose > 0) { + ldif_write_msg(ldb, stdout, LDB_CHANGETYPE_MODIFY, &mod); + } + return count; } @@ -130,6 +150,9 @@ static int merge_edits(struct ldb_context *ldb, msgs2[i]->dn, ldb_errstring(ldb)); return -1; } + if (verbose > 0) { + ldif_write_msg(ldb, stdout, LDB_CHANGETYPE_ADD, msgs2[i]); + } adds++; } else { if (modify_record(ldb, msg, msgs2[i]) > 0) { @@ -147,6 +170,9 @@ static int merge_edits(struct ldb_context *ldb, msgs1[i]->dn, ldb_errstring(ldb)); return -1; } + if (verbose > 0) { + ldif_write_msg(ldb, stdout, LDB_CHANGETYPE_DELETE, msgs1[i]); + } deletes++; } } @@ -295,7 +321,7 @@ static void usage(void) editor = "vi"; } - while ((opt = getopt(argc, argv, "hab:e:H:s:")) != EOF) { + while ((opt = getopt(argc, argv, "hab:e:H:s:v")) != EOF) { switch (opt) { case 'b': basedn = optarg; @@ -323,6 +349,10 @@ static void usage(void) expression = "(|(objectclass=*)(dn=*))"; break; + case 'v': + verbose++; + break; + case 'h': default: usage();