[SCM] Samba Shared Repository - branch master updated

Matthias Dieter Wallnöfer mdw at samba.org
Sat Mar 6 12:01:42 MST 2010


The branch, master has been updated
       via  6870313... s4:lib/registry/ldb.c - fix trailing whitespaces
       via  ed678a2... s4:registry library - fix up "reg_ldb_set_value"
       via  f5b86cd... s4:registry library - make "reg_ldb_pack/unpack_value" more robust
       via  73e7aa8... s4:provision.reg - call us Windows 2008 from the current version point of view
       via  89ab681... s4:libregistry - change counters to be "unsigned"
      from  5a3633f... s3: Fix the build of net_afs.c with --fake-kaserver=yes, bug 7216

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


- Log -----------------------------------------------------------------
commit 6870313db5600c2dd68c51e757f233dad56aa250
Author: Matthias Dieter Wallnöfer <mwallnoefer at yahoo.de>
Date:   Sat Mar 6 19:39:45 2010 +0100

    s4:lib/registry/ldb.c - fix trailing whitespaces

commit ed678a2234dda656d0a2d5bbf65b22afa7a47144
Author: Matthias Dieter Wallnöfer <mwallnoefer at yahoo.de>
Date:   Sat Mar 6 19:36:01 2010 +0100

    s4:registry library - fix up "reg_ldb_set_value"
    
    The previous logic was wrong since it tried to add empty data in some cases
    which always ended in an error. This problem should be fixed with the new logic.

commit f5b86cdac52c1eb7f30c1900cce880ed868789c8
Author: Matthias Dieter Wallnöfer <mwallnoefer at yahoo.de>
Date:   Sat Mar 6 19:20:48 2010 +0100

    s4:registry library - make "reg_ldb_pack/unpack_value" more robust
    
    This to prevent segmentation faults, wrong server inputs ecc.

commit 73e7aa863bddd717e1556b0c7b8fdc80922609c3
Author: Matthias Dieter Wallnöfer <mwallnoefer at yahoo.de>
Date:   Sat Mar 6 18:51:41 2010 +0100

    s4:provision.reg - call us Windows 2008 from the current version point of view

commit 89ab6818e170b305a70b7258ac11e11a2eb53aeb
Author: Matthias Dieter Wallnöfer <mwallnoefer at yahoo.de>
Date:   Sat Nov 7 21:07:20 2009 +0100

    s4:libregistry - change counters to be "unsigned"
    
    Also the s4 registry library has to have "unsigned" counters like the Windows
    one.

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

Summary of changes:
 source4/lib/registry/dir.c            |    6 +-
 source4/lib/registry/interface.c      |    6 +-
 source4/lib/registry/ldb.c            |  118 +++++++++++++++++++-------------
 source4/lib/registry/local.c          |    4 +-
 source4/lib/registry/patchfile.c      |    4 +-
 source4/lib/registry/regf.c           |   22 +++---
 source4/lib/registry/registry.h       |    4 +-
 source4/lib/registry/tools/regshell.c |   14 ++--
 source4/lib/registry/tools/regtree.c  |    2 +-
 source4/lib/registry/util.c           |    6 +-
 source4/setup/provision.reg           |    2 +-
 11 files changed, 105 insertions(+), 83 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source4/lib/registry/dir.c b/source4/lib/registry/dir.c
index 42946bc..4380dce 100644
--- a/source4/lib/registry/dir.c
+++ b/source4/lib/registry/dir.c
@@ -159,7 +159,7 @@ static WERROR reg_dir_key_by_index(TALLOC_CTX *mem_ctx,
 {
 	struct dirent *e;
 	const struct dir_key *dk = talloc_get_type(k, struct dir_key);
-	int i = 0;
+	unsigned int i = 0;
 	DIR *d;
 
 	d = opendir(dk->path);
@@ -342,14 +342,14 @@ static WERROR reg_dir_get_value(TALLOC_CTX *mem_ctx,
 }
 
 static WERROR reg_dir_enum_value(TALLOC_CTX *mem_ctx,
-				 struct hive_key *key, int idx,
+				 struct hive_key *key, uint32_t idx,
 				 const char **name,
 				 uint32_t *type, DATA_BLOB *data)
 {
 	const struct dir_key *dk = talloc_get_type(key, struct dir_key);
 	DIR *d;
 	struct dirent *e;
-	int i;
+	unsigned int i;
 
 	d = opendir(dk->path);
 	if (d == NULL) {
diff --git a/source4/lib/registry/interface.c b/source4/lib/registry/interface.c
index 81ca2c3..5d24f6d 100644
--- a/source4/lib/registry/interface.c
+++ b/source4/lib/registry/interface.c
@@ -44,7 +44,7 @@ const struct reg_predefined_key reg_predefined_keys[] = {
 /** Obtain name of specific hkey. */
 _PUBLIC_ const char *reg_get_predef_name(uint32_t hkey)
 {
-	int i;
+	unsigned int i;
 	for (i = 0; reg_predefined_keys[i].name; i++) {
 		if (reg_predefined_keys[i].handle == hkey)
 			return reg_predefined_keys[i].name;
@@ -58,7 +58,7 @@ _PUBLIC_ WERROR reg_get_predefined_key_by_name(struct registry_context *ctx,
 					       const char *name,
 					       struct registry_key **key)
 {
-	int i;
+	unsigned int i;
 
 	for (i = 0; reg_predefined_keys[i].name; i++) {
 		if (!strcasecmp(reg_predefined_keys[i].name, name))
@@ -150,7 +150,7 @@ _PUBLIC_ WERROR reg_key_get_info(TALLOC_CTX *mem_ctx,
  */
 _PUBLIC_ WERROR reg_key_get_subkey_by_index(TALLOC_CTX *mem_ctx,
 					    const struct registry_key *key,
-					    int idx, const char **name,
+					    uint32_t idx, const char **name,
 					    const char **keyclass,
 					    NTTIME *last_changed_time)
 {
diff --git a/source4/lib/registry/ldb.c b/source4/lib/registry/ldb.c
index 68639f5..12722c9 100644
--- a/source4/lib/registry/ldb.c
+++ b/source4/lib/registry/ldb.c
@@ -2,7 +2,7 @@
    Unix SMB/CIFS implementation.
    Registry interface
    Copyright (C) 2004-2007, Jelmer Vernooij, jelmer at samba.org
-   Copyright (C) 2008 Matthias Dieter Wallnöfer, mwallnoefer at yahoo.de
+   Copyright (C) 2008-2010, Matthias Dieter Wallnöfer, mdw at samba.org
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -34,10 +34,10 @@ struct ldb_key_data
 	struct ldb_context *ldb;
 	struct ldb_dn *dn;
 	struct ldb_message **subkeys, **values;
-	int subkey_count, value_count;
+	unsigned int subkey_count, value_count;
 };
 
-static void reg_ldb_unpack_value(TALLOC_CTX *mem_ctx, 
+static void reg_ldb_unpack_value(TALLOC_CTX *mem_ctx,
 				 struct ldb_message *msg,
 				 const char **name, uint32_t *type,
 				 DATA_BLOB *data)
@@ -45,13 +45,14 @@ static void reg_ldb_unpack_value(TALLOC_CTX *mem_ctx,
 	const struct ldb_val *val;
 	uint32_t value_type;
 
-	if (name != NULL)
+	if (name != NULL) {
 		*name = talloc_strdup(mem_ctx,
 				      ldb_msg_find_attr_as_string(msg, "value",
 				      NULL));
+	}
 
 	value_type = ldb_msg_find_attr_as_uint(msg, "type", 0);
-	*type = value_type; 
+	*type = value_type;
 
 	val = ldb_msg_find_ldb_val(msg, "data");
 
@@ -59,34 +60,35 @@ static void reg_ldb_unpack_value(TALLOC_CTX *mem_ctx,
 	{
 	case REG_SZ:
 	case REG_EXPAND_SZ:
-		if (val != NULL)
+		if (val != NULL) {
 			convert_string_talloc(mem_ctx, CH_UTF8, CH_UTF16,
 						     val->data, val->length,
 						     (void **)&data->data, &data->length, false);
-		else {
+		} else {
 			data->data = NULL;
 			data->length = 0;
 		}
 		break;
 
-	case REG_BINARY:
-		if (val != NULL)
-			*data = data_blob_talloc(mem_ctx, val->data, val->length);
-		else {
+	case REG_DWORD:
+		if (val != NULL) {
+			uint32_t tmp = strtoul((char *)val->data, NULL, 0);
+			*data = data_blob_talloc(mem_ctx, NULL, 4);
+			SIVAL(data->data, 0, tmp);
+		} else {
 			data->data = NULL;
 			data->length = 0;
 		}
 		break;
 
-	case REG_DWORD: {
-		uint32_t tmp = strtoul((char *)val->data, NULL, 0);
-		*data = data_blob_talloc(mem_ctx, NULL, 4);
-		SIVAL(data->data, 0, tmp);
-		}
-		break;
-
+	case REG_BINARY:
 	default:
-		*data = data_blob_talloc(mem_ctx, val->data, val->length);
+		if (val != NULL) {
+			*data = data_blob_talloc(mem_ctx, val->data, val->length);
+		} else {
+			data->data = NULL;
+			data->length = 0;
+		}
 		break;
 	}
 }
@@ -105,7 +107,8 @@ static struct ldb_message *reg_ldb_pack_value(struct ldb_context *ctx,
 	switch (type) {
 	case REG_SZ:
 	case REG_EXPAND_SZ:
-		if (data.data[0] != '\0') {
+		if ((data.length > 0) && (data.data != NULL)
+		    && (data.data[0] != '\0')) {
 			convert_string_talloc(mem_ctx, CH_UTF16, CH_UTF8,
 						   (void *)data.data,
 						   data.length,
@@ -116,23 +119,27 @@ static struct ldb_message *reg_ldb_pack_value(struct ldb_context *ctx,
 		}
 		break;
 
-	case REG_BINARY:
-		if (data.length > 0)
-			ldb_msg_add_value(msg, "data", &data, NULL);
-		else
+	case REG_DWORD:
+		if ((data.length > 0) && (data.data != NULL)) {
+			ldb_msg_add_string(msg, "data",
+					   talloc_asprintf(mem_ctx, "0x%x",
+							   IVAL(data.data, 0)));
+		} else {
 			ldb_msg_add_empty(msg, "data", LDB_FLAG_MOD_DELETE, NULL);
+		}
 		break;
 
-	case REG_DWORD:
-		ldb_msg_add_string(msg, "data",
-				   talloc_asprintf(mem_ctx, "0x%x",
-				   		   IVAL(data.data, 0)));
-		break;
+	case REG_BINARY:
 	default:
-		ldb_msg_add_value(msg, "data", &data, NULL);
+		if ((data.length > 0) && (data.data != NULL)
+		    && (data.data[0] != '\0')) {
+			ldb_msg_add_value(msg, "data", &data, NULL);
+		} else {
+			ldb_msg_add_empty(msg, "data", LDB_FLAG_MOD_DELETE, NULL);
+		}
+		break;
 	}
 
-
 	type_s = talloc_asprintf(mem_ctx, "%u", type);
 	ldb_msg_add_string(msg, "type", type_s);
 
@@ -271,7 +278,7 @@ static WERROR ldb_get_subkey_by_id(TALLOC_CTX *mem_ctx,
 {
 	struct ldb_message_element *el;
 	struct ldb_key_data *kd = talloc_get_type(k, struct ldb_key_data);
-	
+
 	/* Initialization */
 	if (name != NULL)
 		*name = NULL;
@@ -320,7 +327,7 @@ static WERROR ldb_get_default_value(TALLOC_CTX *mem_ctx, struct hive_key *k,
 	if (res->count == 0 || res->msgs[0]->num_elements == 0)
 		return WERR_BADFILE;
 
-	reg_ldb_unpack_value(mem_ctx, 
+	reg_ldb_unpack_value(mem_ctx,
 		 res->msgs[0], name, data_type, data);
 
 	talloc_free(res);
@@ -329,7 +336,7 @@ static WERROR ldb_get_default_value(TALLOC_CTX *mem_ctx, struct hive_key *k,
 }
 
 static WERROR ldb_get_value_by_id(TALLOC_CTX *mem_ctx, struct hive_key *k,
-				  int idx, const char **name,
+				  uint32_t idx, const char **name,
 				  uint32_t *data_type, DATA_BLOB *data)
 {
 	struct ldb_key_data *kd = talloc_get_type(k, struct ldb_key_data);
@@ -572,7 +579,8 @@ static WERROR ldb_del_value (struct hive_key *key, const char *child)
 
 static WERROR ldb_del_key(const struct hive_key *key, const char *name)
 {
-	int i, ret;
+	unsigned int i;
+	int ret;
 	struct ldb_key_data *parentkd = talloc_get_type(key, struct ldb_key_data);
 	struct ldb_dn *ldap_path;
 	TALLOC_CTX *mem_ctx = talloc_init("ldb_del_key");
@@ -692,13 +700,14 @@ static WERROR ldb_set_value(struct hive_key *parent,
 {
 	struct ldb_message *msg;
 	struct ldb_key_data *kd = talloc_get_type(parent, struct ldb_key_data);
+	unsigned int i;
 	int ret;
 	TALLOC_CTX *mem_ctx = talloc_init("ldb_set_value");
 
 	msg = reg_ldb_pack_value(kd->ldb, mem_ctx, name, type, data);
 	msg->dn = ldb_dn_copy(msg, kd->dn);
-	
-	if (strlen(name) > 0) {
+
+	if (name[0] != '\0') {
 		/* For a default value, we add/overwrite the attributes to/of the hive.
 		   For a normal value, we create a new child. */
 		if (!ldb_dn_add_child_fmt(msg->dn, "value=%s",
@@ -709,14 +718,27 @@ static WERROR ldb_set_value(struct hive_key *parent,
 		}
 	}
 
-	ret = ldb_add(kd->ldb, msg);
-	if (ret == LDB_ERR_ENTRY_ALREADY_EXISTS) {
-		int i;
-		for (i = 0; i < msg->num_elements; i++) {
-			if (msg->elements[i].flags != LDB_FLAG_MOD_DELETE)
-				msg->elements[i].flags = LDB_FLAG_MOD_REPLACE;
+	/* Try first a "modify" and if this doesn't work do try an "add" */
+	for (i = 0; i < msg->num_elements; i++) {
+		if (msg->elements[i].flags != LDB_FLAG_MOD_DELETE) {
+			msg->elements[i].flags = LDB_FLAG_MOD_REPLACE;
 		}
-		ret = ldb_modify(kd->ldb, msg);
+	}
+	ret = ldb_modify(kd->ldb, msg);
+	if (ret == LDB_ERR_NO_SUCH_OBJECT) {
+		i = 0;
+		while (i < msg->num_elements) {
+			if (msg->elements[i].flags == LDB_FLAG_MOD_DELETE) {
+				ldb_msg_remove_element(msg, &msg->elements[i]);
+			} else {
+				++i;
+			}
+		}
+		ret = ldb_add(kd->ldb, msg);
+	}
+	if (ret == LDB_ERR_NO_SUCH_ATTRIBUTE) {
+		/* ignore this -> the value didn't exist and also now doesn't */
+		ret = LDB_SUCCESS;
 	}
 
 	if (ret != LDB_SUCCESS) {
@@ -778,7 +800,7 @@ static WERROR ldb_get_key_info(TALLOC_CTX *mem_ctx,
 
 
 	if (max_subkeynamelen != NULL) {
-		int i;
+		unsigned int i;
 		struct ldb_message_element *el;
 
 		*max_subkeynamelen = 0;
@@ -790,7 +812,7 @@ static WERROR ldb_get_key_info(TALLOC_CTX *mem_ctx,
 	}
 
 	if (max_valnamelen != NULL || max_valbufsize != NULL) {
-		int i;
+		unsigned int i;
 		struct ldb_message_element *el;
 		W_ERROR_NOT_OK_RETURN(cache_values(kd));
 
@@ -809,8 +831,8 @@ static WERROR ldb_get_key_info(TALLOC_CTX *mem_ctx,
 			if (max_valbufsize != NULL) {
 				uint32_t data_type;
 				DATA_BLOB data;
-				reg_ldb_unpack_value(mem_ctx, 
-						     kd->values[i], NULL, 
+				reg_ldb_unpack_value(mem_ctx,
+						     kd->values[i], NULL,
 						     &data_type, &data);
 				*max_valbufsize = MAX(*max_valbufsize, data.length);
 				talloc_free(data.data);
diff --git a/source4/lib/registry/local.c b/source4/lib/registry/local.c
index a3aee06..458239b 100644
--- a/source4/lib/registry/local.c
+++ b/source4/lib/registry/local.c
@@ -167,7 +167,7 @@ static WERROR local_create_key(TALLOC_CTX *mem_ctx,
 	struct local_key *local_parent;
 	struct hive_key *hivekey;
 	const char **elements;
-	int i;
+	unsigned int i;
 	const char *last_part;
 
 	last_part = strrchr(name, '\\');
@@ -328,7 +328,7 @@ WERROR reg_mount_hive(struct registry_context *rctx,
 	struct registry_local *reg_local = talloc_get_type(rctx,
 							   struct registry_local);
 	struct mountpoint *mp = talloc(rctx, struct mountpoint);
-	int i = 0;
+	unsigned int i = 0;
 
 	mp->path.predefined_key = key_id;
 	mp->prev = mp->next = NULL;
diff --git a/source4/lib/registry/patchfile.c b/source4/lib/registry/patchfile.c
index 0631e76..19e27f5 100644
--- a/source4/lib/registry/patchfile.c
+++ b/source4/lib/registry/patchfile.c
@@ -44,7 +44,7 @@ WERROR reg_generate_diff_key(struct registry_key *oldkey,
 			     const struct reg_diff_callbacks *callbacks,
 			     void *callback_data)
 {
-	int i;
+	unsigned int i;
 	struct registry_key *t1 = NULL, *t2 = NULL;
 	char *tmppath;
 	const char *keyname1;
@@ -256,7 +256,7 @@ _PUBLIC_ WERROR reg_generate_diff(struct registry_context *ctx1,
 				  const struct reg_diff_callbacks *callbacks,
 				  void *callback_data)
 {
-	int i;
+	unsigned int i;
 	WERROR error;
 
 	for (i = 0; reg_predefined_keys[i].name; i++) {
diff --git a/source4/lib/registry/regf.c b/source4/lib/registry/regf.c
index 5bc2335..ddb917d 100644
--- a/source4/lib/registry/regf.c
+++ b/source4/lib/registry/regf.c
@@ -64,7 +64,7 @@ struct regf_key_data {
 static struct hbin_block *hbin_by_offset(const struct regf_data *data,
 					 uint32_t offset, uint32_t *rel_offset)
 {
-	int i;
+	unsigned int i;
 
 	for (i = 0; data->hbins[i]; i++) {
 		if (offset >= data->hbins[i]->offset_from_first &&
@@ -86,7 +86,7 @@ static struct hbin_block *hbin_by_offset(const struct regf_data *data,
 static uint32_t regf_hdr_checksum(const uint8_t *buffer)
 {
 	uint32_t checksum = 0, x;
-	int i;
+	unsigned int i;
 
 	for (i = 0; i < 0x01FB; i+= 4) {
 		x = IVAL(buffer, i);
@@ -161,7 +161,7 @@ static DATA_BLOB hbin_alloc(struct regf_data *data, uint32_t size,
 	DATA_BLOB ret;
 	uint32_t rel_offset = -1; /* Relative offset ! */
 	struct hbin_block *hbin = NULL;
-	int i;
+	unsigned int i;
 
 	*offset = 0;
 
@@ -340,7 +340,7 @@ static uint32_t hbin_store_resize(struct regf_data *data,
 	int32_t orig_size;
 	int32_t needed_size;
 	int32_t possible_size;
-	int i;
+	unsigned int i;
 
 	SMB_ASSERT(orig_offset > 0);
 
@@ -504,7 +504,7 @@ static struct regf_key_data *regf_get_key(TALLOC_CTX *ctx,
 
 
 static WERROR regf_get_value(TALLOC_CTX *ctx, struct hive_key *key,
-			     int idx, const char **name,
+			     uint32_t idx, const char **name,
 			     uint32_t *data_type, DATA_BLOB *data)
 {
 	const struct regf_key_data *private_data =
@@ -567,7 +567,7 @@ static WERROR regf_get_value_by_name(TALLOC_CTX *mem_ctx,
 				     struct hive_key *key, const char *name,
 				     uint32_t *type, DATA_BLOB *data)
 {
-	int i;
+	unsigned int i;
 	const char *vname;
 	WERROR error;
 
@@ -1551,7 +1551,7 @@ static WERROR regf_del_value (struct hive_key *key, const char *name)
 	uint32_t vk_offset;
 	bool found_offset = false;
 	DATA_BLOB values;
-	uint32_t i;
+	unsigned int i;
 
 	if (nk->values_offset == -1) {
 		return WERR_BADFILE;
@@ -1627,7 +1627,7 @@ static WERROR regf_del_key(const struct hive_key *parent, const char *name)
 	if (key->nk->subkeys_offset != -1) {
 		char *sk_name;
 		struct hive_key *sk = (struct hive_key *)key;
-		int i = key->nk->num_subkeys;
+		unsigned int i = key->nk->num_subkeys;
 		while (i--) {
 			/* Get subkey information. */
 			error = regf_get_subkey_by_index(parent_nk, sk, 0,
@@ -1653,7 +1653,7 @@ static WERROR regf_del_key(const struct hive_key *parent, const char *name)
 		char *val_name;
 		struct hive_key *sk = (struct hive_key *)key;
 		DATA_BLOB data;
-		int i = key->nk->num_values;
+		unsigned int i = key->nk->num_values;
 		while (i--) {
 			/* Get value information. */
 			error = regf_get_value(parent_nk, sk, 0,
@@ -1878,7 +1878,7 @@ static WERROR regf_set_value(struct hive_key *key, const char *name,
 static WERROR regf_save_hbin(struct regf_data *regf)
 {
 	struct tdr_push *push = tdr_push_init(regf, regf->iconv_convenience);
-	int i;
+	unsigned int i;
 
 	W_ERROR_HAVE_NO_MEMORY(push);
 
@@ -2053,7 +2053,7 @@ WERROR reg_open_regf_file(TALLOC_CTX *parent_ctx, const char *location,
 	struct regf_data *regf;
 	struct regf_hdr *regf_hdr;
 	struct tdr_pull *pull;
-	int i;
+	unsigned int i;
 
 	regf = (struct regf_data *)talloc_zero(parent_ctx, struct regf_data);
 
diff --git a/source4/lib/registry/registry.h b/source4/lib/registry/registry.h
index a97d9f6..eeabaef 100644
--- a/source4/lib/registry/registry.h
+++ b/source4/lib/registry/registry.h
@@ -88,7 +88,7 @@ struct hive_operations {
 	 * Retrieve a registry value with a specific index.
 	 */
 	WERROR (*enum_value) (TALLOC_CTX *mem_ctx,
-			      struct hive_key *key, int idx,
+			      struct hive_key *key, uint32_t idx,
 			      const char **name, uint32_t *type,
 			      DATA_BLOB *data);
 
@@ -411,7 +411,7 @@ WERROR reg_key_get_info(TALLOC_CTX *mem_ctx,
 			uint32_t *max_valbufsize);
 WERROR reg_key_get_subkey_by_index(TALLOC_CTX *mem_ctx,
 				   const struct registry_key *key,
-				   int idx,
+				   uint32_t idx,
 				   const char **name,
 				   const char **classname,
 				   NTTIME *last_mod_time);
diff --git a/source4/lib/registry/tools/regshell.c b/source4/lib/registry/tools/regshell.c
index 2bacaac..003cbd1 100644
--- a/source4/lib/registry/tools/regshell.c
+++ b/source4/lib/registry/tools/regshell.c
@@ -266,7 +266,7 @@ static WERROR cmd_print(struct regshell_context *ctx, int argc, char **argv)
 
 static WERROR cmd_ls(struct regshell_context *ctx, int argc, char **argv)
 {
-	int i;
+	unsigned int i;


-- 
Samba Shared Repository


More information about the samba-cvs mailing list