[SCM] Samba Shared Repository - branch master updated

Matthias Dieter Wallnöfer mdw at samba.org
Thu Jul 1 07:48:30 MDT 2010


The branch, master has been updated
       via  de8a339... s4:registry - move some common constraint checks to the "local" backend
       via  d81e2af... s4:lib/registry/tests/registry.c - test recursive key generation
       via  ae50385... s4:registry - on key add operations we have to handle with paths not always only a name
       via  781ea5b... s4:lib/registry/local.c - support recursive key generation
       via  809c747... s4:lib/registry/ldb.c - refactor "reg_path_to_ldb"
       via  50ae292... s4:lib/registry/ldb.c - use "ldb_path" rather than "ldap_path" as LDB key varibale identifiers
       via  d0e877e... s4:lib/registry/ldb.c - "ldb_add_key" - fix talloc handling
      from  e4ba8fb... s3-printing: Fix Bug #7541, %D in "printer admin" causing smbd crash.

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit de8a339cdf95f6737a8b1d34aa2aa9287bae0e46
Author: Matthias Dieter Wallnöfer <mdw at samba.org>
Date:   Tue Jun 29 16:10:32 2010 +0200

    s4:registry - move some common constraint checks to the "local" backend
    
    They should also be enforced when we don't use "ldb".

commit d81e2af69de4401335681d859c44b2c30fb4456c
Author: Matthias Dieter Wallnöfer <mdw at samba.org>
Date:   Tue Jun 29 18:27:49 2010 +0200

    s4:lib/registry/tests/registry.c - test recursive key generation

commit ae50385d524d8cb4831d8eb0c45feb4d04437f28
Author: Matthias Dieter Wallnöfer <mdw at samba.org>
Date:   Tue Jun 29 18:08:47 2010 +0200

    s4:registry - on key add operations we have to handle with paths not always only a name
    
    Recursive key generations are allowed.

commit 781ea5be1399de8abe201ab239d3915331264deb
Author: Matthias Dieter Wallnöfer <mdw at samba.org>
Date:   Tue Jun 29 15:45:37 2010 +0200

    s4:lib/registry/local.c - support recursive key generation
    
    Code taken from "local_open_key".

commit 809c74790006c985ac64eb7823a4a450498c832f
Author: Matthias Dieter Wallnöfer <mdw at samba.org>
Date:   Thu Jun 24 21:12:19 2010 +0200

    s4:lib/registry/ldb.c - refactor "reg_path_to_ldb"
    
    This makes it easier to understand and would also support splitting in more
    DN components.

commit 50ae292e60e53275f87ad2281b25eda34d0af59c
Author: Matthias Dieter Wallnöfer <mdw at samba.org>
Date:   Tue Jun 29 17:37:45 2010 +0200

    s4:lib/registry/ldb.c - use "ldb_path" rather than "ldap_path" as LDB key varibale identifiers

commit d0e877e785f6463dadbb973bc42174674cbdbad2
Author: Matthias Dieter Wallnöfer <mdw at samba.org>
Date:   Tue Jun 29 15:52:19 2010 +0200

    s4:lib/registry/ldb.c - "ldb_add_key" - fix talloc handling
    
    - free "msg" when possible
    - prevent "talloc_strdup"s where not necessary

-----------------------------------------------------------------------

Summary of changes:
 source4/lib/registry/interface.c      |    4 +-
 source4/lib/registry/ldb.c            |  112 ++++++++++++++------------------
 source4/lib/registry/local.c          |  115 ++++++++++++++++++++++-----------
 source4/lib/registry/registry.h       |    2 +-
 source4/lib/registry/rpc.c            |    4 +-
 source4/lib/registry/tests/registry.c |   11 +--
 6 files changed, 132 insertions(+), 116 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source4/lib/registry/interface.c b/source4/lib/registry/interface.c
index c5d5ce8..07e606d 100644
--- a/source4/lib/registry/interface.c
+++ b/source4/lib/registry/interface.c
@@ -202,7 +202,7 @@ _PUBLIC_ WERROR reg_key_del(TALLOC_CTX *mem_ctx, struct registry_key *parent,
  */
 _PUBLIC_ WERROR reg_key_add_name(TALLOC_CTX *mem_ctx,
 				 struct registry_key *parent,
-				 const char *name, const char *key_class,
+				 const char *path, const char *key_class,
 				 struct security_descriptor *desc,
 				 struct registry_key **newkey)
 {
@@ -215,7 +215,7 @@ _PUBLIC_ WERROR reg_key_add_name(TALLOC_CTX *mem_ctx,
 		return WERR_NOT_SUPPORTED;
 	}
 
-	return parent->context->ops->create_key(mem_ctx, parent, name,
+	return parent->context->ops->create_key(mem_ctx, parent, path,
 						key_class, desc, newkey);
 }
 
diff --git a/source4/lib/registry/ldb.c b/source4/lib/registry/ldb.c
index 2b08445..122f565 100644
--- a/source4/lib/registry/ldb.c
+++ b/source4/lib/registry/ldb.c
@@ -277,44 +277,46 @@ static struct ldb_dn *reg_path_to_ldb(TALLOC_CTX *mem_ctx,
 				      const char *path, const char *add)
 {
 	struct ldb_dn *ret;
-	char *mypath = talloc_strdup(mem_ctx, path);
+	char *mypath;
 	char *begin;
 	struct ldb_key_data *kd = talloc_get_type(from, struct ldb_key_data);
 	struct ldb_context *ldb = kd->ldb;
 
+	mypath = talloc_strdup(mem_ctx, path);
+	if (mypath == NULL) {
+		return NULL;
+	}
+
 	ret = ldb_dn_new(mem_ctx, ldb, add);
 	if (!ldb_dn_validate(ret)) {
 		talloc_free(ret);
 		return NULL;
 	}
 
-	while (mypath) {
-		char *keyname;
-
-		begin = strrchr(mypath, '\\');
+	if (!ldb_dn_add_base(ret, kd->dn)) {
+		talloc_free(ret);
+		return NULL;
+	}
 
-		if (begin) keyname = begin + 1;
-		else keyname = mypath;
+	while (mypath[0] != '\0') {
+		begin = strchr(mypath, '\\');
+		if (begin != NULL) {
+			*begin = '\0';
+		}
 
-		if (keyname[0] != '\0') {
-			if (!ldb_dn_add_base_fmt(ret, "key=%s",
-						 reg_ldb_escape(mem_ctx,
-								keyname)))
-			{
-				talloc_free(ret);
-				return NULL;
-			}
+		if (!ldb_dn_add_child_fmt(ret, "key=%s",
+					  reg_ldb_escape(mem_ctx, mypath))) {
+			talloc_free(ret);
+			return NULL;
 		}
 
-		if(begin) {
-			*begin = '\0';
+		if (begin != NULL) {
+			mypath = begin + 1;
 		} else {
 			break;
 		}
 	}
 
-	ldb_dn_add_base(ret, kd->dn);
-
 	return ret;
 }
 
@@ -464,10 +466,6 @@ static WERROR ldb_get_value(TALLOC_CTX *mem_ctx, struct hive_key *k,
 	const char *res_name;
 	uint32_t idx;
 
-	if (name == NULL) {
-		return WERR_INVALID_PARAM;
-	}
-
 	/* the default value was requested, give it back */
 	if (name[0] == '\0') {
 		return ldb_get_default_value(mem_ctx, k, NULL, data_type, data);
@@ -495,28 +493,24 @@ static WERROR ldb_open_key(TALLOC_CTX *mem_ctx, const struct hive_key *h,
 			   const char *name, struct hive_key **key)
 {
 	struct ldb_result *res;
-	struct ldb_dn *ldap_path;
+	struct ldb_dn *ldb_path;
 	int ret;
 	struct ldb_key_data *newkd;
 	struct ldb_key_data *kd = talloc_get_type(h, struct ldb_key_data);
 	struct ldb_context *c = kd->ldb;
 
-	if (name == NULL) {
-		return WERR_INVALID_PARAM;
-	}
-
-	ldap_path = reg_path_to_ldb(mem_ctx, h, name, NULL);
-	W_ERROR_HAVE_NO_MEMORY(ldap_path);
+	ldb_path = reg_path_to_ldb(mem_ctx, h, name, NULL);
+	W_ERROR_HAVE_NO_MEMORY(ldb_path);
 
-	ret = ldb_search(c, mem_ctx, &res, ldap_path, LDB_SCOPE_BASE, NULL, "(key=*)");
+	ret = ldb_search(c, mem_ctx, &res, ldb_path, LDB_SCOPE_BASE, NULL, "(key=*)");
 
 	if (ret != LDB_SUCCESS) {
 		DEBUG(3, ("Error opening key '%s': %s\n",
-			ldb_dn_get_linearized(ldap_path), ldb_errstring(c)));
+			ldb_dn_get_linearized(ldb_path), ldb_errstring(c)));
 		return WERR_FOOBAR;
 	} else if (res->count == 0) {
 		DEBUG(3, ("Key '%s' not found\n",
-			ldb_dn_get_linearized(ldap_path)));
+			ldb_dn_get_linearized(ldb_path)));
 		talloc_free(res);
 		return WERR_BADFILE;
 	}
@@ -586,26 +580,28 @@ static WERROR ldb_add_key(TALLOC_CTX *mem_ctx, const struct hive_key *parent,
 			  struct hive_key **newkey)
 {
 	struct ldb_key_data *parentkd = discard_const_p(struct ldb_key_data, parent);
+	struct ldb_dn *ldb_path;
 	struct ldb_message *msg;
 	struct ldb_key_data *newkd;
 	int ret;
 
-	if (name == NULL) {
-		return WERR_INVALID_PARAM;
-	}
+	ldb_path = reg_path_to_ldb(mem_ctx, parent, name, NULL);
+	W_ERROR_HAVE_NO_MEMORY(ldb_path);
 
 	msg = ldb_msg_new(mem_ctx);
 	W_ERROR_HAVE_NO_MEMORY(msg);
 
-	msg->dn = reg_path_to_ldb(msg, parent, name, NULL);
-	W_ERROR_HAVE_NO_MEMORY(msg->dn);
+	msg->dn = ldb_path;
 
-	ldb_msg_add_string(msg, "key", talloc_strdup(mem_ctx, name));
-	if (classname != NULL)
-		ldb_msg_add_string(msg, "classname",
-				   talloc_strdup(mem_ctx, classname));
+	ldb_msg_add_string(msg, "key", name);
+	if (classname != NULL) {
+		ldb_msg_add_string(msg, "classname", classname);
+	}
 
 	ret = ldb_add(parentkd->ldb, msg);
+
+	talloc_free(msg);
+
 	if (ret == LDB_ERR_ENTRY_ALREADY_EXISTS) {
 		return WERR_ALREADY_EXISTS;
 	}
@@ -615,13 +611,13 @@ static WERROR ldb_add_key(TALLOC_CTX *mem_ctx, const struct hive_key *parent,
 		return WERR_FOOBAR;
 	}
 
-	DEBUG(2, ("key added: %s\n", ldb_dn_get_linearized(msg->dn)));
+	DEBUG(2, ("key added: %s\n", ldb_dn_get_linearized(ldb_path)));
 
 	newkd = talloc_zero(mem_ctx, struct ldb_key_data);
 	W_ERROR_HAVE_NO_MEMORY(newkd);
 	newkd->ldb = talloc_reference(newkd, parentkd->ldb);
 	newkd->key.ops = &reg_backend_ldb;
-	newkd->dn = talloc_steal(newkd, msg->dn);
+	newkd->dn = talloc_steal(newkd, ldb_path);
 	newkd->classname = talloc_steal(newkd, classname);
 
 	*newkey = (struct hive_key *)newkd;
@@ -641,10 +637,6 @@ static WERROR ldb_del_value(TALLOC_CTX *mem_ctx, struct hive_key *key,
 	struct ldb_message *msg;
 	struct ldb_dn *childdn;
 
-	if (child == NULL) {
-		return WERR_INVALID_PARAM;
-	}
-
 	if (child[0] == '\0') {
 		/* default value */
 		msg = talloc_zero(mem_ctx, struct ldb_message);
@@ -694,43 +686,39 @@ static WERROR ldb_del_key(TALLOC_CTX *mem_ctx, const struct hive_key *key,
 	unsigned int i;
 	int ret;
 	struct ldb_key_data *parentkd = talloc_get_type(key, struct ldb_key_data);
-	struct ldb_dn *ldap_path;
+	struct ldb_dn *ldb_path;
 	struct ldb_context *c = parentkd->ldb;
 	struct ldb_result *res_keys;
 	struct ldb_result *res_vals;
 	WERROR werr;
 	struct hive_key *hk;
 
-	if (name == NULL) {
-		return WERR_INVALID_PARAM;
-	}
-
 	/* Verify key exists by opening it */
 	werr = ldb_open_key(mem_ctx, key, name, &hk);
 	if (!W_ERROR_IS_OK(werr)) {
 		return werr;
 	}
 
-	ldap_path = reg_path_to_ldb(mem_ctx, key, name, NULL);
-	W_ERROR_HAVE_NO_MEMORY(ldap_path);
+	ldb_path = reg_path_to_ldb(mem_ctx, key, name, NULL);
+	W_ERROR_HAVE_NO_MEMORY(ldb_path);
 
 	/* Search for subkeys */
-	ret = ldb_search(c, mem_ctx, &res_keys, ldap_path, LDB_SCOPE_ONELEVEL,
+	ret = ldb_search(c, mem_ctx, &res_keys, ldb_path, LDB_SCOPE_ONELEVEL,
 			 NULL, "(key=*)");
 
 	if (ret != LDB_SUCCESS) {
 		DEBUG(0, ("Error getting subkeys for '%s': %s\n",
-		      ldb_dn_get_linearized(ldap_path), ldb_errstring(c)));
+		      ldb_dn_get_linearized(ldb_path), ldb_errstring(c)));
 		return WERR_FOOBAR;
 	}
 
 	/* Search for values */
-	ret = ldb_search(c, mem_ctx, &res_vals, ldap_path, LDB_SCOPE_ONELEVEL,
+	ret = ldb_search(c, mem_ctx, &res_vals, ldb_path, LDB_SCOPE_ONELEVEL,
 			 NULL, "(value=*)");
 
 	if (ret != LDB_SUCCESS) {
 		DEBUG(0, ("Error getting values for '%s': %s\n",
-		      ldb_dn_get_linearized(ldap_path), ldb_errstring(c)));
+		      ldb_dn_get_linearized(ldb_path), ldb_errstring(c)));
 		return WERR_FOOBAR;
 	}
 
@@ -772,7 +760,7 @@ static WERROR ldb_del_key(TALLOC_CTX *mem_ctx, const struct hive_key *key,
 	}
 
 	/* Delete the key itself */
-	ret = ldb_delete(c, ldap_path);
+	ret = ldb_delete(c, ldb_path);
 
 	if (ret != LDB_SUCCESS)
 	{
@@ -808,10 +796,6 @@ static WERROR ldb_set_value(struct hive_key *parent,
 	int ret;
 	TALLOC_CTX *mem_ctx = talloc_init("ldb_set_value");
 
-	if (name == NULL) {
-		return WERR_INVALID_PARAM;
-	}
-
 	msg = reg_ldb_pack_value(kd->ldb, mem_ctx, name, type, data);
 	W_ERROR_HAVE_NO_MEMORY(msg);
 
diff --git a/source4/lib/registry/local.c b/source4/lib/registry/local.c
index be48729..9879174 100644
--- a/source4/lib/registry/local.c
+++ b/source4/lib/registry/local.c
@@ -80,6 +80,10 @@ static WERROR local_open_key(TALLOC_CTX *mem_ctx,
 	const char **elements = NULL;
 	int el;
 
+	if (path == NULL) {
+		return WERR_INVALID_PARAM;
+	}
+
 	orig = talloc_strdup(mem_ctx, path);
 	W_ERROR_HAVE_NO_MEMORY(orig);
 	curbegin = orig;
@@ -166,58 +170,75 @@ static WERROR local_enum_key(TALLOC_CTX *mem_ctx,
 }
 
 static WERROR local_create_key(TALLOC_CTX *mem_ctx,
-			       struct registry_key *parent_key,
-			       const char *name,
+			       struct registry_key *parent,
+			       const char *path,
 			       const char *key_class,
 			       struct security_descriptor *security,
-			       struct registry_key **key)
+			       struct registry_key **result)
 {
-	struct local_key *local_parent;
-	struct hive_key *hivekey;
-	const char **elements;
-	unsigned int i;
-	const char *last_part;
-	char *trunc_name;
-
-	last_part = strrchr(name, '\\');
-	if (last_part == NULL) {
-		last_part = name;
-		local_parent = (struct local_key *)parent_key;
-	} else {
-		trunc_name = talloc_strndup(mem_ctx, name, last_part - name);
-		W_ERROR_HAVE_NO_MEMORY(trunc_name);
-		W_ERROR_NOT_OK_RETURN(reg_open_key(mem_ctx, parent_key,
-						   trunc_name,
-						   (struct registry_key **)&local_parent));
-		talloc_free(trunc_name);
-		last_part++;
+	char *orig, *curbegin, *curend;
+	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 (path == NULL) {
+		return WERR_INVALID_PARAM;
 	}
 
-	W_ERROR_NOT_OK_RETURN(hive_key_add_name(mem_ctx, local_parent->hive_key,
-						last_part, key_class, security,
-						&hivekey));
+	orig = talloc_strdup(mem_ctx, path);
+	W_ERROR_HAVE_NO_MEMORY(orig);
+	curbegin = orig;
+	curend = strchr(orig, '\\');
 
 	if (local_parent->path.elements != NULL) {
-		elements = talloc_array(hivekey, const char *,
-					str_list_length(local_parent->path.elements)+2);
+		elements = talloc_array(mem_ctx, const char *,
+					str_list_length(local_parent->path.elements) + 1);
 		W_ERROR_HAVE_NO_MEMORY(elements);
-		for (i = 0; local_parent->path.elements[i] != NULL; i++) {
-			elements[i] = talloc_reference(elements,
-						       local_parent->path.elements[i]);
+		for (el = 0; local_parent->path.elements[el] != NULL; el++) {
+			elements[el] = talloc_reference(elements,
+							local_parent->path.elements[el]);
 		}
+		elements[el] = NULL;
 	} else {
-		elements = talloc_array(hivekey, const char *, 2);
-		W_ERROR_HAVE_NO_MEMORY(elements);
-		i = 0;
+		elements = NULL;
+		el = 0;
 	}
 
-	elements[i] = talloc_strdup(elements, name);
-	W_ERROR_HAVE_NO_MEMORY(elements[i]);
-	elements[i+1] = NULL;
+	while (curbegin != NULL && *curbegin) {
+		if (curend != NULL)
+			*curend = '\0';
+		elements = talloc_realloc(mem_ctx, elements, const char *, el+2);
+		W_ERROR_HAVE_NO_MEMORY(elements);
+		elements[el] = talloc_strdup(elements, curbegin);
+		W_ERROR_HAVE_NO_MEMORY(elements[el]);
+		el++;
+		elements[el] = NULL;
+		error = hive_get_key_by_name(mem_ctx, curkey,
+					     curbegin, &curkey);
+		if (W_ERROR_EQUAL(error, WERR_BADFILE)) {
+			error = hive_key_add_name(mem_ctx, curkey, curbegin,
+						  key_class, security,
+						  &curkey);
+		}
+		if (!W_ERROR_IS_OK(error)) {
+			DEBUG(2, ("Open/Creation of key %s failed: %s\n",
+				curbegin, win_errstr(error)));
+			talloc_free(orig);
+			return error;
+		}
+		if (curend == NULL)
+			break;
+		curbegin = curend + 1;
+		curend = strchr(curbegin, '\\');
+	}
+	talloc_free(orig);
 
-	*key = reg_import_hive_key(local_parent->global.context, hivekey,
-				   local_parent->path.predefined_key,
-				   elements);
+	*result = reg_import_hive_key(local_parent->global.context, curkey,
+				      local_parent->path.predefined_key,
+				      talloc_steal(curkey, elements));
 
 	return WERR_OK;
 }
@@ -227,6 +248,10 @@ static WERROR local_set_value(struct registry_key *key, const char *name,
 {
 	struct local_key *local = (struct local_key *)key;
 
+	if (name == NULL) {
+		return WERR_INVALID_PARAM;
+	}
+
 	return hive_key_set_value(local->hive_key, name, type, data);
 }
 
@@ -236,6 +261,10 @@ static WERROR local_get_value(TALLOC_CTX *mem_ctx,
 {
 	const struct local_key *local = (const struct local_key *)key;
 
+	if (name == NULL) {
+		return WERR_INVALID_PARAM;
+	}
+
 	return hive_get_value(mem_ctx, local->hive_key, name, type, data);
 }
 
@@ -256,6 +285,10 @@ static WERROR local_delete_key(TALLOC_CTX *mem_ctx, struct registry_key *key,
 {
 	const struct local_key *local = (const struct local_key *)key;
 
+	if (name == NULL) {
+		return WERR_INVALID_PARAM;
+	}
+
 	return hive_key_del(mem_ctx, local->hive_key, name);
 }
 
@@ -264,6 +297,10 @@ static WERROR local_delete_value(TALLOC_CTX *mem_ctx, struct registry_key *key,
 {
 	const struct local_key *local = (const struct local_key *)key;
 
+	if (name == NULL) {
+		return WERR_INVALID_PARAM;
+	}
+
 	return hive_key_del_value(mem_ctx, local->hive_key, name);
 }
 
diff --git a/source4/lib/registry/registry.h b/source4/lib/registry/registry.h
index 7624752..8fc0257 100644
--- a/source4/lib/registry/registry.h
+++ b/source4/lib/registry/registry.h
@@ -69,7 +69,7 @@ struct hive_operations {
 	 * Add a new key.
 	 */
 	WERROR (*add_key) (TALLOC_CTX *ctx,
-			   const struct hive_key *parent_key, const char *name,
+			   const struct hive_key *parent_key, const char *path,
 			   const char *classname,
 			   struct security_descriptor *desc,
 			   struct hive_key **key);
diff --git a/source4/lib/registry/rpc.c b/source4/lib/registry/rpc.c
index 7948f7c..bc49045 100644
--- a/source4/lib/registry/rpc.c
+++ b/source4/lib/registry/rpc.c
@@ -331,7 +331,7 @@ static WERROR rpc_get_subkey_by_index(TALLOC_CTX *mem_ctx,
 }
 
 static WERROR rpc_add_key(TALLOC_CTX *mem_ctx,
-			  struct registry_key *parent, const char *name,
+			  struct registry_key *parent, const char *path,
 			  const char *key_class,
 			  struct security_descriptor *sec,
 			  struct registry_key **key)
@@ -344,7 +344,7 @@ static WERROR rpc_add_key(TALLOC_CTX *mem_ctx,
 
 	ZERO_STRUCT(r);
 	r.in.handle = &parentkd->pol;
-	r.in.name.name = name;
+	r.in.name.name = path;
 	r.in.keyclass.name = NULL;
 	r.in.options = 0;
 	r.in.access_mask = 0x02000000;
diff --git a/source4/lib/registry/tests/registry.c b/source4/lib/registry/tests/registry.c
index 1bb2039..3003468 100644
--- a/source4/lib/registry/tests/registry.c
+++ b/source4/lib/registry/tests/registry.c
@@ -117,22 +117,17 @@ static bool test_create_subkey(struct torture_context *tctx, void *_data)
 static bool test_create_nested_subkey(struct torture_context *tctx, void *_data)
 {
 	struct registry_context *rctx = (struct registry_context *)_data;
-	struct registry_key *root, *newkey1, *newkey2;
+	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,


-- 
Samba Shared Repository


More information about the samba-cvs mailing list