1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-22 13:34:15 +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,18 +1,18 @@
/*
/*
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
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
@ -29,11 +29,11 @@ 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)
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)
{
struct dir_key *dk = talloc_get_type(parent, struct dir_key);
char *path;
@ -61,8 +61,8 @@ static WERROR reg_dir_del_key(const struct hive_key *k, const char *name)
char *child = talloc_asprintf(NULL, "%s/%s", dk->path, name);
WERROR ret;
if (rmdir(child) == 0)
ret = WERR_OK;
if (rmdir(child) == 0)
ret = WERR_OK;
else if (errno == ENOENT)
ret = WERR_NOT_FOUND;
else
@ -73,25 +73,26 @@ static WERROR reg_dir_del_key(const struct hive_key *k, const char *name)
return ret;
}
static WERROR reg_dir_open_key(TALLOC_CTX *mem_ctx,
const struct hive_key *parent,
const char *name, struct hive_key **subkey)
static WERROR reg_dir_open_key(TALLOC_CTX *mem_ctx,
const struct hive_key *parent,
const char *name, struct hive_key **subkey)
{
DIR *d;
char *fullpath;
const struct dir_key *p = talloc_get_type(parent, struct dir_key);
struct dir_key *ret;
if (name == NULL) {
DEBUG(0, ("NULL pointer passed as directory name!"));
return WERR_INVALID_PARAM;
}
fullpath = talloc_asprintf(mem_ctx, "%s/%s", p->path, name);
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);
@ -102,11 +103,11 @@ static WERROR reg_dir_open_key(TALLOC_CTX *mem_ctx,
return WERR_OK;
}
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)
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)
{
struct dirent *e;
const struct dir_key *dk = talloc_get_type(k, struct dir_key);
@ -115,14 +116,14 @@ static WERROR reg_dir_key_by_index(TALLOC_CTX *mem_ctx,
d = opendir(dk->path);
if (d == NULL)
if (d == NULL)
return WERR_INVALID_PARAM;
while((e = readdir(d))) {
if(!ISDOT(e->d_name) && !ISDOTDOT(e->d_name)) {
struct stat stbuf;
char *thispath;
/* Check if file is a directory */
asprintf(&thispath, "%s/%s", dk->path, e->d_name);
stat(thispath, &stbuf);
@ -153,12 +154,12 @@ static WERROR reg_dir_key_by_index(TALLOC_CTX *mem_ctx,
return WERR_NO_MORE_ITEMS;
}
WERROR reg_open_directory(TALLOC_CTX *parent_ctx,
const char *location, struct hive_key **key)
WERROR reg_open_directory(TALLOC_CTX *parent_ctx,
const char *location, struct hive_key **key)
{
struct dir_key *dk;
if (location == NULL)
if (location == NULL)
return WERR_INVALID_PARAM;
dk = talloc(parent_ctx, struct dir_key);
@ -168,8 +169,8 @@ WERROR reg_open_directory(TALLOC_CTX *parent_ctx,
return WERR_OK;
}
WERROR reg_create_directory(TALLOC_CTX *parent_ctx,
const char *location, struct hive_key **key)
WERROR reg_create_directory(TALLOC_CTX *parent_ctx,
const char *location, struct hive_key **key)
{
if (mkdir(location, 0700) != 0) {
*key = NULL;
@ -179,11 +180,11 @@ WERROR reg_create_directory(TALLOC_CTX *parent_ctx,
return reg_open_directory(parent_ctx, location, key);
}
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)
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)
{
DIR *d;
const struct dir_key *dk = talloc_get_type(key, struct dir_key);
@ -196,7 +197,7 @@ static WERROR reg_dir_get_info(TALLOC_CTX *ctx, const struct hive_key *key,
*classname = NULL;
d = opendir(dk->path);
if (d == NULL)
if (d == NULL)
return WERR_INVALID_PARAM;
if (num_subkeys != NULL)
@ -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);
@ -256,7 +259,7 @@ static WERROR reg_dir_get_value (TALLOC_CTX *mem_ctx,
contents = file_load(path, &size, mem_ctx);
talloc_free(path);
if (contents == NULL)
if (contents == NULL)
return WERR_NOT_FOUND;
if (type != NULL)
@ -267,11 +270,11 @@ 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,19 +283,22 @@ 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;
}
i = 0;
while((e = readdir(d))) {
if (ISDOT(e->d_name) || ISDOTDOT(e->d_name))
if (ISDOT(e->d_name) || ISDOTDOT(e->d_name))
continue;
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;
}
@ -315,7 +321,7 @@ static WERROR reg_dir_del_value (struct hive_key *key, const char *name)
return WERR_GENERAL_FAILURE;
}
talloc_free(path);
return WERR_OK;
}

View File

@ -1,19 +1,19 @@
/*
/*
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
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
@ -24,10 +24,10 @@
#include "system/filesys.h"
/** 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)
_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)
{
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);
return key->ops->get_key_info(mem_ctx, key, classname, num_subkeys,
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);
return key->ops->enum_key(mem_ctx, key, idx, name, classname,
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

@ -1,18 +1,18 @@
/*
/*
Unix SMB/CIFS implementation.
Registry hive interface
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
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
@ -26,13 +26,13 @@
#include "libcli/util/ntstatus.h"
/**
* This file contains the hive API. This API is generally used for
* reading a specific file that contains just one hive.
* This file contains the hive API. This API is generally used for
* reading a specific file that contains just one hive.
*
* Good examples are .DAT (NTUSER.DAT) files.
*
* This API does not have any notification support (that
* should be provided by the registry implementation), nor
* This API does not have any notification support (that
* should be provided by the registry implementation), nor
* does it understand what predefined keys are.
*/
@ -41,31 +41,32 @@ struct hive_key {
};
struct hive_operations {
const char *name;
const char *name;
/**
* 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);
WERROR (*get_value_by_name) (TALLOC_CTX *mem_ctx,
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);
WERROR (*set_value) (struct hive_key *key, const char *name,
uint32_t type, const DATA_BLOB data);
/**
* Remove a value.
@ -107,91 +108,93 @@ struct hive_operations {
/**
* Change the security descriptor on a registry key.
*
* This should return WERR_NOT_SUPPORTED if the underlying
* format does not have a mechanism for storing
* This should return WERR_NOT_SUPPORTED if the underlying
* format does not have a mechanism for storing
* security descriptors.
*/
WERROR (*set_sec_desc) (struct hive_key *key,
const struct security_descriptor *desc);
WERROR (*set_sec_desc) (struct hive_key *key,
const struct security_descriptor *desc);
/**
* Retrieve the security descriptor on a registry key.
*
* This should return WERR_NOT_SUPPORTED if the underlying
* format does not have a mechanism for storing
* This should return WERR_NOT_SUPPORTED if the underlying
* format does not have a mechanism for storing
* 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);
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);
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);
WERROR reg_open_regf_file(TALLOC_CTX *parent_ctx,
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);
WERROR reg_open_directory(TALLOC_CTX *parent_ctx,
const char *location, struct hive_key **key);
WERROR reg_open_regf_file(TALLOC_CTX *parent_ctx,
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);
WERROR reg_create_directory(TALLOC_CTX *parent_ctx,
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);
WERROR reg_create_directory(TALLOC_CTX *parent_ctx,
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);
#endif /* __REGISTRY_HIVE_H__ */

View File

@ -1,4 +1,4 @@
/*
/*
Unix SMB/CIFS implementation.
Transparent registry backend handling
Copyright (C) Jelmer Vernooij 2003-2007.
@ -47,7 +47,7 @@ _PUBLIC_ const char *reg_get_predef_name(uint32_t hkey)
{
int i;
for (i = 0; reg_predefined_keys[i].name; i++) {
if (reg_predefined_keys[i].handle == hkey)
if (reg_predefined_keys[i].handle == hkey)
return reg_predefined_keys[i].name;
}
@ -55,40 +55,42 @@ _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)
_PUBLIC_ WERROR reg_get_predefined_key_by_name(struct registry_context *ctx,
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);
if (!strcasecmp(reg_predefined_keys[i].name, name))
return reg_get_predefined_key(ctx,
reg_predefined_keys[i].handle,
key);
}
DEBUG(1, ("No predefined key with name '%s'\n", name));
return WERR_BADFILE;
}
/** Get predefined key by id. */
_PUBLIC_ WERROR reg_get_predefined_key(const struct registry_context *ctx,
uint32_t hkey, struct registry_key **key)
_PUBLIC_ WERROR reg_get_predefined_key(const struct registry_context *ctx,
uint32_t hkey, struct registry_key **key)
{
return ctx->ops->get_predefined_key(ctx, hkey, key);
}
/**
* Open a key
* Open a key
* First tries to use the open_key function from the backend
* then falls back to get_subkey_by_name and later get_subkey_by_index
* 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)
_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;
}
@ -103,69 +105,71 @@ _PUBLIC_ WERROR reg_open_key(TALLOC_CTX *mem_ctx, struct registry_key *parent,
/**
* Get value by index
*/
_PUBLIC_ WERROR reg_key_get_value_by_index(TALLOC_CTX *mem_ctx,
const struct registry_key *key,
_PUBLIC_ 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)
{
if (key == NULL)
if (key == NULL)
return WERR_INVALID_PARAM;
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)
_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)
{
if (key == NULL)
if (key == NULL)
return WERR_INVALID_PARAM;
if (key->context->ops->get_key_info == NULL)
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)
_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)
{
if (key == NULL)
if (key == NULL)
return WERR_INVALID_PARAM;
if (key->context->ops->enum_key == NULL)
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)
_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)
{
if (key == NULL)
if (key == NULL)
return WERR_INVALID_PARAM;
if (key->context->ops->get_value == NULL)
@ -179,49 +183,49 @@ _PUBLIC_ WERROR reg_key_get_value_by_name(TALLOC_CTX *mem_ctx,
*/
_PUBLIC_ WERROR reg_key_del(struct registry_key *parent, const char *name)
{
if (parent == NULL)
if (parent == NULL)
return WERR_INVALID_PARAM;
if (parent->context->ops->delete_key == NULL)
return WERR_NOT_SUPPORTED;
return parent->context->ops->delete_key(parent, 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)
_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)
{
if (parent == NULL)
if (parent == NULL)
return WERR_INVALID_PARAM;
if (parent->context->ops->create_key == NULL) {
DEBUG(1, ("Backend '%s' doesn't support method add_key\n",
DEBUG(1, ("Backend '%s' doesn't support method add_key\n",
parent->context->ops->name));
return WERR_NOT_SUPPORTED;
}
return parent->context->ops->create_key(mem_ctx, parent, name,
key_class, desc, newkey);
return parent->context->ops->create_key(mem_ctx, parent, name,
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)
_PUBLIC_ WERROR reg_val_set(struct registry_key *key, const char *value,
uint32_t type, const DATA_BLOB data)
{
if (key == NULL)
return WERR_INVALID_PARAM;
/* A 'real' set function has preference */
if (key->context->ops->set_value == NULL) {
DEBUG(1, ("Backend '%s' doesn't support method set_value\n",
DEBUG(1, ("Backend '%s' doesn't support method set_value\n",
key->context->ops->name));
return WERR_NOT_SUPPORTED;
}
@ -232,15 +236,15 @@ _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)
_PUBLIC_ WERROR reg_get_sec_desc(TALLOC_CTX *ctx,
const struct registry_key *key,
struct security_descriptor **secdesc)
{
if (key == NULL)
return WERR_INVALID_PARAM;
/* A 'real' set function has preference */
if (key->context->ops->get_security == NULL)
if (key->context->ops->get_security == NULL)
return WERR_NOT_SUPPORTED;
return key->context->ops->get_security(ctx, key, secdesc);
@ -267,32 +271,32 @@ _PUBLIC_ WERROR reg_key_flush(struct registry_key *key)
{
if (key == NULL)
return WERR_INVALID_PARAM;
if (key->context->ops->flush_key == NULL)
return WERR_NOT_SUPPORTED;
return key->context->ops->flush_key(key);
}
_PUBLIC_ WERROR reg_get_security(TALLOC_CTX *mem_ctx,
const struct registry_key *key,
struct security_descriptor **security)
_PUBLIC_ WERROR reg_get_security(TALLOC_CTX *mem_ctx,
const struct registry_key *key,
struct security_descriptor **security)
{
if (key == NULL)
return WERR_INVALID_PARAM;
if (key->context->ops->get_security == NULL)
return WERR_NOT_SUPPORTED;
return key->context->ops->get_security(mem_ctx, key, security);
}
_PUBLIC_ WERROR reg_set_security(struct registry_key *key,
struct security_descriptor *security)
_PUBLIC_ WERROR reg_set_security(struct registry_key *key,
struct security_descriptor *security)
{
if (key == NULL)
return WERR_INVALID_PARAM;
if (key->context->ops->set_security == NULL)
return WERR_NOT_SUPPORTED;

View File

@ -1,18 +1,18 @@
/*
/*
Unix SMB/CIFS implementation.
Registry interface
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
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
@ -27,7 +27,7 @@
static struct hive_operations reg_backend_ldb;
struct ldb_key_data
struct ldb_key_data
{
struct hive_key key;
struct ldb_context *ldb;
@ -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);
@ -51,8 +54,9 @@ 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);
data->length = convert_string_talloc(mem_ctx, CH_UTF8, CH_UTF16,
val->data, val->length,
(void **)&data->data);
break;
case REG_DWORD: {
@ -67,9 +71,10 @@ 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)
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)
{
struct ldb_val val;
struct ldb_message *msg = talloc_zero(mem_ctx, struct ldb_message);
@ -80,13 +85,17 @@ static struct ldb_message *reg_ldb_pack_value(struct ldb_context *ctx,
switch (type) {
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);
val.length = convert_string_talloc(mem_ctx, CH_UTF16, CH_UTF8,
(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);
@ -94,7 +103,7 @@ static struct ldb_message *reg_ldb_pack_value(struct ldb_context *ctx,
type_s = talloc_asprintf(mem_ctx, "%u", type);
ldb_msg_add_string(msg, "type", type_s);
ldb_msg_add_string(msg, "type", type_s);
return msg;
}
@ -103,20 +112,20 @@ static struct ldb_message *reg_ldb_pack_value(struct ldb_context *ctx,
static int reg_close_ldb_key(struct ldb_key_data *key)
{
if (key->subkeys != NULL) {
talloc_free(key->subkeys);
talloc_free(key->subkeys);
key->subkeys = NULL;
}
if (key->values != NULL) {
talloc_free(key->values);
talloc_free(key->values);
key->values = NULL;
}
return 0;
}
static struct ldb_dn *reg_path_to_ldb(TALLOC_CTX *mem_ctx,
const struct hive_key *from,
const char *path, const char *add)
static struct ldb_dn *reg_path_to_ldb(TALLOC_CTX *mem_ctx,
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;
@ -203,11 +215,11 @@ 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)
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)
{
struct ldb_message_element *el;
struct ldb_key_data *kd = talloc_get_type(k, struct ldb_key_data);
@ -215,21 +227,21 @@ static WERROR ldb_get_subkey_by_id(TALLOC_CTX *mem_ctx,
/* Do a search if necessary */
if (kd->subkeys == NULL) {
W_ERROR_NOT_OK_RETURN(cache_subkeys(kd));
}
}
if (idx >= kd->subkey_count)
if (idx >= kd->subkey_count)
return WERR_NO_MORE_ITEMS;
el = ldb_msg_find_element(kd->subkeys[idx], "key");
SMB_ASSERT(el != NULL);
SMB_ASSERT(el->num_values != 0);
if (name != NULL)
*name = talloc_strdup(mem_ctx, (char *)el->values[0].data);
if (classname != NULL)
*classname = NULL; /* TODO: Store properly */
if (last_mod_time != NULL)
*last_mod_time = 0; /* TODO: we need to add this to the
ldb backend properly */
@ -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);
reg_ldb_unpack_value(mem_ctx, kd->values[idx],
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)
static WERROR ldb_get_value(TALLOC_CTX *mem_ctx, struct hive_key *k,
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;
}
@ -281,8 +297,8 @@ static WERROR ldb_get_value(TALLOC_CTX *mem_ctx, struct hive_key *k,
return WERR_OK;
}
static WERROR ldb_open_key(TALLOC_CTX *mem_ctx, const struct hive_key *h,
const char *name, struct hive_key **key)
static WERROR ldb_open_key(TALLOC_CTX *mem_ctx, const struct hive_key *h,
const char *name, struct hive_key **key)
{
struct ldb_result *res;
struct ldb_dn *ldap_path;
@ -296,11 +312,12 @@ static WERROR ldb_open_key(TALLOC_CTX *mem_ctx, const struct hive_key *h,
ret = ldb_search(c, ldap_path, LDB_SCOPE_BASE, "(key=*)", NULL, &res);
if (ret != LDB_SUCCESS) {
DEBUG(3, ("Error opening key '%s': %s\n",
ldb_dn_get_linearized(ldap_path), ldb_errstring(c)));
DEBUG(3, ("Error opening key '%s': %s\n",
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;
}
@ -308,7 +325,7 @@ static WERROR ldb_open_key(TALLOC_CTX *mem_ctx, const struct hive_key *h,
newkd = talloc_zero(mem_ctx, struct ldb_key_data);
newkd->key.ops = &reg_backend_ldb;
newkd->ldb = talloc_reference(newkd, kd->ldb);
newkd->dn = ldb_dn_copy(mem_ctx, res->msgs[0]->dn);
newkd->dn = ldb_dn_copy(mem_ctx, res->msgs[0]->dn);
*key = (struct hive_key *)newkd;
@ -317,7 +334,7 @@ static WERROR ldb_open_key(TALLOC_CTX *mem_ctx, const struct hive_key *h,
return WERR_OK;
}
WERROR reg_open_ldb_file(TALLOC_CTX *parent_ctx, const char *location,
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)
@ -325,10 +342,10 @@ WERROR reg_open_ldb_file(TALLOC_CTX *parent_ctx, const char *location,
struct ldb_key_data *kd;
struct ldb_context *wrap;
if (location == NULL)
if (location == NULL)
return WERR_INVALID_PARAM;
wrap = ldb_wrap_connect(parent_ctx, global_loadparm,
wrap = ldb_wrap_connect(parent_ctx, global_loadparm,
location, session_info, credentials, 0, NULL);
if (wrap == NULL) {
@ -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,13 +382,14 @@ 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) {
DEBUG(1, ("ldb_msg_add: %s\n", ldb_errstring(parentkd->ldb)));
return WERR_FOOBAR;
}
}
DEBUG(2, ("key added: %s\n", ldb_dn_get_linearized(msg->dn)));
@ -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);
@ -431,9 +449,9 @@ static WERROR ldb_del_value (struct hive_key *key, const char *child)
return WERR_OK;
}
static WERROR ldb_set_value(struct hive_key *parent,
const char *name, uint32_t type,
const DATA_BLOB data)
static WERROR ldb_set_value(struct hive_key *parent,
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);
@ -454,17 +472,17 @@ static WERROR ldb_set_value(struct hive_key *parent,
return WERR_FOOBAR;
}
}
talloc_free(mem_ctx);
return WERR_OK;
}
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)
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)
{
struct ldb_key_data *kd = talloc_get_type(key, struct ldb_key_data);

View File

@ -1,4 +1,4 @@
/*
/*
Unix SMB/CIFS implementation.
Transparent registry backend handling
Copyright (C) Jelmer Vernooij 2003-2007.
@ -38,7 +38,7 @@ struct registry_local {
struct mountpoint *prev, *next;
} *mountpoints;
struct auth_session_info *session_info;
struct auth_session_info *session_info;
struct cli_credentials *credentials;
};
@ -49,9 +49,9 @@ struct local_key {
};
struct registry_key *reg_import_hive_key(struct registry_context *ctx,
struct hive_key *hive,
uint32_t predefined_key,
struct registry_key *reg_import_hive_key(struct registry_context *ctx,
struct hive_key *hive,
uint32_t predefined_key,
const char **elements)
{
struct local_key *local_key;
@ -70,25 +70,26 @@ 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,
*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;
int el;
if (local_parent->path.elements != NULL) {
elements = talloc_array(mem_ctx, const char *,
str_list_length(local_parent->path.elements) + 1);
elements = talloc_array(mem_ctx, const char *,
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]);
elements[el] = talloc_reference(elements,
local_parent->path.elements[el]);
}
elements[el] = NULL;
} else {
@ -103,67 +104,69 @@ 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;
}
if (curend == NULL)
if (curend == NULL)
break;
curbegin = curend + 1;
curend = strchr(curbegin, '\\');
}
talloc_free(orig);
*result = reg_import_hive_key(local_parent->global.context, curkey,
local_parent->path.predefined_key,
talloc_steal(curkey, elements));
*result = reg_import_hive_key(local_parent->global.context, curkey,
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)
{
struct registry_local *rctx = talloc_get_type(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,
struct registry_local);
struct mountpoint *mp;
for (mp = rctx->mountpoints; mp != NULL; mp = mp->next) {
if (mp->path.predefined_key == key_id &&
if (mp->path.predefined_key == key_id &&
mp->path.elements == NULL)
break;
}
if (mp == NULL)
return WERR_NOT_FOUND;
*key = reg_import_hive_key(ctx, mp->key,
mp->path.predefined_key,
*key = reg_import_hive_key(ctx, mp->key,
mp->path.predefined_key,
mp->path.elements);
return WERR_OK;
}
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);
return hive_enum_key(mem_ctx, local->hive_key, idx, name, keyclass,
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;
@ -176,21 +179,22 @@ static WERROR local_create_key (TALLOC_CTX *mem_ctx,
last_part = name;
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));
W_ERROR_NOT_OK_RETURN(reg_open_key(mem_ctx, parent_key,
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));
W_ERROR_NOT_OK_RETURN(hive_key_add_name(mem_ctx, local_parent->hive_key,
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);
elements = talloc_array(hivekey, const char *,
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]);
elements[i] = talloc_reference(elements,
local_parent->path.elements[i]);
}
} else {
elements = talloc_array(hivekey, const char *, 2);
@ -200,75 +204,75 @@ static WERROR local_create_key (TALLOC_CTX *mem_ctx,
elements[i] = talloc_strdup(elements, name);
elements[i+1] = NULL;
*key = reg_import_hive_key(local_parent->global.context, hivekey,
local_parent->path.predefined_key,
elements);
*key = reg_import_hive_key(local_parent->global.context, hivekey,
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);
return hive_get_value_by_index(mem_ctx, local->hive_key, idx,
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);
return hive_key_get_info(mem_ctx, local->hive_key,
classname, num_subkeys, num_values,
last_change_time);
}
const static struct registry_operations local_ops = {
@ -286,11 +290,12 @@ const static struct registry_operations local_ops = {
.get_key_info = local_get_key_info,
};
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)
{
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);
@ -299,16 +304,17 @@ WERROR reg_open_local(TALLOC_CTX *mem_ctx, struct registry_context **ctx,
ret->credentials = credentials;
*ctx = (struct registry_context *)ret;
return WERR_OK;
}
WERROR reg_mount_hive(struct registry_context *rctx,
struct hive_key *hive_key,
uint32_t key_id,
const char **elements)
WERROR reg_mount_hive(struct registry_context *rctx,
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;
@ -316,11 +322,11 @@ WERROR reg_mount_hive(struct registry_context *rctx,
mp->prev = mp->next = NULL;
mp->key = hive_key;
if (elements != NULL) {
mp->path.elements = talloc_array(mp, const char *,
str_list_length(elements));
mp->path.elements = talloc_array(mp, const char *,
str_list_length(elements));
for (i = 0; elements[i] != NULL; i++) {
mp->path.elements[i] = talloc_reference(mp->path.elements,
elements[i]);
mp->path.elements[i] = talloc_reference(mp->path.elements,
elements[i]);
}
mp->path.elements[i] = NULL;
} else {

View File

@ -1,7 +1,7 @@
/*
/*
Unix SMB/CIFS implementation.
Reading registry patch files
Copyright (C) Jelmer Vernooij 2004-2007
Copyright (C) Wilco Baan Hofman 2006
@ -9,12 +9,12 @@
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
@ -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)
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)
{
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)));
DEBUG(0, ("Error occured while getting key info: %s\n",
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)));
DEBUG(0, ("Error occured while getting subkey by index: %s\n",
win_errstr(error2)));
continue;
}
@ -81,8 +87,8 @@ 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)));
DEBUG(0, ("Error occured while getting subkey by name: %s\n",
win_errstr(error2)));
talloc_free(mem_ctx);
return error2;
}
@ -90,15 +96,16 @@ WERROR reg_generate_diff_key(struct registry_key *oldkey,
/* newkey didn't have such a subkey, add del diff */
tmppath = talloc_asprintf(mem_ctx, "%s\\%s", path, keyname1);
callbacks->del_key(callback_data, tmppath);
talloc_free(tmppath);
talloc_free(tmppath);
}
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)));
DEBUG(0, ("Error occured while getting key info: %s\n",
win_errstr(error)));
return error;
}
} else {
@ -108,28 +115,29 @@ 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)));
DEBUG(0, ("Error occured while getting subkey by index: %s\n",
win_errstr(error1)));
talloc_free(mem_ctx);
return error1;
}
if (oldkey != NULL) {
error2 = reg_open_key(mem_ctx, oldkey, keyname1, &t1);
if (W_ERROR_IS_OK(error2))
continue;
} else {
t1 = NULL;
error2 = WERR_DEST_NOT_FOUND;
}
if (!W_ERROR_EQUAL(error2, WERR_DEST_NOT_FOUND)) {
DEBUG(0, ("Error occured while getting subkey by name: %s\n",
win_errstr(error2)));
DEBUG(0, ("Error occured while getting subkey by name: %s\n",
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);
}
@ -151,56 +160,59 @@ WERROR reg_generate_diff_key(struct registry_key *oldkey,
uint32_t type1, type2;
DATA_BLOB contents1, contents2;
error1 = reg_key_get_value_by_index(mem_ctx, newkey, i,
&name, &type1, &contents1);
error1 = reg_key_get_value_by_index(mem_ctx, newkey, i,
&name, &type1, &contents1);
if (!W_ERROR_IS_OK(error1)) {
DEBUG(0, ("Unable to get key by index: %s\n",
win_errstr(error1)));
DEBUG(0, ("Unable to get key by index: %s\n",
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);
} else
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) &&
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)));
DEBUG(0, ("Error occured while getting value by name: %s\n",
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);
error1 = reg_key_get_value_by_index(mem_ctx, oldkey, i, &name,
NULL, NULL);
if (!W_ERROR_IS_OK(error1)) {
DEBUG(0, ("Error ocurred getting value by index: %s\n",
win_errstr(error1)));
DEBUG(0, ("Error ocurred getting value by index: %s\n",
win_errstr(error1)));
talloc_free(mem_ctx);
return error1;
}
error2 = reg_key_get_value_by_name(mem_ctx, newkey, name, NULL,
NULL);
error2 = reg_key_get_value_by_name(mem_ctx, newkey, name, 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)));
DEBUG(0, ("Error occured while getting value by name: %s\n",
win_errstr(error2)));
return error2;
}
@ -212,10 +224,10 @@ WERROR reg_generate_diff_key(struct registry_key *oldkey,
}
/**
* Generate diff between two registry contexts
* Generate diff between two registry contexts
*/
_PUBLIC_ WERROR reg_generate_diff(struct registry_context *ctx1,
struct registry_context *ctx2,
_PUBLIC_ WERROR reg_generate_diff(struct registry_context *ctx1,
struct registry_context *ctx2,
const struct reg_diff_callbacks *callbacks,
void *callback_data)
{
@ -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;
}
}
@ -252,21 +270,23 @@ _PUBLIC_ WERROR reg_generate_diff(struct registry_context *ctx1,
/**
* Load diff file
*/
_PUBLIC_ WERROR reg_diff_load(const char *filename,
const struct reg_diff_callbacks *callbacks,
_PUBLIC_ WERROR reg_diff_load(const char *filename,
const struct reg_diff_callbacks *callbacks,
void *callback_data)
{
int fd;
char hdr[4];
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;
}
@ -279,8 +299,8 @@ _PUBLIC_ WERROR reg_diff_load(const char *filename,
} else if (strncmp(hdr, "regf", 4) == 0) {
/* Must be a REGF NTConfig.pol file */
return reg_regf_diff_load(diff, fd);
} else
#endif
} else
#endif
if (strncmp(hdr, "PReg", 4) == 0) {
/* Must be a GPO Registry.pol file */
return reg_preg_diff_load(fd, callbacks, callback_data);
@ -293,7 +313,7 @@ _PUBLIC_ WERROR reg_diff_load(const char *filename,
/**
* The reg_diff_apply functions
*/
static WERROR reg_diff_apply_add_key(void *_ctx, const char *key_name)
static WERROR reg_diff_apply_add_key(void *_ctx, const char *key_name)
{
struct registry_context *ctx = (struct registry_context *)_ctx;
struct registry_key *tmp;
@ -301,14 +321,16 @@ 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;
}
static WERROR reg_diff_apply_del_key(void *_ctx, const char *key_name)
static WERROR reg_diff_apply_del_key(void *_ctx, const char *key_name)
{
struct registry_context *ctx = (struct registry_context *)_ctx;
WERROR error;
@ -319,16 +341,18 @@ static WERROR reg_diff_apply_del_key(void *_ctx, const char *key_name)
DEBUG(0, ("Unable to delete key '%s'\n", key_name));
return error;
}
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;
WERROR error;
/* Open key */
error = reg_open_key_abs(ctx, ctx, path, &tmp);
@ -338,22 +362,23 @@ static WERROR reg_diff_apply_set_value(void *_ctx, const char *path, const char
}
/* Set value */
error = reg_val_set(tmp, value_name,
error = reg_val_set(tmp, value_name,
value_type, value);
if (!W_ERROR_IS_OK(error)) {
DEBUG(0, ("Error setting value '%s'\n", value_name));
return error;
}
}
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;
WERROR error;
/* Open key */
error = reg_open_key_abs(ctx, ctx, key_name, &tmp);
@ -367,7 +392,7 @@ static WERROR reg_diff_apply_del_value (void *_ctx, const char *key_name, const
DEBUG(0, ("Error deleting value '%s'\n", value_name));
return error;
}
return WERR_OK;
}
@ -387,26 +412,28 @@ static WERROR reg_diff_apply_del_all_values(void *_ctx, const char *key_name)
return error;
}
W_ERROR_NOT_OK_RETURN(reg_key_get_info(ctx, key,
NULL,
NULL,
&num_values,
NULL));
W_ERROR_NOT_OK_RETURN(reg_key_get_info(ctx, key,
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));
}
return WERR_OK;
}
/**
* Apply diff to a registry context
/**
* 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

@ -1,52 +1,55 @@
/*
/*
Unix SMB/CIFS implementation.
Patchfile interface
Copyright (C) Jelmer Vernooij 2006
Copyright (C) Wilco Baan Hofman 2006
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
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef _PATCHFILE_H
#define _PATCHFILE_H
#define _PATCHFILE_H
#include "lib/registry/registry.h"
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);
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);
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);
WERROR reg_diff_apply (const char *filename,
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);
WERROR reg_dotreg_diff_save(TALLOC_CTX *ctx, const char *filename,
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);
WERROR reg_generate_diff(struct registry_context *ctx1,
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);
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);
#endif /* _PATCHFILE_H */

View File

@ -1,7 +1,7 @@
/*
/*
Unix SMB/CIFS implementation.
Reading .REG files
Copyright (C) Jelmer Vernooij 2004-2007
Copyright (C) Wilco Baan Hofman 2006
@ -9,12 +9,12 @@
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
@ -43,7 +43,7 @@ static WERROR reg_dotreg_diff_add_key(void *_data, const char *key_name)
struct dotreg_data *data = (struct dotreg_data *)_data;
fdprintf(data->fd, "\n[%s]\n", key_name);
return WERR_OK;
}
@ -52,23 +52,25 @@ static WERROR reg_dotreg_diff_del_key(void *_data, const char *key_name)
struct dotreg_data *data = (struct dotreg_data *)_data;
fdprintf(data->fd, "\n[-%s]\n", key_name);
return WERR_OK;
}
static WERROR reg_dotreg_diff_set_value(void *_data, const char *path,
const char *value_name, uint32_t value_type, DATA_BLOB value)
static WERROR reg_dotreg_diff_set_value(void *_data, const char *path,
const char *value_name,
uint32_t value_type, DATA_BLOB value)
{
struct dotreg_data *data = (struct dotreg_data *)_data;
fdprintf(data->fd, "\"%s\"=%s:%s\n",
value_name, str_regtype(value_type),
value_name, str_regtype(value_type),
reg_val_data_string(NULL, value_type, value));
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;
}
@ -95,8 +98,9 @@ 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)
_PUBLIC_ WERROR reg_dotreg_diff_save(TALLOC_CTX *ctx, const char *filename,
struct reg_diff_callbacks **callbacks,
void **callback_data)
{
struct dotreg_data *data;
@ -125,13 +129,14 @@ _PUBLIC_ WERROR reg_dotreg_diff_save(TALLOC_CTX *ctx, const char *filename,
(*callbacks)->done = reg_dotreg_diff_done;
return WERR_OK;
}
}
/**
* Load diff file
*/
_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)
{
char *line, *p, *q;
char *curkey = NULL;
@ -152,8 +157,8 @@ _PUBLIC_ WERROR reg_dotreg_diff_load(int fd,
/* Ignore comments and empty lines */
if (strlen(line) == 0 || line[0] == ';') {
talloc_free(line);
if (curkey) {
if (curkey) {
talloc_free(curkey);
}
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;
}
@ -223,18 +232,21 @@ _PUBLIC_ WERROR reg_dotreg_diff_load(int fd,
talloc_free(line);
continue;
}
q = strchr_m(p, ':');
if (q) {
*q = '\0';
*q = '\0';
q++;
}
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);
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);
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

@ -1,19 +1,19 @@
/*
/*
Unix SMB/CIFS implementation.
Reading Registry.pol PReg registry files
Copyright (C) Wilco Baan Hofman 2006
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
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
@ -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,14 +86,16 @@ 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 {
char hdr[4];
uint32_t version;
} preg_header;
data = talloc_zero(ctx, struct preg_data);
*callback_data = data;
@ -106,23 +111,25 @@ _PUBLIC_ WERROR reg_preg_diff_save(TALLOC_CTX *ctx, const char *filename, struct
}
snprintf(preg_header.hdr, 4, "PReg");
SIVAL(&preg_header, 4, 1);
write(data->fd, (uint8_t *)&preg_header,8);
write(data->fd, (uint8_t *)&preg_header,8);
*callbacks = talloc(ctx, struct reg_diff_callbacks);
(*callbacks)->add_key = reg_preg_diff_add_key;
(*callbacks)->del_key = reg_preg_diff_del_key;
(*callbacks)->set_value = reg_preg_diff_set_value;
(*callbacks)->del_value = reg_preg_diff_del_value;
(*callbacks)->del_all_values = reg_preg_diff_del_all_values;
(*callbacks)->done = reg_preg_diff_done;
return WERR_OK;
}
/**
* 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];
@ -132,7 +139,7 @@ _PUBLIC_ WERROR reg_preg_diff_load(int fd, const struct reg_diff_callbacks *call
char *buf_ptr = buf;
TALLOC_CTX *mem_ctx = talloc_init("reg_preg_diff_load");
/* Read first 8 bytes (the header) */
if (read(fd, &preg_header, 8) != 8) {
DEBUG(0, ("Could not read PReg file: %s\n",
@ -147,14 +154,14 @@ _PUBLIC_ WERROR reg_preg_diff_load(int fd, const struct reg_diff_callbacks *call
}
if (preg_header.version > 1) {
DEBUG(0, ("Warning: file format version is higher than expected.\n"));
}
}
/* Read the entries */
while(1) {
char *key, *value_name;
uint32_t value_type, length;
DATA_BLOB data;
if (!W_ERROR_IS_OK(preg_read_utf16(fd, buf_ptr))) {
break;
}
@ -163,17 +170,19 @@ _PUBLIC_ WERROR reg_preg_diff_load(int fd, const struct reg_diff_callbacks *call
close(fd);
return WERR_GENERAL_FAILURE;
}
/* 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,39 +209,43 @@ _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;
}
data = data_blob_talloc(mem_ctx, buf, length);
/* 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) {
callbacks->del_all_values(callback_data, key);
} else if (strncasecmp(value_name, "**Del.",6) == 0) {
char *p = value_name+6;
callbacks->del_value(callback_data, key, p);
} else if (strcasecmp(value_name, "**DeleteValues") == 0) {
char *p, *q;
p = (char *) data.data;
while ((q = strchr_m(p, ';'))) {
*q = '\0';
*q = '\0';
q++;
callbacks->del_value(callback_data, key, p);
@ -243,28 +257,30 @@ _PUBLIC_ WERROR reg_preg_diff_load(int fd, const struct reg_diff_callbacks *call
char *p, *q, *full_key;
p = (char *) data.data;
while ((q = strchr_m(p, ';'))) {
*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);
p = q;
p = q;
}
full_key = talloc_asprintf(mem_ctx, "%s\\%s", key, p);
callbacks->del_key(callback_data, full_key);
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);
talloc_free(data.data);
}
close(fd);
close(fd);
return WERR_OK;
}

File diff suppressed because it is too large Load Diff

View File

@ -1,25 +1,25 @@
/*
/*
Unix SMB/CIFS implementation.
Registry interface
Copyright (C) Gerald Carter 2002.
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
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _REGISTRY_H /* _REGISTRY_H */
#define _REGISTRY_H
#define _REGISTRY_H
struct registry_context;
@ -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
@ -61,18 +61,18 @@ extern const struct reg_predefined_key reg_predefined_keys[];
struct reg_key_operations;
/* structure to store the registry handles */
struct registry_key
struct registry_key
{
struct registry_context *context;
};
#include "lib/registry/patchfile.h"
struct registry_value
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,77 +86,77 @@ 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);
WERROR (*get_predefined_key) (const struct registry_context *ctx,
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);
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);
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);
};
/**
* Handle to a full registry
* contains zero or more hives
* contains zero or more hives
*/
struct registry_context {
const struct registry_operations *ops;
@ -168,113 +168,118 @@ 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);
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);
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);
WERROR reg_get_predefined_key(const struct registry_context *ctx,
uint32_t hkey,
struct registry_key **key);
WERROR reg_get_predefined_key_by_name(struct registry_context *ctx,
const char *name,
struct registry_key **key);
WERROR reg_get_predefined_key(const struct registry_context *ctx,
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);
WERROR reg_open_key(TALLOC_CTX *mem_ctx, struct registry_key *parent,
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);
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);
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);
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);
WERROR reg_key_get_subkey_by_name(TALLOC_CTX *mem_ctx,
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 **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);
WERROR reg_key_get_subkey_by_name(TALLOC_CTX *mem_ctx,
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);
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);
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_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);
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_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);
/* Utility functions */
const char *str_regtype(int type);
char *reg_val_data_string(TALLOC_CTX *mem_ctx, uint32_t type,
const DATA_BLOB data);
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);
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_load_key(struct registry_context *ctx, struct registry_key *key,
const char *name, const char *filename);
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);
WERROR reg_mount_hive(struct registry_context *rctx,
struct hive_key *hive_key,
uint32_t key_id,
const char **elements);
WERROR reg_mount_hive(struct registry_context *rctx,
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);
WERROR reg_get_security(TALLOC_CTX *mem_ctx,
const struct registry_key *key,
struct security_descriptor **security);
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);
WERROR reg_set_security(struct registry_key *key,
struct security_descriptor *security);
WERROR reg_set_security(struct registry_key *key,
struct security_descriptor *security);
#endif /* _REGISTRY_H */

View File

@ -7,15 +7,15 @@
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include "includes.h"
#include "registry.h"
#include "librpc/gen_ndr/ndr_winreg_c.h"
@ -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 },
@ -90,20 +91,20 @@ 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)
static WERROR rpc_get_predefined_key(const struct registry_context *ctx,
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 *rctx = talloc_get_type(ctx,
struct rpc_registry_context);
struct rpc_key *mykeydata;
for(n = 0; known_hives[n].hkey; n++) {
if(known_hives[n].hkey == hkey_type)
if(known_hives[n].hkey == hkey_type)
break;
}
if (known_hives[n].open == NULL) {
DEBUG(1, ("No such hive %d\n", hkey_type));
return WERR_NO_MORE_ITEMS;
@ -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)
static WERROR rpc_open_key(TALLOC_CTX *mem_ctx, struct registry_key *h,
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)
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)
{
struct rpc_key *mykeydata = talloc_get_type(parent, struct rpc_key);
WERROR error;
@ -177,14 +179,14 @@ static WERROR rpc_get_value_by_index(TALLOC_CTX *mem_ctx,
NTSTATUS status;
struct winreg_StringBuf name;
uint8_t u8;
if (mykeydata->num_values == -1) {
error = rpc_query_key(parent);
if(!W_ERROR_IS_OK(error)) return error;
}
len1 = mykeydata->max_valdatalen;
name.length = 0;
name.size = mykeydata->max_valnamelen * 2;
name.name = "";
@ -197,29 +199,29 @@ static WERROR rpc_get_value_by_index(TALLOC_CTX *mem_ctx,
r.in.length = &zero;
r.in.size = &len1;
r.out.name = &name;
status = dcerpc_winreg_EnumValue(mykeydata->pipe, mem_ctx, &r);
if(NT_STATUS_IS_ERR(status)) {
DEBUG(0, ("Error in EnumValue: %s\n", nt_errstr(status)));
return WERR_GENERAL_FAILURE;
}
if(NT_STATUS_IS_OK(status) &&
if(NT_STATUS_IS_OK(status) &&
W_ERROR_IS_OK(r.out.result) && r.out.length) {
*value_name = talloc_strdup(mem_ctx, r.out.name->name);
*data = data_blob_talloc(mem_ctx, r.out.value, *r.out.length);
return WERR_OK;
}
return r.out.result;
}
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)
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)
{
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;
@ -251,11 +253,11 @@ static WERROR rpc_get_subkey_by_index(TALLOC_CTX *mem_ctx,
return r.out.result;
}
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)
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)
{
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,29 +291,29 @@ 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;
status = dcerpc_winreg_QueryInfoKey(mykeydata->pipe, mem_ctx, &r);
init_winreg_String(r.in.classname, NULL);
r.in.handle = &mykeydata->pol;
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 (W_ERROR_IS_OK(r.out.result)) {
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)) {
mykeydata->num_subkeys = *r.out.num_subkeys;
mykeydata->num_values = *r.out.num_values;
mykeydata->max_valnamelen = *r.out.max_valnamelen;
mykeydata->max_valdatalen = *r.out.max_valbufsize;
}
}
return r.out.result;
}
@ -322,11 +324,11 @@ static WERROR rpc_del_key(struct registry_key *parent, const char *name)
struct rpc_key *mykeydata = talloc_get_type(parent, struct rpc_key);
struct winreg_DeleteKey r;
TALLOC_CTX *mem_ctx = talloc_init("del_key");
r.in.handle = &mykeydata->pol;
init_winreg_String(&r.in.key, name);
status = dcerpc_winreg_DeleteKey(mykeydata->pipe, mem_ctx, &r);
r.in.handle = &mykeydata->pol;
init_winreg_String(&r.in.key, name);
status = dcerpc_winreg_DeleteKey(mykeydata->pipe, mem_ctx, &r);
talloc_free(mem_ctx);
@ -334,19 +336,19 @@ static WERROR rpc_del_key(struct registry_key *parent, const char *name)
}
static WERROR rpc_get_info(TALLOC_CTX *mem_ctx, const struct registry_key *key,
const char **classname,
const char **classname,
uint32_t *numsubkeys,
uint32_t *numvalue,
NTTIME *last_changed_time)
{
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;
}
/* FIXME: *classname = talloc_strdup(mem_ctx, mykeydata->classname); */
/* FIXME: *last_changed_time = mykeydata->last_changed_time */
@ -370,10 +372,10 @@ static struct registry_operations reg_backend_rpc = {
.get_predefined_key = rpc_get_predefined_key,
};
_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)
_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)
{
NTSTATUS status;
struct dcerpc_pipe *p;
@ -388,14 +390,15 @@ _PUBLIC_ WERROR reg_open_remote(struct registry_context **ctx,
location = talloc_strdup(ctx, "ncalrpc:");
}
status = dcerpc_pipe_connect(*ctx /* TALLOC_CTX */,
&p, location,
status = dcerpc_pipe_connect(*ctx /* TALLOC_CTX */,
&p, location,
&ndr_table_winreg,
credentials, ev);
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

@ -1,4 +1,4 @@
/*
/*
Unix SMB/CIFS implementation.
Copyright (C) Jelmer Vernooij 2004-2007.
@ -25,23 +25,25 @@
* @brief Samba-specific registry functions
*/
static WERROR mount_samba_hive(struct registry_context *ctx,
static WERROR mount_samba_hive(struct registry_context *ctx,
struct auth_session_info *auth_info,
struct cli_credentials *creds,
const char *name,
const char *name,
uint32_t hive_id)
{
WERROR error;
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;
@ -62,19 +64,19 @@ _PUBLIC_ WERROR reg_open_samba (TALLOC_CTX *mem_ctx,
return result;
}
mount_samba_hive(*ctx, session_info, credentials,
"hklm", HKEY_LOCAL_MACHINE);
mount_samba_hive(*ctx, session_info, credentials,
"hklm", HKEY_LOCAL_MACHINE);
mount_samba_hive(*ctx, session_info, credentials,
"hkcr", HKEY_CLASSES_ROOT);
mount_samba_hive(*ctx, session_info, credentials,
"hkcr", HKEY_CLASSES_ROOT);
/* FIXME: Should be mounted from NTUSER.DAT in the home directory of the
/* 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);
mount_samba_hive(*ctx, session_info, credentials,
"hkcu", HKEY_CURRENT_USER);
mount_samba_hive(*ctx, session_info, credentials,
"hku", HKEY_USERS);
mount_samba_hive(*ctx, session_info, credentials,
"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 */
@ -86,6 +88,6 @@ _PUBLIC_ WERROR reg_open_samba (TALLOC_CTX *mem_ctx,
/* FIXME: HKEY_LOCAL_MACHINE\Hardware is autogenerated */
/* FIXME: HKEY_LOCAL_MACHINE\Security\SAM is an alias for HKEY_LOCAL_MACHINE\SAM */
return WERR_OK;
}

View File

@ -1,4 +1,4 @@
/*
/*
Unix SMB/CIFS implementation.
Transparent registry backend handling
Copyright (C) Jelmer Vernooij 2003-2007.
@ -43,60 +43,59 @@ _PUBLIC_ const char *str_regtype(int type)
{
int i;
for (i = 0; reg_value_types[i].name; i++) {
if (reg_value_types[i].id == type)
if (reg_value_types[i].id == type)
return reg_value_types[i].name;
}
return "Unknown";
}
_PUBLIC_ char *reg_val_data_string(TALLOC_CTX *mem_ctx, uint32_t 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)
_PUBLIC_ char *reg_val_description(TALLOC_CTX *mem_ctx, const char *name,
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));
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));
}
_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;
@ -109,16 +108,18 @@ _PUBLIC_ bool reg_string_to_val(TALLOC_CTX *mem_ctx, const char *type_str, const
}
}
if (*type == -1)
if (*type == -1)
return false;
/* Convert data appropriately */
switch (*type)
switch (*type)
{
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: {
@ -130,12 +131,12 @@ _PUBLIC_ bool reg_string_to_val(TALLOC_CTX *mem_ctx, const char *type_str, const
case REG_NONE:
ZERO_STRUCTP(data);
break;
case REG_BINARY:
case REG_BINARY:
*data = strhex_to_data_blob(data_str);
talloc_steal(mem_ctx, data->data);
break;
default:
/* FIXME */
return false;
@ -144,16 +145,17 @@ _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;
int predeflength;
char *predefname;
if (strchr(name, '\\') != NULL)
if (strchr(name, '\\') != NULL)
predeflength = strchr(name, '\\')-name;
else
else
predeflength = strlen(name);
predefname = talloc_strndup(mem_ctx, name, predeflength);
@ -165,31 +167,32 @@ 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;
}
}
static WERROR get_abs_parent(TALLOC_CTX *mem_ctx, struct registry_context *ctx,
const char *path, struct registry_key **parent,
const char **name)
static WERROR get_abs_parent(TALLOC_CTX *mem_ctx, struct registry_context *ctx,
const char *path, struct registry_key **parent,
const char **name)
{
char *parent_name;
WERROR error;
if (strchr(path, '\\') == NULL) {
return WERR_FOOBAR;
}
parent_name = talloc_strndup(mem_ctx, path, strrchr(path, '\\')-path);
error = reg_open_key_abs(mem_ctx, ctx, parent_name, parent);
if (!W_ERROR_IS_OK(error)) {
return error;
}
*name = talloc_strdup(mem_ctx, strrchr(path, '\\')+1);
return WERR_OK;
@ -201,11 +204,11 @@ WERROR reg_key_del_abs(struct registry_context *ctx, const char *path)
const char *n;
TALLOC_CTX *mem_ctx = talloc_init("reg_key_del_abs");
WERROR error;
if (!strchr(path, '\\')) {
return WERR_FOOBAR;
}
error = get_abs_parent(mem_ctx, ctx, path, &parent, &n);
if (W_ERROR_IS_OK(error)) {
error = reg_key_del(parent, n);
@ -216,22 +219,22 @@ WERROR reg_key_del_abs(struct registry_context *ctx, const char *path)
return error;
}
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)
{
struct registry_key *parent;
const char *n;
WERROR error;
if (!strchr(path, '\\')) {
return WERR_ALREADY_EXISTS;
}
error = get_abs_parent(mem_ctx, ctx, path, &parent, &n);
if (!W_ERROR_IS_OK(error)) {
DEBUG(2, ("Opening parent of %s failed with %s\n", path,
DEBUG(2, ("Opening parent of %s failed with %s\n", path,
win_errstr(error)));
return error;
}

View File

@ -1,18 +1,18 @@
/*
/*
Unix SMB/CIFS implementation.
Registry interface
Copyright (C) Jelmer Vernooij 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
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
@ -29,7 +29,7 @@ static WERROR wine_open_reg (struct registry_hive *h, struct registry_key **key)
static REG_OPS reg_backend_wine = {
.name = "wine",
.open_hive = wine_open_reg,
};
NTSTATUS registry_wine_init(void)