From 8dc636ad674a11825e9043fc356209bf2e28bcff Mon Sep 17 00:00:00 2001 From: Matthieu Patou Date: Sat, 5 Dec 2009 17:56:35 +0300 Subject: [PATCH] s4: tests controls parsing and using for ldbadd/ldbedit/ldbmodify --- source4/lib/ldb/config.mk | 13 ++++++++ source4/lib/ldb/tests/sample_module.c | 30 ++++++++++++++++- source4/lib/ldb/tests/test-controls.sh | 46 ++++++++++++++++++++++++++ source4/lib/ldb/tests/test-tdb.sh | 2 ++ 4 files changed, 90 insertions(+), 1 deletion(-) create mode 100755 source4/lib/ldb/tests/test-controls.sh diff --git a/source4/lib/ldb/config.mk b/source4/lib/ldb/config.mk index 4a1f814baac..7d110fc618e 100644 --- a/source4/lib/ldb/config.mk +++ b/source4/lib/ldb/config.mk @@ -10,6 +10,19 @@ ldb_asq_OBJ_FILES = $(ldbsrcdir)/modules/asq.o # End MODULE ldb_asq ################################################ +################################################ +# Start MODULE sample_module +[MODULE::sample] +PRIVATE_DEPENDENCIES = LIBTALLOC LIBTEVENT +CFLAGS = -I$(ldbsrcdir)/include +INIT_FUNCTION = LDB_MODULE(sample) +SUBSYSTEM = LIBTESTLDB + +# End MODULE sample_module +################################################ +sample_OBJ_FILES = $(ldbsrcdir)/tests/sample_module.o + + ################################################ # Start MODULE ldb_server_sort [MODULE::ldb_server_sort] diff --git a/source4/lib/ldb/tests/sample_module.c b/source4/lib/ldb/tests/sample_module.c index bbe4419b598..bb7906e7ba0 100644 --- a/source4/lib/ldb/tests/sample_module.c +++ b/source4/lib/ldb/tests/sample_module.c @@ -25,12 +25,40 @@ int sample_add(struct ldb_module *mod, struct ldb_request *req) { + struct ldb_control *control; + struct ldb_control *controls; ldb_msg_add_fmt(req->op.add.message, "touchedBy", "sample"); - return ldb_next_request(mod, req); + + /* check if there's a relax control */ + control = ldb_request_get_control(req, LDB_CONTROL_RELAX_OID); + if (control == NULL) { + /* not found go on */ + return ldb_next_request(mod, req); + } else { + return LDB_ERR_UNWILLING_TO_PERFORM; + } +} + +int sample_modify(struct ldb_module *mod, struct ldb_request *req) +{ + struct ldb_control *control; + struct ldb_control *controls; + + /* check if there's a relax control */ + control = ldb_request_get_control(req, LDB_CONTROL_RELAX_OID); + if (control == NULL) { + /* not found go on */ + return ldb_next_request(mod, req); + } else { + return LDB_ERR_UNWILLING_TO_PERFORM; + } } + const struct ldb_module_ops ldb_sample_module_ops = { .name = "sample", .add = sample_add, + .del = sample_modify, + .modify = sample_modify, }; diff --git a/source4/lib/ldb/tests/test-controls.sh b/source4/lib/ldb/tests/test-controls.sh new file mode 100755 index 00000000000..db139bbec7b --- /dev/null +++ b/source4/lib/ldb/tests/test-controls.sh @@ -0,0 +1,46 @@ +#!/bin/sh + +if [ -n "$TEST_DATA_PREFIX" ]; then + LDB_URL="$TEST_DATA_PREFIX/tdbtest.ldb" +else + LDB_URL="tdbtest.ldb" +fi +export LDB_URL + +PATH=bin:$PATH +export PATH + +rm -f $LDB_URL* +LDB_MODULES_PATH=`dirname $0`/../../../bin/modules/testldb +echo $LDB_MODULES_PATH + +echo "LDB_URL: $LDB_URL" +cat <