[SCM] Samba Shared Repository - branch master updated

Jelmer Vernooij jelmer at samba.org
Mon Mar 22 16:09:34 MDT 2010


Hi Matthias,

Can you please send patches to the registry in for review first?

On 03/14/10 18:48, Matthias Dieter Wallnöfer wrote:
> diff --git a/source4/lib/registry/ldb.c b/source4/lib/registry/ldb.c
> index 0213c54..9e77f1f 100644
> --- a/source4/lib/registry/ldb.c
> +++ b/source4/lib/registry/ldb.c
> @@ -61,9 +61,22 @@ static void reg_ldb_unpack_value(TALLOC_CTX *mem_ctx,
>   	case REG_SZ:
>   	case REG_EXPAND_SZ:
>   		if (val != NULL) {
> -			convert_string_talloc(mem_ctx, CH_UTF8, CH_UTF16,
> -						     val->data, val->length,
> -						     (void **)&data->data,&data->length, false);
> +			if (val->data[0] != '\0') {
> +				/* The data should be provided as UTF16 string */
> +				convert_string_talloc(mem_ctx, CH_UTF8, CH_UTF16,
> +						      val->data, val->length,
> +						      (void **)&data->data,&data->length, false);
> +			} else {
> +				/* Provide a possibility to store also UTF8
> +				 * REG_SZ/REG_EXPAND_SZ values. This is done
> +				 * by adding a '\0' in front of the data */
> +				data->data = talloc_size(mem_ctx, val->length - 1);
> +				if (data->data != NULL) {
> +					memcpy(data->data, val->data + 1,
> +					       val->length - 1);
> +				}
> +				data->length = val->length - 1;
> +			}
>   		} else {
>   			data->data = NULL;
>   			data->length = 0;
>
^^ This is needlessly complicated.. Why do we need to support both UTF8 
and UTF16 inside of the LDB registry backend?

> @@ -72,9 +85,25 @@ static void reg_ldb_unpack_value(TALLOC_CTX *mem_ctx,
>
>   	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);
> +			if (val->data[0] != '\0') {
> +				/* The data is a plain DWORD */
> +				uint32_t tmp = strtoul((char *)val->data, NULL, 0);
> +				data->data = talloc_size(mem_ctx, sizeof(uint32_t) + 1);
> +				if (data->data != NULL) {
> +					SIVAL(data->data, 0, tmp);
> +				}
> +				data->length = sizeof(uint32_t);
> +			} else {
> +				/* Provide a possibility to store also UTF8
> +				 * REG_DWORD values. This is done by adding a
> +				 * '\0' in front of the data */
> +				data->data = talloc_size(mem_ctx, val->length - 1);
> +				if (data->data != NULL) {
> +					memcpy(data->data, val->data + 1,
> +					       val->length - 1);
> +				}
> +				data->length = val->length - 1;
> +			}
>
^^^ There is no such thing as a "UTF-8" DWORD.
>   		} else {
>   			data->data = NULL;
>   			data->length = 0;
> @@ -84,7 +113,9 @@ static void reg_ldb_unpack_value(TALLOC_CTX *mem_ctx,
>   	case REG_BINARY:
>   	default:
>   		if (val != NULL) {
> -			*data = data_blob_talloc(mem_ctx, val->data, val->length);
> +			data->data = talloc_memdup(mem_ctx, val->data,
> +						   val->length);
> +			data->length = val->length;
>
^^ What's wrong with data_blob_talloc ?

> @@ -98,34 +129,105 @@ static struct ldb_message *reg_ldb_pack_value(struct ldb_context *ctx,
>   					      const char *name,
>   					      uint32_t type, DATA_BLOB data)
>   {
> -	struct ldb_val val;
> -	struct ldb_message *msg = talloc_zero(mem_ctx, struct ldb_message);
> -	char *type_s;
> +	struct ldb_message *msg;
> +	char *name_dup, *type_str;
> +	int ret;
>
> -	ldb_msg_add_string(msg, "value", talloc_strdup(mem_ctx, name));
> +	msg = talloc_zero(mem_ctx, struct ldb_message);
> +	if (msg == NULL) {
> +		return NULL;
> +	}
> +
> +	name_dup = talloc_strdup(msg, name);
> +	if (name_dup == NULL) {
> +		talloc_free(msg);
> +		return NULL;
> +	}
> +
> +	ret = ldb_msg_add_string(msg, "value", name_dup);
> +	if (ret != LDB_SUCCESS) {
> +		talloc_free(msg);
> +		return NULL;
> +	}
>
>   	switch (type) {
>   	case REG_SZ:
>   	case REG_EXPAND_SZ:
>   		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,
> -						   (void **)&val.data,&val.length, false);
> -			ldb_msg_add_value(msg, "data",&val, NULL);
> +			struct ldb_val *val;
> +			bool ret2;
> +
> +			val = talloc_zero(msg, struct ldb_val);
> +			if (val == NULL) {
> +				talloc_free(msg);
> +				return NULL;
> +			}
> +
> +			if (data.length % 2 == 0) {
> +				/* The data is provided as UTF16 string */
> +				ret2 = convert_string_talloc(mem_ctx, CH_UTF16, CH_UTF8,
> +							     (void *)data.data, data.length,
> +							     (void **)&val->data,&val->length,
> +							     false);
> +				if (!ret2) {
> +					talloc_free(msg);
> +					return NULL;
> +				}
>
^^ This isn't necessarily true ? What if there is an uneven number of 
characters in a UTF-8 string? In that case the length of that string 
would be even.

Cheers,

Jelmer


More information about the samba-technical mailing list