From 1afda7bdde90948027e3230c19753280afb16e96 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 2 Mar 2007 14:53:09 +0000 Subject: r21656: Move tests a bit closer to the things they test, should make syncing with samba3 easier. (This used to be commit 4d755fb5d7adedd1dd8bad917b921324411bfd59) --- source4/lib/registry/tests/generic.c | 93 ++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 source4/lib/registry/tests/generic.c (limited to 'source4/lib/registry/tests') diff --git a/source4/lib/registry/tests/generic.c b/source4/lib/registry/tests/generic.c new file mode 100644 index 0000000000..d200ba6e1b --- /dev/null +++ b/source4/lib/registry/tests/generic.c @@ -0,0 +1,93 @@ +/* + Unix SMB/CIFS implementation. + + local testing of registry library + + Copyright (C) Jelmer Vernooij 2005 + + 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 2 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, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" +#include "lib/registry/registry.h" +#include "lib/cmdline/popt_common.h" +#include "torture/torture.h" + +const static struct test_backend_settings { + const char *name; + const char *location; +} backends[] = { + { "nt4", "TEST.DAT" }, + { "ldb", "test.ldb" }, + { "gconf", "." }, + { "dir", "." }, + { NULL, NULL } +}; + +static bool test_hive(struct torture_context *tctx, + const void *test_data) +{ + WERROR error; + struct registry_key *root, *subkey; + uint32_t count; + const struct test_backend_settings *backend = test_data; + TALLOC_CTX *mem_ctx = tctx; + + if (!reg_has_backend(backend->name)) { + torture_skip(tctx, talloc_asprintf(tctx, + "Backend '%s' support not compiled in", backend->name)); + } + + error = reg_open_hive(mem_ctx, backend->name, + backend->location, NULL, cmdline_credentials, &root); + torture_assert_werr_ok(tctx, error, "reg_open_hive()"); + + /* This is a new backend. There should be no subkeys and no + * values */ + error = reg_key_num_subkeys(root, &count); + torture_assert_werr_ok(tctx, error, "reg_key_num_subkeys()"); + + torture_assert(tctx, count != 0, "New key has non-zero subkey count"); + + error = reg_key_num_values(root, &count); + torture_assert_werr_ok(tctx, error, "reg_key_num_values"); + + torture_assert(tctx, count != 0, "New key has non-zero value count"); + + error = reg_key_add_name(mem_ctx, root, "Nested\\Key", SEC_MASK_GENERIC, NULL, &subkey); + torture_assert_werr_ok(tctx, error, "reg_key_add_name"); + + error = reg_key_del(root, "Nested\\Key"); + torture_assert_werr_ok(tctx, error, "reg_key_del"); + + talloc_free(root); + return true; +} + + +struct torture_suite *torture_registry(TALLOC_CTX *mem_ctx) +{ + struct torture_suite *suite = torture_suite_create(mem_ctx, + "REGISTRY"); + int i; + + registry_init(); + + for (i = 0; backends[i].name; i++) { + torture_suite_add_simple_tcase(suite, backends[i].name, test_hive, &backends[i]); + } + + return suite; +} -- cgit From d693c2707ba77405fbe42bf6441cc397dd9007a1 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 4 Mar 2007 19:52:16 +0000 Subject: r21685: Add some unit tests for the registry utility functions. (This used to be commit 0ae6d18ebe382a378ff1dc65069c629d8060ac2b) --- source4/lib/registry/tests/generic.c | 109 ++++++++++++++++++++--------------- 1 file changed, 63 insertions(+), 46 deletions(-) (limited to 'source4/lib/registry/tests') diff --git a/source4/lib/registry/tests/generic.c b/source4/lib/registry/tests/generic.c index d200ba6e1b..ac4ab98fc0 100644 --- a/source4/lib/registry/tests/generic.c +++ b/source4/lib/registry/tests/generic.c @@ -24,70 +24,87 @@ #include "lib/registry/registry.h" #include "lib/cmdline/popt_common.h" #include "torture/torture.h" +#include "librpc/gen_ndr/winreg.h" -const static struct test_backend_settings { - const char *name; - const char *location; -} backends[] = { - { "nt4", "TEST.DAT" }, - { "ldb", "test.ldb" }, - { "gconf", "." }, - { "dir", "." }, - { NULL, NULL } -}; - -static bool test_hive(struct torture_context *tctx, - const void *test_data) +static bool test_str_regtype(struct torture_context *ctx) { - WERROR error; - struct registry_key *root, *subkey; - uint32_t count; - const struct test_backend_settings *backend = test_data; - TALLOC_CTX *mem_ctx = tctx; + torture_assert_str_equal(ctx, str_regtype(1), "REG_SZ", "REG_SZ failed"); + torture_assert_str_equal(ctx, str_regtype(4), "REG_DWORD", "REG_DWORD failed"); - if (!reg_has_backend(backend->name)) { - torture_skip(tctx, talloc_asprintf(tctx, - "Backend '%s' support not compiled in", backend->name)); - } - - error = reg_open_hive(mem_ctx, backend->name, - backend->location, NULL, cmdline_credentials, &root); - torture_assert_werr_ok(tctx, error, "reg_open_hive()"); + return true; +} - /* This is a new backend. There should be no subkeys and no - * values */ - error = reg_key_num_subkeys(root, &count); - torture_assert_werr_ok(tctx, error, "reg_key_num_subkeys()"); - torture_assert(tctx, count != 0, "New key has non-zero subkey count"); +static bool test_reg_val_data_string_dword(struct torture_context *ctx) +{ + uint32_t d = 0x20; + DATA_BLOB db = { (uint8_t *)&d, sizeof(d) }; + torture_assert_str_equal(ctx, "0x20", reg_val_data_string(ctx, REG_DWORD, &db), "dword failed"); + return true; +} - error = reg_key_num_values(root, &count); - torture_assert_werr_ok(tctx, error, "reg_key_num_values"); +static bool test_reg_val_data_string_sz(struct torture_context *ctx) +{ + DATA_BLOB db; + db.length = convert_string_talloc(ctx, CH_UNIX, CH_UTF16, "bla", 3, (void **)&db.data); + torture_assert_str_equal(ctx, "bla", reg_val_data_string(ctx, REG_SZ, &db), "sz failed"); + db.length = 4; + torture_assert_str_equal(ctx, "bl", reg_val_data_string(ctx, REG_SZ, &db), "sz failed"); + return true; +} - torture_assert(tctx, count != 0, "New key has non-zero value count"); +static bool test_reg_val_data_string_binary(struct torture_context *ctx) +{ + uint8_t x[] = { 0x1, 0x2, 0x3, 0x4 }; + DATA_BLOB db = { x, 4 }; + torture_assert_str_equal(ctx, "01020304", reg_val_data_string(ctx, REG_BINARY, &db), "binary failed"); + return true; +} - error = reg_key_add_name(mem_ctx, root, "Nested\\Key", SEC_MASK_GENERIC, NULL, &subkey); - torture_assert_werr_ok(tctx, error, "reg_key_add_name"); - error = reg_key_del(root, "Nested\\Key"); - torture_assert_werr_ok(tctx, error, "reg_key_del"); +static bool test_reg_val_data_string_empty(struct torture_context *ctx) +{ + DATA_BLOB db = { NULL, 0 }; + torture_assert_str_equal(ctx, "", reg_val_data_string(ctx, REG_BINARY, &db), "empty failed"); + return true; +} - talloc_free(root); +static bool test_reg_val_description(struct torture_context *ctx) +{ + struct registry_value val; + val.name = "camel"; + val.data_type = REG_SZ; + val.data.length = convert_string_talloc(ctx, CH_UNIX, CH_UTF16, "stationary traveller", + strlen("stationary traveller"), (void **)&val.data.data); + torture_assert_str_equal(ctx, "camel = REG_SZ : stationary traveller", reg_val_description(ctx, &val), + "reg_val_description failed"); return true; } +static bool test_reg_val_description_nullname(struct torture_context *ctx) +{ + struct registry_value val; + val.name = NULL; + val.data_type = REG_SZ; + val.data.length = convert_string_talloc(ctx, CH_UNIX, CH_UTF16, "west berlin", + strlen("west berlin"), (void **)&val.data.data); + torture_assert_str_equal(ctx, " = REG_SZ : west berlin", reg_val_description(ctx, &val), + "description with null name failed"); + return true; +} + struct torture_suite *torture_registry(TALLOC_CTX *mem_ctx) { struct torture_suite *suite = torture_suite_create(mem_ctx, "REGISTRY"); - int i; - - registry_init(); - - for (i = 0; backends[i].name; i++) { - torture_suite_add_simple_tcase(suite, backends[i].name, test_hive, &backends[i]); - } + torture_suite_add_simple_test(suite, "str_regtype", test_str_regtype); + torture_suite_add_simple_test(suite, "reg_val_data_string dword", test_reg_val_data_string_dword); + torture_suite_add_simple_test(suite, "reg_val_data_string sz", test_reg_val_data_string_sz); + torture_suite_add_simple_test(suite, "reg_val_data_string binary", test_reg_val_data_string_binary); + torture_suite_add_simple_test(suite, "reg_val_data_string empty", test_reg_val_data_string_empty); + torture_suite_add_simple_test(suite, "reg_val_description", test_reg_val_description); + torture_suite_add_simple_test(suite, "reg_val_description null", test_reg_val_description_nullname); return suite; } -- cgit From 0479a2f1cbae51fcd8dbdc3c148c808421fb4d25 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 02:07:03 +0000 Subject: r23792: convert Samba4 to GPLv3 There are still a few tidyups of old FSF addresses to come (in both s3 and s4). More commits soon. (This used to be commit fcf38a38ac691abd0fa51b89dc951a08e89fdafa) --- source4/lib/registry/tests/generic.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'source4/lib/registry/tests') diff --git a/source4/lib/registry/tests/generic.c b/source4/lib/registry/tests/generic.c index ac4ab98fc0..1f0c89e058 100644 --- a/source4/lib/registry/tests/generic.c +++ b/source4/lib/registry/tests/generic.c @@ -7,7 +7,7 @@ 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 2 of the License, or + 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, @@ -16,8 +16,7 @@ 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, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ #include "includes.h" -- cgit From b409d4120f9ae451f93a2322267c0f346531d9f3 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 26 Aug 2007 15:16:40 +0000 Subject: r24667: Finally merge the registry improvements that Wilco Baan Hofman and I have been working on for at least half a year now. Contains the following improvements: * proper layering (finally!) for the registry library. Distinction is now made between 'real' backends (local, remote, wine, etc) and the low-level hive backends (regf, creg, ldb, ...) that are only used by the local registry backend * tests for all important hive and registry operations * re-enable RPC-WINREG tests (still needs more work though, as some return values aren't checked yet) * write support for REGF files * dir backend now supports setting/reading values, creating keys * support for storing security descriptors * remove CREG backend as it was incomplete, didn't match the data model and wasn't used at all anyway * support for parsing ADM files as used by the policy editor (see lib/policy) * support for parsing PREG files (format used by .POL files) * new streaming interface for registry diffs (improves speed and memory usage for regdiff/regpatch significantly) ... and fixes a large number of bugs in the registry code (This used to be commit 7a1eec6358bc863dfc671c542b7185d3e39d7b5a) --- source4/lib/registry/tests/diff.c | 105 ++++++++ source4/lib/registry/tests/generic.c | 66 +++-- source4/lib/registry/tests/hive.c | 383 +++++++++++++++++++++++++++ source4/lib/registry/tests/registry.c | 486 ++++++++++++++++++++++++++++++++++ 4 files changed, 1016 insertions(+), 24 deletions(-) create mode 100644 source4/lib/registry/tests/diff.c create mode 100644 source4/lib/registry/tests/hive.c create mode 100644 source4/lib/registry/tests/registry.c (limited to 'source4/lib/registry/tests') diff --git a/source4/lib/registry/tests/diff.c b/source4/lib/registry/tests/diff.c new file mode 100644 index 0000000000..220da88601 --- /dev/null +++ b/source4/lib/registry/tests/diff.c @@ -0,0 +1,105 @@ +/* + Unix SMB/CIFS implementation. + + local testing of registry diff functionality + + Copyright (C) Jelmer Vernooij 2007 + + 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 . +*/ + +#include "includes.h" +#include "lib/registry/registry.h" +#include "lib/cmdline/popt_common.h" +#include "torture/torture.h" +#include "librpc/gen_ndr/winreg.h" + +static bool test_generate_diff(struct torture_context *test) +{ + /* WERROR reg_generate_diff(struct registry_context *ctx1, + struct registry_context *ctx2, + const struct reg_diff_callbacks *callbacks, + void *callback_data) + */ + return true; +} + + +static bool test_diff_load(struct torture_context *test) +{ + /* WERROR reg_diff_load(const char *filename, const struct reg_diff_callbacks *callbacks, void *callback_data) */ + + return true; +} + +static bool test_diff_apply(struct torture_context *test) +{ + /* +_PUBLIC_ WERROR reg_diff_apply (const char *filename, struct registry_context *ctx) + */ + + return true; +} + +static const char *added_key = NULL; + +static WERROR test_add_key (void *callback_data, const char *key_name) +{ + added_key = talloc_strdup(callback_data, key_name); + + return WERR_OK; +} + +static bool test_generate_diff_key_add(struct torture_context *test) +{ + struct reg_diff_callbacks cb; + struct registry_key rk; + + return true; + + ZERO_STRUCT(cb); + + cb.add_key = test_add_key; + + if (W_ERROR_IS_OK(reg_generate_diff_key(&rk, NULL, "bla", &cb, test))) + return false; + + torture_assert_str_equal(test, added_key, "bla", "key added"); + + return true; +} + +static bool test_generate_diff_key_null(struct torture_context *test) +{ + struct reg_diff_callbacks cb; + + ZERO_STRUCT(cb); + + if (!W_ERROR_IS_OK(reg_generate_diff_key(NULL, NULL, "", &cb, NULL))) + return false; + + return true; +} + +struct torture_suite *torture_registry_diff(TALLOC_CTX *mem_ctx) +{ + struct torture_suite *suite = torture_suite_create(mem_ctx, + "DIFF"); + torture_suite_add_simple_test(suite, "test_generate_diff_key_add", test_generate_diff_key_add); + torture_suite_add_simple_test(suite, "test_generate_diff_key_null", test_generate_diff_key_null); + torture_suite_add_simple_test(suite, "test_diff_apply", test_diff_apply); + torture_suite_add_simple_test(suite, "test_generate_diff", test_generate_diff); + torture_suite_add_simple_test(suite, "test_diff_load", test_diff_load); + return suite; +} diff --git a/source4/lib/registry/tests/generic.c b/source4/lib/registry/tests/generic.c index 1f0c89e058..6595f86b18 100644 --- a/source4/lib/registry/tests/generic.c +++ b/source4/lib/registry/tests/generic.c @@ -3,7 +3,7 @@ local testing of registry library - Copyright (C) Jelmer Vernooij 2005 + Copyright (C) Jelmer Vernooij 2005-2007 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 @@ -25,6 +25,10 @@ #include "torture/torture.h" #include "librpc/gen_ndr/winreg.h" +struct torture_suite *torture_registry_hive(TALLOC_CTX *mem_ctx); +struct torture_suite *torture_registry_registry(TALLOC_CTX *mem_ctx); +struct torture_suite *torture_registry_diff(TALLOC_CTX *mem_ctx); + static bool test_str_regtype(struct torture_context *ctx) { torture_assert_str_equal(ctx, str_regtype(1), "REG_SZ", "REG_SZ failed"); @@ -38,7 +42,8 @@ static bool test_reg_val_data_string_dword(struct torture_context *ctx) { uint32_t d = 0x20; DATA_BLOB db = { (uint8_t *)&d, sizeof(d) }; - torture_assert_str_equal(ctx, "0x20", reg_val_data_string(ctx, REG_DWORD, &db), "dword failed"); + torture_assert_str_equal(ctx, "0x20", + reg_val_data_string(ctx, REG_DWORD, db), "dword failed"); return true; } @@ -46,9 +51,9 @@ static bool test_reg_val_data_string_sz(struct torture_context *ctx) { DATA_BLOB db; db.length = convert_string_talloc(ctx, CH_UNIX, CH_UTF16, "bla", 3, (void **)&db.data); - torture_assert_str_equal(ctx, "bla", reg_val_data_string(ctx, REG_SZ, &db), "sz failed"); + torture_assert_str_equal(ctx, "bla", reg_val_data_string(ctx, REG_SZ, db), "sz failed"); db.length = 4; - torture_assert_str_equal(ctx, "bl", reg_val_data_string(ctx, REG_SZ, &db), "sz failed"); + torture_assert_str_equal(ctx, "bl", reg_val_data_string(ctx, REG_SZ, db), "sz failed"); return true; } @@ -56,7 +61,9 @@ static bool test_reg_val_data_string_binary(struct torture_context *ctx) { uint8_t x[] = { 0x1, 0x2, 0x3, 0x4 }; DATA_BLOB db = { x, 4 }; - torture_assert_str_equal(ctx, "01020304", reg_val_data_string(ctx, REG_BINARY, &db), "binary failed"); + torture_assert_str_equal(ctx, "01020304", + reg_val_data_string(ctx, REG_BINARY, db), + "binary failed"); return true; } @@ -64,18 +71,20 @@ static bool test_reg_val_data_string_binary(struct torture_context *ctx) static bool test_reg_val_data_string_empty(struct torture_context *ctx) { DATA_BLOB db = { NULL, 0 }; - torture_assert_str_equal(ctx, "", reg_val_data_string(ctx, REG_BINARY, &db), "empty failed"); + torture_assert_str_equal(ctx, "", + reg_val_data_string(ctx, REG_BINARY, db), "empty failed"); return true; } static bool test_reg_val_description(struct torture_context *ctx) { - struct registry_value val; - val.name = "camel"; - val.data_type = REG_SZ; - val.data.length = convert_string_talloc(ctx, CH_UNIX, CH_UTF16, "stationary traveller", - strlen("stationary traveller"), (void **)&val.data.data); - torture_assert_str_equal(ctx, "camel = REG_SZ : stationary traveller", reg_val_description(ctx, &val), + DATA_BLOB data; + data.length = convert_string_talloc(ctx, CH_UNIX, CH_UTF16, + "stationary traveller", + strlen("stationary traveller"), + (void **)&data.data); + torture_assert_str_equal(ctx, "camel = REG_SZ : stationary traveller", + reg_val_description(ctx, "camel", REG_SZ, data), "reg_val_description failed"); return true; } @@ -83,12 +92,11 @@ static bool test_reg_val_description(struct torture_context *ctx) static bool test_reg_val_description_nullname(struct torture_context *ctx) { - struct registry_value val; - val.name = NULL; - val.data_type = REG_SZ; - val.data.length = convert_string_talloc(ctx, CH_UNIX, CH_UTF16, "west berlin", - strlen("west berlin"), (void **)&val.data.data); - torture_assert_str_equal(ctx, " = REG_SZ : west berlin", reg_val_description(ctx, &val), + DATA_BLOB data; + data.length = convert_string_talloc(ctx, CH_UNIX, CH_UTF16, "west berlin", + strlen("west berlin"), (void **)&data.data); + torture_assert_str_equal(ctx, " = REG_SZ : west berlin", + reg_val_description(ctx, NULL, REG_SZ, data), "description with null name failed"); return true; } @@ -98,12 +106,22 @@ struct torture_suite *torture_registry(TALLOC_CTX *mem_ctx) struct torture_suite *suite = torture_suite_create(mem_ctx, "REGISTRY"); torture_suite_add_simple_test(suite, "str_regtype", test_str_regtype); - torture_suite_add_simple_test(suite, "reg_val_data_string dword", test_reg_val_data_string_dword); - torture_suite_add_simple_test(suite, "reg_val_data_string sz", test_reg_val_data_string_sz); - torture_suite_add_simple_test(suite, "reg_val_data_string binary", test_reg_val_data_string_binary); - torture_suite_add_simple_test(suite, "reg_val_data_string empty", test_reg_val_data_string_empty); - torture_suite_add_simple_test(suite, "reg_val_description", test_reg_val_description); - torture_suite_add_simple_test(suite, "reg_val_description null", test_reg_val_description_nullname); + torture_suite_add_simple_test(suite, "reg_val_data_string dword", + test_reg_val_data_string_dword); + torture_suite_add_simple_test(suite, "reg_val_data_string sz", + test_reg_val_data_string_sz); + torture_suite_add_simple_test(suite, "reg_val_data_string binary", + test_reg_val_data_string_binary); + torture_suite_add_simple_test(suite, "reg_val_data_string empty", + test_reg_val_data_string_empty); + torture_suite_add_simple_test(suite, "reg_val_description", + test_reg_val_description); + torture_suite_add_simple_test(suite, "reg_val_description null", + test_reg_val_description_nullname); + + torture_suite_add_suite(suite, torture_registry_hive(mem_ctx)); + torture_suite_add_suite(suite, torture_registry_registry(mem_ctx)); + torture_suite_add_suite(suite, torture_registry_diff(mem_ctx)); return suite; } diff --git a/source4/lib/registry/tests/hive.c b/source4/lib/registry/tests/hive.c new file mode 100644 index 0000000000..a04bc1168e --- /dev/null +++ b/source4/lib/registry/tests/hive.c @@ -0,0 +1,383 @@ +/* + Unix SMB/CIFS implementation. + + local testing of registry library - hives + + Copyright (C) Jelmer Vernooij 2005-2007 + + 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 2 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, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" +#include "lib/registry/registry.h" +#include "lib/cmdline/popt_common.h" +#include "torture/torture.h" +#include "librpc/gen_ndr/winreg.h" +#include "system/filesys.h" + +NTSTATUS torture_temp_dir(struct torture_context *tctx, const char *prefix, + const char **tempdir); + +static bool test_del_nonexistant_key(struct torture_context *tctx, + const void *test_data) +{ + const struct hive_key *root = test_data; + WERROR error = hive_key_del(root, "bla"); + torture_assert_werr_equal(tctx, error, WERR_NOT_FOUND, + "invalid return code"); + + return true; +} + +static bool test_keyinfo_root(struct torture_context *tctx, + const void *test_data) +{ + uint32_t num_subkeys, num_values; + const struct hive_key *root = test_data; + WERROR error; + + /* This is a new backend. There should be no subkeys and no + * values */ + error = hive_key_get_info(tctx, root, NULL, &num_subkeys, &num_values, + NULL); + torture_assert_werr_ok(tctx, error, "reg_key_num_subkeys()"); + + torture_assert_int_equal(tctx, num_subkeys, 0, "New key has non-zero subkey count"); + + torture_assert_werr_ok(tctx, error, "reg_key_num_values"); + + torture_assert_int_equal(tctx, num_values, 0, "New key has non-zero value count"); + + return true; +} + +static bool test_keyinfo_nums(struct torture_context *tctx, + const void *test_data) +{ + uint32_t num_subkeys, num_values; + const struct hive_key *root = test_data; + WERROR error; + struct hive_key *subkey; + uint32_t data = 42; + + error = hive_key_add_name(tctx, root, "Nested Keyll", NULL, + NULL, &subkey); + torture_assert_werr_ok(tctx, error, "hive_key_add_name"); + + error = hive_set_value(root, "Answer", REG_DWORD, + data_blob_talloc(tctx, &data, sizeof(data))); + torture_assert_werr_ok(tctx, error, "hive_set_value"); + + /* This is a new backend. There should be no subkeys and no + * values */ + error = hive_key_get_info(tctx, root, NULL, &num_subkeys, &num_values, + NULL); + torture_assert_werr_ok(tctx, error, "reg_key_num_subkeys()"); + + torture_assert_int_equal(tctx, num_subkeys, 1, "subkey count"); + + torture_assert_werr_ok(tctx, error, "reg_key_num_values"); + + torture_assert_int_equal(tctx, num_values, 1, "value count"); + + return true; +} + +static bool test_add_subkey(struct torture_context *tctx, + const void *test_data) +{ + WERROR error; + struct hive_key *subkey; + const struct hive_key *root = test_data; + TALLOC_CTX *mem_ctx = tctx; + + error = hive_key_add_name(mem_ctx, root, "Nested Key", NULL, + NULL, &subkey); + torture_assert_werr_ok(tctx, error, "hive_key_add_name"); + + error = hive_key_del(root, "Nested Key"); + torture_assert_werr_ok(tctx, error, "reg_key_del"); + + return true; +} + +static bool test_flush_key(struct torture_context *tctx, + const void *test_data) +{ + const struct hive_key *root = test_data; + + torture_assert_werr_ok(tctx, hive_key_flush(root), "flush key"); + + return true; +} + +static bool test_del_key(struct torture_context *tctx, const void *test_data) +{ + WERROR error; + struct hive_key *subkey; + const struct hive_key *root = test_data; + TALLOC_CTX *mem_ctx = tctx; + + error = hive_key_add_name(mem_ctx, root, "Nested Key", NULL, + NULL, &subkey); + torture_assert_werr_ok(tctx, error, "hive_key_add_name"); + + error = hive_key_del(root, "Nested Key"); + torture_assert_werr_ok(tctx, error, "reg_key_del"); + + error = hive_key_del(root, "Nested Key"); + torture_assert_werr_equal(tctx, error, WERR_NOT_FOUND, "reg_key_del"); + + return true; +} + +static bool test_set_value(struct torture_context *tctx, + const void *test_data) +{ + WERROR error; + struct hive_key *subkey; + const struct hive_key *root = test_data; + TALLOC_CTX *mem_ctx = tctx; + uint32_t data = 42; + + error = hive_key_add_name(mem_ctx, root, "YA Nested Key", NULL, + NULL, &subkey); + torture_assert_werr_ok(tctx, error, "hive_key_add_name"); + + error = hive_set_value(subkey, "Answer", REG_DWORD, + data_blob_talloc(mem_ctx, &data, sizeof(data))); + torture_assert_werr_ok(tctx, error, "hive_set_value"); + + return true; +} + +static bool test_get_value(struct torture_context *tctx, const void *test_data) +{ + WERROR error; + struct hive_key *subkey; + const struct hive_key *root = test_data; + TALLOC_CTX *mem_ctx = tctx; + uint32_t data = 42; + uint32_t type; + DATA_BLOB value; + + error = hive_key_add_name(mem_ctx, root, "EYA Nested Key", NULL, + NULL, &subkey); + torture_assert_werr_ok(tctx, error, "hive_key_add_name"); + + error = hive_get_value(mem_ctx, subkey, "Answer", &type, &value); + torture_assert_werr_equal(tctx, error, WERR_NOT_FOUND, + "getting missing value"); + + error = hive_set_value(subkey, "Answer", REG_DWORD, + data_blob_talloc(mem_ctx, &data, sizeof(data))); + torture_assert_werr_ok(tctx, error, "hive_set_value"); + + error = hive_get_value(mem_ctx, subkey, "Answer", &type, &value); + torture_assert_werr_ok(tctx, error, "getting value"); + + torture_assert(tctx, memcmp(value.data, &data, 4) == 0, "value data"); + + torture_assert_int_equal(tctx, value.length, 4, "value length"); + torture_assert_int_equal(tctx, type, REG_DWORD, "value type"); + + return true; +} + +static bool test_del_value(struct torture_context *tctx, const void *test_data) +{ + WERROR error; + struct hive_key *subkey; + const struct hive_key *root = test_data; + TALLOC_CTX *mem_ctx = tctx; + uint32_t data = 42; + uint32_t type; + DATA_BLOB value; + + error = hive_key_add_name(mem_ctx, root, "EEYA Nested Key", NULL, + NULL, &subkey); + torture_assert_werr_ok(tctx, error, "hive_key_add_name"); + + error = hive_set_value(subkey, "Answer", REG_DWORD, + data_blob_talloc(mem_ctx, &data, sizeof(data))); + torture_assert_werr_ok(tctx, error, "hive_set_value"); + + error = hive_del_value(subkey, "Answer"); + torture_assert_werr_ok(tctx, error, "deleting value"); + + error = hive_get_value(mem_ctx, subkey, "Answer", &type, &value); + torture_assert_werr_equal(tctx, error, WERR_NOT_FOUND, "getting value"); + + error = hive_del_value(subkey, "Answer"); + torture_assert_werr_equal(tctx, error, WERR_NOT_FOUND, "deleting value"); + + return true; +} + +static bool test_list_values(struct torture_context *tctx, + const void *test_data) +{ + WERROR error; + struct hive_key *subkey; + const struct hive_key *root = test_data; + TALLOC_CTX *mem_ctx = tctx; + uint32_t data = 42; + uint32_t type; + DATA_BLOB value; + const char *name; + + error = hive_key_add_name(mem_ctx, root, "AYAYA Nested Key", NULL, + NULL, &subkey); + torture_assert_werr_ok(tctx, error, "hive_key_add_name"); + + error = hive_set_value(subkey, "Answer", REG_DWORD, + data_blob_talloc(mem_ctx, &data, sizeof(data))); + torture_assert_werr_ok(tctx, error, "hive_set_value"); + + error = hive_get_value_by_index(mem_ctx, subkey, 0, &name, &type, &value); + torture_assert_werr_ok(tctx, error, "getting value"); + + torture_assert_str_equal(tctx, name, "Answer", "value name"); + torture_assert(tctx, memcmp(value.data, &data, 4) == 0, "value data"); + + torture_assert_int_equal(tctx, value.length, 4, "value length"); + torture_assert_int_equal(tctx, type, REG_DWORD, "value type"); + + error = hive_get_value_by_index(mem_ctx, subkey, 1, &name, &type, &value); + torture_assert_werr_equal(tctx, error, WERR_NO_MORE_ITEMS, + "getting missing value"); + + return true; +} + +static void tcase_add_tests(struct torture_tcase *tcase) +{ + torture_tcase_add_simple_test(tcase, "del_nonexistant_key", + test_del_nonexistant_key); + torture_tcase_add_simple_test(tcase, "add_subkey", test_add_subkey); + torture_tcase_add_simple_test(tcase, "flush_key", test_flush_key); + torture_tcase_add_simple_test(tcase, "get_info", test_keyinfo_root); + torture_tcase_add_simple_test(tcase, "get_info_nums", test_keyinfo_nums); + torture_tcase_add_simple_test(tcase, "set_value", test_set_value); + torture_tcase_add_simple_test(tcase, "get_value", test_get_value); + torture_tcase_add_simple_test(tcase, "list_values", test_list_values); + torture_tcase_add_simple_test(tcase, "del_key", test_del_key); + torture_tcase_add_simple_test(tcase, "del_value", test_del_value); +} + +static bool hive_setup_dir(struct torture_context *tctx, void **data) +{ + struct hive_key *key; + WERROR error; + const char *dirname; + NTSTATUS status; + + status = torture_temp_dir(tctx, "hive-dir", &dirname); + if (!NT_STATUS_IS_OK(status)) + return false; + + rmdir(dirname); + + error = reg_create_directory(tctx, dirname, &key); + if (!W_ERROR_IS_OK(error)) { + fprintf(stderr, "Unable to initialize dir hive\n"); + return false; + } + + *data = key; + + return true; +} + +static bool hive_setup_ldb(struct torture_context *tctx, void **data) +{ + struct hive_key *key; + WERROR error; + const char *dirname; + NTSTATUS status; + + status = torture_temp_dir(tctx, "hive-ldb", &dirname); + if (!NT_STATUS_IS_OK(status)) + return false; + + rmdir(dirname); + + error = reg_open_ldb_file(tctx, dirname, NULL, NULL, &key); + if (!W_ERROR_IS_OK(error)) { + fprintf(stderr, "Unable to initialize ldb hive\n"); + return false; + } + + *data = key; + + return true; +} + +static bool hive_setup_regf(struct torture_context *tctx, void **data) +{ + struct hive_key *key; + WERROR error; + const char *dirname; + NTSTATUS status; + + status = torture_temp_dir(tctx, "hive-dir", &dirname); + if (!NT_STATUS_IS_OK(status)) + return false; + + rmdir(dirname); + + error = reg_create_regf_file(tctx, dirname, 5, &key); + if (!W_ERROR_IS_OK(error)) { + fprintf(stderr, "Unable to create new regf file\n"); + return false; + } + + *data = key; + + return true; +} + +static bool test_dir_refuses_null_location(struct torture_context *tctx) +{ + torture_assert_werr_equal(tctx, WERR_INVALID_PARAM, + reg_open_directory(NULL, NULL, NULL), + "reg_open_directory accepts NULL location"); + return true; +} + +struct torture_suite *torture_registry_hive(TALLOC_CTX *mem_ctx) +{ + struct torture_tcase *tcase; + struct torture_suite *suite = torture_suite_create(mem_ctx, + "HIVE"); + + torture_suite_add_simple_test(suite, "dir-refuses-null-location", + test_dir_refuses_null_location); + + + tcase = torture_suite_add_tcase(suite, "dir"); + torture_tcase_set_fixture(tcase, hive_setup_dir, NULL); + tcase_add_tests(tcase); + + tcase = torture_suite_add_tcase(suite, "ldb"); + torture_tcase_set_fixture(tcase, hive_setup_ldb, NULL); + tcase_add_tests(tcase); + + tcase = torture_suite_add_tcase(suite, "regf"); + torture_tcase_set_fixture(tcase, hive_setup_regf, NULL); + tcase_add_tests(tcase); + + return suite; +} diff --git a/source4/lib/registry/tests/registry.c b/source4/lib/registry/tests/registry.c new file mode 100644 index 0000000000..851f74fa3c --- /dev/null +++ b/source4/lib/registry/tests/registry.c @@ -0,0 +1,486 @@ +/* + Unix SMB/CIFS implementation. + + local testing of registry library - registry backend + + Copyright (C) Jelmer Vernooij 2005-2007 + + 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 2 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, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" +#include "lib/registry/registry.h" +#include "lib/cmdline/popt_common.h" +#include "torture/torture.h" +#include "librpc/gen_ndr/winreg.h" +#include "system/filesys.h" + +NTSTATUS torture_temp_dir(struct torture_context *tctx, const char *prefix, + const char **tempdir); + +/** + * Test obtaining a predefined key. + */ +static bool test_get_predefined(struct torture_context *tctx, + const void *_data) +{ + const struct registry_context *rctx = _data; + struct registry_key *root; + WERROR error; + + error = reg_get_predefined_key(rctx, HKEY_CLASSES_ROOT, &root); + torture_assert_werr_ok(tctx, error, + "getting predefined key failed"); + return true; +} + +/** + * Test creating a new subkey + */ +static bool test_create_subkey(struct torture_context *tctx, + const void *_data) +{ + const struct registry_context *rctx = _data; + struct registry_key *root, *newkey; + WERROR error; + + error = reg_get_predefined_key(rctx, HKEY_CLASSES_ROOT, &root); + torture_assert_werr_ok(tctx, error, + "getting predefined key failed"); + + error = reg_key_add_name(rctx, root, "Bad Bentheim", NULL, NULL, &newkey); + torture_assert_werr_ok(tctx, error, "Creating key return code"); + torture_assert(tctx, newkey != NULL, "Creating new key"); + + return true; +} + +/** + * Test creating a new nested subkey + */ +static bool test_create_nested_subkey(struct torture_context *tctx, + const void *_data) +{ + const struct registry_context *rctx = _data; + struct registry_key *root, *newkey1, *newkey2; + WERROR error; + + error = reg_get_predefined_key(rctx, HKEY_CLASSES_ROOT, &root); + torture_assert_werr_ok(tctx, error, + "getting predefined key failed"); + + error = reg_key_add_name(rctx, root, "Hamburg", NULL, NULL, + &newkey1); + torture_assert_werr_ok(tctx, error, "Creating key return code"); + torture_assert(tctx, newkey2 != NULL, "Creating new key"); + + error = reg_key_add_name(rctx, root, "Hamburg\\Hamburg", NULL, NULL, + &newkey2); + torture_assert_werr_ok(tctx, error, "Creating key return code"); + torture_assert(tctx, newkey2 != NULL, "Creating new key"); + + return true; +} + +/** + * Test creating a new subkey + */ +static bool test_key_add_abs_top(struct torture_context *tctx, + const void *_data) +{ + const struct registry_context *rctx = _data; + struct registry_key *root; + WERROR error; + + error = reg_key_add_abs(tctx, rctx, "HKEY_CLASSES_ROOT", 0, NULL, &root); + torture_assert_werr_equal(tctx, error, WERR_ALREADY_EXISTS, "create top level"); + + return true; +} + +/** + * Test creating a new subkey + */ +static bool test_key_add_abs(struct torture_context *tctx, + const void *_data) +{ + WERROR error; + const struct registry_context *rctx = _data; + struct registry_key *root, *result1, *result2; + + error = reg_key_add_abs(tctx, rctx, "HKEY_CLASSES_ROOT\\bloe", 0, NULL, &result1); + torture_assert_werr_ok(tctx, error, "create lowest"); + + error = reg_key_add_abs(tctx, rctx, "HKEY_CLASSES_ROOT\\bloe\\bla", 0, NULL, &result1); + torture_assert_werr_ok(tctx, error, "create nested"); + + error = reg_get_predefined_key(rctx, HKEY_CLASSES_ROOT, &root); + torture_assert_werr_ok(tctx, error, + "getting predefined key failed"); + + error = reg_open_key(tctx, root, "bloe", &result2); + torture_assert_werr_ok(tctx, error, "opening key"); + + error = reg_open_key(tctx, root, "bloe\\bla", &result2); + torture_assert_werr_ok(tctx, error, "opening key"); + + return true; +} + + +static bool test_del_key(struct torture_context *tctx, const void *_data) +{ + const struct registry_context *rctx = _data; + struct registry_key *root, *newkey; + WERROR error; + + error = reg_get_predefined_key(rctx, HKEY_CLASSES_ROOT, &root); + torture_assert_werr_ok(tctx, error, + "getting predefined key failed"); + + error = reg_key_add_name(rctx, root, "Hamburg", NULL, NULL, &newkey); + + torture_assert_werr_ok(tctx, error, "Creating key return code"); + torture_assert(tctx, newkey != NULL, "Creating new key"); + + error = reg_key_del(root, "Hamburg"); + torture_assert_werr_ok(tctx, error, "Delete key"); + + error = reg_key_del(root, "Hamburg"); + torture_assert_werr_equal(tctx, error, WERR_NOT_FOUND, + "Delete missing key"); + + return true; +} + +/** + * Convenience function for opening the HKEY_CLASSES_ROOT hive and + * creating a single key for testing purposes. + */ +static bool create_test_key(struct torture_context *tctx, + const struct registry_context *rctx, + const char *name, + struct registry_key **root, + struct registry_key **subkey) +{ + WERROR error; + + error = reg_get_predefined_key(rctx, HKEY_CLASSES_ROOT, root); + torture_assert_werr_ok(tctx, error, + "getting predefined key failed"); + + error = reg_key_add_name(rctx, *root, name, NULL, NULL, subkey); + torture_assert_werr_ok(tctx, error, "Creating key return code"); + + return true; +} + + +static bool test_flush_key(struct torture_context *tctx, const void *_data) +{ + const struct registry_context *rctx = _data; + struct registry_key *root, *subkey; + WERROR error; + + if (!create_test_key(tctx, rctx, "Munchen", &root, &subkey)) + return false; + + error = reg_key_flush(subkey); + torture_assert_werr_ok(tctx, error, "flush key"); + + return true; +} + +static bool test_query_key(struct torture_context *tctx, const void *_data) +{ + const struct registry_context *rctx = _data; + struct registry_key *root, *subkey; + WERROR error; + NTTIME last_changed_time; + uint32_t num_subkeys, num_values; + const char *classname; + + if (!create_test_key(tctx, rctx, "Munchen", &root, &subkey)) + return false; + + error = reg_key_get_info(tctx, subkey, &classname, + &num_subkeys, &num_values, + &last_changed_time); + + torture_assert_werr_ok(tctx, error, "get info key"); + torture_assert(tctx, classname == NULL, "classname"); + torture_assert_int_equal(tctx, num_subkeys, 0, "num subkeys"); + torture_assert_int_equal(tctx, num_values, 0, "num values"); + + return true; +} + +static bool test_query_key_nums(struct torture_context *tctx, const void *_data) +{ + const struct registry_context *rctx = _data; + struct registry_key *root, *subkey1, *subkey2; + WERROR error; + uint32_t num_subkeys, num_values; + uint32_t data = 42; + + if (!create_test_key(tctx, rctx, "Berlin", &root, &subkey1)) + return false; + + error = reg_key_add_name(rctx, subkey1, "Bentheim", NULL, NULL, &subkey2); + torture_assert_werr_ok(tctx, error, "Creating key return code"); + + error = reg_val_set(subkey1, "Answer", REG_DWORD, + data_blob_talloc(tctx, &data, sizeof(data))); + torture_assert_werr_ok(tctx, error, "set value"); + + error = reg_key_get_info(tctx, subkey1, NULL, &num_subkeys, + &num_values, NULL); + + torture_assert_werr_ok(tctx, error, "get info key"); + torture_assert_int_equal(tctx, num_subkeys, 1, "num subkeys"); + torture_assert_int_equal(tctx, num_values, 1, "num values"); + + return true; +} + +/** + * Test that the subkeys of a key can be enumerated, that + * the returned parameters for get_subkey_by_index are optional and + * that enumerating the parents of a non-top-level node works. + */ +static bool test_list_subkeys(struct torture_context *tctx, const void *_data) +{ + const struct registry_context *rctx = _data; + struct registry_key *subkey = NULL, *root; + WERROR error; + NTTIME last_mod_time; + const char *classname, *name; + + if (!create_test_key(tctx, rctx, "Goettingen", &root, &subkey)) + return false; + + error = reg_key_get_subkey_by_index(tctx, root, 0, &name, &classname, + &last_mod_time); + + torture_assert_werr_ok(tctx, error, "Enum keys return code"); + torture_assert_str_equal(tctx, name, "Goettingen", "Enum keys data"); + + + error = reg_key_get_subkey_by_index(tctx, root, 0, NULL, NULL, NULL); + + torture_assert_werr_ok(tctx, error, "Enum keys with NULL arguments return code"); + + error = reg_key_get_subkey_by_index(tctx, root, 1, NULL, NULL, NULL); + + torture_assert_werr_equal(tctx, error, WERR_NO_MORE_ITEMS, + "Invalid error for no more items"); + + error = reg_key_get_subkey_by_index(tctx, subkey, 0, NULL, NULL, NULL); + + torture_assert_werr_equal(tctx, error, WERR_NO_MORE_ITEMS, + "Invalid error for no more items"); + + return true; +} + +/** + * Test setting a value + */ +static bool test_set_value(struct torture_context *tctx, const void *_data) +{ + const struct registry_context *rctx = _data; + struct registry_key *subkey = NULL, *root; + WERROR error; + uint32_t data = 42; + + if (!create_test_key(tctx, rctx, "Dusseldorf", &root, &subkey)) + return false; + + error = reg_val_set(subkey, "Answer", REG_DWORD, + data_blob_talloc(tctx, &data, sizeof(data))); + torture_assert_werr_ok (tctx, error, "setting value"); + + return true; +} + +/** + * Test getting a value + */ +static bool test_get_value(struct torture_context *tctx, const void *_data) +{ + const struct registry_context *rctx = _data; + struct registry_key *subkey = NULL, *root; + WERROR error; + DATA_BLOB data; + uint32_t value = 42; + uint32_t type; + + if (!create_test_key(tctx, rctx, "Duisburg", &root, &subkey)) + return false; + + error = reg_key_get_value_by_name(tctx, subkey, __FUNCTION__, &type, + &data); + torture_assert_werr_equal(tctx, error, WERR_NOT_FOUND, + "getting missing value"); + + error = reg_val_set(subkey, __FUNCTION__, REG_DWORD, + data_blob_talloc(tctx, &value, 4)); + torture_assert_werr_ok (tctx, error, "setting value"); + + error = reg_key_get_value_by_name(tctx, subkey, __FUNCTION__, &type, + &data); + torture_assert_werr_ok(tctx, error, "getting value"); + + torture_assert_int_equal(tctx, 4, data.length, "value length ok"); + torture_assert(tctx, memcmp(data.data, &value, 4) == 0, "value content ok"); + torture_assert_int_equal(tctx, REG_DWORD, type, "value type"); + + return true; +} + +/** + * Test unsetting a value + */ +static bool test_del_value(struct torture_context *tctx, const void *_data) +{ + const struct registry_context *rctx = _data; + struct registry_key *subkey = NULL, *root; + WERROR error; + DATA_BLOB data; + uint32_t value = 42; + uint32_t type; + + if (!create_test_key(tctx, rctx, "Duisburg", &root, &subkey)) + return false; + + error = reg_key_get_value_by_name(tctx, subkey, __FUNCTION__, &type, + &data); + torture_assert_werr_equal(tctx, error, WERR_NOT_FOUND, + "getting missing value"); + + error = reg_val_set(subkey, __FUNCTION__, REG_DWORD, + data_blob_talloc(tctx, &value, 4)); + torture_assert_werr_ok (tctx, error, "setting value"); + + error = reg_del_value(subkey, __FUNCTION__); + torture_assert_werr_ok (tctx, error, "unsetting value"); + + error = reg_key_get_value_by_name(tctx, subkey, __FUNCTION__, &type, &data); + torture_assert_werr_equal(tctx, error, WERR_NOT_FOUND, + "getting missing value"); + + return true; +} + +/** + * Test listing values + */ +static bool test_list_values(struct torture_context *tctx, const void *_data) +{ + const struct registry_context *rctx = _data; + struct registry_key *subkey = NULL, *root; + WERROR error; + DATA_BLOB data; + uint32_t value = 42; + uint32_t type; + const char *name; + + if (!create_test_key(tctx, rctx, "Bonn", &root, &subkey)) + return false; + + error = reg_val_set(subkey, "bar", REG_DWORD, + data_blob_talloc(tctx, &value, 4)); + torture_assert_werr_ok (tctx, error, "setting value"); + + error = reg_key_get_value_by_index(tctx, subkey, 0, &name, &type, &data); + torture_assert_werr_ok(tctx, error, "getting value"); + + torture_assert_str_equal(tctx, name, "bar", "value name"); + torture_assert_int_equal(tctx, 4, data.length, "value length"); + torture_assert(tctx, memcmp(data.data, &value, 4) == 0, "value content"); + torture_assert_int_equal(tctx, REG_DWORD, type, "value type"); + + error = reg_key_get_value_by_index(tctx, subkey, 1, &name, &type, &data); + torture_assert_werr_equal(tctx, error, WERR_NO_MORE_ITEMS, + "getting missing value"); + + return true; +} + +static bool setup_local_registry(struct torture_context *tctx, void **data) +{ + struct registry_context *rctx; + WERROR error; + const char *tempdir; + NTSTATUS status; + struct hive_key *hive_key; + + error = reg_open_local(tctx, &rctx, NULL, NULL); + if (!W_ERROR_IS_OK(error)) + return false; + + status = torture_temp_dir(tctx, "registry-local", &tempdir); + if (!NT_STATUS_IS_OK(status)) + return false; + + error = reg_open_ldb_file(tctx, + talloc_asprintf(tctx, "%s/classes_root.ldb", tempdir), + NULL, + NULL, + &hive_key); + if (!W_ERROR_IS_OK(error)) + return false; + + error = reg_mount_hive(rctx, hive_key, HKEY_CLASSES_ROOT, NULL); + if (!W_ERROR_IS_OK(error)) + return false; + + *data = rctx; + + return true; +} + +static void tcase_add_tests(struct torture_tcase *tcase) +{ + torture_tcase_add_simple_test(tcase, "list_subkeys", test_list_subkeys); + torture_tcase_add_simple_test(tcase, "get_predefined_key", + test_get_predefined); + torture_tcase_add_simple_test(tcase, "create_key", test_create_subkey); + torture_tcase_add_simple_test(tcase, "create_key", + test_create_nested_subkey); + torture_tcase_add_simple_test(tcase, "key_add_abs", test_key_add_abs); + torture_tcase_add_simple_test(tcase, "key_add_abs_top", test_key_add_abs_top); + torture_tcase_add_simple_test(tcase, "set_value", test_set_value); + torture_tcase_add_simple_test(tcase, "get_value", test_get_value); + torture_tcase_add_simple_test(tcase, "list_values", test_list_values); + torture_tcase_add_simple_test(tcase, "del_key", test_del_key); + torture_tcase_add_simple_test(tcase, "del_value", test_del_value); + torture_tcase_add_simple_test(tcase, "flush_key", test_flush_key); + torture_tcase_add_simple_test(tcase, "query_key", test_query_key); + torture_tcase_add_simple_test(tcase, "query_key_nums", test_query_key_nums); +} + +struct torture_suite *torture_registry_registry(TALLOC_CTX *mem_ctx) +{ + struct torture_tcase *tcase; + struct torture_suite *suite = torture_suite_create(mem_ctx, + "REGISTRY"); + + tcase = torture_suite_add_tcase(suite, "local"); + torture_tcase_set_fixture(tcase, setup_local_registry, NULL); + tcase_add_tests(tcase); + + return suite; +} -- cgit From f96b1778a42d8388fd1c6384cd7c90b6e4bcd437 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 26 Aug 2007 19:58:40 +0000 Subject: r24674: Make sure results are always on a new line, fix typo in test name. (This used to be commit 40c1635b39b4acff0acecc734583daa0217215ce) --- source4/lib/registry/tests/registry.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'source4/lib/registry/tests') diff --git a/source4/lib/registry/tests/registry.c b/source4/lib/registry/tests/registry.c index 851f74fa3c..0fda7587dc 100644 --- a/source4/lib/registry/tests/registry.c +++ b/source4/lib/registry/tests/registry.c @@ -46,6 +46,22 @@ static bool test_get_predefined(struct torture_context *tctx, return true; } +/** + * Test obtaining a predefined key. + */ +static bool test_get_predefined_unknown(struct torture_context *tctx, + const void *_data) +{ + const struct registry_context *rctx = _data; + struct registry_key *root; + WERROR error; + + error = reg_get_predefined_key(rctx, 1337, &root); + torture_assert_werr_equal(tctx, error, WERR_BADFILE, + "getting predefined key failed"); + return true; +} + /** * Test creating a new subkey */ @@ -200,6 +216,9 @@ static bool test_flush_key(struct torture_context *tctx, const void *_data) error = reg_key_flush(subkey); torture_assert_werr_ok(tctx, error, "flush key"); + torture_assert_werr_equal(tctx, reg_key_flush(NULL), + WERR_INVALID_PARAM, "flush key"); + return true; } @@ -457,6 +476,8 @@ static void tcase_add_tests(struct torture_tcase *tcase) torture_tcase_add_simple_test(tcase, "list_subkeys", test_list_subkeys); torture_tcase_add_simple_test(tcase, "get_predefined_key", test_get_predefined); + torture_tcase_add_simple_test(tcase, "get_predefined_key", + test_get_predefined_unknown); torture_tcase_add_simple_test(tcase, "create_key", test_create_subkey); torture_tcase_add_simple_test(tcase, "create_key", test_create_nested_subkey); -- cgit From 3c9f28334c62167c80589b348c7662388342a922 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 26 Aug 2007 21:52:27 +0000 Subject: r24683: Add two more tests. (This used to be commit c87576743b09773489478e6eebeb3a282d6ec21b) --- source4/lib/registry/tests/generic.c | 2 ++ source4/lib/registry/tests/registry.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) (limited to 'source4/lib/registry/tests') diff --git a/source4/lib/registry/tests/generic.c b/source4/lib/registry/tests/generic.c index 6595f86b18..549ed6282d 100644 --- a/source4/lib/registry/tests/generic.c +++ b/source4/lib/registry/tests/generic.c @@ -101,6 +101,8 @@ static bool test_reg_val_description_nullname(struct torture_context *ctx) return true; } + + struct torture_suite *torture_registry(TALLOC_CTX *mem_ctx) { struct torture_suite *suite = torture_suite_create(mem_ctx, diff --git a/source4/lib/registry/tests/registry.c b/source4/lib/registry/tests/registry.c index 0fda7587dc..2aab034ff3 100644 --- a/source4/lib/registry/tests/registry.c +++ b/source4/lib/registry/tests/registry.c @@ -57,6 +57,37 @@ static bool test_get_predefined_unknown(struct torture_context *tctx, WERROR error; error = reg_get_predefined_key(rctx, 1337, &root); + torture_assert_werr_equal(tctx, error, WERR_NOT_FOUND, + "getting predefined key failed"); + return true; +} + +static bool test_predef_key_by_name(struct torture_context *tctx, + const void *_data) +{ + const struct registry_context *rctx = _data; + struct registry_key *root; + WERROR error; + + error = reg_get_predefined_key_by_name(rctx, "HKEY_CLASSES_ROOT", &root); + torture_assert_werr_ok(tctx, error, + "getting predefined key failed"); + + error = reg_get_predefined_key_by_name(rctx, "HKEY_classes_ROOT", &root); + torture_assert_werr_ok(tctx, error, + "getting predefined key case insensitively failed"); + + return true; +} + +static bool test_predef_key_by_name_invalid(struct torture_context *tctx, + const void *_data) +{ + const struct registry_context *rctx = _data; + struct registry_key *root; + WERROR error; + + error = reg_get_predefined_key_by_name(tctx, "BLA", &root); torture_assert_werr_equal(tctx, error, WERR_BADFILE, "getting predefined key failed"); return true; @@ -491,6 +522,10 @@ static void tcase_add_tests(struct torture_tcase *tcase) torture_tcase_add_simple_test(tcase, "flush_key", test_flush_key); torture_tcase_add_simple_test(tcase, "query_key", test_query_key); torture_tcase_add_simple_test(tcase, "query_key_nums", test_query_key_nums); + torture_tcase_add_simple_test(tcase, "test_predef_key_by_name", + test_predef_key_by_name); + torture_tcase_add_simple_test(tcase, "test_predef_key_by_name_invalid", + test_predef_key_by_name_invalid); } struct torture_suite *torture_registry_registry(TALLOC_CTX *mem_ctx) -- cgit From 616c45f16a56527f54d428a7fbeabcc9952459f5 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 27 Aug 2007 18:56:46 +0000 Subject: r24718: Fix some compiler warnings. (This used to be commit 08f7389ab7312d350e056b1ba98da86d80944424) --- source4/lib/registry/tests/diff.c | 4 +--- source4/lib/registry/tests/registry.c | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) (limited to 'source4/lib/registry/tests') diff --git a/source4/lib/registry/tests/diff.c b/source4/lib/registry/tests/diff.c index 220da88601..99a4589309 100644 --- a/source4/lib/registry/tests/diff.c +++ b/source4/lib/registry/tests/diff.c @@ -45,9 +45,7 @@ static bool test_diff_load(struct torture_context *test) static bool test_diff_apply(struct torture_context *test) { - /* -_PUBLIC_ WERROR reg_diff_apply (const char *filename, struct registry_context *ctx) - */ + /* _PUBLIC_ WERROR reg_diff_apply (const char *filename, struct registry_context *ctx) */ return true; } diff --git a/source4/lib/registry/tests/registry.c b/source4/lib/registry/tests/registry.c index 2aab034ff3..dfc8e09d57 100644 --- a/source4/lib/registry/tests/registry.c +++ b/source4/lib/registry/tests/registry.c @@ -87,7 +87,7 @@ static bool test_predef_key_by_name_invalid(struct torture_context *tctx, struct registry_key *root; WERROR error; - error = reg_get_predefined_key_by_name(tctx, "BLA", &root); + error = reg_get_predefined_key_by_name(rctx, "BLA", &root); torture_assert_werr_equal(tctx, error, WERR_BADFILE, "getting predefined key failed"); return true; -- cgit From 5d518417f8dc64ce9bbfedc3ddb988d69961bde4 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 27 Aug 2007 22:01:58 +0000 Subject: r24726: Add tests for getting/setting security descriptors (still failing at the moment) (This used to be commit ecdfaf56c09e75dc3ca37a3599c89661ad3485ff) --- source4/lib/registry/tests/registry.c | 37 +++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'source4/lib/registry/tests') diff --git a/source4/lib/registry/tests/registry.c b/source4/lib/registry/tests/registry.c index dfc8e09d57..fd2e98eac8 100644 --- a/source4/lib/registry/tests/registry.c +++ b/source4/lib/registry/tests/registry.c @@ -25,6 +25,7 @@ #include "lib/cmdline/popt_common.h" #include "torture/torture.h" #include "librpc/gen_ndr/winreg.h" +#include "libcli/security/security.h" #include "system/filesys.h" NTSTATUS torture_temp_dir(struct torture_context *tctx, const char *prefix, @@ -365,6 +366,40 @@ static bool test_set_value(struct torture_context *tctx, const void *_data) return true; } +/** + * Test getting/setting security descriptors + */ +static bool test_security(struct torture_context *tctx, const void *_data) +{ + const struct registry_context *rctx = _data; + struct registry_key *subkey = NULL, *root; + WERROR error; + uint32_t data = 42; + struct security_descriptor *osd, *nsd; + + if (!create_test_key(tctx, rctx, "Düsseldorf", &root, &subkey)) + return false; + + osd = security_descriptor_create(tctx, + NULL, NULL, + SID_NT_AUTHENTICATED_USERS, + SEC_ACE_TYPE_ACCESS_ALLOWED, + SEC_GENERIC_ALL, + SEC_ACE_FLAG_OBJECT_INHERIT, + NULL); + + error = reg_set_security(subkey, osd); + torture_assert_werr_ok(tctx, error, "setting security"); + + error = reg_get_security(tctx, subkey, &nsd); + torture_assert_werr_ok (tctx, error, "setting security"); + + torture_assert(tctx, security_descriptor_equal(osd, nsd), + "security descriptor changed!"); + + return true; +} + /** * Test getting a value */ @@ -524,6 +559,8 @@ static void tcase_add_tests(struct torture_tcase *tcase) torture_tcase_add_simple_test(tcase, "query_key_nums", test_query_key_nums); torture_tcase_add_simple_test(tcase, "test_predef_key_by_name", test_predef_key_by_name); + torture_tcase_add_simple_test(tcase, "security", + test_security); torture_tcase_add_simple_test(tcase, "test_predef_key_by_name_invalid", test_predef_key_by_name_invalid); } -- cgit From 033c2c07a3a080922a35cc674163b1768d0ff227 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 2 Sep 2007 16:17:12 +0000 Subject: r24898: Fix LOCAL-REGISTRY, do not silently ignore testcase setup failures. (This used to be commit 527ea7fccf4ace9cd9cbacf49820ecd208b8d570) --- source4/lib/registry/tests/registry.c | 42 +++++++++++++---------------------- 1 file changed, 15 insertions(+), 27 deletions(-) (limited to 'source4/lib/registry/tests') diff --git a/source4/lib/registry/tests/registry.c b/source4/lib/registry/tests/registry.c index fd2e98eac8..9ac61b1bc0 100644 --- a/source4/lib/registry/tests/registry.c +++ b/source4/lib/registry/tests/registry.c @@ -132,7 +132,7 @@ static bool test_create_nested_subkey(struct torture_context *tctx, error = reg_key_add_name(rctx, root, "Hamburg", NULL, NULL, &newkey1); torture_assert_werr_ok(tctx, error, "Creating key return code"); - torture_assert(tctx, newkey2 != NULL, "Creating new key"); + torture_assert(tctx, newkey1 != NULL, "Creating new key"); error = reg_key_add_name(rctx, root, "Hamburg\\Hamburg", NULL, NULL, &newkey2); @@ -374,7 +374,6 @@ static bool test_security(struct torture_context *tctx, const void *_data) const struct registry_context *rctx = _data; struct registry_key *subkey = NULL, *root; WERROR error; - uint32_t data = 42; struct security_descriptor *osd, *nsd; if (!create_test_key(tctx, rctx, "Düsseldorf", &root, &subkey)) @@ -511,26 +510,20 @@ static bool setup_local_registry(struct torture_context *tctx, void **data) const char *tempdir; NTSTATUS status; struct hive_key *hive_key; + const char *filename; error = reg_open_local(tctx, &rctx, NULL, NULL); - if (!W_ERROR_IS_OK(error)) - return false; + torture_assert_werr_ok(tctx, error, "Opening local registry failed"); status = torture_temp_dir(tctx, "registry-local", &tempdir); - if (!NT_STATUS_IS_OK(status)) - return false; + torture_assert_ntstatus_ok(tctx, status, "Creating temp dir failed"); - error = reg_open_ldb_file(tctx, - talloc_asprintf(tctx, "%s/classes_root.ldb", tempdir), - NULL, - NULL, - &hive_key); - if (!W_ERROR_IS_OK(error)) - return false; + filename = talloc_asprintf(tctx, "%s/classes_root.ldb", tempdir); + error = reg_open_ldb_file(tctx, filename, NULL, NULL, &hive_key); + torture_assert_werr_ok(tctx, error, "Opening classes_root file failed"); error = reg_mount_hive(rctx, hive_key, HKEY_CLASSES_ROOT, NULL); - if (!W_ERROR_IS_OK(error)) - return false; + torture_assert_werr_ok(tctx, error, "Mounting hive failed"); *data = rctx; @@ -540,13 +533,10 @@ static bool setup_local_registry(struct torture_context *tctx, void **data) static void tcase_add_tests(struct torture_tcase *tcase) { torture_tcase_add_simple_test(tcase, "list_subkeys", test_list_subkeys); - torture_tcase_add_simple_test(tcase, "get_predefined_key", - test_get_predefined); - torture_tcase_add_simple_test(tcase, "get_predefined_key", - test_get_predefined_unknown); + torture_tcase_add_simple_test(tcase, "get_predefined_key", test_get_predefined); + torture_tcase_add_simple_test(tcase, "get_predefined_key", test_get_predefined_unknown); torture_tcase_add_simple_test(tcase, "create_key", test_create_subkey); - torture_tcase_add_simple_test(tcase, "create_key", - test_create_nested_subkey); + torture_tcase_add_simple_test(tcase, "create_key", test_create_nested_subkey); torture_tcase_add_simple_test(tcase, "key_add_abs", test_key_add_abs); torture_tcase_add_simple_test(tcase, "key_add_abs_top", test_key_add_abs_top); torture_tcase_add_simple_test(tcase, "set_value", test_set_value); @@ -558,18 +548,16 @@ static void tcase_add_tests(struct torture_tcase *tcase) torture_tcase_add_simple_test(tcase, "query_key", test_query_key); torture_tcase_add_simple_test(tcase, "query_key_nums", test_query_key_nums); torture_tcase_add_simple_test(tcase, "test_predef_key_by_name", - test_predef_key_by_name); - torture_tcase_add_simple_test(tcase, "security", - test_security); + test_predef_key_by_name); + torture_tcase_add_simple_test(tcase, "security", test_security); torture_tcase_add_simple_test(tcase, "test_predef_key_by_name_invalid", - test_predef_key_by_name_invalid); + test_predef_key_by_name_invalid); } struct torture_suite *torture_registry_registry(TALLOC_CTX *mem_ctx) { struct torture_tcase *tcase; - struct torture_suite *suite = torture_suite_create(mem_ctx, - "REGISTRY"); + struct torture_suite *suite = torture_suite_create(mem_ctx, "REGISTRY"); tcase = torture_suite_add_tcase(suite, "local"); torture_tcase_set_fixture(tcase, setup_local_registry, NULL); -- cgit From 98b57d5eb61094a9c88e2f7d90d3e21b7e74e9d8 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 8 Sep 2007 16:46:30 +0000 Subject: r25035: Fix some more warnings, use service pointer rather than service number in more places. (This used to be commit df9cebcb97e20564359097148665bd519f31bc6f) --- source4/lib/registry/tests/hive.c | 24 ++++++++--------- source4/lib/registry/tests/registry.c | 51 +++++++++++++++++++++++------------ 2 files changed, 46 insertions(+), 29 deletions(-) (limited to 'source4/lib/registry/tests') diff --git a/source4/lib/registry/tests/hive.c b/source4/lib/registry/tests/hive.c index a04bc1168e..a71e31474c 100644 --- a/source4/lib/registry/tests/hive.c +++ b/source4/lib/registry/tests/hive.c @@ -31,9 +31,9 @@ NTSTATUS torture_temp_dir(struct torture_context *tctx, const char *prefix, const char **tempdir); static bool test_del_nonexistant_key(struct torture_context *tctx, - const void *test_data) + const void *test_data) { - const struct hive_key *root = test_data; + const struct hive_key *root = (const struct hive_key *)test_data; WERROR error = hive_key_del(root, "bla"); torture_assert_werr_equal(tctx, error, WERR_NOT_FOUND, "invalid return code"); @@ -45,7 +45,7 @@ static bool test_keyinfo_root(struct torture_context *tctx, const void *test_data) { uint32_t num_subkeys, num_values; - const struct hive_key *root = test_data; + const struct hive_key *root = (const struct hive_key *)test_data; WERROR error; /* This is a new backend. There should be no subkeys and no @@ -67,7 +67,7 @@ static bool test_keyinfo_nums(struct torture_context *tctx, const void *test_data) { uint32_t num_subkeys, num_values; - const struct hive_key *root = test_data; + const struct hive_key *root = (const struct hive_key *)test_data; WERROR error; struct hive_key *subkey; uint32_t data = 42; @@ -100,7 +100,7 @@ static bool test_add_subkey(struct torture_context *tctx, { WERROR error; struct hive_key *subkey; - const struct hive_key *root = test_data; + const struct hive_key *root = (const struct hive_key *)test_data; TALLOC_CTX *mem_ctx = tctx; error = hive_key_add_name(mem_ctx, root, "Nested Key", NULL, @@ -114,9 +114,9 @@ static bool test_add_subkey(struct torture_context *tctx, } static bool test_flush_key(struct torture_context *tctx, - const void *test_data) + const void *test_data) { - const struct hive_key *root = test_data; + const struct hive_key *root = (const struct hive_key *)test_data; torture_assert_werr_ok(tctx, hive_key_flush(root), "flush key"); @@ -127,7 +127,7 @@ static bool test_del_key(struct torture_context *tctx, const void *test_data) { WERROR error; struct hive_key *subkey; - const struct hive_key *root = test_data; + const struct hive_key *root = (const struct hive_key *)test_data; TALLOC_CTX *mem_ctx = tctx; error = hive_key_add_name(mem_ctx, root, "Nested Key", NULL, @@ -148,7 +148,7 @@ static bool test_set_value(struct torture_context *tctx, { WERROR error; struct hive_key *subkey; - const struct hive_key *root = test_data; + const struct hive_key *root = (const struct hive_key *)test_data; TALLOC_CTX *mem_ctx = tctx; uint32_t data = 42; @@ -167,7 +167,7 @@ static bool test_get_value(struct torture_context *tctx, const void *test_data) { WERROR error; struct hive_key *subkey; - const struct hive_key *root = test_data; + const struct hive_key *root = (const struct hive_key *)test_data; TALLOC_CTX *mem_ctx = tctx; uint32_t data = 42; uint32_t type; @@ -200,7 +200,7 @@ static bool test_del_value(struct torture_context *tctx, const void *test_data) { WERROR error; struct hive_key *subkey; - const struct hive_key *root = test_data; + const struct hive_key *root = (const struct hive_key *)test_data; TALLOC_CTX *mem_ctx = tctx; uint32_t data = 42; uint32_t type; @@ -231,7 +231,7 @@ static bool test_list_values(struct torture_context *tctx, { WERROR error; struct hive_key *subkey; - const struct hive_key *root = test_data; + const struct hive_key *root = (const struct hive_key *)test_data; TALLOC_CTX *mem_ctx = tctx; uint32_t data = 42; uint32_t type; diff --git a/source4/lib/registry/tests/registry.c b/source4/lib/registry/tests/registry.c index 9ac61b1bc0..9809a6d4c8 100644 --- a/source4/lib/registry/tests/registry.c +++ b/source4/lib/registry/tests/registry.c @@ -37,7 +37,8 @@ NTSTATUS torture_temp_dir(struct torture_context *tctx, const char *prefix, static bool test_get_predefined(struct torture_context *tctx, const void *_data) { - const struct registry_context *rctx = _data; + const struct registry_context *rctx = + (const struct registry_context *)_data; struct registry_key *root; WERROR error; @@ -66,7 +67,8 @@ static bool test_get_predefined_unknown(struct torture_context *tctx, static bool test_predef_key_by_name(struct torture_context *tctx, const void *_data) { - const struct registry_context *rctx = _data; + const struct registry_context *rctx = + (const struct registry_context *)_data; struct registry_key *root; WERROR error; @@ -84,7 +86,8 @@ static bool test_predef_key_by_name(struct torture_context *tctx, static bool test_predef_key_by_name_invalid(struct torture_context *tctx, const void *_data) { - const struct registry_context *rctx = _data; + const struct registry_context *rctx = + (const struct registry_context *)_data; struct registry_key *root; WERROR error; @@ -100,7 +103,8 @@ static bool test_predef_key_by_name_invalid(struct torture_context *tctx, static bool test_create_subkey(struct torture_context *tctx, const void *_data) { - const struct registry_context *rctx = _data; + const struct registry_context *rctx = + (const struct registry_context *)_data; struct registry_key *root, *newkey; WERROR error; @@ -121,7 +125,8 @@ static bool test_create_subkey(struct torture_context *tctx, static bool test_create_nested_subkey(struct torture_context *tctx, const void *_data) { - const struct registry_context *rctx = _data; + const struct registry_context *rctx = + (const struct registry_context *)_data; struct registry_key *root, *newkey1, *newkey2; WERROR error; @@ -148,7 +153,8 @@ static bool test_create_nested_subkey(struct torture_context *tctx, static bool test_key_add_abs_top(struct torture_context *tctx, const void *_data) { - const struct registry_context *rctx = _data; + const struct registry_context *rctx = + (const struct registry_context *)_data; struct registry_key *root; WERROR error; @@ -165,7 +171,8 @@ static bool test_key_add_abs(struct torture_context *tctx, const void *_data) { WERROR error; - const struct registry_context *rctx = _data; + const struct registry_context *rctx = + (const struct registry_context *)_data; struct registry_key *root, *result1, *result2; error = reg_key_add_abs(tctx, rctx, "HKEY_CLASSES_ROOT\\bloe", 0, NULL, &result1); @@ -190,7 +197,8 @@ static bool test_key_add_abs(struct torture_context *tctx, static bool test_del_key(struct torture_context *tctx, const void *_data) { - const struct registry_context *rctx = _data; + const struct registry_context *rctx = + (const struct registry_context *)_data; struct registry_key *root, *newkey; WERROR error; @@ -238,7 +246,8 @@ static bool create_test_key(struct torture_context *tctx, static bool test_flush_key(struct torture_context *tctx, const void *_data) { - const struct registry_context *rctx = _data; + const struct registry_context *rctx = + (const struct registry_context *)_data; struct registry_key *root, *subkey; WERROR error; @@ -256,7 +265,8 @@ static bool test_flush_key(struct torture_context *tctx, const void *_data) static bool test_query_key(struct torture_context *tctx, const void *_data) { - const struct registry_context *rctx = _data; + const struct registry_context *rctx = + (const struct registry_context *)_data; struct registry_key *root, *subkey; WERROR error; NTTIME last_changed_time; @@ -280,7 +290,8 @@ static bool test_query_key(struct torture_context *tctx, const void *_data) static bool test_query_key_nums(struct torture_context *tctx, const void *_data) { - const struct registry_context *rctx = _data; + const struct registry_context *rctx = + (const struct registry_context *)_data; struct registry_key *root, *subkey1, *subkey2; WERROR error; uint32_t num_subkeys, num_values; @@ -313,7 +324,8 @@ static bool test_query_key_nums(struct torture_context *tctx, const void *_data) */ static bool test_list_subkeys(struct torture_context *tctx, const void *_data) { - const struct registry_context *rctx = _data; + const struct registry_context *rctx = + (const struct registry_context *)_data; struct registry_key *subkey = NULL, *root; WERROR error; NTTIME last_mod_time; @@ -351,7 +363,8 @@ static bool test_list_subkeys(struct torture_context *tctx, const void *_data) */ static bool test_set_value(struct torture_context *tctx, const void *_data) { - const struct registry_context *rctx = _data; + const struct registry_context *rctx = + (const struct registry_context *)_data; struct registry_key *subkey = NULL, *root; WERROR error; uint32_t data = 42; @@ -371,7 +384,8 @@ static bool test_set_value(struct torture_context *tctx, const void *_data) */ static bool test_security(struct torture_context *tctx, const void *_data) { - const struct registry_context *rctx = _data; + const struct registry_context *rctx = + (const struct registry_context *)_data; struct registry_key *subkey = NULL, *root; WERROR error; struct security_descriptor *osd, *nsd; @@ -404,7 +418,8 @@ static bool test_security(struct torture_context *tctx, const void *_data) */ static bool test_get_value(struct torture_context *tctx, const void *_data) { - const struct registry_context *rctx = _data; + const struct registry_context *rctx = + (const struct registry_context *)_data; struct registry_key *subkey = NULL, *root; WERROR error; DATA_BLOB data; @@ -439,7 +454,8 @@ static bool test_get_value(struct torture_context *tctx, const void *_data) */ static bool test_del_value(struct torture_context *tctx, const void *_data) { - const struct registry_context *rctx = _data; + const struct registry_context *rctx = + (const struct registry_context *)_data; struct registry_key *subkey = NULL, *root; WERROR error; DATA_BLOB data; @@ -473,7 +489,8 @@ static bool test_del_value(struct torture_context *tctx, const void *_data) */ static bool test_list_values(struct torture_context *tctx, const void *_data) { - const struct registry_context *rctx = _data; + const struct registry_context *rctx = + (const struct registry_context *)_data; struct registry_key *subkey = NULL, *root; WERROR error; DATA_BLOB data; -- cgit From ab309ada8ba2e4ef867f7fdb13012d09cb8d05c9 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Wed, 12 Sep 2007 07:29:29 +0000 Subject: r25112: make torture_temp_dir() available via tortore/torture.h and return more detailed errors metze (This used to be commit c2b645c8763fd75a0a81983ec44a5990670c4fc4) --- source4/lib/registry/tests/hive.c | 3 --- source4/lib/registry/tests/registry.c | 3 --- 2 files changed, 6 deletions(-) (limited to 'source4/lib/registry/tests') diff --git a/source4/lib/registry/tests/hive.c b/source4/lib/registry/tests/hive.c index a71e31474c..dff6d1e829 100644 --- a/source4/lib/registry/tests/hive.c +++ b/source4/lib/registry/tests/hive.c @@ -27,9 +27,6 @@ #include "librpc/gen_ndr/winreg.h" #include "system/filesys.h" -NTSTATUS torture_temp_dir(struct torture_context *tctx, const char *prefix, - const char **tempdir); - static bool test_del_nonexistant_key(struct torture_context *tctx, const void *test_data) { diff --git a/source4/lib/registry/tests/registry.c b/source4/lib/registry/tests/registry.c index 9809a6d4c8..962c7fd2b5 100644 --- a/source4/lib/registry/tests/registry.c +++ b/source4/lib/registry/tests/registry.c @@ -28,9 +28,6 @@ #include "libcli/security/security.h" #include "system/filesys.h" -NTSTATUS torture_temp_dir(struct torture_context *tctx, const char *prefix, - const char **tempdir); - /** * Test obtaining a predefined key. */ -- cgit From c353a7b05e8475bbc726123ae41c91102d96c6f5 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 10 Oct 2007 12:44:48 +0200 Subject: r25605: Last round of registry reformats (before this gets an obsession...). Guenther (This used to be commit ceb2ebfbf1eeb80bd34beadbba3a3c7a04da306a) --- source4/lib/registry/tests/diff.c | 34 ++-- source4/lib/registry/tests/generic.c | 99 ++++++----- source4/lib/registry/tests/hive.c | 154 +++++++++-------- source4/lib/registry/tests/registry.c | 312 +++++++++++++++++++--------------- 4 files changed, 328 insertions(+), 271 deletions(-) (limited to 'source4/lib/registry/tests') diff --git a/source4/lib/registry/tests/diff.c b/source4/lib/registry/tests/diff.c index 99a4589309..8e6907382c 100644 --- a/source4/lib/registry/tests/diff.c +++ b/source4/lib/registry/tests/diff.c @@ -1,20 +1,20 @@ -/* +/* Unix SMB/CIFS implementation. local testing of registry diff functionality Copyright (C) Jelmer Vernooij 2007 - + 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 . */ @@ -27,8 +27,8 @@ static bool test_generate_diff(struct torture_context *test) { - /* WERROR reg_generate_diff(struct registry_context *ctx1, - struct registry_context *ctx2, + /* WERROR reg_generate_diff(struct registry_context *ctx1, + struct registry_context *ctx2, const struct reg_diff_callbacks *callbacks, void *callback_data) */ @@ -52,7 +52,7 @@ static bool test_diff_apply(struct torture_context *test) static const char *added_key = NULL; -static WERROR test_add_key (void *callback_data, const char *key_name) +static WERROR test_add_key(void *callback_data, const char *key_name) { added_key = talloc_strdup(callback_data, key_name); @@ -90,14 +90,18 @@ static bool test_generate_diff_key_null(struct torture_context *test) return true; } -struct torture_suite *torture_registry_diff(TALLOC_CTX *mem_ctx) +struct torture_suite *torture_registry_diff(TALLOC_CTX *mem_ctx) { - struct torture_suite *suite = torture_suite_create(mem_ctx, - "DIFF"); - torture_suite_add_simple_test(suite, "test_generate_diff_key_add", test_generate_diff_key_add); - torture_suite_add_simple_test(suite, "test_generate_diff_key_null", test_generate_diff_key_null); - torture_suite_add_simple_test(suite, "test_diff_apply", test_diff_apply); - torture_suite_add_simple_test(suite, "test_generate_diff", test_generate_diff); - torture_suite_add_simple_test(suite, "test_diff_load", test_diff_load); + struct torture_suite *suite = torture_suite_create(mem_ctx, "DIFF"); + torture_suite_add_simple_test(suite, "test_generate_diff_key_add", + test_generate_diff_key_add); + torture_suite_add_simple_test(suite, "test_generate_diff_key_null", + test_generate_diff_key_null); + torture_suite_add_simple_test(suite, "test_diff_apply", + test_diff_apply); + torture_suite_add_simple_test(suite, "test_generate_diff", + test_generate_diff); + torture_suite_add_simple_test(suite, "test_diff_load", + test_diff_load); return suite; } diff --git a/source4/lib/registry/tests/generic.c b/source4/lib/registry/tests/generic.c index 549ed6282d..1b680f20b7 100644 --- a/source4/lib/registry/tests/generic.c +++ b/source4/lib/registry/tests/generic.c @@ -1,20 +1,20 @@ -/* +/* Unix SMB/CIFS implementation. local testing of registry library Copyright (C) Jelmer Vernooij 2005-2007 - + 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 . */ @@ -31,8 +31,10 @@ struct torture_suite *torture_registry_diff(TALLOC_CTX *mem_ctx); static bool test_str_regtype(struct torture_context *ctx) { - torture_assert_str_equal(ctx, str_regtype(1), "REG_SZ", "REG_SZ failed"); - torture_assert_str_equal(ctx, str_regtype(4), "REG_DWORD", "REG_DWORD failed"); + torture_assert_str_equal(ctx, str_regtype(1), + "REG_SZ", "REG_SZ failed"); + torture_assert_str_equal(ctx, str_regtype(4), + "REG_DWORD", "REG_DWORD failed"); return true; } @@ -42,18 +44,24 @@ static bool test_reg_val_data_string_dword(struct torture_context *ctx) { uint32_t d = 0x20; DATA_BLOB db = { (uint8_t *)&d, sizeof(d) }; - torture_assert_str_equal(ctx, "0x20", - reg_val_data_string(ctx, REG_DWORD, db), "dword failed"); + torture_assert_str_equal(ctx, "0x20", + reg_val_data_string(ctx, REG_DWORD, db), + "dword failed"); return true; } static bool test_reg_val_data_string_sz(struct torture_context *ctx) { DATA_BLOB db; - db.length = convert_string_talloc(ctx, CH_UNIX, CH_UTF16, "bla", 3, (void **)&db.data); - torture_assert_str_equal(ctx, "bla", reg_val_data_string(ctx, REG_SZ, db), "sz failed"); + db.length = convert_string_talloc(ctx, CH_UNIX, CH_UTF16, + "bla", 3, (void **)&db.data); + torture_assert_str_equal(ctx, "bla", + reg_val_data_string(ctx, REG_SZ, db), + "sz failed"); db.length = 4; - torture_assert_str_equal(ctx, "bl", reg_val_data_string(ctx, REG_SZ, db), "sz failed"); + torture_assert_str_equal(ctx, "bl", + reg_val_data_string(ctx, REG_SZ, db), + "sz failed"); return true; } @@ -61,9 +69,9 @@ static bool test_reg_val_data_string_binary(struct torture_context *ctx) { uint8_t x[] = { 0x1, 0x2, 0x3, 0x4 }; DATA_BLOB db = { x, 4 }; - torture_assert_str_equal(ctx, "01020304", - reg_val_data_string(ctx, REG_BINARY, db), - "binary failed"); + torture_assert_str_equal(ctx, "01020304", + reg_val_data_string(ctx, REG_BINARY, db), + "binary failed"); return true; } @@ -71,21 +79,22 @@ static bool test_reg_val_data_string_binary(struct torture_context *ctx) static bool test_reg_val_data_string_empty(struct torture_context *ctx) { DATA_BLOB db = { NULL, 0 }; - torture_assert_str_equal(ctx, "", - reg_val_data_string(ctx, REG_BINARY, db), "empty failed"); + torture_assert_str_equal(ctx, "", + reg_val_data_string(ctx, REG_BINARY, db), + "empty failed"); return true; } static bool test_reg_val_description(struct torture_context *ctx) { DATA_BLOB data; - data.length = convert_string_talloc(ctx, CH_UNIX, CH_UTF16, - "stationary traveller", - strlen("stationary traveller"), - (void **)&data.data); - torture_assert_str_equal(ctx, "camel = REG_SZ : stationary traveller", - reg_val_description(ctx, "camel", REG_SZ, data), - "reg_val_description failed"); + data.length = convert_string_talloc(ctx, CH_UNIX, CH_UTF16, + "stationary traveller", + strlen("stationary traveller"), + (void **)&data.data); + torture_assert_str_equal(ctx, "camel = REG_SZ : stationary traveller", + reg_val_description(ctx, "camel", REG_SZ, data), + "reg_val_description failed"); return true; } @@ -93,33 +102,35 @@ static bool test_reg_val_description(struct torture_context *ctx) static bool test_reg_val_description_nullname(struct torture_context *ctx) { DATA_BLOB data; - data.length = convert_string_talloc(ctx, CH_UNIX, CH_UTF16, "west berlin", - strlen("west berlin"), (void **)&data.data); - torture_assert_str_equal(ctx, " = REG_SZ : west berlin", - reg_val_description(ctx, NULL, REG_SZ, data), - "description with null name failed"); + data.length = convert_string_talloc(ctx, CH_UNIX, CH_UTF16, + "west berlin", + strlen("west berlin"), + (void **)&data.data); + torture_assert_str_equal(ctx, " = REG_SZ : west berlin", + reg_val_description(ctx, NULL, REG_SZ, data), + "description with null name failed"); return true; } -struct torture_suite *torture_registry(TALLOC_CTX *mem_ctx) +struct torture_suite *torture_registry(TALLOC_CTX *mem_ctx) { - struct torture_suite *suite = torture_suite_create(mem_ctx, - "REGISTRY"); - torture_suite_add_simple_test(suite, "str_regtype", test_str_regtype); - torture_suite_add_simple_test(suite, "reg_val_data_string dword", - test_reg_val_data_string_dword); - torture_suite_add_simple_test(suite, "reg_val_data_string sz", - test_reg_val_data_string_sz); - torture_suite_add_simple_test(suite, "reg_val_data_string binary", - test_reg_val_data_string_binary); - torture_suite_add_simple_test(suite, "reg_val_data_string empty", - test_reg_val_data_string_empty); - torture_suite_add_simple_test(suite, "reg_val_description", - test_reg_val_description); - torture_suite_add_simple_test(suite, "reg_val_description null", - test_reg_val_description_nullname); + struct torture_suite *suite = torture_suite_create(mem_ctx, "REGISTRY"); + torture_suite_add_simple_test(suite, "str_regtype", + test_str_regtype); + torture_suite_add_simple_test(suite, "reg_val_data_string dword", + test_reg_val_data_string_dword); + torture_suite_add_simple_test(suite, "reg_val_data_string sz", + test_reg_val_data_string_sz); + torture_suite_add_simple_test(suite, "reg_val_data_string binary", + test_reg_val_data_string_binary); + torture_suite_add_simple_test(suite, "reg_val_data_string empty", + test_reg_val_data_string_empty); + torture_suite_add_simple_test(suite, "reg_val_description", + test_reg_val_description); + torture_suite_add_simple_test(suite, "reg_val_description null", + test_reg_val_description_nullname); torture_suite_add_suite(suite, torture_registry_hive(mem_ctx)); torture_suite_add_suite(suite, torture_registry_registry(mem_ctx)); diff --git a/source4/lib/registry/tests/hive.c b/source4/lib/registry/tests/hive.c index dff6d1e829..9e76ce6aa1 100644 --- a/source4/lib/registry/tests/hive.c +++ b/source4/lib/registry/tests/hive.c @@ -1,20 +1,20 @@ -/* +/* Unix SMB/CIFS implementation. local testing of registry library - hives Copyright (C) Jelmer Vernooij 2005-2007 - + 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 2 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, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. @@ -32,36 +32,38 @@ static bool test_del_nonexistant_key(struct torture_context *tctx, { const struct hive_key *root = (const struct hive_key *)test_data; WERROR error = hive_key_del(root, "bla"); - torture_assert_werr_equal(tctx, error, WERR_NOT_FOUND, - "invalid return code"); + torture_assert_werr_equal(tctx, error, WERR_NOT_FOUND, + "invalid return code"); return true; } static bool test_keyinfo_root(struct torture_context *tctx, - const void *test_data) + const void *test_data) { uint32_t num_subkeys, num_values; const struct hive_key *root = (const struct hive_key *)test_data; WERROR error; - /* This is a new backend. There should be no subkeys and no + /* This is a new backend. There should be no subkeys and no * values */ - error = hive_key_get_info(tctx, root, NULL, &num_subkeys, &num_values, - NULL); + error = hive_key_get_info(tctx, root, NULL, &num_subkeys, &num_values, + NULL); torture_assert_werr_ok(tctx, error, "reg_key_num_subkeys()"); - torture_assert_int_equal(tctx, num_subkeys, 0, "New key has non-zero subkey count"); + torture_assert_int_equal(tctx, num_subkeys, 0, + "New key has non-zero subkey count"); torture_assert_werr_ok(tctx, error, "reg_key_num_values"); - torture_assert_int_equal(tctx, num_values, 0, "New key has non-zero value count"); + torture_assert_int_equal(tctx, num_values, 0, + "New key has non-zero value count"); return true; } static bool test_keyinfo_nums(struct torture_context *tctx, - const void *test_data) + const void *test_data) { uint32_t num_subkeys, num_values; const struct hive_key *root = (const struct hive_key *)test_data; @@ -69,18 +71,18 @@ static bool test_keyinfo_nums(struct torture_context *tctx, struct hive_key *subkey; uint32_t data = 42; - error = hive_key_add_name(tctx, root, "Nested Keyll", NULL, - NULL, &subkey); + error = hive_key_add_name(tctx, root, "Nested Keyll", NULL, + NULL, &subkey); torture_assert_werr_ok(tctx, error, "hive_key_add_name"); - error = hive_set_value(root, "Answer", REG_DWORD, - data_blob_talloc(tctx, &data, sizeof(data))); + error = hive_set_value(root, "Answer", REG_DWORD, + data_blob_talloc(tctx, &data, sizeof(data))); torture_assert_werr_ok(tctx, error, "hive_set_value"); - /* This is a new backend. There should be no subkeys and no + /* This is a new backend. There should be no subkeys and no * values */ - error = hive_key_get_info(tctx, root, NULL, &num_subkeys, &num_values, - NULL); + error = hive_key_get_info(tctx, root, NULL, &num_subkeys, &num_values, + NULL); torture_assert_werr_ok(tctx, error, "reg_key_num_subkeys()"); torture_assert_int_equal(tctx, num_subkeys, 1, "subkey count"); @@ -93,15 +95,15 @@ static bool test_keyinfo_nums(struct torture_context *tctx, } static bool test_add_subkey(struct torture_context *tctx, - const void *test_data) + const void *test_data) { WERROR error; struct hive_key *subkey; const struct hive_key *root = (const struct hive_key *)test_data; TALLOC_CTX *mem_ctx = tctx; - error = hive_key_add_name(mem_ctx, root, "Nested Key", NULL, - NULL, &subkey); + error = hive_key_add_name(mem_ctx, root, "Nested Key", NULL, + NULL, &subkey); torture_assert_werr_ok(tctx, error, "hive_key_add_name"); error = hive_key_del(root, "Nested Key"); @@ -127,8 +129,8 @@ static bool test_del_key(struct torture_context *tctx, const void *test_data) const struct hive_key *root = (const struct hive_key *)test_data; TALLOC_CTX *mem_ctx = tctx; - error = hive_key_add_name(mem_ctx, root, "Nested Key", NULL, - NULL, &subkey); + error = hive_key_add_name(mem_ctx, root, "Nested Key", NULL, + NULL, &subkey); torture_assert_werr_ok(tctx, error, "hive_key_add_name"); error = hive_key_del(root, "Nested Key"); @@ -141,7 +143,7 @@ static bool test_del_key(struct torture_context *tctx, const void *test_data) } static bool test_set_value(struct torture_context *tctx, - const void *test_data) + const void *test_data) { WERROR error; struct hive_key *subkey; @@ -149,12 +151,12 @@ static bool test_set_value(struct torture_context *tctx, TALLOC_CTX *mem_ctx = tctx; uint32_t data = 42; - error = hive_key_add_name(mem_ctx, root, "YA Nested Key", NULL, - NULL, &subkey); + error = hive_key_add_name(mem_ctx, root, "YA Nested Key", NULL, + NULL, &subkey); torture_assert_werr_ok(tctx, error, "hive_key_add_name"); - error = hive_set_value(subkey, "Answer", REG_DWORD, - data_blob_talloc(mem_ctx, &data, sizeof(data))); + error = hive_set_value(subkey, "Answer", REG_DWORD, + data_blob_talloc(mem_ctx, &data, sizeof(data))); torture_assert_werr_ok(tctx, error, "hive_set_value"); return true; @@ -170,16 +172,16 @@ static bool test_get_value(struct torture_context *tctx, const void *test_data) uint32_t type; DATA_BLOB value; - error = hive_key_add_name(mem_ctx, root, "EYA Nested Key", NULL, - NULL, &subkey); + error = hive_key_add_name(mem_ctx, root, "EYA Nested Key", NULL, + NULL, &subkey); torture_assert_werr_ok(tctx, error, "hive_key_add_name"); error = hive_get_value(mem_ctx, subkey, "Answer", &type, &value); - torture_assert_werr_equal(tctx, error, WERR_NOT_FOUND, - "getting missing value"); + torture_assert_werr_equal(tctx, error, WERR_NOT_FOUND, + "getting missing value"); - error = hive_set_value(subkey, "Answer", REG_DWORD, - data_blob_talloc(mem_ctx, &data, sizeof(data))); + error = hive_set_value(subkey, "Answer", REG_DWORD, + data_blob_talloc(mem_ctx, &data, sizeof(data))); torture_assert_werr_ok(tctx, error, "hive_set_value"); error = hive_get_value(mem_ctx, subkey, "Answer", &type, &value); @@ -203,12 +205,12 @@ static bool test_del_value(struct torture_context *tctx, const void *test_data) uint32_t type; DATA_BLOB value; - error = hive_key_add_name(mem_ctx, root, "EEYA Nested Key", NULL, + error = hive_key_add_name(mem_ctx, root, "EEYA Nested Key", NULL, NULL, &subkey); torture_assert_werr_ok(tctx, error, "hive_key_add_name"); - error = hive_set_value(subkey, "Answer", REG_DWORD, - data_blob_talloc(mem_ctx, &data, sizeof(data))); + error = hive_set_value(subkey, "Answer", REG_DWORD, + data_blob_talloc(mem_ctx, &data, sizeof(data))); torture_assert_werr_ok(tctx, error, "hive_set_value"); error = hive_del_value(subkey, "Answer"); @@ -218,13 +220,14 @@ static bool test_del_value(struct torture_context *tctx, const void *test_data) torture_assert_werr_equal(tctx, error, WERR_NOT_FOUND, "getting value"); error = hive_del_value(subkey, "Answer"); - torture_assert_werr_equal(tctx, error, WERR_NOT_FOUND, "deleting value"); + torture_assert_werr_equal(tctx, error, WERR_NOT_FOUND, + "deleting value"); return true; } -static bool test_list_values(struct torture_context *tctx, - const void *test_data) +static bool test_list_values(struct torture_context *tctx, + const void *test_data) { WERROR error; struct hive_key *subkey; @@ -235,15 +238,16 @@ static bool test_list_values(struct torture_context *tctx, DATA_BLOB value; const char *name; - error = hive_key_add_name(mem_ctx, root, "AYAYA Nested Key", NULL, - NULL, &subkey); + error = hive_key_add_name(mem_ctx, root, "AYAYA Nested Key", NULL, + NULL, &subkey); torture_assert_werr_ok(tctx, error, "hive_key_add_name"); - error = hive_set_value(subkey, "Answer", REG_DWORD, - data_blob_talloc(mem_ctx, &data, sizeof(data))); + error = hive_set_value(subkey, "Answer", REG_DWORD, + data_blob_talloc(mem_ctx, &data, sizeof(data))); torture_assert_werr_ok(tctx, error, "hive_set_value"); - error = hive_get_value_by_index(mem_ctx, subkey, 0, &name, &type, &value); + error = hive_get_value_by_index(mem_ctx, subkey, 0, &name, + &type, &value); torture_assert_werr_ok(tctx, error, "getting value"); torture_assert_str_equal(tctx, name, "Answer", "value name"); @@ -252,26 +256,36 @@ static bool test_list_values(struct torture_context *tctx, torture_assert_int_equal(tctx, value.length, 4, "value length"); torture_assert_int_equal(tctx, type, REG_DWORD, "value type"); - error = hive_get_value_by_index(mem_ctx, subkey, 1, &name, &type, &value); - torture_assert_werr_equal(tctx, error, WERR_NO_MORE_ITEMS, - "getting missing value"); + error = hive_get_value_by_index(mem_ctx, subkey, 1, &name, + &type, &value); + torture_assert_werr_equal(tctx, error, WERR_NO_MORE_ITEMS, + "getting missing value"); return true; } -static void tcase_add_tests(struct torture_tcase *tcase) +static void tcase_add_tests(struct torture_tcase *tcase) { - torture_tcase_add_simple_test(tcase, "del_nonexistant_key", - test_del_nonexistant_key); - torture_tcase_add_simple_test(tcase, "add_subkey", test_add_subkey); - torture_tcase_add_simple_test(tcase, "flush_key", test_flush_key); - torture_tcase_add_simple_test(tcase, "get_info", test_keyinfo_root); - torture_tcase_add_simple_test(tcase, "get_info_nums", test_keyinfo_nums); - torture_tcase_add_simple_test(tcase, "set_value", test_set_value); - torture_tcase_add_simple_test(tcase, "get_value", test_get_value); - torture_tcase_add_simple_test(tcase, "list_values", test_list_values); - torture_tcase_add_simple_test(tcase, "del_key", test_del_key); - torture_tcase_add_simple_test(tcase, "del_value", test_del_value); + torture_tcase_add_simple_test(tcase, "del_nonexistant_key", + test_del_nonexistant_key); + torture_tcase_add_simple_test(tcase, "add_subkey", + test_add_subkey); + torture_tcase_add_simple_test(tcase, "flush_key", + test_flush_key); + torture_tcase_add_simple_test(tcase, "get_info", + test_keyinfo_root); + torture_tcase_add_simple_test(tcase, "get_info_nums", + test_keyinfo_nums); + torture_tcase_add_simple_test(tcase, "set_value", + test_set_value); + torture_tcase_add_simple_test(tcase, "get_value", + test_get_value); + torture_tcase_add_simple_test(tcase, "list_values", + test_list_values); + torture_tcase_add_simple_test(tcase, "del_key", + test_del_key); + torture_tcase_add_simple_test(tcase, "del_value", + test_del_value); } static bool hive_setup_dir(struct torture_context *tctx, void **data) @@ -348,21 +362,19 @@ static bool hive_setup_regf(struct torture_context *tctx, void **data) static bool test_dir_refuses_null_location(struct torture_context *tctx) { - torture_assert_werr_equal(tctx, WERR_INVALID_PARAM, - reg_open_directory(NULL, NULL, NULL), - "reg_open_directory accepts NULL location"); + torture_assert_werr_equal(tctx, WERR_INVALID_PARAM, + reg_open_directory(NULL, NULL, NULL), + "reg_open_directory accepts NULL location"); return true; } -struct torture_suite *torture_registry_hive(TALLOC_CTX *mem_ctx) +struct torture_suite *torture_registry_hive(TALLOC_CTX *mem_ctx) { struct torture_tcase *tcase; - struct torture_suite *suite = torture_suite_create(mem_ctx, - "HIVE"); - - torture_suite_add_simple_test(suite, "dir-refuses-null-location", - test_dir_refuses_null_location); + struct torture_suite *suite = torture_suite_create(mem_ctx, "HIVE"); + torture_suite_add_simple_test(suite, "dir-refuses-null-location", + test_dir_refuses_null_location); tcase = torture_suite_add_tcase(suite, "dir"); torture_tcase_set_fixture(tcase, hive_setup_dir, NULL); diff --git a/source4/lib/registry/tests/registry.c b/source4/lib/registry/tests/registry.c index 962c7fd2b5..9b1c6ff249 100644 --- a/source4/lib/registry/tests/registry.c +++ b/source4/lib/registry/tests/registry.c @@ -1,20 +1,20 @@ -/* +/* Unix SMB/CIFS implementation. local testing of registry library - registry backend Copyright (C) Jelmer Vernooij 2005-2007 - + 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 2 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, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. @@ -32,16 +32,16 @@ * Test obtaining a predefined key. */ static bool test_get_predefined(struct torture_context *tctx, - const void *_data) + const void *_data) { - const struct registry_context *rctx = + const struct registry_context *rctx = (const struct registry_context *)_data; struct registry_key *root; WERROR error; error = reg_get_predefined_key(rctx, HKEY_CLASSES_ROOT, &root); - torture_assert_werr_ok(tctx, error, - "getting predefined key failed"); + torture_assert_werr_ok(tctx, error, + "getting predefined key failed"); return true; } @@ -49,7 +49,7 @@ static bool test_get_predefined(struct torture_context *tctx, * Test obtaining a predefined key. */ static bool test_get_predefined_unknown(struct torture_context *tctx, - const void *_data) + const void *_data) { const struct registry_context *rctx = _data; struct registry_key *root; @@ -57,40 +57,42 @@ static bool test_get_predefined_unknown(struct torture_context *tctx, error = reg_get_predefined_key(rctx, 1337, &root); torture_assert_werr_equal(tctx, error, WERR_NOT_FOUND, - "getting predefined key failed"); + "getting predefined key failed"); return true; } static bool test_predef_key_by_name(struct torture_context *tctx, - const void *_data) + const void *_data) { - const struct registry_context *rctx = + const struct registry_context *rctx = (const struct registry_context *)_data; struct registry_key *root; WERROR error; - error = reg_get_predefined_key_by_name(rctx, "HKEY_CLASSES_ROOT", &root); - torture_assert_werr_ok(tctx, error, - "getting predefined key failed"); + error = reg_get_predefined_key_by_name(rctx, "HKEY_CLASSES_ROOT", + &root); + torture_assert_werr_ok(tctx, error, + "getting predefined key failed"); - error = reg_get_predefined_key_by_name(rctx, "HKEY_classes_ROOT", &root); - torture_assert_werr_ok(tctx, error, - "getting predefined key case insensitively failed"); + error = reg_get_predefined_key_by_name(rctx, "HKEY_classes_ROOT", + &root); + torture_assert_werr_ok(tctx, error, + "getting predefined key case insensitively failed"); return true; } static bool test_predef_key_by_name_invalid(struct torture_context *tctx, - const void *_data) + const void *_data) { - const struct registry_context *rctx = + const struct registry_context *rctx = (const struct registry_context *)_data; struct registry_key *root; WERROR error; error = reg_get_predefined_key_by_name(rctx, "BLA", &root); torture_assert_werr_equal(tctx, error, WERR_BADFILE, - "getting predefined key failed"); + "getting predefined key failed"); return true; } @@ -98,18 +100,19 @@ static bool test_predef_key_by_name_invalid(struct torture_context *tctx, * Test creating a new subkey */ static bool test_create_subkey(struct torture_context *tctx, - const void *_data) + const void *_data) { - const struct registry_context *rctx = + const struct registry_context *rctx = (const struct registry_context *)_data; struct registry_key *root, *newkey; WERROR error; error = reg_get_predefined_key(rctx, HKEY_CLASSES_ROOT, &root); - torture_assert_werr_ok(tctx, error, - "getting predefined key failed"); + torture_assert_werr_ok(tctx, error, + "getting predefined key failed"); - error = reg_key_add_name(rctx, root, "Bad Bentheim", NULL, NULL, &newkey); + error = reg_key_add_name(rctx, root, "Bad Bentheim", NULL, NULL, + &newkey); torture_assert_werr_ok(tctx, error, "Creating key return code"); torture_assert(tctx, newkey != NULL, "Creating new key"); @@ -120,24 +123,24 @@ static bool test_create_subkey(struct torture_context *tctx, * Test creating a new nested subkey */ static bool test_create_nested_subkey(struct torture_context *tctx, - const void *_data) + const void *_data) { - const struct registry_context *rctx = + const struct registry_context *rctx = (const struct registry_context *)_data; struct registry_key *root, *newkey1, *newkey2; WERROR error; error = reg_get_predefined_key(rctx, HKEY_CLASSES_ROOT, &root); - torture_assert_werr_ok(tctx, error, - "getting predefined key failed"); + torture_assert_werr_ok(tctx, error, + "getting predefined key failed"); - error = reg_key_add_name(rctx, root, "Hamburg", NULL, NULL, - &newkey1); + error = reg_key_add_name(rctx, root, "Hamburg", NULL, NULL, + &newkey1); torture_assert_werr_ok(tctx, error, "Creating key return code"); torture_assert(tctx, newkey1 != NULL, "Creating new key"); - error = reg_key_add_name(rctx, root, "Hamburg\\Hamburg", NULL, NULL, - &newkey2); + error = reg_key_add_name(rctx, root, "Hamburg\\Hamburg", NULL, NULL, + &newkey2); torture_assert_werr_ok(tctx, error, "Creating key return code"); torture_assert(tctx, newkey2 != NULL, "Creating new key"); @@ -148,15 +151,17 @@ static bool test_create_nested_subkey(struct torture_context *tctx, * Test creating a new subkey */ static bool test_key_add_abs_top(struct torture_context *tctx, - const void *_data) + const void *_data) { - const struct registry_context *rctx = + const struct registry_context *rctx = (const struct registry_context *)_data; struct registry_key *root; WERROR error; - error = reg_key_add_abs(tctx, rctx, "HKEY_CLASSES_ROOT", 0, NULL, &root); - torture_assert_werr_equal(tctx, error, WERR_ALREADY_EXISTS, "create top level"); + error = reg_key_add_abs(tctx, rctx, "HKEY_CLASSES_ROOT", 0, NULL, + &root); + torture_assert_werr_equal(tctx, error, WERR_ALREADY_EXISTS, + "create top level"); return true; } @@ -165,22 +170,24 @@ static bool test_key_add_abs_top(struct torture_context *tctx, * Test creating a new subkey */ static bool test_key_add_abs(struct torture_context *tctx, - const void *_data) + const void *_data) { WERROR error; - const struct registry_context *rctx = + const struct registry_context *rctx = (const struct registry_context *)_data; struct registry_key *root, *result1, *result2; - error = reg_key_add_abs(tctx, rctx, "HKEY_CLASSES_ROOT\\bloe", 0, NULL, &result1); + error = reg_key_add_abs(tctx, rctx, "HKEY_CLASSES_ROOT\\bloe", 0, NULL, + &result1); torture_assert_werr_ok(tctx, error, "create lowest"); - error = reg_key_add_abs(tctx, rctx, "HKEY_CLASSES_ROOT\\bloe\\bla", 0, NULL, &result1); + error = reg_key_add_abs(tctx, rctx, "HKEY_CLASSES_ROOT\\bloe\\bla", 0, + NULL, &result1); torture_assert_werr_ok(tctx, error, "create nested"); error = reg_get_predefined_key(rctx, HKEY_CLASSES_ROOT, &root); - torture_assert_werr_ok(tctx, error, - "getting predefined key failed"); + torture_assert_werr_ok(tctx, error, + "getting predefined key failed"); error = reg_open_key(tctx, root, "bloe", &result2); torture_assert_werr_ok(tctx, error, "opening key"); @@ -194,14 +201,14 @@ static bool test_key_add_abs(struct torture_context *tctx, static bool test_del_key(struct torture_context *tctx, const void *_data) { - const struct registry_context *rctx = + const struct registry_context *rctx = (const struct registry_context *)_data; struct registry_key *root, *newkey; WERROR error; error = reg_get_predefined_key(rctx, HKEY_CLASSES_ROOT, &root); - torture_assert_werr_ok(tctx, error, - "getting predefined key failed"); + torture_assert_werr_ok(tctx, error, + "getting predefined key failed"); error = reg_key_add_name(rctx, root, "Hamburg", NULL, NULL, &newkey); @@ -212,27 +219,27 @@ static bool test_del_key(struct torture_context *tctx, const void *_data) torture_assert_werr_ok(tctx, error, "Delete key"); error = reg_key_del(root, "Hamburg"); - torture_assert_werr_equal(tctx, error, WERR_NOT_FOUND, - "Delete missing key"); + torture_assert_werr_equal(tctx, error, WERR_NOT_FOUND, + "Delete missing key"); return true; } /** - * Convenience function for opening the HKEY_CLASSES_ROOT hive and + * Convenience function for opening the HKEY_CLASSES_ROOT hive and * creating a single key for testing purposes. */ -static bool create_test_key(struct torture_context *tctx, - const struct registry_context *rctx, - const char *name, - struct registry_key **root, - struct registry_key **subkey) +static bool create_test_key(struct torture_context *tctx, + const struct registry_context *rctx, + const char *name, + struct registry_key **root, + struct registry_key **subkey) { WERROR error; error = reg_get_predefined_key(rctx, HKEY_CLASSES_ROOT, root); - torture_assert_werr_ok(tctx, error, - "getting predefined key failed"); + torture_assert_werr_ok(tctx, error, + "getting predefined key failed"); error = reg_key_add_name(rctx, *root, name, NULL, NULL, subkey); torture_assert_werr_ok(tctx, error, "Creating key return code"); @@ -243,7 +250,7 @@ static bool create_test_key(struct torture_context *tctx, static bool test_flush_key(struct torture_context *tctx, const void *_data) { - const struct registry_context *rctx = + const struct registry_context *rctx = (const struct registry_context *)_data; struct registry_key *root, *subkey; WERROR error; @@ -254,15 +261,15 @@ static bool test_flush_key(struct torture_context *tctx, const void *_data) error = reg_key_flush(subkey); torture_assert_werr_ok(tctx, error, "flush key"); - torture_assert_werr_equal(tctx, reg_key_flush(NULL), - WERR_INVALID_PARAM, "flush key"); + torture_assert_werr_equal(tctx, reg_key_flush(NULL), + WERR_INVALID_PARAM, "flush key"); return true; } static bool test_query_key(struct torture_context *tctx, const void *_data) { - const struct registry_context *rctx = + const struct registry_context *rctx = (const struct registry_context *)_data; struct registry_key *root, *subkey; WERROR error; @@ -274,8 +281,8 @@ static bool test_query_key(struct torture_context *tctx, const void *_data) return false; error = reg_key_get_info(tctx, subkey, &classname, - &num_subkeys, &num_values, - &last_changed_time); + &num_subkeys, &num_values, + &last_changed_time); torture_assert_werr_ok(tctx, error, "get info key"); torture_assert(tctx, classname == NULL, "classname"); @@ -287,7 +294,7 @@ static bool test_query_key(struct torture_context *tctx, const void *_data) static bool test_query_key_nums(struct torture_context *tctx, const void *_data) { - const struct registry_context *rctx = + const struct registry_context *rctx = (const struct registry_context *)_data; struct registry_key *root, *subkey1, *subkey2; WERROR error; @@ -297,15 +304,16 @@ static bool test_query_key_nums(struct torture_context *tctx, const void *_data) if (!create_test_key(tctx, rctx, "Berlin", &root, &subkey1)) return false; - error = reg_key_add_name(rctx, subkey1, "Bentheim", NULL, NULL, &subkey2); + error = reg_key_add_name(rctx, subkey1, "Bentheim", NULL, NULL, + &subkey2); torture_assert_werr_ok(tctx, error, "Creating key return code"); - error = reg_val_set(subkey1, "Answer", REG_DWORD, - data_blob_talloc(tctx, &data, sizeof(data))); + error = reg_val_set(subkey1, "Answer", REG_DWORD, + data_blob_talloc(tctx, &data, sizeof(data))); torture_assert_werr_ok(tctx, error, "set value"); error = reg_key_get_info(tctx, subkey1, NULL, &num_subkeys, - &num_values, NULL); + &num_values, NULL); torture_assert_werr_ok(tctx, error, "get info key"); torture_assert_int_equal(tctx, num_subkeys, 1, "num subkeys"); @@ -315,13 +323,13 @@ static bool test_query_key_nums(struct torture_context *tctx, const void *_data) } /** - * Test that the subkeys of a key can be enumerated, that - * the returned parameters for get_subkey_by_index are optional and + * Test that the subkeys of a key can be enumerated, that + * the returned parameters for get_subkey_by_index are optional and * that enumerating the parents of a non-top-level node works. */ static bool test_list_subkeys(struct torture_context *tctx, const void *_data) { - const struct registry_context *rctx = + const struct registry_context *rctx = (const struct registry_context *)_data; struct registry_key *subkey = NULL, *root; WERROR error; @@ -331,8 +339,8 @@ static bool test_list_subkeys(struct torture_context *tctx, const void *_data) if (!create_test_key(tctx, rctx, "Goettingen", &root, &subkey)) return false; - error = reg_key_get_subkey_by_index(tctx, root, 0, &name, &classname, - &last_mod_time); + error = reg_key_get_subkey_by_index(tctx, root, 0, &name, &classname, + &last_mod_time); torture_assert_werr_ok(tctx, error, "Enum keys return code"); torture_assert_str_equal(tctx, name, "Goettingen", "Enum keys data"); @@ -340,17 +348,18 @@ static bool test_list_subkeys(struct torture_context *tctx, const void *_data) error = reg_key_get_subkey_by_index(tctx, root, 0, NULL, NULL, NULL); - torture_assert_werr_ok(tctx, error, "Enum keys with NULL arguments return code"); + torture_assert_werr_ok(tctx, error, + "Enum keys with NULL arguments return code"); error = reg_key_get_subkey_by_index(tctx, root, 1, NULL, NULL, NULL); - - torture_assert_werr_equal(tctx, error, WERR_NO_MORE_ITEMS, - "Invalid error for no more items"); + + torture_assert_werr_equal(tctx, error, WERR_NO_MORE_ITEMS, + "Invalid error for no more items"); error = reg_key_get_subkey_by_index(tctx, subkey, 0, NULL, NULL, NULL); - - torture_assert_werr_equal(tctx, error, WERR_NO_MORE_ITEMS, - "Invalid error for no more items"); + + torture_assert_werr_equal(tctx, error, WERR_NO_MORE_ITEMS, + "Invalid error for no more items"); return true; } @@ -360,7 +369,7 @@ static bool test_list_subkeys(struct torture_context *tctx, const void *_data) */ static bool test_set_value(struct torture_context *tctx, const void *_data) { - const struct registry_context *rctx = + const struct registry_context *rctx = (const struct registry_context *)_data; struct registry_key *subkey = NULL, *root; WERROR error; @@ -369,8 +378,8 @@ static bool test_set_value(struct torture_context *tctx, const void *_data) if (!create_test_key(tctx, rctx, "Dusseldorf", &root, &subkey)) return false; - error = reg_val_set(subkey, "Answer", REG_DWORD, - data_blob_talloc(tctx, &data, sizeof(data))); + error = reg_val_set(subkey, "Answer", REG_DWORD, + data_blob_talloc(tctx, &data, sizeof(data))); torture_assert_werr_ok (tctx, error, "setting value"); return true; @@ -381,7 +390,7 @@ static bool test_set_value(struct torture_context *tctx, const void *_data) */ static bool test_security(struct torture_context *tctx, const void *_data) { - const struct registry_context *rctx = + const struct registry_context *rctx = (const struct registry_context *)_data; struct registry_key *subkey = NULL, *root; WERROR error; @@ -391,12 +400,12 @@ static bool test_security(struct torture_context *tctx, const void *_data) return false; osd = security_descriptor_create(tctx, - NULL, NULL, - SID_NT_AUTHENTICATED_USERS, - SEC_ACE_TYPE_ACCESS_ALLOWED, - SEC_GENERIC_ALL, - SEC_ACE_FLAG_OBJECT_INHERIT, - NULL); + NULL, NULL, + SID_NT_AUTHENTICATED_USERS, + SEC_ACE_TYPE_ACCESS_ALLOWED, + SEC_GENERIC_ALL, + SEC_ACE_FLAG_OBJECT_INHERIT, + NULL); error = reg_set_security(subkey, osd); torture_assert_werr_ok(tctx, error, "setting security"); @@ -404,8 +413,8 @@ static bool test_security(struct torture_context *tctx, const void *_data) error = reg_get_security(tctx, subkey, &nsd); torture_assert_werr_ok (tctx, error, "setting security"); - torture_assert(tctx, security_descriptor_equal(osd, nsd), - "security descriptor changed!"); + torture_assert(tctx, security_descriptor_equal(osd, nsd), + "security descriptor changed!"); return true; } @@ -415,7 +424,7 @@ static bool test_security(struct torture_context *tctx, const void *_data) */ static bool test_get_value(struct torture_context *tctx, const void *_data) { - const struct registry_context *rctx = + const struct registry_context *rctx = (const struct registry_context *)_data; struct registry_key *subkey = NULL, *root; WERROR error; @@ -426,21 +435,22 @@ static bool test_get_value(struct torture_context *tctx, const void *_data) if (!create_test_key(tctx, rctx, "Duisburg", &root, &subkey)) return false; - error = reg_key_get_value_by_name(tctx, subkey, __FUNCTION__, &type, - &data); - torture_assert_werr_equal(tctx, error, WERR_NOT_FOUND, - "getting missing value"); + error = reg_key_get_value_by_name(tctx, subkey, __FUNCTION__, &type, + &data); + torture_assert_werr_equal(tctx, error, WERR_NOT_FOUND, + "getting missing value"); - error = reg_val_set(subkey, __FUNCTION__, REG_DWORD, - data_blob_talloc(tctx, &value, 4)); - torture_assert_werr_ok (tctx, error, "setting value"); + error = reg_val_set(subkey, __FUNCTION__, REG_DWORD, + data_blob_talloc(tctx, &value, 4)); + torture_assert_werr_ok(tctx, error, "setting value"); - error = reg_key_get_value_by_name(tctx, subkey, __FUNCTION__, &type, - &data); + error = reg_key_get_value_by_name(tctx, subkey, __FUNCTION__, &type, + &data); torture_assert_werr_ok(tctx, error, "getting value"); torture_assert_int_equal(tctx, 4, data.length, "value length ok"); - torture_assert(tctx, memcmp(data.data, &value, 4) == 0, "value content ok"); + torture_assert(tctx, memcmp(data.data, &value, 4) == 0, + "value content ok"); torture_assert_int_equal(tctx, REG_DWORD, type, "value type"); return true; @@ -451,7 +461,7 @@ static bool test_get_value(struct torture_context *tctx, const void *_data) */ static bool test_del_value(struct torture_context *tctx, const void *_data) { - const struct registry_context *rctx = + const struct registry_context *rctx = (const struct registry_context *)_data; struct registry_key *subkey = NULL, *root; WERROR error; @@ -462,21 +472,22 @@ static bool test_del_value(struct torture_context *tctx, const void *_data) if (!create_test_key(tctx, rctx, "Duisburg", &root, &subkey)) return false; - error = reg_key_get_value_by_name(tctx, subkey, __FUNCTION__, &type, - &data); - torture_assert_werr_equal(tctx, error, WERR_NOT_FOUND, - "getting missing value"); + error = reg_key_get_value_by_name(tctx, subkey, __FUNCTION__, &type, + &data); + torture_assert_werr_equal(tctx, error, WERR_NOT_FOUND, + "getting missing value"); - error = reg_val_set(subkey, __FUNCTION__, REG_DWORD, - data_blob_talloc(tctx, &value, 4)); + error = reg_val_set(subkey, __FUNCTION__, REG_DWORD, + data_blob_talloc(tctx, &value, 4)); torture_assert_werr_ok (tctx, error, "setting value"); error = reg_del_value(subkey, __FUNCTION__); torture_assert_werr_ok (tctx, error, "unsetting value"); - error = reg_key_get_value_by_name(tctx, subkey, __FUNCTION__, &type, &data); - torture_assert_werr_equal(tctx, error, WERR_NOT_FOUND, - "getting missing value"); + error = reg_key_get_value_by_name(tctx, subkey, __FUNCTION__, + &type, &data); + torture_assert_werr_equal(tctx, error, WERR_NOT_FOUND, + "getting missing value"); return true; } @@ -486,7 +497,7 @@ static bool test_del_value(struct torture_context *tctx, const void *_data) */ static bool test_list_values(struct torture_context *tctx, const void *_data) { - const struct registry_context *rctx = + const struct registry_context *rctx = (const struct registry_context *)_data; struct registry_key *subkey = NULL, *root; WERROR error; @@ -498,21 +509,24 @@ static bool test_list_values(struct torture_context *tctx, const void *_data) if (!create_test_key(tctx, rctx, "Bonn", &root, &subkey)) return false; - error = reg_val_set(subkey, "bar", REG_DWORD, - data_blob_talloc(tctx, &value, 4)); + error = reg_val_set(subkey, "bar", REG_DWORD, + data_blob_talloc(tctx, &value, 4)); torture_assert_werr_ok (tctx, error, "setting value"); - error = reg_key_get_value_by_index(tctx, subkey, 0, &name, &type, &data); + error = reg_key_get_value_by_index(tctx, subkey, 0, &name, + &type, &data); torture_assert_werr_ok(tctx, error, "getting value"); torture_assert_str_equal(tctx, name, "bar", "value name"); torture_assert_int_equal(tctx, 4, data.length, "value length"); - torture_assert(tctx, memcmp(data.data, &value, 4) == 0, "value content"); + torture_assert(tctx, memcmp(data.data, &value, 4) == 0, + "value content"); torture_assert_int_equal(tctx, REG_DWORD, type, "value type"); - error = reg_key_get_value_by_index(tctx, subkey, 1, &name, &type, &data); - torture_assert_werr_equal(tctx, error, WERR_NO_MORE_ITEMS, - "getting missing value"); + error = reg_key_get_value_by_index(tctx, subkey, 1, &name, + &type, &data); + torture_assert_werr_equal(tctx, error, WERR_NO_MORE_ITEMS, + "getting missing value"); return true; } @@ -546,33 +560,49 @@ static bool setup_local_registry(struct torture_context *tctx, void **data) static void tcase_add_tests(struct torture_tcase *tcase) { - torture_tcase_add_simple_test(tcase, "list_subkeys", test_list_subkeys); - torture_tcase_add_simple_test(tcase, "get_predefined_key", test_get_predefined); - torture_tcase_add_simple_test(tcase, "get_predefined_key", test_get_predefined_unknown); - torture_tcase_add_simple_test(tcase, "create_key", test_create_subkey); - torture_tcase_add_simple_test(tcase, "create_key", test_create_nested_subkey); - torture_tcase_add_simple_test(tcase, "key_add_abs", test_key_add_abs); - torture_tcase_add_simple_test(tcase, "key_add_abs_top", test_key_add_abs_top); - torture_tcase_add_simple_test(tcase, "set_value", test_set_value); - torture_tcase_add_simple_test(tcase, "get_value", test_get_value); - torture_tcase_add_simple_test(tcase, "list_values", test_list_values); - torture_tcase_add_simple_test(tcase, "del_key", test_del_key); - torture_tcase_add_simple_test(tcase, "del_value", test_del_value); - torture_tcase_add_simple_test(tcase, "flush_key", test_flush_key); - torture_tcase_add_simple_test(tcase, "query_key", test_query_key); - torture_tcase_add_simple_test(tcase, "query_key_nums", test_query_key_nums); - torture_tcase_add_simple_test(tcase, "test_predef_key_by_name", + torture_tcase_add_simple_test(tcase, "list_subkeys", + test_list_subkeys); + torture_tcase_add_simple_test(tcase, "get_predefined_key", + test_get_predefined); + torture_tcase_add_simple_test(tcase, "get_predefined_key", + test_get_predefined_unknown); + torture_tcase_add_simple_test(tcase, "create_key", + test_create_subkey); + torture_tcase_add_simple_test(tcase, "create_key", + test_create_nested_subkey); + torture_tcase_add_simple_test(tcase, "key_add_abs", + test_key_add_abs); + torture_tcase_add_simple_test(tcase, "key_add_abs_top", + test_key_add_abs_top); + torture_tcase_add_simple_test(tcase, "set_value", + test_set_value); + torture_tcase_add_simple_test(tcase, "get_value", + test_get_value); + torture_tcase_add_simple_test(tcase, "list_values", + test_list_values); + torture_tcase_add_simple_test(tcase, "del_key", + test_del_key); + torture_tcase_add_simple_test(tcase, "del_value", + test_del_value); + torture_tcase_add_simple_test(tcase, "flush_key", + test_flush_key); + torture_tcase_add_simple_test(tcase, "query_key", + test_query_key); + torture_tcase_add_simple_test(tcase, "query_key_nums", + test_query_key_nums); + torture_tcase_add_simple_test(tcase, "test_predef_key_by_name", test_predef_key_by_name); - torture_tcase_add_simple_test(tcase, "security", test_security); - torture_tcase_add_simple_test(tcase, "test_predef_key_by_name_invalid", + torture_tcase_add_simple_test(tcase, "security", + test_security); + torture_tcase_add_simple_test(tcase, "test_predef_key_by_name_invalid", test_predef_key_by_name_invalid); } -struct torture_suite *torture_registry_registry(TALLOC_CTX *mem_ctx) +struct torture_suite *torture_registry_registry(TALLOC_CTX *mem_ctx) { struct torture_tcase *tcase; struct torture_suite *suite = torture_suite_create(mem_ctx, "REGISTRY"); - + tcase = torture_suite_add_tcase(suite, "local"); torture_tcase_set_fixture(tcase, setup_local_registry, NULL); tcase_add_tests(tcase); -- cgit From a6c4b9d1793c7ea1965a23e1d23b73012acd151b Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 10 Oct 2007 13:12:53 +0200 Subject: r25607: Allow to set security descriptor type flags at creation time with security_descriptor_create(). Guenther (This used to be commit 7dd0d28d254f78891b0807492baafa188b42df16) --- source4/lib/registry/tests/registry.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/lib/registry/tests') diff --git a/source4/lib/registry/tests/registry.c b/source4/lib/registry/tests/registry.c index 9b1c6ff249..d2838e363f 100644 --- a/source4/lib/registry/tests/registry.c +++ b/source4/lib/registry/tests/registry.c @@ -400,6 +400,7 @@ static bool test_security(struct torture_context *tctx, const void *_data) return false; osd = security_descriptor_create(tctx, + 0, NULL, NULL, SID_NT_AUTHENTICATED_USERS, SEC_ACE_TYPE_ACCESS_ALLOWED, -- cgit From 0e3069186186ffed24269968d75c8f007900fd95 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Wed, 10 Oct 2007 14:12:25 +0200 Subject: r25613: verify the length and type before checking the value, hopefully gives more info why this fails some bigendian platforms metze (This used to be commit 1d2bc79aa5841bbdbaf003005a161bbf294c7366) --- source4/lib/registry/tests/hive.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'source4/lib/registry/tests') diff --git a/source4/lib/registry/tests/hive.c b/source4/lib/registry/tests/hive.c index 9e76ce6aa1..2ddfe6f036 100644 --- a/source4/lib/registry/tests/hive.c +++ b/source4/lib/registry/tests/hive.c @@ -187,10 +187,9 @@ static bool test_get_value(struct torture_context *tctx, const void *test_data) error = hive_get_value(mem_ctx, subkey, "Answer", &type, &value); torture_assert_werr_ok(tctx, error, "getting value"); - torture_assert(tctx, memcmp(value.data, &data, 4) == 0, "value data"); - torture_assert_int_equal(tctx, value.length, 4, "value length"); torture_assert_int_equal(tctx, type, REG_DWORD, "value type"); + torture_assert(tctx, memcmp(value.data, &data, 4) == 0, "value data"); return true; } @@ -251,10 +250,10 @@ static bool test_list_values(struct torture_context *tctx, torture_assert_werr_ok(tctx, error, "getting value"); torture_assert_str_equal(tctx, name, "Answer", "value name"); - torture_assert(tctx, memcmp(value.data, &data, 4) == 0, "value data"); torture_assert_int_equal(tctx, value.length, 4, "value length"); torture_assert_int_equal(tctx, type, REG_DWORD, "value type"); + torture_assert(tctx, memcmp(value.data, &data, 4) == 0, "value data"); error = hive_get_value_by_index(mem_ctx, subkey, 1, &name, &type, &value); -- cgit From f2002541ced97da3658348fe9ac9e212dd50c55b Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 2 Nov 2007 12:54:19 +0100 Subject: r25803: Make our security descriptor acl manipulation methods more generic so that we can add and delete ACEs for SACLs as well as for DACLs. Guenther (This used to be commit 947fff994181f0ae50ac76d09621ddd684873112) --- source4/lib/registry/tests/registry.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/registry/tests') diff --git a/source4/lib/registry/tests/registry.c b/source4/lib/registry/tests/registry.c index d2838e363f..155e891c40 100644 --- a/source4/lib/registry/tests/registry.c +++ b/source4/lib/registry/tests/registry.c @@ -399,7 +399,7 @@ static bool test_security(struct torture_context *tctx, const void *_data) if (!create_test_key(tctx, rctx, "Düsseldorf", &root, &subkey)) return false; - osd = security_descriptor_create(tctx, + osd = security_descriptor_dacl_create(tctx, 0, NULL, NULL, SID_NT_AUTHENTICATED_USERS, -- cgit From dbc78e20169c97f2592ddb18fdf48a1c91a3f77d Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 11 Nov 2007 23:36:53 +0100 Subject: r25928: Split up torture-local a bit. (This used to be commit c6b109040856ba0f1ae0db2787cc838ff61df767) --- source4/lib/registry/tests/generic.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'source4/lib/registry/tests') diff --git a/source4/lib/registry/tests/generic.c b/source4/lib/registry/tests/generic.c index 1b680f20b7..69146186dc 100644 --- a/source4/lib/registry/tests/generic.c +++ b/source4/lib/registry/tests/generic.c @@ -112,11 +112,9 @@ static bool test_reg_val_description_nullname(struct torture_context *ctx) return true; } - - -struct torture_suite *torture_registry(TALLOC_CTX *mem_ctx) +_PUBLIC_ NTSTATUS torture_registry_init(void) { - struct torture_suite *suite = torture_suite_create(mem_ctx, "REGISTRY"); + struct torture_suite *suite = torture_suite_create(talloc_autofree_context(), "REGISTRY"); torture_suite_add_simple_test(suite, "str_regtype", test_str_regtype); torture_suite_add_simple_test(suite, "reg_val_data_string dword", @@ -132,9 +130,11 @@ struct torture_suite *torture_registry(TALLOC_CTX *mem_ctx) torture_suite_add_simple_test(suite, "reg_val_description null", test_reg_val_description_nullname); - torture_suite_add_suite(suite, torture_registry_hive(mem_ctx)); - torture_suite_add_suite(suite, torture_registry_registry(mem_ctx)); - torture_suite_add_suite(suite, torture_registry_diff(mem_ctx)); + torture_suite_add_suite(suite, torture_registry_hive(suite)); + torture_suite_add_suite(suite, torture_registry_registry(suite)); + torture_suite_add_suite(suite, torture_registry_diff(suite)); - return suite; + torture_register_suite(suite); + + return NT_STATUS_OK; } -- cgit From 0b2780a6a424eea9989443d288435b248d653763 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 11 Nov 2007 23:37:01 +0100 Subject: r25930: fix test name (This used to be commit 41dcd8c261aecaccee21667367bb524c13d620d9) --- source4/lib/registry/tests/generic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/registry/tests') diff --git a/source4/lib/registry/tests/generic.c b/source4/lib/registry/tests/generic.c index 69146186dc..68040ea98e 100644 --- a/source4/lib/registry/tests/generic.c +++ b/source4/lib/registry/tests/generic.c @@ -114,7 +114,7 @@ static bool test_reg_val_description_nullname(struct torture_context *ctx) _PUBLIC_ NTSTATUS torture_registry_init(void) { - struct torture_suite *suite = torture_suite_create(talloc_autofree_context(), "REGISTRY"); + struct torture_suite *suite = torture_suite_create(talloc_autofree_context(), "LOCAL-REGISTRY"); torture_suite_add_simple_test(suite, "str_regtype", test_str_regtype); torture_suite_add_simple_test(suite, "reg_val_data_string dword", -- cgit From d0d0a69d0b2fafafa1ab340c8a352406b07329ef Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 12 Nov 2007 17:22:12 +0100 Subject: r25932: Remove unnecessary include - should fix the build on hosts without popt. (This used to be commit f250ae0c361aef864f25dfc7599ce1e7a4e29cf8) --- source4/lib/registry/tests/diff.c | 1 - source4/lib/registry/tests/generic.c | 1 - source4/lib/registry/tests/hive.c | 1 - source4/lib/registry/tests/registry.c | 1 - 4 files changed, 4 deletions(-) (limited to 'source4/lib/registry/tests') diff --git a/source4/lib/registry/tests/diff.c b/source4/lib/registry/tests/diff.c index 8e6907382c..690f71fcf7 100644 --- a/source4/lib/registry/tests/diff.c +++ b/source4/lib/registry/tests/diff.c @@ -21,7 +21,6 @@ #include "includes.h" #include "lib/registry/registry.h" -#include "lib/cmdline/popt_common.h" #include "torture/torture.h" #include "librpc/gen_ndr/winreg.h" diff --git a/source4/lib/registry/tests/generic.c b/source4/lib/registry/tests/generic.c index 68040ea98e..d18d300423 100644 --- a/source4/lib/registry/tests/generic.c +++ b/source4/lib/registry/tests/generic.c @@ -21,7 +21,6 @@ #include "includes.h" #include "lib/registry/registry.h" -#include "lib/cmdline/popt_common.h" #include "torture/torture.h" #include "librpc/gen_ndr/winreg.h" diff --git a/source4/lib/registry/tests/hive.c b/source4/lib/registry/tests/hive.c index 2ddfe6f036..2a0f04eb54 100644 --- a/source4/lib/registry/tests/hive.c +++ b/source4/lib/registry/tests/hive.c @@ -22,7 +22,6 @@ #include "includes.h" #include "lib/registry/registry.h" -#include "lib/cmdline/popt_common.h" #include "torture/torture.h" #include "librpc/gen_ndr/winreg.h" #include "system/filesys.h" diff --git a/source4/lib/registry/tests/registry.c b/source4/lib/registry/tests/registry.c index 155e891c40..f0035071f2 100644 --- a/source4/lib/registry/tests/registry.c +++ b/source4/lib/registry/tests/registry.c @@ -22,7 +22,6 @@ #include "includes.h" #include "lib/registry/registry.h" -#include "lib/cmdline/popt_common.h" #include "torture/torture.h" #include "librpc/gen_ndr/winreg.h" #include "libcli/security/security.h" -- cgit From 81ad27b3096af61f792dc9bd8983a86161f0f30b Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 13 Nov 2007 04:57:09 +0100 Subject: r25935: Fix registry tests. (This used to be commit b311094714b4d51ea7ea756df1aecba169dc0d45) --- source4/lib/registry/tests/generic.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'source4/lib/registry/tests') diff --git a/source4/lib/registry/tests/generic.c b/source4/lib/registry/tests/generic.c index d18d300423..13e27cd80b 100644 --- a/source4/lib/registry/tests/generic.c +++ b/source4/lib/registry/tests/generic.c @@ -111,9 +111,9 @@ static bool test_reg_val_description_nullname(struct torture_context *ctx) return true; } -_PUBLIC_ NTSTATUS torture_registry_init(void) +_PUBLIC_ struct torture_suite *torture_registry(TALLOC_CTX *mem_ctx) { - struct torture_suite *suite = torture_suite_create(talloc_autofree_context(), "LOCAL-REGISTRY"); + struct torture_suite *suite = torture_suite_create(mem_ctx, "REGISTRY"); torture_suite_add_simple_test(suite, "str_regtype", test_str_regtype); torture_suite_add_simple_test(suite, "reg_val_data_string dword", @@ -133,7 +133,5 @@ _PUBLIC_ NTSTATUS torture_registry_init(void) torture_suite_add_suite(suite, torture_registry_registry(suite)); torture_suite_add_suite(suite, torture_registry_diff(suite)); - torture_register_suite(suite); - - return NT_STATUS_OK; + return suite; } -- cgit From 75c7fd4030a7c2ec5eeb752ccbc0f5fde74d1029 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 21 Nov 2007 12:31:26 +0100 Subject: r26073: Import Python bindings for the registry. (This used to be commit 777205b5705940c00384172c531ea99ba3eae235) --- source4/lib/registry/tests/bindings.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 source4/lib/registry/tests/bindings.py (limited to 'source4/lib/registry/tests') diff --git a/source4/lib/registry/tests/bindings.py b/source4/lib/registry/tests/bindings.py new file mode 100644 index 0000000000..be87efe594 --- /dev/null +++ b/source4/lib/registry/tests/bindings.py @@ -0,0 +1,34 @@ +#!/usr/bin/python + +# Unix SMB/CIFS implementation. +# Copyright (C) Jelmer Vernooij 2007 +# +# 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 . +# + +import unittest +import registry + +class HelperTests(unittest.TestCase): + def test_predef_to_name(self): + self.assertEquals("HKEY_LOCAL_MACHINE", + registry.reg_get_predef_name(0x80000002)) + + def test_str_regtype(self): + self.assertEquals("REG_DWORD", registry.str_regtype(4)) + + +class RegistryTests(unittest.TestCase): + def test_new(self): + self.registry = registry.Registry() -- cgit From 39ee38d9c1aabf4db065b433d067d0da053d7d61 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 6 Dec 2007 17:52:23 +0100 Subject: r26316: Use contexts for conversion functions. (This used to be commit f6420d933b5b011d428974f3a2a57edf19e6f482) --- source4/lib/registry/tests/generic.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source4/lib/registry/tests') diff --git a/source4/lib/registry/tests/generic.c b/source4/lib/registry/tests/generic.c index 13e27cd80b..1acb6342e7 100644 --- a/source4/lib/registry/tests/generic.c +++ b/source4/lib/registry/tests/generic.c @@ -52,7 +52,7 @@ static bool test_reg_val_data_string_dword(struct torture_context *ctx) static bool test_reg_val_data_string_sz(struct torture_context *ctx) { DATA_BLOB db; - db.length = convert_string_talloc(ctx, CH_UNIX, CH_UTF16, + db.length = convert_string_talloc(ctx, global_smb_iconv_convenience, CH_UNIX, CH_UTF16, "bla", 3, (void **)&db.data); torture_assert_str_equal(ctx, "bla", reg_val_data_string(ctx, REG_SZ, db), @@ -87,7 +87,7 @@ static bool test_reg_val_data_string_empty(struct torture_context *ctx) static bool test_reg_val_description(struct torture_context *ctx) { DATA_BLOB data; - data.length = convert_string_talloc(ctx, CH_UNIX, CH_UTF16, + data.length = convert_string_talloc(ctx, global_smb_iconv_convenience, CH_UNIX, CH_UTF16, "stationary traveller", strlen("stationary traveller"), (void **)&data.data); @@ -101,7 +101,7 @@ static bool test_reg_val_description(struct torture_context *ctx) static bool test_reg_val_description_nullname(struct torture_context *ctx) { DATA_BLOB data; - data.length = convert_string_talloc(ctx, CH_UNIX, CH_UTF16, + data.length = convert_string_talloc(ctx, global_smb_iconv_convenience, CH_UNIX, CH_UTF16, "west berlin", strlen("west berlin"), (void **)&data.data); -- cgit From a5b8999f23d56b4a19b87fc17b22c96f88e487e8 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 13 Dec 2007 12:19:33 +0100 Subject: r26427: Avoid global_smb_iconv_convenience. (This used to be commit bf072c6fb37b3e6a71c0c747b9fbeaa01480229e) --- source4/lib/registry/tests/generic.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'source4/lib/registry/tests') diff --git a/source4/lib/registry/tests/generic.c b/source4/lib/registry/tests/generic.c index 1acb6342e7..25a89793bd 100644 --- a/source4/lib/registry/tests/generic.c +++ b/source4/lib/registry/tests/generic.c @@ -23,6 +23,7 @@ #include "lib/registry/registry.h" #include "torture/torture.h" #include "librpc/gen_ndr/winreg.h" +#include "param/param.h" struct torture_suite *torture_registry_hive(TALLOC_CTX *mem_ctx); struct torture_suite *torture_registry_registry(TALLOC_CTX *mem_ctx); @@ -52,7 +53,7 @@ static bool test_reg_val_data_string_dword(struct torture_context *ctx) static bool test_reg_val_data_string_sz(struct torture_context *ctx) { DATA_BLOB db; - db.length = convert_string_talloc(ctx, global_smb_iconv_convenience, CH_UNIX, CH_UTF16, + db.length = convert_string_talloc(ctx, lp_iconv_convenience(ctx->lp_ctx), CH_UNIX, CH_UTF16, "bla", 3, (void **)&db.data); torture_assert_str_equal(ctx, "bla", reg_val_data_string(ctx, REG_SZ, db), @@ -87,7 +88,7 @@ static bool test_reg_val_data_string_empty(struct torture_context *ctx) static bool test_reg_val_description(struct torture_context *ctx) { DATA_BLOB data; - data.length = convert_string_talloc(ctx, global_smb_iconv_convenience, CH_UNIX, CH_UTF16, + data.length = convert_string_talloc(ctx, lp_iconv_convenience(ctx->lp_ctx), CH_UNIX, CH_UTF16, "stationary traveller", strlen("stationary traveller"), (void **)&data.data); @@ -101,7 +102,7 @@ static bool test_reg_val_description(struct torture_context *ctx) static bool test_reg_val_description_nullname(struct torture_context *ctx) { DATA_BLOB data; - data.length = convert_string_talloc(ctx, global_smb_iconv_convenience, CH_UNIX, CH_UTF16, + data.length = convert_string_talloc(ctx, lp_iconv_convenience(ctx->lp_ctx), CH_UNIX, CH_UTF16, "west berlin", strlen("west berlin"), (void **)&data.data); -- cgit From 96a200511e884a88dcf48fa5b313b2cddb2df566 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 14 Dec 2007 00:27:31 +0100 Subject: r26443: Remove global_loadparm instances. (This used to be commit 8242c696235d1bfb402b5c276a57f36d93610545) --- source4/lib/registry/tests/hive.c | 2 +- source4/lib/registry/tests/registry.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/lib/registry/tests') diff --git a/source4/lib/registry/tests/hive.c b/source4/lib/registry/tests/hive.c index 2a0f04eb54..04a91d42fa 100644 --- a/source4/lib/registry/tests/hive.c +++ b/source4/lib/registry/tests/hive.c @@ -323,7 +323,7 @@ static bool hive_setup_ldb(struct torture_context *tctx, void **data) rmdir(dirname); - error = reg_open_ldb_file(tctx, dirname, NULL, NULL, &key); + error = reg_open_ldb_file(tctx, dirname, NULL, NULL, tctx->lp_ctx, &key); if (!W_ERROR_IS_OK(error)) { fprintf(stderr, "Unable to initialize ldb hive\n"); return false; diff --git a/source4/lib/registry/tests/registry.c b/source4/lib/registry/tests/registry.c index f0035071f2..8cb0433084 100644 --- a/source4/lib/registry/tests/registry.c +++ b/source4/lib/registry/tests/registry.c @@ -547,7 +547,7 @@ static bool setup_local_registry(struct torture_context *tctx, void **data) torture_assert_ntstatus_ok(tctx, status, "Creating temp dir failed"); filename = talloc_asprintf(tctx, "%s/classes_root.ldb", tempdir); - error = reg_open_ldb_file(tctx, filename, NULL, NULL, &hive_key); + error = reg_open_ldb_file(tctx, filename, NULL, NULL, tctx->lp_ctx, &hive_key); torture_assert_werr_ok(tctx, error, "Opening classes_root file failed"); error = reg_mount_hive(rctx, hive_key, HKEY_CLASSES_ROOT, NULL); -- cgit From 45015eda2421253f858f0a4500a57c2855f9686c Mon Sep 17 00:00:00 2001 From: Kai Blin Date: Fri, 14 Dec 2007 10:38:26 +0100 Subject: r26451: Janitorial: fix warnings in lib/registry/ This does not fix the discarded qualifier warnings in tests, as the test data is currently passed as const. Jelmer wants to provide a test function that passes non-const test data, thus allowing for a cleaner way to fix those warnings. (This used to be commit 46dfa63d4f7381c5c6ce3f4b8b0bd9aa9e16950c) --- source4/lib/registry/tests/hive.c | 6 +++--- source4/lib/registry/tests/registry.c | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'source4/lib/registry/tests') diff --git a/source4/lib/registry/tests/hive.c b/source4/lib/registry/tests/hive.c index 04a91d42fa..fdb7282395 100644 --- a/source4/lib/registry/tests/hive.c +++ b/source4/lib/registry/tests/hive.c @@ -290,7 +290,7 @@ static bool hive_setup_dir(struct torture_context *tctx, void **data) { struct hive_key *key; WERROR error; - const char *dirname; + char *dirname; NTSTATUS status; status = torture_temp_dir(tctx, "hive-dir", &dirname); @@ -314,7 +314,7 @@ static bool hive_setup_ldb(struct torture_context *tctx, void **data) { struct hive_key *key; WERROR error; - const char *dirname; + char *dirname; NTSTATUS status; status = torture_temp_dir(tctx, "hive-ldb", &dirname); @@ -338,7 +338,7 @@ static bool hive_setup_regf(struct torture_context *tctx, void **data) { struct hive_key *key; WERROR error; - const char *dirname; + char *dirname; NTSTATUS status; status = torture_temp_dir(tctx, "hive-dir", &dirname); diff --git a/source4/lib/registry/tests/registry.c b/source4/lib/registry/tests/registry.c index 8cb0433084..6c520f54ed 100644 --- a/source4/lib/registry/tests/registry.c +++ b/source4/lib/registry/tests/registry.c @@ -535,7 +535,7 @@ static bool setup_local_registry(struct torture_context *tctx, void **data) { struct registry_context *rctx; WERROR error; - const char *tempdir; + char *tempdir; NTSTATUS status; struct hive_key *hive_key; const char *filename; -- cgit From 09f820f0bd1a9fc7ffd171418ceb0e19df8e2e43 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 22 Dec 2007 05:02:57 -0600 Subject: r26564: More python bindings for registry code. (This used to be commit f40fad9827d0e9567224bc1e64ea91e610a07a3f) --- source4/lib/registry/tests/hive.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/lib/registry/tests') diff --git a/source4/lib/registry/tests/hive.c b/source4/lib/registry/tests/hive.c index fdb7282395..e3a301710f 100644 --- a/source4/lib/registry/tests/hive.c +++ b/source4/lib/registry/tests/hive.c @@ -211,13 +211,13 @@ static bool test_del_value(struct torture_context *tctx, const void *test_data) data_blob_talloc(mem_ctx, &data, sizeof(data))); torture_assert_werr_ok(tctx, error, "hive_set_value"); - error = hive_del_value(subkey, "Answer"); + error = hive_key_del_value(subkey, "Answer"); torture_assert_werr_ok(tctx, error, "deleting value"); error = hive_get_value(mem_ctx, subkey, "Answer", &type, &value); torture_assert_werr_equal(tctx, error, WERR_NOT_FOUND, "getting value"); - error = hive_del_value(subkey, "Answer"); + error = hive_key_del_value(subkey, "Answer"); torture_assert_werr_equal(tctx, error, WERR_NOT_FOUND, "deleting value"); -- cgit From 249cc734cebfef31320ec10b05dbfaaaa39682ca Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 22 Dec 2007 05:03:02 -0600 Subject: r26565: Fix python registry bindings. 'PROVISION_PYTHON=yes make test' works now. (This used to be commit 485d1fa3d17fe6cc7a0ecd80e8bac42d173bbb19) --- source4/lib/registry/tests/bindings.py | 18 ++++++++++++++++++ source4/lib/registry/tests/hive.c | 20 ++++++++++---------- 2 files changed, 28 insertions(+), 10 deletions(-) (limited to 'source4/lib/registry/tests') diff --git a/source4/lib/registry/tests/bindings.py b/source4/lib/registry/tests/bindings.py index be87efe594..9f93ee9382 100644 --- a/source4/lib/registry/tests/bindings.py +++ b/source4/lib/registry/tests/bindings.py @@ -17,8 +17,10 @@ # along with this program. If not, see . # +import os import unittest import registry +import samba.tests class HelperTests(unittest.TestCase): def test_predef_to_name(self): @@ -29,6 +31,22 @@ class HelperTests(unittest.TestCase): self.assertEquals("REG_DWORD", registry.str_regtype(4)) + +class HiveTests(samba.tests.TestCaseInTempDir): + def setUp(self): + super(HiveTests, self).setUp() + self.hive = registry.open_ldb(os.path.join(self.tempdir, "ldb_new.ldb")) + + def test_ldb_new(self): + self.assertTrue(self.hive is not None) + + def test_flush(self): + self.hive.flush() + + def test_del_value(self): + self.hive.del_value("FOO") + + class RegistryTests(unittest.TestCase): def test_new(self): self.registry = registry.Registry() diff --git a/source4/lib/registry/tests/hive.c b/source4/lib/registry/tests/hive.c index e3a301710f..43ec9e4252 100644 --- a/source4/lib/registry/tests/hive.c +++ b/source4/lib/registry/tests/hive.c @@ -74,9 +74,9 @@ static bool test_keyinfo_nums(struct torture_context *tctx, NULL, &subkey); torture_assert_werr_ok(tctx, error, "hive_key_add_name"); - error = hive_set_value(root, "Answer", REG_DWORD, + error = hive_key_set_value(root, "Answer", REG_DWORD, data_blob_talloc(tctx, &data, sizeof(data))); - torture_assert_werr_ok(tctx, error, "hive_set_value"); + torture_assert_werr_ok(tctx, error, "hive_key_set_value"); /* This is a new backend. There should be no subkeys and no * values */ @@ -154,9 +154,9 @@ static bool test_set_value(struct torture_context *tctx, NULL, &subkey); torture_assert_werr_ok(tctx, error, "hive_key_add_name"); - error = hive_set_value(subkey, "Answer", REG_DWORD, + error = hive_key_set_value(subkey, "Answer", REG_DWORD, data_blob_talloc(mem_ctx, &data, sizeof(data))); - torture_assert_werr_ok(tctx, error, "hive_set_value"); + torture_assert_werr_ok(tctx, error, "hive_key_set_value"); return true; } @@ -179,9 +179,9 @@ static bool test_get_value(struct torture_context *tctx, const void *test_data) torture_assert_werr_equal(tctx, error, WERR_NOT_FOUND, "getting missing value"); - error = hive_set_value(subkey, "Answer", REG_DWORD, + error = hive_key_set_value(subkey, "Answer", REG_DWORD, data_blob_talloc(mem_ctx, &data, sizeof(data))); - torture_assert_werr_ok(tctx, error, "hive_set_value"); + torture_assert_werr_ok(tctx, error, "hive_key_set_value"); error = hive_get_value(mem_ctx, subkey, "Answer", &type, &value); torture_assert_werr_ok(tctx, error, "getting value"); @@ -207,9 +207,9 @@ static bool test_del_value(struct torture_context *tctx, const void *test_data) NULL, &subkey); torture_assert_werr_ok(tctx, error, "hive_key_add_name"); - error = hive_set_value(subkey, "Answer", REG_DWORD, + error = hive_key_set_value(subkey, "Answer", REG_DWORD, data_blob_talloc(mem_ctx, &data, sizeof(data))); - torture_assert_werr_ok(tctx, error, "hive_set_value"); + torture_assert_werr_ok(tctx, error, "hive_key_set_value"); error = hive_key_del_value(subkey, "Answer"); torture_assert_werr_ok(tctx, error, "deleting value"); @@ -240,9 +240,9 @@ static bool test_list_values(struct torture_context *tctx, NULL, &subkey); torture_assert_werr_ok(tctx, error, "hive_key_add_name"); - error = hive_set_value(subkey, "Answer", REG_DWORD, + error = hive_key_set_value(subkey, "Answer", REG_DWORD, data_blob_talloc(mem_ctx, &data, sizeof(data))); - torture_assert_werr_ok(tctx, error, "hive_set_value"); + torture_assert_werr_ok(tctx, error, "hive_key_set_value"); error = hive_get_value_by_index(mem_ctx, subkey, 0, &name, &type, &value); -- cgit From aa0a06f13c44e0eca0b3f2f0c34f0f7995b87159 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 23 Dec 2007 19:19:41 -0600 Subject: r26570: - Trim size of the swig-generated Python bindings by removing a bunch of {}'s. - Start working on Python equivalents for various EJS tests. - Fix regression in argument order for reg_diff_apply() in EJS bindings. (This used to be commit c550c03372cb260b78f6a6c132e70571bc4cb852) --- source4/lib/registry/tests/bindings.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source4/lib/registry/tests') diff --git a/source4/lib/registry/tests/bindings.py b/source4/lib/registry/tests/bindings.py index 9f93ee9382..906deed7e9 100644 --- a/source4/lib/registry/tests/bindings.py +++ b/source4/lib/registry/tests/bindings.py @@ -40,11 +40,11 @@ class HiveTests(samba.tests.TestCaseInTempDir): def test_ldb_new(self): self.assertTrue(self.hive is not None) - def test_flush(self): - self.hive.flush() + #def test_flush(self): + # self.hive.flush() - def test_del_value(self): - self.hive.del_value("FOO") + #def test_del_value(self): + # self.hive.del_value("FOO") class RegistryTests(unittest.TestCase): -- cgit From 3c744ddd2c33a9a06013f357261b8ea86804e8e8 Mon Sep 17 00:00:00 2001 From: Kai Blin Date: Mon, 24 Dec 2007 13:04:56 -0600 Subject: r26588: Janitorial: Rename torture_*_add_*test to torture_*_add_*test_const. Also rename the corresponding wrap_ functions. (This used to be commit e59c2eaf681f076d175b9779d1c27b5f74a57c96) --- source4/lib/registry/tests/hive.c | 40 +++++++++---------- source4/lib/registry/tests/registry.c | 73 ++++++++++++++++++----------------- 2 files changed, 57 insertions(+), 56 deletions(-) (limited to 'source4/lib/registry/tests') diff --git a/source4/lib/registry/tests/hive.c b/source4/lib/registry/tests/hive.c index 43ec9e4252..dc59d0f9ca 100644 --- a/source4/lib/registry/tests/hive.c +++ b/source4/lib/registry/tests/hive.c @@ -264,26 +264,26 @@ static bool test_list_values(struct torture_context *tctx, static void tcase_add_tests(struct torture_tcase *tcase) { - torture_tcase_add_simple_test(tcase, "del_nonexistant_key", - test_del_nonexistant_key); - torture_tcase_add_simple_test(tcase, "add_subkey", - test_add_subkey); - torture_tcase_add_simple_test(tcase, "flush_key", - test_flush_key); - torture_tcase_add_simple_test(tcase, "get_info", - test_keyinfo_root); - torture_tcase_add_simple_test(tcase, "get_info_nums", - test_keyinfo_nums); - torture_tcase_add_simple_test(tcase, "set_value", - test_set_value); - torture_tcase_add_simple_test(tcase, "get_value", - test_get_value); - torture_tcase_add_simple_test(tcase, "list_values", - test_list_values); - torture_tcase_add_simple_test(tcase, "del_key", - test_del_key); - torture_tcase_add_simple_test(tcase, "del_value", - test_del_value); + torture_tcase_add_simple_test_const(tcase, "del_nonexistant_key", + test_del_nonexistant_key); + torture_tcase_add_simple_test_const(tcase, "add_subkey", + test_add_subkey); + torture_tcase_add_simple_test_const(tcase, "flush_key", + test_flush_key); + torture_tcase_add_simple_test_const(tcase, "get_info", + test_keyinfo_root); + torture_tcase_add_simple_test_const(tcase, "get_info_nums", + test_keyinfo_nums); + torture_tcase_add_simple_test_const(tcase, "set_value", + test_set_value); + torture_tcase_add_simple_test_const(tcase, "get_value", + test_get_value); + torture_tcase_add_simple_test_const(tcase, "list_values", + test_list_values); + torture_tcase_add_simple_test_const(tcase, "del_key", + test_del_key); + torture_tcase_add_simple_test_const(tcase, "del_value", + test_del_value); } static bool hive_setup_dir(struct torture_context *tctx, void **data) diff --git a/source4/lib/registry/tests/registry.c b/source4/lib/registry/tests/registry.c index 6c520f54ed..7897909865 100644 --- a/source4/lib/registry/tests/registry.c +++ b/source4/lib/registry/tests/registry.c @@ -560,42 +560,43 @@ static bool setup_local_registry(struct torture_context *tctx, void **data) static void tcase_add_tests(struct torture_tcase *tcase) { - torture_tcase_add_simple_test(tcase, "list_subkeys", - test_list_subkeys); - torture_tcase_add_simple_test(tcase, "get_predefined_key", - test_get_predefined); - torture_tcase_add_simple_test(tcase, "get_predefined_key", - test_get_predefined_unknown); - torture_tcase_add_simple_test(tcase, "create_key", - test_create_subkey); - torture_tcase_add_simple_test(tcase, "create_key", - test_create_nested_subkey); - torture_tcase_add_simple_test(tcase, "key_add_abs", - test_key_add_abs); - torture_tcase_add_simple_test(tcase, "key_add_abs_top", - test_key_add_abs_top); - torture_tcase_add_simple_test(tcase, "set_value", - test_set_value); - torture_tcase_add_simple_test(tcase, "get_value", - test_get_value); - torture_tcase_add_simple_test(tcase, "list_values", - test_list_values); - torture_tcase_add_simple_test(tcase, "del_key", - test_del_key); - torture_tcase_add_simple_test(tcase, "del_value", - test_del_value); - torture_tcase_add_simple_test(tcase, "flush_key", - test_flush_key); - torture_tcase_add_simple_test(tcase, "query_key", - test_query_key); - torture_tcase_add_simple_test(tcase, "query_key_nums", - test_query_key_nums); - torture_tcase_add_simple_test(tcase, "test_predef_key_by_name", - test_predef_key_by_name); - torture_tcase_add_simple_test(tcase, "security", - test_security); - torture_tcase_add_simple_test(tcase, "test_predef_key_by_name_invalid", - test_predef_key_by_name_invalid); + torture_tcase_add_simple_test_const(tcase, "list_subkeys", + test_list_subkeys); + torture_tcase_add_simple_test_const(tcase, "get_predefined_key", + test_get_predefined); + torture_tcase_add_simple_test_const(tcase, "get_predefined_key", + test_get_predefined_unknown); + torture_tcase_add_simple_test_const(tcase, "create_key", + test_create_subkey); + torture_tcase_add_simple_test_const(tcase, "create_key", + test_create_nested_subkey); + torture_tcase_add_simple_test_const(tcase, "key_add_abs", + test_key_add_abs); + torture_tcase_add_simple_test_const(tcase, "key_add_abs_top", + test_key_add_abs_top); + torture_tcase_add_simple_test_const(tcase, "set_value", + test_set_value); + torture_tcase_add_simple_test_const(tcase, "get_value", + test_get_value); + torture_tcase_add_simple_test_const(tcase, "list_values", + test_list_values); + torture_tcase_add_simple_test_const(tcase, "del_key", + test_del_key); + torture_tcase_add_simple_test_const(tcase, "del_value", + test_del_value); + torture_tcase_add_simple_test_const(tcase, "flush_key", + test_flush_key); + torture_tcase_add_simple_test_const(tcase, "query_key", + test_query_key); + torture_tcase_add_simple_test_const(tcase, "query_key_nums", + test_query_key_nums); + torture_tcase_add_simple_test_const(tcase, "test_predef_key_by_name", + test_predef_key_by_name); + torture_tcase_add_simple_test_const(tcase, "security", + test_security); + torture_tcase_add_simple_test_const(tcase, + "test_predef_key_by_name_invalid", + test_predef_key_by_name_invalid); } struct torture_suite *torture_registry_registry(TALLOC_CTX *mem_ctx) -- cgit From a6caca9abcf4de57901ba8ecc610cf8c13cd2821 Mon Sep 17 00:00:00 2001 From: Kai Blin Date: Mon, 24 Dec 2007 13:06:57 -0600 Subject: r26589: torture: Add non-const version of torture_tcase_add_simple_test (This used to be commit 1ae9cde5105cc4349a44e6098e9393e06acaf95d) --- source4/lib/registry/tests/hive.c | 14 ++- source4/lib/registry/tests/registry.c | 170 +++++++++++++++------------------- 2 files changed, 79 insertions(+), 105 deletions(-) (limited to 'source4/lib/registry/tests') diff --git a/source4/lib/registry/tests/hive.c b/source4/lib/registry/tests/hive.c index dc59d0f9ca..bc3c82552e 100644 --- a/source4/lib/registry/tests/hive.c +++ b/source4/lib/registry/tests/hive.c @@ -61,11 +61,10 @@ static bool test_keyinfo_root(struct torture_context *tctx, return true; } -static bool test_keyinfo_nums(struct torture_context *tctx, - const void *test_data) +static bool test_keyinfo_nums(struct torture_context *tctx, void *test_data) { uint32_t num_subkeys, num_values; - const struct hive_key *root = (const struct hive_key *)test_data; + struct hive_key *root = (struct hive_key *)test_data; WERROR error; struct hive_key *subkey; uint32_t data = 42; @@ -111,10 +110,9 @@ static bool test_add_subkey(struct torture_context *tctx, return true; } -static bool test_flush_key(struct torture_context *tctx, - const void *test_data) +static bool test_flush_key(struct torture_context *tctx, void *test_data) { - const struct hive_key *root = (const struct hive_key *)test_data; + struct hive_key *root = (struct hive_key *)test_data; torture_assert_werr_ok(tctx, hive_key_flush(root), "flush key"); @@ -268,11 +266,11 @@ static void tcase_add_tests(struct torture_tcase *tcase) test_del_nonexistant_key); torture_tcase_add_simple_test_const(tcase, "add_subkey", test_add_subkey); - torture_tcase_add_simple_test_const(tcase, "flush_key", + torture_tcase_add_simple_test(tcase, "flush_key", test_flush_key); torture_tcase_add_simple_test_const(tcase, "get_info", test_keyinfo_root); - torture_tcase_add_simple_test_const(tcase, "get_info_nums", + torture_tcase_add_simple_test(tcase, "get_info_nums", test_keyinfo_nums); torture_tcase_add_simple_test_const(tcase, "set_value", test_set_value); diff --git a/source4/lib/registry/tests/registry.c b/source4/lib/registry/tests/registry.c index 7897909865..2133e72310 100644 --- a/source4/lib/registry/tests/registry.c +++ b/source4/lib/registry/tests/registry.c @@ -30,11 +30,9 @@ /** * Test obtaining a predefined key. */ -static bool test_get_predefined(struct torture_context *tctx, - const void *_data) +static bool test_get_predefined(struct torture_context *tctx, void *_data) { - const struct registry_context *rctx = - (const struct registry_context *)_data; + struct registry_context *rctx = (struct registry_context *)_data; struct registry_key *root; WERROR error; @@ -48,9 +46,9 @@ static bool test_get_predefined(struct torture_context *tctx, * Test obtaining a predefined key. */ static bool test_get_predefined_unknown(struct torture_context *tctx, - const void *_data) + void *_data) { - const struct registry_context *rctx = _data; + struct registry_context *rctx = _data; struct registry_key *root; WERROR error; @@ -60,11 +58,9 @@ static bool test_get_predefined_unknown(struct torture_context *tctx, return true; } -static bool test_predef_key_by_name(struct torture_context *tctx, - const void *_data) +static bool test_predef_key_by_name(struct torture_context *tctx, void *_data) { - const struct registry_context *rctx = - (const struct registry_context *)_data; + struct registry_context *rctx = (struct registry_context *)_data; struct registry_key *root; WERROR error; @@ -82,10 +78,9 @@ static bool test_predef_key_by_name(struct torture_context *tctx, } static bool test_predef_key_by_name_invalid(struct torture_context *tctx, - const void *_data) + void *_data) { - const struct registry_context *rctx = - (const struct registry_context *)_data; + struct registry_context *rctx = (struct registry_context *)_data; struct registry_key *root; WERROR error; @@ -98,11 +93,9 @@ static bool test_predef_key_by_name_invalid(struct torture_context *tctx, /** * Test creating a new subkey */ -static bool test_create_subkey(struct torture_context *tctx, - const void *_data) +static bool test_create_subkey(struct torture_context *tctx, void *_data) { - const struct registry_context *rctx = - (const struct registry_context *)_data; + struct registry_context *rctx = (struct registry_context *)_data; struct registry_key *root, *newkey; WERROR error; @@ -121,11 +114,9 @@ static bool test_create_subkey(struct torture_context *tctx, /** * Test creating a new nested subkey */ -static bool test_create_nested_subkey(struct torture_context *tctx, - const void *_data) +static bool test_create_nested_subkey(struct torture_context *tctx, void *_data) { - const struct registry_context *rctx = - (const struct registry_context *)_data; + struct registry_context *rctx = (struct registry_context *)_data; struct registry_key *root, *newkey1, *newkey2; WERROR error; @@ -149,11 +140,9 @@ static bool test_create_nested_subkey(struct torture_context *tctx, /** * Test creating a new subkey */ -static bool test_key_add_abs_top(struct torture_context *tctx, - const void *_data) +static bool test_key_add_abs_top(struct torture_context *tctx, void *_data) { - const struct registry_context *rctx = - (const struct registry_context *)_data; + struct registry_context *rctx = (struct registry_context *)_data; struct registry_key *root; WERROR error; @@ -168,12 +157,10 @@ static bool test_key_add_abs_top(struct torture_context *tctx, /** * Test creating a new subkey */ -static bool test_key_add_abs(struct torture_context *tctx, - const void *_data) +static bool test_key_add_abs(struct torture_context *tctx, void *_data) { WERROR error; - const struct registry_context *rctx = - (const struct registry_context *)_data; + struct registry_context *rctx = (struct registry_context *)_data; struct registry_key *root, *result1, *result2; error = reg_key_add_abs(tctx, rctx, "HKEY_CLASSES_ROOT\\bloe", 0, NULL, @@ -198,10 +185,9 @@ static bool test_key_add_abs(struct torture_context *tctx, } -static bool test_del_key(struct torture_context *tctx, const void *_data) +static bool test_del_key(struct torture_context *tctx, void *_data) { - const struct registry_context *rctx = - (const struct registry_context *)_data; + struct registry_context *rctx = (struct registry_context *)_data; struct registry_key *root, *newkey; WERROR error; @@ -229,7 +215,7 @@ static bool test_del_key(struct torture_context *tctx, const void *_data) * creating a single key for testing purposes. */ static bool create_test_key(struct torture_context *tctx, - const struct registry_context *rctx, + struct registry_context *rctx, const char *name, struct registry_key **root, struct registry_key **subkey) @@ -247,10 +233,9 @@ static bool create_test_key(struct torture_context *tctx, } -static bool test_flush_key(struct torture_context *tctx, const void *_data) +static bool test_flush_key(struct torture_context *tctx, void *_data) { - const struct registry_context *rctx = - (const struct registry_context *)_data; + struct registry_context *rctx = (struct registry_context *)_data; struct registry_key *root, *subkey; WERROR error; @@ -266,10 +251,9 @@ static bool test_flush_key(struct torture_context *tctx, const void *_data) return true; } -static bool test_query_key(struct torture_context *tctx, const void *_data) +static bool test_query_key(struct torture_context *tctx, void *_data) { - const struct registry_context *rctx = - (const struct registry_context *)_data; + struct registry_context *rctx = (struct registry_context *)_data; struct registry_key *root, *subkey; WERROR error; NTTIME last_changed_time; @@ -291,10 +275,9 @@ static bool test_query_key(struct torture_context *tctx, const void *_data) return true; } -static bool test_query_key_nums(struct torture_context *tctx, const void *_data) +static bool test_query_key_nums(struct torture_context *tctx, void *_data) { - const struct registry_context *rctx = - (const struct registry_context *)_data; + struct registry_context *rctx = (struct registry_context *)_data; struct registry_key *root, *subkey1, *subkey2; WERROR error; uint32_t num_subkeys, num_values; @@ -326,10 +309,9 @@ static bool test_query_key_nums(struct torture_context *tctx, const void *_data) * the returned parameters for get_subkey_by_index are optional and * that enumerating the parents of a non-top-level node works. */ -static bool test_list_subkeys(struct torture_context *tctx, const void *_data) +static bool test_list_subkeys(struct torture_context *tctx, void *_data) { - const struct registry_context *rctx = - (const struct registry_context *)_data; + struct registry_context *rctx = (struct registry_context *)_data; struct registry_key *subkey = NULL, *root; WERROR error; NTTIME last_mod_time; @@ -366,10 +348,9 @@ static bool test_list_subkeys(struct torture_context *tctx, const void *_data) /** * Test setting a value */ -static bool test_set_value(struct torture_context *tctx, const void *_data) +static bool test_set_value(struct torture_context *tctx, void *_data) { - const struct registry_context *rctx = - (const struct registry_context *)_data; + struct registry_context *rctx = (struct registry_context *)_data; struct registry_key *subkey = NULL, *root; WERROR error; uint32_t data = 42; @@ -387,10 +368,9 @@ static bool test_set_value(struct torture_context *tctx, const void *_data) /** * Test getting/setting security descriptors */ -static bool test_security(struct torture_context *tctx, const void *_data) +static bool test_security(struct torture_context *tctx, void *_data) { - const struct registry_context *rctx = - (const struct registry_context *)_data; + struct registry_context *rctx = (struct registry_context *)_data; struct registry_key *subkey = NULL, *root; WERROR error; struct security_descriptor *osd, *nsd; @@ -422,10 +402,9 @@ static bool test_security(struct torture_context *tctx, const void *_data) /** * Test getting a value */ -static bool test_get_value(struct torture_context *tctx, const void *_data) +static bool test_get_value(struct torture_context *tctx, void *_data) { - const struct registry_context *rctx = - (const struct registry_context *)_data; + struct registry_context *rctx = (struct registry_context *)_data; struct registry_key *subkey = NULL, *root; WERROR error; DATA_BLOB data; @@ -459,10 +438,9 @@ static bool test_get_value(struct torture_context *tctx, const void *_data) /** * Test unsetting a value */ -static bool test_del_value(struct torture_context *tctx, const void *_data) +static bool test_del_value(struct torture_context *tctx, void *_data) { - const struct registry_context *rctx = - (const struct registry_context *)_data; + struct registry_context *rctx =(struct registry_context *)_data; struct registry_key *subkey = NULL, *root; WERROR error; DATA_BLOB data; @@ -495,10 +473,9 @@ static bool test_del_value(struct torture_context *tctx, const void *_data) /** * Test listing values */ -static bool test_list_values(struct torture_context *tctx, const void *_data) +static bool test_list_values(struct torture_context *tctx, void *_data) { - const struct registry_context *rctx = - (const struct registry_context *)_data; + struct registry_context *rctx = (struct registry_context *)_data; struct registry_key *subkey = NULL, *root; WERROR error; DATA_BLOB data; @@ -560,43 +537,42 @@ static bool setup_local_registry(struct torture_context *tctx, void **data) static void tcase_add_tests(struct torture_tcase *tcase) { - torture_tcase_add_simple_test_const(tcase, "list_subkeys", - test_list_subkeys); - torture_tcase_add_simple_test_const(tcase, "get_predefined_key", - test_get_predefined); - torture_tcase_add_simple_test_const(tcase, "get_predefined_key", - test_get_predefined_unknown); - torture_tcase_add_simple_test_const(tcase, "create_key", - test_create_subkey); - torture_tcase_add_simple_test_const(tcase, "create_key", - test_create_nested_subkey); - torture_tcase_add_simple_test_const(tcase, "key_add_abs", - test_key_add_abs); - torture_tcase_add_simple_test_const(tcase, "key_add_abs_top", - test_key_add_abs_top); - torture_tcase_add_simple_test_const(tcase, "set_value", - test_set_value); - torture_tcase_add_simple_test_const(tcase, "get_value", - test_get_value); - torture_tcase_add_simple_test_const(tcase, "list_values", - test_list_values); - torture_tcase_add_simple_test_const(tcase, "del_key", - test_del_key); - torture_tcase_add_simple_test_const(tcase, "del_value", - test_del_value); - torture_tcase_add_simple_test_const(tcase, "flush_key", - test_flush_key); - torture_tcase_add_simple_test_const(tcase, "query_key", - test_query_key); - torture_tcase_add_simple_test_const(tcase, "query_key_nums", - test_query_key_nums); - torture_tcase_add_simple_test_const(tcase, "test_predef_key_by_name", - test_predef_key_by_name); - torture_tcase_add_simple_test_const(tcase, "security", - test_security); - torture_tcase_add_simple_test_const(tcase, - "test_predef_key_by_name_invalid", - test_predef_key_by_name_invalid); + torture_tcase_add_simple_test(tcase, "list_subkeys", + test_list_subkeys); + torture_tcase_add_simple_test(tcase, "get_predefined_key", + test_get_predefined); + torture_tcase_add_simple_test(tcase, "get_predefined_key", + test_get_predefined_unknown); + torture_tcase_add_simple_test(tcase, "create_key", + test_create_subkey); + torture_tcase_add_simple_test(tcase, "create_key", + test_create_nested_subkey); + torture_tcase_add_simple_test(tcase, "key_add_abs", + test_key_add_abs); + torture_tcase_add_simple_test(tcase, "key_add_abs_top", + test_key_add_abs_top); + torture_tcase_add_simple_test(tcase, "set_value", + test_set_value); + torture_tcase_add_simple_test(tcase, "get_value", + test_get_value); + torture_tcase_add_simple_test(tcase, "list_values", + test_list_values); + torture_tcase_add_simple_test(tcase, "del_key", + test_del_key); + torture_tcase_add_simple_test(tcase, "del_value", + test_del_value); + torture_tcase_add_simple_test(tcase, "flush_key", + test_flush_key); + torture_tcase_add_simple_test(tcase, "query_key", + test_query_key); + torture_tcase_add_simple_test(tcase, "query_key_nums", + test_query_key_nums); + torture_tcase_add_simple_test(tcase, "test_predef_key_by_name", + test_predef_key_by_name); + torture_tcase_add_simple_test(tcase, "security", + test_security); + torture_tcase_add_simple_test(tcase,"test_predef_key_by_name_invalid", + test_predef_key_by_name_invalid); } struct torture_suite *torture_registry_registry(TALLOC_CTX *mem_ctx) -- cgit From 533cc583ed20efdfd6bee60f86d16fef3942898b Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 25 Dec 2007 16:36:44 -0600 Subject: r26596: Fixed upgrade.py. Added blackbox tests for provision and upgrade Python scripts. Clean up temporary files created by the Python tests. (This used to be commit 2227fb6df62240cae64d27a1920d878316f819fc) --- source4/lib/registry/tests/bindings.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'source4/lib/registry/tests') diff --git a/source4/lib/registry/tests/bindings.py b/source4/lib/registry/tests/bindings.py index 906deed7e9..314cf778a1 100644 --- a/source4/lib/registry/tests/bindings.py +++ b/source4/lib/registry/tests/bindings.py @@ -35,7 +35,12 @@ class HelperTests(unittest.TestCase): class HiveTests(samba.tests.TestCaseInTempDir): def setUp(self): super(HiveTests, self).setUp() - self.hive = registry.open_ldb(os.path.join(self.tempdir, "ldb_new.ldb")) + self.hive_path = os.path.join(self.tempdir, "ldb_new.ldb") + self.hive = registry.open_ldb(self.hive_path) + + def tearDown(self): + del self.hive + os.unlink(self.hive_path) def test_ldb_new(self): self.assertTrue(self.hive is not None) -- cgit From df70180c0ff55a526cec997b6a9fc550cf2719d6 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 5 Jan 2008 13:59:53 -0600 Subject: r26665: registry: Fix tests on bigendian machines. (This used to be commit bcd8f50f7952d1e502326f11ddfa8cfe8a982b1b) --- source4/lib/registry/tests/hive.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'source4/lib/registry/tests') diff --git a/source4/lib/registry/tests/hive.c b/source4/lib/registry/tests/hive.c index bc3c82552e..36eea84d94 100644 --- a/source4/lib/registry/tests/hive.c +++ b/source4/lib/registry/tests/hive.c @@ -186,7 +186,9 @@ static bool test_get_value(struct torture_context *tctx, const void *test_data) torture_assert_int_equal(tctx, value.length, 4, "value length"); torture_assert_int_equal(tctx, type, REG_DWORD, "value type"); - torture_assert(tctx, memcmp(value.data, &data, 4) == 0, "value data"); + + torture_assert_int_equal(tctx, data, IVAL(value.data, 0), + "value data"); return true; } @@ -250,7 +252,9 @@ static bool test_list_values(struct torture_context *tctx, torture_assert_int_equal(tctx, value.length, 4, "value length"); torture_assert_int_equal(tctx, type, REG_DWORD, "value type"); - torture_assert(tctx, memcmp(value.data, &data, 4) == 0, "value data"); + + + torture_assert_int_equal(tctx, data, IVAL(value.data, 0), "value data"); error = hive_get_value_by_index(mem_ctx, subkey, 1, &name, &type, &value); -- cgit From 47f6bbf8cf5bdd03c72c59d00e3e1eab8895590e Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 7 Jan 2008 14:11:29 -0600 Subject: r26689: registry: Return max_subkeynamelen, max_valnamelen and max_valbufsize in getkeyinfo(). (This used to be commit b06896d2378e536f5044dbe500a5232a89d6d0b5) --- source4/lib/registry/tests/hive.c | 4 ++-- source4/lib/registry/tests/registry.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'source4/lib/registry/tests') diff --git a/source4/lib/registry/tests/hive.c b/source4/lib/registry/tests/hive.c index 36eea84d94..22b4785222 100644 --- a/source4/lib/registry/tests/hive.c +++ b/source4/lib/registry/tests/hive.c @@ -47,7 +47,7 @@ static bool test_keyinfo_root(struct torture_context *tctx, /* This is a new backend. There should be no subkeys and no * values */ error = hive_key_get_info(tctx, root, NULL, &num_subkeys, &num_values, - NULL); + NULL, NULL, NULL, NULL); torture_assert_werr_ok(tctx, error, "reg_key_num_subkeys()"); torture_assert_int_equal(tctx, num_subkeys, 0, @@ -80,7 +80,7 @@ static bool test_keyinfo_nums(struct torture_context *tctx, void *test_data) /* This is a new backend. There should be no subkeys and no * values */ error = hive_key_get_info(tctx, root, NULL, &num_subkeys, &num_values, - NULL); + NULL, NULL, NULL, NULL); torture_assert_werr_ok(tctx, error, "reg_key_num_subkeys()"); torture_assert_int_equal(tctx, num_subkeys, 1, "subkey count"); diff --git a/source4/lib/registry/tests/registry.c b/source4/lib/registry/tests/registry.c index 2133e72310..75fbe1cbea 100644 --- a/source4/lib/registry/tests/registry.c +++ b/source4/lib/registry/tests/registry.c @@ -265,7 +265,7 @@ static bool test_query_key(struct torture_context *tctx, void *_data) error = reg_key_get_info(tctx, subkey, &classname, &num_subkeys, &num_values, - &last_changed_time); + &last_changed_time, NULL, NULL, NULL); torture_assert_werr_ok(tctx, error, "get info key"); torture_assert(tctx, classname == NULL, "classname"); @@ -295,7 +295,7 @@ static bool test_query_key_nums(struct torture_context *tctx, void *_data) torture_assert_werr_ok(tctx, error, "set value"); error = reg_key_get_info(tctx, subkey1, NULL, &num_subkeys, - &num_values, NULL); + &num_values, NULL, NULL, NULL, NULL); torture_assert_werr_ok(tctx, error, "get info key"); torture_assert_int_equal(tctx, num_subkeys, 1, "num subkeys"); -- cgit From 85d60d2d091a2eb6bd4c73c87c94b10ee93167ee Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 18 Jan 2008 02:45:00 +0100 Subject: registry: Improve error codes and update tests. Rather than map the error returned by the registry to the correct error, return the correct error in the first place. Also deal with the fact that the right error code is now returned in a couple of places. (This used to be commit 1e31fcb8a097810a97e2d4bb1f243f1b34cc2415) --- source4/lib/registry/tests/hive.c | 4 ++-- source4/lib/registry/tests/registry.c | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) (limited to 'source4/lib/registry/tests') diff --git a/source4/lib/registry/tests/hive.c b/source4/lib/registry/tests/hive.c index 22b4785222..f72b7d6bf3 100644 --- a/source4/lib/registry/tests/hive.c +++ b/source4/lib/registry/tests/hive.c @@ -174,7 +174,7 @@ static bool test_get_value(struct torture_context *tctx, const void *test_data) torture_assert_werr_ok(tctx, error, "hive_key_add_name"); error = hive_get_value(mem_ctx, subkey, "Answer", &type, &value); - torture_assert_werr_equal(tctx, error, WERR_NOT_FOUND, + torture_assert_werr_equal(tctx, error, WERR_BADFILE, "getting missing value"); error = hive_key_set_value(subkey, "Answer", REG_DWORD, @@ -215,7 +215,7 @@ static bool test_del_value(struct torture_context *tctx, const void *test_data) torture_assert_werr_ok(tctx, error, "deleting value"); error = hive_get_value(mem_ctx, subkey, "Answer", &type, &value); - torture_assert_werr_equal(tctx, error, WERR_NOT_FOUND, "getting value"); + torture_assert_werr_equal(tctx, error, WERR_BADFILE, "getting value"); error = hive_key_del_value(subkey, "Answer"); torture_assert_werr_equal(tctx, error, WERR_NOT_FOUND, diff --git a/source4/lib/registry/tests/registry.c b/source4/lib/registry/tests/registry.c index 75fbe1cbea..59e31f55dc 100644 --- a/source4/lib/registry/tests/registry.c +++ b/source4/lib/registry/tests/registry.c @@ -195,15 +195,15 @@ static bool test_del_key(struct torture_context *tctx, void *_data) torture_assert_werr_ok(tctx, error, "getting predefined key failed"); - error = reg_key_add_name(rctx, root, "Hamburg", NULL, NULL, &newkey); + error = reg_key_add_name(rctx, root, "Polen", NULL, NULL, &newkey); torture_assert_werr_ok(tctx, error, "Creating key return code"); torture_assert(tctx, newkey != NULL, "Creating new key"); - error = reg_key_del(root, "Hamburg"); + error = reg_key_del(root, "Polen"); torture_assert_werr_ok(tctx, error, "Delete key"); - error = reg_key_del(root, "Hamburg"); + error = reg_key_del(root, "Polen"); torture_assert_werr_equal(tctx, error, WERR_NOT_FOUND, "Delete missing key"); @@ -239,7 +239,7 @@ static bool test_flush_key(struct torture_context *tctx, void *_data) struct registry_key *root, *subkey; WERROR error; - if (!create_test_key(tctx, rctx, "Munchen", &root, &subkey)) + if (!create_test_key(tctx, rctx, "Bremen", &root, &subkey)) return false; error = reg_key_flush(subkey); @@ -416,7 +416,7 @@ static bool test_get_value(struct torture_context *tctx, void *_data) error = reg_key_get_value_by_name(tctx, subkey, __FUNCTION__, &type, &data); - torture_assert_werr_equal(tctx, error, WERR_NOT_FOUND, + torture_assert_werr_equal(tctx, error, WERR_BADFILE, "getting missing value"); error = reg_val_set(subkey, __FUNCTION__, REG_DWORD, @@ -447,12 +447,12 @@ static bool test_del_value(struct torture_context *tctx, void *_data) uint32_t value = 42; uint32_t type; - if (!create_test_key(tctx, rctx, "Duisburg", &root, &subkey)) + if (!create_test_key(tctx, rctx, "Warschau", &root, &subkey)) return false; error = reg_key_get_value_by_name(tctx, subkey, __FUNCTION__, &type, &data); - torture_assert_werr_equal(tctx, error, WERR_NOT_FOUND, + torture_assert_werr_equal(tctx, error, WERR_BADFILE, "getting missing value"); error = reg_val_set(subkey, __FUNCTION__, REG_DWORD, @@ -464,7 +464,7 @@ static bool test_del_value(struct torture_context *tctx, void *_data) error = reg_key_get_value_by_name(tctx, subkey, __FUNCTION__, &type, &data); - torture_assert_werr_equal(tctx, error, WERR_NOT_FOUND, + torture_assert_werr_equal(tctx, error, WERR_BADFILE, "getting missing value"); return true; -- cgit From b5ba4910120e5350e48927cc0f5f06742ee02eb8 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 18 Jan 2008 03:00:00 +0100 Subject: registry: Avoid mapping registry return codes: return the right value in the first place. (This used to be commit 434e4857cec17d6d9e8983e151c170eed59fc6d1) --- source4/lib/registry/tests/registry.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/registry/tests') diff --git a/source4/lib/registry/tests/registry.c b/source4/lib/registry/tests/registry.c index 59e31f55dc..06783e6a75 100644 --- a/source4/lib/registry/tests/registry.c +++ b/source4/lib/registry/tests/registry.c @@ -53,7 +53,7 @@ static bool test_get_predefined_unknown(struct torture_context *tctx, WERROR error; error = reg_get_predefined_key(rctx, 1337, &root); - torture_assert_werr_equal(tctx, error, WERR_NOT_FOUND, + torture_assert_werr_equal(tctx, error, WERR_BADFILE, "getting predefined key failed"); return true; } -- cgit From 55ad09a01b31f2d2c9503f744b519e089f9f936b Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 18 Jan 2008 03:37:06 +0100 Subject: registry: Use correct return values. (This used to be commit 98ebdbe52fd615ea62a3caa17acfe8bb31b8f85d) --- source4/lib/registry/tests/hive.c | 6 +++--- source4/lib/registry/tests/registry.c | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'source4/lib/registry/tests') diff --git a/source4/lib/registry/tests/hive.c b/source4/lib/registry/tests/hive.c index f72b7d6bf3..4d27e83a74 100644 --- a/source4/lib/registry/tests/hive.c +++ b/source4/lib/registry/tests/hive.c @@ -31,7 +31,7 @@ static bool test_del_nonexistant_key(struct torture_context *tctx, { const struct hive_key *root = (const struct hive_key *)test_data; WERROR error = hive_key_del(root, "bla"); - torture_assert_werr_equal(tctx, error, WERR_NOT_FOUND, + torture_assert_werr_equal(tctx, error, WERR_BADFILE, "invalid return code"); return true; @@ -134,7 +134,7 @@ static bool test_del_key(struct torture_context *tctx, const void *test_data) torture_assert_werr_ok(tctx, error, "reg_key_del"); error = hive_key_del(root, "Nested Key"); - torture_assert_werr_equal(tctx, error, WERR_NOT_FOUND, "reg_key_del"); + torture_assert_werr_equal(tctx, error, WERR_BADFILE, "reg_key_del"); return true; } @@ -218,7 +218,7 @@ static bool test_del_value(struct torture_context *tctx, const void *test_data) torture_assert_werr_equal(tctx, error, WERR_BADFILE, "getting value"); error = hive_key_del_value(subkey, "Answer"); - torture_assert_werr_equal(tctx, error, WERR_NOT_FOUND, + torture_assert_werr_equal(tctx, error, WERR_BADFILE, "deleting value"); return true; diff --git a/source4/lib/registry/tests/registry.c b/source4/lib/registry/tests/registry.c index 06783e6a75..7d14b3a412 100644 --- a/source4/lib/registry/tests/registry.c +++ b/source4/lib/registry/tests/registry.c @@ -204,7 +204,7 @@ static bool test_del_key(struct torture_context *tctx, void *_data) torture_assert_werr_ok(tctx, error, "Delete key"); error = reg_key_del(root, "Polen"); - torture_assert_werr_equal(tctx, error, WERR_NOT_FOUND, + torture_assert_werr_equal(tctx, error, WERR_BADFILE, "Delete missing key"); return true; -- cgit From 48307b54f95395fbd201d92d738b482f80cd15ef Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 21 Feb 2008 16:01:19 +0100 Subject: Remove more uses of global_loadparm. (This used to be commit 3430cc60972b94d0d238bc39f473feed96949c5d) --- source4/lib/registry/tests/generic.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'source4/lib/registry/tests') diff --git a/source4/lib/registry/tests/generic.c b/source4/lib/registry/tests/generic.c index 25a89793bd..145e599504 100644 --- a/source4/lib/registry/tests/generic.c +++ b/source4/lib/registry/tests/generic.c @@ -45,7 +45,7 @@ static bool test_reg_val_data_string_dword(struct torture_context *ctx) uint32_t d = 0x20; DATA_BLOB db = { (uint8_t *)&d, sizeof(d) }; torture_assert_str_equal(ctx, "0x20", - reg_val_data_string(ctx, REG_DWORD, db), + reg_val_data_string(ctx, lp_iconv_convenience(ctx->lp_ctx), REG_DWORD, db), "dword failed"); return true; } @@ -56,11 +56,11 @@ static bool test_reg_val_data_string_sz(struct torture_context *ctx) db.length = convert_string_talloc(ctx, lp_iconv_convenience(ctx->lp_ctx), CH_UNIX, CH_UTF16, "bla", 3, (void **)&db.data); torture_assert_str_equal(ctx, "bla", - reg_val_data_string(ctx, REG_SZ, db), + reg_val_data_string(ctx, lp_iconv_convenience(ctx->lp_ctx), REG_SZ, db), "sz failed"); db.length = 4; torture_assert_str_equal(ctx, "bl", - reg_val_data_string(ctx, REG_SZ, db), + reg_val_data_string(ctx, lp_iconv_convenience(ctx->lp_ctx), REG_SZ, db), "sz failed"); return true; } @@ -70,7 +70,7 @@ static bool test_reg_val_data_string_binary(struct torture_context *ctx) uint8_t x[] = { 0x1, 0x2, 0x3, 0x4 }; DATA_BLOB db = { x, 4 }; torture_assert_str_equal(ctx, "01020304", - reg_val_data_string(ctx, REG_BINARY, db), + reg_val_data_string(ctx, lp_iconv_convenience(ctx->lp_ctx), REG_BINARY, db), "binary failed"); return true; } @@ -80,7 +80,7 @@ static bool test_reg_val_data_string_empty(struct torture_context *ctx) { DATA_BLOB db = { NULL, 0 }; torture_assert_str_equal(ctx, "", - reg_val_data_string(ctx, REG_BINARY, db), + reg_val_data_string(ctx, lp_iconv_convenience(ctx->lp_ctx), REG_BINARY, db), "empty failed"); return true; } @@ -93,7 +93,7 @@ static bool test_reg_val_description(struct torture_context *ctx) strlen("stationary traveller"), (void **)&data.data); torture_assert_str_equal(ctx, "camel = REG_SZ : stationary traveller", - reg_val_description(ctx, "camel", REG_SZ, data), + reg_val_description(ctx, lp_iconv_convenience(ctx->lp_ctx), "camel", REG_SZ, data), "reg_val_description failed"); return true; } @@ -107,7 +107,7 @@ static bool test_reg_val_description_nullname(struct torture_context *ctx) strlen("west berlin"), (void **)&data.data); torture_assert_str_equal(ctx, " = REG_SZ : west berlin", - reg_val_description(ctx, NULL, REG_SZ, data), + reg_val_description(ctx, lp_iconv_convenience(ctx->lp_ctx), NULL, REG_SZ, data), "description with null name failed"); return true; } -- cgit From c38c2765d1059b33f044a42c6555f3d10d339911 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 21 Feb 2008 17:17:37 +0100 Subject: Remove yet more uses of global_loadparm. (This used to be commit e01c1e87c0fe9709df7eb5b863f7ce85564174cd) --- source4/lib/registry/tests/hive.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'source4/lib/registry/tests') diff --git a/source4/lib/registry/tests/hive.c b/source4/lib/registry/tests/hive.c index 4d27e83a74..1dcb464d80 100644 --- a/source4/lib/registry/tests/hive.c +++ b/source4/lib/registry/tests/hive.c @@ -25,6 +25,7 @@ #include "torture/torture.h" #include "librpc/gen_ndr/winreg.h" #include "system/filesys.h" +#include "param/param.h" static bool test_del_nonexistant_key(struct torture_context *tctx, const void *test_data) @@ -349,7 +350,8 @@ static bool hive_setup_regf(struct torture_context *tctx, void **data) rmdir(dirname); - error = reg_create_regf_file(tctx, dirname, 5, &key); + error = reg_create_regf_file(tctx, lp_iconv_convenience(tctx->lp_ctx), + dirname, 5, &key); if (!W_ERROR_IS_OK(error)) { fprintf(stderr, "Unable to create new regf file\n"); return false; -- cgit From a13395c8731db614e543e60d3da67873c3164ea2 Mon Sep 17 00:00:00 2001 From: Andrew Kroeger Date: Sat, 16 Feb 2008 15:21:26 -0600 Subject: registry: Add an explicit test for recursive deletion. (This used to be commit 5e905804993df4c2ac28090d056e6db6bb63ac44) --- source4/lib/registry/tests/hive.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'source4/lib/registry/tests') diff --git a/source4/lib/registry/tests/hive.c b/source4/lib/registry/tests/hive.c index 4d27e83a74..915782694f 100644 --- a/source4/lib/registry/tests/hive.c +++ b/source4/lib/registry/tests/hive.c @@ -110,6 +110,38 @@ static bool test_add_subkey(struct torture_context *tctx, return true; } +static bool test_del_recursive(struct torture_context *tctx, + const void *test_data) +{ + WERROR error; + struct hive_key *subkey; + struct hive_key *subkey2; + const struct hive_key *root = (const struct hive_key *)test_data; + TALLOC_CTX *mem_ctx = tctx; + uint32_t data = 42; + + /* Create a new key under the root */ + error = hive_key_add_name(mem_ctx, root, "Parent Key", NULL, + NULL, &subkey); + torture_assert_werr_ok(tctx, error, "hive_key_add_name"); + + /* Create a new key under "Parent Key" */ + error = hive_key_add_name(mem_ctx, subkey, "Child Key", NULL, + NULL, &subkey2); + torture_assert_werr_ok(tctx, error, "hive_key_add_name"); + + /* Create a new value under "Child Key" */ + error = hive_key_set_value(subkey2, "Answer Recursive", REG_DWORD, + data_blob_talloc(mem_ctx, &data, sizeof(data))); + torture_assert_werr_ok(tctx, error, "hive_key_set_value"); + + /* Deleting "Parent Key" will also delete "Child Key" and the value. */ + error = hive_key_del(root, "Parent Key"); + torture_assert_werr_ok(tctx, error, "hive_key_del"); + + return true; +} + static bool test_flush_key(struct torture_context *tctx, void *test_data) { struct hive_key *root = (struct hive_key *)test_data; @@ -272,6 +304,11 @@ static void tcase_add_tests(struct torture_tcase *tcase) test_add_subkey); torture_tcase_add_simple_test(tcase, "flush_key", test_flush_key); + /* test_del_recursive() test must run before test_keyinfo_root(). + test_keyinfo_root() checks the number of subkeys, which verifies + the recursive delete worked properly. */ + torture_tcase_add_simple_test_const(tcase, "del_recursive", + test_del_recursive); torture_tcase_add_simple_test_const(tcase, "get_info", test_keyinfo_root); torture_tcase_add_simple_test(tcase, "get_info_nums", -- cgit From 8f8c56bfbcbfe8f80afb09eb1d481a108b252bee Mon Sep 17 00:00:00 2001 From: Andrew Kroeger Date: Fri, 28 Mar 2008 01:08:49 -0500 Subject: Convert some more files to GPLv3. (This used to be commit ebe5e8399422eb7e2ff4deb546338823e2718907) --- source4/lib/registry/tests/hive.c | 2 +- source4/lib/registry/tests/registry.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/lib/registry/tests') diff --git a/source4/lib/registry/tests/hive.c b/source4/lib/registry/tests/hive.c index 1e56f125c5..70b0241b04 100644 --- a/source4/lib/registry/tests/hive.c +++ b/source4/lib/registry/tests/hive.c @@ -7,7 +7,7 @@ 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 2 of the License, or + 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, diff --git a/source4/lib/registry/tests/registry.c b/source4/lib/registry/tests/registry.c index 7d14b3a412..e5e34c11e0 100644 --- a/source4/lib/registry/tests/registry.c +++ b/source4/lib/registry/tests/registry.c @@ -7,7 +7,7 @@ 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 2 of the License, or + 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, -- cgit From afe3e8172ddaa5e4aa811faceecda4f943d6e2ef Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 2 Apr 2008 04:53:27 +0200 Subject: Install public header files again and include required prototypes. (This used to be commit 47ffbbf67435904754469544390b67d34c958343) --- source4/lib/registry/tests/generic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/registry/tests') diff --git a/source4/lib/registry/tests/generic.c b/source4/lib/registry/tests/generic.c index 145e599504..6eae26bc46 100644 --- a/source4/lib/registry/tests/generic.c +++ b/source4/lib/registry/tests/generic.c @@ -112,7 +112,7 @@ static bool test_reg_val_description_nullname(struct torture_context *ctx) return true; } -_PUBLIC_ struct torture_suite *torture_registry(TALLOC_CTX *mem_ctx) +struct torture_suite *torture_registry(TALLOC_CTX *mem_ctx) { struct torture_suite *suite = torture_suite_create(mem_ctx, "REGISTRY"); torture_suite_add_simple_test(suite, "str_regtype", -- cgit From 225a65da2d3c675dba8bd2330dd56f949e21fa4b Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 13 Apr 2008 21:31:06 +0200 Subject: Attempt to fix get_value() test on sparc machines. (This used to be commit 10102d80d0f78777a69f6b3b1e5606d7d56b7254) --- source4/lib/registry/tests/hive.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/registry/tests') diff --git a/source4/lib/registry/tests/hive.c b/source4/lib/registry/tests/hive.c index 70b0241b04..a16736c761 100644 --- a/source4/lib/registry/tests/hive.c +++ b/source4/lib/registry/tests/hive.c @@ -220,7 +220,7 @@ static bool test_get_value(struct torture_context *tctx, const void *test_data) torture_assert_int_equal(tctx, value.length, 4, "value length"); torture_assert_int_equal(tctx, type, REG_DWORD, "value type"); - torture_assert_int_equal(tctx, data, IVAL(value.data, 0), + torture_assert_mem_equal(tctx, &data, value.data, sizeof(uint32_t), "value data"); return true; -- cgit From ae553dfcecdd605658dea73ccb6e577b059f478c Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 13 Apr 2008 21:33:59 +0200 Subject: Use new torture_assert_mem_equal. (This used to be commit b6319b64d7ef9c58f771f338317d4d525d39a8f2) --- source4/lib/registry/tests/registry.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/registry/tests') diff --git a/source4/lib/registry/tests/registry.c b/source4/lib/registry/tests/registry.c index e5e34c11e0..1780b4e772 100644 --- a/source4/lib/registry/tests/registry.c +++ b/source4/lib/registry/tests/registry.c @@ -428,7 +428,7 @@ static bool test_get_value(struct torture_context *tctx, void *_data) torture_assert_werr_ok(tctx, error, "getting value"); torture_assert_int_equal(tctx, 4, data.length, "value length ok"); - torture_assert(tctx, memcmp(data.data, &value, 4) == 0, + torture_assert_mem_equal(tctx, data.data, &value, 4, "value content ok"); torture_assert_int_equal(tctx, REG_DWORD, type, "value type"); -- cgit From 148d3b170ae00d4001fa011450c7238052d32ae2 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 13 Apr 2008 22:00:36 +0200 Subject: Use torture_assert_mem_equal() in a couple more places. (This used to be commit e2c3fab9d1bf0482c15a115e7d373562ffe50b29) --- source4/lib/registry/tests/registry.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/registry/tests') diff --git a/source4/lib/registry/tests/registry.c b/source4/lib/registry/tests/registry.c index 1780b4e772..b19a6abffb 100644 --- a/source4/lib/registry/tests/registry.c +++ b/source4/lib/registry/tests/registry.c @@ -496,7 +496,7 @@ static bool test_list_values(struct torture_context *tctx, void *_data) torture_assert_str_equal(tctx, name, "bar", "value name"); torture_assert_int_equal(tctx, 4, data.length, "value length"); - torture_assert(tctx, memcmp(data.data, &value, 4) == 0, + torture_assert_mem_equal(tctx, data.data, &value, 4, "value content"); torture_assert_int_equal(tctx, REG_DWORD, type, "value type"); -- cgit From 12147fca2b3acd37eb20db82996714320cd4e9b2 Mon Sep 17 00:00:00 2001 From: Wilco Baan Hofman Date: Mon, 14 Apr 2008 22:52:51 +0200 Subject: Add support for security descriptors. Also patched the regf backend to support this. Did not touch the ldb, dir and rpc backends yet. (This used to be commit c4626f21a898da27a051f2c67f8fd73f55d4fc7d) --- source4/lib/registry/tests/hive.c | 56 ++++++++++++++++++++++++++++++++++- source4/lib/registry/tests/registry.c | 8 ++--- 2 files changed, 59 insertions(+), 5 deletions(-) (limited to 'source4/lib/registry/tests') diff --git a/source4/lib/registry/tests/hive.c b/source4/lib/registry/tests/hive.c index a16736c761..4fe7f66c03 100644 --- a/source4/lib/registry/tests/hive.c +++ b/source4/lib/registry/tests/hive.c @@ -26,6 +26,7 @@ #include "librpc/gen_ndr/winreg.h" #include "system/filesys.h" #include "param/param.h" +#include "libcli/security/security.h" static bool test_del_nonexistant_key(struct torture_context *tctx, const void *test_data) @@ -297,6 +298,57 @@ static bool test_list_values(struct torture_context *tctx, return true; } +static bool test_hive_security(struct torture_context *tctx, const void *_data) +{ + struct hive_key *subkey = NULL; + const struct hive_key *root = _data; + WERROR error; + struct security_descriptor *osd, *nsd; + + osd = security_descriptor_dacl_create(tctx, + 0, + NULL, NULL, + SID_NT_AUTHENTICATED_USERS, + SEC_ACE_TYPE_ACCESS_ALLOWED, + SEC_GENERIC_ALL, + SEC_ACE_FLAG_OBJECT_INHERIT, + NULL); + + + error = hive_key_add_name(tctx, root, "SecurityKey", NULL, + osd, &subkey); + torture_assert_werr_ok(tctx, error, "hive_key_add_name"); + + error = hive_get_sec_desc(tctx, subkey, &nsd); + torture_assert_werr_ok (tctx, error, "getting security descriptor"); + + torture_assert(tctx, security_descriptor_equal(osd, nsd), + "security descriptor changed!"); + + /* Create a fresh security descriptor */ + talloc_free(osd); + osd = security_descriptor_dacl_create(tctx, + 0, + NULL, NULL, + SID_NT_AUTHENTICATED_USERS, + SEC_ACE_TYPE_ACCESS_ALLOWED, + SEC_GENERIC_ALL, + SEC_ACE_FLAG_OBJECT_INHERIT, + NULL); + + error = hive_set_sec_desc(subkey, osd); + torture_assert_werr_ok(tctx, error, "setting security descriptor"); + + printf("The second one is done.\n"); + error = hive_get_sec_desc(tctx, subkey, &nsd); + torture_assert_werr_ok (tctx, error, "getting security descriptor"); + + torture_assert(tctx, security_descriptor_equal(osd, nsd), + "security descriptor changed!"); + + return true; +} + static void tcase_add_tests(struct torture_tcase *tcase) { torture_tcase_add_simple_test_const(tcase, "del_nonexistant_key", @@ -324,6 +376,8 @@ static void tcase_add_tests(struct torture_tcase *tcase) test_del_key); torture_tcase_add_simple_test_const(tcase, "del_value", test_del_value); + torture_tcase_add_simple_test_const(tcase, "check hive security", + test_hive_security); } static bool hive_setup_dir(struct torture_context *tctx, void **data) @@ -381,7 +435,7 @@ static bool hive_setup_regf(struct torture_context *tctx, void **data) char *dirname; NTSTATUS status; - status = torture_temp_dir(tctx, "hive-dir", &dirname); + status = torture_temp_dir(tctx, "hive-regf", &dirname); if (!NT_STATUS_IS_OK(status)) return false; diff --git a/source4/lib/registry/tests/registry.c b/source4/lib/registry/tests/registry.c index b19a6abffb..97c1190a68 100644 --- a/source4/lib/registry/tests/registry.c +++ b/source4/lib/registry/tests/registry.c @@ -387,11 +387,11 @@ static bool test_security(struct torture_context *tctx, void *_data) SEC_ACE_FLAG_OBJECT_INHERIT, NULL); - error = reg_set_security(subkey, osd); - torture_assert_werr_ok(tctx, error, "setting security"); + error = reg_set_sec_desc(subkey, osd); + torture_assert_werr_ok(tctx, error, "setting security descriptor"); - error = reg_get_security(tctx, subkey, &nsd); - torture_assert_werr_ok (tctx, error, "setting security"); + error = reg_get_sec_desc(tctx, subkey, &nsd); + torture_assert_werr_ok (tctx, error, "getting security descriptor"); torture_assert(tctx, security_descriptor_equal(osd, nsd), "security descriptor changed!"); -- cgit From a31b6607f22f6b3e1b354db2f9f611b299a2f7ae Mon Sep 17 00:00:00 2001 From: Wilco Baan Hofman Date: Mon, 14 Apr 2008 22:56:14 +0200 Subject: Remove debug stuff. (This used to be commit 7ba2e5dc5b6d82457c298f7ecdb6baea43f04854) --- source4/lib/registry/tests/hive.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source4/lib/registry/tests') diff --git a/source4/lib/registry/tests/hive.c b/source4/lib/registry/tests/hive.c index 4fe7f66c03..474704b517 100644 --- a/source4/lib/registry/tests/hive.c +++ b/source4/lib/registry/tests/hive.c @@ -339,7 +339,6 @@ static bool test_hive_security(struct torture_context *tctx, const void *_data) error = hive_set_sec_desc(subkey, osd); torture_assert_werr_ok(tctx, error, "setting security descriptor"); - printf("The second one is done.\n"); error = hive_get_sec_desc(tctx, subkey, &nsd); torture_assert_werr_ok (tctx, error, "getting security descriptor"); -- cgit From 0b8d2b3cb779463a1e24039300ac2669862f9b64 Mon Sep 17 00:00:00 2001 From: Wilco Baan Hofman Date: Tue, 15 Apr 2008 11:52:33 +0200 Subject: Fixed the patchfile tests and tidy up the patchfile backends. (This used to be commit 6e9b1e35a269af2eda79356c1525f5413656d648) --- source4/lib/registry/tests/diff.c | 232 ++++++++++++++++++++++++++++++++++---- 1 file changed, 211 insertions(+), 21 deletions(-) (limited to 'source4/lib/registry/tests') diff --git a/source4/lib/registry/tests/diff.c b/source4/lib/registry/tests/diff.c index 690f71fcf7..da62342124 100644 --- a/source4/lib/registry/tests/diff.c +++ b/source4/lib/registry/tests/diff.c @@ -4,6 +4,7 @@ local testing of registry diff functionality Copyright (C) Jelmer Vernooij 2007 + Copyright (C) Wilco Baan Hofman 2008 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 @@ -24,27 +25,79 @@ #include "torture/torture.h" #include "librpc/gen_ndr/winreg.h" -static bool test_generate_diff(struct torture_context *test) +struct diff_tcase_data { + struct registry_context *r1_ctx; + struct registry_context *r2_ctx; + struct reg_diff_callbacks *callbacks; + void *callback_data; + char *tempdir; + char *filename; +}; + +static bool test_generate_diff(struct torture_context *tctx, void *tcase_data) { /* WERROR reg_generate_diff(struct registry_context *ctx1, struct registry_context *ctx2, const struct reg_diff_callbacks *callbacks, void *callback_data) */ + WERROR error; + struct diff_tcase_data *td = tcase_data; + + error = reg_generate_diff(td->r1_ctx, td->r2_ctx, + td->callbacks, + td->callback_data); + torture_assert_werr_ok(tctx, error, "reg_generate_diff"); + return true; } - -static bool test_diff_load(struct torture_context *test) +#if 0 +static bool test_diff_load(struct torture_context *tctx, void *tcase_data) { - /* WERROR reg_diff_load(const char *filename, const struct reg_diff_callbacks *callbacks, void *callback_data) */ + struct diff_tcase_data *td = tcase_data; + struct smb_iconv_convenience *iconv_convenience; + struct reg_diff_callbacks *callbacks; + void *data; + WERROR error; + + iconv_convenience = smb_iconv_convenience_init(tctx, "CP850", "UTF-8", 1); + + + error = reg_diff_load(td->filename, iconv_convenience, callbacks, data); + torture_assert_werr_ok(tctx, error, "reg_diff_load"); return true; } - -static bool test_diff_apply(struct torture_context *test) +#endif +static bool test_diff_apply(struct torture_context *tctx, void *tcase_data) { - /* _PUBLIC_ WERROR reg_diff_apply (const char *filename, struct registry_context *ctx) */ + struct diff_tcase_data *td = tcase_data; + struct registry_key *key; + WERROR error; + + error = reg_diff_apply(td->r1_ctx, td->filename); + torture_assert_werr_ok(tctx, error, "reg_diff_apply"); + + error = td->r1_ctx->ops->get_predefined_key(td->r1_ctx, HKEY_LOCAL_MACHINE, &key); + torture_assert_werr_ok(tctx, error, "Opening HKEY_LOCAL_MACHINE failed"); + + /* If this generates an error it could be that the apply doesn't work, + * but also that the reg_generate_diff didn't work. */ + error = td->r1_ctx->ops->open_key(td->r1_ctx, key, "Software", &key); + torture_assert_werr_ok(tctx, error, "Opening HKLM\\Software failed"); + error = td->r1_ctx->ops->open_key(td->r1_ctx, key, "Microsoft", &key); + torture_assert_werr_ok(tctx, error, "Opening HKLM\\Software\\Microsoft failed"); + error = td->r1_ctx->ops->open_key(td->r1_ctx, key, "Windows", &key); + torture_assert_werr_ok(tctx, error, "Opening HKLM\\..\\Microsoft\\Windows failed"); + error = td->r1_ctx->ops->open_key(td->r1_ctx, key, "CurrentVersion", &key); + torture_assert_werr_ok(tctx, error, "Opening HKLM\\..\\Windows\\CurrentVersion failed"); + error = td->r1_ctx->ops->open_key(td->r1_ctx, key, "Policies", &key); + torture_assert_werr_ok(tctx, error, "Opening HKLM\\..\\CurrentVersion\\Policies failed"); + error = td->r1_ctx->ops->open_key(td->r1_ctx, key, "Explorer", &key); + torture_assert_werr_ok(tctx, error, "Opening HKLM\\..\\Policies\\Explorer failed"); + + return true; } @@ -58,7 +111,7 @@ static WERROR test_add_key(void *callback_data, const char *key_name) return WERR_OK; } -static bool test_generate_diff_key_add(struct torture_context *test) +static bool test_generate_diff_key_add(struct torture_context *tctx, void *tcase_data) { struct reg_diff_callbacks cb; struct registry_key rk; @@ -69,15 +122,15 @@ static bool test_generate_diff_key_add(struct torture_context *test) cb.add_key = test_add_key; - if (W_ERROR_IS_OK(reg_generate_diff_key(&rk, NULL, "bla", &cb, test))) + if (W_ERROR_IS_OK(reg_generate_diff_key(&rk, NULL, "bla", &cb, tctx))) return false; - torture_assert_str_equal(test, added_key, "bla", "key added"); + torture_assert_str_equal(tctx, added_key, "bla", "key added"); return true; } -static bool test_generate_diff_key_null(struct torture_context *test) +static bool test_generate_diff_key_null(struct torture_context *tctx, void *tcase_data) { struct reg_diff_callbacks cb; @@ -88,19 +141,156 @@ static bool test_generate_diff_key_null(struct torture_context *test) return true; } +static void tcase_add_tests (struct torture_tcase *tcase) +{ + torture_tcase_add_simple_test(tcase, "test_generate_diff_key_add", + test_generate_diff_key_add); + torture_tcase_add_simple_test(tcase, "test_generate_diff_key_null", + test_generate_diff_key_null); + torture_tcase_add_simple_test(tcase, "test_generate_diff", + test_generate_diff); + torture_tcase_add_simple_test(tcase, "test_diff_apply", + test_diff_apply); +/* torture_tcase_add_simple_test(tcase, "test_diff_load", + test_diff_load); +*/ +} + +static bool diff_setup_tcase(struct torture_context *tctx, void **data) +{ + struct registry_context *r1_ctx, *r2_ctx; + WERROR error; + NTSTATUS status; + struct hive_key *r1_hklm, *r1_hkcu; + struct hive_key *r2_hklm, *r2_hkcu; + const char *filename; + struct diff_tcase_data *td; + struct registry_key *key, *newkey; + DATA_BLOB blob; + + td = talloc(tctx, struct diff_tcase_data); + + /* Create two registry contexts */ + error = reg_open_local(tctx, &r1_ctx, NULL, NULL); + torture_assert_werr_ok(tctx, error, "Opening registry 1 for patch tests failed"); + + error = reg_open_local(tctx, &r2_ctx, NULL, NULL); + torture_assert_werr_ok(tctx, error, "Opening registry 2 for patch tests failed"); + + /* Create temp directory */ + status = torture_temp_dir(tctx, "patchfile", &td->tempdir); + torture_assert_ntstatus_ok(tctx, status, "Creating temp dir failed"); + + /* Create and mount HKLM and HKCU hives for registry 1 */ + filename = talloc_asprintf(tctx, "%s/r1_local_machine.ldb", td->tempdir); + error = reg_open_ldb_file(tctx, filename, NULL, NULL, tctx->lp_ctx, &r1_hklm); + torture_assert_werr_ok(tctx, error, "Opening local machine file failed"); + + error = reg_mount_hive(r1_ctx, r1_hklm, HKEY_LOCAL_MACHINE, NULL); + torture_assert_werr_ok(tctx, error, "Mounting hive failed"); + + filename = talloc_asprintf(tctx, "%s/r1_current_user.ldb", td->tempdir); + error = reg_open_ldb_file(tctx, filename, NULL, NULL, tctx->lp_ctx, &r1_hkcu); + torture_assert_werr_ok(tctx, error, "Opening current user file failed"); + + error = reg_mount_hive(r1_ctx, r1_hkcu, HKEY_CURRENT_USER, NULL); + torture_assert_werr_ok(tctx, error, "Mounting hive failed"); + + /* Create and mount HKLM and HKCU hives for registry 2 */ + filename = talloc_asprintf(tctx, "%s/r2_local_machine.ldb", td->tempdir); + error = reg_open_ldb_file(tctx, filename, NULL, NULL, tctx->lp_ctx, &r2_hklm); + torture_assert_werr_ok(tctx, error, "Opening local machine file failed"); + + error = reg_mount_hive(r2_ctx, r2_hklm, HKEY_LOCAL_MACHINE, NULL); + torture_assert_werr_ok(tctx, error, "Mounting hive failed"); + + filename = talloc_asprintf(tctx, "%s/r2_current_user.ldb", td->tempdir); + error = reg_open_ldb_file(tctx, filename, NULL, NULL, tctx->lp_ctx, &r2_hkcu); + torture_assert_werr_ok(tctx, error, "Opening current user file failed"); + + error = reg_mount_hive(r2_ctx, r2_hkcu, HKEY_CURRENT_USER, NULL); + torture_assert_werr_ok(tctx, error, "Mounting hive failed"); + + error = r1_ctx->ops->get_predefined_key(r2_ctx, HKEY_LOCAL_MACHINE, &key); + torture_assert_werr_ok(tctx, error, "Opening HKEY_LOCAL_MACHINE failed"); + error = r1_ctx->ops->create_key(r2_ctx, key, "Software", NULL, NULL, &newkey); + torture_assert_werr_ok(tctx, error, "Creating HKLM\\Sofware failed"); + error = r1_ctx->ops->create_key(r2_ctx, newkey, "Microsoft", NULL, NULL, &newkey); + torture_assert_werr_ok(tctx, error, "Creating HKLM\\Software\\Microsoft failed"); + error = r1_ctx->ops->create_key(r2_ctx, newkey, "Windows", NULL, NULL, &newkey); + torture_assert_werr_ok(tctx, error, "Creating HKLM\\Software\\Microsoft\\Windows failed"); + error = r1_ctx->ops->create_key(r2_ctx, newkey, "CurrentVersion", NULL, NULL, &newkey); + torture_assert_werr_ok(tctx, error, "Creating HKLM\\..\\Windows\\CurrentVersion failed"); + error = r1_ctx->ops->create_key(r2_ctx, newkey, "Policies", NULL, NULL, &newkey); + torture_assert_werr_ok(tctx, error, "Creating HKLM\\..\\CurrentVersion\\Policies failed"); + error = r1_ctx->ops->create_key(r2_ctx, newkey, "Explorer", NULL, NULL, &newkey); + torture_assert_werr_ok(tctx, error, "Creating HKLM\\..\\Policies\\Explorer failed"); + + blob.data = (void *)talloc(r2_ctx, uint32_t); + SIVAL(blob.data, 0, 0x03ffffff); + blob.length = sizeof(uint32_t); + r1_ctx->ops->set_value(newkey, "NoDrives", REG_DWORD, blob); + + /* Set test case data */ + td->r1_ctx = r1_ctx; + td->r2_ctx = r2_ctx; + + *data = td; + + return true; +} + +static bool diff_setup_preg_tcase (struct torture_context *tctx, void **data) +{ + struct diff_tcase_data *td; + WERROR error; + + diff_setup_tcase(tctx, data); + td = *data; + + td->filename = talloc_asprintf(tctx, "%s/test.pol", td->tempdir); + error = reg_preg_diff_save(tctx, td->filename, &td->callbacks, &td->callback_data); + torture_assert_werr_ok(tctx, error, "reg_preg_diff_save"); + + return true; +} + +static bool diff_setup_dotreg_tcase (struct torture_context *tctx, void **data) +{ + struct diff_tcase_data *td; + struct smb_iconv_convenience *iconv_convenience; + WERROR error; + + diff_setup_tcase(tctx, data); + td = *data; + + iconv_convenience = smb_iconv_convenience_init(tctx, "CP850", "UTF-8", 1); + + td->filename = talloc_asprintf(tctx, "%s/test.reg", td->tempdir); + error = reg_dotreg_diff_save(tctx, td->filename, iconv_convenience, &td->callbacks, &td->callback_data); + torture_assert_werr_ok(tctx, error, "reg_dotreg_diff_save"); + + return true; +} +static bool diff_teardown_tcase (struct torture_context *tctx, void *data) +{ + /* Done is called by generate_diff itself! */ + + return true; +} struct torture_suite *torture_registry_diff(TALLOC_CTX *mem_ctx) { + struct torture_tcase *tcase; struct torture_suite *suite = torture_suite_create(mem_ctx, "DIFF"); - torture_suite_add_simple_test(suite, "test_generate_diff_key_add", - test_generate_diff_key_add); - torture_suite_add_simple_test(suite, "test_generate_diff_key_null", - test_generate_diff_key_null); - torture_suite_add_simple_test(suite, "test_diff_apply", - test_diff_apply); - torture_suite_add_simple_test(suite, "test_generate_diff", - test_generate_diff); - torture_suite_add_simple_test(suite, "test_diff_load", - test_diff_load); + + tcase = torture_suite_add_tcase(suite, "PReg"); + torture_tcase_set_fixture(tcase, diff_setup_preg_tcase, diff_teardown_tcase); + tcase_add_tests(tcase); + + tcase = torture_suite_add_tcase(suite, "dotreg"); + torture_tcase_set_fixture(tcase, diff_setup_dotreg_tcase, diff_teardown_tcase); + tcase_add_tests(tcase); + return suite; } -- cgit From 5e687d79533684949deb9bd9bc86f88eab4ae310 Mon Sep 17 00:00:00 2001 From: Wilco Baan Hofman Date: Tue, 15 Apr 2008 19:57:29 +0200 Subject: Fix PReg write support. Add tests for patch files (.REG and PReg). (This used to be commit 497977c36c621a4820be51cbcb7b78eac1e292b7) --- source4/lib/registry/tests/diff.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'source4/lib/registry/tests') diff --git a/source4/lib/registry/tests/diff.c b/source4/lib/registry/tests/diff.c index da62342124..4bd868ea51 100644 --- a/source4/lib/registry/tests/diff.c +++ b/source4/lib/registry/tests/diff.c @@ -24,6 +24,7 @@ #include "lib/registry/registry.h" #include "torture/torture.h" #include "librpc/gen_ndr/winreg.h" +#include "param/param.h" struct diff_tcase_data { struct registry_context *r1_ctx; @@ -56,13 +57,12 @@ static bool test_generate_diff(struct torture_context *tctx, void *tcase_data) static bool test_diff_load(struct torture_context *tctx, void *tcase_data) { struct diff_tcase_data *td = tcase_data; - struct smb_iconv_convenience *iconv_convenience; + struct smb_iconv_convenience *ic; struct reg_diff_callbacks *callbacks; void *data; WERROR error; - iconv_convenience = smb_iconv_convenience_init(tctx, "CP850", "UTF-8", 1); - + ic = lp_iconv_convenience(tctx->lp_ctx); error = reg_diff_load(td->filename, iconv_convenience, callbacks, data); torture_assert_werr_ok(tctx, error, "reg_diff_load"); @@ -244,13 +244,16 @@ static bool diff_setup_tcase(struct torture_context *tctx, void **data) static bool diff_setup_preg_tcase (struct torture_context *tctx, void **data) { struct diff_tcase_data *td; + struct smb_iconv_convenience *ic; WERROR error; diff_setup_tcase(tctx, data); td = *data; - + + ic = lp_iconv_convenience(tctx->lp_ctx); + td->filename = talloc_asprintf(tctx, "%s/test.pol", td->tempdir); - error = reg_preg_diff_save(tctx, td->filename, &td->callbacks, &td->callback_data); + error = reg_preg_diff_save(tctx, td->filename, ic, &td->callbacks, &td->callback_data); torture_assert_werr_ok(tctx, error, "reg_preg_diff_save"); return true; @@ -259,16 +262,16 @@ static bool diff_setup_preg_tcase (struct torture_context *tctx, void **data) static bool diff_setup_dotreg_tcase (struct torture_context *tctx, void **data) { struct diff_tcase_data *td; - struct smb_iconv_convenience *iconv_convenience; + struct smb_iconv_convenience *ic; WERROR error; diff_setup_tcase(tctx, data); td = *data; - iconv_convenience = smb_iconv_convenience_init(tctx, "CP850", "UTF-8", 1); + ic = lp_iconv_convenience(tctx->lp_ctx); td->filename = talloc_asprintf(tctx, "%s/test.reg", td->tempdir); - error = reg_dotreg_diff_save(tctx, td->filename, iconv_convenience, &td->callbacks, &td->callback_data); + error = reg_dotreg_diff_save(tctx, td->filename, ic, &td->callbacks, &td->callback_data); torture_assert_werr_ok(tctx, error, "reg_dotreg_diff_save"); return true; -- cgit From 439f75f522d241aa78f06572c47ff6b871289793 Mon Sep 17 00:00:00 2001 From: Wilco Baan Hofman Date: Tue, 15 Apr 2008 21:35:59 +0200 Subject: More patchfile fixes. Write support should work now. (This used to be commit cc38f2f086b92bbe65bd6e7f4e03fdf7f21ef2f6) --- source4/lib/registry/tests/diff.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'source4/lib/registry/tests') diff --git a/source4/lib/registry/tests/diff.c b/source4/lib/registry/tests/diff.c index 4bd868ea51..492f4de0b5 100644 --- a/source4/lib/registry/tests/diff.c +++ b/source4/lib/registry/tests/diff.c @@ -211,21 +211,29 @@ static bool diff_setup_tcase(struct torture_context *tctx, void **data) error = reg_mount_hive(r2_ctx, r2_hkcu, HKEY_CURRENT_USER, NULL); torture_assert_werr_ok(tctx, error, "Mounting hive failed"); - error = r1_ctx->ops->get_predefined_key(r2_ctx, HKEY_LOCAL_MACHINE, &key); + error = r1_ctx->ops->get_predefined_key(r1_ctx, HKEY_CURRENT_USER, &key); + torture_assert_werr_ok(tctx, error, "Opening HKEY_CURRENT_USER failed"); + error = r1_ctx->ops->create_key(r1_ctx, key, "Network", NULL, NULL, &newkey); + torture_assert_werr_ok(tctx, error, "Opening HKCU\\Network failed"); + error = r1_ctx->ops->create_key(r1_ctx, newkey, "L", NULL, NULL, &newkey); + torture_assert_werr_ok(tctx, error, "Opening HKCU\\Network\\L failed"); + + error = r2_ctx->ops->get_predefined_key(r2_ctx, HKEY_LOCAL_MACHINE, &key); torture_assert_werr_ok(tctx, error, "Opening HKEY_LOCAL_MACHINE failed"); - error = r1_ctx->ops->create_key(r2_ctx, key, "Software", NULL, NULL, &newkey); + error = r2_ctx->ops->create_key(r2_ctx, key, "Software", NULL, NULL, &newkey); torture_assert_werr_ok(tctx, error, "Creating HKLM\\Sofware failed"); - error = r1_ctx->ops->create_key(r2_ctx, newkey, "Microsoft", NULL, NULL, &newkey); + error = r2_ctx->ops->create_key(r2_ctx, newkey, "Microsoft", NULL, NULL, &newkey); torture_assert_werr_ok(tctx, error, "Creating HKLM\\Software\\Microsoft failed"); - error = r1_ctx->ops->create_key(r2_ctx, newkey, "Windows", NULL, NULL, &newkey); + error = r2_ctx->ops->create_key(r2_ctx, newkey, "Windows", NULL, NULL, &newkey); torture_assert_werr_ok(tctx, error, "Creating HKLM\\Software\\Microsoft\\Windows failed"); - error = r1_ctx->ops->create_key(r2_ctx, newkey, "CurrentVersion", NULL, NULL, &newkey); + error = r2_ctx->ops->create_key(r2_ctx, newkey, "CurrentVersion", NULL, NULL, &newkey); torture_assert_werr_ok(tctx, error, "Creating HKLM\\..\\Windows\\CurrentVersion failed"); - error = r1_ctx->ops->create_key(r2_ctx, newkey, "Policies", NULL, NULL, &newkey); + error = r2_ctx->ops->create_key(r2_ctx, newkey, "Policies", NULL, NULL, &newkey); torture_assert_werr_ok(tctx, error, "Creating HKLM\\..\\CurrentVersion\\Policies failed"); - error = r1_ctx->ops->create_key(r2_ctx, newkey, "Explorer", NULL, NULL, &newkey); + error = r2_ctx->ops->create_key(r2_ctx, newkey, "Explorer", NULL, NULL, &newkey); torture_assert_werr_ok(tctx, error, "Creating HKLM\\..\\Policies\\Explorer failed"); + blob.data = (void *)talloc(r2_ctx, uint32_t); SIVAL(blob.data, 0, 0x03ffffff); blob.length = sizeof(uint32_t); -- cgit From f01c377bc039b776ded213f455cdb79d682ae7b2 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 15 Apr 2008 22:08:31 +0200 Subject: Fix formatting, remove unused function. (This used to be commit 6ec206ba58777395b2d1251680b21648f4c0f78e) --- source4/lib/registry/tests/diff.c | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) (limited to 'source4/lib/registry/tests') diff --git a/source4/lib/registry/tests/diff.c b/source4/lib/registry/tests/diff.c index 492f4de0b5..c7726545f6 100644 --- a/source4/lib/registry/tests/diff.c +++ b/source4/lib/registry/tests/diff.c @@ -37,11 +37,6 @@ struct diff_tcase_data { static bool test_generate_diff(struct torture_context *tctx, void *tcase_data) { - /* WERROR reg_generate_diff(struct registry_context *ctx1, - struct registry_context *ctx2, - const struct reg_diff_callbacks *callbacks, - void *callback_data) - */ WERROR error; struct diff_tcase_data *td = tcase_data; @@ -97,8 +92,6 @@ static bool test_diff_apply(struct torture_context *tctx, void *tcase_data) error = td->r1_ctx->ops->open_key(td->r1_ctx, key, "Explorer", &key); torture_assert_werr_ok(tctx, error, "Opening HKLM\\..\\Policies\\Explorer failed"); - - return true; } @@ -141,6 +134,7 @@ static bool test_generate_diff_key_null(struct torture_context *tctx, void *tcas return true; } + static void tcase_add_tests (struct torture_tcase *tcase) { torture_tcase_add_simple_test(tcase, "test_generate_diff_key_add", @@ -284,23 +278,18 @@ static bool diff_setup_dotreg_tcase (struct torture_context *tctx, void **data) return true; } -static bool diff_teardown_tcase (struct torture_context *tctx, void *data) -{ - /* Done is called by generate_diff itself! */ - return true; -} struct torture_suite *torture_registry_diff(TALLOC_CTX *mem_ctx) { struct torture_tcase *tcase; struct torture_suite *suite = torture_suite_create(mem_ctx, "DIFF"); tcase = torture_suite_add_tcase(suite, "PReg"); - torture_tcase_set_fixture(tcase, diff_setup_preg_tcase, diff_teardown_tcase); + torture_tcase_set_fixture(tcase, diff_setup_preg_tcase, NULL); tcase_add_tests(tcase); tcase = torture_suite_add_tcase(suite, "dotreg"); - torture_tcase_set_fixture(tcase, diff_setup_dotreg_tcase, diff_teardown_tcase); + torture_tcase_set_fixture(tcase, diff_setup_dotreg_tcase, NULL); tcase_add_tests(tcase); return suite; -- cgit From 2ef07ad551d398c39a595494aaa083a932ef79aa Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 16 Apr 2008 01:32:54 +0200 Subject: Remove unused arguments from reg_open_local(). (This used to be commit fee7ea7080ec40182efc6ffe57b267444eb9389a) --- source4/lib/registry/tests/registry.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/registry/tests') diff --git a/source4/lib/registry/tests/registry.c b/source4/lib/registry/tests/registry.c index b19a6abffb..33512a0c8c 100644 --- a/source4/lib/registry/tests/registry.c +++ b/source4/lib/registry/tests/registry.c @@ -517,7 +517,7 @@ static bool setup_local_registry(struct torture_context *tctx, void **data) struct hive_key *hive_key; const char *filename; - error = reg_open_local(tctx, &rctx, NULL, NULL); + error = reg_open_local(tctx, &rctx); torture_assert_werr_ok(tctx, error, "Opening local registry failed"); status = torture_temp_dir(tctx, "registry-local", &tempdir); -- cgit From 21fc7673780aa1d7c0caab7b17ff9171238913ba Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 17 Apr 2008 12:23:44 +0200 Subject: Specify event_context to ldb_wrap_connect explicitly. (This used to be commit b4e1ae07a284c044704322446c94351c2decff91) --- source4/lib/registry/tests/hive.c | 2 +- source4/lib/registry/tests/registry.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/lib/registry/tests') diff --git a/source4/lib/registry/tests/hive.c b/source4/lib/registry/tests/hive.c index a16736c761..83abdd793d 100644 --- a/source4/lib/registry/tests/hive.c +++ b/source4/lib/registry/tests/hive.c @@ -363,7 +363,7 @@ static bool hive_setup_ldb(struct torture_context *tctx, void **data) rmdir(dirname); - error = reg_open_ldb_file(tctx, dirname, NULL, NULL, tctx->lp_ctx, &key); + error = reg_open_ldb_file(tctx, dirname, NULL, NULL, tctx->ev, tctx->lp_ctx, &key); if (!W_ERROR_IS_OK(error)) { fprintf(stderr, "Unable to initialize ldb hive\n"); return false; diff --git a/source4/lib/registry/tests/registry.c b/source4/lib/registry/tests/registry.c index 33512a0c8c..ec7873a111 100644 --- a/source4/lib/registry/tests/registry.c +++ b/source4/lib/registry/tests/registry.c @@ -524,7 +524,7 @@ static bool setup_local_registry(struct torture_context *tctx, void **data) torture_assert_ntstatus_ok(tctx, status, "Creating temp dir failed"); filename = talloc_asprintf(tctx, "%s/classes_root.ldb", tempdir); - error = reg_open_ldb_file(tctx, filename, NULL, NULL, tctx->lp_ctx, &hive_key); + error = reg_open_ldb_file(tctx, filename, NULL, NULL, tctx->ev, tctx->lp_ctx, &hive_key); torture_assert_werr_ok(tctx, error, "Opening classes_root file failed"); error = reg_mount_hive(rctx, hive_key, HKEY_CLASSES_ROOT, NULL); -- cgit From e739fe91cfdbb7c8a792c4bdc6c5f18603507fc6 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Thu, 17 Apr 2008 15:54:22 +0200 Subject: Fix bug in registry test on big-endian machines. Andrew Bartlett (This used to be commit c74c67c38383b43efd707934e8c457b757e49db1) --- source4/lib/registry/tests/hive.c | 35 ++++++++++++++++++++++------------- source4/lib/registry/tests/registry.c | 16 ++++++++++------ 2 files changed, 32 insertions(+), 19 deletions(-) (limited to 'source4/lib/registry/tests') diff --git a/source4/lib/registry/tests/hive.c b/source4/lib/registry/tests/hive.c index 83abdd793d..29f7e685c1 100644 --- a/source4/lib/registry/tests/hive.c +++ b/source4/lib/registry/tests/hive.c @@ -68,14 +68,15 @@ static bool test_keyinfo_nums(struct torture_context *tctx, void *test_data) struct hive_key *root = (struct hive_key *)test_data; WERROR error; struct hive_key *subkey; - uint32_t data = 42; + char data[4]; + SIVAL(data, 0, 42); error = hive_key_add_name(tctx, root, "Nested Keyll", NULL, NULL, &subkey); torture_assert_werr_ok(tctx, error, "hive_key_add_name"); error = hive_key_set_value(root, "Answer", REG_DWORD, - data_blob_talloc(tctx, &data, sizeof(data))); + data_blob_talloc(tctx, data, sizeof(data))); torture_assert_werr_ok(tctx, error, "hive_key_set_value"); /* This is a new backend. There should be no subkeys and no @@ -119,7 +120,8 @@ static bool test_del_recursive(struct torture_context *tctx, struct hive_key *subkey2; const struct hive_key *root = (const struct hive_key *)test_data; TALLOC_CTX *mem_ctx = tctx; - uint32_t data = 42; + char data[4]; + SIVAL(data, 0, 42); /* Create a new key under the root */ error = hive_key_add_name(mem_ctx, root, "Parent Key", NULL, @@ -133,7 +135,7 @@ static bool test_del_recursive(struct torture_context *tctx, /* Create a new value under "Child Key" */ error = hive_key_set_value(subkey2, "Answer Recursive", REG_DWORD, - data_blob_talloc(mem_ctx, &data, sizeof(data))); + data_blob_talloc(mem_ctx, data, sizeof(data))); torture_assert_werr_ok(tctx, error, "hive_key_set_value"); /* Deleting "Parent Key" will also delete "Child Key" and the value. */ @@ -179,14 +181,15 @@ static bool test_set_value(struct torture_context *tctx, struct hive_key *subkey; const struct hive_key *root = (const struct hive_key *)test_data; TALLOC_CTX *mem_ctx = tctx; - uint32_t data = 42; + char data[4]; + SIVAL(data, 0, 42); error = hive_key_add_name(mem_ctx, root, "YA Nested Key", NULL, NULL, &subkey); torture_assert_werr_ok(tctx, error, "hive_key_add_name"); error = hive_key_set_value(subkey, "Answer", REG_DWORD, - data_blob_talloc(mem_ctx, &data, sizeof(data))); + data_blob_talloc(mem_ctx, data, sizeof(data))); torture_assert_werr_ok(tctx, error, "hive_key_set_value"); return true; @@ -198,10 +201,12 @@ static bool test_get_value(struct torture_context *tctx, const void *test_data) struct hive_key *subkey; const struct hive_key *root = (const struct hive_key *)test_data; TALLOC_CTX *mem_ctx = tctx; - uint32_t data = 42; + char data[4]; uint32_t type; DATA_BLOB value; + SIVAL(data, 0, 42); + error = hive_key_add_name(mem_ctx, root, "EYA Nested Key", NULL, NULL, &subkey); torture_assert_werr_ok(tctx, error, "hive_key_add_name"); @@ -211,7 +216,7 @@ static bool test_get_value(struct torture_context *tctx, const void *test_data) "getting missing value"); error = hive_key_set_value(subkey, "Answer", REG_DWORD, - data_blob_talloc(mem_ctx, &data, sizeof(data))); + data_blob_talloc(mem_ctx, data, sizeof(data))); torture_assert_werr_ok(tctx, error, "hive_key_set_value"); error = hive_get_value(mem_ctx, subkey, "Answer", &type, &value); @@ -232,16 +237,18 @@ static bool test_del_value(struct torture_context *tctx, const void *test_data) struct hive_key *subkey; const struct hive_key *root = (const struct hive_key *)test_data; TALLOC_CTX *mem_ctx = tctx; - uint32_t data = 42; + char data[4]; uint32_t type; DATA_BLOB value; + SIVAL(data, 0, 42); + error = hive_key_add_name(mem_ctx, root, "EEYA Nested Key", NULL, NULL, &subkey); torture_assert_werr_ok(tctx, error, "hive_key_add_name"); error = hive_key_set_value(subkey, "Answer", REG_DWORD, - data_blob_talloc(mem_ctx, &data, sizeof(data))); + data_blob_talloc(mem_ctx, data, sizeof(data))); torture_assert_werr_ok(tctx, error, "hive_key_set_value"); error = hive_key_del_value(subkey, "Answer"); @@ -264,17 +271,19 @@ static bool test_list_values(struct torture_context *tctx, struct hive_key *subkey; const struct hive_key *root = (const struct hive_key *)test_data; TALLOC_CTX *mem_ctx = tctx; - uint32_t data = 42; + char data[4]; uint32_t type; DATA_BLOB value; const char *name; + int data_val = 42; + SIVAL(data, 0, data_val); error = hive_key_add_name(mem_ctx, root, "AYAYA Nested Key", NULL, NULL, &subkey); torture_assert_werr_ok(tctx, error, "hive_key_add_name"); error = hive_key_set_value(subkey, "Answer", REG_DWORD, - data_blob_talloc(mem_ctx, &data, sizeof(data))); + data_blob_talloc(mem_ctx, data, sizeof(data))); torture_assert_werr_ok(tctx, error, "hive_key_set_value"); error = hive_get_value_by_index(mem_ctx, subkey, 0, &name, @@ -287,7 +296,7 @@ static bool test_list_values(struct torture_context *tctx, torture_assert_int_equal(tctx, type, REG_DWORD, "value type"); - torture_assert_int_equal(tctx, data, IVAL(value.data, 0), "value data"); + torture_assert_int_equal(tctx, data_val, IVAL(value.data, 0), "value data"); error = hive_get_value_by_index(mem_ctx, subkey, 1, &name, &type, &value); diff --git a/source4/lib/registry/tests/registry.c b/source4/lib/registry/tests/registry.c index ec7873a111..ac812823b2 100644 --- a/source4/lib/registry/tests/registry.c +++ b/source4/lib/registry/tests/registry.c @@ -281,7 +281,8 @@ static bool test_query_key_nums(struct torture_context *tctx, void *_data) struct registry_key *root, *subkey1, *subkey2; WERROR error; uint32_t num_subkeys, num_values; - uint32_t data = 42; + char data[4]; + SIVAL(data, 0, 42); if (!create_test_key(tctx, rctx, "Berlin", &root, &subkey1)) return false; @@ -353,13 +354,15 @@ static bool test_set_value(struct torture_context *tctx, void *_data) struct registry_context *rctx = (struct registry_context *)_data; struct registry_key *subkey = NULL, *root; WERROR error; - uint32_t data = 42; + char data[4]; + + SIVAL(data, 0, 42); if (!create_test_key(tctx, rctx, "Dusseldorf", &root, &subkey)) return false; error = reg_val_set(subkey, "Answer", REG_DWORD, - data_blob_talloc(tctx, &data, sizeof(data))); + data_blob_talloc(tctx, data, sizeof(data))); torture_assert_werr_ok (tctx, error, "setting value"); return true; @@ -408,8 +411,9 @@ static bool test_get_value(struct torture_context *tctx, void *_data) struct registry_key *subkey = NULL, *root; WERROR error; DATA_BLOB data; - uint32_t value = 42; + char value[4]; uint32_t type; + SIVAL(value, 0, 42); if (!create_test_key(tctx, rctx, "Duisburg", &root, &subkey)) return false; @@ -420,7 +424,7 @@ static bool test_get_value(struct torture_context *tctx, void *_data) "getting missing value"); error = reg_val_set(subkey, __FUNCTION__, REG_DWORD, - data_blob_talloc(tctx, &value, 4)); + data_blob_talloc(tctx, value, sizeof(value))); torture_assert_werr_ok(tctx, error, "setting value"); error = reg_key_get_value_by_name(tctx, subkey, __FUNCTION__, &type, @@ -428,7 +432,7 @@ static bool test_get_value(struct torture_context *tctx, void *_data) torture_assert_werr_ok(tctx, error, "getting value"); torture_assert_int_equal(tctx, 4, data.length, "value length ok"); - torture_assert_mem_equal(tctx, data.data, &value, 4, + torture_assert_mem_equal(tctx, data.data, value, 4, "value content ok"); torture_assert_int_equal(tctx, REG_DWORD, type, "value type"); -- cgit From 8582063e9120932e598afbba00d0257e5e9a428f Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Thu, 17 Apr 2008 16:38:53 +0200 Subject: More work to avoid endian bugs in registry tests. Andrew Bartlett (This used to be commit 500544f4127d4042ab5ea8e3800156246982c297) --- source4/lib/registry/tests/registry.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'source4/lib/registry/tests') diff --git a/source4/lib/registry/tests/registry.c b/source4/lib/registry/tests/registry.c index ac812823b2..7fad219752 100644 --- a/source4/lib/registry/tests/registry.c +++ b/source4/lib/registry/tests/registry.c @@ -448,8 +448,9 @@ static bool test_del_value(struct torture_context *tctx, void *_data) struct registry_key *subkey = NULL, *root; WERROR error; DATA_BLOB data; - uint32_t value = 42; uint32_t type; + char value[4]; + SIVAL(value, 0, 42); if (!create_test_key(tctx, rctx, "Warschau", &root, &subkey)) return false; @@ -460,7 +461,7 @@ static bool test_del_value(struct torture_context *tctx, void *_data) "getting missing value"); error = reg_val_set(subkey, __FUNCTION__, REG_DWORD, - data_blob_talloc(tctx, &value, 4)); + data_blob_talloc(tctx, value, sizeof(value))); torture_assert_werr_ok (tctx, error, "setting value"); error = reg_del_value(subkey, __FUNCTION__); @@ -483,15 +484,16 @@ static bool test_list_values(struct torture_context *tctx, void *_data) struct registry_key *subkey = NULL, *root; WERROR error; DATA_BLOB data; - uint32_t value = 42; uint32_t type; const char *name; + char value[4]; + SIVAL(value, 0, 42); if (!create_test_key(tctx, rctx, "Bonn", &root, &subkey)) return false; error = reg_val_set(subkey, "bar", REG_DWORD, - data_blob_talloc(tctx, &value, 4)); + data_blob_talloc(tctx, value, sizeof(val))); torture_assert_werr_ok (tctx, error, "setting value"); error = reg_key_get_value_by_index(tctx, subkey, 0, &name, @@ -500,7 +502,7 @@ static bool test_list_values(struct torture_context *tctx, void *_data) torture_assert_str_equal(tctx, name, "bar", "value name"); torture_assert_int_equal(tctx, 4, data.length, "value length"); - torture_assert_mem_equal(tctx, data.data, &value, 4, + torture_assert_mem_equal(tctx, data.data, &value, sizeof(value), "value content"); torture_assert_int_equal(tctx, REG_DWORD, type, "value type"); -- cgit From d0525ff0c2c9ae6d7e39c0fda1d4ab956763b585 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Thu, 17 Apr 2008 16:44:55 +0200 Subject: Fix typo (This used to be commit ba6546504505f19abaa5aa35fe3e469ddfd3d619) --- source4/lib/registry/tests/registry.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/registry/tests') diff --git a/source4/lib/registry/tests/registry.c b/source4/lib/registry/tests/registry.c index 7fad219752..85b68ac8a2 100644 --- a/source4/lib/registry/tests/registry.c +++ b/source4/lib/registry/tests/registry.c @@ -493,7 +493,7 @@ static bool test_list_values(struct torture_context *tctx, void *_data) return false; error = reg_val_set(subkey, "bar", REG_DWORD, - data_blob_talloc(tctx, value, sizeof(val))); + data_blob_talloc(tctx, value, sizeof(value))); torture_assert_werr_ok (tctx, error, "setting value"); error = reg_key_get_value_by_index(tctx, subkey, 0, &name, -- cgit From c9a12fa55d63e4bccb5b453186022dae1da39032 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Thu, 17 Apr 2008 18:40:56 +0200 Subject: More endian fixes in the registry (This used to be commit b26662be196a84237543eb90d6e08809489df3a9) --- source4/lib/registry/tests/registry.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'source4/lib/registry/tests') diff --git a/source4/lib/registry/tests/registry.c b/source4/lib/registry/tests/registry.c index 85b68ac8a2..661d7c2c69 100644 --- a/source4/lib/registry/tests/registry.c +++ b/source4/lib/registry/tests/registry.c @@ -431,9 +431,9 @@ static bool test_get_value(struct torture_context *tctx, void *_data) &data); torture_assert_werr_ok(tctx, error, "getting value"); - torture_assert_int_equal(tctx, 4, data.length, "value length ok"); - torture_assert_mem_equal(tctx, data.data, value, 4, - "value content ok"); + torture_assert_int_equal(tctx, sizeof(value), data.length, "value length ok"); + torture_assert_mem_equal(tctx, data.data, value, sizeof(value), + "value content ok"); torture_assert_int_equal(tctx, REG_DWORD, type, "value type"); return true; @@ -501,8 +501,8 @@ static bool test_list_values(struct torture_context *tctx, void *_data) torture_assert_werr_ok(tctx, error, "getting value"); torture_assert_str_equal(tctx, name, "bar", "value name"); - torture_assert_int_equal(tctx, 4, data.length, "value length"); - torture_assert_mem_equal(tctx, data.data, &value, sizeof(value), + torture_assert_int_equal(tctx, sizeof(value), data.length, "value length"); + torture_assert_mem_equal(tctx, data.data, value, sizeof(value), "value content"); torture_assert_int_equal(tctx, REG_DWORD, type, "value type"); -- cgit From 49706ab19bd3ffd6125639e6a7753b2350cf54e1 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 21 May 2008 23:59:34 +0200 Subject: Move more modules inside of the samba package. (This used to be commit 9b39e99f48266a54ed0b8890c2efde218b4b118a) --- source4/lib/registry/tests/bindings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/registry/tests') diff --git a/source4/lib/registry/tests/bindings.py b/source4/lib/registry/tests/bindings.py index 314cf778a1..1fb5c70b70 100644 --- a/source4/lib/registry/tests/bindings.py +++ b/source4/lib/registry/tests/bindings.py @@ -19,7 +19,7 @@ import os import unittest -import registry +from samba import registry import samba.tests class HelperTests(unittest.TestCase): -- cgit From a255c9399518419b1028abac09fb9e0c1d572403 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 23 May 2008 16:17:58 +0200 Subject: Cope with new event context parameter in API and removed parameters to reg_open_local(). (This used to be commit 0d5752c940360a0ceb5e23cd6f71cbc61271137a) --- source4/lib/registry/tests/diff.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'source4/lib/registry/tests') diff --git a/source4/lib/registry/tests/diff.c b/source4/lib/registry/tests/diff.c index c7726545f6..44ea090527 100644 --- a/source4/lib/registry/tests/diff.c +++ b/source4/lib/registry/tests/diff.c @@ -165,10 +165,10 @@ static bool diff_setup_tcase(struct torture_context *tctx, void **data) td = talloc(tctx, struct diff_tcase_data); /* Create two registry contexts */ - error = reg_open_local(tctx, &r1_ctx, NULL, NULL); + error = reg_open_local(tctx, &r1_ctx); torture_assert_werr_ok(tctx, error, "Opening registry 1 for patch tests failed"); - error = reg_open_local(tctx, &r2_ctx, NULL, NULL); + error = reg_open_local(tctx, &r2_ctx); torture_assert_werr_ok(tctx, error, "Opening registry 2 for patch tests failed"); /* Create temp directory */ @@ -177,14 +177,14 @@ static bool diff_setup_tcase(struct torture_context *tctx, void **data) /* Create and mount HKLM and HKCU hives for registry 1 */ filename = talloc_asprintf(tctx, "%s/r1_local_machine.ldb", td->tempdir); - error = reg_open_ldb_file(tctx, filename, NULL, NULL, tctx->lp_ctx, &r1_hklm); + error = reg_open_ldb_file(tctx, filename, NULL, NULL, tctx->ev, tctx->lp_ctx, &r1_hklm); torture_assert_werr_ok(tctx, error, "Opening local machine file failed"); error = reg_mount_hive(r1_ctx, r1_hklm, HKEY_LOCAL_MACHINE, NULL); torture_assert_werr_ok(tctx, error, "Mounting hive failed"); filename = talloc_asprintf(tctx, "%s/r1_current_user.ldb", td->tempdir); - error = reg_open_ldb_file(tctx, filename, NULL, NULL, tctx->lp_ctx, &r1_hkcu); + error = reg_open_ldb_file(tctx, filename, NULL, NULL, tctx->ev, tctx->lp_ctx, &r1_hkcu); torture_assert_werr_ok(tctx, error, "Opening current user file failed"); error = reg_mount_hive(r1_ctx, r1_hkcu, HKEY_CURRENT_USER, NULL); @@ -192,14 +192,14 @@ static bool diff_setup_tcase(struct torture_context *tctx, void **data) /* Create and mount HKLM and HKCU hives for registry 2 */ filename = talloc_asprintf(tctx, "%s/r2_local_machine.ldb", td->tempdir); - error = reg_open_ldb_file(tctx, filename, NULL, NULL, tctx->lp_ctx, &r2_hklm); + error = reg_open_ldb_file(tctx, filename, NULL, NULL, tctx->ev, tctx->lp_ctx, &r2_hklm); torture_assert_werr_ok(tctx, error, "Opening local machine file failed"); error = reg_mount_hive(r2_ctx, r2_hklm, HKEY_LOCAL_MACHINE, NULL); torture_assert_werr_ok(tctx, error, "Mounting hive failed"); filename = talloc_asprintf(tctx, "%s/r2_current_user.ldb", td->tempdir); - error = reg_open_ldb_file(tctx, filename, NULL, NULL, tctx->lp_ctx, &r2_hkcu); + error = reg_open_ldb_file(tctx, filename, NULL, NULL, tctx->ev, tctx->lp_ctx, &r2_hkcu); torture_assert_werr_ok(tctx, error, "Opening current user file failed"); error = reg_mount_hive(r2_ctx, r2_hkcu, HKEY_CURRENT_USER, NULL); -- cgit