summaryrefslogtreecommitdiffstats
path: root/source3
diff options
context:
space:
mode:
authorVolker Lendecke <vlendec@samba.org>2006-12-03 17:16:45 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 12:16:21 -0500
commit61bd0c8e450b3638c38bc60eb31fc6a4488f3121 (patch)
tree1134e4c540231a0d497be3008cb788b7716450b2 /source3
parentb0a6049391d4aebcaa6e0370deb20651a07dcbe8 (diff)
downloadsamba-61bd0c8e450b3638c38bc60eb31fc6a4488f3121.tar.gz
samba-61bd0c8e450b3638c38bc60eb31fc6a4488f3121.tar.xz
samba-61bd0c8e450b3638c38bc60eb31fc6a4488f3121.zip
r20019: Replace one set of tricky code by calls to another set of tricky code:
Initializing the reg_db now uses reg_createkey and reg_setvalue. Volker (This used to be commit cab5ccbbe484795f13531726d68b978073262e33)
Diffstat (limited to 'source3')
-rw-r--r--source3/registry/reg_db.c165
-rw-r--r--source3/registry/reg_frontend.c32
-rw-r--r--source3/rpc_server/srv_srvsvc_nt.c10
3 files changed, 107 insertions, 100 deletions
diff --git a/source3/registry/reg_db.c b/source3/registry/reg_db.c
index 345193716e..e0838a2b71 100644
--- a/source3/registry/reg_db.c
+++ b/source3/registry/reg_db.c
@@ -41,6 +41,10 @@ static int tdb_refcount;
the reg_printing backend onto the last component of the path (see
KEY_PRINTING_2K in include/rpc_reg.h) --jerry */
+static const char *builtin_registry_hives[] = {
+ "HKLM", "HKU", "HKCR", "HKPD", "HKPT", NULL
+};
+
static const char *builtin_registry_paths[] = {
KEY_PRINTING_2K,
KEY_PRINTING_PORTS,
@@ -55,10 +59,6 @@ static const char *builtin_registry_paths[] = {
"HKLM\\SYSTEM\\CurrentControlSet\\Control\\Terminal Server\\DefaultUserConfiguration",
"HKLM\\SYSTEM\\CurrentControlSet\\Services\\TcpIp\\Parameters",
"HKLM\\SYSTEM\\CurrentControlSet\\Services\\Netlogon\\Parameters",
- "HKU",
- "HKCR",
- "HKPD",
- "HKPT",
NULL };
struct builtin_regkey_value {
@@ -91,105 +91,98 @@ static struct builtin_regkey_value builtin_registry_values[] = {
static BOOL init_registry_data( void )
{
- pstring path, base, remaining;
- fstring keyname, subkeyname;
- REGSUBKEY_CTR *subkeys;
- REGVAL_CTR *values;
int i;
- const char *p, *p2;
- UNISTR2 data;
+
+ for (i=0; builtin_registry_hives[i] != NULL; i++) {
+ REGSUBKEY_CTR *subkeys;
+
+ if (!(subkeys = TALLOC_ZERO_P(NULL, REGSUBKEY_CTR))) {
+ DEBUG(0, ("talloc failed\n"));
+ return False;
+ }
+ regdb_fetch_keys(builtin_registry_hives[i], subkeys);
+ if (!regdb_store_keys(builtin_registry_hives[i], subkeys)) {
+ TALLOC_FREE(subkeys);
+ return False;
+ }
+ TALLOC_FREE(subkeys);
+ }
/* loop over all of the predefined paths and add each component */
for ( i=0; builtin_registry_paths[i] != NULL; i++ ) {
-
- DEBUG(6,("init_registry_data: Adding [%s]\n", builtin_registry_paths[i]));
-
- pstrcpy( path, builtin_registry_paths[i] );
- pstrcpy( base, "" );
- p = path;
-
- while ( next_token(&p, keyname, "\\", sizeof(keyname)) ) {
-
- /* build up the registry path from the components */
-
- if ( *base )
- pstrcat( base, "\\" );
- pstrcat( base, keyname );
-
- /* get the immediate subkeyname (if we have one ) */
-
- *subkeyname = '\0';
- if ( *p ) {
- pstrcpy( remaining, p );
- p2 = remaining;
-
- if ( !next_token(&p2, subkeyname, "\\", sizeof(subkeyname)) )
- fstrcpy( subkeyname, p2 );
- }
-
- DEBUG(10,("init_registry_data: Storing key [%s] with subkey [%s]\n",
- base, *subkeyname ? subkeyname : "NULL"));
-
- /* we don't really care if the lookup succeeds or not since
- we are about to update the record. We just want any
- subkeys already present */
-
- if ( !(subkeys = TALLOC_ZERO_P( NULL, REGSUBKEY_CTR )) ) {
- DEBUG(0,("talloc() failure!\n"));
- return False;
- }
-
- regdb_fetch_keys( base, subkeys );
- if ( *subkeyname )
- regsubkey_ctr_addkey( subkeys, subkeyname );
- if ( !regdb_store_keys( base, subkeys ))
- return False;
-
- TALLOC_FREE( subkeys );
+ WERROR err;
+ struct registry_key *key;
+
+ DEBUG(10,("init_registry_data: Adding [%s]\n",
+ builtin_registry_paths[i]));
+
+ err = reg_create_path(NULL, builtin_registry_paths[i],
+ REG_KEY_READ, get_root_nt_token(),
+ NULL, &key);
+ if (!W_ERROR_IS_OK(err)) {
+ DEBUG(6, ("reg_create_path failed for %s: %s\n",
+ builtin_registry_paths[i],
+ dos_errstr(err)));
+ return False;
}
+ TALLOC_FREE(key);
}
/* loop over all of the predefined values and add each component */
for ( i=0; builtin_registry_values[i].path != NULL; i++ ) {
- if ( !(values = TALLOC_ZERO_P( NULL, REGVAL_CTR )) ) {
- DEBUG(0,("talloc() failure!\n"));
+ WERROR err;
+ struct registry_key *key;
+ struct registry_value *pval;
+
+ err = reg_open_path(NULL, builtin_registry_values[i].path,
+ REG_KEY_WRITE, get_root_nt_token(), &key);
+ if (!W_ERROR_IS_OK(err)) {
+ DEBUG(10, ("Could not open key %s: %s\n",
+ builtin_registry_values[i].path,
+ dos_errstr(err)));
return False;
}
- regdb_fetch_values( builtin_registry_values[i].path, values );
+ if (W_ERROR_IS_OK(reg_queryvalue(
+ key, key,
+ builtin_registry_values[i].valuename,
+ &pval))) {
+ /* preserve existing values across restarts. Only add
+ * new ones */
+ TALLOC_FREE(key);
+ continue;
+ }
- /* preserve existing values across restarts. Only add new ones */
+ err = WERR_OK;
+
+ switch( builtin_registry_values[i].type ) {
+ case REG_DWORD:
+ err = reg_set_dword(
+ key, builtin_registry_values[i].valuename,
+ builtin_registry_values[i].data.dw_value);
+ break;
+ case REG_SZ:
+ err = reg_set_sz(
+ key, builtin_registry_values[i].valuename,
+ builtin_registry_values[i].data.string);
+ break;
+ default:
+ DEBUG(0,("init_registry_data: invalid value type in "
+ "builtin_registry_values [%d]\n",
+ builtin_registry_values[i].type));
+ }
- if ( !regval_ctr_key_exists( values, builtin_registry_values[i].valuename ) )
- {
- switch( builtin_registry_values[i].type ) {
- case REG_DWORD:
- regval_ctr_addvalue( values,
- builtin_registry_values[i].valuename,
- REG_DWORD,
- (char*)&builtin_registry_values[i].data.dw_value,
- sizeof(uint32) );
- break;
-
- case REG_SZ:
- init_unistr2( &data, builtin_registry_values[i].data.string, UNI_STR_TERMINATE);
- regval_ctr_addvalue( values,
- builtin_registry_values[i].valuename,
- REG_SZ,
- (char*)data.buffer,
- data.uni_str_len*sizeof(uint16) );
- break;
-
- default:
- DEBUG(0,("init_registry_data: invalid value type in builtin_registry_values [%d]\n",
- builtin_registry_values[i].type));
- }
- regdb_store_values( builtin_registry_values[i].path, values );
+ if (!W_ERROR_IS_OK(err)) {
+ DEBUG(0, ("setting regvalue %s[%s] failed: %s\n",
+ builtin_registry_values[i].path,
+ builtin_registry_values[i].valuename,
+ dos_errstr(err)));
+ return False;
}
-
- TALLOC_FREE( values );
+
+ TALLOC_FREE(key);
}
return True;
diff --git a/source3/registry/reg_frontend.c b/source3/registry/reg_frontend.c
index 3bb88eaf47..1f6b285653 100644
--- a/source3/registry/reg_frontend.c
+++ b/source3/registry/reg_frontend.c
@@ -93,15 +93,16 @@ BOOL init_registry( void )
int i;
- if ( !regdb_init() ) {
- DEBUG(0,("init_registry: failed to initialize the registry tdb!\n"));
- return False;
- }
-
/* build the cache tree of registry hooks */
reghook_cache_init();
+ if ( !regdb_init() ) {
+ DEBUG(0,("init_registry: failed to initialize the registry "
+ "tdb!\n"));
+ return False;
+ }
+
for ( i=0; reg_hooks[i].keyname; i++ ) {
if ( !reghook_cache_add(&reg_hooks[i]) )
return False;
@@ -642,3 +643,24 @@ WERROR reg_delete_path(const struct nt_user_token *token,
TALLOC_FREE(hive);
return err;
}
+
+WERROR reg_set_dword(struct registry_key *key, const char *valuename,
+ uint32 value)
+{
+ struct registry_value val;
+ ZERO_STRUCT(val);
+ val.type = REG_DWORD;
+ val.v.dword = value;
+ return reg_setvalue(key, valuename, &val);
+}
+
+WERROR reg_set_sz(struct registry_key *key, const char *valuename,
+ const char *value)
+{
+ struct registry_value val;
+ ZERO_STRUCT(val);
+ val.type = REG_SZ;
+ val.v.sz.str = CONST_DISCARD(char *, value);
+ val.v.sz.len = strlen(value)+1;
+ return reg_setvalue(key, valuename, &val);
+}
diff --git a/source3/rpc_server/srv_srvsvc_nt.c b/source3/rpc_server/srv_srvsvc_nt.c
index abfa794518..1b86fa349f 100644
--- a/source3/rpc_server/srv_srvsvc_nt.c
+++ b/source3/rpc_server/srv_srvsvc_nt.c
@@ -1375,18 +1375,10 @@ char *valid_share_pathname(char *dos_pathname)
static void setval_helper(struct registry_key *key, const char *name,
const char *value, WERROR *err)
{
- struct registry_value val;
-
if (!W_ERROR_IS_OK(*err)) {
return;
}
-
- ZERO_STRUCT(val);
- val.type = REG_SZ;
- val.v.sz.str = CONST_DISCARD(char *, value);
- val.v.sz.len = strlen(value)+1;
-
- *err = reg_setvalue(key, name, &val);
+ *err = reg_set_sz(key, name, value);
}
static WERROR add_share(const char *share_name, const char *path,