svn commit: samba r19273 - in branches/SAMBA_4_0/source/lib/ldb: ldb_ldap tests tools

tridge at samba.org tridge at samba.org
Sat Oct 14 04:43:52 GMT 2006


Author: tridge
Date: 2006-10-14 04:43:51 +0000 (Sat, 14 Oct 2006)
New Revision: 19273

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=19273

Log:

- 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

Modified:
   branches/SAMBA_4_0/source/lib/ldb/ldb_ldap/ldb_ldap.c
   branches/SAMBA_4_0/source/lib/ldb/tests/test-generic.sh
   branches/SAMBA_4_0/source/lib/ldb/tests/test-tdb.sh
   branches/SAMBA_4_0/source/lib/ldb/tests/test.ldif
   branches/SAMBA_4_0/source/lib/ldb/tools/ldbadd.c


Changeset:
Modified: branches/SAMBA_4_0/source/lib/ldb/ldb_ldap/ldb_ldap.c
===================================================================
--- branches/SAMBA_4_0/source/lib/ldb/ldb_ldap/ldb_ldap.c	2006-10-14 01:57:59 UTC (rev 19272)
+++ branches/SAMBA_4_0/source/lib/ldb/ldb_ldap/ldb_ldap.c	2006-10-14 04:43:51 UTC (rev 19273)
@@ -497,9 +497,11 @@
 	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 @@
 	}
 
 	if (matcheddnp) ldap_memfree(matcheddnp);
+	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) {
-		ldb_set_errstring(ac->module->ldb, 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;

Modified: branches/SAMBA_4_0/source/lib/ldb/tests/test-generic.sh
===================================================================
--- branches/SAMBA_4_0/source/lib/ldb/tests/test-generic.sh	2006-10-14 01:57:59 UTC (rev 19272)
+++ branches/SAMBA_4_0/source/lib/ldb/tests/test-generic.sh	2006-10-14 04:43:51 UTC (rev 19273)
@@ -10,6 +10,12 @@
 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 @@
  $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 @@
 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 @@
 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`

Modified: branches/SAMBA_4_0/source/lib/ldb/tests/test-tdb.sh
===================================================================
--- branches/SAMBA_4_0/source/lib/ldb/tests/test-tdb.sh	2006-10-14 01:57:59 UTC (rev 19272)
+++ branches/SAMBA_4_0/source/lib/ldb/tests/test-tdb.sh	2006-10-14 04:43:51 UTC (rev 19273)
@@ -17,6 +17,13 @@
     export LDBDIR
 fi
 
+cat <<EOF | $VALGRIND ldbadd || exit 1
+dn: @MODULES
+ at LIST: rdn_name
+EOF
+
+$VALGRIND ldbadd $LDBDIR/tests/init.ldif || exit 1
+
 . $LDBDIR/tests/test-generic.sh
 
 . $LDBDIR/tests/test-extended.sh

Modified: branches/SAMBA_4_0/source/lib/ldb/tests/test.ldif
===================================================================
--- branches/SAMBA_4_0/source/lib/ldb/tests/test.ldif	2006-10-14 01:57:59 UTC (rev 19272)
+++ branches/SAMBA_4_0/source/lib/ldb/tests/test.ldif	2006-10-14 04:43:51 UTC (rev 19273)
@@ -409,8 +409,3 @@
 pager: +1 313 555 2844
 facsimiletelephonenumber: +1 313 555 9700
 telephonenumber: +1 313 555 5331
-
-dn: ou=Ldb Test,ou=People,o=University of Michigan,c=TEST
-objectclass: organizationalUnit
-ou: Ldb Test
-

Modified: branches/SAMBA_4_0/source/lib/ldb/tools/ldbadd.c
===================================================================
--- branches/SAMBA_4_0/source/lib/ldb/tools/ldbadd.c	2006-10-14 01:57:59 UTC (rev 19272)
+++ branches/SAMBA_4_0/source/lib/ldb/tools/ldbadd.c	2006-10-14 04:43:51 UTC (rev 19273)
@@ -54,10 +54,10 @@
 /*
   add records from an opened file
 */
-static int process_file(struct ldb_context *ldb, FILE *f)
+static int process_file(struct ldb_context *ldb, FILE *f, int *count)
 {
 	struct ldb_ldif *ldif;
-	int ret, count=0;
+	int ret = LDB_SUCCESS;
 
 	while ((ldif = ldb_ldif_read_file(ldb, f))) {
 		if (ldif->changetype != LDB_CHANGETYPE_ADD &&
@@ -74,12 +74,12 @@
 				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 @@
 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 @@
 	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;i<options->argc;i++) {
 			const char *fname = options->argv[i];
@@ -107,7 +107,7 @@
 				perror(fname);
 				exit(1);
 			}
-			count += process_file(ldb, f);
+			ret = process_file(ldb, f, &count);
 			fclose(f);
 		}
 	}
@@ -116,5 +116,5 @@
 
 	printf("Added %d records with %d failures\n", count, failures);
 	
-	return 0;
+	return ret;
 }



More information about the samba-cvs mailing list