svn commit: samba r23422 - in branches/SAMBA_3_0_26/source: include lib utils

obnox at samba.org obnox at samba.org
Mon Jun 11 15:49:58 GMT 2007


Author: obnox
Date: 2007-06-11 15:49:57 +0000 (Mon, 11 Jun 2007)
New Revision: 23422

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

Log:
Merge (parts of) r19807, r19811, r19827.
Preleminary merge for subsequent merge of restructuring of registry code.

Michael


Modified:
   branches/SAMBA_3_0_26/source/include/reg_objects.h
   branches/SAMBA_3_0_26/source/lib/util_reg.c
   branches/SAMBA_3_0_26/source/utils/net_rpc_printer.c


Changeset:
Modified: branches/SAMBA_3_0_26/source/include/reg_objects.h
===================================================================
--- branches/SAMBA_3_0_26/source/include/reg_objects.h	2007-06-11 14:47:05 UTC (rev 23421)
+++ branches/SAMBA_3_0_26/source/include/reg_objects.h	2007-06-11 15:49:57 UTC (rev 23422)
@@ -32,6 +32,31 @@
 	uint8           *data_p;
 } REGISTRY_VALUE;
 
+/*
+ * 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;
+};
+
 /* container for registry values */
 
 typedef struct {

Modified: branches/SAMBA_3_0_26/source/lib/util_reg.c
===================================================================
--- branches/SAMBA_3_0_26/source/lib/util_reg.c	2007-06-11 14:47:05 UTC (rev 23421)
+++ branches/SAMBA_3_0_26/source/lib/util_reg.c	2007-06-11 15:49:57 UTC (rev 23422)
@@ -20,7 +20,7 @@
 
 #include "includes.h"
 
-const char *reg_type_lookup(uint32 type)
+const char *reg_type_lookup(enum winreg_Type type)
 {
 	const char *result;
 
@@ -69,7 +69,7 @@
 }
 
 NTSTATUS reg_pull_multi_sz(TALLOC_CTX *mem_ctx, const void *buf, size_t len,
-			   int *num_values, char ***values)
+			   uint32 *num_values, char ***values)
 {
 	const smb_ucs2_t *p = (const smb_ucs2_t *)buf;
 	*num_values = 0;
@@ -108,3 +108,118 @@
 
 	return NT_STATUS_OK;
 }
+
+NTSTATUS registry_pull_value(TALLOC_CTX *mem_ctx,
+			     struct registry_value **pvalue,
+			     enum winreg_Type type, uint8 *data,
+			     uint32 size, uint32 length)
+{
+	struct registry_value *value;
+	NTSTATUS status;
+
+	if (!(value = TALLOC_ZERO_P(mem_ctx, struct registry_value))) {
+		return NT_STATUS_NO_MEMORY;
+	}
+
+	value->type = type;
+
+	switch (type) {
+	case REG_DWORD:
+		if ((size != 4) || (length != 4)) {
+			status = NT_STATUS_INVALID_PARAMETER;
+			goto error;
+		}
+		value->v.dword = IVAL(data, 0);
+		break;
+	case REG_SZ:
+	case REG_EXPAND_SZ:
+	{
+		/*
+		 * Make sure we get a NULL terminated string for
+		 * convert_string_talloc().
+		 */
+
+		smb_ucs2_t *tmp;
+		uint32 num_ucs2 = length / 2;
+
+		if ((length % 2) != 0) {
+			status = NT_STATUS_INVALID_PARAMETER;
+			goto error;
+		}
+
+		if (!(tmp = SMB_MALLOC_ARRAY(smb_ucs2_t, num_ucs2+1))) {
+			status = NT_STATUS_NO_MEMORY;
+			goto error;
+		}
+
+		memcpy((void *)tmp, (const void *)data, length);
+		tmp[num_ucs2] = 0;
+
+		value->v.sz.len = convert_string_talloc(
+			value, CH_UTF16LE, CH_UNIX, tmp, length+2,
+			&value->v.sz.str, False);
+
+		SAFE_FREE(tmp);
+
+		if (value->v.sz.len == (size_t)-1) {
+			status = NT_STATUS_INVALID_PARAMETER;
+			goto error;
+		}
+		break;
+	}
+	case REG_MULTI_SZ:
+		status = reg_pull_multi_sz(value, (void *)data, length,
+					   &value->v.multi_sz.num_strings,
+					   &value->v.multi_sz.strings);
+		if (!(NT_STATUS_IS_OK(status))) {
+			goto error;
+		}
+		break;
+	case REG_BINARY:
+		value->v.binary.data = talloc_move(value, &data);
+		value->v.binary.length = length;
+		break;
+	default:
+		status = NT_STATUS_INVALID_PARAMETER;
+		goto error;
+	}
+
+	*pvalue = value;
+	return NT_STATUS_OK;
+
+ error:
+	TALLOC_FREE(value);
+	return status;
+}
+
+NTSTATUS registry_push_value(TALLOC_CTX *mem_ctx,
+			     const struct registry_value *value,
+			     DATA_BLOB *presult)
+{
+	switch (value->type) {
+	case REG_DWORD: {
+		char buf[4];
+		SIVAL(buf, 0, value->v.dword);
+		*presult = data_blob_talloc(mem_ctx, (void *)buf, 4);
+		if (presult->data == NULL) {
+			return NT_STATUS_NO_MEMORY;
+		}
+		break;
+	}
+	case REG_SZ:
+	case REG_EXPAND_SZ: {
+		presult->length = convert_string_talloc(
+			mem_ctx, CH_UNIX, CH_UTF16LE, value->v.sz.str,
+			MIN(value->v.sz.len, strlen(value->v.sz.str)+1),
+			(void *)&(presult->data), False);
+		if (presult->length == (size_t)-1) {
+			return NT_STATUS_NO_MEMORY;
+		}
+		break;
+	}
+	default:
+		return NT_STATUS_INVALID_PARAMETER;
+	}
+
+	return NT_STATUS_OK;
+}

Modified: branches/SAMBA_3_0_26/source/utils/net_rpc_printer.c
===================================================================
--- branches/SAMBA_3_0_26/source/utils/net_rpc_printer.c	2007-06-11 14:47:05 UTC (rev 23421)
+++ branches/SAMBA_3_0_26/source/utils/net_rpc_printer.c	2007-06-11 15:49:57 UTC (rev 23422)
@@ -129,7 +129,7 @@
 		break;
 
 	case REG_MULTI_SZ: {
-		int i, num_values;
+		uint32 i, num_values;
 		char **values;
 
 		if (!NT_STATUS_IS_OK(reg_pull_multi_sz(NULL, value.data_p,



More information about the samba-cvs mailing list