svn commit: samba r24666 - in branches/4.0-regwrite: . source/lib/registry source/lib/registry/tests

jelmer at samba.org jelmer at samba.org
Sun Aug 26 14:38:44 GMT 2007


Author: jelmer
Date: 2007-08-26 14:38:43 +0000 (Sun, 26 Aug 2007)
New Revision: 24666

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=24666

Log:
Support relative paths in CreateKey.
Modified:
   branches/4.0-regwrite/
   branches/4.0-regwrite/source/lib/registry/local.c
   branches/4.0-regwrite/source/lib/registry/tests/registry.c


Changeset:

Property changes on: branches/4.0-regwrite
___________________________________________________________________
Name: bzr:revision-info
...skipped...
Name: bzr:revision-id:v3-trunk0
...skipped...

Modified: branches/4.0-regwrite/source/lib/registry/local.c
===================================================================
--- branches/4.0-regwrite/source/lib/registry/local.c	2007-08-26 14:07:23 UTC (rev 24665)
+++ branches/4.0-regwrite/source/lib/registry/local.c	2007-08-26 14:38:43 UTC (rev 24666)
@@ -165,15 +165,25 @@
 								struct security_descriptor *security,
 								struct registry_key **key)
 {
-	const struct local_key *local_parent = (const struct local_key *)parent_key;
+	const struct local_key *local_parent;
 	struct hive_key *hivekey;
 	const char **elements;
 	int i;
+	char *last_part;
 
-	SMB_ASSERT(strchr(name, '\\') == NULL);
+	last_part = strrchr(name, '\\');
+	if (last_part == NULL) {
+		last_part = name;
+		local_parent = (const struct local_key *)parent_key;
+	} else {
+		W_ERROR_NOT_OK_RETURN(reg_open_key(mem_ctx, parent_key, 
+							  talloc_strndup(mem_ctx, name, last_part-name),
+							  &local_parent));
+		last_part++;
+	}
 
 	W_ERROR_NOT_OK_RETURN(hive_key_add_name(mem_ctx, local_parent->hive_key, 
-										name, key_class, security, &hivekey));
+								last_part, key_class, security, &hivekey));
 
 	if (local_parent->path.elements != NULL) {
 		elements = talloc_array(hivekey, const char *, 

Modified: branches/4.0-regwrite/source/lib/registry/tests/registry.c
===================================================================
--- branches/4.0-regwrite/source/lib/registry/tests/registry.c	2007-08-26 14:07:23 UTC (rev 24665)
+++ branches/4.0-regwrite/source/lib/registry/tests/registry.c	2007-08-26 14:38:43 UTC (rev 24666)
@@ -68,6 +68,33 @@
 }
 
 /**
+ * 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,
@@ -431,6 +458,8 @@
 	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);



More information about the samba-cvs mailing list