summaryrefslogtreecommitdiff
path: root/source3/registry
diff options
context:
space:
mode:
authorVolker Lendecke <vlendec@samba.org>2006-12-05 07:36:14 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 12:16:22 -0500
commit5b1f85a83277e153a47761afe8a231ac5d67c2d9 (patch)
treec2dbd10fde8c43007a8f75428a57213ee17159e3 /source3/registry
parent1710dd1fe248ff82613e50ebb97be079e4f31bf4 (diff)
downloadsamba-5b1f85a83277e153a47761afe8a231ac5d67c2d9.tar.gz
samba-5b1f85a83277e153a47761afe8a231ac5d67c2d9.tar.bz2
samba-5b1f85a83277e153a47761afe8a231ac5d67c2d9.zip
r20037: Reduce code size slightly by shuffling stuff around
(This used to be commit 0742faaacd496f9cc4581a1fad74217024383661)
Diffstat (limited to 'source3/registry')
-rw-r--r--source3/registry/reg_api.c94
-rw-r--r--source3/registry/reg_frontend.c90
2 files changed, 68 insertions, 116 deletions
diff --git a/source3/registry/reg_api.c b/source3/registry/reg_api.c
index 7abf0538f8..7d8cd993a3 100644
--- a/source3/registry/reg_api.c
+++ b/source3/registry/reg_api.c
@@ -62,81 +62,67 @@ WERROR reg_openhive(TALLOC_CTX *mem_ctx, const char *hive,
const struct nt_user_token *token,
struct registry_key **pkey)
{
- struct registry_key *key;
- WERROR err;
-
+ SMB_ASSERT(hive != NULL);
SMB_ASSERT(hive[0] != '\0');
SMB_ASSERT(strchr(hive, '\\') == NULL);
- if (!(key = TALLOC_ZERO_P(mem_ctx, struct registry_key))) {
- return WERR_NOMEM;
- }
-
- if (!(key->token = dup_nt_token(key, token))) {
- TALLOC_FREE(key);
- return WERR_NOMEM;
- }
-
- err = regkey_open_internal(key, &key->key, hive, token,
- desired_access);
-
- if (!W_ERROR_IS_OK(err)) {
- TALLOC_FREE(key);
- return err;
- }
-
- *pkey = key;
- return WERR_OK;
-
+ return regkey_open_onelevel(mem_ctx, NULL, hive, token, desired_access,
+ pkey);
}
WERROR reg_openkey(TALLOC_CTX *mem_ctx, struct registry_key *parent,
const char *name, uint32 desired_access,
struct registry_key **pkey)
{
- struct registry_key *key;
+ struct registry_key *direct_parent = parent;
WERROR err;
- char *path;
+ char *p, *path, *to_free;
+ size_t len;
- if (!(key = TALLOC_ZERO_P(mem_ctx, struct registry_key))) {
+ if (!(path = SMB_STRDUP(name))) {
return WERR_NOMEM;
}
+ to_free = path;
- if (!(key->token = dup_nt_token(key, parent->token))) {
- TALLOC_FREE(key);
- return WERR_NOMEM;
- }
+ len = strlen(path);
- if (name[0] == '\0') {
- /*
- * Make a copy of the parent
- */
- path = talloc_strdup(key, parent->key->name);
- }
- else {
- /*
- * Normal subpath open
- */
- path = talloc_asprintf(key, "%s\\%s", parent->key->name,
- name);
+ if ((len > 0) && (path[len-1] == '\\')) {
+ path[len-1] = '\0';
}
- if (!path) {
- TALLOC_FREE(key);
- return WERR_NOMEM;
- }
+ while ((p = strchr(path, '\\')) != NULL) {
+ char *name_component;
+ struct registry_key *tmp;
- err = regkey_open_internal(key, &key->key, path, parent->token,
- desired_access);
- TALLOC_FREE(path);
+ if (!(name_component = SMB_STRNDUP(path, (p - path)))) {
+ err = WERR_NOMEM;
+ goto error;
+ }
- if (!W_ERROR_IS_OK(err)) {
- TALLOC_FREE(key);
- return err;
+ err = regkey_open_onelevel(mem_ctx, direct_parent,
+ name_component, parent->token,
+ SEC_RIGHTS_ENUM_SUBKEYS, &tmp);
+ SAFE_FREE(name_component);
+
+ if (!W_ERROR_IS_OK(err)) {
+ goto error;
+ }
+ if (direct_parent != parent) {
+ TALLOC_FREE(direct_parent);
+ }
+
+ direct_parent = tmp;
+ path = p+1;
}
- *pkey = key;
- return WERR_OK;
+ err = regkey_open_onelevel(mem_ctx, direct_parent, path, parent->token,
+ desired_access, pkey);
+ error:
+ if (direct_parent != parent) {
+ TALLOC_FREE(direct_parent);
+ }
+ SAFE_FREE(to_free);
+ return err;
}
WERROR reg_enumkey(TALLOC_CTX *mem_ctx, struct registry_key *key,
diff --git a/source3/registry/reg_frontend.c b/source3/registry/reg_frontend.c
index 3bb88eaf47..e0907c2dbd 100644
--- a/source3/registry/reg_frontend.c
+++ b/source3/registry/reg_frontend.c
@@ -301,31 +301,33 @@ static int regkey_destructor(REGISTRY_KEY *key)
return regdb_close();
}
-WERROR regkey_open_onelevel( TALLOC_CTX *mem_ctx, REGISTRY_KEY *parent,
- REGISTRY_KEY **regkey, const char *name,
- const struct nt_user_token *token,
- uint32 access_desired )
+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;
- REGISTRY_KEY *key;
+ struct registry_key *regkey;
+ REGISTRY_KEY *key;
REGSUBKEY_CTR *subkeys = NULL;
DEBUG(7,("regkey_open_onelevel: name = [%s]\n", name));
- if ((parent != NULL) &&
- ((parent->access_granted & SEC_RIGHTS_ENUM_SUBKEYS) == 0)) {
- return WERR_ACCESS_DENIED;
- }
+ SMB_ASSERT(strchr(name, '\\') == NULL);
- if ( !(key = TALLOC_ZERO_P(mem_ctx, REGISTRY_KEY)) ) {
- return WERR_NOMEM;
+ 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()) ) ) {
- TALLOC_FREE(key);
- return result;
+ if ( !(W_ERROR_IS_OK(result = regdb_open())) ) {
+ goto done;
}
+ key = regkey->key;
talloc_set_destructor(key, regkey_destructor);
/* initialization */
@@ -340,14 +342,14 @@ WERROR regkey_open_onelevel( TALLOC_CTX *mem_ctx, REGISTRY_KEY *parent,
result = WERR_BADFILE;
goto done;
}
- key->name = talloc_strdup(key, parent->name);
+ key->name = talloc_strdup(key, parent->key->name);
}
else {
/*
- * Normal open, concat parent and new keynames
+ * Normal subkey open
*/
key->name = talloc_asprintf(key, "%s%s%s",
- parent ? parent->name : "",
+ parent ? parent->key->name : "",
parent ? "\\": "",
name);
}
@@ -392,12 +394,12 @@ WERROR regkey_open_onelevel( TALLOC_CTX *mem_ctx, REGISTRY_KEY *parent,
goto done;
}
- *regkey = key;
+ *pregkey = regkey;
result = WERR_OK;
done:
if ( !W_ERROR_IS_OK(result) ) {
- TALLOC_FREE(key);
+ TALLOC_FREE(regkey);
}
return result;
@@ -408,53 +410,17 @@ WERROR regkey_open_internal( TALLOC_CTX *ctx, REGISTRY_KEY **regkey,
const struct nt_user_token *token,
uint32 access_desired )
{
- TALLOC_CTX *mem_ctx;
- const char *p;
- REGISTRY_KEY *parent = NULL;
+ struct registry_key *key;
WERROR err;
- size_t len;
-
- if (!(mem_ctx = talloc_new(ctx))) {
- return WERR_NOMEM;
- }
-
- len = strlen(path);
- if ((len > 0) && (path[len-1] == '\\')) {
- if (!(path = talloc_strndup(mem_ctx, path, len-1))) {
- TALLOC_FREE(mem_ctx);
- return WERR_NOMEM;
- }
- }
- while ((p = strchr(path, '\\')) != NULL) {
- char *name_component;
- REGISTRY_KEY *intermediate;
-
- if (!(name_component = talloc_strndup(
- mem_ctx, path, (p - path)))) {
- TALLOC_FREE(mem_ctx);
- return WERR_NOMEM;
- }
-
- err = regkey_open_onelevel(mem_ctx, parent, &intermediate,
- name_component, token,
- SEC_RIGHTS_ENUM_SUBKEYS);
- TALLOC_FREE(name_component);
-
- if (!W_ERROR_IS_OK(err)) {
- TALLOC_FREE(mem_ctx);
- return WERR_NOMEM;
- }
-
- TALLOC_FREE(parent);
- parent = intermediate;
- path = p+1;
+ err = reg_open_path(NULL, path, access_desired, token, &key);
+ if (!W_ERROR_IS_OK(err)) {
+ return err;
}
- err = regkey_open_onelevel(ctx, parent, regkey, path, token,
- access_desired);
- TALLOC_FREE(mem_ctx);
- return err;
+ *regkey = talloc_move(ctx, &key->key);
+ TALLOC_FREE(key);
+ return WERR_OK;
}
WERROR regkey_get_secdesc(TALLOC_CTX *mem_ctx, REGISTRY_KEY *key,