Author: jelmer Date: 2007-08-04 18:16:25 +0000 (Sat, 04 Aug 2007) New Revision: 24219
WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=24219 Log: Start working on global registry backend tests. Added: branches/4.0-regwrite/source/lib/registry/tests/registry.c Modified: branches/4.0-regwrite/ branches/4.0-regwrite/source/lib/registry/hive.c branches/4.0-regwrite/source/lib/registry/hive.h branches/4.0-regwrite/source/lib/registry/interface.c branches/4.0-regwrite/source/lib/registry/local.c branches/4.0-regwrite/source/lib/registry/registry.h branches/4.0-regwrite/source/torture/local/config.mk Changeset: Property changes on: branches/4.0-regwrite ___________________________________________________________________ Name: bzr:revision-info - timestamp: Wed 2007-06-13 02:13:44.184000015 +0200 committer: Jelmer Vernooij <[EMAIL PROTECTED]> properties: branch-nick: 4.0-regwrite rebase-of: [EMAIL PROTECTED] + timestamp: Wed 2007-06-13 22:53:58.466000080 +0200 committer: Jelmer Vernooij <[EMAIL PROTECTED]> properties: branch-nick: 4.0-regwrite rebase-of: [EMAIL PROTECTED] Name: bzr:file-ids - + source/lib/registry/tests/registry.c registry.c-20070613193046-9w6vxztx0uea8a0p-1 Name: bzr:revision-id:v3-trunk0 - 11140 [EMAIL PROTECTED] 11142 [EMAIL PROTECTED] 11143 [EMAIL PROTECTED] 11144 [EMAIL PROTECTED] 11145 [EMAIL PROTECTED] 11146 [EMAIL PROTECTED] 11147 [EMAIL PROTECTED] 11148 [EMAIL PROTECTED] 11149 [EMAIL PROTECTED] 11150 [EMAIL PROTECTED] 11151 [EMAIL PROTECTED] 11152 [EMAIL PROTECTED] 11153 [EMAIL PROTECTED] 11154 [EMAIL PROTECTED] 11155 [EMAIL PROTECTED] 11156 [EMAIL PROTECTED] 11157 [EMAIL PROTECTED] 11158 [EMAIL PROTECTED] 11159 [EMAIL PROTECTED] 11160 [EMAIL PROTECTED] 11161 [EMAIL PROTECTED] 11162 [EMAIL PROTECTED] 11163 [EMAIL PROTECTED] 11164 [EMAIL PROTECTED] 11165 [EMAIL PROTECTED] 11166 [EMAIL PROTECTED] 11167 [EMAIL PROTECTED] 11168 [EMAIL PROTECTED] 11169 [EMAIL PROTECTED] 11170 [EMAIL PROTECTED] 11171 [EMAIL PROTECTED] 11172 [EMAIL PROTECTED] 11173 [EMAIL PROTECTED] 11174 [EMAIL PROTECTED] 11175 [EMAIL PROTECTED] 11176 [EMAIL PROTECTED] 11177 [EMAIL PROTECTED] 11178 [EMAIL PROTECTED] 11179 [EMAIL PROTECTED] 11180 [EMAIL PROTECTED] 11181 [EMAIL PROTECTED] 11182 [EMAIL PROTECTED] 11183 [EMAIL PROTECTED] 11184 [EMAIL PROTECTED] 11185 [EMAIL PROTECTED] 11186 [EMAIL PROTECTED] 11187 [EMAIL PROTECTED] 11188 [EMAIL PROTECTED] 11189 [EMAIL PROTECTED] 11190 [EMAIL PROTECTED] 11191 [EMAIL PROTECTED] + 11140 [EMAIL PROTECTED] 11142 [EMAIL PROTECTED] 11143 [EMAIL PROTECTED] 11144 [EMAIL PROTECTED] 11145 [EMAIL PROTECTED] 11146 [EMAIL PROTECTED] 11147 [EMAIL PROTECTED] 11148 [EMAIL PROTECTED] 11149 [EMAIL PROTECTED] 11150 [EMAIL PROTECTED] 11151 [EMAIL PROTECTED] 11152 [EMAIL PROTECTED] 11153 [EMAIL PROTECTED] 11154 [EMAIL PROTECTED] 11155 [EMAIL PROTECTED] 11156 [EMAIL PROTECTED] 11157 [EMAIL PROTECTED] 11158 [EMAIL PROTECTED] 11159 [EMAIL PROTECTED] 11160 [EMAIL PROTECTED] 11161 [EMAIL PROTECTED] 11162 [EMAIL PROTECTED] 11163 [EMAIL PROTECTED] 11164 [EMAIL PROTECTED] 11165 [EMAIL PROTECTED] 11166 [EMAIL PROTECTED] 11167 [EMAIL PROTECTED] 11168 [EMAIL PROTECTED] 11169 [EMAIL PROTECTED] 11170 [EMAIL PROTECTED] 11171 [EMAIL PROTECTED] 11172 [EMAIL PROTECTED] 11173 [EMAIL PROTECTED] 11174 [EMAIL PROTECTED] 11175 [EMAIL PROTECTED] 11176 [EMAIL PROTECTED] 11177 [EMAIL PROTECTED] 11178 [EMAIL PROTECTED] 11179 [EMAIL PROTECTED] 11180 [EMAIL PROTECTED] 11181 [EMAIL PROTECTED] 11182 [EMAIL PROTECTED] 11183 [EMAIL PROTECTED] 11184 [EMAIL PROTECTED] 11185 [EMAIL PROTECTED] 11186 [EMAIL PROTECTED] 11187 [EMAIL PROTECTED] 11188 [EMAIL PROTECTED] 11189 [EMAIL PROTECTED] 11190 [EMAIL PROTECTED] 11191 [EMAIL PROTECTED] 11192 [EMAIL PROTECTED] Modified: branches/4.0-regwrite/source/lib/registry/hive.c =================================================================== --- branches/4.0-regwrite/source/lib/registry/hive.c 2007-08-04 18:16:18 UTC (rev 24218) +++ branches/4.0-regwrite/source/lib/registry/hive.c 2007-08-04 18:16:25 UTC (rev 24219) @@ -78,3 +78,11 @@ { return key->ops->del_key(key, name); } + +_PUBLIC_ WERROR hive_get_key_by_name(TALLOC_CTX *mem_ctx, + const struct hive_key *key, const char *name, + struct hive_key **subkey) +{ + return key->ops->get_key_by_name(mem_ctx, key, name, + subkey); +} Modified: branches/4.0-regwrite/source/lib/registry/hive.h =================================================================== --- branches/4.0-regwrite/source/lib/registry/hive.h 2007-08-04 18:16:18 UTC (rev 24218) +++ branches/4.0-regwrite/source/lib/registry/hive.h 2007-08-04 18:16:25 UTC (rev 24219) @@ -150,6 +150,9 @@ const char *name, const char *classname, struct security_descriptor *desc, struct hive_key **key); _PUBLIC_ WERROR hive_key_del(const struct hive_key *key, const char *name); +_PUBLIC_ WERROR hive_get_key_by_name(TALLOC_CTX *mem_ctx, + const struct hive_key *key, const char *name, + struct hive_key **subkey); /* Individual backends */ Modified: branches/4.0-regwrite/source/lib/registry/interface.c =================================================================== --- branches/4.0-regwrite/source/lib/registry/interface.c 2007-08-04 18:16:18 UTC (rev 24218) +++ branches/4.0-regwrite/source/lib/registry/interface.c 2007-08-04 18:16:25 UTC (rev 24219) @@ -63,7 +63,8 @@ { int i; for (i = 0; reg_predefined_keys[i].name; i++) { - if (reg_predefined_keys[i].handle == hkey) return reg_predefined_keys[i].name; + if (reg_predefined_keys[i].handle == hkey) + return reg_predefined_keys[i].name; } return NULL; @@ -84,7 +85,7 @@ } /** Get predefined key by id. */ -_PUBLIC_ WERROR reg_get_predefined_key(struct registry_context *ctx, +_PUBLIC_ WERROR reg_get_predefined_key(const struct registry_context *ctx, uint32_t hkey, struct registry_key **key) { return ctx->ops->get_predefined_key(ctx, hkey, key); Modified: branches/4.0-regwrite/source/lib/registry/local.c =================================================================== --- branches/4.0-regwrite/source/lib/registry/local.c 2007-08-04 18:16:18 UTC (rev 24218) +++ branches/4.0-regwrite/source/lib/registry/local.c 2007-08-04 18:16:25 UTC (rev 24219) @@ -37,12 +37,15 @@ struct hive_key *key; struct mountpoint *prev, *next; } *mountpoints; + + struct auth_session_info *session_info; + struct cli_credentials *credentials; }; struct local_key { struct registry_key global; struct reg_key_path path; - struct hive_key hive; + struct hive_key *hive_key; }; WERROR reg_mount_hive(struct registry_context *ctx, struct reg_key_path *path, @@ -57,13 +60,27 @@ char *orig = strdup(path), *curbegin = orig, *curend = strchr(path, '\\'); - struct registry_key *curkey = parent; + struct local_key *local_parent = talloc_get_type(parent, struct local_key), + *local_key; + struct hive_key *curkey = local_parent->hive_key; WERROR error; + const char **elements = NULL; + int el; - while (curbegin && *curbegin) { + elements = talloc_array(mem_ctx, const char *, + str_list_length(local_parent->path.elements) + 1); + for (el = 0; local_parent->path.elements[el]; el++) { + elements[el] = local_parent->path.elements[el]; + } + elements[el] = NULL; + + while (curbegin != NULL && *curbegin) { if (curend != NULL) *curend = '\0'; - error = reg_open_key(mem_ctx, curkey, curbegin, &curkey); + elements = talloc_realloc(mem_ctx, elements, const char *, el+2); + elements[el] = talloc_strdup(elements, curbegin); + el++; + error = hive_get_key_by_name(mem_ctx, curkey, curbegin, &curkey); if (!W_ERROR_IS_OK(error)) { SAFE_FREE(orig); return error; @@ -75,14 +92,48 @@ } SAFE_FREE(orig); - *result = curkey; - + local_key->global.context = talloc_reference(local_key, + local_parent->global.context); + local_key->hive_key = curkey; + local_key->path.predefined_key = local_parent->path.predefined_key; + local_key->path.elements = talloc_steal(local_key, elements); + + *result = (struct registry_key *)local_key; + return WERR_OK; } +WERROR local_get_predefined_key (struct registry_context *ctx, + uint32_t key_id, struct registry_key **key) +{ + struct registry_local *rctx = talloc_get_type(ctx, struct registry_local); + struct local_key *local_key; + struct mountpoint *mp; + + for (mp = rctx->mountpoints; mp != NULL; mp = mp->next) { + if (mp->path.predefined_key == key_id && + mp->path.elements == NULL) + break; + } + + if (mp == NULL) + return WERR_NOT_FOUND; + + local_key = talloc(ctx, struct local_key); + local_key->hive_key = mp->key; + local_key->global.context = ctx; + local_key->path = mp->path; + + *key = (struct registry_key *)local_key; + + return WERR_OK; +} + + const static struct registry_operations local_ops = { .name = "local", - .open_key = local_open_key + .open_key = local_open_key, + .get_predefined_key = local_get_predefined_key, }; WERROR reg_open_local(TALLOC_CTX *mem_ctx, struct registry_context **ctx, @@ -94,6 +145,8 @@ W_ERROR_HAVE_NO_MEMORY(ret); ret->registry.ops = &local_ops; + ret->session_info = session_info; + ret->credentials = credentials; *ctx = (struct registry_context *)ret; Modified: branches/4.0-regwrite/source/lib/registry/registry.h =================================================================== --- branches/4.0-regwrite/source/lib/registry/registry.h 2007-08-04 18:16:18 UTC (rev 24218) +++ branches/4.0-regwrite/source/lib/registry/registry.h 2007-08-04 18:16:25 UTC (rev 24219) @@ -94,7 +94,7 @@ WERROR (*flush_key) (struct registry_key *key); - WERROR (*get_predefined_key) (struct registry_context *ctx, + WERROR (*get_predefined_key) (const struct registry_context *ctx, uint32_t key_id, struct registry_key **key); @@ -198,7 +198,7 @@ _PUBLIC_ WERROR reg_get_predefined_key_by_name(struct registry_context *ctx, const char *name, struct registry_key **key); -_PUBLIC_ WERROR reg_get_predefined_key(struct registry_context *ctx, +_PUBLIC_ WERROR reg_get_predefined_key(const struct registry_context *ctx, uint32_t hkey, struct registry_key **key); Added: branches/4.0-regwrite/source/lib/registry/tests/registry.c =================================================================== --- branches/4.0-regwrite/source/lib/registry/tests/registry.c 2007-08-04 18:16:18 UTC (rev 24218) +++ branches/4.0-regwrite/source/lib/registry/tests/registry.c 2007-08-04 18:16:25 UTC (rev 24219) @@ -0,0 +1,75 @@ +/* + Unix SMB/CIFS implementation. + + local testing of registry library - registry backend + + Copyright (C) Jelmer Vernooij 2005-2007 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" +#include "lib/registry/registry.h" +#include "lib/cmdline/popt_common.h" +#include "torture/torture.h" +#include "librpc/gen_ndr/winreg.h" +#include "system/filesys.h" + +static bool test_get_predefined(struct torture_context *tctx, + const void *_data) +{ + const struct registry_context *rctx = _data; + struct registry_key *root; + WERROR error; + + error = reg_get_predefined_key(rctx, HKEY_CLASSES_ROOT, &root); + torture_assert_werr_ok(tctx, error, + "getting predefined key failed"); + return true; +} + +static bool setup_local_registry(struct torture_context *tctx, + void **data) +{ + struct registry_context *rctx; + WERROR error; + + error = reg_open_local(tctx, &rctx, NULL, NULL); + if (!W_ERROR_IS_OK(error)) { + return false; + } + + /* FIXME */ + return true; +} + +static void tcase_add_tests(struct torture_tcase *tcase) +{ + torture_tcase_add_simple_test(tcase, "get_predefined_key", + test_get_predefined); +} + +struct torture_suite *torture_registry_registry(TALLOC_CTX *mem_ctx) +{ + struct torture_tcase *tcase; + struct torture_suite *suite = torture_suite_create(mem_ctx, + "REGISTRY"); + + tcase = torture_suite_add_tcase(suite, "local"); + torture_tcase_set_fixture(tcase, setup_local_registry, NULL); + tcase_add_tests(tcase); + + return suite; +} Modified: branches/4.0-regwrite/source/torture/local/config.mk =================================================================== --- branches/4.0-regwrite/source/torture/local/config.mk 2007-08-04 18:16:18 UTC (rev 24218) +++ branches/4.0-regwrite/source/torture/local/config.mk 2007-08-04 18:16:25 UTC (rev 24219) @@ -24,6 +24,7 @@ irpc.o \ ../../lib/registry/tests/generic.o \ ../../lib/registry/tests/hive.o \ + ../../lib/registry/tests/registry.o \ resolve.o \ ../../lib/util/tests/strlist.o \ ../../lib/util/tests/file.o \
