summaryrefslogtreecommitdiff
path: root/source3/utils
diff options
context:
space:
mode:
authorGünther Deschner <gd@samba.org>2010-06-29 16:13:15 +0200
committerGünther Deschner <gd@samba.org>2010-07-02 10:50:21 +0200
commitb381fba0892021f164223bae8b0951014a28735e (patch)
tree5dc8f39ea4997a0863e9506dbe9387ca7ceb6971 /source3/utils
parent84c5dd1e4bb1b4c45d7b5ac68ab432cfc399835c (diff)
downloadsamba-b381fba0892021f164223bae8b0951014a28735e.tar.gz
samba-b381fba0892021f164223bae8b0951014a28735e.tar.bz2
samba-b381fba0892021f164223bae8b0951014a28735e.zip
s3-registry: avoid using registry_value union.
Just pull and push data as is. Guenther
Diffstat (limited to 'source3/utils')
-rw-r--r--source3/utils/net_registry.c40
-rw-r--r--source3/utils/net_registry_util.c30
-rw-r--r--source3/utils/net_rpc_registry.c53
3 files changed, 79 insertions, 44 deletions
diff --git a/source3/utils/net_registry.c b/source3/utils/net_registry.c
index 53cce12360..4a6af959dc 100644
--- a/source3/utils/net_registry.c
+++ b/source3/utils/net_registry.c
@@ -352,16 +352,33 @@ static int net_registry_setvalue(struct net_context *c, int argc,
}
if (strequal(argv[2], "dword")) {
+ uint32_t v = strtoul(argv[3], NULL, 10);
value.type = REG_DWORD;
- value.v.dword = strtoul(argv[3], NULL, 10);
+ value.data = data_blob_talloc(ctx, NULL, 4);
+ SIVAL(value.data.data, 0, v);
} else if (strequal(argv[2], "sz")) {
value.type = REG_SZ;
- value.v.sz.len = strlen(argv[3])+1;
- value.v.sz.str = CONST_DISCARD(char *, argv[3]);
+ if (!push_reg_sz(ctx, &value.data, argv[3])) {
+ goto done;
+ }
} else if (strequal(argv[2], "multi_sz")) {
+ const char **array;
+ int count = argc - 3;
+ int i;
value.type = REG_MULTI_SZ;
- value.v.multi_sz.num_strings = argc - 3;
- value.v.multi_sz.strings = (char **)(argv + 3);
+ array = talloc_zero_array(ctx, const char *, count + 1);
+ if (array == NULL) {
+ goto done;
+ }
+ for (i=0; i < count; i++) {
+ array[i] = talloc_strdup(array, argv[count+i]);
+ if (array[i] == NULL) {
+ goto done;
+ }
+ }
+ if (!push_reg_multi_sz(ctx, &value.data, array)) {
+ goto done;
+ }
} else {
d_fprintf(stderr, _("type \"%s\" not implemented\n"), argv[2]);
goto done;
@@ -401,6 +418,7 @@ static void net_registry_increment_fn(void *private_data)
(struct net_registry_increment_state *)private_data;
struct registry_value *value;
struct registry_key *key = NULL;
+ uint32_t v;
state->werr = open_key(talloc_tos(), state->keyname,
REG_KEY_READ|REG_KEY_WRITE, &key);
@@ -423,8 +441,16 @@ static void net_registry_increment_fn(void *private_data)
goto done;
}
- value->v.dword += state->increment;
- state->newvalue = value->v.dword;
+ if (value->data.length < 4) {
+ d_fprintf(stderr, _("value too short for regular DWORD\n"));
+ goto done;
+ }
+
+ v = IVAL(value->data.data, 0);
+ v += state->increment;
+ state->newvalue = v;
+
+ SIVAL(value->data.data, 0, v);
state->werr = reg_setvalue(key, state->valuename, value);
if (!W_ERROR_IS_OK(state->werr)) {
diff --git a/source3/utils/net_registry_util.c b/source3/utils/net_registry_util.c
index a3b84a344f..7cbf238aeb 100644
--- a/source3/utils/net_registry_util.c
+++ b/source3/utils/net_registry_util.c
@@ -41,30 +41,46 @@ void print_registry_value(const struct registry_value *valvalue, bool raw)
str_regtype(valvalue->type));
}
switch(valvalue->type) {
- case REG_DWORD:
+ case REG_DWORD: {
+ uint32_t v = 0;
+ if (valvalue->data.length >= 4) {
+ v = IVAL(valvalue->data.data, 0);
+ }
if (!raw) {
d_printf(_("Value = "));
}
- d_printf("%d\n", valvalue->v.dword);
+ d_printf("%d\n", v);
break;
+ }
case REG_SZ:
- case REG_EXPAND_SZ:
+ case REG_EXPAND_SZ: {
+ const char *s;
+
+ if (!pull_reg_sz(talloc_tos(), &valvalue->data, &s)) {
+ break;
+ }
if (!raw) {
d_printf(_("Value = \""));
}
- d_printf("%s", valvalue->v.sz.str);
+ d_printf("%s", s);
if (!raw) {
d_printf("\"");
}
d_printf("\n");
break;
+ }
case REG_MULTI_SZ: {
uint32 j;
- for (j = 0; j < valvalue->v.multi_sz.num_strings; j++) {
+ const char **a;
+
+ if (!pull_reg_multi_sz(talloc_tos(), &valvalue->data, &a)) {
+ break;
+ }
+ for (j = 0; a[j] != NULL; j++) {
if (!raw) {
d_printf(_("Value[%3.3d] = \""), j);
}
- d_printf("%s", valvalue->v.multi_sz.strings[j]);
+ d_printf("%s", a[j]);
if (!raw) {
d_printf("\"");
}
@@ -76,7 +92,7 @@ void print_registry_value(const struct registry_value *valvalue, bool raw)
if (!raw) {
d_printf(_("Value = "));
}
- d_printf(_("%d bytes\n"), (int)valvalue->v.binary.length);
+ d_printf(_("%d bytes\n"), (int)valvalue->data.length);
break;
default:
if (!raw) {
diff --git a/source3/utils/net_rpc_registry.c b/source3/utils/net_rpc_registry.c
index fb1e14f0d5..9fec13b371 100644
--- a/source3/utils/net_rpc_registry.c
+++ b/source3/utils/net_rpc_registry.c
@@ -352,12 +352,14 @@ static NTSTATUS registry_enumvalues(TALLOC_CTX *ctx,
goto error;
}
- err = registry_pull_value(values, &values[i], type, data,
- data_size, value_length);
- if (!W_ERROR_IS_OK(err)) {
- status = werror_to_ntstatus(err);
+ values[i] = talloc_zero(values, struct registry_value);
+ if (values[i] == NULL) {
+ status = NT_STATUS_NO_MEMORY;
goto error;
}
+
+ values[i]->type = type;
+ values[i]->data = data_blob_talloc(values[i], data, data_size);
}
*pnum_values = num_values;
@@ -394,22 +396,14 @@ static NTSTATUS registry_setvalue(TALLOC_CTX *mem_ctx,
const struct registry_value *value)
{
struct winreg_String name_string;
- DATA_BLOB blob;
NTSTATUS result;
- WERROR err;
-
- err = registry_push_value(mem_ctx, value, &blob);
- if (!W_ERROR_IS_OK(err)) {
- return werror_to_ntstatus(err);
- }
ZERO_STRUCT(name_string);
name_string.name = name;
- result = rpccli_winreg_SetValue(pipe_hnd, blob.data, key_hnd,
+ result = rpccli_winreg_SetValue(pipe_hnd, mem_ctx, key_hnd,
name_string, value->type,
- blob.data, blob.length, NULL);
- TALLOC_FREE(blob.data);
+ value->data.data, value->data.length, NULL);
return result;
}
@@ -441,13 +435,17 @@ static NTSTATUS rpc_registry_setvalue_internal(struct net_context *c,
}
if (strequal(argv[2], "dword")) {
+ uint32_t v = strtoul(argv[3], NULL, 10);
value.type = REG_DWORD;
- value.v.dword = strtoul(argv[3], NULL, 10);
+ value.data = data_blob_talloc(mem_ctx, NULL, 4);
+ SIVAL(value.data.data, 0, v);
}
else if (strequal(argv[2], "sz")) {
value.type = REG_SZ;
- value.v.sz.len = strlen(argv[3])+1;
- value.v.sz.str = CONST_DISCARD(char *, argv[3]);
+ if (!push_reg_sz(mem_ctx, &value.data, argv[3])) {
+ status = NT_STATUS_NO_MEMORY;
+ goto error;
+ }
}
else {
d_fprintf(stderr, _("type \"%s\" not implemented\n"), argv[2]);
@@ -551,11 +549,9 @@ static NTSTATUS rpc_registry_getvalue_internal(struct net_context *c,
{
struct policy_handle hive_hnd, key_hnd;
NTSTATUS status;
- WERROR werr;
struct winreg_String valuename;
struct registry_value *value = NULL;
enum winreg_Type type = REG_NONE;
- uint8_t *data = NULL;
uint32_t data_size = 0;
uint32_t value_length = 0;
TALLOC_CTX *tmp_ctx = talloc_stackframe();
@@ -573,6 +569,11 @@ static NTSTATUS rpc_registry_getvalue_internal(struct net_context *c,
valuename.name = argv[1];
+ value = talloc_zero(tmp_ctx, struct registry_value);
+ if (value == NULL) {
+ return NT_STATUS_NO_MEMORY;
+ }
+
/*
* call QueryValue once with data == NULL to get the
* needed memory size to be allocated, then allocate
@@ -581,7 +582,7 @@ static NTSTATUS rpc_registry_getvalue_internal(struct net_context *c,
status = rpccli_winreg_QueryValue(pipe_hnd, tmp_ctx, &key_hnd,
&valuename,
&type,
- data,
+ NULL,
&data_size,
&value_length,
NULL);
@@ -592,13 +593,12 @@ static NTSTATUS rpc_registry_getvalue_internal(struct net_context *c,
goto done;
}
- data = (uint8 *)TALLOC(tmp_ctx, data_size);
- value_length = 0;
+ value->data = data_blob_talloc(tmp_ctx, NULL, data_size);
status = rpccli_winreg_QueryValue(pipe_hnd, tmp_ctx, &key_hnd,
&valuename,
&type,
- data,
+ value->data.data,
&data_size,
&value_length,
NULL);
@@ -609,13 +609,6 @@ static NTSTATUS rpc_registry_getvalue_internal(struct net_context *c,
goto done;
}
- werr = registry_pull_value(tmp_ctx, &value, type, data,
- data_size, value_length);
- if (!W_ERROR_IS_OK(werr)) {
- status = werror_to_ntstatus(werr);
- goto done;
- }
-
print_registry_value(value, raw);
done: