summaryrefslogtreecommitdiff
path: root/source3/registry
diff options
context:
space:
mode:
authorKarolin Seeger <kseeger@samba.org>2008-02-29 10:44:38 +0100
committerKarolin Seeger <kseeger@samba.org>2008-02-29 10:44:38 +0100
commitc4fbe2846231a6b322c1094c6a1dbf93b7305768 (patch)
tree09eb77a294f4acda131b41fe4c9bec4ed175eb16 /source3/registry
parent1a6415fc77c708b87c8e2ce6e7828f486ffc87ac (diff)
parent695b6662abe64a40061bfa05ede12173fc4b1945 (diff)
downloadsamba-c4fbe2846231a6b322c1094c6a1dbf93b7305768.tar.gz
samba-c4fbe2846231a6b322c1094c6a1dbf93b7305768.tar.bz2
samba-c4fbe2846231a6b322c1094c6a1dbf93b7305768.zip
Merge commit 'origin/v3-2-test' into v3-2-stable
Conflicts: WHATSNEW.txt (This used to be commit a390bcf9403df4cf4d5eef42b35ebccbe253882e)
Diffstat (limited to 'source3/registry')
-rw-r--r--source3/registry/reg_api.c472
-rw-r--r--source3/registry/reg_backend_current_version.c81
-rw-r--r--source3/registry/reg_backend_db.c (renamed from source3/registry/reg_db.c)23
-rw-r--r--source3/registry/reg_backend_hkpt_params.c70
-rw-r--r--source3/registry/reg_backend_netlogon_params.c57
-rw-r--r--source3/registry/reg_backend_perflib.c106
-rw-r--r--source3/registry/reg_backend_printing.c (renamed from source3/registry/reg_printing.c)9
-rw-r--r--source3/registry/reg_backend_prod_options.c70
-rw-r--r--source3/registry/reg_backend_shares.c (renamed from source3/registry/reg_shares.c)9
-rw-r--r--source3/registry/reg_backend_smbconf.c (renamed from source3/registry/reg_smbconf.c)16
-rw-r--r--source3/registry/reg_backend_tcpip_params.c67
-rw-r--r--source3/registry/reg_cachehook.c13
-rw-r--r--source3/registry/reg_dispatcher.c (renamed from source3/registry/reg_frontend_hilvl.c)103
-rw-r--r--source3/registry/reg_dynamic.c264
-rw-r--r--source3/registry/reg_frontend.c202
-rw-r--r--source3/registry/reg_init_full.c103
-rw-r--r--source3/registry/reg_init_smbconf.c97
-rw-r--r--source3/registry/reg_util_legacy.c47
-rw-r--r--source3/registry/regfio.c6
19 files changed, 1248 insertions, 567 deletions
diff --git a/source3/registry/reg_api.c b/source3/registry/reg_api.c
index d1657c8cf6..e52aaacb4d 100644
--- a/source3/registry/reg_api.c
+++ b/source3/registry/reg_api.c
@@ -2,6 +2,7 @@
* Unix SMB/CIFS implementation.
* Virtual Windows Registry Layer
* Copyright (C) Volker Lendecke 2006
+ * Copyright (C) Michael Adam 2007-2008
*
* 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
@@ -19,11 +20,59 @@
/* Attempt to wrap the existing API in a more winreg.idl-like way */
+/*
+ * Here is a list of winreg.idl functions and corresponding implementations
+ * provided here:
+ *
+ * 0x00 winreg_OpenHKCR
+ * 0x01 winreg_OpenHKCU
+ * 0x02 winreg_OpenHKLM
+ * 0x03 winreg_OpenHKPD
+ * 0x04 winreg_OpenHKU
+ * 0x05 winreg_CloseKey
+ * 0x06 winreg_CreateKey reg_createkey
+ * 0x07 winreg_DeleteKey reg_deletekey
+ * 0x08 winreg_DeleteValue reg_deletevalue
+ * 0x09 winreg_EnumKey reg_enumkey
+ * 0x0a winreg_EnumValue reg_enumvalue
+ * 0x0b winreg_FlushKey
+ * 0x0c winreg_GetKeySecurity reg_getkeysecurity
+ * 0x0d winreg_LoadKey
+ * 0x0e winreg_NotifyChangeKeyValue
+ * 0x0f winreg_OpenKey reg_openkey
+ * 0x10 winreg_QueryInfoKey reg_queryinfokey
+ * 0x11 winreg_QueryValue reg_queryvalue
+ * 0x12 winreg_ReplaceKey
+ * 0x13 winreg_RestoreKey reg_restorekey
+ * 0x14 winreg_SaveKey reg_savekey
+ * 0x15 winreg_SetKeySecurity reg_setkeysecurity
+ * 0x16 winreg_SetValue reg_setvalue
+ * 0x17 winreg_UnLoadKey
+ * 0x18 winreg_InitiateSystemShutdown
+ * 0x19 winreg_AbortSystemShutdown
+ * 0x1a winreg_GetVersion reg_getversion
+ * 0x1b winreg_OpenHKCC
+ * 0x1c winreg_OpenHKDD
+ * 0x1d winreg_QueryMultipleValues
+ * 0x1e winreg_InitiateSystemShutdownEx
+ * 0x1f winreg_SaveKeyEx
+ * 0x20 winreg_OpenHKPT
+ * 0x21 winreg_OpenHKPN
+ * 0x22 winreg_QueryMultipleValues2
+ *
+ */
+
#include "includes.h"
+#include "regfio.h"
#undef DBGC_CLASS
#define DBGC_CLASS DBGC_REGISTRY
+
+/**********************************************************************
+ * Helper functions
+ **********************************************************************/
+
static WERROR fill_value_cache(struct registry_key *key)
{
if (key->values != NULL) {
@@ -135,7 +184,7 @@ static WERROR regkey_open_onelevel(TALLOC_CTX *mem_ctx,
/* Look up the table of registry I/O operations */
if ( !(key->hook = reghook_cache_find( key->name )) ) {
- DEBUG(0,("reg_open_onelevel: Failed to assigned a "
+ DEBUG(0,("reg_open_onelevel: Failed to assign a "
"REGISTRY_HOOK to [%s]\n", key->name ));
result = WERR_BADFILE;
goto done;
@@ -186,6 +235,11 @@ WERROR reg_openhive(TALLOC_CTX *mem_ctx, const char *hive,
pkey);
}
+
+/**********************************************************************
+ * The API functions
+ **********************************************************************/
+
WERROR reg_openkey(TALLOC_CTX *mem_ctx, struct registry_key *parent,
const char *name, uint32 desired_access,
struct registry_key **pkey)
@@ -400,7 +454,6 @@ WERROR reg_createkey(TALLOC_CTX *ctx, struct registry_key *parent,
TALLOC_CTX *mem_ctx;
char *path, *end;
WERROR err;
- REGSUBKEY_CTR *subkeys;
if (!(mem_ctx = talloc_new(ctx))) return WERR_NOMEM;
@@ -464,11 +517,6 @@ WERROR reg_createkey(TALLOC_CTX *ctx, struct registry_key *parent,
* Actually create the subkey
*/
- if (!(subkeys = TALLOC_ZERO_P(mem_ctx, REGSUBKEY_CTR))) {
- err = WERR_NOMEM;
- goto done;
- }
-
err = fill_subkey_cache(create_parent);
if (!W_ERROR_IS_OK(err)) goto done;
@@ -627,6 +675,305 @@ WERROR reg_deletevalue(struct registry_key *key, const char *name)
return WERR_OK;
}
+WERROR reg_getkeysecurity(TALLOC_CTX *mem_ctx, struct registry_key *key,
+ struct security_descriptor **psecdesc)
+{
+ return regkey_get_secdesc(mem_ctx, key->key, psecdesc);
+}
+
+WERROR reg_setkeysecurity(struct registry_key *key,
+ struct security_descriptor *psecdesc)
+{
+ return regkey_set_secdesc(key->key, psecdesc);
+}
+
+WERROR reg_getversion(uint32_t *version)
+{
+ if (version == NULL) {
+ return WERR_INVALID_PARAM;
+ }
+
+ *version = 0x00000005; /* Windows 2000 registry API version */
+ return WERR_OK;
+}
+
+/*******************************************************************
+ Note: topkeypat is the *full* path that this *key will be
+ loaded into (including the name of the key)
+ ********************************************************************/
+
+static WERROR reg_load_tree(REGF_FILE *regfile, const char *topkeypath,
+ REGF_NK_REC *key)
+{
+ REGF_NK_REC *subkey;
+ REGISTRY_KEY registry_key;
+ REGVAL_CTR *values;
+ REGSUBKEY_CTR *subkeys;
+ int i;
+ char *path = NULL;
+ WERROR result = WERR_OK;
+
+ /* initialize the REGISTRY_KEY structure */
+
+ registry_key.hook = reghook_cache_find(topkeypath);
+ if (!registry_key.hook) {
+ DEBUG(0, ("reg_load_tree: Failed to assigned a REGISTRY_HOOK "
+ "to [%s]\n", topkeypath));
+ return WERR_BADFILE;
+ }
+
+ registry_key.name = talloc_strdup(regfile->mem_ctx, topkeypath);
+ if (!registry_key.name) {
+ DEBUG(0, ("reg_load_tree: Talloc failed for reg_key.name!\n"));
+ return WERR_NOMEM;
+ }
+
+ /* now start parsing the values and subkeys */
+
+ subkeys = TALLOC_ZERO_P(regfile->mem_ctx, REGSUBKEY_CTR);
+ if (subkeys == NULL) {
+ return WERR_NOMEM;
+ }
+
+ values = TALLOC_ZERO_P(subkeys, REGVAL_CTR);
+ if (values == NULL) {
+ return WERR_NOMEM;
+ }
+
+ /* copy values into the REGVAL_CTR */
+
+ for (i=0; i<key->num_values; i++) {
+ regval_ctr_addvalue(values, key->values[i].valuename,
+ key->values[i].type,
+ (char*)key->values[i].data,
+ (key->values[i].data_size & ~VK_DATA_IN_OFFSET));
+ }
+
+ /* copy subkeys into the REGSUBKEY_CTR */
+
+ key->subkey_index = 0;
+ while ((subkey = regfio_fetch_subkey( regfile, key ))) {
+ regsubkey_ctr_addkey(subkeys, subkey->keyname);
+ }
+
+ /* write this key and values out */
+
+ if (!store_reg_values(&registry_key, values)
+ || !store_reg_keys(&registry_key, subkeys))
+ {
+ DEBUG(0,("reg_load_tree: Failed to load %s!\n", topkeypath));
+ result = WERR_REG_IO_FAILURE;
+ }
+
+ TALLOC_FREE(subkeys);
+
+ if (!W_ERROR_IS_OK(result)) {
+ return result;
+ }
+
+ /* now continue to load each subkey registry tree */
+
+ key->subkey_index = 0;
+ while ((subkey = regfio_fetch_subkey(regfile, key))) {
+ path = talloc_asprintf(regfile->mem_ctx,
+ "%s\\%s",
+ topkeypath,
+ subkey->keyname);
+ if (path == NULL) {
+ return WERR_NOMEM;
+ }
+ result = reg_load_tree(regfile, path, subkey);
+ if (!W_ERROR_IS_OK(result)) {
+ break;
+ }
+ }
+
+ return result;
+}
+
+/*******************************************************************
+ ********************************************************************/
+
+static WERROR restore_registry_key(REGISTRY_KEY *krecord, const char *fname)
+{
+ REGF_FILE *regfile;
+ REGF_NK_REC *rootkey;
+ WERROR result;
+
+ /* open the registry file....fail if the file already exists */
+
+ regfile = regfio_open(fname, (O_RDONLY), 0);
+ if (regfile == NULL) {
+ DEBUG(0, ("restore_registry_key: failed to open \"%s\" (%s)\n",
+ fname, strerror(errno)));
+ return ntstatus_to_werror(map_nt_error_from_unix(errno));
+ }
+
+ /* get the rootkey from the regf file and then load the tree
+ via recursive calls */
+
+ if (!(rootkey = regfio_rootkey(regfile))) {
+ regfio_close(regfile);
+ return WERR_REG_FILE_INVALID;
+ }
+
+ result = reg_load_tree(regfile, krecord->name, rootkey);
+
+ /* cleanup */
+
+ regfio_close(regfile);
+
+ return result;
+}
+
+WERROR reg_restorekey(struct registry_key *key, const char *fname)
+{
+ return restore_registry_key(key->key, fname);
+}
+
+/********************************************************************
+********************************************************************/
+
+static WERROR reg_write_tree(REGF_FILE *regfile, const char *keypath,
+ REGF_NK_REC *parent)
+{
+ REGF_NK_REC *key;
+ REGVAL_CTR *values;
+ REGSUBKEY_CTR *subkeys;
+ int i, num_subkeys;
+ char *key_tmp = NULL;
+ char *keyname, *parentpath;
+ char *subkeypath = NULL;
+ char *subkeyname;
+ REGISTRY_KEY registry_key;
+ WERROR result = WERR_OK;
+ SEC_DESC *sec_desc = NULL;
+
+ if (!regfile) {
+ return WERR_GENERAL_FAILURE;
+ }
+
+ if (!keypath) {
+ return WERR_OBJECT_PATH_INVALID;
+ }
+
+ /* split up the registry key path */
+
+ key_tmp = talloc_strdup(regfile->mem_ctx, keypath);
+ if (!key_tmp) {
+ return WERR_NOMEM;
+ }
+ if (!reg_split_key(key_tmp, &parentpath, &keyname)) {
+ return WERR_OBJECT_PATH_INVALID;
+ }
+
+ if (!keyname) {
+ keyname = parentpath;
+ }
+
+ /* we need a REGISTRY_KEY object here to enumerate subkeys and values */
+
+ ZERO_STRUCT(registry_key);
+
+ registry_key.name = talloc_strdup(regfile->mem_ctx, keypath);
+ if (registry_key.name == NULL) {
+ return WERR_NOMEM;
+ }
+
+ registry_key.hook = reghook_cache_find(registry_key.name);
+ if (registry_key.hook == NULL) {
+ return WERR_BADFILE;
+ }
+
+ /* lookup the values and subkeys */
+
+ subkeys = TALLOC_ZERO_P(regfile->mem_ctx, REGSUBKEY_CTR);
+ if (subkeys == NULL) {
+ return WERR_NOMEM;
+ }
+
+ values = TALLOC_ZERO_P(subkeys, REGVAL_CTR);
+ if (values == NULL) {
+ return WERR_NOMEM;
+ }
+
+ fetch_reg_keys(&registry_key, subkeys);
+ fetch_reg_values(&registry_key, values);
+
+ result = regkey_get_secdesc(regfile->mem_ctx, &registry_key, &sec_desc);
+ if (!W_ERROR_IS_OK(result)) {
+ goto done;
+ }
+
+ /* write out this key */
+
+ key = regfio_write_key(regfile, keyname, values, subkeys, sec_desc,
+ parent);
+ if (key == NULL) {
+ result = WERR_CAN_NOT_COMPLETE;
+ goto done;
+ }
+
+ /* write each one of the subkeys out */
+
+ num_subkeys = regsubkey_ctr_numkeys(subkeys);
+ for (i=0; i<num_subkeys; i++) {
+ subkeyname = regsubkey_ctr_specific_key(subkeys, i);
+ subkeypath = talloc_asprintf(regfile->mem_ctx, "%s\\%s",
+ keypath, subkeyname);
+ if (subkeypath == NULL) {
+ result = WERR_NOMEM;
+ goto done;
+ }
+ result = reg_write_tree(regfile, subkeypath, key);
+ if (!W_ERROR_IS_OK(result))
+ goto done;
+ }
+
+ DEBUG(6, ("reg_write_tree: wrote key [%s]\n", keypath));
+
+done:
+ TALLOC_FREE(subkeys);
+ TALLOC_FREE(registry_key.name);
+
+ return result;
+}
+
+static WERROR backup_registry_key(REGISTRY_KEY *krecord, const char *fname)
+{
+ REGF_FILE *regfile;
+ WERROR result;
+
+ /* open the registry file....fail if the file already exists */
+
+ regfile = regfio_open(fname, (O_RDWR|O_CREAT|O_EXCL),
+ (S_IREAD|S_IWRITE));
+ if (regfile == NULL) {
+ DEBUG(0,("backup_registry_key: failed to open \"%s\" (%s)\n",
+ fname, strerror(errno) ));
+ return ntstatus_to_werror(map_nt_error_from_unix(errno));
+ }
+
+ /* write the registry tree to the file */
+
+ result = reg_write_tree(regfile, krecord->name, NULL);
+
+ /* cleanup */
+
+ regfio_close(regfile);
+
+ return result;
+}
+
+WERROR reg_savekey(struct registry_key *key, const char *fname)
+{
+ return backup_registry_key(key->key, fname);
+}
+
+/**********************************************************************
+ * Higher level utility functions
+ **********************************************************************/
+
WERROR reg_deleteallvalues(struct registry_key *key)
{
WERROR err;
@@ -653,9 +1000,7 @@ WERROR reg_deleteallvalues(struct registry_key *key)
}
/*
- * Utility function to open a complete registry path including the hive
- * prefix. This should become the replacement function for
- * regkey_open_internal.
+ * Utility function to open a complete registry path including the hive prefix.
*/
WERROR reg_open_path(TALLOC_CTX *mem_ctx, const char *orig_path,
@@ -715,10 +1060,10 @@ WERROR reg_open_path(TALLOC_CTX *mem_ctx, const char *orig_path,
* Note that reg_deletekey returns ACCESS_DENIED when called on a
* key that has subkeys.
*/
-WERROR reg_deletekey_recursive_internal(TALLOC_CTX *ctx,
- struct registry_key *parent,
- const char *path,
- bool del_key)
+static WERROR reg_deletekey_recursive_internal(TALLOC_CTX *ctx,
+ struct registry_key *parent,
+ const char *path,
+ bool del_key)
{
TALLOC_CTX *mem_ctx = NULL;
WERROR werr = WERR_OK;
@@ -779,3 +1124,102 @@ WERROR reg_deletesubkeys_recursive(TALLOC_CTX *ctx,
{
return reg_deletekey_recursive_internal(ctx, parent, path, false);
}
+
+#if 0
+/* these two functions are unused. */
+
+/**
+ * Utility function to create a registry key without opening the hive
+ * before. Assumes the hive already exists.
+ */
+
+WERROR reg_create_path(TALLOC_CTX *mem_ctx, const char *orig_path,
+ uint32 desired_access,
+ const struct nt_user_token *token,
+ enum winreg_CreateAction *paction,
+ struct registry_key **pkey)
+{
+ struct registry_key *hive;
+ char *path, *p;
+ WERROR err;
+
+ if (!(path = SMB_STRDUP(orig_path))) {
+ return WERR_NOMEM;
+ }
+
+ p = strchr(path, '\\');
+
+ if ((p == NULL) || (p[1] == '\0')) {
+ /*
+ * No key behind the hive, just return the hive
+ */
+
+ err = reg_openhive(mem_ctx, path, desired_access, token,
+ &hive);
+ if (!W_ERROR_IS_OK(err)) {
+ SAFE_FREE(path);
+ return err;
+ }
+ SAFE_FREE(path);
+ *pkey = hive;
+ *paction = REG_OPENED_EXISTING_KEY;
+ return WERR_OK;
+ }
+
+ *p = '\0';
+
+ err = reg_openhive(mem_ctx, path,
+ (strchr(p+1, '\\') != NULL) ?
+ SEC_RIGHTS_ENUM_SUBKEYS : SEC_RIGHTS_CREATE_SUBKEY,
+ token, &hive);
+ if (!W_ERROR_IS_OK(err)) {
+ SAFE_FREE(path);
+ return err;
+ }
+
+ err = reg_createkey(mem_ctx, hive, p+1, desired_access, pkey, paction);
+ SAFE_FREE(path);
+ TALLOC_FREE(hive);
+ return err;
+}
+
+/*
+ * Utility function to create a registry key without opening the hive
+ * before. Will not delete a hive.
+ */
+
+WERROR reg_delete_path(const struct nt_user_token *token,
+ const char *orig_path)
+{
+ struct registry_key *hive;
+ char *path, *p;
+ WERROR err;
+
+ if (!(path = SMB_STRDUP(orig_path))) {
+ return WERR_NOMEM;
+ }
+
+ p = strchr(path, '\\');
+
+ if ((p == NULL) || (p[1] == '\0')) {
+ SAFE_FREE(path);
+ return WERR_INVALID_PARAM;
+ }
+
+ *p = '\0';
+
+ err = reg_openhive(NULL, path,
+ (strchr(p+1, '\\') != NULL) ?
+ SEC_RIGHTS_ENUM_SUBKEYS : SEC_RIGHTS_CREATE_SUBKEY,
+ token, &hive);
+ if (!W_ERROR_IS_OK(err)) {
+ SAFE_FREE(path);
+ return err;
+ }
+
+ err = reg_deletekey(hive, p+1);
+ SAFE_FREE(path);
+ TALLOC_FREE(hive);
+ return err;
+}
+#endif /* #if 0 */
diff --git a/source3/registry/reg_backend_current_version.c b/source3/registry/reg_backend_current_version.c
new file mode 100644
index 0000000000..a9d281c522
--- /dev/null
+++ b/source3/registry/reg_backend_current_version.c
@@ -0,0 +1,81 @@
+/*
+ * Unix SMB/CIFS implementation.
+ * Virtual Windows Registry Layer
+ * Copyright (C) Gerald Carter 2002-2005
+ * Copyright (C) Michael Adam 2008
+ *
+ * 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/>.
+ */
+
+/*
+ * CurrentVersion registry backend.
+ *
+ * This is a virtual overlay, dynamically presenting version information.
+ */
+
+#include "includes.h"
+
+#undef DBGC_CLASS
+#define DBGC_CLASS DBGC_REGISTRY
+
+extern REGISTRY_OPS regdb_ops;
+
+#define KEY_CURRENT_VERSION_NORM "HKLM/SOFTWARE/MICROSOFT/WINDOWS NT/CURRENTVERSION"
+
+static int current_version_fetch_values(const char *key, REGVAL_CTR *values)
+{
+ const char *sysroot_string = "c:\\Windows";
+ fstring sysversion;
+ fstring value;
+ uint32 value_length;
+ char *path = NULL;
+ TALLOC_CTX *ctx = talloc_tos();
+
+ path = talloc_strdup(ctx, key);
+ if (path == NULL) {
+ return -1;
+ }
+ path = normalize_reg_path(ctx, path);
+ if (path == NULL) {
+ return -1;
+ }
+
+ if (strncmp(path, KEY_CURRENT_VERSION_NORM, strlen(path)) != 0) {
+ return 0;
+ }
+
+ value_length = push_ucs2(value, value, sysroot_string, sizeof(value),
+ STR_TERMINATE|STR_NOALIGN );
+ regval_ctr_addvalue(values, "SystemRoot", REG_SZ, value, value_length);
+
+ fstr_sprintf(sysversion, "%d.%d", lp_major_announce_version(),
+ lp_minor_announce_version());
+ value_length = push_ucs2(value, value, sysversion, sizeof(value),
+ STR_TERMINATE|STR_NOALIGN);
+ regval_ctr_addvalue(values, "CurrentVersion", REG_SZ, value,
+ value_length);
+
+ return regval_ctr_numvals(values);
+}
+
+static int current_version_fetch_subkeys(const char *key,
+ REGSUBKEY_CTR *subkey_ctr)
+{
+ return regdb_ops.fetch_subkeys(key, subkey_ctr);
+}
+
+REGISTRY_OPS current_version_reg_ops = {
+ .fetch_values = current_version_fetch_values,
+ .fetch_subkeys = current_version_fetch_subkeys,
+};
diff --git a/source3/registry/reg_db.c b/source3/registry/reg_backend_db.c
index c4bfc2b6c9..52e0fd4289 100644
--- a/source3/registry/reg_db.c
+++ b/source3/registry/reg_backend_db.c
@@ -44,17 +44,17 @@ static const char *builtin_registry_paths[] = {
KEY_SHARES,
KEY_EVENTLOG,
KEY_SMBCONF,
- "HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Perflib",
- "HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Perflib\\009",
+ KEY_PERFLIB,
+ KEY_PERFLIB_009,
"HKLM\\SYSTEM\\CurrentControlSet\\Control\\Print\\Monitors",
- "HKLM\\SYSTEM\\CurrentControlSet\\Control\\ProductOptions",
+ KEY_PROD_OPTIONS,
"HKLM\\SYSTEM\\CurrentControlSet\\Control\\Terminal Server\\DefaultUserConfiguration",
- "HKLM\\SYSTEM\\CurrentControlSet\\Services\\TcpIp\\Parameters",
- "HKLM\\SYSTEM\\CurrentControlSet\\Services\\Netlogon\\Parameters",
- "HKU",
- "HKCR",
- "HKPD",
- "HKPT",
+ KEY_TCPIP_PARAMS,
+ KEY_NETLOGON_PARAMS,
+ KEY_HKU,
+ KEY_HKCR,
+ KEY_HKPD,
+ KEY_HKPT,
NULL };
struct builtin_regkey_value {
@@ -258,8 +258,11 @@ bool regdb_init( void )
const char *vstring = "INFO/version";
uint32 vers_id;
- if ( tdb_reg )
+ if ( tdb_reg ) {
+ DEBUG(10,("regdb_init: incrementing refcount (%d)\n", tdb_refcount));
+ tdb_refcount++;
return true;
+ }
if ( !(tdb_reg = tdb_wrap_open(NULL, state_path("registry.tdb"), 0, REG_TDB_FLAGS, O_RDWR, 0600)) )
{
diff --git a/source3/registry/reg_backend_hkpt_params.c b/source3/registry/reg_backend_hkpt_params.c
new file mode 100644
index 0000000000..2ed5e78e1c
--- /dev/null
+++ b/source3/registry/reg_backend_hkpt_params.c
@@ -0,0 +1,70 @@
+/*
+ * Unix SMB/CIFS implementation.
+ * Virtual Windows Registry Layer
+ * Copyright (C) Gerald Carter 2002-2005
+ * Copyright (C) Michael Adam 2008
+ *
+ * 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/>.
+ */
+
+/*
+ * HKPT parameters registry backend.
+ *
+ * This replaces the former dynamic hkpt parameters overlay.
+ */
+
+#include "includes.h"
+
+#undef DBGC_CLASS
+#define DBGC_CLASS DBGC_REGISTRY
+
+extern REGISTRY_OPS regdb_ops;
+
+static int hkpt_params_fetch_values(const char *key, REGVAL_CTR *regvals)
+{
+ uint32 base_index;
+ uint32 buffer_size;
+ char *buffer = NULL;
+
+ /* This is ALMOST the same as perflib_009_params, but HKPT has
+ a "Counters" entry instead of a "Counter" key. <Grrrr> */
+
+ base_index = reg_perfcount_get_base_index();
+ buffer_size = reg_perfcount_get_counter_names(base_index, &buffer);
+ regval_ctr_addvalue(regvals, "Counters", REG_MULTI_SZ, buffer,
+ buffer_size);
+
+ if(buffer_size > 0) {
+ SAFE_FREE(buffer);
+ }
+
+ buffer_size = reg_perfcount_get_counter_help(base_index, &buffer);
+ regval_ctr_addvalue(regvals, "Help", REG_MULTI_SZ, buffer, buffer_size);
+ if(buffer_size > 0) {
+ SAFE_FREE(buffer);
+ }
+
+ return regval_ctr_numvals( regvals );
+}
+
+static int hkpt_params_fetch_subkeys(const char *key,
+ REGSUBKEY_CTR *subkey_ctr)
+{
+ return regdb_ops.fetch_subkeys(key, subkey_ctr);
+}
+
+REGISTRY_OPS hkpt_params_reg_ops = {
+ .fetch_values = hkpt_params_fetch_values,
+ .fetch_subkeys = hkpt_params_fetch_subkeys,
+};
diff --git a/source3/registry/reg_backend_netlogon_params.c b/source3/registry/reg_backend_netlogon_params.c
new file mode 100644
index 0000000000..71f88144c8
--- /dev/null
+++ b/source3/registry/reg_backend_netlogon_params.c
@@ -0,0 +1,57 @@
+/*
+ * Unix SMB/CIFS implementation.
+ * Virtual Windows Registry Layer
+ * Copyright (C) Gerald Carter 2002-2005
+ * Copyright (C) Michael Adam 2008
+ *
+ * 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/>.
+ */
+
+/*
+ * Netlogon parameters registry backend.
+ *
+ * This replaces the former dynamic netlogon parameters overlay.
+ */
+
+#include "includes.h"
+
+#undef DBGC_CLASS
+#define DBGC_CLASS DBGC_REGISTRY
+
+extern REGISTRY_OPS regdb_ops;
+
+static int netlogon_params_fetch_values(const char *key, REGVAL_CTR *regvals)
+{
+ uint32 dwValue;
+
+ if (!pdb_get_account_policy(AP_REFUSE_MACHINE_PW_CHANGE, &dwValue)) {
+ dwValue = 0;
+ }
+
+ regval_ctr_addvalue(regvals, "RefusePasswordChange", REG_DWORD,
+ (char*)&dwValue, sizeof(dwValue));
+
+ return regval_ctr_numvals(regvals);
+}
+
+static int netlogon_params_fetch_subkeys(const char *key,
+ REGSUBKEY_CTR *subkey_ctr)
+{
+ return regdb_ops.fetch_subkeys(key, subkey_ctr);
+}
+
+REGISTRY_OPS netlogon_params_reg_ops = {
+ .fetch_values = netlogon_params_fetch_values,
+ .fetch_subkeys = netlogon_params_fetch_subkeys,
+};
diff --git a/source3/registry/reg_backend_perflib.c b/source3/registry/reg_backend_perflib.c
new file mode 100644
index 0000000000..999bca2682
--- /dev/null
+++ b/source3/registry/reg_backend_perflib.c
@@ -0,0 +1,106 @@
+/*
+ * Unix SMB/CIFS implementation.
+ * Virtual Windows Registry Layer
+ * Copyright (C) Gerald Carter 2002-2005
+ * Copyright (C) Michael Adam 2008
+ *
+ * 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/>.
+ */
+
+/*
+ * perflib registry backend.
+ *
+ * This is a virtual overlay, dynamically presenting perflib values.
+ */
+
+#include "includes.h"
+
+#undef DBGC_CLASS
+#define DBGC_CLASS DBGC_REGISTRY
+
+extern REGISTRY_OPS regdb_ops;
+
+#define KEY_PERFLIB_NORM "HKLM/SOFTWARE/MICROSOFT/WINDOWS NT/CURRENTVERSION/PERFLIB"
+#define KEY_PERFLIB_009_NORM "HKLM/SOFTWARE/MICROSOFT/WINDOWS NT/CURRENTVERSION/PERFLIB/009"
+
+static int perflib_params( REGVAL_CTR *regvals )
+{
+ int base_index = -1;
+ int last_counter = -1;
+ int last_help = -1;
+ int version = 0x00010001;
+
+ base_index = reg_perfcount_get_base_index();
+ regval_ctr_addvalue(regvals, "Base Index", REG_DWORD, (char *)&base_index, sizeof(base_index));
+ last_counter = reg_perfcount_get_last_counter(base_index);
+ regval_ctr_addvalue(regvals, "Last Counter", REG_DWORD, (char *)&last_counter, sizeof(last_counter));
+ last_help = reg_perfcount_get_last_help(last_counter);
+ regval_ctr_addvalue(regvals, "Last Help", REG_DWORD, (char *)&last_help, sizeof(last_help));
+ regval_ctr_addvalue(regvals, "Version", REG_DWORD, (char *)&version, sizeof(version));
+
+ return regval_ctr_numvals( regvals );
+}
+
+static int perflib_009_params( REGVAL_CTR *regvals )
+{
+ int base_index;
+ int buffer_size;
+ char *buffer = NULL;
+
+ base_index = reg_perfcount_get_base_index();
+ buffer_size = reg_perfcount_get_counter_names(base_index, &buffer);
+ regval_ctr_addvalue(regvals, "Counter", REG_MULTI_SZ, buffer, buffer_size);
+ if(buffer_size > 0)
+ SAFE_FREE(buffer);
+ buffer_size = reg_perfcount_get_counter_help(base_index, &buffer);
+ regval_ctr_addvalue(regvals, "Help", REG_MULTI_SZ, buffer, buffer_size);
+ if(buffer_size > 0)
+ SAFE_FREE(buffer);
+
+ return regval_ctr_numvals( regvals );
+}
+
+static int perflib_fetch_values(const char *key, REGVAL_CTR *regvals)
+{
+ char *path = NULL;
+ TALLOC_CTX *ctx = talloc_tos();
+
+ path = talloc_strdup(ctx, key);
+ if (path == NULL) {
+ return -1;
+ }
+ path = normalize_reg_path(ctx, path);
+ if (path == NULL) {
+ return -1;
+ }
+
+ if (strncmp(path, KEY_PERFLIB_NORM, strlen(path)) == 0) {
+ return perflib_params(regvals);
+ } else if (strncmp(path, KEY_PERFLIB_009_NORM, strlen(path)) == 0) {
+ return perflib_009_params(regvals);
+ } else {
+ return 0;
+ }
+}
+
+static int perflib_fetch_subkeys(const char *key,
+ REGSUBKEY_CTR *subkey_ctr)
+{
+ return regdb_ops.fetch_subkeys(key, subkey_ctr);
+}
+
+REGISTRY_OPS perflib_reg_ops = {
+ .fetch_values = perflib_fetch_values,
+ .fetch_subkeys = perflib_fetch_subkeys,
+};
diff --git a/source3/registry/reg_printing.c b/source3/registry/reg_backend_printing.c
index 5be0796002..a4da103d40 100644
--- a/source3/registry/reg_printing.c
+++ b/source3/registry/reg_backend_printing.c
@@ -1262,9 +1262,8 @@ static bool regprint_store_reg_values( const char *key, REGVAL_CTR *values )
*/
REGISTRY_OPS printing_ops = {
- regprint_fetch_reg_keys,
- regprint_fetch_reg_values,
- regprint_store_reg_keys,
- regprint_store_reg_values,
- NULL, NULL, NULL, NULL, NULL
+ .fetch_subkeys = regprint_fetch_reg_keys,
+ .fetch_values = regprint_fetch_reg_values,
+ .store_subkeys = regprint_store_reg_keys,
+ .store_values = regprint_store_reg_values,
};
diff --git a/source3/registry/reg_backend_prod_options.c b/source3/registry/reg_backend_prod_options.c
new file mode 100644
index 0000000000..7ac5c5b4b9
--- /dev/null
+++ b/source3/registry/reg_backend_prod_options.c
@@ -0,0 +1,70 @@
+/*
+ * Unix SMB/CIFS implementation.
+ * Virtual Windows Registry Layer
+ * Copyright (C) Gerald Carter 2002-2005
+ * Copyright (C) Michael Adam 2008
+ *
+ * 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/>.
+ */
+
+/*
+ * Product options registry backend.
+ *
+ * This replaces the former dynamic product options overlay.
+ */
+
+#include "includes.h"
+
+#undef DBGC_CLASS
+#define DBGC_CLASS DBGC_REGISTRY
+
+extern REGISTRY_OPS regdb_ops;
+
+static int prod_options_fetch_values(const char *key, REGVAL_CTR *regvals)
+{
+ const char *value_ascii = "";
+ fstring value;
+ int value_length;
+
+ switch (lp_server_role()) {
+ case ROLE_DOMAIN_PDC:
+ case ROLE_DOMAIN_BDC:
+ value_ascii = "LanmanNT";
+ break;
+ case ROLE_STANDALONE:
+ value_ascii = "ServerNT";
+ break;
+ case ROLE_DOMAIN_MEMBER:
+ value_ascii = "WinNT";
+ break;
+ }
+
+ value_length = push_ucs2(value, value, value_ascii, sizeof(value),
+ STR_TERMINATE|STR_NOALIGN );
+ regval_ctr_addvalue(regvals, "ProductType", REG_SZ, value,
+ value_length);
+
+ return regval_ctr_numvals( regvals );
+}
+
+static int prod_options_fetch_subkeys(const char *key,
+ REGSUBKEY_CTR *subkey_ctr)
+{
+ return regdb_ops.fetch_subkeys(key, subkey_ctr);
+}
+
+REGISTRY_OPS prod_options_reg_ops = {
+ .fetch_values = prod_options_fetch_values,
+ .fetch_subkeys = prod_options_fetch_subkeys,
+};
diff --git a/source3/registry/reg_shares.c b/source3/registry/reg_backend_shares.c
index 4ac6e1d151..ee9e5dc5a1 100644
--- a/source3/registry/reg_shares.c
+++ b/source3/registry/reg_backend_shares.c
@@ -155,11 +155,10 @@ static bool shares_store_value( const char *key, REGVAL_CTR *val )
*/
REGISTRY_OPS shares_reg_ops = {
- shares_subkey_info,
- shares_value_info,
- shares_store_subkey,
- shares_store_value,
- NULL, NULL, NULL, NULL, NULL
+ .fetch_subkeys = shares_subkey_info,
+ .fetch_values = shares_value_info,
+ .store_subkeys = shares_store_subkey,
+ .store_values = shares_store_value,
};
diff --git a/source3/registry/reg_smbconf.c b/source3/registry/reg_backend_smbconf.c
index 8dfb745a7e..a6e478200f 100644
--- a/source3/registry/reg_smbconf.c
+++ b/source3/registry/reg_backend_smbconf.c
@@ -265,13 +265,11 @@ static WERROR smbconf_set_secdesc(const char *key,
*/
REGISTRY_OPS smbconf_reg_ops = {
- smbconf_fetch_keys,
- smbconf_fetch_values,
- smbconf_store_keys,
- smbconf_store_values,
- smbconf_reg_access_check,
- smbconf_get_secdesc,
- smbconf_set_secdesc,
- NULL,
- NULL
+ .fetch_subkeys = smbconf_fetch_keys,
+ .fetch_values = smbconf_fetch_values,
+ .store_subkeys = smbconf_store_keys,
+ .store_values = smbconf_store_values,
+ .reg_access_check = smbconf_reg_access_check,
+ .get_secdesc = smbconf_get_secdesc,
+ .set_secdesc = smbconf_set_secdesc,
};
diff --git a/source3/registry/reg_backend_tcpip_params.c b/source3/registry/reg_backend_tcpip_params.c
new file mode 100644
index 0000000000..db7df5dd8f
--- /dev/null
+++ b/source3/registry/reg_backend_tcpip_params.c
@@ -0,0 +1,67 @@
+/*
+ * Unix SMB/CIFS implementation.
+ * Virtual Windows Registry Layer
+ * Copyright (C) Gerald Carter 2002-2005
+ * Copyright (C) Michael Adam 2008
+ *
+ * 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/>.
+ */
+
+/*
+ * TCP/IP parameters registry backend.
+ *
+ * This replaces the former dynamic tcpip parameters overlay.
+ */
+
+#include "includes.h"
+
+#undef DBGC_CLASS
+#define DBGC_CLASS DBGC_REGISTRY
+
+extern REGISTRY_OPS regdb_ops;
+
+static int tcpip_params_fetch_values(const char *key, REGVAL_CTR *regvals)
+{
+ fstring value;
+ int value_length;
+ char *hname;
+ char *mydomainname = NULL;
+
+ hname = myhostname();
+ value_length = push_ucs2(value, value, hname, sizeof(value),
+ STR_TERMINATE|STR_NOALIGN);
+ regval_ctr_addvalue(regvals, "Hostname",REG_SZ, value, value_length);
+
+ mydomainname = get_mydnsdomname(talloc_tos());
+ if (!mydomainname) {
+ return -1;
+ }
+
+ value_length = push_ucs2(value, value, mydomainname, sizeof(value),
+ STR_TERMINATE|STR_NOALIGN);
+ regval_ctr_addvalue(regvals, "Domain", REG_SZ, value, value_length);
+
+ return regval_ctr_numvals(regvals);
+}
+
+static int tcpip_params_fetch_subkeys(const char *key,
+ REGSUBKEY_CTR *subkey_ctr)
+{
+ return regdb_ops.fetch_subkeys(key, subkey_ctr);
+}
+
+REGISTRY_OPS tcpip_params_reg_ops = {
+ .fetch_values = tcpip_params_fetch_values,
+ .fetch_subkeys = tcpip_params_fetch_subkeys,
+};
diff --git a/source3/registry/reg_cachehook.c b/source3/registry/reg_cachehook.c
index 74670aac30..f9851c7810 100644
--- a/source3/registry/reg_cachehook.c
+++ b/source3/registry/reg_cachehook.c
@@ -37,6 +37,11 @@ bool reghook_cache_init( void )
{
if (cache_tree == NULL) {
cache_tree = pathtree_init(&default_hook, NULL);
+ if (cache_tree !=0) {
+ DEBUG(10, ("reghook_cache_init: new tree with default "
+ "ops %p for key [%s]\n", (void *)&regdb_ops,
+ KEY_TREE_ROOT));
+ }
}
return (cache_tree != NULL);
@@ -56,7 +61,7 @@ bool reghook_cache_add( REGISTRY_HOOK *hook )
return false;
}
- key = talloc_asprintf(ctx, "//%s", hook->keyname);
+ key = talloc_asprintf(ctx, "\\%s", hook->keyname);
if (!key) {
return false;
}
@@ -65,7 +70,8 @@ bool reghook_cache_add( REGISTRY_HOOK *hook )
return false;
}
- DEBUG(10,("reghook_cache_add: Adding key [%s]\n", key));
+ DEBUG(10, ("reghook_cache_add: Adding ops %p for key [%s]\n",
+ (void *)hook->ops, key));
return pathtree_add( cache_tree, key, hook );
}
@@ -102,6 +108,9 @@ REGISTRY_HOOK* reghook_cache_find( const char *keyname )
DEBUG(10,("reghook_cache_find: Searching for keyname [%s]\n", key));
hook = (REGISTRY_HOOK *)pathtree_find( cache_tree, key ) ;
+
+ DEBUG(10, ("reghook_cache_find: found ops %p for key [%s]\n",
+ hook ? (void *)hook->ops : 0, key));
SAFE_FREE( key );
diff --git a/source3/registry/reg_frontend_hilvl.c b/source3/registry/reg_dispatcher.c
index 73fcf87e17..cdcd045904 100644
--- a/source3/registry/reg_frontend_hilvl.c
+++ b/source3/registry/reg_dispatcher.c
@@ -1,25 +1,25 @@
-/*
+/*
* Unix SMB/CIFS implementation.
* Virtual Windows Registry Layer
* Copyright (C) Gerald Carter 2002-2005
- * Copyright (C) Michael Adam 2006
+ * Copyright (C) Michael Adam 2006-2008
*
* 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/>.
*/
-/*
- * Implementation of registry frontend view functions.
+/*
+ * Implementation of registry frontend view functions.
* Functions moved from reg_frontend.c to minimize linker deps.
*/
@@ -34,7 +34,7 @@ static const struct generic_mapping reg_generic_map =
/********************************************************************
********************************************************************/
-static SEC_DESC* construct_registry_sd( TALLOC_CTX *ctx )
+static WERROR construct_registry_sd(TALLOC_CTX *ctx, SEC_DESC **psd)
{
SEC_ACE ace[3];
SEC_ACCESS mask;
@@ -44,58 +44,64 @@ static SEC_DESC* construct_registry_sd( TALLOC_CTX *ctx )
size_t sd_size;
/* basic access for Everyone */
-
- init_sec_access(&mask, REG_KEY_READ );
- init_sec_ace(&ace[i++], &global_sid_World, SEC_ACE_TYPE_ACCESS_ALLOWED, mask, 0);
-
+
+ init_sec_access(&mask, REG_KEY_READ);
+ init_sec_ace(&ace[i++], &global_sid_World, SEC_ACE_TYPE_ACCESS_ALLOWED,
+ mask, 0);
+
/* Full Access 'BUILTIN\Administrators' */
-
- init_sec_access(&mask, REG_KEY_ALL );
- init_sec_ace(&ace[i++], &global_sid_Builtin_Administrators, SEC_ACE_TYPE_ACCESS_ALLOWED, mask, 0);
+
+ init_sec_access(&mask, REG_KEY_ALL);
+ init_sec_ace(&ace[i++], &global_sid_Builtin_Administrators,
+ SEC_ACE_TYPE_ACCESS_ALLOWED, mask, 0);
/* Full Access 'NT Authority\System' */
init_sec_access(&mask, REG_KEY_ALL );
- init_sec_ace(&ace[i++], &global_sid_System, SEC_ACE_TYPE_ACCESS_ALLOWED, mask, 0);
+ init_sec_ace(&ace[i++], &global_sid_System, SEC_ACE_TYPE_ACCESS_ALLOWED,
+ mask, 0);
-
/* create the security descriptor */
-
- if ( !(acl = make_sec_acl(ctx, NT4_ACL_REVISION, i, ace)) )
- return NULL;
- if ( !(sd = make_sec_desc(ctx, SEC_DESC_REVISION, SEC_DESC_SELF_RELATIVE, NULL, NULL, NULL, acl, &sd_size)) )
- return NULL;
+ acl = make_sec_acl(ctx, NT4_ACL_REVISION, i, ace);
+ if (acl == NULL) {
+ return WERR_NOMEM;
+ }
+
+ sd = make_sec_desc(ctx, SEC_DESC_REVISION, SEC_DESC_SELF_RELATIVE,
+ &global_sid_Builtin_Administrators,
+ &global_sid_System, NULL, acl,
+ &sd_size);
+ if (sd == NULL) {
+ return WERR_NOMEM;
+ }
- return sd;
+ *psd = sd;
+ return WERR_OK;
}
/***********************************************************************
High level wrapper function for storing registry subkeys
***********************************************************************/
-
+
bool store_reg_keys( REGISTRY_KEY *key, REGSUBKEY_CTR *subkeys )
{
if ( key->hook && key->hook->ops && key->hook->ops->store_subkeys )
return key->hook->ops->store_subkeys( key->name, subkeys );
-
- return False;
+ return false;
}
/***********************************************************************
High level wrapper function for storing registry values
***********************************************************************/
-
+
bool store_reg_values( REGISTRY_KEY *key, REGVAL_CTR *val )
{
- if ( check_dynamic_reg_values( key ) )
- return False;
-
if ( key->hook && key->hook->ops && key->hook->ops->store_values )
return key->hook->ops->store_values( key->name, val );
- return False;
+ return false;
}
/***********************************************************************
@@ -106,7 +112,7 @@ bool store_reg_values( REGISTRY_KEY *key, REGVAL_CTR *val )
int fetch_reg_keys( REGISTRY_KEY *key, REGSUBKEY_CTR *subkey_ctr )
{
int result = -1;
-
+
if ( key->hook && key->hook->ops && key->hook->ops->fetch_subkeys )
result = key->hook->ops->fetch_subkeys( key->name, subkey_ctr );
@@ -120,23 +126,18 @@ int fetch_reg_keys( REGISTRY_KEY *key, REGSUBKEY_CTR *subkey_ctr )
int fetch_reg_values( REGISTRY_KEY *key, REGVAL_CTR *val )
{
int result = -1;
-
+
+ DEBUG(10, ("fetch_reg_values called for key '%s' (ops %p)\n", key->name,
+ (key->hook && key->hook->ops) ? (void *)key->hook->ops : NULL));
+
if ( key->hook && key->hook->ops && key->hook->ops->fetch_values )
result = key->hook->ops->fetch_values( key->name, val );
-
- /* if the backend lookup returned no data, try the dynamic overlay */
-
- if ( result == 0 ) {
- result = fetch_dynamic_reg_values( key, val );
- return ( result != -1 ) ? result : 0;
- }
-
return result;
}
/***********************************************************************
- High level access check for passing the required access mask to the
+ High level access check for passing the required access mask to the
underlying registry backend
***********************************************************************/
@@ -161,21 +162,21 @@ bool regkey_access_check( REGISTRY_KEY *key, uint32 requested, uint32 *granted,
*/
if (!(mem_ctx = talloc_init("regkey_access_check"))) {
- return False;
+ return false;
}
err = regkey_get_secdesc(mem_ctx, key, &sec_desc);
if (!W_ERROR_IS_OK(err)) {
TALLOC_FREE(mem_ctx);
- return False;
+ return false;
}
se_map_generic( &requested, &reg_generic_map );
if (!se_access_check(sec_desc, token, requested, granted, &status)) {
TALLOC_FREE(mem_ctx);
- return False;
+ return false;
}
TALLOC_FREE(mem_ctx);
@@ -186,19 +187,19 @@ WERROR regkey_get_secdesc(TALLOC_CTX *mem_ctx, REGISTRY_KEY *key,
struct security_descriptor **psecdesc)
{
struct security_descriptor *secdesc;
+ WERROR werr;
if (key->hook && key->hook->ops && key->hook->ops->get_secdesc) {
- WERROR err;
-
- err = key->hook->ops->get_secdesc(mem_ctx, key->name,
- psecdesc);
- if (W_ERROR_IS_OK(err)) {
+ werr = key->hook->ops->get_secdesc(mem_ctx, key->name,
+ psecdesc);
+ if (W_ERROR_IS_OK(werr)) {
return WERR_OK;
}
}
- if (!(secdesc = construct_registry_sd(mem_ctx))) {
- return WERR_NOMEM;
+ werr = construct_registry_sd(mem_ctx, &secdesc);
+ if (!W_ERROR_IS_OK(werr)) {
+ return werr;
}
*psecdesc = secdesc;
diff --git a/source3/registry/reg_dynamic.c b/source3/registry/reg_dynamic.c
deleted file mode 100644
index e70bd178f9..0000000000
--- a/source3/registry/reg_dynamic.c
+++ /dev/null
@@ -1,264 +0,0 @@
-/*
- * Unix SMB/CIFS implementation.
- * Virtual Windows Registry Layer
- * Copyright (C) Gerald Carter 2002-2005
- *
- * 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/>.
- */
-
-/* Implementation of registry frontend view functions. */
-
-#include "includes.h"
-
-#undef DBGC_CLASS
-#define DBGC_CLASS DBGC_REGISTRY
-
-struct reg_dyn_values {
- const char *path;
- int (*fetch_values) ( REGVAL_CTR *val );
-};
-
-/***********************************************************************
-***********************************************************************/
-
-static int netlogon_params( REGVAL_CTR *regvals )
-{
- uint32 dwValue;
-
- if ( !pdb_get_account_policy(AP_REFUSE_MACHINE_PW_CHANGE, &dwValue) )
- dwValue = 0;
-
- regval_ctr_addvalue( regvals, "RefusePasswordChange", REG_DWORD,
- (char*)&dwValue, sizeof(dwValue) );
-
- return regval_ctr_numvals( regvals );
-}
-
-/***********************************************************************
-***********************************************************************/
-
-static int prod_options( REGVAL_CTR *regvals )
-{
- const char *value_ascii = "";
- fstring value;
- int value_length;
-
- switch (lp_server_role()) {
- case ROLE_DOMAIN_PDC:
- case ROLE_DOMAIN_BDC:
- value_ascii = "LanmanNT";
- break;
- case ROLE_STANDALONE:
- value_ascii = "ServerNT";
- break;
- case ROLE_DOMAIN_MEMBER:
- value_ascii = "WinNT";
- break;
- }
-
- value_length = push_ucs2( value, value, value_ascii, sizeof(value),
- STR_TERMINATE|STR_NOALIGN );
- regval_ctr_addvalue( regvals, "ProductType", REG_SZ, value,
- value_length );
-
- return regval_ctr_numvals( regvals );
-}
-
-/***********************************************************************
-***********************************************************************/
-
-static int tcpip_params( REGVAL_CTR *regvals )
-{
- fstring value;
- int value_length;
- char *hname;
- char *mydomainname = NULL;
-
- hname = myhostname();
- value_length = push_ucs2( value, value, hname, sizeof(value), STR_TERMINATE|STR_NOALIGN);
- regval_ctr_addvalue( regvals, "Hostname",REG_SZ, value, value_length );
-
- mydomainname = get_mydnsdomname(talloc_tos());
- if (!mydomainname) {
- return -1;
- }
-
- value_length = push_ucs2( value, value, mydomainname, sizeof(value), STR_TERMINATE|STR_NOALIGN);
- regval_ctr_addvalue( regvals, "Domain", REG_SZ, value, value_length );
-
- return regval_ctr_numvals( regvals );
-}
-
-/***********************************************************************
-***********************************************************************/
-
-static int perflib_params( REGVAL_CTR *regvals )
-{
- int base_index = -1;
- int last_counter = -1;
- int last_help = -1;
- int version = 0x00010001;
-
- base_index = reg_perfcount_get_base_index();
- regval_ctr_addvalue(regvals, "Base Index", REG_DWORD, (char *)&base_index, sizeof(base_index));
- last_counter = reg_perfcount_get_last_counter(base_index);
- regval_ctr_addvalue(regvals, "Last Counter", REG_DWORD, (char *)&last_counter, sizeof(last_counter));
- last_help = reg_perfcount_get_last_help(last_counter);
- regval_ctr_addvalue(regvals, "Last Help", REG_DWORD, (char *)&last_help, sizeof(last_help));
- regval_ctr_addvalue(regvals, "Version", REG_DWORD, (char *)&version, sizeof(version));
-
- return regval_ctr_numvals( regvals );
-}
-
-/***********************************************************************
-***********************************************************************/
-
-static int perflib_009_params( REGVAL_CTR *regvals )
-{
- int base_index;
- int buffer_size;
- char *buffer = NULL;
-
- base_index = reg_perfcount_get_base_index();
- buffer_size = reg_perfcount_get_counter_names(base_index, &buffer);
- regval_ctr_addvalue(regvals, "Counter", REG_MULTI_SZ, buffer, buffer_size);
- if(buffer_size > 0)
- SAFE_FREE(buffer);
- buffer_size = reg_perfcount_get_counter_help(base_index, &buffer);
- regval_ctr_addvalue(regvals, "Help", REG_MULTI_SZ, buffer, buffer_size);
- if(buffer_size > 0)
- SAFE_FREE(buffer);
-
- return regval_ctr_numvals( regvals );
-}
-
-/***********************************************************************
-***********************************************************************/
-
-static int hkpt_params( REGVAL_CTR *regvals )
-{
- uint32 base_index;
- uint32 buffer_size;
- char *buffer = NULL;
-
- /* This is ALMOST the same as perflib_009_params, but HKPT has
- a "Counters" entry instead of a "Counter" key. <Grrrr> */
-
- base_index = reg_perfcount_get_base_index();
- buffer_size = reg_perfcount_get_counter_names(base_index, &buffer);
- regval_ctr_addvalue(regvals, "Counters", REG_MULTI_SZ, buffer, buffer_size);
-
- if(buffer_size > 0)
- SAFE_FREE(buffer);
-
- buffer_size = reg_perfcount_get_counter_help(base_index, &buffer);
- regval_ctr_addvalue(regvals, "Help", REG_MULTI_SZ, buffer, buffer_size);
- if(buffer_size > 0)
- SAFE_FREE(buffer);
-
- return regval_ctr_numvals( regvals );
-}
-
-/***********************************************************************
-***********************************************************************/
-
-static int current_version( REGVAL_CTR *values )
-{
- const char *sysroot_string = "c:\\Windows";
- fstring sysversion;
- fstring value;
- uint32 value_length;
-
- value_length = push_ucs2( value, value, sysroot_string, sizeof(value),
- STR_TERMINATE|STR_NOALIGN );
- regval_ctr_addvalue( values, "SystemRoot", REG_SZ, value, value_length );
-
- fstr_sprintf( sysversion, "%d.%d", lp_major_announce_version(), lp_minor_announce_version() );
- value_length = push_ucs2( value, value, sysversion, sizeof(value),
- STR_TERMINATE|STR_NOALIGN );
- regval_ctr_addvalue( values, "CurrentVersion", REG_SZ, value, value_length );
-
-
- return regval_ctr_numvals( values );
-}
-
-
-/***********************************************************************
- Structure holding the registry paths and pointers to the value
- enumeration functions
-***********************************************************************/
-
-static struct reg_dyn_values dynamic_values[] = {
- { "HKLM/SYSTEM/CURRENTCONTROLSET/SERVICES/NETLOGON/PARAMETERS", &netlogon_params },
- { "HKLM/SYSTEM/CURRENTCONTROLSET/CONTROL/PRODUCTOPTIONS", &prod_options },
- { "HKLM/SYSTEM/CURRENTCONTROLSET/SERVICES/TCPIP/PARAMETERS", &tcpip_params },
- { "HKLM/SOFTWARE/MICROSOFT/WINDOWS NT/CURRENTVERSION/PERFLIB", &perflib_params },
- { "HKLM/SOFTWARE/MICROSOFT/WINDOWS NT/CURRENTVERSION/PERFLIB/009", &perflib_009_params },
- { "HKLM/SOFTWARE/MICROSOFT/WINDOWS NT/CURRENTVERSION", &current_version },
- { "HKPT", &hkpt_params },
- { NULL, NULL }
-};
-
-/***********************************************************************
-***********************************************************************/
-
-int fetch_dynamic_reg_values( REGISTRY_KEY *key, REGVAL_CTR *val )
-{
- int i;
- char *path = NULL;
- TALLOC_CTX *ctx = talloc_tos();
-
- path = talloc_strdup(ctx, key->name);
- if (!path) {
- return -1;
- }
- path = normalize_reg_path(ctx, path);
- if (!path) {
- return -1;
- }
-
- for ( i=0; dynamic_values[i].path; i++ ) {
- if ( strcmp( path, dynamic_values[i].path ) == 0 )
- return dynamic_values[i].fetch_values( val );
- }
-
- return -1;
-}
-
-/***********************************************************************
-***********************************************************************/
-
-bool check_dynamic_reg_values( REGISTRY_KEY *key )
-{
- int i;
- char *path = NULL;
- TALLOC_CTX *ctx = talloc_tos();
-
- path = talloc_strdup(ctx, key->name);
- if (!path) {
- return false;
- }
- path = normalize_reg_path(ctx, path);
- if (!path) {
- return false;
- }
-
- for ( i=0; dynamic_values[i].path; i++ ) {
- /* can't write to dynamic keys */
- if ( strcmp( path, dynamic_values[i].path ) == 0 )
- return true;
- }
-
- return false;
-}
diff --git a/source3/registry/reg_frontend.c b/source3/registry/reg_frontend.c
deleted file mode 100644
index 40d9192b08..0000000000
--- a/source3/registry/reg_frontend.c
+++ /dev/null
@@ -1,202 +0,0 @@
-/*
- * Unix SMB/CIFS implementation.
- * Virtual Windows Registry Layer
- * Copyright (C) Gerald Carter 2002-2005
- *
- * 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/>.
- */
-
-/* Implementation of registry frontend view functions. */
-
-#include "includes.h"
-
-#undef DBGC_CLASS
-#define DBGC_CLASS DBGC_REGISTRY
-
-extern REGISTRY_OPS printing_ops;
-extern REGISTRY_OPS eventlog_ops;
-extern REGISTRY_OPS shares_reg_ops;
-extern REGISTRY_OPS smbconf_reg_ops;
-extern REGISTRY_OPS regdb_ops; /* these are the default */
-
-/* array of REGISTRY_HOOK's which are read into a tree for easy access */
-/* #define REG_TDB_ONLY 1 */
-
-REGISTRY_HOOK reg_hooks[] = {
-#ifndef REG_TDB_ONLY
- { KEY_PRINTING, &printing_ops },
- { KEY_PRINTING_2K, &printing_ops },
- { KEY_PRINTING_PORTS, &printing_ops },
- { KEY_SHARES, &shares_reg_ops },
- { KEY_SMBCONF, &smbconf_reg_ops },
-#endif
- { NULL, NULL }
-};
-
-/***********************************************************************
- Open the registry database and initialize the REGISTRY_HOOK cache
- ***********************************************************************/
-
-bool init_registry( void )
-{
- int i;
- bool ret = false;
- TALLOC_CTX *frame = talloc_stackframe();
-
-
- if ( !regdb_init() ) {
- DEBUG(0,("init_registry: failed to initialize the registry tdb!\n"));
- goto fail;
- }
-
- /* build the cache tree of registry hooks */
-
- reghook_cache_init();
-
- for ( i=0; reg_hooks[i].keyname; i++ ) {
- if ( !reghook_cache_add(&reg_hooks[i]) )
- goto fail;
- }
-
- if ( DEBUGLEVEL >= 20 )
- reghook_dump_cache(20);
-
- /* add any keys for other services */
-
- svcctl_init_keys();
- eventlog_init_keys();
- perfcount_init_keys();
-
- /* close and let each smbd open up as necessary */
-
- regdb_close();
-
- ret = true;
- fail:
- TALLOC_FREE(frame);
- return ret;
-}
-
-WERROR regkey_open_internal( TALLOC_CTX *ctx, REGISTRY_KEY **regkey,
- const char *path,
- const struct nt_user_token *token,
- uint32 access_desired )
-{
- struct registry_key *key;
- WERROR err;
-
- err = reg_open_path(NULL, path, access_desired, token, &key);
- if (!W_ERROR_IS_OK(err)) {
- return err;
- }
-
- *regkey = talloc_move(ctx, &key->key);
- TALLOC_FREE(key);
- return WERR_OK;
-}
-
-/*
- * Utility function to create a registry key without opening the hive
- * before. Assumes the hive already exists.
- */
-
-WERROR reg_create_path(TALLOC_CTX *mem_ctx, const char *orig_path,
- uint32 desired_access,
- const struct nt_user_token *token,
- enum winreg_CreateAction *paction,
- struct registry_key **pkey)
-{
- struct registry_key *hive;
- char *path, *p;
- WERROR err;
-
- if (!(path = SMB_STRDUP(orig_path))) {
- return WERR_NOMEM;
- }
-
- p = strchr(path, '\\');
-
- if ((p == NULL) || (p[1] == '\0')) {
- /*
- * No key behind the hive, just return the hive
- */
-
- err = reg_openhive(mem_ctx, path, desired_access, token,
- &hive);
- if (!W_ERROR_IS_OK(err)) {
- SAFE_FREE(path);
- return err;
- }
- SAFE_FREE(path);
- *pkey = hive;
- *paction = REG_OPENED_EXISTING_KEY;
- return WERR_OK;
- }
-
- *p = '\0';
-
- err = reg_openhive(mem_ctx, path,
- (strchr(p+1, '\\') != NULL) ?
- SEC_RIGHTS_ENUM_SUBKEYS : SEC_RIGHTS_CREATE_SUBKEY,
- token, &hive);
- if (!W_ERROR_IS_OK(err)) {
- SAFE_FREE(path);
- return err;
- }
-
- err = reg_createkey(mem_ctx, hive, p+1, desired_access, pkey, paction);
- SAFE_FREE(path);
- TALLOC_FREE(hive);
- return err;
-}
-
-/*
- * Utility function to create a registry key without opening the hive
- * before. Will not delete a hive.
- */
-
-WERROR reg_delete_path(const struct nt_user_token *token,
- const char *orig_path)
-{
- struct registry_key *hive;
- char *path, *p;
- WERROR err;
-
- if (!(path = SMB_STRDUP(orig_path))) {
- return WERR_NOMEM;
- }
-
- p = strchr(path, '\\');
-
- if ((p == NULL) || (p[1] == '\0')) {
- SAFE_FREE(path);
- return WERR_INVALID_PARAM;
- }
-
- *p = '\0';
-
- err = reg_openhive(NULL, path,
- (strchr(p+1, '\\') != NULL) ?
- SEC_RIGHTS_ENUM_SUBKEYS : SEC_RIGHTS_CREATE_SUBKEY,
- token, &hive);
- if (!W_ERROR_IS_OK(err)) {
- SAFE_FREE(path);
- return err;
- }
-
- err = reg_deletekey(hive, p+1);
- SAFE_FREE(path);
- TALLOC_FREE(hive);
- return err;
-}
diff --git a/source3/registry/reg_init_full.c b/source3/registry/reg_init_full.c
new file mode 100644
index 0000000000..b6a644bb11
--- /dev/null
+++ b/source3/registry/reg_init_full.c
@@ -0,0 +1,103 @@
+/*
+ * Unix SMB/CIFS implementation.
+ * Virtual Windows Registry Layer
+ * Copyright (C) Gerald Carter 2002-2005
+ * Copyright (C) Michael Adam 2008
+ *
+ * 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/>.
+ */
+
+/* Initialize the registry with all available backends. */
+
+#include "includes.h"
+
+#undef DBGC_CLASS
+#define DBGC_CLASS DBGC_REGISTRY
+
+extern REGISTRY_OPS printing_ops;
+extern REGISTRY_OPS eventlog_ops;
+extern REGISTRY_OPS shares_reg_ops;
+extern REGISTRY_OPS smbconf_reg_ops;
+extern REGISTRY_OPS netlogon_params_reg_ops;
+extern REGISTRY_OPS prod_options_reg_ops;
+extern REGISTRY_OPS tcpip_params_reg_ops;
+extern REGISTRY_OPS hkpt_params_reg_ops;
+extern REGISTRY_OPS current_version_reg_ops;
+extern REGISTRY_OPS perflib_reg_ops;
+extern REGISTRY_OPS regdb_ops; /* these are the default */
+
+/* array of REGISTRY_HOOK's which are read into a tree for easy access */
+/* #define REG_TDB_ONLY 1 */
+
+REGISTRY_HOOK reg_hooks[] = {
+#ifndef REG_TDB_ONLY
+ { KEY_PRINTING, &printing_ops },
+ { KEY_PRINTING_2K, &printing_ops },
+ { KEY_PRINTING_PORTS, &printing_ops },
+ { KEY_SHARES, &shares_reg_ops },
+ { KEY_SMBCONF, &smbconf_reg_ops },
+ { KEY_NETLOGON_PARAMS, &netlogon_params_reg_ops },
+ { KEY_PROD_OPTIONS, &prod_options_reg_ops },
+ { KEY_TCPIP_PARAMS, &tcpip_params_reg_ops },
+ { KEY_HKPT, &hkpt_params_reg_ops },
+ { KEY_CURRENT_VERSION, &current_version_reg_ops },
+ { KEY_PERFLIB, &perflib_reg_ops },
+#endif
+ { NULL, NULL }
+};
+
+/***********************************************************************
+ Open the registry database and initialize the REGISTRY_HOOK cache
+ with all available backens.
+ ***********************************************************************/
+
+bool init_registry( void )
+{
+ int i;
+ bool ret = false;
+ TALLOC_CTX *frame = talloc_stackframe();
+
+
+ if ( !regdb_init() ) {
+ DEBUG(0,("init_registry: failed to initialize the registry tdb!\n"));
+ goto fail;
+ }
+
+ /* build the cache tree of registry hooks */
+
+ reghook_cache_init();
+
+ for ( i=0; reg_hooks[i].keyname; i++ ) {
+ if ( !reghook_cache_add(&reg_hooks[i]) )
+ goto fail;
+ }
+
+ if ( DEBUGLEVEL >= 20 )
+ reghook_dump_cache(20);
+
+ /* add any keys for other services */
+
+ svcctl_init_keys();
+ eventlog_init_keys();
+ perfcount_init_keys();
+
+ /* close and let each smbd open up as necessary */
+
+ regdb_close();
+
+ ret = true;
+ fail:
+ TALLOC_FREE(frame);
+ return ret;
+}
diff --git a/source3/registry/reg_init_smbconf.c b/source3/registry/reg_init_smbconf.c
new file mode 100644
index 0000000000..b7e6add112
--- /dev/null
+++ b/source3/registry/reg_init_smbconf.c
@@ -0,0 +1,97 @@
+/*
+ * Unix SMB/CIFS implementation.
+ * Registry helper routines
+ * Copyright (C) Michael Adam 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/>.
+ */
+
+#include "includes.h"
+
+#undef DBGC_CLASS
+#define DBGC_CLASS DBGC_REGISTRY
+
+extern REGISTRY_OPS smbconf_reg_ops;
+
+/*
+ * create a fake token just with enough rights to
+ * locally access the registry:
+ *
+ * - builtin administrators sid
+ * - disk operators privilege
+ */
+NTSTATUS registry_create_admin_token(TALLOC_CTX *mem_ctx,
+ NT_USER_TOKEN **ptoken)
+{
+ NTSTATUS status;
+ NT_USER_TOKEN *token = NULL;
+
+ if (ptoken == NULL) {
+ return NT_STATUS_INVALID_PARAMETER;
+ }
+
+ token = TALLOC_ZERO_P(mem_ctx, NT_USER_TOKEN);
+ if (token == NULL) {
+ DEBUG(1, ("talloc failed\n"));
+ status = NT_STATUS_NO_MEMORY;
+ goto done;
+ }
+ token->privileges = se_disk_operators;
+ status = add_sid_to_array(token, &global_sid_Builtin_Administrators,
+ &token->user_sids, &token->num_sids);
+ if (!NT_STATUS_IS_OK(status)) {
+ DEBUG(1, ("Error adding builtin administrators sid "
+ "to fake token.\n"));
+ goto done;
+ }
+
+ *ptoken = token;
+
+done:
+ return status;
+}
+
+/*
+ * init the smbconf portion of the registry.
+ * for use in places where not the whole registry is needed,
+ * e.g. utils/net_conf.c and loadparm.c
+ */
+bool registry_init_smbconf(void)
+{
+ bool ret = false;
+ int saved_errno = 0;
+ static REGISTRY_HOOK smbconf_reg_hook = {KEY_SMBCONF, &smbconf_reg_ops};
+
+ DEBUG(10, ("registry_init_smbconf called\n"));
+
+ if (!regdb_init()) {
+ saved_errno = errno;
+ DEBUG(1, ("Can't open the registry"));
+ if (saved_errno) {
+ DEBUGADD(1, (": %s", strerror(saved_errno)));
+ }
+ DEBUGADD(1, (".\n"));
+ goto done;
+ }
+ reghook_cache_init();
+ if (!reghook_cache_add(&smbconf_reg_hook)) {
+ DEBUG(1, ("Error adding smbconf reghooks to reghook cache.\n"));
+ goto done;
+ }
+
+ ret = true;
+
+done:
+ return ret;
+}
diff --git a/source3/registry/reg_util_legacy.c b/source3/registry/reg_util_legacy.c
new file mode 100644
index 0000000000..3e68025ae9
--- /dev/null
+++ b/source3/registry/reg_util_legacy.c
@@ -0,0 +1,47 @@
+/*
+ * Unix SMB/CIFS implementation.
+ * Virtual Windows Registry Layer
+ * Copyright (C) Gerald Carter 2002-2005
+ *
+ * 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/>.
+ */
+
+/* Implementation of registry frontend view functions. */
+
+#include "includes.h"
+
+#undef DBGC_CLASS
+#define DBGC_CLASS DBGC_REGISTRY
+
+/**
+ * legacy open key function that should be replaced by uses of
+ * reg_open_path
+ */
+WERROR regkey_open_internal( TALLOC_CTX *ctx, REGISTRY_KEY **regkey,
+ const char *path,
+ const struct nt_user_token *token,
+ uint32 access_desired )
+{
+ struct registry_key *key;
+ WERROR err;
+
+ err = reg_open_path(NULL, path, access_desired, token, &key);
+ if (!W_ERROR_IS_OK(err)) {
+ return err;
+ }
+
+ *regkey = talloc_move(ctx, &key->key);
+ TALLOC_FREE(key);
+ return WERR_OK;
+}
diff --git a/source3/registry/regfio.c b/source3/registry/regfio.c
index 92077aa847..1c3aad7a25 100644
--- a/source3/registry/regfio.c
+++ b/source3/registry/regfio.c
@@ -1171,7 +1171,6 @@ out:
if ( !(rb->mem_ctx = talloc_init( "read_regf_block" )) ) {
regfio_close( rb );
- SAFE_FREE(rb);
return NULL;
}
@@ -1182,7 +1181,6 @@ out:
if ( (rb->fd = open(filename, flags, mode)) == -1 ) {
DEBUG(0,("regfio_open: failure to open %s (%s)\n", filename, strerror(errno)));
regfio_close( rb );
- SAFE_FREE(rb);
return NULL;
}
@@ -1192,7 +1190,6 @@ out:
if ( !init_regf_block( rb ) ) {
DEBUG(0,("regfio_open: Failed to read initial REGF block\n"));
regfio_close( rb );
- SAFE_FREE(rb);
return NULL;
}
@@ -1205,7 +1202,6 @@ out:
if ( !read_regf_block( rb ) ) {
DEBUG(0,("regfio_open: Failed to read initial REGF block\n"));
regfio_close( rb );
- SAFE_FREE(rb);
return NULL;
}
@@ -1234,7 +1230,7 @@ static void regfio_mem_free( REGF_FILE *file )
/* cleanup for a file opened for write */
- if ( file->open_flags & (O_WRONLY|O_RDWR) ) {
+ if ((file->fd != -1) && (file->open_flags & (O_WRONLY|O_RDWR))) {
prs_struct ps;
REGF_SK_REC *sk;