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

@ -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);
@ -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,7 +234,7 @@ 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,
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);
@ -245,7 +248,7 @@ 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,
static WERROR reg_dir_get_value(TALLOC_CTX *mem_ctx,
struct hive_key *key, const char *name,
uint32_t *type, DATA_BLOB *data)
{
@ -268,7 +271,7 @@ static WERROR reg_dir_get_value (TALLOC_CTX *mem_ctx,
return WERR_OK;
}
static WERROR reg_dir_enum_value (TALLOC_CTX *mem_ctx,
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)
@ -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

@ -54,13 +54,15 @@ _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,
_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)
@ -69,13 +71,16 @@ _PUBLIC_ WERROR hive_key_get_info(TALLOC_CTX *mem_ctx, const struct hive_key *ke
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,
_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,7 +89,8 @@ _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,
const struct hive_key *key,
const char *name,
struct hive_key **subkey)
{
return key->ops->get_key_by_name(mem_ctx, key, name, subkey);
@ -109,7 +115,7 @@ 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,
WERROR hive_get_value(TALLOC_CTX *mem_ctx,
struct hive_key *key, const char *name,
uint32_t *type, DATA_BLOB *data)
{
@ -119,8 +125,9 @@ 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,
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)
@ -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

@ -64,7 +64,8 @@ struct hive_operations {
*/
WERROR (*add_key) (TALLOC_CTX *ctx,
const struct hive_key *parent_key, const char *name,
const char *classname, struct security_descriptor *desc,
const char *classname,
struct security_descriptor *desc,
struct hive_key **key);
/**
* Remove an existing key.
@ -148,7 +149,8 @@ WERROR hive_key_get_info(TALLOC_CTX *mem_ctx, const struct hive_key *key,
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,
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,
@ -160,17 +162,18 @@ WERROR hive_enum_key(TALLOC_CTX *mem_ctx,
const char **classname,
NTTIME *last_mod_time);
WERROR hive_set_value (struct hive_key *key, const char *name,
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,
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,
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);

View File

@ -63,7 +63,8 @@ _PUBLIC_ WERROR reg_get_predefined_key_by_name(struct registry_context *ctx,
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,
return reg_get_predefined_key(ctx,
reg_predefined_keys[i].handle,
key);
}
@ -88,7 +89,8 @@ _PUBLIC_ WERROR reg_open_key(TALLOC_CTX *mem_ctx, struct registry_key *parent,
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,8 +116,8 @@ _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);
}
/**
@ -143,8 +145,10 @@ _PUBLIC_ WERROR reg_key_get_info(TALLOC_CTX *mem_ctx,
* 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;

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,7 +72,8 @@ 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,
TALLOC_CTX *mem_ctx,
const char *name,
uint32_t type, DATA_BLOB data)
{
struct ldb_val val;
@ -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);
@ -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;
@ -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,7 +260,8 @@ 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);
@ -256,7 +270,8 @@ static WERROR ldb_get_value_by_id(TALLOC_CTX *mem_ctx, const struct hive_key *k,
}
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;
}
@ -300,7 +316,8 @@ static WERROR ldb_open_key(TALLOC_CTX *mem_ctx, const struct hive_key *h,
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,7 +366,7 @@ 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,
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)
@ -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);

View File

@ -77,7 +77,8 @@ static WERROR local_open_key(TALLOC_CTX *mem_ctx,
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;
@ -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;
}
@ -123,7 +126,7 @@ static WERROR local_open_key(TALLOC_CTX *mem_ctx,
return WERR_OK;
}
WERROR local_get_predefined_key (const struct registry_context *ctx,
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,
@ -158,7 +161,7 @@ static WERROR local_enum_key(TALLOC_CTX *mem_ctx,
last_changed_time);
}
static WERROR local_create_key (TALLOC_CTX *mem_ctx,
static WERROR local_create_key(TALLOC_CTX *mem_ctx,
struct registry_key *parent_key,
const char *name,
const char *key_class,
@ -183,7 +186,8 @@ static WERROR local_create_key (TALLOC_CTX *mem_ctx,
}
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 *,
@ -207,7 +211,7 @@ static WERROR local_create_key (TALLOC_CTX *mem_ctx,
return WERR_OK;
}
static WERROR local_set_value (struct registry_key *key, const char *name,
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;
@ -215,7 +219,7 @@ static WERROR local_set_value (struct registry_key *key, const char *name,
return hive_set_value(local->hive_key, name, type, data);
}
static WERROR local_get_value (TALLOC_CTX *mem_ctx,
static WERROR local_get_value(TALLOC_CTX *mem_ctx,
const struct registry_key *key,
const char *name, uint32_t *type, DATA_BLOB *data)
{
@ -224,7 +228,7 @@ static WERROR local_get_value (TALLOC_CTX *mem_ctx,
return hive_get_value(mem_ctx, local->hive_key, name, type, data);
}
static WERROR local_enum_value (TALLOC_CTX *mem_ctx,
static WERROR local_enum_value(TALLOC_CTX *mem_ctx,
const struct registry_key *key, uint32_t idx,
const char **name,
uint32_t *type,
@ -236,28 +240,28 @@ static WERROR local_enum_value (TALLOC_CTX *mem_ctx,
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,
static WERROR local_get_key_info(TALLOC_CTX *mem_ctx,
const struct registry_key *key,
const char **classname,
uint32_t *num_subkeys,
@ -290,7 +294,8 @@ WERROR reg_open_local(TALLOC_CTX *mem_ctx, struct registry_context **ctx,
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);
@ -308,7 +313,8 @@ WERROR reg_mount_hive(struct registry_context *rctx,
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;

View File

@ -25,9 +25,13 @@
#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
@ -48,7 +52,8 @@ 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,
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",
@ -62,7 +67,8 @@ 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,
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",
@ -94,7 +100,8 @@ 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,
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",
@ -108,7 +115,8 @@ 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,
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",
@ -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);
}
@ -161,8 +170,9 @@ WERROR reg_generate_diff_key(struct registry_key *oldkey,
}
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;
@ -174,10 +184,12 @@ WERROR reg_generate_diff_key(struct registry_key *oldkey,
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 */
@ -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;
@ -395,7 +420,8 @@ static WERROR reg_diff_apply_del_all_values(void *_ctx, const char *key_name)
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,
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,8 +27,10 @@
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);
@ -42,7 +44,8 @@ WERROR reg_generate_diff(struct registry_context *ctx1,
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,

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

@ -128,7 +128,7 @@ 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,
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;
}
@ -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 */
@ -318,7 +325,8 @@ static uint32_t hbin_store_resize(struct regf_data *data,
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,7 +386,8 @@ 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,
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);
@ -409,7 +420,7 @@ static uint32_t regf_create_lh_hash(const char *name)
return ret;
}
static WERROR regf_get_info (TALLOC_CTX *mem_ctx,
static WERROR regf_get_info(TALLOC_CTX *mem_ctx,
const struct hive_key *key,
const char **classname,
uint32_t *num_subkeys,
@ -430,7 +441,8 @@ static WERROR regf_get_info (TALLOC_CTX *mem_ctx,
DATA_BLOB data = hbin_get(private_data->hive,
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;
}
@ -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;
}
@ -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,7 +545,7 @@ 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,
static WERROR regf_get_value_by_name(TALLOC_CTX *mem_ctx,
struct hive_key *key, const char *name,
uint32_t *type, DATA_BLOB *data)
{
@ -542,7 +556,8 @@ 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;
}
@ -554,7 +569,7 @@ static WERROR regf_get_value_by_name (TALLOC_CTX *mem_ctx,
}
static WERROR regf_get_subkey_by_index (TALLOC_CTX *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,
@ -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;
}
@ -726,7 +745,8 @@ static WERROR regf_get_subkey_by_index (TALLOC_CTX *ctx,
DATA_BLOB db = hbin_get(ret->hive,
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,7 +763,8 @@ 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 struct hive_key *key,
uint32_t offset,
const char *name, uint32_t *ret)
{
DATA_BLOB subkey_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,11 +999,12 @@ 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,
static WERROR regf_set_sec_desc(struct hive_key *key,
const struct security_descriptor *sec_desc)
{
const struct regf_key_data *private_data =
@ -993,7 +1034,8 @@ static WERROR regf_set_sec_desc (struct hive_key *key,
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;
}
@ -1007,16 +1049,19 @@ static WERROR regf_set_sec_desc (struct hive_key *key,
}
/* 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,30 +1112,40 @@ 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;
}
@ -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)) {
@ -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);
}
@ -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;
@ -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;
}
@ -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);
@ -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,14 +1999,16 @@ 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;
}

View File

@ -168,12 +168,12 @@ struct event_context;
/**
* Open the locally defined registry.
*/
WERROR reg_open_local (TALLOC_CTX *mem_ctx,
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,
WERROR reg_open_samba(TALLOC_CTX *mem_ctx,
struct registry_context **ctx,
struct auth_session_info *session_info,
struct cli_credentials *credentials);
@ -233,12 +233,12 @@ WERROR reg_key_add_name(TALLOC_CTX *mem_ctx,
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);
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,
WERROR reg_create_key(TALLOC_CTX *mem_ctx,
struct registry_key *parent,
const char *name,
const char *key_class,
struct security_descriptor *security,
@ -253,10 +253,15 @@ char *reg_val_data_string(TALLOC_CTX *mem_ctx, uint32_t type,
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);
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);

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 },
@ -135,7 +136,8 @@ static WERROR rpc_key_put_rpc_data(TALLOC_CTX *mem_ctx, struct registry_key *k)
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;
}
@ -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;
@ -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;
}
@ -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,7 +52,7 @@ static WERROR mount_samba_hive(struct registry_context *ctx,
}
_PUBLIC_ WERROR reg_open_samba (TALLOC_CTX *mem_ctx,
_PUBLIC_ WERROR reg_open_samba(TALLOC_CTX *mem_ctx,
struct registry_context **ctx,
struct auth_session_info *session_info,
struct cli_credentials *credentials)

View File

@ -61,24 +61,21 @@ _PUBLIC_ char *reg_val_data_string(TALLOC_CTX *mem_ctx, uint32_t type,
switch (type) {
case REG_EXPAND_SZ:
case REG_SZ:
convert_string_talloc(mem_ctx, CH_UTF16, CH_UNIX, data.data, data.length,
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);
return talloc_asprintf(mem_ctx, "0x%x",
*(int *)data.data);
case REG_MULTI_SZ:
/* FIXME */
break;
default:
break;
}
@ -96,7 +93,9 @@ _PUBLIC_ char *reg_val_description(TALLOC_CTX *mem_ctx, const char *name,
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;