summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
Diffstat (limited to 'source3')
-rw-r--r--source3/registry/reg_frontend.c84
-rw-r--r--source3/rpc_server/srv_eventlog_nt.c7
-rw-r--r--source3/rpc_server/srv_winreg_nt.c19
-rw-r--r--source3/services/services_db.c71
4 files changed, 91 insertions, 90 deletions
diff --git a/source3/registry/reg_frontend.c b/source3/registry/reg_frontend.c
index 5a76e36c81..498651894c 100644
--- a/source3/registry/reg_frontend.c
+++ b/source3/registry/reg_frontend.c
@@ -290,44 +290,67 @@ BOOL regkey_access_check( REGISTRY_KEY *key, uint32 requested, uint32 *granted,
/***********************************************************************
***********************************************************************/
-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;
}
@@ -335,40 +358,31 @@ WERROR regkey_open_internal( REGISTRY_KEY **regkey, const char *path,
/* 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;
-}
diff --git a/source3/rpc_server/srv_eventlog_nt.c b/source3/rpc_server/srv_eventlog_nt.c
index ec07981de9..73dfd42184 100644
--- a/source3/rpc_server/srv_eventlog_nt.c
+++ b/source3/rpc_server/srv_eventlog_nt.c
@@ -411,9 +411,8 @@ static BOOL sync_eventlog_params( EVENTLOG_INFO *info )
pstr_sprintf( path, "%s/%s", KEY_EVENTLOG, elogname );
- wresult =
- regkey_open_internal( &keyinfo, path, get_root_nt_token( ),
- REG_KEY_READ );
+ wresult = regkey_open_internal( NULL, NULL, &keyinfo, path,
+ get_root_nt_token( ), REG_KEY_READ );
if ( !W_ERROR_IS_OK( wresult ) ) {
DEBUG( 4,
@@ -436,7 +435,7 @@ static BOOL sync_eventlog_params( EVENTLOG_INFO *info )
if ( ( val = regval_ctr_getvalue( values, "MaxSize" ) ) != NULL )
uiMaxSize = IVAL( regval_data_p( val ), 0 );
- regkey_close_internal( keyinfo );
+ TALLOC_FREE( keyinfo );
tdb_store_int32( ELOG_TDB_CTX(info->etdb), EVT_MAXSIZE, uiMaxSize );
tdb_store_int32( ELOG_TDB_CTX(info->etdb), EVT_RETENTION, uiRetention );
diff --git a/source3/rpc_server/srv_winreg_nt.c b/source3/rpc_server/srv_winreg_nt.c
index 52de236bce..16c271427e 100644
--- a/source3/rpc_server/srv_winreg_nt.c
+++ b/source3/rpc_server/srv_winreg_nt.c
@@ -43,7 +43,6 @@ struct regkey_info {
static void free_regkey_info(void *ptr)
{
struct regkey_info *info = (struct regkey_info *)ptr;
- regkey_close_internal( info->key );
TALLOC_FREE(info);
}
@@ -107,36 +106,21 @@ static WERROR open_registry_key( pipes_struct *p, POLICY_HND *hnd,
const char *subkeyname,
uint32 access_desired )
{
- char *keypath;
- int path_len;
WERROR result = WERR_OK;
struct regkey_info *info;
/* create a full registry path and strip any trailing '\'
characters */
- if (asprintf(&keypath, "%s%s%s",
- parent ? parent->name : "",
- parent ? "\\" : "",
- subkeyname) == -1) {
- return WERR_NOMEM;
- }
-
- path_len = strlen( keypath );
- if ( path_len && keypath[path_len-1] == '\\' )
- keypath[path_len-1] = '\0';
-
if (!(info = TALLOC_ZERO_P(NULL, struct regkey_info))) {
- SAFE_FREE(keypath);
return WERR_NOMEM;
}
/* now do the internal open */
- result = regkey_open_internal( &info->key, keypath,
+ result = regkey_open_internal( info, parent, &info->key, subkeyname,
p->pipe_user.nt_user_token,
access_desired );
- SAFE_FREE(keypath);
if ( !W_ERROR_IS_OK(result) ) {
TALLOC_FREE(info);
@@ -144,7 +128,6 @@ static WERROR open_registry_key( pipes_struct *p, POLICY_HND *hnd,
}
if ( !create_policy_hnd( p, hnd, free_regkey_info, info ) ) {
- regkey_close_internal( info->key );
TALLOC_FREE(info);
return WERR_BADFILE;
}
diff --git a/source3/services/services_db.c b/source3/services/services_db.c
index 5b4f58d766..40022ab365 100644
--- a/source3/services/services_db.c
+++ b/source3/services/services_db.c
@@ -322,8 +322,8 @@ static void add_new_svc_name( REGISTRY_KEY *key_parent, REGSUBKEY_CTR *subkeys,
/* 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)));
@@ -334,7 +334,7 @@ static void add_new_svc_name( REGISTRY_KEY *key_parent, REGSUBKEY_CTR *subkeys,
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;
}
@@ -346,7 +346,7 @@ static void add_new_svc_name( REGISTRY_KEY *key_parent, REGSUBKEY_CTR *subkeys,
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;
}
@@ -355,29 +355,29 @@ static void add_new_svc_name( REGISTRY_KEY *key_parent, REGSUBKEY_CTR *subkeys,
/* 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;
}
@@ -394,7 +394,7 @@ static void add_new_svc_name( REGISTRY_KEY *key_parent, REGSUBKEY_CTR *subkeys,
/* finally cleanup the Security key */
prs_mem_free( &ps );
- regkey_close_internal( key_secdesc );
+ TALLOC_FREE( key_secdesc );
return;
}
@@ -412,8 +412,8 @@ void svcctl_init_keys( void )
/* 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",
@@ -425,7 +425,7 @@ void svcctl_init_keys( void )
if ( !(subkeys = TALLOC_ZERO_P( key, REGSUBKEY_CTR )) ) {
DEBUG(0,("init_services_keys: talloc() failed!\n"));
- regkey_close_internal( key );
+ TALLOC_FREE( key );
return;
}
@@ -447,7 +447,7 @@ void svcctl_init_keys( void )
add_new_svc_name( key, subkeys, service_list[i] );
}
- regkey_close_internal( key );
+ TALLOC_FREE( key );
/* initialize the control hooks */
@@ -476,7 +476,8 @@ SEC_DESC* svcctl_get_secdesc( TALLOC_CTX *ctx, const char *name, NT_USER_TOKEN *
/* 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)));
@@ -485,7 +486,7 @@ SEC_DESC* svcctl_get_secdesc( TALLOC_CTX *ctx, const char *name, NT_USER_TOKEN *
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;
}
@@ -494,7 +495,7 @@ SEC_DESC* svcctl_get_secdesc( TALLOC_CTX *ctx, const char *name, NT_USER_TOKEN *
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 );
}
@@ -505,7 +506,7 @@ SEC_DESC* svcctl_get_secdesc( TALLOC_CTX *ctx, const char *name, NT_USER_TOKEN *
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 );
}
@@ -514,7 +515,7 @@ SEC_DESC* svcctl_get_secdesc( TALLOC_CTX *ctx, const char *name, NT_USER_TOKEN *
/* finally cleanup the Security key */
prs_mem_free( &ps );
- regkey_close_internal( key );
+ TALLOC_FREE( key );
return ret_sd;
}
@@ -535,7 +536,8 @@ BOOL svcctl_set_secdesc( TALLOC_CTX *ctx, const char *name, SEC_DESC *sec_desc,
/* 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)));
@@ -544,7 +546,7 @@ BOOL svcctl_set_secdesc( TALLOC_CTX *ctx, const char *name, SEC_DESC *sec_desc,
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;
}
@@ -561,7 +563,7 @@ BOOL svcctl_set_secdesc( TALLOC_CTX *ctx, const char *name, SEC_DESC *sec_desc,
/* cleanup */
prs_mem_free( &ps );
- regkey_close_internal( key);
+ TALLOC_FREE( key);
return ret;
}
@@ -581,7 +583,8 @@ char* svcctl_lookup_dispname( const char *name, NT_USER_TOKEN *token )
/* 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)));
@@ -590,7 +593,7 @@ char* svcctl_lookup_dispname( const char *name, NT_USER_TOKEN *token )
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;
}
@@ -601,13 +604,13 @@ char* svcctl_lookup_dispname( const char *name, NT_USER_TOKEN *token )
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;
}
@@ -627,7 +630,8 @@ char* svcctl_lookup_description( const char *name, NT_USER_TOKEN *token )
/* 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)));
@@ -636,7 +640,7 @@ char* svcctl_lookup_description( const char *name, NT_USER_TOKEN *token )
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;
}
@@ -647,7 +651,7 @@ char* svcctl_lookup_description( const char *name, NT_USER_TOKEN *token )
else
rpcstr_pull( description, regval_data_p(val), sizeof(description), regval_size(val), 0 );
- regkey_close_internal( key );
+ TALLOC_FREE( key );
return description;
}
@@ -666,7 +670,8 @@ REGVAL_CTR* svcctl_fetch_regvalues( const char *name, NT_USER_TOKEN *token )
/* 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)));
@@ -675,13 +680,13 @@ REGVAL_CTR* svcctl_fetch_regvalues( const char *name, NT_USER_TOKEN *token )
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;
}