/***********************************************************************
***********************************************************************/
-WERROR regkey_open_internal( REGISTRY_KEY **regkey, const char *path,
+static int regkey_destructor(REGISTRY_KEY *key)
+{
+ return regdb_close();
+}
+
+WERROR regkey_open_internal( TALLOC_CTX *mem_ctx, REGISTRY_KEY *parent,
+ REGISTRY_KEY **regkey, const char *name,
NT_USER_TOKEN *token, uint32 access_desired )
{
WERROR result = WERR_OK;
- REGISTRY_KEY *keyinfo;
+ REGISTRY_KEY *key;
REGSUBKEY_CTR *subkeys = NULL;
- uint32 access_granted;
-
- if ( !(W_ERROR_IS_OK(result = regdb_open()) ) )
- return result;
+ size_t path_len;
- DEBUG(7,("regkey_open_internal: name = [%s]\n", path));
+ DEBUG(7,("regkey_open_internal: name = [%s]\n", name));
- if ( !(*regkey = TALLOC_ZERO_P(NULL, REGISTRY_KEY)) ) {
- regdb_close();
+ if ( !(key = TALLOC_ZERO_P(mem_ctx, REGISTRY_KEY)) ) {
return WERR_NOMEM;
}
-
- keyinfo = *regkey;
+
+ if ( !(W_ERROR_IS_OK(result = regdb_open()) ) )
+ return result;
+
+ talloc_set_destructor(key, regkey_destructor);
/* initialization */
- keyinfo->type = REG_KEY_GENERIC;
- if (!(keyinfo->name = talloc_strdup(keyinfo, path))) {
+ key->type = REG_KEY_GENERIC;
+ if (!(key->name = talloc_strdup(key, name))) {
result = WERR_NOMEM;
goto done;
}
+ if (parent != NULL) {
+ char *tmp;
+ if (!(tmp = talloc_asprintf(key, "%s%s%s",
+ parent ? parent->name : "",
+ parent ? "\\" : "",
+ key->name))) {
+ result = WERR_NOMEM;
+ goto done;
+ }
+ TALLOC_FREE(key->name);
+ key->name = tmp;
+ }
+
+ path_len = strlen( key->name );
+ if ( (path_len != 0) && (key->name[path_len-1] == '\\') ) {
+ key->name[path_len-1] = '\0';
+ }
+
/* Tag this as a Performance Counter Key */
- if( StrnCaseCmp(path, KEY_HKPD, strlen(KEY_HKPD)) == 0 )
- keyinfo->type = REG_KEY_HKPD;
+ if( StrnCaseCmp(key->name, KEY_HKPD, strlen(KEY_HKPD)) == 0 )
+ key->type = REG_KEY_HKPD;
/* Look up the table of registry I/O operations */
- if ( !(keyinfo->hook = reghook_cache_find( keyinfo->name )) ) {
- DEBUG(0,("open_registry_key: Failed to assigned a REGISTRY_HOOK to [%s]\n",
- keyinfo->name ));
+ if ( !(key->hook = reghook_cache_find( key->name )) ) {
+ DEBUG(0,("open_registry_key: Failed to assigned a "
+ "REGISTRY_HOOK to [%s]\n", key->name ));
result = WERR_BADFILE;
goto done;
}
/* check if the path really exists; failed is indicated by -1 */
/* if the subkey count failed, bail out */
- if ( !(subkeys = TALLOC_ZERO_P( keyinfo, REGSUBKEY_CTR )) ) {
+ if ( !(subkeys = TALLOC_ZERO_P( key, REGSUBKEY_CTR )) ) {
result = WERR_NOMEM;
goto done;
}
- if ( fetch_reg_keys( keyinfo, subkeys ) == -1 ) {
+ if ( fetch_reg_keys( key, subkeys ) == -1 ) {
result = WERR_BADFILE;
goto done;
}
TALLOC_FREE( subkeys );
- if ( !regkey_access_check( keyinfo, access_desired, &access_granted, token ) ) {
+ if ( !regkey_access_check( key, access_desired, &key->access_granted,
+ token ) ) {
result = WERR_ACCESS_DENIED;
goto done;
}
-
- keyinfo->access_granted = access_granted;
+ *regkey = key;
+ result = WERR_OK;
+
done:
if ( !W_ERROR_IS_OK(result) ) {
- regkey_close_internal( *regkey );
+ TALLOC_FREE(key);
}
return result;
}
-
-/*******************************************************************
-*******************************************************************/
-
-WERROR regkey_close_internal( REGISTRY_KEY *key )
-{
- TALLOC_FREE( key );
- regdb_close();
-
- return WERR_OK;
-}
/* open the new service key */
pstr_sprintf( path, "%s\\%s", KEY_SERVICES, name );
- wresult = regkey_open_internal( &key_service, path, get_root_nt_token(),
- REG_KEY_ALL );
+ wresult = regkey_open_internal( NULL, NULL, &key_service, path,
+ get_root_nt_token(), REG_KEY_ALL );
if ( !W_ERROR_IS_OK(wresult) ) {
DEBUG(0,("add_new_svc_name: key lookup failed! [%s] (%s)\n",
path, dos_errstr(wresult)));
if ( !(svc_subkeys = TALLOC_ZERO_P( key_service, REGSUBKEY_CTR )) ) {
DEBUG(0,("add_new_svc_name: talloc() failed!\n"));
- regkey_close_internal( key_service );
+ TALLOC_FREE( key_service );
return;
}
if ( !(values = TALLOC_ZERO_P( key_service, REGVAL_CTR )) ) {
DEBUG(0,("add_new_svc_name: talloc() failed!\n"));
- regkey_close_internal( key_service );
+ TALLOC_FREE( key_service );
return;
}
/* cleanup the service key*/
- regkey_close_internal( key_service );
+ TALLOC_FREE( key_service );
/* now add the security descriptor */
pstr_sprintf( path, "%s\\%s\\%s", KEY_SERVICES, name, "Security" );
- wresult = regkey_open_internal( &key_secdesc, path, get_root_nt_token(),
- REG_KEY_ALL );
+ wresult = regkey_open_internal( NULL, NULL, &key_secdesc, path,
+ get_root_nt_token(), REG_KEY_ALL );
if ( !W_ERROR_IS_OK(wresult) ) {
DEBUG(0,("add_new_svc_name: key lookup failed! [%s] (%s)\n",
path, dos_errstr(wresult)));
- regkey_close_internal( key_secdesc );
+ TALLOC_FREE( key_secdesc );
return;
}
if ( !(values = TALLOC_ZERO_P( key_secdesc, REGVAL_CTR )) ) {
DEBUG(0,("add_new_svc_name: talloc() failed!\n"));
- regkey_close_internal( key_secdesc );
+ TALLOC_FREE( key_secdesc );
return;
}
if ( !(sd = construct_service_sd(key_secdesc)) ) {
DEBUG(0,("add_new_svc_name: Failed to create default sec_desc!\n"));
- regkey_close_internal( key_secdesc );
+ TALLOC_FREE( key_secdesc );
return;
}
/* finally cleanup the Security key */
prs_mem_free( &ps );
- regkey_close_internal( key_secdesc );
+ TALLOC_FREE( key_secdesc );
return;
}
/* bad mojo here if the lookup failed. Should not happen */
- wresult = regkey_open_internal( &key, KEY_SERVICES, get_root_nt_token(),
- REG_KEY_ALL );
+ wresult = regkey_open_internal( NULL, NULL, &key, KEY_SERVICES,
+ get_root_nt_token(), REG_KEY_ALL );
if ( !W_ERROR_IS_OK(wresult) ) {
DEBUG(0,("init_services_keys: key lookup failed! (%s)\n",
if ( !(subkeys = TALLOC_ZERO_P( key, REGSUBKEY_CTR )) ) {
DEBUG(0,("init_services_keys: talloc() failed!\n"));
- regkey_close_internal( key );
+ TALLOC_FREE( key );
return;
}
add_new_svc_name( key, subkeys, service_list[i] );
}
- regkey_close_internal( key );
+ TALLOC_FREE( key );
/* initialize the control hooks */
/* now add the security descriptor */
pstr_sprintf( path, "%s\\%s\\%s", KEY_SERVICES, name, "Security" );
- wresult = regkey_open_internal( &key, path, token, REG_KEY_ALL );
+ wresult = regkey_open_internal( NULL, NULL, &key, path, token,
+ REG_KEY_ALL );
if ( !W_ERROR_IS_OK(wresult) ) {
DEBUG(0,("svcctl_get_secdesc: key lookup failed! [%s] (%s)\n",
path, dos_errstr(wresult)));
if ( !(values = TALLOC_ZERO_P( key, REGVAL_CTR )) ) {
DEBUG(0,("add_new_svc_name: talloc() failed!\n"));
- regkey_close_internal( key );
+ TALLOC_FREE( key );
return NULL;
}
if ( !(val = regval_ctr_getvalue( values, "Security" )) ) {
DEBUG(6,("svcctl_get_secdesc: constructing default secdesc for service [%s]\n",
name));
- regkey_close_internal( key );
+ TALLOC_FREE( key );
return construct_service_sd( ctx );
}
prs_give_memory( &ps, (char *)regval_data_p(val), regval_size(val), False );
if ( !sec_io_desc("sec_desc", &sd, &ps, 0 ) ) {
- regkey_close_internal( key );
+ TALLOC_FREE( key );
return construct_service_sd( ctx );
}
/* finally cleanup the Security key */
prs_mem_free( &ps );
- regkey_close_internal( key );
+ TALLOC_FREE( key );
return ret_sd;
}
/* now add the security descriptor */
pstr_sprintf( path, "%s\\%s\\%s", KEY_SERVICES, name, "Security" );
- wresult = regkey_open_internal( &key, path, token, REG_KEY_ALL );
+ wresult = regkey_open_internal( NULL, NULL, &key, path, token,
+ REG_KEY_ALL );
if ( !W_ERROR_IS_OK(wresult) ) {
DEBUG(0,("svcctl_get_secdesc: key lookup failed! [%s] (%s)\n",
path, dos_errstr(wresult)));
if ( !(values = TALLOC_ZERO_P( key, REGVAL_CTR )) ) {
DEBUG(0,("add_new_svc_name: talloc() failed!\n"));
- regkey_close_internal( key );
+ TALLOC_FREE( key );
return False;
}
/* cleanup */
prs_mem_free( &ps );
- regkey_close_internal( key);
+ TALLOC_FREE( key);
return ret;
}
/* now add the security descriptor */
pstr_sprintf( path, "%s\\%s", KEY_SERVICES, name );
- wresult = regkey_open_internal( &key, path, token, REG_KEY_READ );
+ wresult = regkey_open_internal( NULL, NULL, &key, path, token,
+ REG_KEY_READ );
if ( !W_ERROR_IS_OK(wresult) ) {
DEBUG(0,("svcctl_lookup_dispname: key lookup failed! [%s] (%s)\n",
path, dos_errstr(wresult)));
if ( !(values = TALLOC_ZERO_P( key, REGVAL_CTR )) ) {
DEBUG(0,("svcctl_lookup_dispname: talloc() failed!\n"));
- regkey_close_internal( key );
+ TALLOC_FREE( key );
goto fail;
}
rpcstr_pull( display_name, regval_data_p(val), sizeof(display_name), regval_size(val), 0 );
- regkey_close_internal( key );
+ TALLOC_FREE( key );
return display_name;
fail:
/* default to returning the service name */
- regkey_close_internal( key );
+ TALLOC_FREE( key );
fstrcpy( display_name, name );
return display_name;
}
/* now add the security descriptor */
pstr_sprintf( path, "%s\\%s", KEY_SERVICES, name );
- wresult = regkey_open_internal( &key, path, token, REG_KEY_READ );
+ wresult = regkey_open_internal( NULL, NULL, &key, path, token,
+ REG_KEY_READ );
if ( !W_ERROR_IS_OK(wresult) ) {
DEBUG(0,("svcctl_lookup_dispname: key lookup failed! [%s] (%s)\n",
path, dos_errstr(wresult)));
if ( !(values = TALLOC_ZERO_P( key, REGVAL_CTR )) ) {
DEBUG(0,("svcctl_lookup_dispname: talloc() failed!\n"));
- regkey_close_internal( key );
+ TALLOC_FREE( key );
return NULL;
}
else
rpcstr_pull( description, regval_data_p(val), sizeof(description), regval_size(val), 0 );
- regkey_close_internal( key );
+ TALLOC_FREE( key );
return description;
}
/* now add the security descriptor */
pstr_sprintf( path, "%s\\%s", KEY_SERVICES, name );
- wresult = regkey_open_internal( &key, path, token, REG_KEY_READ );
+ wresult = regkey_open_internal( NULL, NULL, &key, path, token,
+ REG_KEY_READ );
if ( !W_ERROR_IS_OK(wresult) ) {
DEBUG(0,("svcctl_fetch_regvalues: key lookup failed! [%s] (%s)\n",
path, dos_errstr(wresult)));
if ( !(values = TALLOC_ZERO_P( NULL, REGVAL_CTR )) ) {
DEBUG(0,("svcctl_fetch_regvalues: talloc() failed!\n"));
- regkey_close_internal( key );
+ TALLOC_FREE( key );
return NULL;
}
fetch_reg_values( key, values );
- regkey_close_internal( key );
+ TALLOC_FREE( key );
return values;
}