1
0
mirror of https://github.com/samba-team/samba.git synced 2025-02-12 21:58:10 +03:00

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 commit is contained in:
Volker Lendecke 2006-12-03 17:16:45 +00:00 committed by Gerald (Jerry) Carter
parent 281640823b
commit cab5ccbbe4
3 changed files with 107 additions and 100 deletions

View File

@ -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++ ) {
WERROR err;
struct registry_key *key;
DEBUG(6,("init_registry_data: Adding [%s]\n", builtin_registry_paths[i]));
DEBUG(10,("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 );
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 );
/* preserve existing values across restarts. Only add new ones */
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(reg_queryvalue(
key, key,
builtin_registry_values[i].valuename,
&pval))) {
/* preserve existing values across restarts. Only add
* new ones */
TALLOC_FREE(key);
continue;
}
TALLOC_FREE( values );
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 (!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(key);
}
return True;

View File

@ -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);
}

View File

@ -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,