Rev 11187: Make existing tests pass for dir hives. in file:///home/jelmer/bzr.samba-old/4.0-regwrite/

Jelmer Vernooij jelmer at samba.org
Wed Jun 13 17:38:10 GMT 2007


At file:///home/jelmer/bzr.samba-old/4.0-regwrite/

------------------------------------------------------------
revno: 11187
revision-id: jelmer at samba.org-20070612200826-54acueedast7lnmr
parent: jelmer at samba.org-20070612165440-1x7k1m3nb1bzbal0
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: 4.0-regwrite
timestamp: Tue 2007-06-12 22:08:26 +0200
message:
  Make existing tests pass for dir hives.
modified:
  source/lib/registry/dir.c      svn-v2:4132 at 0c0555d6-39d7-0310-84fc-f1cc0bd64818-branches%2fSAMBA_4_0-source%2flib%2fregistry%2freg_backend_dir.c
  source/lib/registry/hive.c     hive.c-20070602140117-9a3wth1mhbrq7ej1-1
  source/lib/registry/hive.h     hive.h-20070423140448-w1nvzs8d2qxvyswz-1
  source/lib/registry/local.c    local.c-20070602140117-9a3wth1mhbrq7ej1-2
  source/lib/registry/regf.c     svn-v2:4132 at 0c0555d6-39d7-0310-84fc-f1cc0bd64818-branches%2fSAMBA_4_0-source%2flib%2fregistry%2freg_backend_nt4.c
  source/lib/registry/tests/hive.c hive.c-20070612151642-hsxkm8j4r69ej3px-1
=== modified file 'source/lib/registry/dir.c'
--- a/source/lib/registry/dir.c	2007-06-12 16:54:40 +0000
+++ b/source/lib/registry/dir.c	2007-06-12 20:08:26 +0000
@@ -28,9 +28,11 @@
 	const char *path;
 };
 
+static struct hive_operations reg_backend_dir;
+
 static WERROR reg_dir_add_key(TALLOC_CTX *mem_ctx, 
-							  struct hive_key *parent, 
-							  const char *name, uint32_t access_mask, 
+							  const struct hive_key *parent, 
+							  const char *name, const char *classname,
 							  struct security_descriptor *desc, 
 							  struct hive_key **result)
 {
@@ -42,20 +44,30 @@
 	ret = mkdir(path, 0700);
 	if (ret == 0) {
 		struct dir_key *key = talloc(mem_ctx, struct dir_key);
+		key->key.ops = &reg_backend_dir;
 		key->path = talloc_steal(key, path);
 		*result = (struct hive_key *)key;
 		return WERR_OK;
 	}
-	return WERR_INVALID_PARAM;
+
+	if (errno == EEXIST)
+		return WERR_ALREADY_EXISTS;
+	printf("FAILED %s BECAUSE: %s\n", path, strerror(errno));
+	return WERR_GENERAL_FAILURE;
 }
 
-static WERROR reg_dir_del_key(struct hive_key *k, const char *name)
+static WERROR reg_dir_del_key(const struct hive_key *k, const char *name)
 {
 	struct dir_key *dk = talloc_get_type(k, struct dir_key);
 	char *child = talloc_asprintf(NULL, "%s/%s", dk->path, name);
 	WERROR ret;
 
-	if (rmdir(child) == 0) ret = WERR_OK; else ret = WERR_GENERAL_FAILURE;
+	if (rmdir(child) == 0) 
+		ret = WERR_OK; 
+	else if (errno == ENOENT)
+		ret = WERR_NOT_FOUND;
+	else
+		ret = WERR_GENERAL_FAILURE;
 
 	talloc_free(child);
 
@@ -85,6 +97,7 @@
 	}
 	closedir(d);
 	ret = talloc(mem_ctx, struct dir_key);
+	ret->key.ops = &reg_backend_dir;
 	ret->path = talloc_steal(ret, fullpath);
 	*subkey = (struct hive_key *)ret;
 	return WERR_OK;
@@ -150,6 +163,7 @@
 		return WERR_INVALID_PARAM;
 
 	dk = talloc(parent_ctx, struct dir_key);
+	dk->key.ops = &reg_backend_dir;
 	dk->path = talloc_strdup(dk, location);
 	*key = (struct hive_key *)dk;
 	return WERR_OK;
@@ -158,16 +172,39 @@
 WERROR reg_create_directory(TALLOC_CTX *parent_ctx, 
 							const char *location, struct hive_key **key)
 {
-	if (mkdir(location, 0644) != 0) {
+	if (mkdir(location, 0700) != 0) {
+		*key = NULL;
 		return WERR_GENERAL_FAILURE;
 	}
 
 	return reg_open_directory(parent_ctx, location, key);
 }
 
+static WERROR reg_dir_get_info(TALLOC_CTX *ctx, const struct hive_key *key, 
+							   const char **classname,
+							   uint32_t *num_subkeys,
+							   uint32_t *num_values,
+							   NTTIME *lastmod)
+{
+	/* FIXME */
+	if (classname != NULL)
+		*classname = NULL;
+
+	if (num_subkeys != NULL)
+		*num_subkeys = 0;
+
+	if (num_values != NULL)
+		*num_values = 0;
+
+	if (lastmod != NULL)
+		*lastmod = 0;
+	return WERR_OK;
+}
+
 static struct hive_operations reg_backend_dir = {
 	.name = "dir",
 	.get_key_by_name = reg_dir_open_key,
+	.get_key_info = reg_dir_get_info,
 	.add_key = reg_dir_add_key,
 	.del_key = reg_dir_del_key,
 	.enum_key = reg_dir_key_by_index

=== modified file 'source/lib/registry/hive.c'
--- a/source/lib/registry/hive.c	2007-06-12 16:54:40 +0000
+++ b/source/lib/registry/hive.c	2007-06-12 20:08:26 +0000
@@ -66,7 +66,7 @@
 						 uint32_t *num_values,
 						 NTTIME *last_change_time)
 {
-	return key->context->ops->get_key_info(mem_ctx, key, classname, num_subkeys, 
+	return key->ops->get_key_info(mem_ctx, key, classname, num_subkeys, 
 									num_values, last_change_time);
 }
 
@@ -74,10 +74,10 @@
 						 const char *name, const char *classname, struct security_descriptor *desc,
 						 struct hive_key **key)
 {
-	return parent_key->context->ops->add_key(ctx, parent_key, name, classname, desc, key);
+	return parent_key->ops->add_key(ctx, parent_key, name, classname, desc, key);
 }
 
 _PUBLIC_ WERROR hive_key_del(const struct hive_key *key, const char *name)
 {
-	return key->context->ops->del_key(key, name);
+	return key->ops->del_key(key, name);
 }

=== modified file 'source/lib/registry/hive.h'
--- a/source/lib/registry/hive.h	2007-06-12 16:54:40 +0000
+++ b/source/lib/registry/hive.h	2007-06-12 20:08:26 +0000
@@ -36,22 +36,13 @@
  * does it understand what predefined keys are.
  */
 
-struct hive_context {
+struct hive_key {
 	const struct hive_operations *ops;
 };
 
-struct hive_key {
-	struct hive_context *context;
-};
-
 struct hive_operations {
 	const char *name;	
 
-	/** 
-	 * Open the root key of this hive
-	 */
-	WERROR (*open_root) (struct hive_context *hive, struct hive_key **key);
-	
 	/**
 	 * Open a specific subkey
 	 */

=== modified file 'source/lib/registry/local.c'
--- a/source/lib/registry/local.c	2007-06-12 16:54:40 +0000
+++ b/source/lib/registry/local.c	2007-06-12 20:08:26 +0000
@@ -46,8 +46,8 @@
 };
 
 WERROR reg_mount_hive(struct registry_context *ctx, struct reg_key_path *path, 
-					  struct hive_context *hive);
-WERROR reg_unmount_hive(struct registry_context *ctx, struct hive_context *hive);
+					  struct hive_key *hive);
+WERROR reg_unmount_hive(struct registry_context *ctx, struct hive_key *hive);
 
 static WERROR local_open_key(TALLOC_CTX *mem_ctx,
 						   struct registry_key *parent, 

=== modified file 'source/lib/registry/regf.c'
--- a/source/lib/registry/regf.c	2007-06-02 15:25:04 +0000
+++ b/source/lib/registry/regf.c	2007-06-12 20:08:26 +0000
@@ -43,7 +43,6 @@
  */
 
 struct regf_data {
-	struct hive_context context;
 	int fd;
 	struct hbin_block **hbins;
 	struct regf_hdr *header;
@@ -53,9 +52,7 @@
 
 struct regf_key_data {
 	struct hive_key key;
-	struct regf_data *hive; /* Duplicaton, as it's already in 
-							   (struct regf_data *)key.context as well, 
-							   but that's harder to get at */
+	struct regf_data *hive; 
 	uint32_t offset;
 	struct nk_block *nk;
 };
@@ -408,7 +405,8 @@
 							 const struct hive_key *key, 
 							 const char **classname,
 							 uint32_t *num_subkeys,
-							 uint32_t *num_values)
+							 uint32_t *num_values,
+							 NTTIME *last_mod_time)
 {
 	const struct regf_key_data *private_data = 
 		(const struct regf_key_data *)key;
@@ -423,6 +421,8 @@
 						 (char*)data.data, private_data->nk->clsname_length);
 	} else 
 		*classname = NULL;
+
+	/* FIXME: Last mod time */
 	
 	return WERR_OK;
 }
@@ -435,7 +435,7 @@
 	struct regf_key_data *ret;
 
 	ret = talloc_zero(ctx, struct regf_key_data);
-	ret->key.context = talloc_reference(ret, regf);
+	ret->hive = talloc_reference(ret, regf);
 	ret->offset = offset;
 	nk = talloc(ret, struct nk_block);
 	ret->nk = nk;
@@ -460,7 +460,7 @@
 	const struct regf_key_data *private_data = 
 			(const struct regf_key_data *)key;
 	struct vk_block *vk;
-	struct regf_data *regf = (struct regf_data *)key->context;
+	struct regf_data *regf = private_data->hive;
 	uint32_t vk_offset;
 	DATA_BLOB tmp;
 
@@ -1402,7 +1402,7 @@
 }
 
 
-static WERROR regf_del_key(struct hive_key *parent, const char *name)
+static WERROR regf_del_key(const struct hive_key *parent, const char *name)
 {
 	const struct regf_key_data *private_data = 
 		(const struct regf_key_data *)parent;
@@ -1454,8 +1454,8 @@
 	return regf_save_hbin(private_data->hive);
 }
 
-static WERROR regf_add_key(TALLOC_CTX *ctx, struct hive_key *parent, 
-						   const char *name, uint32_t access_mask, 
+static WERROR regf_add_key(TALLOC_CTX *ctx, const struct hive_key *parent, 
+						   const char *name, const char *classname,
 						   struct security_descriptor *sec_desc, 
 						   struct hive_key **ret)
 {
@@ -1479,7 +1479,7 @@
 	nk.num_values = 0;
 	nk.values_offset = -1;
 	memset(nk.unk3, 0, 5);
-	nk.clsname_offset = -1;
+	nk.clsname_offset = -1; /* FIXME: fill in */
 	nk.clsname_length = 0;
 	nk.key_name = name;
 	

=== modified file 'source/lib/registry/tests/hive.c'
--- a/source/lib/registry/tests/hive.c	2007-06-12 16:54:40 +0000
+++ b/source/lib/registry/tests/hive.c	2007-06-12 20:08:26 +0000
@@ -31,7 +31,7 @@
 {
 	const struct hive_key *root = test_data;
 	WERROR error = hive_key_del(root, "bla");
-	torture_assert_werr_equal(tctx, error, WERR_BADFILE, 
+	torture_assert_werr_equal(tctx, error, WERR_NOT_FOUND, 
 							  "invalid return code");
 
 	return true;
@@ -50,11 +50,11 @@
 							  NULL);
 	torture_assert_werr_ok(tctx, error, "reg_key_num_subkeys()");
 
-	torture_assert(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(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;
 }
@@ -69,7 +69,7 @@
 
 	error = hive_key_add_name(mem_ctx, root, "Nested Key", NULL, 
 							 NULL, &subkey);
-	torture_assert_werr_ok(tctx, error, "reg_key_add_name");
+	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");
@@ -77,17 +77,8 @@
 	return true;
 }
 
-struct torture_suite *torture_registry_hive(TALLOC_CTX *mem_ctx) 
+static void tcase_add_tests(struct torture_tcase *tcase) 
 {
-	struct torture_tcase *tcase;
-	struct torture_suite *suite = torture_suite_create(mem_ctx, 
-													   "HIVE");
-
-	struct hive_key *key;
-
-	reg_create_directory(mem_ctx, "bla", &key);
-
-	tcase = torture_suite_add_tcase(suite, "dir");
 	torture_tcase_add_simple_test(tcase, "del_nonexistant_key", 
 								  test_del_nonexistant_key);
 
@@ -96,6 +87,45 @@
 
 	torture_tcase_add_simple_test(tcase, "get_info", 
 								  test_keyinfo_root);
-
+}
+
+static bool hive_setup_dir(struct torture_context *tctx, void **data)
+{
+
+	struct hive_key *key;
+	WERROR error;
+
+	error = reg_create_directory(tctx, "bla", &key);
+	if (!W_ERROR_IS_OK(error)) {
+		fprintf(stderr, "Unable to initialize dir hive\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);
 	return suite;
 }



More information about the samba-cvs mailing list