1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-23 17:34:34 +03:00

r25544: Cleanup some more indents in lib/registry.

Guenther
(This used to be commit 0d9826dc54)
This commit is contained in:
Günther Deschner 2007-10-06 00:17:44 +00:00 committed by Gerald (Jerry) Carter
parent e511090a43
commit cc8f4eb3cd
16 changed files with 1430 additions and 1199 deletions

View File

@ -1,7 +1,7 @@
/*
Unix SMB/CIFS implementation.
Registry interface
Copyright (C) Jelmer Vernooij 2004-2007.
Copyright (C) Jelmer Vernooij 2004-2007.
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
@ -30,10 +30,10 @@ struct dir_key {
static struct hive_operations reg_backend_dir;
static WERROR reg_dir_add_key(TALLOC_CTX *mem_ctx,
const struct hive_key *parent,
const char *name, const char *classname,
struct security_descriptor *desc,
struct hive_key **result)
const struct hive_key *parent,
const char *name, const char *classname,
struct security_descriptor *desc,
struct hive_key **result)
{
struct dir_key *dk = talloc_get_type(parent, struct dir_key);
char *path;
@ -74,8 +74,8 @@ static WERROR reg_dir_del_key(const struct hive_key *k, const char *name)
}
static WERROR reg_dir_open_key(TALLOC_CTX *mem_ctx,
const struct hive_key *parent,
const char *name, struct hive_key **subkey)
const struct hive_key *parent,
const char *name, struct hive_key **subkey)
{
DIR *d;
char *fullpath;
@ -91,7 +91,8 @@ static WERROR reg_dir_open_key(TALLOC_CTX *mem_ctx,
d = opendir(fullpath);
if (d == NULL) {
DEBUG(3,("Unable to open '%s': %s\n", fullpath, strerror(errno)));
DEBUG(3,("Unable to open '%s': %s\n", fullpath,
strerror(errno)));
return WERR_BADFILE;
}
closedir(d);
@ -103,10 +104,10 @@ static WERROR reg_dir_open_key(TALLOC_CTX *mem_ctx,
}
static WERROR reg_dir_key_by_index(TALLOC_CTX *mem_ctx,
const struct hive_key *k, uint32_t idx,
const char **name,
const char **classname,
NTTIME *last_mod_time)
const struct hive_key *k, uint32_t idx,
const char **name,
const char **classname,
NTTIME *last_mod_time)
{
struct dirent *e;
const struct dir_key *dk = talloc_get_type(k, struct dir_key);
@ -154,7 +155,7 @@ static WERROR reg_dir_key_by_index(TALLOC_CTX *mem_ctx,
}
WERROR reg_open_directory(TALLOC_CTX *parent_ctx,
const char *location, struct hive_key **key)
const char *location, struct hive_key **key)
{
struct dir_key *dk;
@ -169,7 +170,7 @@ WERROR reg_open_directory(TALLOC_CTX *parent_ctx,
}
WERROR reg_create_directory(TALLOC_CTX *parent_ctx,
const char *location, struct hive_key **key)
const char *location, struct hive_key **key)
{
if (mkdir(location, 0700) != 0) {
*key = NULL;
@ -180,10 +181,10 @@ WERROR reg_create_directory(TALLOC_CTX *parent_ctx,
}
static WERROR reg_dir_get_info(TALLOC_CTX *ctx, const struct hive_key *key,
const char **classname,
uint32_t *num_subkeys,
uint32_t *num_values,
NTTIME *lastmod)
const char **classname,
uint32_t *num_subkeys,
uint32_t *num_values,
NTTIME *lastmod)
{
DIR *d;
const struct dir_key *dk = talloc_get_type(key, struct dir_key);
@ -207,10 +208,12 @@ static WERROR reg_dir_get_info(TALLOC_CTX *ctx, const struct hive_key *key,
while((e = readdir(d))) {
if(!ISDOT(e->d_name) && !ISDOTDOT(e->d_name)) {
char *path = talloc_asprintf(ctx, "%s/%s", dk->path, e->d_name);
char *path = talloc_asprintf(ctx, "%s/%s",
dk->path, e->d_name);
if (stat(path, &st) < 0) {
DEBUG(0, ("Error statting %s: %s\n", path, strerror(errno)));
DEBUG(0, ("Error statting %s: %s\n", path,
strerror(errno)));
continue;
}
@ -231,8 +234,8 @@ static WERROR reg_dir_get_info(TALLOC_CTX *ctx, const struct hive_key *key,
return WERR_OK;
}
static WERROR reg_dir_set_value (struct hive_key *key, const char *name,
uint32_t type, const DATA_BLOB data)
static WERROR reg_dir_set_value(struct hive_key *key, const char *name,
uint32_t type, const DATA_BLOB data)
{
const struct dir_key *dk = talloc_get_type(key, struct dir_key);
char *path = talloc_asprintf(dk, "%s/%s", dk->path, name);
@ -245,9 +248,9 @@ static WERROR reg_dir_set_value (struct hive_key *key, const char *name,
return WERR_OK;
}
static WERROR reg_dir_get_value (TALLOC_CTX *mem_ctx,
struct hive_key *key, const char *name,
uint32_t *type, DATA_BLOB *data)
static WERROR reg_dir_get_value(TALLOC_CTX *mem_ctx,
struct hive_key *key, const char *name,
uint32_t *type, DATA_BLOB *data)
{
const struct dir_key *dk = talloc_get_type(key, struct dir_key);
char *path = talloc_asprintf(mem_ctx, "%s/%s", dk->path, name);
@ -268,10 +271,10 @@ static WERROR reg_dir_get_value (TALLOC_CTX *mem_ctx,
return WERR_OK;
}
static WERROR reg_dir_enum_value (TALLOC_CTX *mem_ctx,
const struct hive_key *key, int idx,
const char **name,
uint32_t *type, DATA_BLOB *data)
static WERROR reg_dir_enum_value(TALLOC_CTX *mem_ctx,
const struct hive_key *key, int idx,
const char **name,
uint32_t *type, DATA_BLOB *data)
{
const struct dir_key *dk = talloc_get_type(key, struct dir_key);
DIR *d;
@ -280,7 +283,8 @@ static WERROR reg_dir_enum_value (TALLOC_CTX *mem_ctx,
d = opendir(dk->path);
if (d == NULL) {
DEBUG(3,("Unable to open '%s': %s\n", dk->path, strerror(errno)));
DEBUG(3,("Unable to open '%s': %s\n", dk->path,
strerror(errno)));
return WERR_BADFILE;
}
@ -292,7 +296,9 @@ static WERROR reg_dir_enum_value (TALLOC_CTX *mem_ctx,
if (i == idx) {
if (name != NULL)
*name = talloc_strdup(mem_ctx, e->d_name);
W_ERROR_NOT_OK_RETURN(reg_dir_get_value(mem_ctx, key, *name, type, data));
W_ERROR_NOT_OK_RETURN(reg_dir_get_value(mem_ctx, key,
*name, type,
data));
return WERR_OK;
}

View File

@ -2,7 +2,7 @@
/*
Unix SMB/CIFS implementation.
Registry hive interface
Copyright (C) Jelmer Vernooij 2003-2007.
Copyright (C) Jelmer Vernooij 2003-2007.
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
@ -25,9 +25,9 @@
/** Open a registry file/host/etc */
_PUBLIC_ WERROR reg_open_hive(TALLOC_CTX *parent_ctx, const char *location,
struct auth_session_info *session_info,
struct cli_credentials *credentials,
struct hive_key **root)
struct auth_session_info *session_info,
struct cli_credentials *credentials,
struct hive_key **root)
{
int fd, num;
char peek[20];
@ -54,28 +54,33 @@ _PUBLIC_ WERROR reg_open_hive(TALLOC_CTX *parent_ctx, const char *location,
return reg_open_regf_file(parent_ctx, location, root);
} else if (!strncmp(peek, "TDB file", 8)) {
close(fd);
return reg_open_ldb_file(parent_ctx, location, session_info, credentials, root);
return reg_open_ldb_file(parent_ctx, location, session_info,
credentials, root);
}
return WERR_BADFILE;
}
_PUBLIC_ WERROR hive_key_get_info(TALLOC_CTX *mem_ctx, const struct hive_key *key,
const char **classname, uint32_t *num_subkeys,
uint32_t *num_values,
NTTIME *last_change_time)
_PUBLIC_ WERROR hive_key_get_info(TALLOC_CTX *mem_ctx,
const struct hive_key *key,
const char **classname, uint32_t *num_subkeys,
uint32_t *num_values,
NTTIME *last_change_time)
{
return key->ops->get_key_info(mem_ctx, key, classname, num_subkeys,
num_values, last_change_time);
num_values, last_change_time);
}
_PUBLIC_ WERROR hive_key_add_name(TALLOC_CTX *ctx, const struct hive_key *parent_key,
const char *name, const char *classname, struct security_descriptor *desc,
struct hive_key **key)
_PUBLIC_ WERROR hive_key_add_name(TALLOC_CTX *ctx,
const struct hive_key *parent_key,
const char *name, const char *classname,
struct security_descriptor *desc,
struct hive_key **key)
{
SMB_ASSERT(strchr(name, '\\') == NULL);
return parent_key->ops->add_key(ctx, parent_key, name, classname, desc, key);
return parent_key->ops->add_key(ctx, parent_key, name, classname,
desc, key);
}
_PUBLIC_ WERROR hive_key_del(const struct hive_key *key, const char *name)
@ -84,20 +89,21 @@ _PUBLIC_ WERROR hive_key_del(const struct hive_key *key, const char *name)
}
_PUBLIC_ WERROR hive_get_key_by_name(TALLOC_CTX *mem_ctx,
const struct hive_key *key, const char *name,
struct hive_key **subkey)
const struct hive_key *key,
const char *name,
struct hive_key **subkey)
{
return key->ops->get_key_by_name(mem_ctx, key, name, subkey);
}
WERROR hive_enum_key(TALLOC_CTX *mem_ctx,
const struct hive_key *key, uint32_t idx,
const char **name,
const char **classname,
NTTIME *last_mod_time)
const struct hive_key *key, uint32_t idx,
const char **name,
const char **classname,
NTTIME *last_mod_time)
{
return key->ops->enum_key(mem_ctx, key, idx, name, classname,
last_mod_time);
last_mod_time);
}
WERROR hive_set_value(struct hive_key *key, const char *name, uint32_t type,
@ -109,9 +115,9 @@ WERROR hive_set_value(struct hive_key *key, const char *name, uint32_t type,
return key->ops->set_value(key, name, type, data);
}
WERROR hive_get_value (TALLOC_CTX *mem_ctx,
struct hive_key *key, const char *name,
uint32_t *type, DATA_BLOB *data)
WERROR hive_get_value(TALLOC_CTX *mem_ctx,
struct hive_key *key, const char *name,
uint32_t *type, DATA_BLOB *data)
{
if (key->ops->get_value_by_name == NULL)
return WERR_NOT_SUPPORTED;
@ -119,9 +125,10 @@ WERROR hive_get_value (TALLOC_CTX *mem_ctx,
return key->ops->get_value_by_name(mem_ctx, key, name, type, data);
}
WERROR hive_get_value_by_index (TALLOC_CTX *mem_ctx,
struct hive_key *key, uint32_t idx, const char **name,
uint32_t *type, DATA_BLOB *data)
WERROR hive_get_value_by_index(TALLOC_CTX *mem_ctx,
struct hive_key *key, uint32_t idx,
const char **name,
uint32_t *type, DATA_BLOB *data)
{
if (key->ops->enum_value == NULL)
return WERR_NOT_SUPPORTED;
@ -130,7 +137,7 @@ WERROR hive_get_value_by_index (TALLOC_CTX *mem_ctx,
}
WERROR hive_del_value (struct hive_key *key, const char *name)
WERROR hive_del_value(struct hive_key *key, const char *name)
{
if (key->ops->delete_value == NULL)
return WERR_NOT_SUPPORTED;

View File

@ -47,25 +47,26 @@ struct hive_operations {
* Open a specific subkey
*/
WERROR (*enum_key) (TALLOC_CTX *mem_ctx,
const struct hive_key *key, uint32_t idx,
const char **name,
const char **classname,
NTTIME *last_mod_time);
const struct hive_key *key, uint32_t idx,
const char **name,
const char **classname,
NTTIME *last_mod_time);
/**
* Open a subkey by name
*/
WERROR (*get_key_by_name) (TALLOC_CTX *mem_ctx,
const struct hive_key *key, const char *name,
struct hive_key **subkey);
const struct hive_key *key, const char *name,
struct hive_key **subkey);
/**
* Add a new key.
*/
WERROR (*add_key) (TALLOC_CTX *ctx,
const struct hive_key *parent_key, const char *name,
const char *classname, struct security_descriptor *desc,
struct hive_key **key);
const struct hive_key *parent_key, const char *name,
const char *classname,
struct security_descriptor *desc,
struct hive_key **key);
/**
* Remove an existing key.
*/
@ -80,22 +81,22 @@ struct hive_operations {
* Retrieve a registry value with a specific index.
*/
WERROR (*enum_value) (TALLOC_CTX *mem_ctx,
const struct hive_key *key, int idx,
const char **name, uint32_t *type,
DATA_BLOB *data);
const struct hive_key *key, int idx,
const char **name, uint32_t *type,
DATA_BLOB *data);
/**
* Retrieve a registry value with the specified name
*/
WERROR (*get_value_by_name) (TALLOC_CTX *mem_ctx,
struct hive_key *key, const char *name,
uint32_t *type, DATA_BLOB *data);
struct hive_key *key, const char *name,
uint32_t *type, DATA_BLOB *data);
/**
* Set a value on the specified registry key.
*/
WERROR (*set_value) (struct hive_key *key, const char *name,
uint32_t type, const DATA_BLOB data);
uint32_t type, const DATA_BLOB data);
/**
* Remove a value.
@ -112,7 +113,7 @@ struct hive_operations {
* security descriptors.
*/
WERROR (*set_sec_desc) (struct hive_key *key,
const struct security_descriptor *desc);
const struct security_descriptor *desc);
/**
* Retrieve the security descriptor on a registry key.
@ -122,76 +123,78 @@ struct hive_operations {
* security descriptors.
*/
WERROR (*get_sec_desc) (TALLOC_CTX *ctx,
const struct hive_key *key,
struct security_descriptor **desc);
const struct hive_key *key,
struct security_descriptor **desc);
/**
* Retrieve general information about a key.
*/
WERROR (*get_key_info) (TALLOC_CTX *mem_ctx,
const struct hive_key *key,
const char **classname,
uint32_t *num_subkeys,
uint32_t *num_values,
NTTIME *last_change_time);
const struct hive_key *key,
const char **classname,
uint32_t *num_subkeys,
uint32_t *num_values,
NTTIME *last_change_time);
};
struct cli_credentials;
struct auth_session_info;
WERROR reg_open_hive(TALLOC_CTX *parent_ctx, const char *location,
struct auth_session_info *session_info,
struct cli_credentials *credentials,
struct hive_key **root);
struct auth_session_info *session_info,
struct cli_credentials *credentials,
struct hive_key **root);
WERROR hive_key_get_info(TALLOC_CTX *mem_ctx, const struct hive_key *key,
const char **classname, uint32_t *num_subkeys,
uint32_t *num_values,
NTTIME *last_change_time);
const char **classname, uint32_t *num_subkeys,
uint32_t *num_values,
NTTIME *last_change_time);
WERROR hive_key_add_name(TALLOC_CTX *ctx, const struct hive_key *parent_key,
const char *name, const char *classname, struct security_descriptor *desc,
struct hive_key **key);
const char *name, const char *classname,
struct security_descriptor *desc,
struct hive_key **key);
WERROR hive_key_del(const struct hive_key *key, const char *name);
WERROR hive_get_key_by_name(TALLOC_CTX *mem_ctx,
const struct hive_key *key, const char *name,
struct hive_key **subkey);
const struct hive_key *key, const char *name,
struct hive_key **subkey);
WERROR hive_enum_key(TALLOC_CTX *mem_ctx,
const struct hive_key *key, uint32_t idx,
const char **name,
const char **classname,
NTTIME *last_mod_time);
const struct hive_key *key, uint32_t idx,
const char **name,
const char **classname,
NTTIME *last_mod_time);
WERROR hive_set_value (struct hive_key *key, const char *name,
uint32_t type, const DATA_BLOB data);
WERROR hive_set_value(struct hive_key *key, const char *name,
uint32_t type, const DATA_BLOB data);
WERROR hive_get_value (TALLOC_CTX *mem_ctx,
struct hive_key *key, const char *name,
uint32_t *type, DATA_BLOB *data);
WERROR hive_get_value_by_index (TALLOC_CTX *mem_ctx,
struct hive_key *key, uint32_t idx, const char **name,
uint32_t *type, DATA_BLOB *data);
WERROR hive_get_value(TALLOC_CTX *mem_ctx,
struct hive_key *key, const char *name,
uint32_t *type, DATA_BLOB *data);
WERROR hive_get_value_by_index(TALLOC_CTX *mem_ctx,
struct hive_key *key, uint32_t idx,
const char **name,
uint32_t *type, DATA_BLOB *data);
WERROR hive_del_value (struct hive_key *key, const char *name);
WERROR hive_del_value(struct hive_key *key, const char *name);
WERROR hive_key_flush(struct hive_key *key);
/* Individual backends */
WERROR reg_open_directory(TALLOC_CTX *parent_ctx,
const char *location, struct hive_key **key);
const char *location, struct hive_key **key);
WERROR reg_open_regf_file(TALLOC_CTX *parent_ctx,
const char *location, struct hive_key **key);
const char *location, struct hive_key **key);
WERROR reg_open_ldb_file(TALLOC_CTX *parent_ctx, const char *location,
struct auth_session_info *session_info,
struct cli_credentials *credentials,
struct hive_key **k);
struct auth_session_info *session_info,
struct cli_credentials *credentials,
struct hive_key **k);
WERROR reg_create_directory(TALLOC_CTX *parent_ctx,
const char *location, struct hive_key **key);
const char *location, struct hive_key **key);
WERROR reg_create_regf_file(TALLOC_CTX *parent_ctx,
const char *location,
int major_version,
struct hive_key **key);
const char *location,
int major_version,
struct hive_key **key);
#endif /* __REGISTRY_HIVE_H__ */

View File

@ -56,15 +56,16 @@ _PUBLIC_ const char *reg_get_predef_name(uint32_t hkey)
/** Get predefined key by name. */
_PUBLIC_ WERROR reg_get_predefined_key_by_name(struct registry_context *ctx,
const char *name,
struct registry_key **key)
const char *name,
struct registry_key **key)
{
int i;
for (i = 0; reg_predefined_keys[i].name; i++) {
if (!strcasecmp(reg_predefined_keys[i].name, name))
return reg_get_predefined_key(ctx, reg_predefined_keys[i].handle,
key);
return reg_get_predefined_key(ctx,
reg_predefined_keys[i].handle,
key);
}
DEBUG(1, ("No predefined key with name '%s'\n", name));
@ -74,7 +75,7 @@ _PUBLIC_ WERROR reg_get_predefined_key_by_name(struct registry_context *ctx,
/** Get predefined key by id. */
_PUBLIC_ WERROR reg_get_predefined_key(const struct registry_context *ctx,
uint32_t hkey, struct registry_key **key)
uint32_t hkey, struct registry_key **key)
{
return ctx->ops->get_predefined_key(ctx, hkey, key);
}
@ -85,10 +86,11 @@ _PUBLIC_ WERROR reg_get_predefined_key(const struct registry_context *ctx,
* then falls back to get_subkey_by_name and later get_subkey_by_index
*/
_PUBLIC_ WERROR reg_open_key(TALLOC_CTX *mem_ctx, struct registry_key *parent,
const char *name, struct registry_key **result)
const char *name, struct registry_key **result)
{
if (parent == NULL) {
DEBUG(0, ("Invalid parent key specified for open of '%s'\n", name));
DEBUG(0, ("Invalid parent key specified for open of '%s'\n",
name));
return WERR_INVALID_PARAM;
}
@ -114,19 +116,19 @@ _PUBLIC_ WERROR reg_key_get_value_by_index(TALLOC_CTX *mem_ctx,
if (key->context->ops->enum_value == NULL)
return WERR_NOT_SUPPORTED;
return key->context->ops->enum_value(mem_ctx, key, idx, name, type,
data);
return key->context->ops->enum_value(mem_ctx, key, idx, name,
type, data);
}
/**
* Get the number of subkeys.
*/
_PUBLIC_ WERROR reg_key_get_info(TALLOC_CTX *mem_ctx,
const struct registry_key *key,
const char **classname,
uint32_t *num_subkeys,
uint32_t *num_values,
NTTIME *last_change_time)
const struct registry_key *key,
const char **classname,
uint32_t *num_subkeys,
uint32_t *num_values,
NTTIME *last_change_time)
{
if (key == NULL)
return WERR_INVALID_PARAM;
@ -135,16 +137,18 @@ _PUBLIC_ WERROR reg_key_get_info(TALLOC_CTX *mem_ctx,
return WERR_NOT_SUPPORTED;
return key->context->ops->get_key_info(mem_ctx,
key, classname, num_subkeys,
num_values, last_change_time);
key, classname, num_subkeys,
num_values, last_change_time);
}
/**
* Get subkey by index.
*/
_PUBLIC_ WERROR reg_key_get_subkey_by_index(TALLOC_CTX *mem_ctx,
const struct registry_key *key, int idx, const char **name,
const char **keyclass, NTTIME *last_changed_time)
const struct registry_key *key,
int idx, const char **name,
const char **keyclass,
NTTIME *last_changed_time)
{
if (key == NULL)
return WERR_INVALID_PARAM;
@ -153,17 +157,17 @@ _PUBLIC_ WERROR reg_key_get_subkey_by_index(TALLOC_CTX *mem_ctx,
return WERR_NOT_SUPPORTED;
return key->context->ops->enum_key(mem_ctx, key, idx, name,
keyclass, last_changed_time);
keyclass, last_changed_time);
}
/**
* Get value by name.
*/
_PUBLIC_ WERROR reg_key_get_value_by_name(TALLOC_CTX *mem_ctx,
const struct registry_key *key,
const char *name,
uint32_t *type,
DATA_BLOB *data)
const struct registry_key *key,
const char *name,
uint32_t *type,
DATA_BLOB *data)
{
if (key == NULL)
return WERR_INVALID_PARAM;
@ -192,10 +196,10 @@ _PUBLIC_ WERROR reg_key_del(struct registry_key *parent, const char *name)
* Add a key.
*/
_PUBLIC_ WERROR reg_key_add_name(TALLOC_CTX *mem_ctx,
struct registry_key *parent,
const char *name, const char *key_class,
struct security_descriptor *desc,
struct registry_key **newkey)
struct registry_key *parent,
const char *name, const char *key_class,
struct security_descriptor *desc,
struct registry_key **newkey)
{
if (parent == NULL)
return WERR_INVALID_PARAM;
@ -207,14 +211,14 @@ _PUBLIC_ WERROR reg_key_add_name(TALLOC_CTX *mem_ctx,
}
return parent->context->ops->create_key(mem_ctx, parent, name,
key_class, desc, newkey);
key_class, desc, newkey);
}
/**
* Set a value.
*/
_PUBLIC_ WERROR reg_val_set(struct registry_key *key, const char *value,
uint32_t type, const DATA_BLOB data)
uint32_t type, const DATA_BLOB data)
{
if (key == NULL)
return WERR_INVALID_PARAM;
@ -233,8 +237,8 @@ _PUBLIC_ WERROR reg_val_set(struct registry_key *key, const char *value,
* Get the security descriptor on a key.
*/
_PUBLIC_ WERROR reg_get_sec_desc(TALLOC_CTX *ctx,
const struct registry_key *key,
struct security_descriptor **secdesc)
const struct registry_key *key,
struct security_descriptor **secdesc)
{
if (key == NULL)
return WERR_INVALID_PARAM;
@ -275,8 +279,8 @@ _PUBLIC_ WERROR reg_key_flush(struct registry_key *key)
}
_PUBLIC_ WERROR reg_get_security(TALLOC_CTX *mem_ctx,
const struct registry_key *key,
struct security_descriptor **security)
const struct registry_key *key,
struct security_descriptor **security)
{
if (key == NULL)
return WERR_INVALID_PARAM;
@ -288,7 +292,7 @@ _PUBLIC_ WERROR reg_get_security(TALLOC_CTX *mem_ctx,
}
_PUBLIC_ WERROR reg_set_security(struct registry_key *key,
struct security_descriptor *security)
struct security_descriptor *security)
{
if (key == NULL)
return WERR_INVALID_PARAM;

View File

@ -36,12 +36,15 @@ struct ldb_key_data
int subkey_count, value_count;
};
static void reg_ldb_unpack_value(TALLOC_CTX *mem_ctx, struct ldb_message *msg, const char **name,
uint32_t *type, DATA_BLOB *data)
static void reg_ldb_unpack_value(TALLOC_CTX *mem_ctx, struct ldb_message *msg,
const char **name, uint32_t *type,
DATA_BLOB *data)
{
const struct ldb_val *val;
if (name != NULL)
*name = talloc_strdup(mem_ctx, ldb_msg_find_attr_as_string(msg, "value", NULL));
*name = talloc_strdup(mem_ctx,
ldb_msg_find_attr_as_string(msg, "value",
NULL));
if (type != NULL)
*type = ldb_msg_find_attr_as_uint(msg, "type", 0);
@ -52,7 +55,8 @@ static void reg_ldb_unpack_value(TALLOC_CTX *mem_ctx, struct ldb_message *msg, c
case REG_SZ:
case REG_EXPAND_SZ:
data->length = convert_string_talloc(mem_ctx, CH_UTF8, CH_UTF16,
val->data, val->length, (void **)&data->data);
val->data, val->length,
(void **)&data->data);
break;
case REG_DWORD: {
@ -68,8 +72,9 @@ static void reg_ldb_unpack_value(TALLOC_CTX *mem_ctx, struct ldb_message *msg, c
}
static struct ldb_message *reg_ldb_pack_value(struct ldb_context *ctx,
TALLOC_CTX *mem_ctx, const char *name,
uint32_t type, DATA_BLOB data)
TALLOC_CTX *mem_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);
@ -81,12 +86,16 @@ static struct ldb_message *reg_ldb_pack_value(struct ldb_context *ctx,
case REG_SZ:
case REG_EXPAND_SZ:
val.length = convert_string_talloc(mem_ctx, CH_UTF16, CH_UTF8,
(void *)data.data, data.length, (void **)&val.data);
(void *)data.data,
data.length,
(void **)&val.data);
ldb_msg_add_value(msg, "data", &val, NULL);
break;
case REG_DWORD:
ldb_msg_add_string(msg, "data", talloc_asprintf(mem_ctx, "0x%x", IVAL(data.data, 0)));
ldb_msg_add_string(msg, "data",
talloc_asprintf(mem_ctx, "0x%x",
IVAL(data.data, 0)));
break;
default:
ldb_msg_add_value(msg, "data", &data, NULL);
@ -115,8 +124,8 @@ static int reg_close_ldb_key(struct ldb_key_data *key)
}
static struct ldb_dn *reg_path_to_ldb(TALLOC_CTX *mem_ctx,
const struct hive_key *from,
const char *path, const char *add)
const struct hive_key *from,
const char *path, const char *add)
{
TALLOC_CTX *local_ctx;
struct ldb_dn *ret;
@ -173,7 +182,8 @@ static WERROR cache_subkeys(struct ldb_key_data *kd)
ret = ldb_search(c, kd->dn, LDB_SCOPE_ONELEVEL, "(key=*)", NULL, &res);
if (ret != LDB_SUCCESS) {
DEBUG(0, ("Error getting subkeys for '%s': %s\n", ldb_dn_get_linearized(kd->dn), ldb_errstring(c)));
DEBUG(0, ("Error getting subkeys for '%s': %s\n",
ldb_dn_get_linearized(kd->dn), ldb_errstring(c)));
return WERR_FOOBAR;
}
@ -190,10 +200,12 @@ static WERROR cache_values(struct ldb_key_data *kd)
struct ldb_result *res;
int ret;
ret = ldb_search(c, kd->dn, LDB_SCOPE_ONELEVEL, "(value=*)", NULL, &res);
ret = ldb_search(c, kd->dn, LDB_SCOPE_ONELEVEL,
"(value=*)", NULL, &res);
if (ret != LDB_SUCCESS) {
DEBUG(0, ("Error getting values for '%s': %s\n", ldb_dn_get_linearized(kd->dn), ldb_errstring(c)));
DEBUG(0, ("Error getting values for '%s': %s\n",
ldb_dn_get_linearized(kd->dn), ldb_errstring(c)));
return WERR_FOOBAR;
}
kd->value_count = res->count;
@ -204,10 +216,10 @@ static WERROR cache_values(struct ldb_key_data *kd)
static WERROR ldb_get_subkey_by_id(TALLOC_CTX *mem_ctx,
const struct hive_key *k, uint32_t idx,
const char **name,
const char **classname,
NTTIME *last_mod_time)
const struct hive_key *k, uint32_t idx,
const char **name,
const char **classname,
NTTIME *last_mod_time)
{
struct ldb_message_element *el;
struct ldb_key_data *kd = talloc_get_type(k, struct ldb_key_data);
@ -237,8 +249,9 @@ static WERROR ldb_get_subkey_by_id(TALLOC_CTX *mem_ctx,
return WERR_OK;
}
static WERROR ldb_get_value_by_id(TALLOC_CTX *mem_ctx, const struct hive_key *k, int idx,
const char **name, uint32_t *data_type, DATA_BLOB *data)
static WERROR ldb_get_value_by_id(TALLOC_CTX *mem_ctx, const struct hive_key *k,
int idx, const char **name,
uint32_t *data_type, DATA_BLOB *data)
{
struct ldb_key_data *kd = talloc_get_type(k, struct ldb_key_data);
@ -247,16 +260,18 @@ static WERROR ldb_get_value_by_id(TALLOC_CTX *mem_ctx, const struct hive_key *k,
W_ERROR_NOT_OK_RETURN(cache_values(kd));
}
if(idx >= kd->value_count) return WERR_NO_MORE_ITEMS;
if (idx >= kd->value_count)
return WERR_NO_MORE_ITEMS;
reg_ldb_unpack_value(mem_ctx, kd->values[idx],
name, data_type, data);
name, data_type, data);
return WERR_OK;
}
static WERROR ldb_get_value(TALLOC_CTX *mem_ctx, struct hive_key *k,
const char *name, uint32_t *data_type, DATA_BLOB *data)
const char *name, uint32_t *data_type,
DATA_BLOB *data)
{
struct ldb_key_data *kd = talloc_get_type(k, struct ldb_key_data);
struct ldb_context *c = kd->ldb;
@ -269,7 +284,8 @@ static WERROR ldb_get_value(TALLOC_CTX *mem_ctx, struct hive_key *k,
talloc_free(query);
if (ret != LDB_SUCCESS) {
DEBUG(0, ("Error getting values for '%s': %s\n", ldb_dn_get_linearized(kd->dn), ldb_errstring(c)));
DEBUG(0, ("Error getting values for '%s': %s\n",
ldb_dn_get_linearized(kd->dn), ldb_errstring(c)));
return WERR_FOOBAR;
}
@ -282,7 +298,7 @@ static WERROR ldb_get_value(TALLOC_CTX *mem_ctx, struct hive_key *k,
}
static WERROR ldb_open_key(TALLOC_CTX *mem_ctx, const struct hive_key *h,
const char *name, struct hive_key **key)
const char *name, struct hive_key **key)
{
struct ldb_result *res;
struct ldb_dn *ldap_path;
@ -297,10 +313,11 @@ static WERROR ldb_open_key(TALLOC_CTX *mem_ctx, const struct hive_key *h,
if (ret != LDB_SUCCESS) {
DEBUG(3, ("Error opening key '%s': %s\n",
ldb_dn_get_linearized(ldap_path), ldb_errstring(c)));
ldb_dn_get_linearized(ldap_path), ldb_errstring(c)));
return WERR_FOOBAR;
} else if (res->count == 0) {
DEBUG(3, ("Key '%s' not found\n", ldb_dn_get_linearized(ldap_path)));
DEBUG(3, ("Key '%s' not found\n",
ldb_dn_get_linearized(ldap_path)));
talloc_free(res);
return WERR_NOT_FOUND;
}
@ -349,10 +366,10 @@ WERROR reg_open_ldb_file(TALLOC_CTX *parent_ctx, const char *location,
return WERR_OK;
}
static WERROR ldb_add_key (TALLOC_CTX *mem_ctx, const struct hive_key *parent,
const char *name, const char *classname,
struct security_descriptor *sd,
struct hive_key **newkey)
static WERROR ldb_add_key(TALLOC_CTX *mem_ctx, const struct hive_key *parent,
const char *name, const char *classname,
struct security_descriptor *sd,
struct hive_key **newkey)
{
const struct ldb_key_data *parentkd = (const struct ldb_key_data *)parent;
struct ldb_message *msg;
@ -365,7 +382,8 @@ static WERROR ldb_add_key (TALLOC_CTX *mem_ctx, const struct hive_key *parent,
ldb_msg_add_string(msg, "key", talloc_strdup(mem_ctx, name));
if (classname != NULL)
ldb_msg_add_string(msg, "classname", talloc_strdup(mem_ctx, classname));
ldb_msg_add_string(msg, "classname",
talloc_strdup(mem_ctx, classname));
ret = ldb_add(parentkd->ldb, msg);
if (ret < 0) {
@ -385,7 +403,7 @@ static WERROR ldb_add_key (TALLOC_CTX *mem_ctx, const struct hive_key *parent,
return WERR_OK;
}
static WERROR ldb_del_key (const struct hive_key *key, const char *child)
static WERROR ldb_del_key(const struct hive_key *key, const char *child)
{
int ret;
struct ldb_key_data *parentkd = talloc_get_type(key, struct ldb_key_data);
@ -432,8 +450,8 @@ static WERROR ldb_del_value (struct hive_key *key, const char *child)
}
static WERROR ldb_set_value(struct hive_key *parent,
const char *name, uint32_t type,
const DATA_BLOB data)
const char *name, uint32_t type,
const DATA_BLOB data)
{
struct ldb_message *msg;
struct ldb_key_data *kd = talloc_get_type(parent, struct ldb_key_data);
@ -460,11 +478,11 @@ static WERROR ldb_set_value(struct hive_key *parent,
}
static WERROR ldb_get_key_info(TALLOC_CTX *mem_ctx,
const struct hive_key *key,
const char **classname,
uint32_t *num_subkeys,
uint32_t *num_values,
NTTIME *last_change_time)
const struct hive_key *key,
const char **classname,
uint32_t *num_subkeys,
uint32_t *num_values,
NTTIME *last_change_time)
{
struct ldb_key_data *kd = talloc_get_type(key, struct ldb_key_data);

View File

@ -70,14 +70,15 @@ struct registry_key *reg_import_hive_key(struct registry_context *ctx,
static WERROR local_open_key(TALLOC_CTX *mem_ctx,
struct registry_key *parent,
const char *path,
struct registry_key **result)
struct registry_key *parent,
const char *path,
struct registry_key **result)
{
char *orig = talloc_strdup(mem_ctx, path),
*curbegin = orig,
*curend = strchr(orig, '\\');
struct local_key *local_parent = talloc_get_type(parent, struct local_key);
struct local_key *local_parent = talloc_get_type(parent,
struct local_key);
struct hive_key *curkey = local_parent->hive_key;
WERROR error;
const char **elements = NULL;
@ -85,10 +86,10 @@ static WERROR local_open_key(TALLOC_CTX *mem_ctx,
if (local_parent->path.elements != NULL) {
elements = talloc_array(mem_ctx, const char *,
str_list_length(local_parent->path.elements) + 1);
str_list_length(local_parent->path.elements) + 1);
for (el = 0; local_parent->path.elements[el] != NULL; el++) {
elements[el] = talloc_reference(elements,
local_parent->path.elements[el]);
local_parent->path.elements[el]);
}
elements[el] = NULL;
} else {
@ -103,9 +104,11 @@ static WERROR local_open_key(TALLOC_CTX *mem_ctx,
elements[el] = talloc_strdup(elements, curbegin);
el++;
elements[el] = NULL;
error = hive_get_key_by_name(mem_ctx, curkey, curbegin, &curkey);
error = hive_get_key_by_name(mem_ctx, curkey,
curbegin, &curkey);
if (!W_ERROR_IS_OK(error)) {
DEBUG(2, ("Opening key %s failed: %s\n", curbegin, win_errstr(error)));
DEBUG(2, ("Opening key %s failed: %s\n", curbegin,
win_errstr(error)));
talloc_free(orig);
return error;
}
@ -117,14 +120,14 @@ static WERROR local_open_key(TALLOC_CTX *mem_ctx,
talloc_free(orig);
*result = reg_import_hive_key(local_parent->global.context, curkey,
local_parent->path.predefined_key,
talloc_steal(curkey, elements));
local_parent->path.predefined_key,
talloc_steal(curkey, elements));
return WERR_OK;
}
WERROR local_get_predefined_key (const struct registry_context *ctx,
uint32_t key_id, struct registry_key **key)
WERROR local_get_predefined_key(const struct registry_context *ctx,
uint32_t key_id, struct registry_key **key)
{
struct registry_local *rctx = talloc_get_type(ctx,
struct registry_local);
@ -147,23 +150,23 @@ WERROR local_get_predefined_key (const struct registry_context *ctx,
}
static WERROR local_enum_key(TALLOC_CTX *mem_ctx,
const struct registry_key *key, uint32_t idx,
const char **name,
const char **keyclass,
NTTIME *last_changed_time)
const struct registry_key *key, uint32_t idx,
const char **name,
const char **keyclass,
NTTIME *last_changed_time)
{
const struct local_key *local = (const struct local_key *)key;
return hive_enum_key(mem_ctx, local->hive_key, idx, name, keyclass,
last_changed_time);
last_changed_time);
}
static WERROR local_create_key (TALLOC_CTX *mem_ctx,
struct registry_key *parent_key,
const char *name,
const char *key_class,
struct security_descriptor *security,
struct registry_key **key)
static WERROR local_create_key(TALLOC_CTX *mem_ctx,
struct registry_key *parent_key,
const char *name,
const char *key_class,
struct security_descriptor *security,
struct registry_key **key)
{
const struct local_key *local_parent;
struct hive_key *hivekey;
@ -177,20 +180,21 @@ static WERROR local_create_key (TALLOC_CTX *mem_ctx,
local_parent = (const struct local_key *)parent_key;
} else {
W_ERROR_NOT_OK_RETURN(reg_open_key(mem_ctx, parent_key,
talloc_strndup(mem_ctx, name, last_part-name),
&local_parent));
talloc_strndup(mem_ctx, name, last_part-name),
&local_parent));
last_part++;
}
W_ERROR_NOT_OK_RETURN(hive_key_add_name(mem_ctx, local_parent->hive_key,
last_part, key_class, security, &hivekey));
last_part, key_class, security,
&hivekey));
if (local_parent->path.elements != NULL) {
elements = talloc_array(hivekey, const char *,
str_list_length(local_parent->path.elements)+2);
str_list_length(local_parent->path.elements)+2);
for (i = 0; local_parent->path.elements[i] != NULL; i++) {
elements[i] = talloc_reference(elements,
local_parent->path.elements[i]);
local_parent->path.elements[i]);
}
} else {
elements = talloc_array(hivekey, const char *, 2);
@ -201,74 +205,74 @@ static WERROR local_create_key (TALLOC_CTX *mem_ctx,
elements[i+1] = NULL;
*key = reg_import_hive_key(local_parent->global.context, hivekey,
local_parent->path.predefined_key,
elements);
local_parent->path.predefined_key,
elements);
return WERR_OK;
}
static WERROR local_set_value (struct registry_key *key, const char *name,
uint32_t type, const DATA_BLOB data)
static WERROR local_set_value(struct registry_key *key, const char *name,
uint32_t type, const DATA_BLOB data)
{
struct local_key *local = (struct local_key *)key;
return hive_set_value(local->hive_key, name, type, data);
}
static WERROR local_get_value (TALLOC_CTX *mem_ctx,
const struct registry_key *key,
const char *name, uint32_t *type, DATA_BLOB *data)
static WERROR local_get_value(TALLOC_CTX *mem_ctx,
const struct registry_key *key,
const char *name, uint32_t *type, DATA_BLOB *data)
{
const struct local_key *local = (const struct local_key *)key;
return hive_get_value(mem_ctx, local->hive_key, name, type, data);
}
static WERROR local_enum_value (TALLOC_CTX *mem_ctx,
const struct registry_key *key, uint32_t idx,
const char **name,
uint32_t *type,
DATA_BLOB *data)
static WERROR local_enum_value(TALLOC_CTX *mem_ctx,
const struct registry_key *key, uint32_t idx,
const char **name,
uint32_t *type,
DATA_BLOB *data)
{
const struct local_key *local = (const struct local_key *)key;
return hive_get_value_by_index(mem_ctx, local->hive_key, idx,
name, type, data);
name, type, data);
}
static WERROR local_delete_key (struct registry_key *key, const char *name)
static WERROR local_delete_key(struct registry_key *key, const char *name)
{
const struct local_key *local = (const struct local_key *)key;
return hive_key_del(local->hive_key, name);
}
static WERROR local_delete_value (struct registry_key *key, const char *name)
static WERROR local_delete_value(struct registry_key *key, const char *name)
{
const struct local_key *local = (const struct local_key *)key;
return hive_del_value(local->hive_key, name);
}
static WERROR local_flush_key (struct registry_key *key)
static WERROR local_flush_key(struct registry_key *key)
{
const struct local_key *local = (const struct local_key *)key;
return hive_key_flush(local->hive_key);
}
static WERROR local_get_key_info (TALLOC_CTX *mem_ctx,
const struct registry_key *key,
const char **classname,
uint32_t *num_subkeys,
uint32_t *num_values,
NTTIME *last_change_time)
static WERROR local_get_key_info(TALLOC_CTX *mem_ctx,
const struct registry_key *key,
const char **classname,
uint32_t *num_subkeys,
uint32_t *num_values,
NTTIME *last_change_time)
{
const struct local_key *local = (const struct local_key *)key;
return hive_key_get_info(mem_ctx, local->hive_key,
classname, num_subkeys, num_values,
last_change_time);
classname, num_subkeys, num_values,
last_change_time);
}
const static struct registry_operations local_ops = {
@ -287,10 +291,11 @@ const static struct registry_operations local_ops = {
};
WERROR reg_open_local(TALLOC_CTX *mem_ctx, struct registry_context **ctx,
struct auth_session_info *session_info,
struct cli_credentials *credentials)
struct auth_session_info *session_info,
struct cli_credentials *credentials)
{
struct registry_local *ret = talloc_zero(mem_ctx, struct registry_local);
struct registry_local *ret = talloc_zero(mem_ctx,
struct registry_local);
W_ERROR_HAVE_NO_MEMORY(ret);
@ -304,11 +309,12 @@ WERROR reg_open_local(TALLOC_CTX *mem_ctx, struct registry_context **ctx,
}
WERROR reg_mount_hive(struct registry_context *rctx,
struct hive_key *hive_key,
uint32_t key_id,
const char **elements)
struct hive_key *hive_key,
uint32_t key_id,
const char **elements)
{
struct registry_local *reg_local = talloc_get_type(rctx, struct registry_local);
struct registry_local *reg_local = talloc_get_type(rctx,
struct registry_local);
struct mountpoint *mp = talloc(rctx, struct mountpoint);
int i = 0;
@ -317,10 +323,10 @@ WERROR reg_mount_hive(struct registry_context *rctx,
mp->key = hive_key;
if (elements != NULL) {
mp->path.elements = talloc_array(mp, const char *,
str_list_length(elements));
str_list_length(elements));
for (i = 0; elements[i] != NULL; i++) {
mp->path.elements[i] = talloc_reference(mp->path.elements,
elements[i]);
elements[i]);
}
mp->path.elements[i] = NULL;
} else {

View File

@ -25,18 +25,22 @@
#include "system/filesys.h"
_PUBLIC_ WERROR reg_preg_diff_load(int fd, const struct reg_diff_callbacks *callbacks, void *callback_data);
_PUBLIC_ WERROR reg_preg_diff_load(int fd,
const struct reg_diff_callbacks *callbacks,
void *callback_data);
_PUBLIC_ WERROR reg_dotreg_diff_load(int fd, const struct reg_diff_callbacks *callbacks, void *callback_data);
_PUBLIC_ WERROR reg_dotreg_diff_load(int fd,
const struct reg_diff_callbacks *callbacks,
void *callback_data);
/*
* Generate difference between two keys
*/
WERROR reg_generate_diff_key(struct registry_key *oldkey,
struct registry_key *newkey,
const char *path,
const struct reg_diff_callbacks *callbacks,
void *callback_data)
struct registry_key *newkey,
const char *path,
const struct reg_diff_callbacks *callbacks,
void *callback_data)
{
int i;
struct registry_key *t1, *t2;
@ -48,11 +52,12 @@ WERROR reg_generate_diff_key(struct registry_key *oldkey,
new_num_subkeys, new_num_values;
if (oldkey != NULL) {
error = reg_key_get_info(mem_ctx, oldkey, NULL, &old_num_subkeys, &old_num_values,
NULL);
error = reg_key_get_info(mem_ctx, oldkey, NULL,
&old_num_subkeys, &old_num_values,
NULL);
if (!W_ERROR_IS_OK(error)) {
DEBUG(0, ("Error occured while getting key info: %s\n",
win_errstr(error)));
win_errstr(error)));
return error;
}
} else {
@ -62,11 +67,12 @@ WERROR reg_generate_diff_key(struct registry_key *oldkey,
/* Subkeys that were deleted */
for (i = 0; i < old_num_subkeys; i++) {
error1 = reg_key_get_subkey_by_index(mem_ctx, oldkey, i, &keyname1,
NULL, NULL);
error1 = reg_key_get_subkey_by_index(mem_ctx, oldkey, i,
&keyname1,
NULL, NULL);
if (!W_ERROR_IS_OK(error1)) {
DEBUG(0, ("Error occured while getting subkey by index: %s\n",
win_errstr(error2)));
win_errstr(error2)));
continue;
}
@ -82,7 +88,7 @@ WERROR reg_generate_diff_key(struct registry_key *oldkey,
if (!W_ERROR_EQUAL(error2, WERR_DEST_NOT_FOUND)) {
DEBUG(0, ("Error occured while getting subkey by name: %s\n",
win_errstr(error2)));
win_errstr(error2)));
talloc_free(mem_ctx);
return error2;
}
@ -94,11 +100,12 @@ WERROR reg_generate_diff_key(struct registry_key *oldkey,
}
if (newkey != NULL) {
error = reg_key_get_info(mem_ctx, newkey, NULL, &new_num_subkeys, &new_num_values,
NULL);
error = reg_key_get_info(mem_ctx, newkey, NULL,
&new_num_subkeys, &new_num_values,
NULL);
if (!W_ERROR_IS_OK(error)) {
DEBUG(0, ("Error occured while getting key info: %s\n",
win_errstr(error)));
win_errstr(error)));
return error;
}
} else {
@ -108,11 +115,12 @@ WERROR reg_generate_diff_key(struct registry_key *oldkey,
/* Subkeys that were added */
for(i = 0; i < new_num_subkeys; i++) {
error1 = reg_key_get_subkey_by_index(mem_ctx, newkey, i, &keyname1,
NULL, NULL);
error1 = reg_key_get_subkey_by_index(mem_ctx, newkey,
i, &keyname1,
NULL, NULL);
if (!W_ERROR_IS_OK(error1)) {
DEBUG(0, ("Error occured while getting subkey by index: %s\n",
win_errstr(error1)));
win_errstr(error1)));
talloc_free(mem_ctx);
return error1;
}
@ -129,7 +137,7 @@ WERROR reg_generate_diff_key(struct registry_key *oldkey,
if (!W_ERROR_EQUAL(error2, WERR_DEST_NOT_FOUND)) {
DEBUG(0, ("Error occured while getting subkey by name: %s\n",
win_errstr(error2)));
win_errstr(error2)));
talloc_free(mem_ctx);
return error2;
}
@ -141,7 +149,8 @@ WERROR reg_generate_diff_key(struct registry_key *oldkey,
W_ERROR_NOT_OK_RETURN(
reg_open_key(mem_ctx, newkey, keyname1, &t2));
reg_generate_diff_key(t1, t2, tmppath, callbacks, callback_data);
reg_generate_diff_key(t1, t2, tmppath,
callbacks, callback_data);
talloc_free(tmppath);
}
@ -152,55 +161,58 @@ WERROR reg_generate_diff_key(struct registry_key *oldkey,
DATA_BLOB contents1, contents2;
error1 = reg_key_get_value_by_index(mem_ctx, newkey, i,
&name, &type1, &contents1);
&name, &type1, &contents1);
if (!W_ERROR_IS_OK(error1)) {
DEBUG(0, ("Unable to get key by index: %s\n",
win_errstr(error1)));
win_errstr(error1)));
talloc_free(mem_ctx);
return error1;
}
if (oldkey != NULL) {
error2 = reg_key_get_value_by_name(mem_ctx, oldkey, name,
&type2, &contents2);
error2 = reg_key_get_value_by_name(mem_ctx, oldkey,
name, &type2,
&contents2);
} else
error2 = WERR_DEST_NOT_FOUND;
if(!W_ERROR_IS_OK(error2) &&
!W_ERROR_EQUAL(error2, WERR_DEST_NOT_FOUND)) {
DEBUG(0, ("Error occured while getting value by name: %s\n",
win_errstr(error2)));
win_errstr(error2)));
talloc_free(mem_ctx);
return error2;
}
if (W_ERROR_IS_OK(error2) && data_blob_cmp(&contents1, &contents2) == 0)
if (W_ERROR_IS_OK(error2) &&
data_blob_cmp(&contents1, &contents2) == 0)
continue;
callbacks->set_value(callback_data, path, name, type1, contents1);
callbacks->set_value(callback_data, path, name,
type1, contents1);
}
/* Values that were deleted */
for (i = 0; i < old_num_values; i++) {
const char *name;
error1 = reg_key_get_value_by_index(mem_ctx, oldkey, i, &name,
NULL, NULL);
NULL, NULL);
if (!W_ERROR_IS_OK(error1)) {
DEBUG(0, ("Error ocurred getting value by index: %s\n",
win_errstr(error1)));
win_errstr(error1)));
talloc_free(mem_ctx);
return error1;
}
error2 = reg_key_get_value_by_name(mem_ctx, newkey, name, NULL,
NULL);
NULL);
if (W_ERROR_IS_OK(error2))
continue;
if (!W_ERROR_EQUAL(error2, WERR_DEST_NOT_FOUND)) {
DEBUG(0, ("Error occured while getting value by name: %s\n",
win_errstr(error2)));
win_errstr(error2)));
return error2;
}
@ -225,21 +237,27 @@ _PUBLIC_ WERROR reg_generate_diff(struct registry_context *ctx1,
for(i = HKEY_FIRST; i <= HKEY_LAST; i++) {
struct registry_key *r1 = NULL, *r2 = NULL;
error = reg_get_predefined_key(ctx1, i, &r1);
if (!W_ERROR_IS_OK(error) && !W_ERROR_EQUAL(error, WERR_NOT_FOUND)) {
DEBUG(0, ("Unable to open hive %s for backend 1\n", reg_get_predef_name(i)));
if (!W_ERROR_IS_OK(error) &&
!W_ERROR_EQUAL(error, WERR_NOT_FOUND)) {
DEBUG(0, ("Unable to open hive %s for backend 1\n",
reg_get_predef_name(i)));
}
error = reg_get_predefined_key(ctx2, i, &r2);
if (!W_ERROR_IS_OK(error) && !W_ERROR_EQUAL(error, WERR_NOT_FOUND)) {
DEBUG(0, ("Unable to open hive %s for backend 2\n", reg_get_predef_name(i)));
if (!W_ERROR_IS_OK(error) &&
!W_ERROR_EQUAL(error, WERR_NOT_FOUND)) {
DEBUG(0, ("Unable to open hive %s for backend 2\n",
reg_get_predef_name(i)));
}
if (r1 == NULL && r2 == NULL)
continue;
error = reg_generate_diff_key(r1, r2, reg_get_predef_name(i), callbacks, callback_data);
error = reg_generate_diff_key(r1, r2, reg_get_predef_name(i),
callbacks, callback_data);
if (!W_ERROR_IS_OK(error)) {
DEBUG(0, ("Unable to determine diff: %s\n", win_errstr(error)));
DEBUG(0, ("Unable to determine diff: %s\n",
win_errstr(error)));
return error;
}
}
@ -261,12 +279,14 @@ _PUBLIC_ WERROR reg_diff_load(const char *filename,
fd = open(filename, O_RDONLY, 0);
if (fd == -1) {
DEBUG(0, ("Error opening registry patch file `%s'\n", filename));
DEBUG(0, ("Error opening registry patch file `%s'\n",
filename));
return WERR_GENERAL_FAILURE;
}
if (read(fd, &hdr, 4) != 4) {
DEBUG(0, ("Error reading registry patch file `%s'\n", filename));
DEBUG(0, ("Error reading registry patch file `%s'\n",
filename));
return WERR_GENERAL_FAILURE;
}
@ -301,8 +321,10 @@ static WERROR reg_diff_apply_add_key(void *_ctx, const char *key_name)
error = reg_key_add_abs(ctx, ctx, key_name, 0, NULL, &tmp);
if (!W_ERROR_EQUAL(error, WERR_ALREADY_EXISTS) && !W_ERROR_IS_OK(error)) {
DEBUG(0, ("Error adding new key '%s': %s\n", key_name, win_errstr(error)));
if (!W_ERROR_EQUAL(error, WERR_ALREADY_EXISTS) &&
!W_ERROR_IS_OK(error)) {
DEBUG(0, ("Error adding new key '%s': %s\n",
key_name, win_errstr(error)));
return error;
}
return WERR_OK;
@ -323,7 +345,9 @@ static WERROR reg_diff_apply_del_key(void *_ctx, const char *key_name)
return WERR_OK;
}
static WERROR reg_diff_apply_set_value(void *_ctx, const char *path, const char *value_name, uint32_t value_type, DATA_BLOB value)
static WERROR reg_diff_apply_set_value(void *_ctx, const char *path,
const char *value_name,
uint32_t value_type, DATA_BLOB value)
{
struct registry_context *ctx = (struct registry_context *)_ctx;
struct registry_key *tmp;
@ -348,7 +372,8 @@ static WERROR reg_diff_apply_set_value(void *_ctx, const char *path, const char
return WERR_OK;
}
static WERROR reg_diff_apply_del_value (void *_ctx, const char *key_name, const char *value_name)
static WERROR reg_diff_apply_del_value(void *_ctx, const char *key_name,
const char *value_name)
{
struct registry_context *ctx = (struct registry_context *)_ctx;
struct registry_key *tmp;
@ -388,15 +413,16 @@ static WERROR reg_diff_apply_del_all_values(void *_ctx, const char *key_name)
}
W_ERROR_NOT_OK_RETURN(reg_key_get_info(ctx, key,
NULL,
NULL,
&num_values,
NULL));
NULL,
NULL,
&num_values,
NULL));
for (i = 0; i < num_values; i++) {
const char *name;
W_ERROR_NOT_OK_RETURN(reg_key_get_value_by_index(ctx, key, i, &name,
NULL, NULL));
W_ERROR_NOT_OK_RETURN(reg_key_get_value_by_index(ctx, key, i,
&name,
NULL, NULL));
W_ERROR_NOT_OK_RETURN(reg_del_value(key, name));
}
@ -406,7 +432,8 @@ static WERROR reg_diff_apply_del_all_values(void *_ctx, const char *key_name)
/**
* Apply diff to a registry context
*/
_PUBLIC_ WERROR reg_diff_apply (const char *filename, struct registry_context *ctx)
_PUBLIC_ WERROR reg_diff_apply(const char *filename,
struct registry_context *ctx)
{
struct reg_diff_callbacks callbacks;

View File

@ -27,26 +27,29 @@
struct reg_diff_callbacks {
WERROR (*add_key) (void *callback_data, const char *key_name);
WERROR (*set_value) (void *callback_data, const char *key_name,
const char *value_name, uint32_t value_type, DATA_BLOB value);
WERROR (*del_value) (void *callback_data, const char *key_name, const char *value_name);
const char *value_name, uint32_t value_type,
DATA_BLOB value);
WERROR (*del_value) (void *callback_data, const char *key_name,
const char *value_name);
WERROR (*del_key) (void *callback_data, const char *key_name);
WERROR (*del_all_values) (void *callback_data, const char *key_name);
WERROR (*done) (void *callback_data);
};
WERROR reg_diff_apply (const char *filename,
struct registry_context *ctx);
struct registry_context *ctx);
WERROR reg_generate_diff(struct registry_context *ctx1,
struct registry_context *ctx2,
const struct reg_diff_callbacks *callbacks,
void *callback_data);
struct registry_context *ctx2,
const struct reg_diff_callbacks *callbacks,
void *callback_data);
WERROR reg_dotreg_diff_save(TALLOC_CTX *ctx, const char *filename,
struct reg_diff_callbacks **callbacks, void **callback_data);
struct reg_diff_callbacks **callbacks,
void **callback_data);
WERROR reg_generate_diff_key(struct registry_key *oldkey,
struct registry_key *newkey,
const char *path,
const struct reg_diff_callbacks *callbacks,
void *callback_data);
struct registry_key *newkey,
const char *path,
const struct reg_diff_callbacks *callbacks,
void *callback_data);
#endif /* _PATCHFILE_H */

View File

@ -57,7 +57,8 @@ static WERROR reg_dotreg_diff_del_key(void *_data, const char *key_name)
}
static WERROR reg_dotreg_diff_set_value(void *_data, const char *path,
const char *value_name, uint32_t value_type, DATA_BLOB value)
const char *value_name,
uint32_t value_type, DATA_BLOB value)
{
struct dotreg_data *data = (struct dotreg_data *)_data;
@ -68,7 +69,8 @@ static WERROR reg_dotreg_diff_set_value(void *_data, const char *path,
return WERR_OK;
}
static WERROR reg_dotreg_diff_del_value(void *_data, const char *path, const char *value_name)
static WERROR reg_dotreg_diff_del_value(void *_data, const char *path,
const char *value_name)
{
struct dotreg_data *data = (struct dotreg_data *)_data;
@ -87,7 +89,8 @@ static WERROR reg_dotreg_diff_done(void *_data)
return WERR_OK;
}
static WERROR reg_dotreg_diff_del_all_values (void *callback_data, const char *key_name)
static WERROR reg_dotreg_diff_del_all_values(void *callback_data,
const char *key_name)
{
return WERR_NOT_SUPPORTED;
}
@ -96,7 +99,8 @@ static WERROR reg_dotreg_diff_del_all_values (void *callback_data, const char *k
* Save registry diff
*/
_PUBLIC_ WERROR reg_dotreg_diff_save(TALLOC_CTX *ctx, const char *filename,
struct reg_diff_callbacks **callbacks, void **callback_data)
struct reg_diff_callbacks **callbacks,
void **callback_data)
{
struct dotreg_data *data;
@ -131,7 +135,8 @@ _PUBLIC_ WERROR reg_dotreg_diff_save(TALLOC_CTX *ctx, const char *filename,
* Load diff file
*/
_PUBLIC_ WERROR reg_dotreg_diff_load(int fd,
const struct reg_diff_callbacks *callbacks, void *callback_data)
const struct reg_diff_callbacks *callbacks,
void *callback_data)
{
char *line, *p, *q;
char *curkey = NULL;
@ -171,9 +176,11 @@ _PUBLIC_ WERROR reg_dotreg_diff_load(int fd,
if (line[1] == '-') {
curkey = talloc_strndup(line, line+2, strlen(line)-3);
error = callbacks->del_key(callback_data, curkey);
error = callbacks->del_key(callback_data,
curkey);
if (!W_ERROR_IS_OK(error)) {
DEBUG(0,("Error deleting key %s\n", curkey));
DEBUG(0,("Error deleting key %s\n",
curkey));
talloc_free(mem_ctx);
return error;
}
@ -213,9 +220,11 @@ _PUBLIC_ WERROR reg_dotreg_diff_load(int fd,
/* Delete value */
if (strcmp(p, "-") == 0) {
error = callbacks->del_value(callback_data, curkey, line);
error = callbacks->del_value(callback_data,
curkey, line);
if (!W_ERROR_IS_OK(error)) {
DEBUG(0, ("Error deleting value %s in key %s\n", line, curkey));
DEBUG(0, ("Error deleting value %s in key %s\n",
line, curkey));
talloc_free(mem_ctx);
return error;
}
@ -230,11 +239,14 @@ _PUBLIC_ WERROR reg_dotreg_diff_load(int fd,
q++;
}
reg_string_to_val(line, q?p:"REG_SZ", q?q:p, &value_type, &value);
reg_string_to_val(line, q?p:"REG_SZ", q?q:p,
&value_type, &value);
error = callbacks->set_value(callback_data, curkey, line, value_type, value);
error = callbacks->set_value(callback_data, curkey, line,
value_type, value);
if (!W_ERROR_IS_OK(error)) {
DEBUG(0, ("Error setting value for %s in %s\n", line, curkey));
DEBUG(0, ("Error setting value for %s in %s\n",
line, curkey));
talloc_free(mem_ctx);
return error;
}

View File

@ -53,13 +53,16 @@ static WERROR reg_preg_diff_del_key(void *_data, const char *key_name)
return WERR_OK;
}
static WERROR reg_preg_diff_set_value(void *_data, const char *key_name, const char *value_name, uint32_t value_type, DATA_BLOB value_data)
static WERROR reg_preg_diff_set_value(void *_data, const char *key_name,
const char *value_name,
uint32_t value_type, DATA_BLOB value_data)
{
struct preg_data *data = (struct preg_data *)_data;
return WERR_OK;
}
static WERROR reg_preg_diff_del_value(void *_data, const char *key_name, const char *value_name)
static WERROR reg_preg_diff_del_value(void *_data, const char *key_name,
const char *value_name)
{
struct preg_data *data = (struct preg_data *)_data;
return WERR_OK;
@ -83,7 +86,9 @@ static WERROR reg_preg_diff_done(void *_data)
/**
* Save registry diff
*/
_PUBLIC_ WERROR reg_preg_diff_save(TALLOC_CTX *ctx, const char *filename, struct reg_diff_callbacks **callbacks, void **callback_data)
_PUBLIC_ WERROR reg_preg_diff_save(TALLOC_CTX *ctx, const char *filename,
struct reg_diff_callbacks **callbacks,
void **callback_data)
{
struct preg_data *data;
struct {
@ -122,7 +127,9 @@ _PUBLIC_ WERROR reg_preg_diff_save(TALLOC_CTX *ctx, const char *filename, struct
/**
* Load diff file
*/
_PUBLIC_ WERROR reg_preg_diff_load(int fd, const struct reg_diff_callbacks *callbacks, void *callback_data)
_PUBLIC_ WERROR reg_preg_diff_load(int fd,
const struct reg_diff_callbacks *callbacks,
void *callback_data)
{
struct {
char hdr[4];
@ -166,14 +173,16 @@ _PUBLIC_ WERROR reg_preg_diff_load(int fd, const struct reg_diff_callbacks *call
/* Get the path */
buf_ptr = buf;
while (W_ERROR_IS_OK(preg_read_utf16(fd, buf_ptr)) && *buf_ptr != ';' && buf_ptr-buf < sizeof(buf)) {
while (W_ERROR_IS_OK(preg_read_utf16(fd, buf_ptr)) &&
*buf_ptr != ';' && buf_ptr-buf < sizeof(buf)) {
buf_ptr++;
}
key = talloc_asprintf(mem_ctx, "\\%s", buf);
/* Get the name */
buf_ptr = buf;
while (W_ERROR_IS_OK(preg_read_utf16(fd, buf_ptr)) && *buf_ptr != ';' && buf_ptr-buf < sizeof(buf)) {
while (W_ERROR_IS_OK(preg_read_utf16(fd, buf_ptr)) &&
*buf_ptr != ';' && buf_ptr-buf < sizeof(buf)) {
buf_ptr++;
}
value_name = talloc_strdup(mem_ctx, buf);
@ -186,7 +195,8 @@ _PUBLIC_ WERROR reg_preg_diff_load(int fd, const struct reg_diff_callbacks *call
}
/* Read past delimiter */
buf_ptr = buf;
if (!(W_ERROR_IS_OK(preg_read_utf16(fd, buf_ptr)) && *buf_ptr == ';') && buf_ptr-buf < sizeof(buf)) {
if (!(W_ERROR_IS_OK(preg_read_utf16(fd, buf_ptr)) &&
*buf_ptr == ';') && buf_ptr-buf < sizeof(buf)) {
DEBUG(0, ("Error in PReg file.\n"));
close(fd);
return WERR_GENERAL_FAILURE;
@ -199,14 +209,16 @@ _PUBLIC_ WERROR reg_preg_diff_load(int fd, const struct reg_diff_callbacks *call
}
/* Read past delimiter */
buf_ptr = buf;
if (!(W_ERROR_IS_OK(preg_read_utf16(fd, buf_ptr)) && *buf_ptr == ';') && buf_ptr-buf < sizeof(buf)) {
if (!(W_ERROR_IS_OK(preg_read_utf16(fd, buf_ptr)) &&
*buf_ptr == ';') && buf_ptr-buf < sizeof(buf)) {
DEBUG(0, ("Error in PReg file.\n"));
close(fd);
return WERR_GENERAL_FAILURE;
}
/* Get the data */
buf_ptr = buf;
if (length < sizeof(buf) && read(fd, buf_ptr, length) != length) {
if (length < sizeof(buf) &&
read(fd, buf_ptr, length) != length) {
DEBUG(0, ("Error while reading PReg\n"));
close(fd);
return WERR_GENERAL_FAILURE;
@ -215,8 +227,10 @@ _PUBLIC_ WERROR reg_preg_diff_load(int fd, const struct reg_diff_callbacks *call
/* Check if delimiter is in place (whine if it isn't) */
buf_ptr = buf;
if (!(W_ERROR_IS_OK(preg_read_utf16(fd, buf_ptr)) && *buf_ptr == ']') && buf_ptr-buf < sizeof(buf)) {
DEBUG(0, ("Warning: Missing ']' in PReg file, expected ']', got '%c' 0x%x.\n",*buf_ptr, *buf_ptr));
if (!(W_ERROR_IS_OK(preg_read_utf16(fd, buf_ptr)) &&
*buf_ptr == ']') && buf_ptr-buf < sizeof(buf)) {
DEBUG(0, ("Warning: Missing ']' in PReg file, expected ']', got '%c' 0x%x.\n",
*buf_ptr, *buf_ptr));
}
if (strcasecmp(value_name, "**DelVals") == 0) {
@ -248,7 +262,8 @@ _PUBLIC_ WERROR reg_preg_diff_load(int fd, const struct reg_diff_callbacks *call
*q = '\0';
q++;
full_key = talloc_asprintf(mem_ctx, "%s\\%s", key, p);
full_key = talloc_asprintf(mem_ctx, "%s\\%s",
key, p);
callbacks->del_key(callback_data, full_key);
talloc_free(full_key);
@ -259,7 +274,8 @@ _PUBLIC_ WERROR reg_preg_diff_load(int fd, const struct reg_diff_callbacks *call
talloc_free(full_key);
} else {
callbacks->add_key(callback_data, key);
callbacks->set_value(callback_data, key, value_name, value_type, data);
callbacks->set_value(callback_data, key, value_name,
value_type, data);
}
talloc_free(key);
talloc_free(value_name);

View File

@ -59,7 +59,7 @@ struct regf_key_data {
};
static struct hbin_block *hbin_by_offset(const struct regf_data *data,
uint32_t offset, uint32_t *rel_offset)
uint32_t offset, uint32_t *rel_offset)
{
int i;
@ -128,8 +128,8 @@ static DATA_BLOB hbin_get(const struct regf_data *data, uint32_t offset)
return ret;
}
static bool hbin_get_tdr (struct regf_data *regf, uint32_t offset,
TALLOC_CTX *ctx, tdr_pull_fn_t pull_fn, void *p)
static bool hbin_get_tdr(struct regf_data *regf, uint32_t offset,
TALLOC_CTX *ctx, tdr_pull_fn_t pull_fn, void *p)
{
struct tdr_pull pull;
@ -142,7 +142,8 @@ static bool hbin_get_tdr (struct regf_data *regf, uint32_t offset,
}
if (NT_STATUS_IS_ERR(pull_fn(&pull, ctx, p))) {
DEBUG(1, ("Error parsing record at 0x%04x using tdr\n", offset));
DEBUG(1, ("Error parsing record at 0x%04x using tdr\n",
offset));
return false;
}
@ -151,7 +152,7 @@ static bool hbin_get_tdr (struct regf_data *regf, uint32_t offset,
/* Allocate some new data */
static DATA_BLOB hbin_alloc(struct regf_data *data, uint32_t size,
uint32_t *offset)
uint32_t *offset)
{
DATA_BLOB ret;
uint32_t rel_offset = -1; /* Relative offset ! */
@ -190,13 +191,15 @@ static DATA_BLOB hbin_alloc(struct regf_data *data, uint32_t size,
my_size = -my_size;
} else if (my_size == size) { /* exact match */
rel_offset = j;
DEBUG(4, ("Found free block of exact size %d in middle of HBIN\n", size));
DEBUG(4, ("Found free block of exact size %d in middle of HBIN\n",
size));
break;
} else if (my_size > size) { /* data will remain */
rel_offset = j;
/* Split this block and mark the next block as free */
SIVAL(hbin->data, rel_offset+size, my_size-size);
DEBUG(4, ("Found free block of size %d (needing %d) in middle of HBIN\n", my_size, size));
DEBUG(4, ("Found free block of size %d (needing %d) in middle of HBIN\n",
my_size, size));
break;
}
}
@ -208,8 +211,10 @@ static DATA_BLOB hbin_alloc(struct regf_data *data, uint32_t size,
/* No space available in previous hbins,
* allocate new one */
if (data->hbins[i] == NULL) {
DEBUG(4, ("No space available in other HBINs for block of size %d, allocating new HBIN\n", size));
data->hbins = talloc_realloc(data, data->hbins, struct hbin_block *, i+2);
DEBUG(4, ("No space available in other HBINs for block of size %d, allocating new HBIN\n",
size));
data->hbins = talloc_realloc(data, data->hbins,
struct hbin_block *, i+2);
hbin = talloc(data->hbins, struct hbin_block);
SMB_ASSERT(hbin != NULL);
@ -255,7 +260,8 @@ static uint32_t hbin_store (struct regf_data *data, DATA_BLOB blob)
return ret;
}
static uint32_t hbin_store_tdr (struct regf_data *data, tdr_push_fn_t push_fn, void *p)
static uint32_t hbin_store_tdr(struct regf_data *data,
tdr_push_fn_t push_fn, void *p)
{
struct tdr_push *push = talloc_zero(data, struct tdr_push);
uint32_t ret;
@ -292,7 +298,8 @@ static void hbin_free (struct regf_data *data, uint32_t offset)
size = IVALS(hbin->data, rel_offset);
if (size > 0) {
DEBUG(1, ("Trying to free already freed block at 0x%04x\n", offset));
DEBUG(1, ("Trying to free already freed block at 0x%04x\n",
offset));
return;
}
/* Mark as unused */
@ -315,10 +322,11 @@ static void hbin_free (struct regf_data *data, uint32_t offset)
* Will try to save it at the current location if possible, otherwise
* does a free + store */
static uint32_t hbin_store_resize(struct regf_data *data,
uint32_t orig_offset, DATA_BLOB blob)
uint32_t orig_offset, DATA_BLOB blob)
{
uint32_t rel_offset;
struct hbin_block *hbin = hbin_by_offset(data, orig_offset, &rel_offset);
struct hbin_block *hbin = hbin_by_offset(data, orig_offset,
&rel_offset);
int32_t my_size;
int32_t orig_size;
int32_t needed_size;
@ -343,7 +351,8 @@ static uint32_t hbin_store_resize(struct regf_data *data,
* and free/merge it */
if (orig_size - needed_size > 0x4) {
SIVALS(hbin->data, rel_offset, -needed_size);
SIVALS(hbin->data, rel_offset + needed_size, needed_size-orig_size);
SIVALS(hbin->data, rel_offset + needed_size,
needed_size-orig_size);
hbin_free(data, orig_offset + needed_size);
}
return orig_offset;
@ -367,7 +376,8 @@ static uint32_t hbin_store_resize(struct regf_data *data,
if (possible_size >= blob.length) {
SIVAL(hbin->data, rel_offset, -possible_size);
memcpy(hbin->data + rel_offset + 0x4, blob.data, blob.length);
memcpy(hbin->data + rel_offset + 0x4,
blob.data, blob.length);
return orig_offset;
}
}
@ -376,8 +386,9 @@ static uint32_t hbin_store_resize(struct regf_data *data,
return hbin_store(data, blob);
}
static uint32_t hbin_store_tdr_resize (struct regf_data *regf, tdr_push_fn_t push_fn,
uint32_t orig_offset, void *p)
static uint32_t hbin_store_tdr_resize(struct regf_data *regf,
tdr_push_fn_t push_fn,
uint32_t orig_offset, void *p)
{
struct tdr_push *push = talloc_zero(regf, struct tdr_push);
uint32_t ret;
@ -409,12 +420,12 @@ static uint32_t regf_create_lh_hash(const char *name)
return ret;
}
static WERROR regf_get_info (TALLOC_CTX *mem_ctx,
const struct hive_key *key,
const char **classname,
uint32_t *num_subkeys,
uint32_t *num_values,
NTTIME *last_mod_time)
static WERROR regf_get_info(TALLOC_CTX *mem_ctx,
const struct hive_key *key,
const char **classname,
uint32_t *num_subkeys,
uint32_t *num_values,
NTTIME *last_mod_time)
{
const struct regf_key_data *private_data =
(const struct regf_key_data *)key;
@ -428,9 +439,10 @@ static WERROR regf_get_info (TALLOC_CTX *mem_ctx,
if (classname != NULL) {
if (private_data->nk->clsname_offset != -1) {
DATA_BLOB data = hbin_get(private_data->hive,
private_data->nk->clsname_offset);
private_data->nk->clsname_offset);
*classname = talloc_strndup(mem_ctx,
(char*)data.data, private_data->nk->clsname_length);
(char*)data.data,
private_data->nk->clsname_length);
} else
*classname = NULL;
}
@ -441,8 +453,8 @@ static WERROR regf_get_info (TALLOC_CTX *mem_ctx,
}
static struct regf_key_data *regf_get_key(TALLOC_CTX *ctx,
struct regf_data *regf,
uint32_t offset)
struct regf_data *regf,
uint32_t offset)
{
struct nk_block *nk;
struct regf_key_data *ret;
@ -457,7 +469,8 @@ static struct regf_key_data *regf_get_key(TALLOC_CTX *ctx,
ret->nk = nk;
if (!hbin_get_tdr(regf, offset, nk, (tdr_pull_fn_t)tdr_pull_nk_block, nk)) {
if (!hbin_get_tdr(regf, offset, nk,
(tdr_pull_fn_t)tdr_pull_nk_block, nk)) {
DEBUG(0, ("Unable to find HBIN data for offset %d\n", offset));
return NULL;
}
@ -473,8 +486,8 @@ static struct regf_key_data *regf_get_key(TALLOC_CTX *ctx,
static WERROR regf_get_value(TALLOC_CTX *ctx, const struct hive_key *key,
int idx, const char **name,
uint32_t *data_type, DATA_BLOB *data)
int idx, const char **name,
uint32_t *data_type, DATA_BLOB *data)
{
const struct regf_key_data *private_data =
(const struct regf_key_data *)key;
@ -501,7 +514,8 @@ static WERROR regf_get_value(TALLOC_CTX *ctx, const struct hive_key *key,
vk = talloc(NULL, struct vk_block);
W_ERROR_HAVE_NO_MEMORY(vk);
if (!hbin_get_tdr(regf, vk_offset, vk, (tdr_pull_fn_t)tdr_pull_vk_block, vk)) {
if (!hbin_get_tdr(regf, vk_offset, vk,
(tdr_pull_fn_t)tdr_pull_vk_block, vk)) {
DEBUG(0, ("Unable to get VK block at %d\n", vk_offset));
talloc_free(vk);
return WERR_GENERAL_FAILURE;
@ -531,9 +545,9 @@ static WERROR regf_get_value(TALLOC_CTX *ctx, const struct hive_key *key,
return WERR_OK;
}
static WERROR regf_get_value_by_name (TALLOC_CTX *mem_ctx,
struct hive_key *key, const char *name,
uint32_t *type, DATA_BLOB *data)
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;
const char *vname;
@ -542,10 +556,11 @@ static WERROR regf_get_value_by_name (TALLOC_CTX *mem_ctx,
/* FIXME: Do binary search? Is this list sorted at all? */
for (i = 0; W_ERROR_IS_OK(error = regf_get_value(mem_ctx, key, i,
&vname, type, data)); i++) {
&vname, type, data));
i++) {
if (!strcmp(vname, name))
return WERR_OK;
}
}
if (W_ERROR_EQUAL(error, WERR_NO_MORE_ITEMS))
return WERR_NOT_FOUND;
@ -554,11 +569,11 @@ static WERROR regf_get_value_by_name (TALLOC_CTX *mem_ctx,
}
static WERROR regf_get_subkey_by_index (TALLOC_CTX *ctx,
const struct hive_key *key,
uint32_t idx, const char **name,
const char **classname,
NTTIME *last_mod_time)
static WERROR regf_get_subkey_by_index(TALLOC_CTX *ctx,
const struct hive_key *key,
uint32_t idx, const char **name,
const char **classname,
NTTIME *last_mod_time)
{
DATA_BLOB data;
struct regf_key_data *ret;
@ -668,7 +683,9 @@ static WERROR regf_get_subkey_by_index (TALLOC_CTX *ctx,
DEBUG(10, ("Subkeys in RI->LI list\n"));
if (NT_STATUS_IS_ERR(tdr_pull_li_block(&pull, nk, &li))) {
if (NT_STATUS_IS_ERR(tdr_pull_li_block(&pull,
nk,
&li))) {
DEBUG(0, ("Error parsing LI list from RI\n"));
return WERR_GENERAL_FAILURE;
}
@ -687,7 +704,9 @@ static WERROR regf_get_subkey_by_index (TALLOC_CTX *ctx,
DEBUG(10, ("Subkeys in RI->LH list\n"));
if (NT_STATUS_IS_ERR(tdr_pull_lh_block(&pull, nk, &lh))) {
if (NT_STATUS_IS_ERR(tdr_pull_lh_block(&pull,
nk,
&lh))) {
DEBUG(0, ("Error parsing LH list from RI\n"));
return WERR_GENERAL_FAILURE;
}
@ -724,9 +743,10 @@ static WERROR regf_get_subkey_by_index (TALLOC_CTX *ctx,
if (classname != NULL) {
if (ret->nk->clsname_offset != -1) {
DATA_BLOB db = hbin_get(ret->hive,
ret->nk->clsname_offset);
ret->nk->clsname_offset);
*classname = talloc_strndup(ctx,
(char*)db.data, ret->nk->clsname_length);
(char*)db.data,
ret->nk->clsname_length);
} else
*classname = NULL;
}
@ -743,8 +763,9 @@ static WERROR regf_get_subkey_by_index (TALLOC_CTX *ctx,
}
static WERROR regf_match_subkey_by_name(TALLOC_CTX *ctx,
const struct hive_key *key, uint32_t offset,
const char *name, uint32_t *ret)
const struct hive_key *key,
uint32_t offset,
const char *name, uint32_t *ret)
{
DATA_BLOB subkey_data;
struct nk_block subkey;
@ -780,9 +801,9 @@ static WERROR regf_match_subkey_by_name(TALLOC_CTX *ctx,
}
static WERROR regf_get_subkey_by_name(TALLOC_CTX *ctx,
const struct hive_key *key,
const char *name,
struct hive_key **ret)
const struct hive_key *key,
const char *name,
struct hive_key **ret)
{
DATA_BLOB data;
const struct regf_key_data *private_data =
@ -817,7 +838,10 @@ static WERROR regf_get_subkey_by_name(TALLOC_CTX *ctx,
}
for (i = 0; i < li.key_count; i++) {
W_ERROR_NOT_OK_RETURN(regf_match_subkey_by_name(nk, key, li.nk_offset[i], name, &key_off));
W_ERROR_NOT_OK_RETURN(regf_match_subkey_by_name(nk, key,
li.nk_offset[i],
name,
&key_off));
if (key_off != 0)
break;
}
@ -847,7 +871,11 @@ static WERROR regf_get_subkey_by_name(TALLOC_CTX *ctx,
if (strncmp(lf.hr[i].hash, name, 4)) {
continue;
}
W_ERROR_NOT_OK_RETURN(regf_match_subkey_by_name(nk, key, lf.hr[i].nk_offset, name, &key_off));
W_ERROR_NOT_OK_RETURN(regf_match_subkey_by_name(nk,
key,
lf.hr[i].nk_offset,
name,
&key_off));
if (key_off != 0)
break;
}
@ -879,7 +907,11 @@ static WERROR regf_get_subkey_by_name(TALLOC_CTX *ctx,
if (lh.hr[i].base37 != hash) {
continue;
}
W_ERROR_NOT_OK_RETURN(regf_match_subkey_by_name(nk, key, lh.hr[i].nk_offset, name, &key_off));
W_ERROR_NOT_OK_RETURN(regf_match_subkey_by_name(nk,
key,
lh.hr[i].nk_offset,
name,
&key_off));
if (key_off != 0)
break;
}
@ -916,7 +948,9 @@ static WERROR regf_get_subkey_by_name(TALLOC_CTX *ctx,
if (!strncmp((char *)list_data.data, "li", 2)) {
struct li_block li;
if (NT_STATUS_IS_ERR(tdr_pull_li_block(&pull, nk, &li))) {
if (NT_STATUS_IS_ERR(tdr_pull_li_block(&pull,
nk,
&li))) {
DEBUG(0, ("Error parsing LI list from RI\n"));
return WERR_GENERAL_FAILURE;
}
@ -924,7 +958,9 @@ static WERROR regf_get_subkey_by_name(TALLOC_CTX *ctx,
for (j = 0; j < li.key_count; j++) {
W_ERROR_NOT_OK_RETURN(regf_match_subkey_by_name(nk, key,
li.nk_offset[j], name, &key_off));
li.nk_offset[j],
name,
&key_off));
if (key_off)
break;
}
@ -932,7 +968,9 @@ static WERROR regf_get_subkey_by_name(TALLOC_CTX *ctx,
struct lh_block lh;
uint32_t hash;
if (NT_STATUS_IS_ERR(tdr_pull_lh_block(&pull, nk, &lh))) {
if (NT_STATUS_IS_ERR(tdr_pull_lh_block(&pull,
nk,
&lh))) {
DEBUG(0, ("Error parsing LH list from RI\n"));
return WERR_GENERAL_FAILURE;
}
@ -944,7 +982,9 @@ static WERROR regf_get_subkey_by_name(TALLOC_CTX *ctx,
continue;
}
W_ERROR_NOT_OK_RETURN(regf_match_subkey_by_name(nk, key,
lh.hr[j].nk_offset, name, &key_off));
lh.hr[j].nk_offset,
name,
&key_off));
if (key_off)
break;
}
@ -959,12 +999,13 @@ static WERROR regf_get_subkey_by_name(TALLOC_CTX *ctx,
return WERR_GENERAL_FAILURE;
}
*ret = (struct hive_key *)regf_get_key (ctx, private_data->hive, key_off);
*ret = (struct hive_key *)regf_get_key(ctx, private_data->hive,
key_off);
return WERR_OK;
}
static WERROR regf_set_sec_desc (struct hive_key *key,
const struct security_descriptor *sec_desc)
static WERROR regf_set_sec_desc(struct hive_key *key,
const struct security_descriptor *sec_desc)
{
const struct regf_key_data *private_data =
(const struct regf_key_data *)key;
@ -977,23 +1018,24 @@ static WERROR regf_set_sec_desc (struct hive_key *key,
/* Get the root nk */
hbin_get_tdr(regf, regf->header->data_offset, regf,
(tdr_pull_fn_t) tdr_pull_nk_block, &root);
(tdr_pull_fn_t) tdr_pull_nk_block, &root);
/* Push the security descriptor to a blob */
if (NT_STATUS_IS_ERR(ndr_push_struct_blob(&data, regf, sec_desc,
(ndr_push_flags_fn_t)ndr_push_security_descriptor))) {
(ndr_push_flags_fn_t)ndr_push_security_descriptor))) {
DEBUG(0, ("Unable to push security descriptor\n"));
return WERR_GENERAL_FAILURE;
}
/* Get the current security descriptor for the key */
if (!hbin_get_tdr(regf, private_data->nk->sk_offset, regf,
(tdr_pull_fn_t) tdr_pull_sk_block, &cur_sk)) {
(tdr_pull_fn_t) tdr_pull_sk_block, &cur_sk)) {
DEBUG(0, ("Unable to find security descriptor for current key\n"));
return WERR_BADFILE;
}
/* If there's no change, change nothing. */
if (memcmp(data.data, cur_sk.sec_desc, MIN(data.length, cur_sk.rec_size)) == 0) {
if (memcmp(data.data, cur_sk.sec_desc,
MIN(data.length, cur_sk.rec_size)) == 0) {
return WERR_OK;
}
@ -1001,22 +1043,25 @@ static WERROR regf_set_sec_desc (struct hive_key *key,
if (cur_sk.ref_cnt == 1) {
/* Get the previous security descriptor for the key */
if (!hbin_get_tdr(regf, cur_sk.prev_offset, regf,
(tdr_pull_fn_t) tdr_pull_sk_block, &sk)) {
(tdr_pull_fn_t) tdr_pull_sk_block, &sk)) {
DEBUG(0, ("Unable to find prev security descriptor for current key\n"));
return WERR_BADFILE;
}
/* Change and store the previous security descriptor */
sk.next_offset = cur_sk.next_offset;
hbin_store_tdr_resize(regf, (tdr_push_fn_t) tdr_push_sk_block, cur_sk.prev_offset, &sk);
hbin_store_tdr_resize(regf, (tdr_push_fn_t) tdr_push_sk_block,
cur_sk.prev_offset, &sk);
/* Get the next security descriptor for the key */
if (!hbin_get_tdr(regf, cur_sk.next_offset, regf, (tdr_pull_fn_t) tdr_pull_sk_block, &sk)) {
if (!hbin_get_tdr(regf, cur_sk.next_offset, regf,
(tdr_pull_fn_t) tdr_pull_sk_block, &sk)) {
DEBUG(0, ("Unable to find next security descriptor for current key\n"));
return WERR_BADFILE;
}
/* Change and store the next security descriptor */
sk.prev_offset = cur_sk.prev_offset;
hbin_store_tdr_resize(regf, (tdr_push_fn_t) tdr_push_sk_block, cur_sk.next_offset, &sk);
hbin_store_tdr_resize(regf, (tdr_push_fn_t) tdr_push_sk_block,
cur_sk.next_offset, &sk);
hbin_free(regf, private_data->nk->sk_offset);
} else {
@ -1029,15 +1074,21 @@ static WERROR regf_set_sec_desc (struct hive_key *key,
do {
cur_sk_offset = sk_offset;
if (!hbin_get_tdr(regf, sk_offset, regf, (tdr_pull_fn_t) tdr_pull_sk_block, &sk)) {
if (!hbin_get_tdr(regf, sk_offset, regf,
(tdr_pull_fn_t) tdr_pull_sk_block, &sk)) {
DEBUG(0, ("Unable to find security descriptor\n"));
return WERR_BADFILE;
}
if (memcmp(data.data, sk.sec_desc, MIN(data.length, sk.rec_size)) == 0) {
private_data->nk->sk_offset = sk_offset;
sk.ref_cnt++;
hbin_store_tdr_resize(regf, (tdr_push_fn_t) tdr_push_sk_block, sk_offset, &sk);
hbin_store_tdr_resize(regf, (tdr_push_fn_t) tdr_push_nk_block, private_data->offset, private_data->nk);
hbin_store_tdr_resize(regf,
(tdr_push_fn_t) tdr_push_sk_block,
sk_offset, &sk);
hbin_store_tdr_resize(regf,
(tdr_push_fn_t) tdr_push_nk_block,
private_data->offset,
private_data->nk);
return WERR_OK;
}
sk_offset = sk.next_offset;
@ -1051,7 +1102,9 @@ static WERROR regf_set_sec_desc (struct hive_key *key,
new_sk.rec_size = data.length;
new_sk.sec_desc = data.data;
sk_offset = hbin_store_tdr(regf, (tdr_push_fn_t) tdr_push_sk_block, &new_sk);
sk_offset = hbin_store_tdr(regf,
(tdr_push_fn_t) tdr_push_sk_block,
&new_sk);
if (sk_offset == -1) {
DEBUG(0, ("Error storing sk block\n"));
return WERR_GENERAL_FAILURE;
@ -1059,35 +1112,45 @@ static WERROR regf_set_sec_desc (struct hive_key *key,
private_data->nk->sk_offset = sk_offset;
if (update_cur_sk) {
hbin_store_tdr_resize(regf, (tdr_push_fn_t) tdr_push_sk_block, private_data->nk->sk_offset, &cur_sk);
hbin_store_tdr_resize(regf,
(tdr_push_fn_t) tdr_push_sk_block,
private_data->nk->sk_offset, &cur_sk);
}
/* Get the previous security descriptor for the key */
if (!hbin_get_tdr(regf, new_sk.prev_offset, regf, (tdr_pull_fn_t) tdr_pull_sk_block, &sk)) {
if (!hbin_get_tdr(regf, new_sk.prev_offset, regf,
(tdr_pull_fn_t) tdr_pull_sk_block, &sk)) {
DEBUG(0, ("Unable to find security descriptor for previous key\n"));
return WERR_BADFILE;
}
/* Change and store the previous security descriptor */
sk.next_offset = sk_offset;
hbin_store_tdr_resize(regf, (tdr_push_fn_t) tdr_push_sk_block, cur_sk.prev_offset, &sk);
hbin_store_tdr_resize(regf,
(tdr_push_fn_t) tdr_push_sk_block,
cur_sk.prev_offset, &sk);
/* Get the next security descriptor for the key (always root, as we append) */
if (!hbin_get_tdr(regf, new_sk.next_offset, regf, (tdr_pull_fn_t) tdr_pull_sk_block, &sk)) {
if (!hbin_get_tdr(regf, new_sk.next_offset, regf,
(tdr_pull_fn_t) tdr_pull_sk_block, &sk)) {
DEBUG(0, ("Unable to find security descriptor for current key\n"));
return WERR_BADFILE;
}
/* Change and store the next security descriptor (always root, as we append) */
sk.prev_offset = sk_offset;
hbin_store_tdr_resize(regf, (tdr_push_fn_t) tdr_push_sk_block, root.sk_offset, &sk);
hbin_store_tdr_resize(regf,
(tdr_push_fn_t) tdr_push_sk_block,
root.sk_offset, &sk);
/* Store the nk. */
hbin_store_tdr_resize(regf, (tdr_push_fn_t) tdr_push_sk_block, private_data->offset, private_data->nk);
hbin_store_tdr_resize(regf,
(tdr_push_fn_t) tdr_push_sk_block,
private_data->offset, private_data->nk);
return WERR_OK;
}
static WERROR regf_get_sec_desc(TALLOC_CTX *ctx, const struct hive_key *key,
struct security_descriptor **sd)
struct security_descriptor **sd)
{
const struct regf_key_data *private_data =
(const struct regf_key_data *)key;
@ -1095,7 +1158,8 @@ static WERROR regf_get_sec_desc(TALLOC_CTX *ctx, const struct hive_key *key,
struct regf_data *regf = private_data->hive;
DATA_BLOB data;
if (!hbin_get_tdr(regf, private_data->nk->sk_offset, ctx, (tdr_pull_fn_t) tdr_pull_sk_block, &sk)) {
if (!hbin_get_tdr(regf, private_data->nk->sk_offset, ctx,
(tdr_pull_fn_t) tdr_pull_sk_block, &sk)) {
DEBUG(0, ("Unable to find security descriptor\n"));
return WERR_GENERAL_FAILURE;
}
@ -1110,7 +1174,8 @@ static WERROR regf_get_sec_desc(TALLOC_CTX *ctx, const struct hive_key *key,
data.data = sk.sec_desc;
data.length = sk.rec_size;
if (NT_STATUS_IS_ERR(ndr_pull_struct_blob(&data, ctx, *sd, (ndr_pull_flags_fn_t)ndr_pull_security_descriptor))) {
if (NT_STATUS_IS_ERR(ndr_pull_struct_blob(&data, ctx, *sd,
(ndr_pull_flags_fn_t)ndr_pull_security_descriptor))) {
DEBUG(0, ("Error parsing security descriptor\n"));
return WERR_GENERAL_FAILURE;
}
@ -1119,7 +1184,8 @@ static WERROR regf_get_sec_desc(TALLOC_CTX *ctx, const struct hive_key *key,
}
static WERROR regf_sl_add_entry(struct regf_data *regf, uint32_t list_offset,
const char *name, uint32_t key_offset, uint32_t *ret)
const char *name,
uint32_t key_offset, uint32_t *ret)
{
DATA_BLOB data;
@ -1140,10 +1206,13 @@ static WERROR regf_sl_add_entry(struct regf_data *regf, uint32_t list_offset,
W_ERROR_HAVE_NO_MEMORY(li.nk_offset);
li.nk_offset[0] = key_offset;
*ret = hbin_store_tdr(regf, (tdr_push_fn_t) tdr_push_li_block, &li);
*ret = hbin_store_tdr(regf,
(tdr_push_fn_t) tdr_push_li_block,
&li);
talloc_free(li.nk_offset);
} else if (regf->header->version.minor == 3 || regf->header->version.minor == 4) {
} else if (regf->header->version.minor == 3 ||
regf->header->version.minor == 4) {
/* Store LF */
struct lf_block lf;
ZERO_STRUCT(lf);
@ -1156,7 +1225,9 @@ static WERROR regf_sl_add_entry(struct regf_data *regf, uint32_t list_offset,
lf.hr[0].hash = talloc_strndup(lf.hr, name, 4);
W_ERROR_HAVE_NO_MEMORY(lf.hr[0].hash);
*ret = hbin_store_tdr(regf, (tdr_push_fn_t) tdr_push_lf_block, &lf);
*ret = hbin_store_tdr(regf,
(tdr_push_fn_t) tdr_push_lf_block,
&lf);
talloc_free(lf.hr);
} else if (regf->header->version.minor == 5) {
@ -1171,7 +1242,9 @@ static WERROR regf_sl_add_entry(struct regf_data *regf, uint32_t list_offset,
lh.hr[0].nk_offset = key_offset;
lh.hr[0].base37 = regf_create_lh_hash(name);
*ret = hbin_store_tdr(regf, (tdr_push_fn_t) tdr_push_lh_block, &lh);
*ret = hbin_store_tdr(regf,
(tdr_push_fn_t) tdr_push_lh_block,
&lh);
talloc_free(lh.hr);
}
@ -1202,11 +1275,14 @@ static WERROR regf_sl_add_entry(struct regf_data *regf, uint32_t list_offset,
return WERR_BADFILE;
}
li.nk_offset = talloc_realloc(regf, li.nk_offset, uint32_t, li.key_count+1);
li.nk_offset = talloc_realloc(regf, li.nk_offset,
uint32_t, li.key_count+1);
W_ERROR_HAVE_NO_MEMORY(li.nk_offset);
li.nk_offset[li.key_count] = key_offset;
li.key_count++;
*ret = hbin_store_tdr_resize(regf, (tdr_push_fn_t)tdr_push_li_block, list_offset, &li);
*ret = hbin_store_tdr_resize(regf,
(tdr_push_fn_t)tdr_push_li_block,
list_offset, &li);
talloc_free(li.nk_offset);
} else if (!strncmp((char *)data.data, "lf", 2)) {
@ -1222,13 +1298,16 @@ static WERROR regf_sl_add_entry(struct regf_data *regf, uint32_t list_offset,
}
SMB_ASSERT(!strncmp(lf.header, "lf", 2));
lf.hr = talloc_realloc(regf, lf.hr, struct hash_record, lf.key_count+1);
lf.hr = talloc_realloc(regf, lf.hr, struct hash_record,
lf.key_count+1);
W_ERROR_HAVE_NO_MEMORY(lf.hr);
lf.hr[lf.key_count].nk_offset = key_offset;
lf.hr[lf.key_count].hash = talloc_strndup(lf.hr, name, 4);
W_ERROR_HAVE_NO_MEMORY(lf.hr[lf.key_count].hash);
lf.key_count++;
*ret = hbin_store_tdr_resize(regf, (tdr_push_fn_t)tdr_push_lf_block, list_offset, &lf);
*ret = hbin_store_tdr_resize(regf,
(tdr_push_fn_t)tdr_push_lf_block,
list_offset, &lf);
talloc_free(lf.hr);
} else if (!strncmp((char *)data.data, "lh", 2)) {
@ -1244,12 +1323,15 @@ static WERROR regf_sl_add_entry(struct regf_data *regf, uint32_t list_offset,
}
SMB_ASSERT(!strncmp(lh.header, "lh", 2));
lh.hr = talloc_realloc(regf, lh.hr, struct lh_hash, lh.key_count+1);
lh.hr = talloc_realloc(regf, lh.hr, struct lh_hash,
lh.key_count+1);
W_ERROR_HAVE_NO_MEMORY(lh.hr);
lh.hr[lh.key_count].nk_offset = key_offset;
lh.hr[lh.key_count].base37 = regf_create_lh_hash(name);
lh.key_count++;
*ret = hbin_store_tdr_resize(regf, (tdr_push_fn_t)tdr_push_lh_block, list_offset, &lh);
*ret = hbin_store_tdr_resize(regf,
(tdr_push_fn_t)tdr_push_lh_block,
list_offset, &lh);
talloc_free(lh.hr);
} else if (!strncmp((char *)data.data, "ri", 2)) {
@ -1265,7 +1347,7 @@ static WERROR regf_sl_add_entry(struct regf_data *regf, uint32_t list_offset,
}
static WERROR regf_sl_del_entry(struct regf_data *regf, uint32_t list_offset,
uint32_t key_offset, uint32_t *ret)
uint32_t key_offset, uint32_t *ret)
{
DATA_BLOB data;
@ -1315,7 +1397,9 @@ static WERROR regf_sl_del_entry(struct regf_data *regf, uint32_t list_offset,
}
/* Store li block */
*ret = hbin_store_tdr_resize(regf, (tdr_push_fn_t) tdr_push_li_block, list_offset, &li);
*ret = hbin_store_tdr_resize(regf,
(tdr_push_fn_t) tdr_push_li_block,
list_offset, &li);
} else if (strncmp((char *)data.data, "lf", 2) == 0) {
struct lf_block lf;
struct tdr_pull pull;
@ -1358,7 +1442,9 @@ static WERROR regf_sl_del_entry(struct regf_data *regf, uint32_t list_offset,
}
/* Store lf block */
*ret = hbin_store_tdr_resize(regf, (tdr_push_fn_t) tdr_push_lf_block, list_offset, &lf);
*ret = hbin_store_tdr_resize(regf,
(tdr_push_fn_t) tdr_push_lf_block,
list_offset, &lf);
} else if (strncmp((char *)data.data, "lh", 2) == 0) {
struct lh_block lh;
struct tdr_pull pull;
@ -1401,7 +1487,9 @@ static WERROR regf_sl_del_entry(struct regf_data *regf, uint32_t list_offset,
}
/* Store lh block */
*ret = hbin_store_tdr_resize(regf, (tdr_push_fn_t) tdr_push_lh_block, list_offset, &lh);
*ret = hbin_store_tdr_resize(regf,
(tdr_push_fn_t) tdr_push_lh_block,
list_offset, &lh);
} else if (strncmp((char *)data.data, "ri", 2) == 0) {
/* FIXME */
DEBUG(0, ("Sorry, deletion from ri block is not supported yet.\n"));
@ -1437,8 +1525,10 @@ static WERROR regf_del_value (struct hive_key *key, const char *name)
} else {
vk_offset = IVAL(values.data, i * 4);
if (!hbin_get_tdr(regf, vk_offset, private_data,
(tdr_pull_fn_t)tdr_pull_vk_block, &vk)) {
DEBUG(0, ("Unable to get VK block at %d\n", vk_offset));
(tdr_pull_fn_t)tdr_pull_vk_block,
&vk)) {
DEBUG(0, ("Unable to get VK block at %d\n",
vk_offset));
return WERR_BADFILE;
}
if (strcmp(vk.data_name, name) == 0) {
@ -1459,9 +1549,12 @@ static WERROR regf_del_value (struct hive_key *key, const char *name)
hbin_free(regf, nk->values_offset);
nk->values_offset = -1;
} else {
nk->values_offset = hbin_store_resize(regf, nk->values_offset, values);
nk->values_offset = hbin_store_resize(regf,
nk->values_offset,
values);
}
hbin_store_tdr_resize(regf, (tdr_push_fn_t) tdr_push_nk_block, private_data->offset, nk);
hbin_store_tdr_resize(regf, (tdr_push_fn_t) tdr_push_nk_block,
private_data->offset, nk);
return regf_save_hbin(private_data->hive);
}
@ -1486,7 +1579,7 @@ static WERROR regf_del_key(const struct hive_key *parent, const char *name)
/* Find the key */
if (!W_ERROR_IS_OK(regf_get_subkey_by_name(parent_nk, parent, name,
(struct hive_key **)&key))) {
(struct hive_key **)&key))) {
DEBUG(2, ("Key '%s' not found\n", name));
return WERR_NOT_FOUND;
}
@ -1499,7 +1592,7 @@ static WERROR regf_del_key(const struct hive_key *parent, const char *name)
/* Delete it from the subkey list. */
error = regf_sl_del_entry(private_data->hive, parent_nk->subkeys_offset,
key->offset, &parent_nk->subkeys_offset);
key->offset, &parent_nk->subkeys_offset);
if (!W_ERROR_IS_OK(error)) {
DEBUG(0, ("Can't store new subkey list for parent key. Won't delete.\n"));
return error;
@ -1508,8 +1601,8 @@ static WERROR regf_del_key(const struct hive_key *parent, const char *name)
/* Re-store parent key */
parent_nk->num_subkeys--;
hbin_store_tdr_resize(private_data->hive,
(tdr_push_fn_t) tdr_push_nk_block,
private_data->offset, parent_nk);
(tdr_push_fn_t) tdr_push_nk_block,
private_data->offset, parent_nk);
if (key->nk->clsname_offset != -1) {
hbin_free(private_data->hive, key->nk->clsname_offset);
@ -1520,9 +1613,9 @@ static WERROR regf_del_key(const struct hive_key *parent, const char *name)
}
static WERROR regf_add_key(TALLOC_CTX *ctx, const struct hive_key *parent,
const char *name, const char *classname,
struct security_descriptor *sec_desc,
struct hive_key **ret)
const char *name, const char *classname,
struct security_descriptor *sec_desc,
struct hive_key **ret)
{
const struct regf_key_data *private_data =
(const struct regf_key_data *)parent;
@ -1553,7 +1646,7 @@ static WERROR regf_add_key(TALLOC_CTX *ctx, const struct hive_key *parent,
W_ERROR_HAVE_NO_MEMORY(root);
if (!hbin_get_tdr(regf, regf->header->data_offset, root,
(tdr_pull_fn_t)tdr_pull_nk_block, root)) {
(tdr_pull_fn_t)tdr_pull_nk_block, root)) {
DEBUG(0, ("Unable to find HBIN data for offset %d\n", offset));
return WERR_GENERAL_FAILURE;
}
@ -1563,7 +1656,8 @@ static WERROR regf_add_key(TALLOC_CTX *ctx, const struct hive_key *parent,
/* Store the new nk key */
offset = hbin_store_tdr(regf, (tdr_push_fn_t) tdr_push_nk_block, &nk);
error = regf_sl_add_entry(regf, parent_nk->subkeys_offset, name, offset, &parent_nk->subkeys_offset);
error = regf_sl_add_entry(regf, parent_nk->subkeys_offset, name, offset,
&parent_nk->subkeys_offset);
if (!W_ERROR_IS_OK(error)) {
hbin_free(regf, offset);
return error;
@ -1581,7 +1675,7 @@ static WERROR regf_add_key(TALLOC_CTX *ctx, const struct hive_key *parent,
}
static WERROR regf_set_value(struct hive_key *key, const char *name,
uint32_t type, const DATA_BLOB data)
uint32_t type, const DATA_BLOB data)
{
const struct regf_key_data *private_data =
(const struct regf_key_data *)key;
@ -1601,8 +1695,10 @@ static WERROR regf_set_value(struct hive_key *key, const char *name,
for (i = 0; i < nk->num_values; i++) {
tmp_vk_offset = IVAL(values.data, i * 4);
if (!hbin_get_tdr(regf, tmp_vk_offset, private_data,
(tdr_pull_fn_t)tdr_pull_vk_block, &vk)) {
DEBUG(0, ("Unable to get VK block at %d\n", tmp_vk_offset));
(tdr_pull_fn_t)tdr_pull_vk_block,
&vk)) {
DEBUG(0, ("Unable to get VK block at %d\n",
tmp_vk_offset));
return WERR_GENERAL_FAILURE;
}
if (strcmp(vk.data_name, name) == 0) {
@ -1638,15 +1734,21 @@ static WERROR regf_set_value(struct hive_key *key, const char *name,
}
if (old_vk_offset == -1) {
/* Store new vk */
vk_offset = hbin_store_tdr(regf, (tdr_push_fn_t) tdr_push_vk_block, &vk);
vk_offset = hbin_store_tdr(regf,
(tdr_push_fn_t) tdr_push_vk_block,
&vk);
} else {
/* Store vk at offset */
vk_offset = hbin_store_tdr_resize(regf, (tdr_push_fn_t) tdr_push_vk_block, old_vk_offset ,&vk);
vk_offset = hbin_store_tdr_resize(regf,
(tdr_push_fn_t) tdr_push_vk_block,
old_vk_offset ,&vk);
}
/* Re-allocate the value list */
if (nk->values_offset == -1) {
nk->values_offset = hbin_store_tdr(regf, (tdr_push_fn_t) tdr_push_uint32, &vk_offset);
nk->values_offset = hbin_store_tdr(regf,
(tdr_push_fn_t) tdr_push_uint32,
&vk_offset);
nk->num_values = 1;
} else {
@ -1664,17 +1766,23 @@ static WERROR regf_set_value(struct hive_key *key, const char *name,
DATA_BLOB value_list;
value_list.length = (nk->num_values+1)*4;
value_list.data = (uint8_t *)talloc_array(private_data, uint32_t, nk->num_values+1);
value_list.data = (uint8_t *)talloc_array(private_data,
uint32_t,
nk->num_values+1);
W_ERROR_HAVE_NO_MEMORY(value_list.data);
memcpy(value_list.data, values.data, nk->num_values * 4);
SIVAL(value_list.data, nk->num_values * 4, vk_offset);
nk->num_values++;
nk->values_offset = hbin_store_resize(regf, nk->values_offset, value_list);
nk->values_offset = hbin_store_resize(regf,
nk->values_offset,
value_list);
}
}
hbin_store_tdr_resize(regf, (tdr_push_fn_t) tdr_push_nk_block, private_data->offset, nk);
hbin_store_tdr_resize(regf,
(tdr_push_fn_t) tdr_push_nk_block,
private_data->offset, nk);
return regf_save_hbin(private_data->hive);
}
@ -1699,7 +1807,8 @@ static WERROR regf_save_hbin(struct regf_data *regf)
talloc_free(push);
if (NT_STATUS_IS_ERR(tdr_push_to_fd(regf->fd,
(tdr_push_fn_t)tdr_push_regf_hdr, regf->header))) {
(tdr_push_fn_t)tdr_push_regf_hdr,
regf->header))) {
DEBUG(0, ("Error writing registry file header\n"));
return WERR_GENERAL_FAILURE;
}
@ -1711,8 +1820,8 @@ static WERROR regf_save_hbin(struct regf_data *regf)
for (i = 0; regf->hbins[i]; i++) {
if (NT_STATUS_IS_ERR(tdr_push_to_fd(regf->fd,
(tdr_push_fn_t)tdr_push_hbin_block,
regf->hbins[i]))) {
(tdr_push_fn_t)tdr_push_hbin_block,
regf->hbins[i]))) {
DEBUG(0, ("Error writing HBIN block\n"));
return WERR_GENERAL_FAILURE;
}
@ -1722,7 +1831,7 @@ static WERROR regf_save_hbin(struct regf_data *regf)
}
WERROR reg_create_regf_file(TALLOC_CTX *parent_ctx, const char *location,
int minor_version, struct hive_key **key)
int minor_version, struct hive_key **key)
{
struct regf_data *regf;
struct regf_hdr *regf_hdr;
@ -1754,7 +1863,8 @@ WERROR reg_create_regf_file(TALLOC_CTX *parent_ctx, const char *location,
regf_hdr->version.major = 1;
regf_hdr->version.minor = minor_version;
regf_hdr->last_block = 0x1000; /* Block size */
regf_hdr->description = talloc_strdup(regf_hdr, "registry created by Samba 4");
regf_hdr->description = talloc_strdup(regf_hdr,
"registry created by Samba 4");
W_ERROR_HAVE_NO_MEMORY(regf_hdr->description);
regf_hdr->chksum = 0;
@ -1790,9 +1900,11 @@ WERROR reg_create_regf_file(TALLOC_CTX *parent_ctx, const char *location,
/* Store the new nk key */
regf->header->data_offset = hbin_store_tdr(regf,
(tdr_push_fn_t)tdr_push_nk_block, &nk);
(tdr_push_fn_t)tdr_push_nk_block,
&nk);
*key = (struct hive_key *)regf_get_key(parent_ctx, regf, regf->header->data_offset);
*key = (struct hive_key *)regf_get_key(parent_ctx, regf,
regf->header->data_offset);
/* We can drop our own reference now that *key will have created one */
talloc_free(regf);
@ -1806,7 +1918,7 @@ WERROR reg_create_regf_file(TALLOC_CTX *parent_ctx, const char *location,
}
WERROR reg_open_regf_file(TALLOC_CTX *parent_ctx,
const char *location, struct hive_key **key)
const char *location, struct hive_key **key)
{
struct regf_data *regf;
struct regf_hdr *regf_hdr;
@ -1850,7 +1962,7 @@ WERROR reg_open_regf_file(TALLOC_CTX *parent_ctx,
if (strcmp(regf_hdr->REGF_ID, "regf") != 0) {
DEBUG(0, ("Unrecognized NT registry header id: %s, %s\n",
regf_hdr->REGF_ID, location));
regf_hdr->REGF_ID, location));
talloc_free(regf);
return WERR_GENERAL_FAILURE;
}
@ -1858,8 +1970,8 @@ WERROR reg_open_regf_file(TALLOC_CTX *parent_ctx,
/* Validate the header ... */
if (regf_hdr_checksum(pull.data.data) != regf_hdr->chksum) {
DEBUG(0, ("Registry file checksum error: %s: %d,%d\n",
location, regf_hdr->chksum,
regf_hdr_checksum(pull.data.data)));
location, regf_hdr->chksum,
regf_hdr_checksum(pull.data.data)));
talloc_free(regf);
return WERR_GENERAL_FAILURE;
}
@ -1873,8 +1985,10 @@ WERROR reg_open_regf_file(TALLOC_CTX *parent_ctx,
regf->hbins[0] = NULL;
while (pull.offset < pull.data.length && pull.offset <= regf->header->last_block) {
struct hbin_block *hbin = talloc(regf->hbins, struct hbin_block);
while (pull.offset < pull.data.length &&
pull.offset <= regf->header->last_block) {
struct hbin_block *hbin = talloc(regf->hbins,
struct hbin_block);
W_ERROR_HAVE_NO_MEMORY(hbin);
@ -1885,21 +1999,23 @@ WERROR reg_open_regf_file(TALLOC_CTX *parent_ctx,
}
if (strcmp(hbin->HBIN_ID, "hbin") != 0) {
DEBUG(0, ("[%d] Expected 'hbin', got '%s'\n", i, hbin->HBIN_ID));
DEBUG(0, ("[%d] Expected 'hbin', got '%s'\n",
i, hbin->HBIN_ID));
talloc_free(regf);
return WERR_FOOBAR;
}
regf->hbins[i] = hbin;
i++;
regf->hbins = talloc_realloc(regf, regf->hbins, struct hbin_block *, i+2);
regf->hbins = talloc_realloc(regf, regf->hbins,
struct hbin_block *, i+2);
regf->hbins[i] = NULL;
}
DEBUG(1, ("%d HBIN blocks read\n", i));
*key = (struct hive_key *)regf_get_key(parent_ctx, regf,
regf->header->data_offset);
regf->header->data_offset);
/* We can drop our own reference now that *key will have created one */
talloc_free(regf);

View File

@ -29,15 +29,15 @@ struct registry_context;
#include "libcli/util/ntstatus.h"
/* Handles for the predefined keys */
#define HKEY_CLASSES_ROOT 0x80000000
#define HKEY_CURRENT_USER 0x80000001
#define HKEY_LOCAL_MACHINE 0x80000002
#define HKEY_USERS 0x80000003
#define HKEY_PERFORMANCE_DATA 0x80000004
#define HKEY_CURRENT_CONFIG 0x80000005
#define HKEY_DYN_DATA 0x80000006
#define HKEY_PERFORMANCE_TEXT 0x80000050
#define HKEY_PERFORMANCE_NLSTEXT 0x80000060
#define HKEY_CLASSES_ROOT 0x80000000
#define HKEY_CURRENT_USER 0x80000001
#define HKEY_LOCAL_MACHINE 0x80000002
#define HKEY_USERS 0x80000003
#define HKEY_PERFORMANCE_DATA 0x80000004
#define HKEY_CURRENT_CONFIG 0x80000005
#define HKEY_DYN_DATA 0x80000006
#define HKEY_PERFORMANCE_TEXT 0x80000050
#define HKEY_PERFORMANCE_NLSTEXT 0x80000060
#define HKEY_FIRST HKEY_CLASSES_ROOT
#define HKEY_LAST HKEY_PERFORMANCE_NLSTEXT
@ -70,9 +70,9 @@ struct registry_key
struct registry_value
{
const char *name;
unsigned int data_type;
DATA_BLOB data;
const char *name;
unsigned int data_type;
DATA_BLOB data;
};
/* FIXME */
@ -86,72 +86,72 @@ struct registry_operations {
const char *name;
WERROR (*get_key_info) (TALLOC_CTX *mem_ctx,
const struct registry_key *key,
const char **classname,
uint32_t *numsubkeys,
uint32_t *numvalues,
NTTIME *last_change_time);
const struct registry_key *key,
const char **classname,
uint32_t *numsubkeys,
uint32_t *numvalues,
NTTIME *last_change_time);
WERROR (*flush_key) (struct registry_key *key);
WERROR (*get_predefined_key) (const struct registry_context *ctx,
uint32_t key_id,
struct registry_key **key);
uint32_t key_id,
struct registry_key **key);
WERROR (*open_key) (TALLOC_CTX *mem_ctx,
struct registry_key *parent,
const char *path,
struct registry_key **key);
struct registry_key *parent,
const char *path,
struct registry_key **key);
WERROR (*create_key) (TALLOC_CTX *mem_ctx,
struct registry_key *parent,
const char *name,
const char *key_class,
struct security_descriptor *security,
struct registry_key **key);
struct registry_key *parent,
const char *name,
const char *key_class,
struct security_descriptor *security,
struct registry_key **key);
WERROR (*delete_key) (struct registry_key *key, const char *name);
WERROR (*delete_value) (struct registry_key *key, const char *name);
WERROR (*enum_key) (TALLOC_CTX *mem_ctx,
const struct registry_key *key, uint32_t idx,
const char **name,
const char **keyclass,
NTTIME *last_changed_time);
const struct registry_key *key, uint32_t idx,
const char **name,
const char **keyclass,
NTTIME *last_changed_time);
WERROR (*enum_value) (TALLOC_CTX *mem_ctx,
const struct registry_key *key, uint32_t idx,
const char **name,
uint32_t *type,
DATA_BLOB *data);
const struct registry_key *key, uint32_t idx,
const char **name,
uint32_t *type,
DATA_BLOB *data);
WERROR (*get_security) (TALLOC_CTX *mem_ctx,
const struct registry_key *key,
struct security_descriptor **security);
const struct registry_key *key,
struct security_descriptor **security);
WERROR (*set_security) (struct registry_key *key,
const struct security_descriptor *security);
const struct security_descriptor *security);
WERROR (*load_key) (struct registry_key *key,
const char *key_name,
const char *path);
const char *key_name,
const char *path);
WERROR (*unload_key) (struct registry_key *key, const char *name);
WERROR (*notify_value_change) (struct registry_key *key,
reg_value_notification_function fn);
reg_value_notification_function fn);
WERROR (*get_value) (TALLOC_CTX *mem_ctx,
const struct registry_key *key,
const char *name,
uint32_t *type,
DATA_BLOB *data);
const struct registry_key *key,
const char *name,
uint32_t *type,
DATA_BLOB *data);
WERROR (*set_value) (struct registry_key *key,
const char *name,
uint32_t type,
const DATA_BLOB data);
const char *name,
uint32_t type,
const DATA_BLOB data);
};
/**
@ -168,81 +168,81 @@ struct event_context;
/**
* Open the locally defined registry.
*/
WERROR reg_open_local (TALLOC_CTX *mem_ctx,
struct registry_context **ctx,
struct auth_session_info *session_info,
struct cli_credentials *credentials);
WERROR reg_open_local(TALLOC_CTX *mem_ctx,
struct registry_context **ctx,
struct auth_session_info *session_info,
struct cli_credentials *credentials);
WERROR reg_open_samba (TALLOC_CTX *mem_ctx,
struct registry_context **ctx,
struct auth_session_info *session_info,
struct cli_credentials *credentials);
WERROR reg_open_samba(TALLOC_CTX *mem_ctx,
struct registry_context **ctx,
struct auth_session_info *session_info,
struct cli_credentials *credentials);
/**
* Open the registry on a remote machine.
*/
WERROR reg_open_remote(struct registry_context **ctx,
struct auth_session_info *session_info,
struct cli_credentials *credentials,
const char *location, struct event_context *ev);
struct auth_session_info *session_info,
struct cli_credentials *credentials,
const char *location, struct event_context *ev);
WERROR reg_open_wine(struct registry_context **ctx, const char *path);
const char *reg_get_predef_name(uint32_t hkey);
WERROR reg_get_predefined_key_by_name(struct registry_context *ctx,
const char *name,
struct registry_key **key);
const char *name,
struct registry_key **key);
WERROR reg_get_predefined_key(const struct registry_context *ctx,
uint32_t hkey,
struct registry_key **key);
uint32_t hkey,
struct registry_key **key);
WERROR reg_open_key(TALLOC_CTX *mem_ctx, struct registry_key *parent,
const char *name, struct registry_key **result);
const char *name, struct registry_key **result);
WERROR reg_key_get_value_by_index(TALLOC_CTX *mem_ctx,
const struct registry_key *key, uint32_t idx,
const char **name,
uint32_t *type,
DATA_BLOB *data);
const struct registry_key *key, uint32_t idx,
const char **name,
uint32_t *type,
DATA_BLOB *data);
WERROR reg_key_get_info(TALLOC_CTX *mem_ctx,
const struct registry_key *key,
const char **class_name,
uint32_t *num_subkeys,
uint32_t *num_values,
NTTIME *last_change_time);
const struct registry_key *key,
const char **class_name,
uint32_t *num_subkeys,
uint32_t *num_values,
NTTIME *last_change_time);
WERROR reg_key_get_subkey_by_index(TALLOC_CTX *mem_ctx,
const struct registry_key *key,
int idx,
const char **name,
const char **classname,
NTTIME *last_mod_time);
const struct registry_key *key,
int idx,
const char **name,
const char **classname,
NTTIME *last_mod_time);
WERROR reg_key_get_subkey_by_name(TALLOC_CTX *mem_ctx,
const struct registry_key *key,
const char *name,
struct registry_key **subkey);
const struct registry_key *key,
const char *name,
struct registry_key **subkey);
WERROR reg_key_get_value_by_name(TALLOC_CTX *mem_ctx,
const struct registry_key *key,
const char *name,
uint32_t *type,
DATA_BLOB *data);
const struct registry_key *key,
const char *name,
uint32_t *type,
DATA_BLOB *data);
WERROR reg_key_del(struct registry_key *parent, const char *name);
WERROR reg_key_add_name(TALLOC_CTX *mem_ctx,
struct registry_key *parent, const char *name,
const char *classname,
struct security_descriptor *desc,
struct registry_key **newkey);
struct registry_key *parent, const char *name,
const char *classname,
struct security_descriptor *desc,
struct registry_key **newkey);
WERROR reg_val_set(struct registry_key *key, const char *value,
uint32_t type, DATA_BLOB data);
WERROR reg_get_sec_desc(TALLOC_CTX *ctx, const struct registry_key *key, struct security_descriptor **secdesc);
uint32_t type, DATA_BLOB data);
WERROR reg_get_sec_desc(TALLOC_CTX *ctx, const struct registry_key *key,
struct security_descriptor **secdesc);
WERROR reg_del_value(struct registry_key *key, const char *valname);
WERROR reg_key_flush(struct registry_key *key);
WERROR reg_create_key (TALLOC_CTX *mem_ctx,
struct registry_key *parent,
const char *name,
const char *key_class,
struct security_descriptor *security,
struct registry_key **key);
WERROR reg_create_key(TALLOC_CTX *mem_ctx,
struct registry_key *parent,
const char *name,
const char *key_class,
struct security_descriptor *security,
struct registry_key **key);
@ -250,31 +250,36 @@ WERROR reg_create_key (TALLOC_CTX *mem_ctx,
/* Utility functions */
const char *str_regtype(int type);
char *reg_val_data_string(TALLOC_CTX *mem_ctx, uint32_t type,
const DATA_BLOB data);
const DATA_BLOB data);
char *reg_val_description(TALLOC_CTX *mem_ctx, const char *name,
uint32_t type, const DATA_BLOB data);
bool reg_string_to_val(TALLOC_CTX *mem_ctx, const char *type_str, const char *data_str, uint32_t *type, DATA_BLOB *data);
WERROR reg_open_key_abs(TALLOC_CTX *mem_ctx, struct registry_context *handle, const char *name, struct registry_key **result);
uint32_t type, const DATA_BLOB data);
bool reg_string_to_val(TALLOC_CTX *mem_ctx, const char *type_str,
const char *data_str, uint32_t *type, DATA_BLOB *data);
WERROR reg_open_key_abs(TALLOC_CTX *mem_ctx, struct registry_context *handle,
const char *name, struct registry_key **result);
WERROR reg_key_del_abs(struct registry_context *ctx, const char *path);
WERROR reg_key_add_abs(TALLOC_CTX *mem_ctx, struct registry_context *ctx, const char *path, uint32_t access_mask, struct security_descriptor *sec_desc, struct registry_key **result);
WERROR reg_key_add_abs(TALLOC_CTX *mem_ctx, struct registry_context *ctx,
const char *path, uint32_t access_mask,
struct security_descriptor *sec_desc,
struct registry_key **result);
WERROR reg_load_key(struct registry_context *ctx, struct registry_key *key,
const char *name, const char *filename);
const char *name, const char *filename);
WERROR reg_mount_hive(struct registry_context *rctx,
struct hive_key *hive_key,
uint32_t key_id,
const char **elements);
struct hive_key *hive_key,
uint32_t key_id,
const char **elements);
struct registry_key *reg_import_hive_key(struct registry_context *ctx,
struct hive_key *hive,
uint32_t predef_key,
const char **elements);
struct hive_key *hive,
uint32_t predef_key,
const char **elements);
WERROR reg_get_security(TALLOC_CTX *mem_ctx,
const struct registry_key *key,
struct security_descriptor **security);
const struct registry_key *key,
struct security_descriptor **security);
WERROR reg_set_security(struct registry_key *key,
struct security_descriptor *security);
struct security_descriptor *security);
#endif /* _REGISTRY_H */

View File

@ -76,7 +76,8 @@ openhive(HKCC)
static struct {
uint32_t hkey;
WERROR (*open) (struct dcerpc_pipe *p, TALLOC_CTX *, struct policy_handle *h);
WERROR (*open) (struct dcerpc_pipe *p, TALLOC_CTX *,
struct policy_handle *h);
} known_hives[] = {
{ HKEY_LOCAL_MACHINE, open_HKLM },
{ HKEY_CURRENT_USER, open_HKCU },
@ -91,12 +92,12 @@ static struct {
static WERROR rpc_query_key(const struct registry_key *k);
static WERROR rpc_get_predefined_key(const struct registry_context *ctx,
uint32_t hkey_type,
struct registry_key **k)
uint32_t hkey_type,
struct registry_key **k)
{
int n;
struct rpc_registry_context *rctx = talloc_get_type(ctx,
struct rpc_registry_context);
struct rpc_registry_context);
struct rpc_key *mykeydata;
for(n = 0; known_hives[n].hkey; n++) {
@ -119,7 +120,7 @@ static WERROR rpc_get_predefined_key(const struct registry_context *ctx,
#if 0
static WERROR rpc_key_put_rpc_data(TALLOC_CTX *mem_ctx, struct registry_key *k)
{
struct winreg_OpenKey r;
struct winreg_OpenKey r;
struct rpc_key_data *mykeydata;
k->backend_data = mykeydata = talloc(mem_ctx, struct rpc_key_data);
@ -129,46 +130,47 @@ static WERROR rpc_key_put_rpc_data(TALLOC_CTX *mem_ctx, struct registry_key *k)
/* Then, open the handle using the hive */
memset(&r, 0, sizeof(struct winreg_OpenKey));
r.in.handle = &(((struct rpc_key_data *)k->hive->root->backend_data)->pol);
init_winreg_String(&r.in.keyname, k->path);
r.in.unknown = 0x00000000;
r.in.access_mask = 0x02000000;
r.out.handle = &mykeydata->pol;
r.in.handle = &(((struct rpc_key_data *)k->hive->root->backend_data)->pol);
init_winreg_String(&r.in.keyname, k->path);
r.in.unknown = 0x00000000;
r.in.access_mask = 0x02000000;
r.out.handle = &mykeydata->pol;
dcerpc_winreg_OpenKey((struct dcerpc_pipe *)k->hive->backend_data, mem_ctx, &r);
dcerpc_winreg_OpenKey((struct dcerpc_pipe *)k->hive->backend_data,
mem_ctx, &r);
return r.out.result;
}
#endif
static WERROR rpc_open_key(TALLOC_CTX *mem_ctx, struct registry_key *h,
const char *name, struct registry_key **key)
const char *name, struct registry_key **key)
{
struct rpc_key *mykeydata = talloc_get_type(h, struct rpc_key),
*newkeydata;
struct winreg_OpenKey r;
*newkeydata;
struct winreg_OpenKey r;
mykeydata = talloc(mem_ctx, struct rpc_key);
/* Then, open the handle using the hive */
memset(&r, 0, sizeof(struct winreg_OpenKey));
r.in.parent_handle = &mykeydata->pol;
init_winreg_String(&r.in.keyname, name);
r.in.unknown = 0x00000000;
r.in.access_mask = 0x02000000;
r.out.handle = &newkeydata->pol;
r.in.parent_handle = &mykeydata->pol;
init_winreg_String(&r.in.keyname, name);
r.in.unknown = 0x00000000;
r.in.access_mask = 0x02000000;
r.out.handle = &newkeydata->pol;
dcerpc_winreg_OpenKey(mykeydata->pipe, mem_ctx, &r);
dcerpc_winreg_OpenKey(mykeydata->pipe, mem_ctx, &r);
return r.out.result;
}
static WERROR rpc_get_value_by_index(TALLOC_CTX *mem_ctx,
const struct registry_key *parent,
uint32_t n,
const char **value_name,
uint32_t *type,
DATA_BLOB *data)
const struct registry_key *parent,
uint32_t n,
const char **value_name,
uint32_t *type,
DATA_BLOB *data)
{
struct rpc_key *mykeydata = talloc_get_type(parent, struct rpc_key);
WERROR error;
@ -215,11 +217,11 @@ static WERROR rpc_get_value_by_index(TALLOC_CTX *mem_ctx,
}
static WERROR rpc_get_subkey_by_index(TALLOC_CTX *mem_ctx,
const struct registry_key *parent,
uint32_t n,
const char **name,
const char **keyclass,
NTTIME *last_changed_time)
const struct registry_key *parent,
uint32_t n,
const char **name,
const char **keyclass,
NTTIME *last_changed_time)
{
struct winreg_EnumKey r;
struct rpc_key *mykeydata = talloc_get_type(parent, struct rpc_key);
@ -242,7 +244,7 @@ static WERROR rpc_get_subkey_by_index(TALLOC_CTX *mem_ctx,
r.out.name = &namebuf;
status = dcerpc_winreg_EnumKey(mykeydata->pipe, mem_ctx, &r);
if(NT_STATUS_IS_OK(status) && W_ERROR_IS_OK(r.out.result)) {
if (NT_STATUS_IS_OK(status) && W_ERROR_IS_OK(r.out.result)) {
*name = talloc_strdup(mem_ctx, r.out.name->name);
*keyclass = talloc_strdup(mem_ctx, r.out.keyclass->name);
*last_changed_time = *r.out.last_changed_time;
@ -252,10 +254,10 @@ static WERROR rpc_get_subkey_by_index(TALLOC_CTX *mem_ctx,
}
static WERROR rpc_add_key(TALLOC_CTX *mem_ctx,
struct registry_key *parent, const char *name,
const char *key_class,
struct security_descriptor *sec,
struct registry_key **key)
struct registry_key *parent, const char *name,
const char *key_class,
struct security_descriptor *sec,
struct registry_key **key)
{
NTSTATUS status;
struct winreg_CreateKey r;
@ -273,11 +275,11 @@ static WERROR rpc_add_key(TALLOC_CTX *mem_ctx,
status = dcerpc_winreg_CreateKey(parentkd->pipe, mem_ctx, &r);
if (!NT_STATUS_IS_OK(status)) {
if (!NT_STATUS_IS_OK(status)) {
talloc_free(rpck);
DEBUG(1, ("CreateKey failed - %s\n", nt_errstr(status)));
return ntstatus_to_werror(status);
}
DEBUG(1, ("CreateKey failed - %s\n", nt_errstr(status)));
return ntstatus_to_werror(status);
}
if (W_ERROR_IS_OK(r.out.result)) {
rpck->pipe = talloc_reference(rpck, parentkd->pipe);
@ -289,24 +291,24 @@ static WERROR rpc_add_key(TALLOC_CTX *mem_ctx,
static WERROR rpc_query_key(const struct registry_key *k)
{
NTSTATUS status;
struct winreg_QueryInfoKey r;
struct rpc_key *mykeydata = talloc_get_type(k, struct rpc_key);
NTSTATUS status;
struct winreg_QueryInfoKey r;
struct rpc_key *mykeydata = talloc_get_type(k, struct rpc_key);
TALLOC_CTX *mem_ctx = talloc_init("query_key");
r.in.classname = talloc(mem_ctx, struct winreg_String);
init_winreg_String(r.in.classname, NULL);
r.in.handle = &mykeydata->pol;
init_winreg_String(r.in.classname, NULL);
r.in.handle = &mykeydata->pol;
status = dcerpc_winreg_QueryInfoKey(mykeydata->pipe, mem_ctx, &r);
status = dcerpc_winreg_QueryInfoKey(mykeydata->pipe, mem_ctx, &r);
talloc_free(mem_ctx);
if (!NT_STATUS_IS_OK(status)) {
DEBUG(1, ("QueryInfoKey failed - %s\n", nt_errstr(status)));
return ntstatus_to_werror(status);
}
if (!NT_STATUS_IS_OK(status)) {
DEBUG(1, ("QueryInfoKey failed - %s\n", nt_errstr(status)));
return ntstatus_to_werror(status);
}
if (W_ERROR_IS_OK(r.out.result)) {
if (W_ERROR_IS_OK(r.out.result)) {
mykeydata->num_subkeys = *r.out.num_subkeys;
mykeydata->num_values = *r.out.num_values;
mykeydata->max_valnamelen = *r.out.max_valnamelen;
@ -323,10 +325,10 @@ static WERROR rpc_del_key(struct registry_key *parent, const char *name)
struct winreg_DeleteKey r;
TALLOC_CTX *mem_ctx = talloc_init("del_key");
r.in.handle = &mykeydata->pol;
init_winreg_String(&r.in.key, name);
r.in.handle = &mykeydata->pol;
init_winreg_String(&r.in.key, name);
status = dcerpc_winreg_DeleteKey(mykeydata->pipe, mem_ctx, &r);
status = dcerpc_winreg_DeleteKey(mykeydata->pipe, mem_ctx, &r);
talloc_free(mem_ctx);
@ -342,7 +344,7 @@ static WERROR rpc_get_info(TALLOC_CTX *mem_ctx, const struct registry_key *key,
struct rpc_key *mykeydata = talloc_get_type(key, struct rpc_key);
WERROR error;
if(mykeydata->num_values == -1) {
if (mykeydata->num_values == -1) {
error = rpc_query_key(key);
if(!W_ERROR_IS_OK(error)) return error;
}
@ -371,9 +373,9 @@ static struct registry_operations reg_backend_rpc = {
};
_PUBLIC_ WERROR reg_open_remote(struct registry_context **ctx,
struct auth_session_info *session_info,
struct cli_credentials *credentials,
const char *location, struct event_context *ev)
struct auth_session_info *session_info,
struct cli_credentials *credentials,
const char *location, struct event_context *ev)
{
NTSTATUS status;
struct dcerpc_pipe *p;
@ -395,7 +397,8 @@ _PUBLIC_ WERROR reg_open_remote(struct registry_context **ctx,
rctx->pipe = p;
if(NT_STATUS_IS_ERR(status)) {
DEBUG(1, ("Unable to open '%s': %s\n", location, nt_errstr(status)));
DEBUG(1, ("Unable to open '%s': %s\n", location,
nt_errstr(status)));
talloc_free(*ctx);
*ctx = NULL;
return ntstatus_to_werror(status);

View File

@ -35,13 +35,15 @@ static WERROR mount_samba_hive(struct registry_context *ctx,
struct hive_key *hive;
const char *location;
location = talloc_asprintf(ctx, "%s/%s.ldb", lp_private_dir(global_loadparm), name);
location = talloc_asprintf(ctx, "%s/%s.ldb",
lp_private_dir(global_loadparm),
name);
error = reg_open_hive(ctx, location, auth_info, creds, &hive);
if (W_ERROR_EQUAL(error, WERR_NOT_FOUND))
error = reg_open_ldb_file(ctx, location, auth_info, creds, &hive);
error = reg_open_ldb_file(ctx, location, auth_info,
creds, &hive);
if (!W_ERROR_IS_OK(error))
return error;
@ -50,10 +52,10 @@ static WERROR mount_samba_hive(struct registry_context *ctx,
}
_PUBLIC_ WERROR reg_open_samba (TALLOC_CTX *mem_ctx,
struct registry_context **ctx,
struct auth_session_info *session_info,
struct cli_credentials *credentials)
_PUBLIC_ WERROR reg_open_samba(TALLOC_CTX *mem_ctx,
struct registry_context **ctx,
struct auth_session_info *session_info,
struct cli_credentials *credentials)
{
WERROR result;
@ -63,18 +65,18 @@ _PUBLIC_ WERROR reg_open_samba (TALLOC_CTX *mem_ctx,
}
mount_samba_hive(*ctx, session_info, credentials,
"hklm", HKEY_LOCAL_MACHINE);
"hklm", HKEY_LOCAL_MACHINE);
mount_samba_hive(*ctx, session_info, credentials,
"hkcr", HKEY_CLASSES_ROOT);
"hkcr", HKEY_CLASSES_ROOT);
/* FIXME: Should be mounted from NTUSER.DAT in the home directory of the
* current user */
mount_samba_hive(*ctx, session_info, credentials,
"hkcu", HKEY_CURRENT_USER);
"hkcu", HKEY_CURRENT_USER);
mount_samba_hive(*ctx, session_info, credentials,
"hku", HKEY_USERS);
"hku", HKEY_USERS);
/* FIXME: Different hive backend for HKEY_CLASSES_ROOT: merged view of HKEY_LOCAL_MACHINE\Software\Classes
* and HKEY_CURRENT_USER\Software\Classes */

View File

@ -53,50 +53,49 @@ _PUBLIC_ const char *str_regtype(int type)
_PUBLIC_ char *reg_val_data_string(TALLOC_CTX *mem_ctx, uint32_t type,
const DATA_BLOB data)
{
char *ret = NULL;
char *ret = NULL;
if (data.length == 0)
return talloc_strdup(mem_ctx, "");
if (data.length == 0)
return talloc_strdup(mem_ctx, "");
switch (type) {
case REG_EXPAND_SZ:
case REG_SZ:
convert_string_talloc(mem_ctx, CH_UTF16, CH_UNIX, data.data, data.length,
(void **)&ret);
return ret;
switch (type) {
case REG_EXPAND_SZ:
case REG_SZ:
convert_string_talloc(mem_ctx, CH_UTF16, CH_UNIX,
data.data, data.length,
(void **)&ret);
return ret;
case REG_BINARY:
ret = data_blob_hex_string(mem_ctx, &data);
return ret;
case REG_DWORD:
if (*(int *)data.data == 0)
return talloc_strdup(mem_ctx, "0");
return talloc_asprintf(mem_ctx, "0x%x",
*(int *)data.data);
case REG_MULTI_SZ:
/* FIXME */
break;
default:
break;
}
case REG_BINARY:
ret = data_blob_hex_string(mem_ctx, &data);
return ret;
case REG_DWORD:
if (*(int *)data.data == 0)
return talloc_strdup(mem_ctx, "0");
return talloc_asprintf(mem_ctx, "0x%x", *(int *)data.data);
case REG_MULTI_SZ:
/* FIXME */
break;
default:
break;
}
return ret;
return ret;
}
/** Generate a string that describes a registry value */
_PUBLIC_ char *reg_val_description(TALLOC_CTX *mem_ctx, const char *name,
uint32_t data_type,
const DATA_BLOB data)
uint32_t data_type,
const DATA_BLOB data)
{
return talloc_asprintf(mem_ctx, "%s = %s : %s", name?name:"<No Name>",
str_regtype(data_type),
reg_val_data_string(mem_ctx, data_type, data));
str_regtype(data_type),
reg_val_data_string(mem_ctx, data_type, data));
}
_PUBLIC_ bool reg_string_to_val(TALLOC_CTX *mem_ctx, const char *type_str, const char *data_str, uint32_t *type, DATA_BLOB *data)
_PUBLIC_ bool reg_string_to_val(TALLOC_CTX *mem_ctx, const char *type_str,
const char *data_str, uint32_t *type,
DATA_BLOB *data)
{
int i;
*type = -1;
@ -118,7 +117,9 @@ _PUBLIC_ bool reg_string_to_val(TALLOC_CTX *mem_ctx, const char *type_str, const
{
case REG_SZ:
case REG_EXPAND_SZ:
data->length = convert_string_talloc(mem_ctx, CH_UNIX, CH_UTF16, data_str, strlen(data_str), (void **)&data->data);
data->length = convert_string_talloc(mem_ctx, CH_UNIX, CH_UTF16,
data_str, strlen(data_str),
(void **)&data->data);
break;
case REG_DWORD: {
@ -144,7 +145,8 @@ _PUBLIC_ bool reg_string_to_val(TALLOC_CTX *mem_ctx, const char *type_str, const
}
/** Open a key by name (including the predefined key name!) */
WERROR reg_open_key_abs(TALLOC_CTX *mem_ctx, struct registry_context *handle, const char *name, struct registry_key **result)
WERROR reg_open_key_abs(TALLOC_CTX *mem_ctx, struct registry_context *handle,
const char *name, struct registry_key **result)
{
struct registry_key *predef;
WERROR error;
@ -165,7 +167,8 @@ WERROR reg_open_key_abs(TALLOC_CTX *mem_ctx, struct registry_context *handle, co
}
if (strchr(name, '\\')) {
return reg_open_key(mem_ctx, predef, strchr(name, '\\')+1, result);
return reg_open_key(mem_ctx, predef, strchr(name, '\\')+1,
result);
} else {
*result = predef;
return WERR_OK;
@ -173,8 +176,8 @@ WERROR reg_open_key_abs(TALLOC_CTX *mem_ctx, struct registry_context *handle, co
}
static WERROR get_abs_parent(TALLOC_CTX *mem_ctx, struct registry_context *ctx,
const char *path, struct registry_key **parent,
const char **name)
const char *path, struct registry_key **parent,
const char **name)
{
char *parent_name;
WERROR error;
@ -217,9 +220,9 @@ WERROR reg_key_del_abs(struct registry_context *ctx, const char *path)
}
WERROR reg_key_add_abs(TALLOC_CTX *mem_ctx, struct registry_context *ctx,
const char *path, uint32_t access_mask,
struct security_descriptor *sec_desc,
struct registry_key **result)
const char *path, uint32_t access_mask,
struct security_descriptor *sec_desc,
struct registry_key **result)
{
struct registry_key *parent;
const char *n;