[SCM] Samba Shared Repository - branch master updated

Günther Deschner gd at samba.org
Fri Jul 2 02:50:48 MDT 2010


The branch, master has been updated
       via  d9429a8... s3-registry: remove 2 byte winreg type limitation.
       via  ddb8fae... s3-registry: allow to read NULL entries (that we allow to store) back from the tdb.
       via  6da0402... s4-smbtorture: enable extended SetValue test against Samba3.
       via  786198e... s3-registry: remove unused reg_util_marshalling code.
       via  b381fba... s3-registry: avoid using registry_value union.
      from  84c5dd1... s4-ldb: fixed error handling in openldap backend

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


- Log -----------------------------------------------------------------
commit d9429a874c5bd463f4b89db55fdae14b1764a494
Author: Günther Deschner <gd at samba.org>
Date:   Thu Jul 1 11:22:20 2010 +0200

    s3-registry: remove 2 byte winreg type limitation.
    
    We already pull and push 4 byte winreg type in the registry.tdb, we were just
    not using full 4 bytes within the reg_object functions.
    
    With this change we finally pass the set extended value torture test.
    
    Guenther

commit ddb8fae40174c72be8b3b6fc1c67cbaad3343153
Author: Günther Deschner <gd at samba.org>
Date:   Thu Jul 1 15:50:58 2010 +0200

    s3-registry: allow to read NULL entries (that we allow to store) back from the tdb.
    
    Guenther

commit 6da040261debcbd4b193caf9d5a055efad898aca
Author: Günther Deschner <gd at samba.org>
Date:   Thu Jul 1 03:04:39 2010 +0200

    s4-smbtorture: enable extended SetValue test against Samba3.
    
    Guenther

commit 786198e523257de75d9238cd993594e5f8a8a4b7
Author: Günther Deschner <gd at samba.org>
Date:   Thu Jul 1 02:57:19 2010 +0200

    s3-registry: remove unused reg_util_marshalling code.
    
    Guenther

commit b381fba0892021f164223bae8b0951014a28735e
Author: Günther Deschner <gd at samba.org>
Date:   Tue Jun 29 16:13:15 2010 +0200

    s3-registry: avoid using registry_value union.
    
    Just pull and push data as is.
    
    Guenther

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

Summary of changes:
 libgpo/gpext/gpext.c                    |   13 +-
 source3/Makefile.in                     |    3 -
 source3/include/registry.h              |   22 +---
 source3/lib/smbconf/smbconf_reg.c       |   68 +++++++---
 source3/libgpo/gpext/registry.c         |   21 +--
 source3/libgpo/gpext/scripts.c          |    8 +-
 source3/libgpo/gpo_reg.c                |   78 +++++++----
 source3/registry/reg_api.c              |   24 +---
 source3/registry/reg_backend_db.c       |    8 +-
 source3/registry/reg_objects.c          |    6 +-
 source3/registry/reg_objects.h          |    4 +-
 source3/registry/reg_util_marshalling.c |  216 -------------------------------
 source3/registry/reg_util_marshalling.h |   32 -----
 source3/rpc_server/srv_eventlog_nt.c    |   13 ++-
 source3/rpc_server/srv_winreg_nt.c      |   51 +++-----
 source3/utils/net_registry.c            |   40 +++++-
 source3/utils/net_registry_util.c       |   30 ++++-
 source3/utils/net_rpc_registry.c        |   54 ++++-----
 source3/wscript_build                   |    2 -
 source4/torture/rpc/winreg.c            |    5 +-
 20 files changed, 242 insertions(+), 456 deletions(-)
 delete mode 100644 source3/registry/reg_util_marshalling.c
 delete mode 100644 source3/registry/reg_util_marshalling.h


Changeset truncated at 500 lines:

diff --git a/libgpo/gpext/gpext.c b/libgpo/gpext/gpext.c
index 865a725..9a09337 100644
--- a/libgpo/gpext/gpext.c
+++ b/libgpo/gpext/gpext.c
@@ -281,13 +281,16 @@ static NTSTATUS gp_ext_info_add_reg(TALLOC_CTX *mem_ctx,
 	switch (type) {
 		case REG_SZ:
 		case REG_EXPAND_SZ:
-			data->v.sz.str = talloc_strdup(mem_ctx, data_s);
-			NT_STATUS_HAVE_NO_MEMORY(data->v.sz.str);
-			data->v.sz.len = strlen(data_s);
+			if (!push_reg_sz(mem_ctx, &data->data, data_s)) {
+				return NT_STATUS_NO_MEMORY;
+			}
 			break;
-		case REG_DWORD:
-			data->v.dword = atoi(data_s);
+		case REG_DWORD: {
+			uint32_t v = atoi(data_s);
+			data->data = data_blob_talloc(mem_ctx, NULL, 4);
+			SIVAL(data->data.data, 0, v);
 			break;
+		}
 		default:
 			return NT_STATUS_NOT_SUPPORTED;
 	}
diff --git a/source3/Makefile.in b/source3/Makefile.in
index 905ab4c..afca6c3 100644
--- a/source3/Makefile.in
+++ b/source3/Makefile.in
@@ -563,8 +563,6 @@ LIBMSRPC_GEN_OBJ = librpc/gen_ndr/cli_lsa.o \
 #
 UTIL_REG_OBJ = ../libcli/registry/util_reg.o
 
-REG_UTIL_MARSHALLING_OBJ = registry/reg_util_marshalling.o
-
 REG_INIT_BASIC_OBJ = registry/reg_init_basic.o
 REG_INIT_SMBCONF_OBJ = registry/reg_init_smbconf.o
 REG_INIT_FULL_OBJ = registry/reg_init_full.o
@@ -592,7 +590,6 @@ REG_BASE_OBJ = registry/reg_api.o \
 	       $(REGFIO_OBJ) \
 	       $(REGOBJS_OBJ) \
 	       registry/reg_util_internal.o \
-	       $(REG_UTIL_MARSHALLING_OBJ) \
 	       lib/util_nttoken.o \
 	       $(REG_BACKENDS_BASE_OBJ) \
 	       $(REG_INIT_BASIC_OBJ)
diff --git a/source3/include/registry.h b/source3/include/registry.h
index 00c27cf..9e7a1d2 100644
--- a/source3/include/registry.h
+++ b/source3/include/registry.h
@@ -23,29 +23,9 @@
 #ifndef _REGISTRY_H
 #define _REGISTRY_H
 
-/*
- * A REG_SZ string is not necessarily NULL terminated. When retrieving it from
- * the net, we guarantee this however. A server might want to push it without
- * the terminator though.
- */
-
-struct registry_string {
-	size_t len;
-	char *str;
-};
-
 struct registry_value {
 	enum winreg_Type type;
-	union {
-		uint32 dword;
-		uint64 qword;
-		struct registry_string sz;
-		struct {
-			uint32 num_strings;
-			char **strings;
-		} multi_sz;
-		DATA_BLOB binary;
-	} v;
+	DATA_BLOB data;
 };
 
 /* forward declarations. definitions in reg_objects.c */
diff --git a/source3/lib/smbconf/smbconf_reg.c b/source3/lib/smbconf/smbconf_reg.c
index 4aa3c09..08d559b 100644
--- a/source3/lib/smbconf/smbconf_reg.c
+++ b/source3/lib/smbconf/smbconf_reg.c
@@ -208,8 +208,10 @@ static WERROR smbconf_reg_set_value(struct registry_key *key,
 	ZERO_STRUCT(val);
 
 	val.type = REG_SZ;
-	val.v.sz.str = CONST_DISCARD(char *, canon_valstr);
-	val.v.sz.len = strlen(canon_valstr) + 1;
+	if (!push_reg_sz(talloc_tos(), &val.data, canon_valstr)) {
+		werr = WERR_NOMEM;
+		goto done;
+	}
 
 	werr = reg_setvalue(key, canon_valname, &val);
 	if (!W_ERROR_IS_OK(werr)) {
@@ -231,31 +233,40 @@ static WERROR smbconf_reg_set_multi_sz_value(struct registry_key *key,
 	struct registry_value *value;
 	uint32_t count;
 	TALLOC_CTX *tmp_ctx = talloc_stackframe();
+	const char **array;
 
 	if (strings == NULL) {
 		werr = WERR_INVALID_PARAM;
 		goto done;
 	}
 
-	value = TALLOC_ZERO_P(tmp_ctx, struct registry_value);
+	array = talloc_zero_array(tmp_ctx, const char *, num_strings + 1);
+	if (array == NULL) {
+		werr = WERR_NOMEM;
+		goto done;
+	}
 
-	value->type = REG_MULTI_SZ;
-	value->v.multi_sz.num_strings = num_strings;
-	value->v.multi_sz.strings = TALLOC_ARRAY(tmp_ctx, char *, num_strings);
-	if (value->v.multi_sz.strings == NULL) {
+	value = TALLOC_ZERO_P(tmp_ctx, struct registry_value);
+	if (value == NULL) {
 		werr = WERR_NOMEM;
 		goto done;
 	}
+
+	value->type = REG_MULTI_SZ;
+
 	for (count = 0; count < num_strings; count++) {
-		value->v.multi_sz.strings[count] =
-			talloc_strdup(value->v.multi_sz.strings,
-				      strings[count]);
-		if (value->v.multi_sz.strings[count] == NULL) {
+		array[count] = talloc_strdup(value, strings[count]);
+		if (array[count] == NULL) {
 			werr = WERR_NOMEM;
 			goto done;
 		}
 	}
 
+	if (!push_reg_multi_sz(value, &value->data, array)) {
+		werr = WERR_NOMEM;
+		goto done;
+	}
+
 	werr = reg_setvalue(key, valname, value);
 	if (!W_ERROR_IS_OK(werr)) {
 		DEBUG(5, ("Error adding value '%s' to key '%s': %s\n",
@@ -286,18 +297,30 @@ static char *smbconf_format_registry_value(TALLOC_CTX *mem_ctx,
 
 	switch (value->type) {
 	case REG_DWORD:
-		result = talloc_asprintf(mem_ctx, "%d", value->v.dword);
+		if (value->data.length >= 4) {
+			uint32_t v = IVAL(value->data.data, 0);
+			result = talloc_asprintf(mem_ctx, "%d", v);
+		}
 		break;
 	case REG_SZ:
-	case REG_EXPAND_SZ:
-		result = talloc_asprintf(mem_ctx, "%s", value->v.sz.str);
+	case REG_EXPAND_SZ: {
+		const char *s;
+		if (!pull_reg_sz(mem_ctx, &value->data, &s)) {
+			break;
+		}
+		result = talloc_strdup(mem_ctx, s);
 		break;
+	}
 	case REG_MULTI_SZ: {
 		uint32 j;
-		for (j = 0; j < value->v.multi_sz.num_strings; j++) {
+		const char **a = NULL;
+		if (!pull_reg_multi_sz(mem_ctx, &value->data, &a)) {
+			break;
+		}
+		for (j = 0; a[j] != NULL; j++) {
 			result = talloc_asprintf(mem_ctx, "%s\"%s\" ",
 						 result ? result : "" ,
-						 value->v.multi_sz.strings[j]);
+						 a[j]);
 			if (result == NULL) {
 				break;
 			}
@@ -306,7 +329,7 @@ static char *smbconf_format_registry_value(TALLOC_CTX *mem_ctx,
 	}
 	case REG_BINARY:
 		result = talloc_asprintf(mem_ctx, "binary (%d bytes)",
-					 (int)value->v.binary.length);
+					 (int)value->data.length);
 		break;
 	default:
 		result = talloc_asprintf(mem_ctx, "<unprintable>");
@@ -324,6 +347,7 @@ static WERROR smbconf_reg_get_includes_internal(TALLOC_CTX *mem_ctx,
 	uint32_t count;
 	struct registry_value *value = NULL;
 	char **tmp_includes = NULL;
+	const char **array = NULL;
 	TALLOC_CTX *tmp_ctx = talloc_stackframe();
 
 	if (!smbconf_value_exists(key, INCLUDES_VALNAME)) {
@@ -344,12 +368,16 @@ static WERROR smbconf_reg_get_includes_internal(TALLOC_CTX *mem_ctx,
 		goto done;
 	}
 
-	for (count = 0; count < value->v.multi_sz.num_strings; count++)
-	{
+	if (!pull_reg_multi_sz(tmp_ctx, &value->data, &array)) {
+		werr = WERR_NOMEM;
+		goto done;
+	}
+
+	for (count = 0; array[count] != NULL; count++) {
 		werr = smbconf_add_string_to_array(tmp_ctx,
 					&tmp_includes,
 					count,
-					value->v.multi_sz.strings[count]);
+					array[count]);
 		if (!W_ERROR_IS_OK(werr)) {
 			goto done;
 		}
diff --git a/source3/libgpo/gpext/registry.c b/source3/libgpo/gpext/registry.c
index 57840a4..a7e8a5e 100644
--- a/source3/libgpo/gpext/registry.c
+++ b/source3/libgpo/gpext/registry.c
@@ -293,24 +293,19 @@ static bool gp_reg_entry_from_file_entry(TALLOC_CTX *mem_ctx,
 
 	switch (data->type) {
 		case REG_DWORD:
-			data->v.dword = atoi((char *)file_entry->data);
+			if (file_entry->size < 4) {
+				return false;
+			}
+			data->data = data_blob_talloc(mem_ctx, NULL, 4);
+			SIVAL(data->data.data, 0, atoi((char *)file_entry->data));
 			break;
 		case REG_BINARY:
-			data->v.binary = data_blob_talloc(mem_ctx,
-							  file_entry->data,
-							  file_entry->size);
+		case REG_SZ:
+			data->data.length = file_entry->size;
+			data->data.data = file_entry->data;
 			break;
 		case REG_NONE:
 			break;
-		case REG_SZ:
-			if (!pull_ucs2_talloc(mem_ctx, &data->v.sz.str,
-					      (const smb_ucs2_t *)
-					      file_entry->data,
-					      &data->v.sz.len)) {
-				data->v.sz.len = -1;
-			}
-
-			break;
 		case REG_DWORD_BIG_ENDIAN:
 		case REG_EXPAND_SZ:
 		case REG_LINK:
diff --git a/source3/libgpo/gpext/scripts.c b/source3/libgpo/gpext/scripts.c
index f03dff4..fee1461 100644
--- a/source3/libgpo/gpext/scripts.c
+++ b/source3/libgpo/gpext/scripts.c
@@ -96,11 +96,13 @@ static NTSTATUS generate_gp_registry_entry(TALLOC_CTX *mem_ctx,
 	data->type = data_type;
 	switch (data->type) {
 		case REG_QWORD:
-			data->v.qword = *(uint64_t *)data_p;
+			data->data = data_blob_talloc(mem_ctx, NULL, 8);
+			SBVAL(data->data.data, 0, *(uint64_t *)data_p);
 			break;
 		case REG_SZ:
-			data->v.sz.str = talloc_strdup(mem_ctx, (char *)data_p);
-			data->v.sz.len = strlen(data->v.sz.str);
+			if (!push_reg_sz(mem_ctx, &data->data, (char *)data_p)) {
+				return NT_STATUS_NO_MEMORY;
+			}
 			break;
 		default:
 			return NT_STATUS_NOT_SUPPORTED;
diff --git a/source3/libgpo/gpo_reg.c b/source3/libgpo/gpo_reg.c
index c4970f6..5b56ecd 100644
--- a/source3/libgpo/gpo_reg.c
+++ b/source3/libgpo/gpo_reg.c
@@ -165,15 +165,11 @@ WERROR gp_store_reg_val_sz(TALLOC_CTX *mem_ctx,
 			   const char *val)
 {
 	struct registry_value reg_val;
-	ZERO_STRUCT(reg_val);
-
-	/* FIXME: hack */
-	val = val ? val : " ";
 
 	reg_val.type = REG_SZ;
-	reg_val.v.sz.len = strlen(val);
-	reg_val.v.sz.str = talloc_strdup(mem_ctx, val);
-	W_ERROR_HAVE_NO_MEMORY(reg_val.v.sz.str);
+	if (!push_reg_sz(mem_ctx, &reg_val.data, val)) {
+		return WERR_NOMEM;
+	}
 
 	return reg_setvalue(key, val_name, &reg_val);
 }
@@ -187,10 +183,10 @@ static WERROR gp_store_reg_val_dword(TALLOC_CTX *mem_ctx,
 				     uint32_t val)
 {
 	struct registry_value reg_val;
-	ZERO_STRUCT(reg_val);
 
 	reg_val.type = REG_DWORD;
-	reg_val.v.dword = val;
+	reg_val.data = data_blob_talloc(mem_ctx, NULL, 4);
+	SIVAL(reg_val.data.data, 0, val);
 
 	return reg_setvalue(key, val_name, &reg_val);
 }
@@ -213,8 +209,9 @@ WERROR gp_read_reg_val_sz(TALLOC_CTX *mem_ctx,
 		return WERR_INVALID_DATATYPE;
 	}
 
-	*val = talloc_strdup(mem_ctx, reg_val->v.sz.str);
-	W_ERROR_HAVE_NO_MEMORY(*val);
+	if (!pull_reg_sz(mem_ctx, &reg_val->data, val)) {
+		return WERR_NOMEM;
+	}
 
 	return WERR_OK;
 }
@@ -237,7 +234,10 @@ static WERROR gp_read_reg_val_dword(TALLOC_CTX *mem_ctx,
 		return WERR_INVALID_DATATYPE;
 	}
 
-	*val = reg_val->v.dword;
+	if (reg_val->data.length < 4) {
+		return WERR_INSUFFICIENT_BUFFER;
+	}
+	*val = IVAL(reg_val->data.data, 0);
 
 	return WERR_OK;
 }
@@ -797,34 +797,56 @@ void dump_reg_val(int lvl, const char *direction,
 		direction, key, subkey, type_str));
 
 	switch (val->type) {
-		case REG_DWORD:
+		case REG_DWORD: {
+			uint32_t v;
+			if (val->data.length < 4) {
+				break;
+			}
+			v = IVAL(val->data.data, 0);
 			DEBUG(lvl,("%d (0x%08x)\n",
-				(int)val->v.dword, val->v.dword));
+				(int)v, v));
 			break;
-		case REG_QWORD:
+		}
+		case REG_QWORD: {
+			uint64_t v;
+			if (val->data.length < 8) {
+				break;
+			}
+			v = BVAL(val->data.data, 0);
 			DEBUG(lvl,("%d (0x%016llx)\n",
-				(int)val->v.qword,
-				(unsigned long long)val->v.qword));
+				(int)v,
+				(unsigned long long)v));
 			break;
-		case REG_SZ:
+		}
+		case REG_SZ: {
+			const char *s;
+			if (!pull_reg_sz(talloc_tos(), &val->data, &s)) {
+				break;
+			}
 			DEBUG(lvl,("%s (length: %d)\n",
-				   val->v.sz.str,
-				   (int)val->v.sz.len));
+				   s, (int)strlen_m(s)));
 			break;
-		case REG_MULTI_SZ:
-			DEBUG(lvl,("(num_strings: %d)\n",
-				   val->v.multi_sz.num_strings));
-			for (i=0; i < val->v.multi_sz.num_strings; i++) {
-				DEBUGADD(lvl,("\t%s\n",
-					val->v.multi_sz.strings[i]));
+		}
+		case REG_MULTI_SZ: {
+			const char **a;
+			if (!pull_reg_multi_sz(talloc_tos(), &val->data, &a)) {
+				break;
+			}
+			for (i=0; a[i] != NULL; i++) {
+				;;
+			}
+			DEBUG(lvl,("(num_strings: %d)\n", i));
+			for (i=0; a[i] != NULL; i++) {
+				DEBUGADD(lvl,("\t%s\n", a[i]));
 			}
 			break;
+		}
 		case REG_NONE:
 			DEBUG(lvl,("\n"));
 			break;
 		case REG_BINARY:
-			dump_data(lvl, val->v.binary.data,
-				  val->v.binary.length);
+			dump_data(lvl, val->data.data,
+				  val->data.length);
 			break;
 		default:
 			DEBUG(lvl,("unsupported type: %d\n", val->type));
diff --git a/source3/registry/reg_api.c b/source3/registry/reg_api.c
index 65118b9..4e3d871 100644
--- a/source3/registry/reg_api.c
+++ b/source3/registry/reg_api.c
@@ -69,7 +69,6 @@
 #include "reg_util_internal.h"
 #include "reg_backend_db.h"
 #include "reg_dispatcher.h"
-#include "reg_util_marshalling.h"
 #include "reg_objects.h"
 #include "../librpc/gen_ndr/ndr_security.h"
 
@@ -357,15 +356,15 @@ WERROR reg_enumvalue(TALLOC_CTX *mem_ctx, struct registry_key *key,
 	}
 
 	blob = regval_ctr_specific_value(key->values, idx);
-	err = registry_pull_value(mem_ctx, &val,
-				  regval_type(blob),
-				  regval_data_p(blob),
-				  regval_size(blob),
-				  regval_size(blob));
-	if (!W_ERROR_IS_OK(err)) {
-		return err;
+
+	val = talloc_zero(mem_ctx, struct registry_value);
+	if (val == NULL) {
+		return WERR_NOMEM;
 	}
 
+	val->type = regval_type(blob);
+	val->data = data_blob_talloc(mem_ctx, regval_data_p(blob), regval_size(blob));
+
 	if (pname
 	    && !(*pname = talloc_strdup(
 			 mem_ctx, regval_name(blob)))) {
@@ -661,7 +660,6 @@ WERROR reg_setvalue(struct registry_key *key, const char *name,
 		    const struct registry_value *val)
 {
 	WERROR err;
-	DATA_BLOB value_data;
 	int res;
 
 	if (!(key->key->access_granted & KEY_SET_VALUE)) {
@@ -672,14 +670,8 @@ WERROR reg_setvalue(struct registry_key *key, const char *name,
 		return err;
 	}
 
-	err = registry_push_value(key, val, &value_data);
-	if (!W_ERROR_IS_OK(err)) {
-		return err;
-	}
-
 	res = regval_ctr_addvalue(key->values, name, val->type,
-				  value_data.data, value_data.length);
-	TALLOC_FREE(value_data.data);
+				  val->data.data, val->data.length);
 
 	if (res == 0) {
 		TALLOC_FREE(key->values);
diff --git a/source3/registry/reg_backend_db.c b/source3/registry/reg_backend_db.c
index a31f7fb..22619ea 100644
--- a/source3/registry/reg_backend_db.c
+++ b/source3/registry/reg_backend_db.c
@@ -1679,12 +1679,8 @@ static int regdb_unpack_values(struct regval_ctr *values, uint8 *buf, int buflen
 				  &size,
 				  &data_p);
 
-		/* add the new value. Paranoid protective code -- make sure data_p is valid */
-
-		if (size && data_p) {
-			regval_ctr_addvalue(values, valuename, type,
-					(uint8_t *)data_p, size);
-		}
+		regval_ctr_addvalue(values, valuename, type,
+				(uint8_t *)data_p, size);
 		SAFE_FREE(data_p); /* 'B' option to tdb_unpack does a malloc() */
 
 		DEBUG(8,("specific: [%s], len: %d\n", valuename, size));
diff --git a/source3/registry/reg_objects.c b/source3/registry/reg_objects.c
index 459f7fc..04b9810 100644
--- a/source3/registry/reg_objects.c
+++ b/source3/registry/reg_objects.c
@@ -31,7 +31,7 @@
 
 struct regval_blob {
 	fstring		valuename;
-	uint16_t	type;


-- 
Samba Shared Repository


More information about the samba-cvs mailing list