summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilco Baan Hofman <wilco@synlap.(none)>2008-04-15 11:52:33 +0200
committerWilco Baan Hofman <wilco@synlap.(none)>2008-04-15 11:52:33 +0200
commit0b8d2b3cb779463a1e24039300ac2669862f9b64 (patch)
treea8e638253e71008f75fbcd84b5fe5ad9717c9ef2
parenta31b6607f22f6b3e1b354db2f9f611b299a2f7ae (diff)
downloadsamba-0b8d2b3cb779463a1e24039300ac2669862f9b64.tar.gz
samba-0b8d2b3cb779463a1e24039300ac2669862f9b64.tar.bz2
samba-0b8d2b3cb779463a1e24039300ac2669862f9b64.zip
Fixed the patchfile tests and tidy up the patchfile backends.
(This used to be commit 6e9b1e35a269af2eda79356c1525f5413656d648)
-rw-r--r--source4/lib/registry/patchfile.c4
-rw-r--r--source4/lib/registry/patchfile_dotreg.c8
-rw-r--r--source4/lib/registry/patchfile_preg.c10
-rw-r--r--source4/lib/registry/registry.h4
-rw-r--r--source4/lib/registry/tests/diff.c232
5 files changed, 226 insertions, 32 deletions
diff --git a/source4/lib/registry/patchfile.c b/source4/lib/registry/patchfile.c
index 15e3a158f2..eaeef341bb 100644
--- a/source4/lib/registry/patchfile.c
+++ b/source4/lib/registry/patchfile.c
@@ -45,7 +45,7 @@ WERROR reg_generate_diff_key(struct registry_key *oldkey,
void *callback_data)
{
int i;
- struct registry_key *t1, *t2;
+ struct registry_key *t1 = NULL, *t2 = NULL;
char *tmppath;
const char *keyname1;
WERROR error, error1, error2;
@@ -295,7 +295,7 @@ _PUBLIC_ WERROR reg_diff_load(const char *filename,
/* Reset position in file */
lseek(fd, 0, SEEK_SET);
-#if 0
+#if 0 /* These backends are not supported yet. */
if (strncmp(hdr, "CREG", 4) == 0) {
/* Must be a W9x CREG Config.pol file */
return reg_creg_diff_load(diff, fd);
diff --git a/source4/lib/registry/patchfile_dotreg.c b/source4/lib/registry/patchfile_dotreg.c
index 5aa7e2bab7..1bc9c60753 100644
--- a/source4/lib/registry/patchfile_dotreg.c
+++ b/source4/lib/registry/patchfile_dotreg.c
@@ -3,7 +3,7 @@
Reading .REG files
Copyright (C) Jelmer Vernooij 2004-2007
- Copyright (C) Wilco Baan Hofman 2006
+ Copyright (C) Wilco Baan Hofman 2006-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
@@ -112,8 +112,8 @@ _PUBLIC_ WERROR reg_dotreg_diff_save(TALLOC_CTX *ctx, const char *filename,
data->iconv_convenience = iconv_convenience;
if (filename) {
- data->fd = open(filename, O_CREAT, 0755);
- if (data->fd == -1) {
+ data->fd = open(filename, O_CREAT|O_WRONLY, 0755);
+ if (data->fd < 0) {
DEBUG(0, ("Unable to open %s\n", filename));
return WERR_BADFILE;
}
@@ -121,7 +121,7 @@ _PUBLIC_ WERROR reg_dotreg_diff_save(TALLOC_CTX *ctx, const char *filename,
data->fd = STDOUT_FILENO;
}
- fdprintf(data->fd, "%s\n", HEADER_STRING);
+ fdprintf(data->fd, "%s\n\n", HEADER_STRING);
*callbacks = talloc(ctx, struct reg_diff_callbacks);
diff --git a/source4/lib/registry/patchfile_preg.c b/source4/lib/registry/patchfile_preg.c
index 5216a04c8b..a28096517c 100644
--- a/source4/lib/registry/patchfile_preg.c
+++ b/source4/lib/registry/patchfile_preg.c
@@ -2,7 +2,7 @@
Unix SMB/CIFS implementation.
Reading Registry.pol PReg registry files
- Copyright (C) Wilco Baan Hofman 2006
+ Copyright (C) Wilco Baan Hofman 2006-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
@@ -71,7 +71,7 @@ static WERROR reg_preg_diff_del_all_values(void *_data, const char *key_name)
static WERROR reg_preg_diff_done(void *_data)
{
struct preg_data *data = (struct preg_data *)_data;
-
+
close(data->fd);
talloc_free(data);
return WERR_OK;
@@ -95,15 +95,15 @@ _PUBLIC_ WERROR reg_preg_diff_save(TALLOC_CTX *ctx, const char *filename,
*callback_data = data;
if (filename) {
- data->fd = open(filename, O_CREAT, 0755);
- if (data->fd == -1) {
+ data->fd = open(filename, O_CREAT|O_WRONLY, 0755);
+ if (data->fd < 0) {
DEBUG(0, ("Unable to open %s\n", filename));
return WERR_BADFILE;
}
} else {
data->fd = STDOUT_FILENO;
}
- snprintf(preg_header.hdr, 4, "PReg");
+ memcpy(preg_header.hdr, "PReg", 4);
SIVAL(&preg_header, 4, 1);
write(data->fd, (uint8_t *)&preg_header,8);
diff --git a/source4/lib/registry/registry.h b/source4/lib/registry/registry.h
index 1348d1121f..573379aff5 100644
--- a/source4/lib/registry/registry.h
+++ b/source4/lib/registry/registry.h
@@ -500,6 +500,10 @@ WERROR reg_generate_diff_key(struct registry_key *oldkey,
const char *path,
const struct reg_diff_callbacks *callbacks,
void *callback_data);
+WERROR reg_diff_load(const char *filename,
+ struct smb_iconv_convenience *iconv_convenience,
+ const struct reg_diff_callbacks *callbacks,
+ void *callback_data);
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;
}