From 3185ace216586b6f1d676210630206bf00d5474e Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 11 Apr 2004 15:03:31 +0000 Subject: r163: - enable ldap in the sample makefile, and use /usr prefix - show number of adds/deletes/modifies after an edit - nicer error messages from ldbedit (This used to be commit 077951f6bcb1d0eba2de76d0df4c186b7fa19a14) --- source4/lib/ldb/Makefile.ldb | 4 ++-- source4/lib/ldb/tools/ldbedit.c | 36 ++++++++++++++++++++++++------------ 2 files changed, 26 insertions(+), 14 deletions(-) (limited to 'source4') diff --git a/source4/lib/ldb/Makefile.ldb b/source4/lib/ldb/Makefile.ldb index f1b2c8ad21..6ff1bcf78e 100644 --- a/source4/lib/ldb/Makefile.ldb +++ b/source4/lib/ldb/Makefile.ldb @@ -1,9 +1,9 @@ # ldap support is optional edit WITH_LDAP to suit -WITH_LDAP=0 +WITH_LDAP=1 ifeq ($(WITH_LDAP),1) -OPENLDAP_PREFIX=/home/tridge/samba/openldap/prefix +OPENLDAP_PREFIX=/usr LDAP_LIBS=-L$(OPENLDAP_PREFIX)/lib -lldap LDAP_FLAGS=-DHAVE_LDAP=1 LDB_LDAP_OBJ=ldb_ldap/ldb_ldap.o diff --git a/source4/lib/ldb/tools/ldbedit.c b/source4/lib/ldb/tools/ldbedit.c index 13516e59cf..5ae62d3ac1 100644 --- a/source4/lib/ldb/tools/ldbedit.c +++ b/source4/lib/ldb/tools/ldbedit.c @@ -27,7 +27,7 @@ * * Component: ldbedit * - * Description: utility for ldb editing + * Description: utility for ldb database editing * * Author: Andrew Tridgell */ @@ -36,6 +36,7 @@ /* modify a database record so msg1 becomes msg2 + returns the number of modified elements */ static int modify_record(struct ldb_context *ldb, struct ldb_message *msg1, @@ -44,6 +45,7 @@ static int modify_record(struct ldb_context *ldb, struct ldb_message mod; struct ldb_message_element *el; int i; + int count = 0; mod.dn = msg1->dn; mod.num_elements = 0; @@ -63,6 +65,7 @@ static int modify_record(struct ldb_context *ldb, el?LDB_FLAG_MOD_REPLACE:LDB_FLAG_MOD_ADD) != 0) { return -1; } + count++; } /* look in msg1 to find elements that need to be deleted */ @@ -74,6 +77,7 @@ static int modify_record(struct ldb_context *ldb, LDB_FLAG_MOD_DELETE) != 0) { return -1; } + count++; } } @@ -82,11 +86,12 @@ static int modify_record(struct ldb_context *ldb, } if (ldb_modify(ldb, &mod) != 0) { - fprintf(stderr, "failed to modify %s\n", msg1->dn); + fprintf(stderr, "failed to modify %s - %s\n", + msg1->dn, ldb_errstring(ldb)); return -1; } - return 0; + return count; } /* @@ -114,18 +119,22 @@ static int merge_edits(struct ldb_context *ldb, int i; struct ldb_message *msg; int ret = 0; + int adds=0, modifies=0, deletes=0; /* do the adds and modifies */ for (i=0;idn); if (!msg) { if (ldb_add(ldb, msgs2[i]) != 0) { - fprintf(stderr, "failed to add %s\n", - msgs2[i]->dn); + fprintf(stderr, "failed to add %s - %s\n", + msgs2[i]->dn, ldb_errstring(ldb)); return -1; } + adds++; } else { - modify_record(ldb, msg, msgs2[i]); + if (modify_record(ldb, msg, msgs2[i]) > 0) { + modifies++; + } } } @@ -134,13 +143,16 @@ static int merge_edits(struct ldb_context *ldb, msg = msg_find(msgs2, count2, msgs1[i]->dn); if (!msg) { if (ldb_delete(ldb, msgs1[i]->dn) != 0) { - fprintf(stderr, "failed to delete %s\n", - msgs1[i]->dn); + fprintf(stderr, "failed to delete %s - %s\n", + msgs1[i]->dn, ldb_errstring(ldb)); return -1; } + deletes++; } } + printf("# %d adds %d modifies %d deletes\n", adds, modifies, deletes); + return ret; } @@ -151,7 +163,7 @@ static int save_ldif(FILE *f, struct ldb_message **msgs, int count) { int i; - fprintf(f, "# returned %d records\n", count); + fprintf(f, "# editing %d records\n", count); for (i=0;i 0) { ret = ldb_search_free(ldb, msgs); if (ret == -1) { - fprintf(stderr, "search_free failed\n"); + fprintf(stderr, "search_free failed - %s\n", ldb_errstring(ldb)); exit(1); } } -- cgit