From 2ad8e1443de55a005cb9249ba317ab8541ec7c90 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 14 Oct 2006 04:43:51 +0000 Subject: r19273: - fixed error handling with the ldap backend - propogate errors to the ldbadd command line tool - use the rdn_name module when testing the tdb backend to allow the same test code to correctly test the ldap and non-ldap backends (This used to be commit dd82c474a123d90329bda653a4cb73c93e087b15) --- source4/lib/ldb/ldb_ldap/ldb_ldap.c | 12 +++++++++--- source4/lib/ldb/tests/test-generic.sh | 17 +++++++++++++---- source4/lib/ldb/tests/test-tdb.sh | 7 +++++++ source4/lib/ldb/tests/test.ldif | 5 ----- source4/lib/ldb/tools/ldbadd.c | 16 ++++++++-------- 5 files changed, 37 insertions(+), 20 deletions(-) (limited to 'source4/lib/ldb') diff --git a/source4/lib/ldb/ldb_ldap/ldb_ldap.c b/source4/lib/ldb/ldb_ldap/ldb_ldap.c index 10563816b9..a34e35c6db 100644 --- a/source4/lib/ldb/ldb_ldap/ldb_ldap.c +++ b/source4/lib/ldb/ldb_ldap/ldb_ldap.c @@ -497,9 +497,11 @@ static int lldb_parse_result(struct ldb_handle *handle, LDAPMessage *result) char **referralsp = NULL; LDAPControl **serverctrlsp = NULL; int ret = LDB_SUCCESS; - + type = ldap_msgtype(result); + handle->status = 0; + switch (type) { case LDAP_RES_SEARCH_ENTRY: @@ -631,15 +633,19 @@ static int lldb_parse_result(struct ldb_handle *handle, LDAPMessage *result) } if (matcheddnp) ldap_memfree(matcheddnp); - if (errmsgp) { + if (errmsgp && *errmsgp) { ldb_set_errstring(ac->module->ldb, errmsgp); + } else if (handle->status) { + ldb_set_errstring(ac->module->ldb, ldap_err2string(handle->status)); + } + if (errmsgp) { ldap_memfree(errmsgp); } if (referralsp) ldap_value_free(referralsp); if (serverctrlsp) ldap_controls_free(serverctrlsp); ldap_msgfree(result); - return ret; + return lldb_ldap_to_ldb(handle->status); error: handle->state = LDB_ASYNC_DONE; diff --git a/source4/lib/ldb/tests/test-generic.sh b/source4/lib/ldb/tests/test-generic.sh index e4085c6d65..14337cc135 100755 --- a/source4/lib/ldb/tests/test-generic.sh +++ b/source4/lib/ldb/tests/test-generic.sh @@ -10,6 +10,12 @@ echo "LDB_URL: $LDB_URL" echo "Adding base elements" $VALGRIND ldbadd $LDBDIR/tests/test.ldif || exit 1 +echo "Adding again - should fail" +ldbadd $LDBDIR/tests/test.ldif 2> /dev/null && { + echo "Should have failed to add again - gave $?" + exit 1 +} + echo "Modifying elements" $VALGRIND ldbmodify $LDBDIR/tests/test-modify.ldif || exit 1 @@ -32,8 +38,11 @@ if [ $LDB_SPECIALS = 1 ]; then $VALGRIND ldbadd $LDBDIR/tests/test-index.ldif || exit 1 fi -echo "Adding attributes" -$VALGRIND ldbadd $LDBDIR/tests/test-wrong_attributes.ldif || exit 1 +echo "Adding bad attributes - should fail" +$VALGRIND ldbadd $LDBDIR/tests/test-wrong_attributes.ldif && { + echo "Should fhave failed - gave $?" + exit 1 +} echo "testing indexed search" $VALGRIND ldbsearch '(uid=uham)' || exit 1 @@ -75,7 +84,7 @@ echo "Testing binary file attribute value" mkdir -p tests/tmp cp $LDBDIR/tests/samba4.png tests/tmp/samba4.png $VALGRIND ldbmodify $LDBDIR/tests/photo.ldif || exit 1 -count=`$VALGRIND ldbsearch '(cn=Ursula Hampster)' jpegPhoto | grep '^dn' | wc -l` +count=`$VALGRIND ldbsearch '(cn=Hampster Ursula)' jpegPhoto | grep '^dn' | wc -l` if [ $count != 1 ]; then echo returned $count records - expected 1 exit 1 @@ -88,7 +97,7 @@ echo "Testing compare" count=`$VALGRIND ldbsearch '(cn>=t)' cn | grep '^dn' | wc -l` if [ $count != 2 ]; then echo returned $count records - expected 2 - echo "this fails on opsnLdap ..." + echo "this fails on openLdap ..." fi count=`$VALGRIND ldbsearch '(cn<=t)' cn | grep '^dn' | wc -l` diff --git a/source4/lib/ldb/tests/test-tdb.sh b/source4/lib/ldb/tests/test-tdb.sh index e1052d1651..7c4f5205b4 100755 --- a/source4/lib/ldb/tests/test-tdb.sh +++ b/source4/lib/ldb/tests/test-tdb.sh @@ -17,6 +17,13 @@ if [ -z "$LDBDIR" ]; then export LDBDIR fi +cat <changetype != LDB_CHANGETYPE_ADD && @@ -74,12 +74,12 @@ static int process_file(struct ldb_context *ldb, FILE *f) ldb_errstring(ldb), ldb_dn_linearize(ldb, ldif->msg->dn)); failures++; } else { - count++; + (*count)++; } ldb_ldif_read_free(ldb, ldif); } - return count; + return ret; } @@ -87,7 +87,7 @@ static int process_file(struct ldb_context *ldb, FILE *f) int main(int argc, const char **argv) { struct ldb_context *ldb; - int i, count=0; + int i, ret=0, count=0; struct ldb_cmdline *options; ldb_global_init(); @@ -97,7 +97,7 @@ int main(int argc, const char **argv) options = ldb_cmdline_process(ldb, argc, argv, usage); if (options->argc == 0) { - count += process_file(ldb, stdin); + ret = process_file(ldb, stdin, &count); } else { for (i=0;iargc;i++) { const char *fname = options->argv[i]; @@ -107,7 +107,7 @@ int main(int argc, const char **argv) perror(fname); exit(1); } - count += process_file(ldb, f); + ret = process_file(ldb, f, &count); fclose(f); } } @@ -116,5 +116,5 @@ int main(int argc, const char **argv) printf("Added %d records with %d failures\n", count, failures); - return 0; + return ret; } -- cgit