diff options
-rw-r--r-- | source3/registry/reg_api.c | 112 | ||||
-rw-r--r-- | source3/registry/reg_frontend_hilvl.c | 115 |
2 files changed, 110 insertions, 117 deletions
diff --git a/source3/registry/reg_api.c b/source3/registry/reg_api.c index e163759dab..4fbf54e753 100644 --- a/source3/registry/reg_api.c +++ b/source3/registry/reg_api.c @@ -57,6 +57,116 @@ static WERROR fill_subkey_cache(struct registry_key *key) return WERR_OK; } +static int regkey_destructor(REGISTRY_KEY *key) +{ + return regdb_close(); +} + +static WERROR regkey_open_onelevel(TALLOC_CTX *mem_ctx, + struct registry_key *parent, + const char *name, + const struct nt_user_token *token, + uint32 access_desired, + struct registry_key **pregkey) +{ + WERROR result = WERR_OK; + struct registry_key *regkey; + REGISTRY_KEY *key; + REGSUBKEY_CTR *subkeys = NULL; + + DEBUG(7,("regkey_open_onelevel: name = [%s]\n", name)); + + SMB_ASSERT(strchr(name, '\\') == NULL); + + if (!(regkey = TALLOC_ZERO_P(mem_ctx, struct registry_key)) || + !(regkey->token = dup_nt_token(regkey, token)) || + !(regkey->key = TALLOC_ZERO_P(regkey, REGISTRY_KEY))) { + result = WERR_NOMEM; + goto done; + } + + if ( !(W_ERROR_IS_OK(result = regdb_open())) ) { + goto done; + } + + key = regkey->key; + talloc_set_destructor(key, regkey_destructor); + + /* initialization */ + + key->type = REG_KEY_GENERIC; + + if (name[0] == '\0') { + /* + * Open a copy of the parent key + */ + if (!parent) { + result = WERR_BADFILE; + goto done; + } + key->name = talloc_strdup(key, parent->key->name); + } + else { + /* + * Normal subkey open + */ + key->name = talloc_asprintf(key, "%s%s%s", + parent ? parent->key->name : "", + parent ? "\\": "", + name); + } + + if (key->name == NULL) { + result = WERR_NOMEM; + goto done; + } + + /* Tag this as a Performance Counter Key */ + + 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 ( !(key->hook = reghook_cache_find( key->name )) ) { + DEBUG(0,("reg_open_onelevel: 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( key, REGSUBKEY_CTR )) ) { + result = WERR_NOMEM; + goto done; + } + + if ( fetch_reg_keys( key, subkeys ) == -1 ) { + result = WERR_BADFILE; + goto done; + } + + TALLOC_FREE( subkeys ); + + if ( !regkey_access_check( key, access_desired, &key->access_granted, + token ) ) { + result = WERR_ACCESS_DENIED; + goto done; + } + + *pregkey = regkey; + result = WERR_OK; + +done: + if ( !W_ERROR_IS_OK(result) ) { + TALLOC_FREE(regkey); + } + + return result; +} + WERROR reg_openhive(TALLOC_CTX *mem_ctx, const char *hive, uint32 desired_access, const struct nt_user_token *token, @@ -567,5 +677,3 @@ WERROR reg_open_path(TALLOC_CTX *mem_ctx, const char *orig_path, *pkey = key; return WERR_OK; } - -/* END */ diff --git a/source3/registry/reg_frontend_hilvl.c b/source3/registry/reg_frontend_hilvl.c index 72441535b5..4c0ed0cc72 100644 --- a/source3/registry/reg_frontend_hilvl.c +++ b/source3/registry/reg_frontend_hilvl.c @@ -176,118 +176,6 @@ BOOL regkey_access_check( REGISTRY_KEY *key, uint32 requested, uint32 *granted, return NT_STATUS_IS_OK(status); } -/*********************************************************************** -***********************************************************************/ - -static int regkey_destructor(REGISTRY_KEY *key) -{ - return regdb_close(); -} - -WERROR regkey_open_onelevel( TALLOC_CTX *mem_ctx, struct registry_key *parent, - const char *name, - const struct nt_user_token *token, - uint32 access_desired, - struct registry_key **pregkey) -{ - WERROR result = WERR_OK; - struct registry_key *regkey; - REGISTRY_KEY *key; - REGSUBKEY_CTR *subkeys = NULL; - - DEBUG(7,("regkey_open_onelevel: name = [%s]\n", name)); - - SMB_ASSERT(strchr(name, '\\') == NULL); - - if (!(regkey = TALLOC_ZERO_P(mem_ctx, struct registry_key)) || - !(regkey->token = dup_nt_token(regkey, token)) || - !(regkey->key = TALLOC_ZERO_P(regkey, REGISTRY_KEY))) { - result = WERR_NOMEM; - goto done; - } - - if ( !(W_ERROR_IS_OK(result = regdb_open())) ) { - goto done; - } - - key = regkey->key; - talloc_set_destructor(key, regkey_destructor); - - /* initialization */ - - key->type = REG_KEY_GENERIC; - - if (name[0] == '\0') { - /* - * Open a copy of the parent key - */ - if (!parent) { - result = WERR_BADFILE; - goto done; - } - key->name = talloc_strdup(key, parent->key->name); - } - else { - /* - * Normal subkey open - */ - key->name = talloc_asprintf(key, "%s%s%s", - parent ? parent->key->name : "", - parent ? "\\": "", - name); - } - - if (key->name == NULL) { - result = WERR_NOMEM; - goto done; - } - - /* Tag this as a Performance Counter Key */ - - 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 ( !(key->hook = reghook_cache_find( key->name )) ) { - DEBUG(0,("reg_open_onelevel: 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( key, REGSUBKEY_CTR )) ) { - result = WERR_NOMEM; - goto done; - } - - if ( fetch_reg_keys( key, subkeys ) == -1 ) { - result = WERR_BADFILE; - goto done; - } - - TALLOC_FREE( subkeys ); - - if ( !regkey_access_check( key, access_desired, &key->access_granted, - token ) ) { - result = WERR_ACCESS_DENIED; - goto done; - } - - *pregkey = regkey; - result = WERR_OK; - -done: - if ( !W_ERROR_IS_OK(result) ) { - TALLOC_FREE(regkey); - } - - return result; -} - WERROR regkey_get_secdesc(TALLOC_CTX *mem_ctx, REGISTRY_KEY *key, struct security_descriptor **psecdesc) { @@ -310,6 +198,3 @@ WERROR regkey_get_secdesc(TALLOC_CTX *mem_ctx, REGISTRY_KEY *key, *psecdesc = secdesc; return WERR_OK; } - - -/* END */ |