summaryrefslogtreecommitdiff
path: root/source3/registry/reg_api.c
diff options
context:
space:
mode:
authorMichael Adam <obnox@samba.org>2007-06-22 11:03:48 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 12:23:32 -0500
commit7fd8a16d23f721af2243e8c14e4b4769cb7a72d5 (patch)
tree7438ab8584df82a1881e5281e34f3b9c47c8df0b /source3/registry/reg_api.c
parentde81984b5e9a7ac77a275722f45c827afa54cb17 (diff)
downloadsamba-7fd8a16d23f721af2243e8c14e4b4769cb7a72d5.tar.gz
samba-7fd8a16d23f721af2243e8c14e4b4769cb7a72d5.tar.bz2
samba-7fd8a16d23f721af2243e8c14e4b4769cb7a72d5.zip
r23581: Move regkey_open_onelevel from reg_frontend to reg_api,
where it actually belongs, and make it static. Michael (This used to be commit aa702e53a7416b5599ed114089327aef8a4e35b8)
Diffstat (limited to 'source3/registry/reg_api.c')
-rw-r--r--source3/registry/reg_api.c112
1 files changed, 110 insertions, 2 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 */