[SCM] Samba Shared Repository - branch master updated - release-4-0-0alpha8-783-g57d690b

Andrew Bartlett abartlet at samba.org
Mon Aug 3 21:12:23 MDT 2009


The branch, master has been updated
       via  57d690b6f693d9a90eb77404bbffc05a1c245972 (commit)
       via  3eaef05506d5c17eea4105c4bf3138accd59df9f (commit)
      from  8f110d30517374514c80d9c69e3451adebb74382 (commit)

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 57d690b6f693d9a90eb77404bbffc05a1c245972
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Tue Aug 4 12:52:11 2009 +1000

    s4:torture rework LDAP sort test
    
    This reworks the test to be part of the LDAP tests, to make better use
    of the torture API and the ldb API (in particular around adding
    controls), and a general cleanup.
    
    This also adds the test to the 'make test' run.
    
    Andrew Bartlett

commit 3eaef05506d5c17eea4105c4bf3138accd59df9f
Author: Matthieu Patou <mat at matws.net>
Date:   Tue Aug 4 11:51:46 2009 +1000

    s4:torture Add test for correct server-side sorting over LDAP

-----------------------------------------------------------------------

Summary of changes:
 source4/selftest/tests.sh        |    2 +-
 source4/torture/config.mk        |    6 +-
 source4/torture/ldap/common.c    |    1 +
 source4/torture/ldap/ldap_sort.c |  156 ++++++++++++++++++++++++++++++++++++++
 4 files changed, 161 insertions(+), 4 deletions(-)
 create mode 100644 source4/torture/ldap/ldap_sort.c


Changeset truncated at 500 lines:

diff --git a/source4/selftest/tests.sh b/source4/selftest/tests.sh
index 1b575a9..6c6a09f 100755
--- a/source4/selftest/tests.sh
+++ b/source4/selftest/tests.sh
@@ -120,7 +120,7 @@ if grep ENABLE_GNUTLS.1 include/config.h > /dev/null; then
     done
 fi
 plantest "ldb.ldapi with options $options" dc $bbdir/test_ldb.sh ldapi \$PREFIX_ABS/dc/private/ldapi $options
-for t in LDAP-CLDAP LDAP-BASIC LDAP-SCHEMA LDAP-UPTODATEVECTOR
+for t in `$smb4torture --list | grep "^LDAP-"`
 do
 	plansmbtorturetest "$t" dc "-U\$USERNAME%\$PASSWORD" //\$SERVER_IP/_none_
 done
diff --git a/source4/torture/config.mk b/source4/torture/config.mk
index dd1d5ea..79d9bd0 100644
--- a/source4/torture/config.mk
+++ b/source4/torture/config.mk
@@ -112,7 +112,7 @@ PRIVATE_DEPENDENCIES = \
 		RPC_NDR_SRVSVC RPC_NDR_WKSSVC RPC_NDR_ROT RPC_NDR_DSSETUP \
 		RPC_NDR_REMACT RPC_NDR_OXIDRESOLVER RPC_NDR_NTSVCS WB_HELPER LIBSAMBA-NET \
 		LIBCLI_AUTH POPT_CREDENTIALS TORTURE_LDAP TORTURE_UTIL TORTURE_RAP \
-		dcerpc_server service process_model ntvfs SERVICE_SMB RPC_NDR_BROWSER LIBCLI_DRSUAPI
+		dcerpc_server service process_model ntvfs SERVICE_SMB RPC_NDR_BROWSER LIBCLI_DRSUAPI TORTURE_LDB_MODULE
 
 torture_rpc_OBJ_FILES = $(addprefix $(torturesrcdir)/rpc/, \
 		join.o lsa.o lsa_lookup.o session_key.o echo.o dfs.o drsuapi.o \
@@ -191,11 +191,11 @@ SUBSYSTEM = smbtorture
 OUTPUT_TYPE = MERGED_OBJ
 INIT_FUNCTION = torture_ldap_init
 PRIVATE_DEPENDENCIES = \
-		LIBCLI_LDAP LIBCLI_CLDAP SAMDB POPT_CREDENTIALS torture
+		LIBCLI_LDAP LIBCLI_CLDAP SAMDB POPT_CREDENTIALS torture LDB_WRAP
 # End SUBSYSTEM TORTURE_LDAP
 #################################
 
-TORTURE_LDAP_OBJ_FILES = $(addprefix $(torturesrcdir)/ldap/, common.o basic.o schema.o uptodatevector.o cldap.o cldapbench.o)
+TORTURE_LDAP_OBJ_FILES = $(addprefix $(torturesrcdir)/ldap/, common.o basic.o schema.o uptodatevector.o cldap.o cldapbench.o ldap_sort.o)
 
 $(eval $(call proto_header_template,$(torturesrcdir)/ldap/proto.h,$(TORTURE_LDAP_OBJ_FILES:.o=.c)))
 
diff --git a/source4/torture/ldap/common.c b/source4/torture/ldap/common.c
index 2c11de7..4a2bc2e 100644
--- a/source4/torture/ldap/common.c
+++ b/source4/torture/ldap/common.c
@@ -105,6 +105,7 @@ NTSTATUS torture_ldap_init(void)
 	struct torture_suite *suite = torture_suite_create(talloc_autofree_context(), "LDAP");
 	torture_suite_add_simple_test(suite, "BENCH-CLDAP", torture_bench_cldap);
 	torture_suite_add_simple_test(suite, "BASIC", torture_ldap_basic);
+	torture_suite_add_simple_test(suite, "SORT", torture_ldap_sort);
 	torture_suite_add_simple_test(suite, "CLDAP", torture_cldap);
 	torture_suite_add_simple_test(suite, "SCHEMA", torture_ldap_schema);
 	torture_suite_add_simple_test(suite, "UPTODATEVECTOR", torture_ldap_uptodatevector);
diff --git a/source4/torture/ldap/ldap_sort.c b/source4/torture/ldap/ldap_sort.c
new file mode 100644
index 0000000..4d732cf
--- /dev/null
+++ b/source4/torture/ldap/ldap_sort.c
@@ -0,0 +1,156 @@
+/* 
+   Unix SMB/CIFS implementation.
+   
+   Test LDB attribute functions
+   
+   Copyright (C) Andrew Bartlet <abartlet at samba.org> 2008-2009
+   Copyright (C) Matthieu Patou <mat at matws.net> 2009
+   
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+   
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	See the
+   GNU General Public License for more details.
+   
+   You should have received a copy of the GNU General Public License
+   along with this program.	If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "includes.h"
+#include "lib/events/events.h"
+#include "lib/ldb/include/ldb.h"
+#include "lib/ldb/include/ldb_errors.h"
+#include "ldb_wrap.h"
+#include "param/param.h"
+#include "lib/cmdline/popt_common.h" 
+#include "torture/smbtorture.h"
+#include "torture/local/proto.h"
+#include <ctype.h>
+bool torture_ldap_sort(struct torture_context *torture)
+{
+
+	struct ldb_context *ldb;
+
+	bool ret = false;
+	const char *host = torture_setting_string(torture, "host", NULL);
+	char *url;
+	int i;
+	codepoint_t j;
+	struct ldb_message_element *elem;
+	struct ldb_message *msg;
+
+	struct ldb_server_sort_control **control;
+	struct ldb_request *req;
+	struct ldb_result *ctx;
+	struct ldb_val* prev = NULL;
+	const char *prev_txt = NULL;
+	int prev_len = 0;
+	struct ldb_val* cur = NULL;
+	const char *cur_txt = NULL;
+	int cur_len = 0;
+	struct ldb_dn* dn;
+		 
+		 
+	/* TALLOC_CTX* ctx;*/
+
+	url = talloc_asprintf(torture, "ldap://%s/", host);
+
+	ldb = ldb_wrap_connect(torture, torture->ev, torture->lp_ctx, url,
+						 NULL,
+						 cmdline_credentials,
+						 0, NULL);
+	torture_assert(torture, ldb, "Failed to make LDB connection to target");
+
+	ctx = talloc_zero(ldb, struct ldb_result);
+
+	control = talloc_array(ctx, struct ldb_server_sort_control *, 2);
+	control[0] = talloc(control, struct ldb_server_sort_control);
+	control[0]->attributeName = talloc_strdup(control, "cn");
+	control[0]->orderingRule = NULL;
+	control[0]->reverse = 0;
+	control[1] = NULL;
+
+	dn = ldb_get_root_basedn(ldb);
+	ldb_dn_add_child_fmt(dn, "cn=users");
+	ret = ldb_build_search_req(&req, ldb, ctx,
+				   dn,
+				   LDB_SCOPE_SUBTREE,
+				   "(objectClass=*)", NULL,
+				   NULL,
+				   ctx, ldb_search_default_callback, NULL);
+	torture_assert(torture, ret == LDB_SUCCESS, "Failed to build search request");
+
+	ret = ldb_request_add_control(req, LDB_CONTROL_SERVER_SORT_OID, true, control);
+	torture_assert(torture, ret == LDB_SUCCESS, "Failed to add control to search request");
+
+	ret = ldb_request(ldb, req);
+	torture_assert(torture, ret == LDB_SUCCESS, ldb_errstring(ldb));
+
+	ret = ldb_wait(req->handle, LDB_WAIT_ALL);
+	torture_assert(torture, ret == LDB_SUCCESS, ldb_errstring(ldb));
+
+	ret = true;
+	if (ctx->count > 1) {
+		for (i=0;i<ctx->count;i++) {
+			msg = ctx->msgs[i];
+			elem = ldb_msg_find_element(msg,"cn");
+			cur = elem->values;
+			torture_comment(torture, "cn: %s\n",cur->data);
+			if (prev != NULL)
+			{
+				/* Do only the ascii case right now ... */
+				cur_txt=cur->data;
+				cur_len=cur->length;
+				prev_txt=prev->data;
+				prev_len=prev->length;
+				/* Remove leading whitespace as the sort function do so ... */
+				while ( cur_txt[0] == cur_txt[1] ) { cur_txt++; cur_len--;}
+				while ( prev_txt[0] == prev_txt[1] ) { prev_txt++; prev_len--;}
+				while( *(cur_txt) && *(prev_txt) && cur_len && prev_len ) {
+					j = toupper_m(*(prev_txt))-toupper_m(*(cur_txt));
+					if ( j > 0 ) {
+						/* Just check that is not due to trailling white space in prev_txt 
+						 * That is to say *cur_txt = 0 and prev_txt = 20 */
+						/* Remove trailling whitespace */
+						while ( *prev_txt == ' ' ) { prev_txt++; prev_len--;}
+						while ( *cur_txt == ' ' ) { cur_txt++; cur_len--;}
+						/* Now that potential whitespace are removed if we are at the end 
+						 * of the cur_txt then it means that in fact strings were identical
+						 */
+						torture_assert(torture, *cur_txt && *prev_txt, "Data wrongly sorted");
+						break;
+					}
+					else
+					{
+						if ( j == 0 )
+						{
+							if ( *(cur_txt) == ' ') {
+								while ( cur_txt[0] == cur_txt[1] ) { cur_txt++; cur_len--;}
+								while ( prev_txt[0] == prev_txt[1] ) { prev_txt++; prev_len--;}
+							}
+							cur_txt++;
+							prev_txt++;
+							prev_len--;
+							cur_len--;
+						}
+						else
+						{
+							break;
+						} 
+					}
+				}
+				if ( ret != 1 ) {
+					break;
+				}
+			}
+			prev = cur; 
+		}
+
+	}
+
+	return ret;
+}


-- 
Samba Shared Repository


More information about the samba-cvs mailing list