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

jelmer at samba.org jelmer at samba.org
Sun Aug 26 14:03:31 GMT 2007


Author: jelmer
Date: 2007-08-26 14:03:29 +0000 (Sun, 26 Aug 2007)
New Revision: 24664

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

Log:
Fix last test.
Modified:
   branches/4.0-regwrite/
   branches/4.0-regwrite/source/lib/registry/hive.c
   branches/4.0-regwrite/source/lib/registry/ldb.c
   branches/4.0-regwrite/source/lib/registry/local.c
   branches/4.0-regwrite/source/lib/registry/samba.c
   branches/4.0-regwrite/source/lib/registry/tests/registry.c
   branches/4.0-regwrite/source/lib/registry/util.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/hive.c
===================================================================
--- branches/4.0-regwrite/source/lib/registry/hive.c	2007-08-26 12:46:40 UTC (rev 24663)
+++ branches/4.0-regwrite/source/lib/registry/hive.c	2007-08-26 14:03:29 UTC (rev 24664)
@@ -71,6 +71,8 @@
 						 const char *name, const char *classname, struct security_descriptor *desc,
 						 struct hive_key **key)
 {
+	SMB_ASSERT(strchr(name, '\\') == NULL);
+
 	return parent_key->ops->add_key(ctx, parent_key, name, classname, desc, key);
 }
 
@@ -83,8 +85,7 @@
 							   const struct hive_key *key, const char *name, 
 							   struct hive_key **subkey)
 {
-	return key->ops->get_key_by_name(mem_ctx, key, name, 
-									 subkey);
+	return key->ops->get_key_by_name(mem_ctx, key, name, subkey);
 }
 
 WERROR hive_enum_key(TALLOC_CTX *mem_ctx,

Modified: branches/4.0-regwrite/source/lib/registry/ldb.c
===================================================================
--- branches/4.0-regwrite/source/lib/registry/ldb.c	2007-08-26 12:46:40 UTC (rev 24663)
+++ branches/4.0-regwrite/source/lib/registry/ldb.c	2007-08-26 14:03:29 UTC (rev 24664)
@@ -295,11 +295,13 @@
 	ret = ldb_search(c, ldap_path, LDB_SCOPE_BASE, "(key=*)", NULL, &res);
 
 	if (ret != LDB_SUCCESS) {
-		DEBUG(0, ("Error opening key '%s': %s\n", ldb_dn_get_linearized(ldap_path), ldb_errstring(c)));
+		DEBUG(0, ("Error opening key '%s': %s\n", 
+				  ldb_dn_get_linearized(ldap_path), ldb_errstring(c)));
 		return WERR_FOOBAR;
 	} else if (res->count == 0) {
+		DEBUG(0, ("Key '%s' not found\n", ldb_dn_get_linearized(ldap_path)));
 		talloc_free(res);
-		return WERR_BADFILE;
+		return WERR_NOT_FOUND;
 	}
 
 	newkd = talloc_zero(mem_ctx, struct ldb_key_data);
@@ -328,7 +330,7 @@
 	wrap = ldb_wrap_connect(parent_ctx, location, session_info, 
 							credentials, 0, NULL);
 
-	if(!wrap) {
+	if (wrap == NULL) {
 		DEBUG(1, (__FILE__": unable to connect\n"));
 		return WERR_FOOBAR;
 	}
@@ -368,8 +370,10 @@
 	if (ret < 0) {
 		DEBUG(1, ("ldb_msg_add: %s\n", ldb_errstring(parentkd->ldb)));
 		return WERR_FOOBAR;
-	}
+	} 
 
+	DEBUG(2, ("key added: %s\n", ldb_dn_get_linearized(msg->dn)));
+
 	newkd = talloc_zero(mem_ctx, struct ldb_key_data);
 	newkd->ldb = talloc_reference(newkd, parentkd->ldb);
 	newkd->key.ops = &reg_backend_ldb;

Modified: branches/4.0-regwrite/source/lib/registry/local.c
===================================================================
--- branches/4.0-regwrite/source/lib/registry/local.c	2007-08-26 12:46:40 UTC (rev 24663)
+++ branches/4.0-regwrite/source/lib/registry/local.c	2007-08-26 14:03:29 UTC (rev 24664)
@@ -76,18 +76,19 @@
 {
 	char *orig = talloc_strdup(mem_ctx, path),
 		 *curbegin = orig, 
-		 *curend = strchr(path, '\\');
+		 *curend = strchr(orig, '\\');
 	struct local_key *local_parent = talloc_get_type(parent, struct local_key);
 	struct hive_key *curkey = local_parent->hive_key;
 	WERROR error;
 	const char **elements = NULL;
 	int el;
 
-	if (elements != NULL) {
+	if (local_parent->path.elements != NULL) {
 		elements = talloc_array(mem_ctx, const char *, 
 							str_list_length(local_parent->path.elements) + 1);
-		for (el = 0; local_parent->path.elements[el]; el++) {
-			elements[el] = local_parent->path.elements[el];
+		for (el = 0; local_parent->path.elements[el] != NULL; el++) {
+			elements[el] = talloc_reference(elements, 
+											local_parent->path.elements[el]);
 		}
 		elements[el] = NULL;
 	} else {
@@ -101,8 +102,10 @@
 		elements = talloc_realloc(mem_ctx, elements, const char *, el+2);
 		elements[el] = talloc_strdup(elements, curbegin);
 		el++;
+		elements[el] = NULL;
 		error = hive_get_key_by_name(mem_ctx, curkey, curbegin, &curkey);
 		if (!W_ERROR_IS_OK(error)) {
+			DEBUG(2, ("Opening key %s failed: %s\n", curbegin, win_errstr(error)));
 			talloc_free(orig);
 			return error;
 		}
@@ -167,15 +170,17 @@
 	const char **elements;
 	int i;
 
+	SMB_ASSERT(strchr(name, '\\') == NULL);
+
 	W_ERROR_NOT_OK_RETURN(hive_key_add_name(mem_ctx, local_parent->hive_key, 
 										name, key_class, security, &hivekey));
 
 	if (local_parent->path.elements != NULL) {
 		elements = talloc_array(hivekey, const char *, 
-								 str_list_length(local_parent->path.elements)+2);
+								str_list_length(local_parent->path.elements)+2);
 		for (i = 0; local_parent->path.elements[i] != NULL; i++) {
 			elements[i] = talloc_reference(elements, 
-												local_parent->path.elements[i]);
+										   local_parent->path.elements[i]);
 		}
 	} else {
 		elements = talloc_array(hivekey, const char *, 2);

Modified: branches/4.0-regwrite/source/lib/registry/samba.c
===================================================================
--- branches/4.0-regwrite/source/lib/registry/samba.c	2007-08-26 12:46:40 UTC (rev 24663)
+++ branches/4.0-regwrite/source/lib/registry/samba.c	2007-08-26 14:03:29 UTC (rev 24664)
@@ -62,6 +62,8 @@
 	mount_samba_hive(*ctx, session_info, credentials, 
 					 "hkcr", HKEY_CLASSES_ROOT);
 
+	/* FIXME: Should be mounted from NTUSER.DAT in the home directory of the 
+	 * current user */
 	mount_samba_hive(*ctx, session_info, credentials, 
 					 "hkcu", HKEY_CURRENT_USER);
 

Modified: branches/4.0-regwrite/source/lib/registry/tests/registry.c
===================================================================
--- branches/4.0-regwrite/source/lib/registry/tests/registry.c	2007-08-26 12:46:40 UTC (rev 24663)
+++ branches/4.0-regwrite/source/lib/registry/tests/registry.c	2007-08-26 14:03:29 UTC (rev 24664)
@@ -96,17 +96,19 @@
 	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\\bla\\bloe", 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");
 
-	error = reg_open_key(tctx, root, "bla\\bloe", &result2);
-	torture_assert_werr_ok(tctx, error, 
-						   "opening key");
+	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;
 }
 

Modified: branches/4.0-regwrite/source/lib/registry/util.c
===================================================================
--- branches/4.0-regwrite/source/lib/registry/util.c	2007-08-26 12:46:40 UTC (rev 24663)
+++ branches/4.0-regwrite/source/lib/registry/util.c	2007-08-26 14:03:29 UTC (rev 24664)
@@ -151,14 +151,16 @@
 	int predeflength;
 	char *predefname;
 
-	if(strchr(name, '\\')) predeflength = strchr(name, '\\')-name;
-	else predeflength = strlen(name);
+	if (strchr(name, '\\') != NULL) 
+		predeflength = strchr(name, '\\')-name;
+	else 
+		predeflength = strlen(name);
 
 	predefname = talloc_strndup(mem_ctx, name, predeflength);
 	error = reg_get_predefined_key_by_name(handle, predefname, &predef);
 	talloc_free(predefname);
 
-	if(!W_ERROR_IS_OK(error)) {
+	if (!W_ERROR_IS_OK(error)) {
 		return error;
 	}
 
@@ -181,14 +183,14 @@
 		return WERR_FOOBAR;
 	}
 	
-	parent_name = talloc_strndup(mem_ctx, path, strrchr(path, '\\')-1-path);
+	parent_name = talloc_strndup(mem_ctx, path, strrchr(path, '\\')-path);
 
 	error = reg_open_key_abs(mem_ctx, ctx, parent_name, parent);
 	if (!W_ERROR_IS_OK(error)) {
 		return error;
 	}
 	
-	*name = talloc_strdup(mem_ctx, strchr(path, '\\')+1);
+	*name = talloc_strdup(mem_ctx, strrchr(path, '\\')+1);
 
 	return WERR_OK;
 }
@@ -215,7 +217,9 @@
 }
 
 WERROR reg_key_add_abs(TALLOC_CTX *mem_ctx, struct registry_context *ctx, 
-					   const char *path, uint32_t access_mask, struct security_descriptor *sec_desc, struct registry_key **result)
+					   const char *path, uint32_t access_mask, 
+					   struct security_descriptor *sec_desc, 
+					   struct registry_key **result)
 {
 	struct registry_key *parent;
 	const char *n;
@@ -226,9 +230,13 @@
 	}
 	
 	error = get_abs_parent(mem_ctx, ctx, path, &parent, &n);
-	if (W_ERROR_IS_OK(error)) {
-		error = reg_key_add_name(mem_ctx, parent, n, NULL, sec_desc, result);
+	if (!W_ERROR_IS_OK(error)) {
+		DEBUG(2, ("Opening parent of %s failed with %s\n", path, 
+				  win_errstr(error)));
+		return error;
 	}
 
+	error = reg_key_add_name(mem_ctx, parent, n, NULL, sec_desc, result);
+
 	return error;
 }



More information about the samba-cvs mailing list