* Unix SMB/CIFS implementation.
* Virtual Windows Registry Layer
* Copyright (C) Gerald Carter 2002-2005
+ * Copyright (C) Michael Adam 2007-2010
*
* 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
/* Implementation of registry frontend view functions. */
#include "includes.h"
+#include "registry.h"
+#include "reg_objects.h"
+#include "util_tdb.h"
+#include "dbwrap.h"
+#include "../libcli/registry/util_reg.h"
#undef DBGC_CLASS
#define DBGC_CLASS DBGC_REGISTRY
+/* low level structure to contain registry values */
+
+struct regval_blob {
+ fstring valuename;
+ uint32_t type;
+ /* this should be encapsulated in an RPC_DATA_BLOB */
+ uint32_t size; /* in bytes */
+ uint8_t *data_p;
+};
+
+/* container for registry values */
+
+struct regval_ctr {
+ uint32_t num_values;
+ struct regval_blob **values;
+ int seqnum;
+};
+
struct regsubkey_ctr {
uint32_t num_subkeys;
char **subkeys;
context for internal private data.
There is no longer a regval_ctr_intit() and regval_ctr_destroy()
- pair of functions. Simply TALLOC_ZERO_P() and TALLOC_FREE() the
+ pair of functions. Simply talloc_zero() and TALLOC_FREE() the
object.
**********************************************************************/
static WERROR regsubkey_ctr_hash_keyname(struct regsubkey_ctr *ctr,
const char *keyname,
- uint32 idx)
+ uint32_t idx)
{
WERROR werr;
werr = ntstatus_to_werror(dbwrap_store_bystring_upper(ctr->subkeys_hash,
keyname,
- make_tdb_data((uint8 *)&idx,
+ make_tdb_data((uint8_t *)&idx,
sizeof(idx)),
TDB_REPLACE));
if (!W_ERROR_IS_OK(werr)) {
static WERROR regsubkey_ctr_index_for_keyname(struct regsubkey_ctr *ctr,
const char *keyname,
- uint32 *idx)
+ uint32_t *idx)
{
TDB_DATA data;
}
if (idx != NULL) {
- *idx = *(uint32 *)data.dptr;
+ *idx = *(uint32_t *)data.dptr;
}
talloc_free(data.dptr);
return WERR_OK;
}
- if (!(newkeys = TALLOC_REALLOC_ARRAY(ctr, ctr->subkeys, char *,
+ if (!(newkeys = talloc_realloc(ctr, ctr->subkeys, char *,
ctr->num_subkeys+1))) {
return WERR_NOMEM;
}
WERROR regsubkey_ctr_delkey( struct regsubkey_ctr *ctr, const char *keyname )
{
WERROR werr;
- uint32 idx, j;
+ uint32_t idx, j;
if (keyname == NULL) {
return WERR_INVALID_PARAM;
* Utility functions for struct regval_ctr
*/
+/**
+ * allocate a regval_ctr structure.
+ */
+WERROR regval_ctr_init(TALLOC_CTX *mem_ctx, struct regval_ctr **ctr)
+{
+ if (ctr == NULL) {
+ return WERR_INVALID_PARAM;
+ }
+
+ *ctr = talloc_zero(mem_ctx, struct regval_ctr);
+ if (*ctr == NULL) {
+ return WERR_NOMEM;
+ }
+
+ return WERR_OK;
+}
+
/***********************************************************************
How many keys does the container hold ?
**********************************************************************/
if ( val->data_p && val->size )
{
- if ( !(copy->data_p = (uint8 *)memdup( val->data_p,
+ if ( !(copy->data_p = (uint8_t *)memdup( val->data_p,
val->size )) ) {
DEBUG(0,("dup_registry_value: memdup() failed for [%d] "
"bytes!\n", val->size));
/**********************************************************************
*********************************************************************/
-uint8* regval_data_p(struct regval_blob *val)
+uint8_t* regval_data_p(struct regval_blob *val)
{
return val->data_p;
}
/**********************************************************************
*********************************************************************/
-uint32 regval_size(struct regval_blob *val)
+uint32_t regval_size(struct regval_blob *val)
{
return val->size;
}
/**********************************************************************
*********************************************************************/
-uint32 regval_type(struct regval_blob *val)
+uint32_t regval_type(struct regval_blob *val)
{
return val->type;
}
**********************************************************************/
struct regval_blob *regval_ctr_specific_value(struct regval_ctr *ctr,
- uint32 idx)
+ uint32_t idx)
{
if ( !(idx < ctr->num_values) )
return NULL;
**********************************************************************/
struct regval_blob *regval_compose(TALLOC_CTX *ctx, const char *name,
- uint16 type,
- const char *data_p, size_t size)
+ uint32_t type,
+ const uint8_t *data_p, size_t size)
{
- struct regval_blob *regval = TALLOC_P(ctx, struct regval_blob);
+ struct regval_blob *regval = talloc(ctx, struct regval_blob);
if (regval == NULL) {
return NULL;
fstrcpy(regval->valuename, name);
regval->type = type;
if (size) {
- regval->data_p = (uint8 *)TALLOC_MEMDUP(regval, data_p, size);
+ regval->data_p = (uint8_t *)TALLOC_MEMDUP(regval, data_p, size);
if (!regval->data_p) {
TALLOC_FREE(regval);
return NULL;
Add a new registry value to the array
**********************************************************************/
-int regval_ctr_addvalue(struct regval_ctr *ctr, const char *name, uint16 type,
- const char *data_p, size_t size)
+int regval_ctr_addvalue(struct regval_ctr *ctr, const char *name, uint32_t type,
+ const uint8_t *data_p, size_t size)
{
if ( !name )
return ctr->num_values;
/* allocate a slot in the array of pointers */
if ( ctr->num_values == 0 ) {
- ctr->values = TALLOC_P( ctr, struct regval_blob *);
+ ctr->values = talloc( ctr, struct regval_blob *);
} else {
- ctr->values = TALLOC_REALLOC_ARRAY(ctr, ctr->values,
+ ctr->values = talloc_realloc(ctr, ctr->values,
struct regval_blob *,
ctr->num_values+1);
}
}
return regval_ctr_addvalue(ctr, name, REG_SZ,
- (const char *)blob.data,
+ (const uint8_t *)blob.data,
+ blob.length);
+}
+
+/***********************************************************************
+ Add a new registry MULTI_SZ value to the array
+ **********************************************************************/
+
+int regval_ctr_addvalue_multi_sz(struct regval_ctr *ctr, const char *name, const char **data)
+{
+ DATA_BLOB blob;
+
+ if (!push_reg_multi_sz(ctr, &blob, data)) {
+ return -1;
+ }
+
+ return regval_ctr_addvalue(ctr, name, REG_MULTI_SZ,
+ (const uint8_t *)blob.data,
blob.length);
}
{
if ( val ) {
regval_ctr_addvalue(ctr, val->valuename, val->type,
- (char *)val->data_p, val->size);
+ (uint8_t *)val->data_p, val->size);
}
return ctr->num_values;
return NULL;
}
+int regval_ctr_get_seqnum(struct regval_ctr *ctr)
+{
+ if (ctr == NULL) {
+ return -1;
+ }
+
+ return ctr->seqnum;
+}
+
+WERROR regval_ctr_set_seqnum(struct regval_ctr *ctr, int seqnum)
+{
+ if (ctr == NULL) {
+ return WERR_INVALID_PARAM;
+ }
+
+ ctr->seqnum = seqnum;
+
+ return WERR_OK;
+}
+
/***********************************************************************
- return the data_p as a uint32
+ return the data_p as a uint32_t
**********************************************************************/
-uint32 regval_dword(struct regval_blob *val)
+uint32_t regval_dword(struct regval_blob *val)
{
- uint32 data;
+ uint32_t data;
data = IVAL( regval_data_p(val), 0 );
return the data_p as a character string
**********************************************************************/
-char *regval_sz(struct regval_blob *val)
+const char *regval_sz(struct regval_blob *val)
{
- char *data = NULL;
+ const char *data = NULL;
+ DATA_BLOB blob = data_blob_const(regval_data_p(val), regval_size(val));
+
+ pull_reg_sz(talloc_tos(), &blob, &data);
- rpcstr_pull_talloc(talloc_tos(), &data,
- regval_data_p(val), regval_size(val),0);
return data;
}