⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 registry.c

📁 samba最新软件
💻 C
📖 第 1 页 / 共 2 页
字号:
/*   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 3 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 "torture/torture.h"#include "librpc/gen_ndr/winreg.h"#include "libcli/security/security.h"#include "system/filesys.h"/** * Test obtaining a predefined key. */static bool test_get_predefined(struct torture_context *tctx, void *_data){	struct registry_context *rctx = (struct registry_context *)_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;}/** * Test obtaining a predefined key. */static bool test_get_predefined_unknown(struct torture_context *tctx,		void *_data){	struct registry_context *rctx = _data;	struct registry_key *root;	WERROR error;	error = reg_get_predefined_key(rctx, 1337, &root);	torture_assert_werr_equal(tctx, error, WERR_BADFILE,				  "getting predefined key failed");	return true;}static bool test_predef_key_by_name(struct torture_context *tctx, void *_data){	struct registry_context *rctx = (struct registry_context *)_data;	struct registry_key *root;	WERROR error;	error = reg_get_predefined_key_by_name(rctx, "HKEY_CLASSES_ROOT",					       &root);	torture_assert_werr_ok(tctx, error,			       "getting predefined key failed");	error = reg_get_predefined_key_by_name(rctx, "HKEY_classes_ROOT",					       &root);	torture_assert_werr_ok(tctx, error,			       "getting predefined key case insensitively failed");	return true;}static bool test_predef_key_by_name_invalid(struct torture_context *tctx,		void *_data){	struct registry_context *rctx = (struct registry_context *)_data;	struct registry_key *root;	WERROR error;	error = reg_get_predefined_key_by_name(rctx, "BLA", &root);	torture_assert_werr_equal(tctx, error, WERR_BADFILE,				  "getting predefined key failed");	return true;}/** * Test creating a new subkey */static bool test_create_subkey(struct torture_context *tctx, void *_data){	struct registry_context *rctx = (struct registry_context *)_data;	struct registry_key *root, *newkey;	WERROR error;	error = reg_get_predefined_key(rctx, HKEY_CLASSES_ROOT, &root);	torture_assert_werr_ok(tctx, error,			       "getting predefined key failed");	error = reg_key_add_name(rctx, root, "Bad Bentheim", NULL, NULL,				 &newkey);	torture_assert_werr_ok(tctx, error, "Creating key return code");	torture_assert(tctx, newkey != NULL, "Creating new key");	return true;}/** * Test creating a new nested subkey */static bool test_create_nested_subkey(struct torture_context *tctx, void *_data){	struct registry_context *rctx = (struct registry_context *)_data;	struct registry_key *root, *newkey1, *newkey2;	WERROR error;	error = reg_get_predefined_key(rctx, HKEY_CLASSES_ROOT, &root);	torture_assert_werr_ok(tctx, error,			       "getting predefined key failed");	error = reg_key_add_name(rctx, root, "Hamburg", NULL, NULL,				 &newkey1);	torture_assert_werr_ok(tctx, error, "Creating key return code");	torture_assert(tctx, newkey1 != NULL, "Creating new key");	error = reg_key_add_name(rctx, root, "Hamburg\\Hamburg", NULL, NULL,				 &newkey2);	torture_assert_werr_ok(tctx, error, "Creating key return code");	torture_assert(tctx, newkey2 != NULL, "Creating new key");	return true;}/** * Test creating a new subkey */static bool test_key_add_abs_top(struct torture_context *tctx, void *_data){	struct registry_context *rctx = (struct registry_context *)_data;	struct registry_key *root;	WERROR error;	error = reg_key_add_abs(tctx, rctx, "HKEY_CLASSES_ROOT", 0, NULL,				&root);	torture_assert_werr_equal(tctx, error, WERR_ALREADY_EXISTS,				  "create top level");	return true;}/** * Test creating a new subkey */static bool test_key_add_abs(struct torture_context *tctx, void *_data){	WERROR error;	struct registry_context *rctx = (struct registry_context *)_data;	struct registry_key *root, *result1, *result2;	error = reg_key_add_abs(tctx, rctx,  "HKEY_CLASSES_ROOT\\bloe", 0, NULL,				&result1);	torture_assert_werr_ok(tctx, error, "create lowest");	error = reg_key_add_abs(tctx, rctx,  "HKEY_CLASSES_ROOT\\bloe\\bla", 0,				NULL, &result1);	torture_assert_werr_ok(tctx, error, "create nested");	error = reg_get_predefined_key(rctx, HKEY_CLASSES_ROOT, &root);	torture_assert_werr_ok(tctx, error,			       "getting predefined key failed");	error = reg_open_key(tctx, root, "bloe", &result2);	torture_assert_werr_ok(tctx, error, "opening key");	error = reg_open_key(tctx, root, "bloe\\bla", &result2);	torture_assert_werr_ok(tctx, error, "opening key");	return true;}static bool test_del_key(struct torture_context *tctx, void *_data){	struct registry_context *rctx = (struct registry_context *)_data;	struct registry_key *root, *newkey;	WERROR error;	error = reg_get_predefined_key(rctx, HKEY_CLASSES_ROOT, &root);	torture_assert_werr_ok(tctx, error,			       "getting predefined key failed");	error = reg_key_add_name(rctx, root, "Polen", NULL, NULL, &newkey);	torture_assert_werr_ok(tctx, error, "Creating key return code");	torture_assert(tctx, newkey != NULL, "Creating new key");	error = reg_key_del(root, "Polen");	torture_assert_werr_ok(tctx, error, "Delete key");	error = reg_key_del(root, "Polen");	torture_assert_werr_equal(tctx, error, WERR_BADFILE,				  "Delete missing key");	return true;}/** * Convenience function for opening the HKEY_CLASSES_ROOT hive and * creating a single key for testing purposes. */static bool create_test_key(struct torture_context *tctx,			    struct registry_context *rctx,			    const char *name,			    struct registry_key **root,			    struct registry_key **subkey){	WERROR error;	error = reg_get_predefined_key(rctx, HKEY_CLASSES_ROOT, root);	torture_assert_werr_ok(tctx, error,			       "getting predefined key failed");	error = reg_key_add_name(rctx, *root, name, NULL, NULL, subkey);	torture_assert_werr_ok(tctx, error, "Creating key return code");	return true;}static bool test_flush_key(struct torture_context *tctx, void *_data){	struct registry_context *rctx = (struct registry_context *)_data;	struct registry_key *root, *subkey;	WERROR error;	if (!create_test_key(tctx, rctx, "Bremen", &root, &subkey))		return false;	error = reg_key_flush(subkey);	torture_assert_werr_ok(tctx, error, "flush key");	torture_assert_werr_equal(tctx, reg_key_flush(NULL),				  WERR_INVALID_PARAM, "flush key");	return true;}static bool test_query_key(struct torture_context *tctx, void *_data){	struct registry_context *rctx = (struct registry_context *)_data;	struct registry_key *root, *subkey;	WERROR error;	NTTIME last_changed_time;	uint32_t num_subkeys, num_values;	const char *classname;	if (!create_test_key(tctx, rctx, "Munchen", &root, &subkey))		return false;	error = reg_key_get_info(tctx, subkey, &classname,				 &num_subkeys, &num_values,				 &last_changed_time, NULL, NULL, NULL);	torture_assert_werr_ok(tctx, error, "get info key");	torture_assert(tctx, classname == NULL, "classname");	torture_assert_int_equal(tctx, num_subkeys, 0, "num subkeys");	torture_assert_int_equal(tctx, num_values, 0, "num values");	return true;}static bool test_query_key_nums(struct torture_context *tctx, void *_data){	struct registry_context *rctx = (struct registry_context *)_data;	struct registry_key *root, *subkey1, *subkey2;	WERROR error;	uint32_t num_subkeys, num_values;	char data[4];	SIVAL(data, 0, 42);	if (!create_test_key(tctx, rctx, "Berlin", &root, &subkey1))		return false;	error = reg_key_add_name(rctx, subkey1, "Bentheim", NULL, NULL,				 &subkey2);	torture_assert_werr_ok(tctx, error, "Creating key return code");	error = reg_val_set(subkey1, "Answer", REG_DWORD,			    data_blob_talloc(tctx, &data, sizeof(data)));	torture_assert_werr_ok(tctx, error, "set value");	error = reg_key_get_info(tctx, subkey1, NULL, &num_subkeys,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -