2007-10-06 01:22:07 +04:00
/*
2003-11-21 08:28:36 +03:00
Unix SMB / CIFS implementation .
test suite for winreg rpc operations
Copyright ( C ) Tim Potter 2003
2007-08-26 19:16:40 +04:00
Copyright ( C ) Jelmer Vernooij 2004 - 2007
2010-05-20 22:49:44 +04:00
Copyright ( C ) Günther Deschner 2007 , 2010
2007-10-06 01:22:07 +04:00
2003-11-21 08:28:36 +03:00
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
2007-07-10 06:07:03 +04:00
the Free Software Foundation ; either version 3 of the License , or
2003-11-21 08:28:36 +03:00
( at your option ) any later version .
2007-10-06 01:22:07 +04:00
2003-11-21 08:28:36 +03:00
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 .
2007-10-06 01:22:07 +04:00
2003-11-21 08:28:36 +03:00
You should have received a copy of the GNU General Public License
2007-07-10 06:07:03 +04:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2003-11-21 08:28:36 +03:00
*/
# include "includes.h"
2006-03-15 02:35:30 +03:00
# include "librpc/gen_ndr/ndr_winreg_c.h"
2006-03-16 03:23:11 +03:00
# include "librpc/gen_ndr/ndr_security.h"
2006-04-02 16:02:01 +04:00
# include "libcli/security/security.h"
2010-04-14 00:06:51 +04:00
# include "torture/rpc/torture_rpc.h"
2010-03-11 20:37:02 +03:00
# include "param/param.h"
# include "lib/registry/registry.h"
2003-11-21 08:28:36 +03:00
2010-05-21 14:42:55 +04:00
# define TEST_KEY_BASE "winreg_torture_test"
# define TEST_KEY1 "spottyfoot"
# define TEST_KEY2 "with a SD (#1)"
# define TEST_KEY3 "with a subkey"
# define TEST_KEY4 "sd_tests"
# define TEST_SUBKEY "subkey"
# define TEST_SUBKEY_SD "subkey_sd"
# define TEST_SUBSUBKEY_SD "subkey_sd\\subsubkey_sd"
2010-03-10 15:04:17 +03:00
# define TEST_VALUE "torture_value_name"
2010-03-17 02:57:22 +03:00
# define TEST_KEY_VOLATILE "torture_volatile_key"
# define TEST_SUBKEY_VOLATILE "torture_volatile_subkey"
# define TEST_KEY_SYMLINK "torture_symlink_key"
2010-05-20 16:00:57 +04:00
# define TEST_KEY_SYMLINK_DEST "torture_symlink_dest"
2007-11-02 16:37:07 +03:00
# define TEST_SID "S-1-5-21-1234567890-1234567890-1234567890-500"
2005-08-24 15:01:10 +04:00
2008-02-19 13:57:32 +03:00
static void init_lsa_StringLarge ( struct lsa_StringLarge * name , const char * s )
2005-03-17 23:28:01 +03:00
{
2008-02-19 13:57:32 +03:00
name - > string = s ;
2005-03-17 23:28:01 +03:00
}
2003-11-21 09:14:14 +03:00
static void init_winreg_String ( struct winreg_String * name , const char * s )
{
name - > name = s ;
2003-11-23 09:31:10 +03:00
if ( s ) {
name - > name_len = 2 * ( strlen_m ( s ) + 1 ) ;
name - > name_size = name - > name_len ;
} else {
name - > name_len = 0 ;
name - > name_size = 0 ;
}
2003-11-21 09:14:14 +03:00
}
2010-03-15 19:56:14 +03:00
static bool test_GetVersion ( struct dcerpc_binding_handle * b ,
2007-10-06 00:45:16 +04:00
struct torture_context * tctx ,
2003-11-21 08:28:36 +03:00
struct policy_handle * handle )
{
struct winreg_GetVersion r ;
2006-09-16 00:36:38 +04:00
uint32_t v ;
2003-11-21 08:28:36 +03:00
2010-03-17 03:25:42 +03:00
torture_comment ( tctx , " Testing GetVersion \n " ) ;
2006-09-16 00:36:38 +04:00
ZERO_STRUCT ( r ) ;
2003-11-21 08:28:36 +03:00
r . in . handle = handle ;
2006-09-16 00:36:38 +04:00
r . out . version = & v ;
2003-11-21 08:28:36 +03:00
2010-03-15 19:56:14 +03:00
torture_assert_ntstatus_ok ( tctx , dcerpc_winreg_GetVersion_r ( b , tctx , & r ) ,
2007-10-06 01:22:07 +04:00
" GetVersion failed " ) ;
2003-11-21 08:28:36 +03:00
2007-08-26 19:16:40 +04:00
torture_assert_werr_ok ( tctx , r . out . result , " GetVersion failed " ) ;
2004-10-29 03:06:12 +04:00
2007-04-18 18:43:05 +04:00
return true ;
2003-11-21 08:28:36 +03:00
}
2010-03-15 19:56:14 +03:00
static bool test_NotifyChangeKeyValue ( struct dcerpc_binding_handle * b ,
2007-10-06 00:45:16 +04:00
struct torture_context * tctx ,
struct policy_handle * handle )
2004-12-13 05:04:34 +03:00
{
struct winreg_NotifyChangeKeyValue r ;
2008-09-15 23:09:32 +04:00
ZERO_STRUCT ( r ) ;
2004-12-13 05:04:34 +03:00
r . in . handle = handle ;
2007-10-25 13:26:02 +04:00
r . in . watch_subtree = true ;
2004-12-13 05:04:34 +03:00
r . in . notify_filter = 0 ;
r . in . unknown = r . in . unknown2 = 0 ;
init_winreg_String ( & r . in . string1 , NULL ) ;
init_winreg_String ( & r . in . string2 , NULL ) ;
2007-10-06 00:45:16 +04:00
torture_assert_ntstatus_ok ( tctx ,
2010-03-15 19:56:14 +03:00
dcerpc_winreg_NotifyChangeKeyValue_r ( b , tctx , & r ) ,
2007-10-06 00:45:16 +04:00
" NotifyChangeKeyValue failed " ) ;
2004-12-13 05:04:34 +03:00
if ( ! W_ERROR_IS_OK ( r . out . result ) ) {
2007-10-06 00:45:16 +04:00
torture_comment ( tctx ,
2007-10-25 13:26:02 +04:00
" NotifyChangeKeyValue failed - %s - not considering \n " ,
win_errstr ( r . out . result ) ) ;
2007-04-18 18:43:05 +04:00
return true ;
2004-12-13 05:04:34 +03:00
}
2007-04-18 18:43:05 +04:00
return true ;
2004-12-13 05:04:34 +03:00
}
2010-03-17 02:53:21 +03:00
static bool test_CreateKey_opts ( struct torture_context * tctx ,
struct dcerpc_binding_handle * b ,
struct policy_handle * handle ,
const char * name ,
const char * kclass ,
2010-04-09 14:26:06 +04:00
uint32_t options ,
2010-03-17 02:53:21 +03:00
uint32_t access_mask ,
struct winreg_SecBuf * secdesc ,
2010-03-17 02:55:41 +03:00
WERROR expected_result ,
2010-03-17 02:53:21 +03:00
enum winreg_CreateAction * action_taken_p ,
struct policy_handle * new_handle_p )
2004-04-05 17:50:45 +04:00
{
struct winreg_CreateKey r ;
struct policy_handle newhandle ;
2006-04-30 17:54:03 +04:00
enum winreg_CreateAction action_taken = 0 ;
2004-04-05 17:50:45 +04:00
2010-03-17 02:55:41 +03:00
torture_comment ( tctx , " Testing CreateKey(%s) \n " , name ) ;
2008-09-15 23:09:32 +04:00
ZERO_STRUCT ( r ) ;
2004-04-05 17:50:45 +04:00
r . in . handle = handle ;
2007-10-06 00:45:16 +04:00
init_winreg_String ( & r . in . name , name ) ;
2009-02-02 15:04:06 +03:00
init_winreg_String ( & r . in . keyclass , kclass ) ;
2010-03-17 02:53:21 +03:00
r . in . options = options ;
r . in . access_mask = access_mask ;
r . in . action_taken = & action_taken ;
r . in . secdesc = secdesc ;
r . out . new_handle = & newhandle ;
r . out . action_taken = & action_taken ;
2004-04-05 17:50:45 +04:00
2010-03-15 19:56:14 +03:00
torture_assert_ntstatus_ok ( tctx , dcerpc_winreg_CreateKey_r ( b , tctx , & r ) ,
2007-10-06 01:22:07 +04:00
" CreateKey failed " ) ;
2004-04-05 17:50:45 +04:00
2010-03-17 02:55:41 +03:00
torture_assert_werr_equal ( tctx , r . out . result , expected_result , " CreateKey failed " ) ;
2004-04-06 00:44:33 +04:00
2010-03-17 02:53:21 +03:00
if ( new_handle_p ) {
* new_handle_p = newhandle ;
}
if ( action_taken_p ) {
2010-03-17 02:55:41 +03:00
* action_taken_p = * r . out . action_taken ;
2010-03-17 02:53:21 +03:00
}
2007-04-18 18:43:05 +04:00
return true ;
2004-04-05 17:50:45 +04:00
}
2010-03-17 02:53:21 +03:00
static bool test_CreateKey ( struct dcerpc_binding_handle * b ,
struct torture_context * tctx ,
struct policy_handle * handle , const char * name ,
const char * kclass )
{
return test_CreateKey_opts ( tctx , b , handle , name , kclass ,
2010-04-09 15:51:42 +04:00
REG_OPTION_NON_VOLATILE ,
2010-03-17 02:53:21 +03:00
SEC_FLAG_MAXIMUM_ALLOWED ,
NULL , /* secdesc */
2010-03-17 02:55:41 +03:00
WERR_OK ,
2010-03-17 02:53:21 +03:00
NULL , /* action_taken */
NULL /* new_handle */ ) ;
}
2005-08-24 15:01:10 +04:00
/*
createkey testing with a SD
*/
2010-03-15 19:56:14 +03:00
static bool test_CreateKey_sd ( struct dcerpc_binding_handle * b ,
2007-10-06 00:45:16 +04:00
struct torture_context * tctx ,
struct policy_handle * handle , const char * name ,
2009-02-02 15:04:06 +03:00
const char * kclass ,
2007-10-10 15:23:06 +04:00
struct policy_handle * newhandle )
2005-08-24 15:01:10 +04:00
{
struct winreg_CreateKey r ;
2006-04-30 17:54:03 +04:00
enum winreg_CreateAction action_taken = 0 ;
2005-08-24 15:01:10 +04:00
struct security_descriptor * sd ;
DATA_BLOB sdblob ;
struct winreg_SecBuf secbuf ;
2007-11-02 14:54:19 +03:00
sd = security_descriptor_dacl_create ( tctx ,
2007-10-10 15:12:53 +04:00
0 ,
2005-08-24 15:01:10 +04:00
NULL , NULL ,
SID_NT_AUTHENTICATED_USERS ,
SEC_ACE_TYPE_ACCESS_ALLOWED ,
SEC_GENERIC_ALL ,
2007-11-02 16:27:58 +03:00
SEC_ACE_FLAG_OBJECT_INHERIT |
SEC_ACE_FLAG_CONTAINER_INHERIT ,
2005-08-24 15:01:10 +04:00
NULL ) ;
2007-11-09 21:24:51 +03:00
torture_assert_ndr_success ( tctx ,
2010-05-09 19:20:01 +04:00
ndr_push_struct_blob ( & sdblob , tctx , sd ,
2007-10-06 00:45:16 +04:00
( ndr_push_flags_fn_t ) ndr_push_security_descriptor ) ,
" Failed to push security_descriptor ?! \n " ) ;
2005-08-24 15:01:10 +04:00
secbuf . sd . data = sdblob . data ;
secbuf . sd . len = sdblob . length ;
secbuf . sd . size = sdblob . length ;
secbuf . length = sdblob . length - 10 ;
secbuf . inherit = 0 ;
2008-09-15 23:09:32 +04:00
ZERO_STRUCT ( r ) ;
2005-08-24 15:01:10 +04:00
r . in . handle = handle ;
r . out . new_handle = newhandle ;
2007-10-06 00:45:16 +04:00
init_winreg_String ( & r . in . name , name ) ;
2009-02-02 15:04:06 +03:00
init_winreg_String ( & r . in . keyclass , kclass ) ;
2005-08-24 15:01:10 +04:00
r . in . options = 0x0 ;
2005-10-22 12:00:09 +04:00
r . in . access_mask = SEC_FLAG_MAXIMUM_ALLOWED ;
2005-08-24 15:01:10 +04:00
r . in . action_taken = r . out . action_taken = & action_taken ;
r . in . secdesc = & secbuf ;
2010-03-15 19:56:14 +03:00
torture_assert_ntstatus_ok ( tctx , dcerpc_winreg_CreateKey_r ( b , tctx , & r ) ,
2007-10-06 01:22:07 +04:00
" CreateKey with sd failed " ) ;
2005-08-24 15:01:10 +04:00
2007-08-26 19:16:40 +04:00
torture_assert_werr_ok ( tctx , r . out . result , " CreateKey with sd failed " ) ;
2005-08-24 15:01:10 +04:00
2007-04-18 18:43:05 +04:00
return true ;
2005-08-24 15:01:10 +04:00
}
2007-11-02 16:27:58 +03:00
static bool _test_GetKeySecurity ( struct dcerpc_pipe * p ,
struct torture_context * tctx ,
struct policy_handle * handle ,
uint32_t * sec_info_ptr ,
WERROR get_werr ,
struct security_descriptor * * sd_out )
2004-12-12 02:28:48 +03:00
{
struct winreg_GetKeySecurity r ;
2007-10-10 15:50:21 +04:00
struct security_descriptor * sd = NULL ;
2007-11-02 16:27:58 +03:00
uint32_t sec_info ;
2005-08-24 12:31:39 +04:00
DATA_BLOB sdblob ;
2010-03-15 19:56:14 +03:00
struct dcerpc_binding_handle * b = p - > binding_handle ;
2004-12-12 02:28:48 +03:00
2007-11-02 16:27:58 +03:00
if ( sec_info_ptr ) {
sec_info = * sec_info_ptr ;
} else {
sec_info = SECINFO_OWNER | SECINFO_GROUP | SECINFO_DACL ;
}
2004-12-12 02:28:48 +03:00
ZERO_STRUCT ( r ) ;
r . in . handle = handle ;
2007-11-02 16:27:58 +03:00
r . in . sec_info = sec_info ;
2007-08-26 19:16:40 +04:00
r . in . sd = r . out . sd = talloc_zero ( tctx , struct KeySecurityData ) ;
2005-08-24 15:01:10 +04:00
r . in . sd - > size = 0x1000 ;
2004-12-12 02:28:48 +03:00
2007-10-10 14:55:07 +04:00
torture_assert_ntstatus_ok ( tctx ,
2010-03-15 19:56:14 +03:00
dcerpc_winreg_GetKeySecurity_r ( b , tctx , & r ) ,
2007-10-06 01:22:07 +04:00
" GetKeySecurity failed " ) ;
2004-12-12 02:28:48 +03:00
2007-11-02 16:27:58 +03:00
torture_assert_werr_equal ( tctx , r . out . result , get_werr ,
" GetKeySecurity failed " ) ;
2004-12-12 02:28:48 +03:00
2005-08-24 12:31:39 +04:00
sdblob . data = r . out . sd - > data ;
sdblob . length = r . out . sd - > len ;
2007-10-10 15:50:21 +04:00
sd = talloc_zero ( tctx , struct security_descriptor ) ;
2007-11-09 21:24:51 +03:00
torture_assert_ndr_success ( tctx ,
2010-05-09 19:20:01 +04:00
ndr_pull_struct_blob ( & sdblob , tctx , sd ,
2007-10-06 00:45:16 +04:00
( ndr_pull_flags_fn_t ) ndr_pull_security_descriptor ) ,
" pull_security_descriptor failed " ) ;
2007-08-26 19:16:40 +04:00
2005-08-24 12:31:39 +04:00
if ( p - > conn - > flags & DCERPC_DEBUG_PRINT_OUT ) {
2007-10-10 14:55:07 +04:00
NDR_PRINT_DEBUG ( security_descriptor , sd ) ;
}
if ( sd_out ) {
* sd_out = sd ;
2007-10-10 15:50:21 +04:00
} else {
talloc_free ( sd ) ;
2005-08-24 12:31:39 +04:00
}
2007-04-18 18:43:05 +04:00
return true ;
2004-12-12 02:28:48 +03:00
}
2007-11-02 16:27:58 +03:00
static bool test_GetKeySecurity ( struct dcerpc_pipe * p ,
2007-10-10 15:56:47 +04:00
struct torture_context * tctx ,
struct policy_handle * handle ,
2007-11-02 16:27:58 +03:00
struct security_descriptor * * sd_out )
{
return _test_GetKeySecurity ( p , tctx , handle , NULL , WERR_OK , sd_out ) ;
}
static bool _test_SetKeySecurity ( struct dcerpc_pipe * p ,
struct torture_context * tctx ,
struct policy_handle * handle ,
uint32_t * sec_info_ptr ,
struct security_descriptor * sd ,
WERROR werr )
2007-10-10 15:56:47 +04:00
{
struct winreg_SetKeySecurity r ;
struct KeySecurityData * sdata = NULL ;
DATA_BLOB sdblob ;
2007-10-25 13:12:02 +04:00
uint32_t sec_info ;
2010-03-15 19:56:14 +03:00
struct dcerpc_binding_handle * b = p - > binding_handle ;
2007-10-10 15:56:47 +04:00
ZERO_STRUCT ( r ) ;
2007-11-02 16:27:58 +03:00
if ( sd & & ( p - > conn - > flags & DCERPC_DEBUG_PRINT_OUT ) ) {
2007-10-10 15:56:47 +04:00
NDR_PRINT_DEBUG ( security_descriptor , sd ) ;
}
2007-11-09 21:24:51 +03:00
torture_assert_ndr_success ( tctx ,
2010-05-09 19:20:01 +04:00
ndr_push_struct_blob ( & sdblob , tctx , sd ,
2007-10-10 15:56:47 +04:00
( ndr_push_flags_fn_t ) ndr_push_security_descriptor ) ,
" push_security_descriptor failed " ) ;
sdata = talloc_zero ( tctx , struct KeySecurityData ) ;
sdata - > data = sdblob . data ;
sdata - > size = sdblob . length ;
sdata - > len = sdblob . length ;
2007-11-02 16:27:58 +03:00
if ( sec_info_ptr ) {
sec_info = * sec_info_ptr ;
} else {
sec_info = SECINFO_UNPROTECTED_SACL |
SECINFO_UNPROTECTED_DACL ;
if ( sd - > owner_sid ) {
sec_info | = SECINFO_OWNER ;
}
if ( sd - > group_sid ) {
sec_info | = SECINFO_GROUP ;
}
if ( sd - > sacl ) {
sec_info | = SECINFO_SACL ;
}
if ( sd - > dacl ) {
sec_info | = SECINFO_DACL ;
}
2007-10-25 13:12:02 +04:00
}
2007-10-10 15:56:47 +04:00
r . in . handle = handle ;
2007-10-25 13:12:02 +04:00
r . in . sec_info = sec_info ;
2007-10-10 15:56:47 +04:00
r . in . sd = sdata ;
torture_assert_ntstatus_ok ( tctx ,
2010-03-15 19:56:14 +03:00
dcerpc_winreg_SetKeySecurity_r ( b , tctx , & r ) ,
2007-10-10 15:56:47 +04:00
" SetKeySecurity failed " ) ;
2007-11-02 16:27:58 +03:00
torture_assert_werr_equal ( tctx , r . out . result , werr ,
" SetKeySecurity failed " ) ;
2007-10-10 15:56:47 +04:00
return true ;
}
2007-11-02 16:37:07 +03:00
static bool test_SetKeySecurity ( struct dcerpc_pipe * p ,
struct torture_context * tctx ,
struct policy_handle * handle ,
struct security_descriptor * sd )
{
return _test_SetKeySecurity ( p , tctx , handle , NULL , sd , WERR_OK ) ;
}
2010-03-15 19:56:14 +03:00
static bool test_CloseKey ( struct dcerpc_binding_handle * b ,
struct torture_context * tctx ,
2003-11-21 08:28:36 +03:00
struct policy_handle * handle )
{
struct winreg_CloseKey r ;
2008-09-15 23:09:32 +04:00
ZERO_STRUCT ( r ) ;
2003-11-21 08:28:36 +03:00
r . in . handle = r . out . handle = handle ;
2010-03-15 19:56:14 +03:00
torture_assert_ntstatus_ok ( tctx , dcerpc_winreg_CloseKey_r ( b , tctx , & r ) ,
2007-10-06 01:22:07 +04:00
" CloseKey failed " ) ;
2003-11-21 08:28:36 +03:00
2007-08-26 19:16:40 +04:00
torture_assert_werr_ok ( tctx , r . out . result , " CloseKey failed " ) ;
2004-10-29 03:06:12 +04:00
2007-04-18 18:43:05 +04:00
return true ;
2003-11-21 08:28:36 +03:00
}
2010-03-15 19:56:14 +03:00
static bool test_FlushKey ( struct dcerpc_binding_handle * b ,
struct torture_context * tctx ,
2003-11-21 09:14:14 +03:00
struct policy_handle * handle )
{
struct winreg_FlushKey r ;
2008-09-15 23:09:32 +04:00
ZERO_STRUCT ( r ) ;
2003-11-21 09:14:14 +03:00
r . in . handle = handle ;
2010-03-15 19:56:14 +03:00
torture_assert_ntstatus_ok ( tctx , dcerpc_winreg_FlushKey_r ( b , tctx , & r ) ,
2007-10-06 00:45:16 +04:00
" FlushKey failed " ) ;
2003-11-21 09:14:14 +03:00
2007-08-26 19:16:40 +04:00
torture_assert_werr_ok ( tctx , r . out . result , " FlushKey failed " ) ;
2004-10-29 01:24:29 +04:00
2007-04-18 18:43:05 +04:00
return true ;
2003-11-21 09:14:14 +03:00
}
2010-03-17 02:55:41 +03:00
static bool test_OpenKey_opts ( struct torture_context * tctx ,
struct dcerpc_binding_handle * b ,
struct policy_handle * hive_handle ,
const char * keyname ,
2010-04-09 14:26:06 +04:00
uint32_t options ,
2010-03-17 02:55:41 +03:00
uint32_t access_mask ,
struct policy_handle * key_handle ,
WERROR expected_result )
2003-11-22 08:34:25 +03:00
{
struct winreg_OpenKey r ;
2008-09-15 23:09:32 +04:00
ZERO_STRUCT ( r ) ;
2006-09-15 22:34:03 +04:00
r . in . parent_handle = hive_handle ;
2003-11-22 08:34:25 +03:00
init_winreg_String ( & r . in . keyname , keyname ) ;
2010-03-17 02:55:41 +03:00
r . in . options = options ;
2007-11-02 16:50:27 +03:00
r . in . access_mask = access_mask ;
2003-11-22 08:34:25 +03:00
r . out . handle = key_handle ;
2010-03-15 19:56:14 +03:00
torture_assert_ntstatus_ok ( tctx , dcerpc_winreg_OpenKey_r ( b , tctx , & r ) ,
2007-10-06 00:45:16 +04:00
" OpenKey failed " ) ;
2004-12-09 01:02:49 +03:00
2010-03-17 02:55:41 +03:00
torture_assert_werr_equal ( tctx , r . out . result , expected_result ,
2007-11-02 16:50:27 +03:00
" OpenKey failed " ) ;
2007-04-18 18:43:05 +04:00
return true ;
2003-11-22 08:34:25 +03:00
}
2010-03-15 19:56:14 +03:00
static bool test_OpenKey ( struct dcerpc_binding_handle * b ,
struct torture_context * tctx ,
2007-11-02 16:50:27 +03:00
struct policy_handle * hive_handle ,
const char * keyname , struct policy_handle * key_handle )
{
2010-03-17 02:55:41 +03:00
return test_OpenKey_opts ( tctx , b , hive_handle , keyname ,
2010-04-09 15:51:42 +04:00
REG_OPTION_NON_VOLATILE ,
2010-03-17 02:55:41 +03:00
SEC_FLAG_MAXIMUM_ALLOWED ,
key_handle ,
WERR_OK ) ;
2007-11-02 16:50:27 +03:00
}
2010-03-15 19:56:14 +03:00
static bool test_Cleanup ( struct dcerpc_binding_handle * b ,
struct torture_context * tctx ,
2005-08-24 15:01:10 +04:00
struct policy_handle * handle , const char * key )
{
struct winreg_DeleteKey r ;
2008-09-15 23:09:32 +04:00
ZERO_STRUCT ( r ) ;
2005-08-24 15:01:10 +04:00
r . in . handle = handle ;
2005-08-24 15:12:16 +04:00
init_winreg_String ( & r . in . key , key ) ;
2010-03-15 19:56:14 +03:00
dcerpc_winreg_DeleteKey_r ( b , tctx , & r ) ;
2005-08-24 15:01:10 +04:00
2007-04-18 18:43:05 +04:00
return true ;
2005-08-24 15:01:10 +04:00
}
2007-11-02 16:27:58 +03:00
static bool _test_GetSetSecurityDescriptor ( struct dcerpc_pipe * p ,
struct torture_context * tctx ,
struct policy_handle * handle ,
WERROR get_werr ,
WERROR set_werr )
{
struct security_descriptor * sd = NULL ;
if ( ! _test_GetKeySecurity ( p , tctx , handle , NULL , get_werr , & sd ) ) {
return false ;
}
if ( ! _test_SetKeySecurity ( p , tctx , handle , NULL , sd , set_werr ) ) {
return false ;
}
return true ;
}
static bool test_SecurityDescriptor ( struct dcerpc_pipe * p ,
struct torture_context * tctx ,
struct policy_handle * handle ,
const char * key )
{
struct policy_handle new_handle ;
bool ret = true ;
2010-03-15 19:56:14 +03:00
struct dcerpc_binding_handle * b = p - > binding_handle ;
2007-11-02 16:27:58 +03:00
torture_comment ( tctx , " SecurityDescriptor get & set \n " ) ;
2010-03-15 19:56:14 +03:00
if ( ! test_OpenKey ( b , tctx , handle , key , & new_handle ) ) {
2007-11-02 16:27:58 +03:00
return false ;
}
if ( ! _test_GetSetSecurityDescriptor ( p , tctx , & new_handle ,
WERR_OK , WERR_OK ) ) {
ret = false ;
}
2010-03-15 19:56:14 +03:00
if ( ! test_CloseKey ( b , tctx , & new_handle ) ) {
2007-11-02 16:27:58 +03:00
return false ;
}
return ret ;
}
2005-08-24 15:01:10 +04:00
2007-11-02 17:06:58 +03:00
static bool _test_SecurityDescriptor ( struct dcerpc_pipe * p ,
struct torture_context * tctx ,
struct policy_handle * handle ,
uint32_t access_mask ,
const char * key ,
WERROR open_werr ,
WERROR get_werr ,
WERROR set_werr )
{
struct policy_handle new_handle ;
bool ret = true ;
2010-03-15 19:56:14 +03:00
struct dcerpc_binding_handle * b = p - > binding_handle ;
2007-11-02 17:06:58 +03:00
2010-03-17 02:55:41 +03:00
torture_assert ( tctx ,
test_OpenKey_opts ( tctx , b , handle , key ,
2010-04-09 15:51:42 +04:00
REG_OPTION_NON_VOLATILE ,
2010-03-17 02:55:41 +03:00
access_mask ,
& new_handle ,
open_werr ) ,
" failed to open key " ) ;
if ( ! W_ERROR_IS_OK ( open_werr ) ) {
2007-11-02 17:06:58 +03:00
return true ;
}
if ( ! _test_GetSetSecurityDescriptor ( p , tctx , & new_handle ,
get_werr , set_werr ) ) {
ret = false ;
}
2010-03-15 19:56:14 +03:00
if ( ! test_CloseKey ( b , tctx , & new_handle ) ) {
2007-11-02 17:06:58 +03:00
return false ;
}
return ret ;
}
2007-11-02 16:43:11 +03:00
static bool test_dacl_trustee_present ( struct dcerpc_pipe * p ,
struct torture_context * tctx ,
struct policy_handle * handle ,
const struct dom_sid * sid )
{
struct security_descriptor * sd = NULL ;
int i ;
if ( ! test_GetKeySecurity ( p , tctx , handle , & sd ) ) {
return false ;
}
if ( ! sd | | ! sd - > dacl ) {
return false ;
}
for ( i = 0 ; i < sd - > dacl - > num_aces ; i + + ) {
if ( dom_sid_equal ( & sd - > dacl - > aces [ i ] . trustee , sid ) ) {
return true ;
}
}
return false ;
}
2007-11-02 16:50:27 +03:00
static bool _test_dacl_trustee_present ( struct dcerpc_pipe * p ,
struct torture_context * tctx ,
struct policy_handle * handle ,
const char * key ,
const struct dom_sid * sid )
{
struct policy_handle new_handle ;
bool ret = true ;
2010-03-15 19:56:14 +03:00
struct dcerpc_binding_handle * b = p - > binding_handle ;
2007-11-02 16:50:27 +03:00
2010-03-15 19:56:14 +03:00
if ( ! test_OpenKey ( b , tctx , handle , key , & new_handle ) ) {
2007-11-02 16:50:27 +03:00
return false ;
}
ret = test_dacl_trustee_present ( p , tctx , & new_handle , sid ) ;
2010-03-15 19:56:14 +03:00
test_CloseKey ( b , tctx , & new_handle ) ;
2007-11-02 16:50:27 +03:00
return ret ;
}
static bool test_sacl_trustee_present ( struct dcerpc_pipe * p ,
struct torture_context * tctx ,
struct policy_handle * handle ,
const struct dom_sid * sid )
{
struct security_descriptor * sd = NULL ;
int i ;
uint32_t sec_info = SECINFO_SACL ;
if ( ! _test_GetKeySecurity ( p , tctx , handle , & sec_info , WERR_OK , & sd ) ) {
return false ;
}
if ( ! sd | | ! sd - > sacl ) {
return false ;
}
for ( i = 0 ; i < sd - > sacl - > num_aces ; i + + ) {
if ( dom_sid_equal ( & sd - > sacl - > aces [ i ] . trustee , sid ) ) {
return true ;
}
}
return false ;
}
static bool _test_sacl_trustee_present ( struct dcerpc_pipe * p ,
struct torture_context * tctx ,
struct policy_handle * handle ,
const char * key ,
const struct dom_sid * sid )
{
struct policy_handle new_handle ;
bool ret = true ;
2010-03-15 19:56:14 +03:00
struct dcerpc_binding_handle * b = p - > binding_handle ;
2007-11-02 16:50:27 +03:00
2010-03-17 02:55:41 +03:00
torture_assert ( tctx ,
test_OpenKey_opts ( tctx , b , handle , key ,
2010-04-09 15:51:42 +04:00
REG_OPTION_NON_VOLATILE ,
2010-03-17 02:55:41 +03:00
SEC_FLAG_SYSTEM_SECURITY ,
& new_handle ,
WERR_OK ) ,
" failed to open key " ) ;
2007-11-02 16:50:27 +03:00
ret = test_sacl_trustee_present ( p , tctx , & new_handle , sid ) ;
2010-03-15 19:56:14 +03:00
test_CloseKey ( b , tctx , & new_handle ) ;
2007-11-02 16:50:27 +03:00
return ret ;
}
static bool test_owner_present ( struct dcerpc_pipe * p ,
struct torture_context * tctx ,
struct policy_handle * handle ,
const struct dom_sid * sid )
{
struct security_descriptor * sd = NULL ;
uint32_t sec_info = SECINFO_OWNER ;
if ( ! _test_GetKeySecurity ( p , tctx , handle , & sec_info , WERR_OK , & sd ) ) {
return false ;
}
if ( ! sd | | ! sd - > owner_sid ) {
return false ;
}
return dom_sid_equal ( sd - > owner_sid , sid ) ;
}
static bool _test_owner_present ( struct dcerpc_pipe * p ,
struct torture_context * tctx ,
struct policy_handle * handle ,
const char * key ,
const struct dom_sid * sid )
{
struct policy_handle new_handle ;
bool ret = true ;
2010-03-15 19:56:14 +03:00
struct dcerpc_binding_handle * b = p - > binding_handle ;
2007-11-02 16:50:27 +03:00
2010-03-15 19:56:14 +03:00
if ( ! test_OpenKey ( b , tctx , handle , key , & new_handle ) ) {
2007-11-02 16:50:27 +03:00
return false ;
}
ret = test_owner_present ( p , tctx , & new_handle , sid ) ;
2010-03-15 19:56:14 +03:00
test_CloseKey ( b , tctx , & new_handle ) ;
2007-11-02 16:50:27 +03:00
return ret ;
}
static bool test_group_present ( struct dcerpc_pipe * p ,
struct torture_context * tctx ,
struct policy_handle * handle ,
const struct dom_sid * sid )
{
struct security_descriptor * sd = NULL ;
uint32_t sec_info = SECINFO_GROUP ;
if ( ! _test_GetKeySecurity ( p , tctx , handle , & sec_info , WERR_OK , & sd ) ) {
return false ;
}
if ( ! sd | | ! sd - > group_sid ) {
return false ;
}
return dom_sid_equal ( sd - > group_sid , sid ) ;
}
static bool _test_group_present ( struct dcerpc_pipe * p ,
struct torture_context * tctx ,
struct policy_handle * handle ,
const char * key ,
const struct dom_sid * sid )
{
struct policy_handle new_handle ;
bool ret = true ;
2010-03-15 19:56:14 +03:00
struct dcerpc_binding_handle * b = p - > binding_handle ;
2007-11-02 16:50:27 +03:00
2010-03-15 19:56:14 +03:00
if ( ! test_OpenKey ( b , tctx , handle , key , & new_handle ) ) {
2007-11-02 16:50:27 +03:00
return false ;
}
ret = test_group_present ( p , tctx , & new_handle , sid ) ;
2010-03-15 19:56:14 +03:00
test_CloseKey ( b , tctx , & new_handle ) ;
2007-11-02 16:50:27 +03:00
return ret ;
}
2007-11-02 16:43:11 +03:00
static bool test_dacl_trustee_flags_present ( struct dcerpc_pipe * p ,
struct torture_context * tctx ,
struct policy_handle * handle ,
const struct dom_sid * sid ,
uint8_t flags )
{
struct security_descriptor * sd = NULL ;
int i ;
if ( ! test_GetKeySecurity ( p , tctx , handle , & sd ) ) {
return false ;
}
if ( ! sd | | ! sd - > dacl ) {
return false ;
}
for ( i = 0 ; i < sd - > dacl - > num_aces ; i + + ) {
if ( ( dom_sid_equal ( & sd - > dacl - > aces [ i ] . trustee , sid ) ) & &
( sd - > dacl - > aces [ i ] . flags = = flags ) ) {
return true ;
}
}
return false ;
}
2007-11-02 16:37:07 +03:00
static bool test_dacl_ace_present ( struct dcerpc_pipe * p ,
struct torture_context * tctx ,
struct policy_handle * handle ,
const struct security_ace * ace )
2003-11-21 09:14:14 +03:00
{
2007-11-02 16:37:07 +03:00
struct security_descriptor * sd = NULL ;
int i ;
if ( ! test_GetKeySecurity ( p , tctx , handle , & sd ) ) {
return false ;
}
if ( ! sd | | ! sd - > dacl ) {
return false ;
}
for ( i = 0 ; i < sd - > dacl - > num_aces ; i + + ) {
if ( security_ace_equal ( & sd - > dacl - > aces [ i ] , ace ) ) {
return true ;
}
}
return false ;
}
static bool test_RestoreSecurity ( struct dcerpc_pipe * p ,
struct torture_context * tctx ,
struct policy_handle * handle ,
const char * key ,
struct security_descriptor * sd )
{
struct policy_handle new_handle ;
bool ret = true ;
2010-03-15 19:56:14 +03:00
struct dcerpc_binding_handle * b = p - > binding_handle ;
2007-11-02 16:37:07 +03:00
2010-03-15 19:56:14 +03:00
if ( ! test_OpenKey ( b , tctx , handle , key , & new_handle ) ) {
2007-11-02 16:37:07 +03:00
return false ;
}
if ( ! test_SetKeySecurity ( p , tctx , & new_handle , sd ) ) {
ret = false ;
}
2010-03-15 19:56:14 +03:00
if ( ! test_CloseKey ( b , tctx , & new_handle ) ) {
2007-11-02 16:37:07 +03:00
ret = false ;
}
return ret ;
}
2007-11-02 16:50:27 +03:00
static bool test_BackupSecurity ( struct dcerpc_pipe * p ,
struct torture_context * tctx ,
struct policy_handle * handle ,
const char * key ,
struct security_descriptor * * sd )
{
struct policy_handle new_handle ;
bool ret = true ;
2010-03-15 19:56:14 +03:00
struct dcerpc_binding_handle * b = p - > binding_handle ;
2007-11-02 16:50:27 +03:00
2010-03-15 19:56:14 +03:00
if ( ! test_OpenKey ( b , tctx , handle , key , & new_handle ) ) {
2007-11-02 16:50:27 +03:00
return false ;
}
if ( ! test_GetKeySecurity ( p , tctx , & new_handle , sd ) ) {
ret = false ;
}
2010-03-15 19:56:14 +03:00
if ( ! test_CloseKey ( b , tctx , & new_handle ) ) {
2007-11-02 16:50:27 +03:00
ret = false ;
}
return ret ;
}
2007-11-02 16:37:07 +03:00
static bool test_SecurityDescriptorInheritance ( struct dcerpc_pipe * p ,
struct torture_context * tctx ,
struct policy_handle * handle ,
const char * key )
{
/* get sd
add ace SEC_ACE_FLAG_CONTAINER_INHERIT
set sd
get sd
check ace
add subkey
get sd
check ace
add subsubkey
get sd
check ace
del subsubkey
del subkey
reset sd
*/
struct security_descriptor * sd = NULL ;
struct security_descriptor * sd_orig = NULL ;
struct security_ace * ace = NULL ;
struct policy_handle new_handle ;
bool ret = true ;
2010-03-15 19:56:14 +03:00
struct dcerpc_binding_handle * b = p - > binding_handle ;
2010-05-21 14:42:55 +04:00
const char * test_subkey_sd ;
const char * test_subsubkey_sd ;
2003-11-21 09:14:14 +03:00
2007-11-02 16:37:07 +03:00
torture_comment ( tctx , " SecurityDescriptor inheritance \n " ) ;
2003-11-21 09:14:14 +03:00
2010-03-15 19:56:14 +03:00
if ( ! test_OpenKey ( b , tctx , handle , key , & new_handle ) ) {
2007-11-02 16:37:07 +03:00
return false ;
}
2003-11-21 09:14:14 +03:00
2007-11-02 16:37:07 +03:00
if ( ! _test_GetKeySecurity ( p , tctx , & new_handle , NULL , WERR_OK , & sd ) ) {
return false ;
}
sd_orig = security_descriptor_copy ( tctx , sd ) ;
if ( sd_orig = = NULL ) {
return false ;
}
ace = security_ace_create ( tctx ,
TEST_SID ,
SEC_ACE_TYPE_ACCESS_ALLOWED ,
SEC_STD_REQUIRED ,
SEC_ACE_FLAG_CONTAINER_INHERIT ) ;
2010-03-16 14:24:18 +03:00
torture_assert_ntstatus_ok ( tctx ,
security_descriptor_dacl_add ( sd , ace ) ,
" failed to add ace " ) ;
2007-11-02 16:37:07 +03:00
/* FIXME: add further tests for these flags */
sd - > type | = SEC_DESC_DACL_AUTO_INHERIT_REQ |
SEC_DESC_SACL_AUTO_INHERITED ;
if ( ! test_SetKeySecurity ( p , tctx , & new_handle , sd ) ) {
return false ;
}
2010-03-16 14:24:18 +03:00
torture_assert ( tctx ,
test_dacl_ace_present ( p , tctx , & new_handle , ace ) ,
" new ACE not present! " ) ;
2007-11-02 16:37:07 +03:00
2010-03-15 19:56:14 +03:00
if ( ! test_CloseKey ( b , tctx , & new_handle ) ) {
2007-11-02 16:37:07 +03:00
return false ;
}
2010-05-21 14:42:55 +04:00
test_subkey_sd = talloc_asprintf ( tctx , " %s \\ %s " , key , TEST_SUBKEY_SD ) ;
if ( ! test_CreateKey ( b , tctx , handle , test_subkey_sd , NULL ) ) {
2007-11-02 16:37:07 +03:00
ret = false ;
goto out ;
}
2010-05-21 14:42:55 +04:00
if ( ! test_OpenKey ( b , tctx , handle , test_subkey_sd , & new_handle ) ) {
2007-11-02 16:37:07 +03:00
ret = false ;
goto out ;
}
if ( ! test_dacl_ace_present ( p , tctx , & new_handle , ace ) ) {
2010-03-16 14:24:18 +03:00
torture_comment ( tctx , " inherited ACE not present! \n " ) ;
2007-11-02 16:37:07 +03:00
ret = false ;
goto out ;
}
2010-05-21 14:42:55 +04:00
test_subsubkey_sd = talloc_asprintf ( tctx , " %s \\ %s " , key , TEST_SUBSUBKEY_SD ) ;
2010-03-15 19:56:14 +03:00
test_CloseKey ( b , tctx , & new_handle ) ;
2010-05-21 14:42:55 +04:00
if ( ! test_CreateKey ( b , tctx , handle , test_subsubkey_sd , NULL ) ) {
2007-11-02 16:37:07 +03:00
ret = false ;
goto out ;
}
2010-05-21 14:42:55 +04:00
if ( ! test_OpenKey ( b , tctx , handle , test_subsubkey_sd , & new_handle ) ) {
2007-11-02 16:37:07 +03:00
ret = false ;
goto out ;
}
if ( ! test_dacl_ace_present ( p , tctx , & new_handle , ace ) ) {
2010-03-16 14:24:18 +03:00
torture_comment ( tctx , " inherited ACE not present! \n " ) ;
2007-11-02 16:37:07 +03:00
ret = false ;
goto out ;
}
out :
2010-03-15 19:56:14 +03:00
test_CloseKey ( b , tctx , & new_handle ) ;
2010-05-21 14:42:55 +04:00
test_Cleanup ( b , tctx , handle , test_subkey_sd ) ;
2007-11-02 16:37:07 +03:00
test_RestoreSecurity ( p , tctx , handle , key , sd_orig ) ;
2004-04-06 00:44:33 +04:00
2010-05-21 14:42:55 +04:00
return ret ;
2003-11-21 09:14:14 +03:00
}
2007-11-02 16:43:11 +03:00
static bool test_SecurityDescriptorBlockInheritance ( struct dcerpc_pipe * p ,
struct torture_context * tctx ,
struct policy_handle * handle ,
const char * key )
{
/* get sd
add ace SEC_ACE_FLAG_NO_PROPAGATE_INHERIT
set sd
add subkey / subkey
get sd
check ace
get sd from subkey
check ace
del subkey / subkey
del subkey
reset sd
*/
struct security_descriptor * sd = NULL ;
struct security_descriptor * sd_orig = NULL ;
struct security_ace * ace = NULL ;
struct policy_handle new_handle ;
struct dom_sid * sid = NULL ;
bool ret = true ;
uint8_t ace_flags = 0x0 ;
2010-03-15 19:56:14 +03:00
struct dcerpc_binding_handle * b = p - > binding_handle ;
2010-05-21 14:42:55 +04:00
const char * test_subkey_sd ;
const char * test_subsubkey_sd ;
2007-11-02 16:43:11 +03:00
torture_comment ( tctx , " SecurityDescriptor inheritance block \n " ) ;
2010-03-15 19:56:14 +03:00
if ( ! test_OpenKey ( b , tctx , handle , key , & new_handle ) ) {
2007-11-02 16:43:11 +03:00
return false ;
}
if ( ! _test_GetKeySecurity ( p , tctx , & new_handle , NULL , WERR_OK , & sd ) ) {
return false ;
}
sd_orig = security_descriptor_copy ( tctx , sd ) ;
if ( sd_orig = = NULL ) {
return false ;
}
ace = security_ace_create ( tctx ,
TEST_SID ,
SEC_ACE_TYPE_ACCESS_ALLOWED ,
SEC_STD_REQUIRED ,
SEC_ACE_FLAG_CONTAINER_INHERIT |
SEC_ACE_FLAG_NO_PROPAGATE_INHERIT ) ;
2010-03-16 14:24:18 +03:00
torture_assert_ntstatus_ok ( tctx ,
security_descriptor_dacl_add ( sd , ace ) ,
" failed to add ace " ) ;
2007-11-02 16:43:11 +03:00
if ( ! _test_SetKeySecurity ( p , tctx , & new_handle , NULL , sd , WERR_OK ) ) {
return false ;
}
2010-03-16 14:24:18 +03:00
torture_assert ( tctx ,
test_dacl_ace_present ( p , tctx , & new_handle , ace ) ,
" new ACE not present! " ) ;
2007-11-02 16:43:11 +03:00
2010-03-15 19:56:14 +03:00
if ( ! test_CloseKey ( b , tctx , & new_handle ) ) {
2007-11-02 16:43:11 +03:00
return false ;
}
2010-05-21 14:42:55 +04:00
test_subkey_sd = talloc_asprintf ( tctx , " %s \\ %s " , key , TEST_SUBKEY_SD ) ;
test_subsubkey_sd = talloc_asprintf ( tctx , " %s \\ %s " , key , TEST_SUBSUBKEY_SD ) ;
if ( ! test_CreateKey ( b , tctx , handle , test_subsubkey_sd , NULL ) ) {
2007-11-02 16:43:11 +03:00
return false ;
}
2010-05-21 14:42:55 +04:00
if ( ! test_OpenKey ( b , tctx , handle , test_subsubkey_sd , & new_handle ) ) {
2007-11-02 16:43:11 +03:00
ret = false ;
goto out ;
}
if ( test_dacl_ace_present ( p , tctx , & new_handle , ace ) ) {
2010-03-16 14:24:18 +03:00
torture_comment ( tctx , " inherited ACE present but should not! \n " ) ;
2007-11-02 16:43:11 +03:00
ret = false ;
goto out ;
}
sid = dom_sid_parse_talloc ( tctx , TEST_SID ) ;
if ( sid = = NULL ) {
return false ;
}
if ( test_dacl_trustee_present ( p , tctx , & new_handle , sid ) ) {
2010-03-16 14:24:18 +03:00
torture_comment ( tctx , " inherited trustee SID present but should not! \n " ) ;
2007-11-02 16:43:11 +03:00
ret = false ;
goto out ;
}
2010-03-15 19:56:14 +03:00
test_CloseKey ( b , tctx , & new_handle ) ;
2007-11-02 16:43:11 +03:00
2010-05-21 14:42:55 +04:00
if ( ! test_OpenKey ( b , tctx , handle , test_subkey_sd , & new_handle ) ) {
2007-11-02 16:43:11 +03:00
ret = false ;
goto out ;
}
if ( test_dacl_ace_present ( p , tctx , & new_handle , ace ) ) {
2010-03-16 14:24:18 +03:00
torture_comment ( tctx , " inherited ACE present but should not! \n " ) ;
2007-11-02 16:43:11 +03:00
ret = false ;
goto out ;
}
if ( ! test_dacl_trustee_flags_present ( p , tctx , & new_handle , sid , ace_flags ) ) {
2010-03-16 14:24:18 +03:00
torture_comment ( tctx , " inherited trustee SID with flags 0x%02x not present! \n " ,
2007-11-02 16:43:11 +03:00
ace_flags ) ;
ret = false ;
goto out ;
}
out :
2010-03-15 19:56:14 +03:00
test_CloseKey ( b , tctx , & new_handle ) ;
2010-05-21 14:42:55 +04:00
test_Cleanup ( b , tctx , handle , test_subkey_sd ) ;
2007-11-02 16:43:11 +03:00
test_RestoreSecurity ( p , tctx , handle , key , sd_orig ) ;
return ret ;
}
2007-11-02 17:06:58 +03:00
static bool test_SecurityDescriptorsMasks ( struct dcerpc_pipe * p ,
struct torture_context * tctx ,
struct policy_handle * handle ,
const char * key )
{
bool ret = true ;
int i ;
struct winreg_mask_result_table {
uint32_t access_mask ;
WERROR open_werr ;
WERROR get_werr ;
WERROR set_werr ;
} sd_mask_tests [ ] = {
{ 0 ,
2015-12-03 17:24:12 +03:00
WERR_ACCESS_DENIED , WERR_FILE_NOT_FOUND , WERR_FOOBAR } ,
2007-11-02 17:06:58 +03:00
{ SEC_FLAG_MAXIMUM_ALLOWED ,
WERR_OK , WERR_OK , WERR_OK } ,
{ SEC_STD_WRITE_DAC ,
WERR_OK , WERR_ACCESS_DENIED , WERR_FOOBAR } ,
{ SEC_FLAG_SYSTEM_SECURITY ,
WERR_OK , WERR_ACCESS_DENIED , WERR_FOOBAR }
} ;
/* FIXME: before this test can ever run successfully we need a way to
* correctly read a NULL security_descritpor in ndr , get the required
* length , requery , etc .
*/
return true ;
for ( i = 0 ; i < ARRAY_SIZE ( sd_mask_tests ) ; i + + ) {
torture_comment ( tctx ,
" SecurityDescriptor get & set with access_mask: 0x%08x \n " ,
sd_mask_tests [ i ] . access_mask ) ;
torture_comment ( tctx ,
" expecting: open %s, get: %s, set: %s \n " ,
win_errstr ( sd_mask_tests [ i ] . open_werr ) ,
win_errstr ( sd_mask_tests [ i ] . get_werr ) ,
win_errstr ( sd_mask_tests [ i ] . set_werr ) ) ;
if ( _test_SecurityDescriptor ( p , tctx , handle ,
sd_mask_tests [ i ] . access_mask , key ,
sd_mask_tests [ i ] . open_werr ,
sd_mask_tests [ i ] . get_werr ,
sd_mask_tests [ i ] . set_werr ) ) {
ret = false ;
}
}
return ret ;
}
2007-11-02 16:51:49 +03:00
typedef bool ( * secinfo_verify_fn ) ( struct dcerpc_pipe * ,
struct torture_context * ,
struct policy_handle * ,
const char * ,
const struct dom_sid * ) ;
static bool test_SetSecurityDescriptor_SecInfo ( struct dcerpc_pipe * p ,
struct torture_context * tctx ,
struct policy_handle * handle ,
const char * key ,
const char * test ,
uint32_t access_mask ,
uint32_t sec_info ,
struct security_descriptor * sd ,
WERROR set_werr ,
bool expect_present ,
bool ( * fn ) ( struct dcerpc_pipe * ,
struct torture_context * ,
struct policy_handle * ,
const char * ,
const struct dom_sid * ) ,
const struct dom_sid * sid )
{
struct policy_handle new_handle ;
2010-03-15 19:56:14 +03:00
struct dcerpc_binding_handle * b = p - > binding_handle ;
2007-11-02 16:51:49 +03:00
torture_comment ( tctx , " SecurityDescriptor (%s) sets for secinfo: "
" 0x%08x, access_mask: 0x%08x \n " ,
test , sec_info , access_mask ) ;
2010-03-17 02:55:41 +03:00
torture_assert ( tctx ,
test_OpenKey_opts ( tctx , b , handle , key ,
2010-04-09 15:51:42 +04:00
REG_OPTION_NON_VOLATILE ,
2010-03-17 02:55:41 +03:00
access_mask ,
& new_handle ,
WERR_OK ) ,
" failed to open key " ) ;
2007-11-02 16:51:49 +03:00
if ( ! _test_SetKeySecurity ( p , tctx , & new_handle , & sec_info ,
sd ,
set_werr ) ) {
torture_warning ( tctx ,
" SetKeySecurity with secinfo: 0x%08x has failed \n " ,
sec_info ) ;
smb_panic ( " " ) ;
2010-03-15 19:56:14 +03:00
test_CloseKey ( b , tctx , & new_handle ) ;
2007-11-02 16:51:49 +03:00
return false ;
}
2010-03-15 19:56:14 +03:00
test_CloseKey ( b , tctx , & new_handle ) ;
2007-11-02 16:51:49 +03:00
if ( W_ERROR_IS_OK ( set_werr ) ) {
bool present ;
present = fn ( p , tctx , handle , key , sid ) ;
if ( ( expect_present ) & & ( ! present ) ) {
torture_warning ( tctx ,
" %s sid is not present! \n " ,
test ) ;
return false ;
}
if ( ( ! expect_present ) & & ( present ) ) {
torture_warning ( tctx ,
" %s sid is present but not expected! \n " ,
test ) ;
return false ;
}
}
return true ;
}
static bool test_SecurityDescriptorsSecInfo ( struct dcerpc_pipe * p ,
struct torture_context * tctx ,
struct policy_handle * handle ,
const char * key )
{
struct security_descriptor * sd_orig = NULL ;
struct dom_sid * sid = NULL ;
bool ret = true ;
int i , a ;
struct security_descriptor * sd_owner =
security_descriptor_dacl_create ( tctx ,
0 ,
TEST_SID , NULL , NULL ) ;
struct security_descriptor * sd_group =
security_descriptor_dacl_create ( tctx ,
0 ,
NULL , TEST_SID , NULL ) ;
struct security_descriptor * sd_dacl =
security_descriptor_dacl_create ( tctx ,
0 ,
NULL , NULL ,
TEST_SID ,
SEC_ACE_TYPE_ACCESS_ALLOWED ,
SEC_GENERIC_ALL ,
0 ,
SID_NT_AUTHENTICATED_USERS ,
SEC_ACE_TYPE_ACCESS_ALLOWED ,
SEC_GENERIC_ALL ,
0 ,
NULL ) ;
struct security_descriptor * sd_sacl =
security_descriptor_sacl_create ( tctx ,
0 ,
NULL , NULL ,
TEST_SID ,
SEC_ACE_TYPE_SYSTEM_AUDIT ,
SEC_GENERIC_ALL ,
SEC_ACE_FLAG_SUCCESSFUL_ACCESS ,
NULL ) ;
struct winreg_secinfo_table {
struct security_descriptor * sd ;
uint32_t sec_info ;
WERROR set_werr ;
bool sid_present ;
secinfo_verify_fn fn ;
} ;
struct winreg_secinfo_table sec_info_owner_tests [ ] = {
2019-01-07 19:11:42 +03:00
{
. sd = sd_owner ,
. sec_info = 0 ,
. set_werr = WERR_OK ,
. sid_present = false ,
. fn = ( secinfo_verify_fn ) _test_owner_present ,
} ,
{
. sd = sd_owner ,
. sec_info = SECINFO_OWNER ,
. set_werr = WERR_OK ,
. sid_present = true ,
. fn = ( secinfo_verify_fn ) _test_owner_present ,
} ,
{
. sd = sd_owner ,
. sec_info = SECINFO_GROUP ,
. set_werr = WERR_INVALID_PARAMETER ,
. sid_present = false ,
} ,
{
. sd = sd_owner ,
. sec_info = SECINFO_DACL ,
. set_werr = WERR_OK ,
. sid_present = true ,
. fn = ( secinfo_verify_fn ) _test_owner_present ,
} ,
{
. sd = sd_owner ,
. sec_info = SECINFO_SACL ,
. set_werr = WERR_ACCESS_DENIED ,
. sid_present = false ,
} ,
2007-11-02 16:51:49 +03:00
} ;
uint32_t sd_owner_good_access_masks [ ] = {
SEC_FLAG_MAXIMUM_ALLOWED ,
/* SEC_STD_WRITE_OWNER, */
} ;
struct winreg_secinfo_table sec_info_group_tests [ ] = {
2019-01-07 19:11:42 +03:00
{
. sd = sd_group ,
. sec_info = 0 ,
. set_werr = WERR_OK ,
. sid_present = false ,
. fn = ( secinfo_verify_fn ) _test_group_present ,
} ,
{
. sd = sd_group ,
. sec_info = SECINFO_OWNER ,
. set_werr = WERR_INVALID_PARAMETER ,
. sid_present = false ,
} ,
{
. sd = sd_group ,
. sec_info = SECINFO_GROUP ,
. set_werr = WERR_OK ,
. sid_present = true ,
. fn = ( secinfo_verify_fn ) _test_group_present ,
} ,
{
. sd = sd_group ,
. sec_info = SECINFO_DACL ,
. set_werr = WERR_OK ,
. sid_present = true ,
. fn = ( secinfo_verify_fn ) _test_group_present ,
} ,
{
. sd = sd_group ,
. sec_info = SECINFO_SACL ,
. set_werr = WERR_ACCESS_DENIED ,
. sid_present = false ,
} ,
2007-11-02 16:51:49 +03:00
} ;
uint32_t sd_group_good_access_masks [ ] = {
SEC_FLAG_MAXIMUM_ALLOWED ,
} ;
struct winreg_secinfo_table sec_info_dacl_tests [ ] = {
2019-01-07 19:11:42 +03:00
{
. sd = sd_dacl ,
. sec_info = 0 ,
. set_werr = WERR_OK ,
. sid_present = false ,
. fn = ( secinfo_verify_fn ) _test_dacl_trustee_present ,
} ,
{
. sd = sd_dacl ,
. sec_info = SECINFO_OWNER ,
. set_werr = WERR_INVALID_PARAMETER ,
. sid_present = false ,
} ,
{
. sd = sd_dacl ,
. sec_info = SECINFO_GROUP ,
. set_werr = WERR_INVALID_PARAMETER ,
. sid_present = false ,
} ,
{
. sd = sd_dacl ,
. sec_info = SECINFO_DACL ,
. set_werr = WERR_OK ,
. sid_present = true ,
. fn = ( secinfo_verify_fn ) _test_dacl_trustee_present
} ,
{
. sd = sd_dacl ,
. sec_info = SECINFO_SACL ,
. set_werr = WERR_ACCESS_DENIED ,
. sid_present = false ,
} ,
2007-11-02 16:51:49 +03:00
} ;
uint32_t sd_dacl_good_access_masks [ ] = {
SEC_FLAG_MAXIMUM_ALLOWED ,
SEC_STD_WRITE_DAC ,
} ;
struct winreg_secinfo_table sec_info_sacl_tests [ ] = {
2019-01-07 19:11:42 +03:00
{
. sd = sd_sacl ,
. sec_info = 0 ,
. set_werr = WERR_OK ,
. sid_present = false ,
. fn = ( secinfo_verify_fn ) _test_sacl_trustee_present ,
} ,
{
. sd = sd_sacl ,
. sec_info = SECINFO_OWNER ,
. set_werr = WERR_INVALID_PARAMETER ,
. sid_present = false ,
} ,
{
. sd = sd_sacl ,
. sec_info = SECINFO_GROUP ,
. set_werr = WERR_INVALID_PARAMETER ,
. sid_present = false ,
} ,
{
. sd = sd_sacl ,
. sec_info = SECINFO_DACL ,
. set_werr = WERR_OK ,
. sid_present = false ,
. fn = ( secinfo_verify_fn ) _test_sacl_trustee_present ,
} ,
{
. sd = sd_sacl ,
. sec_info = SECINFO_SACL ,
. set_werr = WERR_OK ,
. sid_present = true ,
. fn = ( secinfo_verify_fn ) _test_sacl_trustee_present ,
} ,
2007-11-02 16:51:49 +03:00
} ;
uint32_t sd_sacl_good_access_masks [ ] = {
SEC_FLAG_MAXIMUM_ALLOWED | SEC_FLAG_SYSTEM_SECURITY ,
/* SEC_FLAG_SYSTEM_SECURITY, */
} ;
sid = dom_sid_parse_talloc ( tctx , TEST_SID ) ;
if ( sid = = NULL ) {
return false ;
}
if ( ! test_BackupSecurity ( p , tctx , handle , key , & sd_orig ) ) {
return false ;
}
/* OWNER */
for ( i = 0 ; i < ARRAY_SIZE ( sec_info_owner_tests ) ; i + + ) {
for ( a = 0 ; a < ARRAY_SIZE ( sd_owner_good_access_masks ) ; a + + ) {
if ( ! test_SetSecurityDescriptor_SecInfo ( p , tctx , handle ,
key ,
" OWNER " ,
sd_owner_good_access_masks [ a ] ,
sec_info_owner_tests [ i ] . sec_info ,
sec_info_owner_tests [ i ] . sd ,
sec_info_owner_tests [ i ] . set_werr ,
sec_info_owner_tests [ i ] . sid_present ,
sec_info_owner_tests [ i ] . fn ,
sid ) )
{
2010-03-16 14:24:18 +03:00
torture_comment ( tctx , " test_SetSecurityDescriptor_SecInfo failed for OWNER \n " ) ;
2007-11-02 16:51:49 +03:00
ret = false ;
goto out ;
}
}
}
/* GROUP */
for ( i = 0 ; i < ARRAY_SIZE ( sec_info_group_tests ) ; i + + ) {
for ( a = 0 ; a < ARRAY_SIZE ( sd_group_good_access_masks ) ; a + + ) {
if ( ! test_SetSecurityDescriptor_SecInfo ( p , tctx , handle ,
key ,
" GROUP " ,
sd_group_good_access_masks [ a ] ,
sec_info_group_tests [ i ] . sec_info ,
sec_info_group_tests [ i ] . sd ,
sec_info_group_tests [ i ] . set_werr ,
sec_info_group_tests [ i ] . sid_present ,
sec_info_group_tests [ i ] . fn ,
sid ) )
{
2010-03-16 14:24:18 +03:00
torture_comment ( tctx , " test_SetSecurityDescriptor_SecInfo failed for GROUP \n " ) ;
2007-11-02 16:51:49 +03:00
ret = false ;
goto out ;
}
}
}
/* DACL */
for ( i = 0 ; i < ARRAY_SIZE ( sec_info_dacl_tests ) ; i + + ) {
for ( a = 0 ; a < ARRAY_SIZE ( sd_dacl_good_access_masks ) ; a + + ) {
if ( ! test_SetSecurityDescriptor_SecInfo ( p , tctx , handle ,
key ,
" DACL " ,
sd_dacl_good_access_masks [ a ] ,
sec_info_dacl_tests [ i ] . sec_info ,
sec_info_dacl_tests [ i ] . sd ,
sec_info_dacl_tests [ i ] . set_werr ,
sec_info_dacl_tests [ i ] . sid_present ,
sec_info_dacl_tests [ i ] . fn ,
sid ) )
{
2010-03-16 14:24:18 +03:00
torture_comment ( tctx , " test_SetSecurityDescriptor_SecInfo failed for DACL \n " ) ;
2007-11-02 16:51:49 +03:00
ret = false ;
goto out ;
}
}
}
/* SACL */
for ( i = 0 ; i < ARRAY_SIZE ( sec_info_sacl_tests ) ; i + + ) {
for ( a = 0 ; a < ARRAY_SIZE ( sd_sacl_good_access_masks ) ; a + + ) {
if ( ! test_SetSecurityDescriptor_SecInfo ( p , tctx , handle ,
key ,
" SACL " ,
sd_sacl_good_access_masks [ a ] ,
sec_info_sacl_tests [ i ] . sec_info ,
sec_info_sacl_tests [ i ] . sd ,
sec_info_sacl_tests [ i ] . set_werr ,
sec_info_sacl_tests [ i ] . sid_present ,
sec_info_sacl_tests [ i ] . fn ,
sid ) )
{
2010-03-16 14:24:18 +03:00
torture_comment ( tctx , " test_SetSecurityDescriptor_SecInfo failed for SACL \n " ) ;
2007-11-02 16:51:49 +03:00
ret = false ;
goto out ;
}
}
}
out :
test_RestoreSecurity ( p , tctx , handle , key , sd_orig ) ;
return ret ;
}
2007-11-02 16:27:58 +03:00
static bool test_SecurityDescriptors ( struct dcerpc_pipe * p ,
struct torture_context * tctx ,
struct policy_handle * handle ,
const char * key )
{
bool ret = true ;
if ( ! test_SecurityDescriptor ( p , tctx , handle , key ) ) {
2010-03-16 14:24:18 +03:00
torture_comment ( tctx , " test_SecurityDescriptor failed \n " ) ;
2007-11-02 16:27:58 +03:00
ret = false ;
}
2007-11-02 16:37:07 +03:00
if ( ! test_SecurityDescriptorInheritance ( p , tctx , handle , key ) ) {
2010-03-16 14:24:18 +03:00
torture_comment ( tctx , " test_SecurityDescriptorInheritance failed \n " ) ;
2007-11-02 16:37:07 +03:00
ret = false ;
}
2007-11-02 16:43:11 +03:00
if ( ! test_SecurityDescriptorBlockInheritance ( p , tctx , handle , key ) ) {
2010-03-16 14:24:18 +03:00
torture_comment ( tctx , " test_SecurityDescriptorBlockInheritance failed \n " ) ;
2007-11-02 16:43:11 +03:00
ret = false ;
}
2007-11-02 16:51:49 +03:00
if ( ! test_SecurityDescriptorsSecInfo ( p , tctx , handle , key ) ) {
2010-03-16 14:24:18 +03:00
torture_comment ( tctx , " test_SecurityDescriptorsSecInfo failed \n " ) ;
2007-11-02 16:51:49 +03:00
ret = false ;
}
2007-11-02 17:06:58 +03:00
if ( ! test_SecurityDescriptorsMasks ( p , tctx , handle , key ) ) {
2010-03-16 14:24:18 +03:00
torture_comment ( tctx , " test_SecurityDescriptorsMasks failed \n " ) ;
2007-11-02 17:06:58 +03:00
ret = false ;
}
2007-11-02 16:27:58 +03:00
return ret ;
}
2010-03-17 13:36:09 +03:00
static bool test_DeleteKey_opts ( struct dcerpc_binding_handle * b ,
struct torture_context * tctx ,
struct policy_handle * handle ,
const char * key ,
WERROR expected_result )
2007-11-02 16:37:07 +03:00
{
struct winreg_DeleteKey r ;
2010-03-17 13:36:09 +03:00
torture_comment ( tctx , " Testing DeleteKey(%s) \n " , key ) ;
2007-11-02 16:37:07 +03:00
r . in . handle = handle ;
init_winreg_String ( & r . in . key , key ) ;
2010-03-17 13:36:09 +03:00
torture_assert_ntstatus_ok ( tctx , dcerpc_winreg_DeleteKey_r ( b , tctx , & r ) ,
" Delete Key failed " ) ;
torture_assert_werr_equal ( tctx , r . out . result , expected_result ,
" DeleteKey failed " ) ;
2007-11-02 16:37:07 +03:00
return true ;
}
2010-03-17 13:36:09 +03:00
static bool test_DeleteKey ( struct dcerpc_binding_handle * b ,
struct torture_context * tctx ,
struct policy_handle * handle , const char * key )
{
return test_DeleteKey_opts ( b , tctx , handle , key , WERR_OK ) ;
}
2010-03-15 19:56:14 +03:00
static bool test_QueryInfoKey ( struct dcerpc_binding_handle * b ,
2007-10-06 00:45:16 +04:00
struct torture_context * tctx ,
2010-08-05 17:24:20 +04:00
struct policy_handle * handle ,
char * kclass ,
uint32_t * pmax_valnamelen ,
uint32_t * pmax_valbufsize )
2003-11-22 08:34:25 +03:00
{
struct winreg_QueryInfoKey r ;
2008-10-20 17:53:24 +04:00
uint32_t num_subkeys , max_subkeylen , max_classlen ,
2006-09-16 00:36:38 +04:00
num_values , max_valnamelen , max_valbufsize ,
secdescsize ;
NTTIME last_changed_time ;
2003-11-22 08:34:25 +03:00
2006-09-16 00:36:38 +04:00
ZERO_STRUCT ( r ) ;
2003-11-22 08:34:25 +03:00
r . in . handle = handle ;
2006-09-16 00:36:38 +04:00
r . out . num_subkeys = & num_subkeys ;
r . out . max_subkeylen = & max_subkeylen ;
2008-10-20 17:53:24 +04:00
r . out . max_classlen = & max_classlen ;
2006-09-16 00:36:38 +04:00
r . out . num_values = & num_values ;
r . out . max_valnamelen = & max_valnamelen ;
r . out . max_valbufsize = & max_valbufsize ;
r . out . secdescsize = & secdescsize ;
r . out . last_changed_time = & last_changed_time ;
2007-04-18 18:43:05 +04:00
2007-08-26 19:16:40 +04:00
r . out . classname = talloc ( tctx , struct winreg_String ) ;
2007-10-06 00:45:16 +04:00
2007-08-26 19:16:40 +04:00
r . in . classname = talloc ( tctx , struct winreg_String ) ;
2009-02-02 15:04:06 +03:00
init_winreg_String ( r . in . classname , kclass ) ;
2007-10-06 00:45:16 +04:00
torture_assert_ntstatus_ok ( tctx ,
2010-03-15 19:56:14 +03:00
dcerpc_winreg_QueryInfoKey_r ( b , tctx , & r ) ,
2007-10-06 01:22:07 +04:00
" QueryInfoKey failed " ) ;
2004-04-09 02:39:47 +04:00
2007-08-26 19:16:40 +04:00
torture_assert_werr_ok ( tctx , r . out . result , " QueryInfoKey failed " ) ;
2003-11-22 08:34:25 +03:00
2010-08-05 17:24:20 +04:00
if ( pmax_valnamelen ) {
* pmax_valnamelen = max_valnamelen ;
}
if ( pmax_valbufsize ) {
* pmax_valbufsize = max_valbufsize ;
}
2007-04-18 18:43:05 +04:00
return true ;
2003-11-22 08:34:25 +03:00
}
2010-03-15 19:56:14 +03:00
static bool test_SetValue ( struct dcerpc_binding_handle * b ,
2010-03-10 02:06:52 +03:00
struct torture_context * tctx ,
struct policy_handle * handle ,
const char * value_name ,
enum winreg_Type type ,
uint8_t * data ,
uint32_t size )
{
struct winreg_SetValue r ;
struct winreg_String name ;
2010-03-11 20:37:02 +03:00
torture_comment ( tctx , " Testing SetValue(%s), type: %s, offered: 0x%08x) \n " ,
value_name , str_regtype ( type ) , size ) ;
2010-03-10 02:06:52 +03:00
init_winreg_String ( & name , value_name ) ;
r . in . handle = handle ;
r . in . name = name ;
r . in . type = type ;
r . in . data = data ;
r . in . size = size ;
2010-03-15 19:56:14 +03:00
torture_assert_ntstatus_ok ( tctx , dcerpc_winreg_SetValue_r ( b , tctx , & r ) ,
2010-03-10 02:06:52 +03:00
" winreg_SetValue failed " ) ;
torture_assert_werr_ok ( tctx , r . out . result ,
" winreg_SetValue failed " ) ;
return true ;
}
2010-03-15 19:56:14 +03:00
static bool test_DeleteValue ( struct dcerpc_binding_handle * b ,
2010-03-10 02:06:52 +03:00
struct torture_context * tctx ,
struct policy_handle * handle ,
const char * value_name )
{
struct winreg_DeleteValue r ;
struct winreg_String value ;
torture_comment ( tctx , " Testing DeleteValue(%s) \n " , value_name ) ;
init_winreg_String ( & value , value_name ) ;
r . in . handle = handle ;
r . in . value = value ;
2010-03-15 19:56:14 +03:00
torture_assert_ntstatus_ok ( tctx , dcerpc_winreg_DeleteValue_r ( b , tctx , & r ) ,
2010-03-10 02:06:52 +03:00
" winreg_DeleteValue failed " ) ;
torture_assert_werr_ok ( tctx , r . out . result ,
" winreg_DeleteValue failed " ) ;
return true ;
}
2007-08-26 19:16:40 +04:00
static bool test_key ( struct dcerpc_pipe * p , struct torture_context * tctx ,
2008-02-19 18:18:10 +03:00
struct policy_handle * handle , int depth ,
bool test_security ) ;
2003-12-12 09:29:21 +03:00
2007-08-26 19:16:40 +04:00
static bool test_EnumKey ( struct dcerpc_pipe * p , struct torture_context * tctx ,
2008-02-19 18:18:10 +03:00
struct policy_handle * handle , int depth ,
bool test_security )
2003-11-22 08:34:25 +03:00
{
2003-12-12 14:49:29 +03:00
struct winreg_EnumKey r ;
2009-02-02 15:04:06 +03:00
struct winreg_StringBuf kclass , name ;
2003-11-22 08:34:25 +03:00
NTSTATUS status ;
2005-08-17 05:25:58 +04:00
NTTIME t = 0 ;
2010-03-15 19:56:14 +03:00
struct dcerpc_binding_handle * b = p - > binding_handle ;
2003-11-22 08:34:25 +03:00
2009-02-02 15:04:06 +03:00
kclass . name = " " ;
kclass . size = 1024 ;
2005-08-17 05:25:58 +04:00
2008-09-15 23:09:32 +04:00
ZERO_STRUCT ( r ) ;
2003-12-12 14:49:29 +03:00
r . in . handle = handle ;
r . in . enum_index = 0 ;
2005-08-17 05:25:58 +04:00
r . in . name = & name ;
2009-02-02 15:04:06 +03:00
r . in . keyclass = & kclass ;
2005-08-17 05:25:58 +04:00
r . out . name = & name ;
r . in . last_changed_time = & t ;
2003-11-22 08:34:25 +03:00
2003-12-12 14:49:29 +03:00
do {
2005-08-17 05:25:58 +04:00
name . name = NULL ;
2005-11-02 04:01:17 +03:00
name . size = 1024 ;
2005-08-17 05:25:58 +04:00
2010-03-15 19:56:14 +03:00
status = dcerpc_winreg_EnumKey_r ( b , tctx , & r ) ;
2003-11-22 08:34:25 +03:00
2003-12-12 14:49:29 +03:00
if ( NT_STATUS_IS_OK ( status ) & & W_ERROR_IS_OK ( r . out . result ) ) {
struct policy_handle key_handle ;
2003-11-22 08:34:25 +03:00
2007-10-10 15:23:06 +04:00
torture_comment ( tctx , " EnumKey: %d: %s \n " ,
r . in . enum_index ,
2007-10-06 01:22:07 +04:00
r . out . name - > name ) ;
2004-10-29 05:10:40 +04:00
2010-03-15 19:56:14 +03:00
if ( ! test_OpenKey ( b , tctx , handle , r . out . name - > name ,
2007-10-06 01:22:07 +04:00
& key_handle ) ) {
2004-10-29 05:10:40 +04:00
} else {
2008-02-19 18:18:10 +03:00
test_key ( p , tctx , & key_handle ,
depth + 1 , test_security ) ;
2003-12-12 14:49:29 +03:00
}
}
r . in . enum_index + + ;
2004-10-29 01:24:29 +04:00
} while ( NT_STATUS_IS_OK ( status ) & & W_ERROR_IS_OK ( r . out . result ) ) ;
2003-12-12 14:49:29 +03:00
2007-08-26 19:16:40 +04:00
torture_assert_ntstatus_ok ( tctx , status , " EnumKey failed " ) ;
2004-10-29 05:10:40 +04:00
2007-10-06 00:45:16 +04:00
if ( ! W_ERROR_IS_OK ( r . out . result ) & &
2007-08-26 19:16:40 +04:00
! W_ERROR_EQUAL ( r . out . result , WERR_NO_MORE_ITEMS ) ) {
torture_fail ( tctx , " EnumKey failed " ) ;
2004-10-29 05:10:40 +04:00
}
2007-04-18 18:43:05 +04:00
return true ;
2003-12-12 14:49:29 +03:00
}
2010-03-15 19:56:14 +03:00
static bool test_QueryMultipleValues ( struct dcerpc_binding_handle * b ,
2007-10-06 00:45:16 +04:00
struct torture_context * tctx ,
struct policy_handle * handle ,
const char * valuename )
2004-12-12 03:22:30 +03:00
{
struct winreg_QueryMultipleValues r ;
2005-08-24 15:42:46 +04:00
uint32_t bufsize = 0 ;
2004-12-12 03:22:30 +03:00
2008-09-15 23:09:32 +04:00
ZERO_STRUCT ( r ) ;
2010-06-29 13:40:24 +04:00
2004-12-12 03:22:30 +03:00
r . in . key_handle = handle ;
2010-06-29 13:40:24 +04:00
r . in . values_in = r . out . values_out = talloc_zero_array ( tctx , struct QueryMultipleValue , 1 ) ;
r . in . values_in [ 0 ] . ve_valuename = talloc ( tctx , struct winreg_ValNameBuf ) ;
r . in . values_in [ 0 ] . ve_valuename - > name = valuename ;
/* size needs to be set manually for winreg_ValNameBuf */
r . in . values_in [ 0 ] . ve_valuename - > size = strlen_m_term ( valuename ) * 2 ;
2004-12-12 03:22:30 +03:00
r . in . num_values = 1 ;
2007-08-26 19:16:40 +04:00
r . in . buffer_size = r . out . buffer_size = talloc ( tctx , uint32_t ) ;
2005-08-24 15:42:46 +04:00
* r . in . buffer_size = bufsize ;
2007-10-06 00:45:16 +04:00
do {
2005-08-24 15:42:46 +04:00
* r . in . buffer_size = bufsize ;
2007-10-06 00:45:16 +04:00
r . in . buffer = r . out . buffer = talloc_zero_array ( tctx , uint8_t ,
2005-08-24 15:01:10 +04:00
* r . in . buffer_size ) ;
2005-05-25 01:59:01 +04:00
2010-04-09 19:50:51 +04:00
torture_assert_ntstatus_ok ( tctx ,
dcerpc_winreg_QueryMultipleValues_r ( b , tctx , & r ) ,
" QueryMultipleValues failed " ) ;
2007-08-26 19:16:40 +04:00
2005-08-24 15:42:46 +04:00
talloc_free ( r . in . buffer ) ;
bufsize + = 0x20 ;
2005-05-25 01:59:01 +04:00
} while ( W_ERROR_EQUAL ( r . out . result , WERR_MORE_DATA ) ) ;
2004-12-12 03:22:30 +03:00
2007-08-26 19:16:40 +04:00
torture_assert_werr_ok ( tctx , r . out . result , " QueryMultipleValues failed " ) ;
2004-12-12 03:22:30 +03:00
2007-04-18 18:43:05 +04:00
return true ;
2004-12-12 03:22:30 +03:00
}
2010-06-29 23:53:00 +04:00
static bool test_QueryMultipleValues_full ( struct dcerpc_binding_handle * b ,
struct torture_context * tctx ,
struct policy_handle * handle ,
uint32_t num_values ,
2010-08-01 13:17:14 +04:00
const char * const * valuenames ,
2010-06-29 23:53:00 +04:00
bool existing_value )
{
struct winreg_QueryMultipleValues r ;
uint32_t bufsize = 0 ;
int i ;
torture_comment ( tctx , " Testing QueryMultipleValues \n " ) ;
ZERO_STRUCT ( r ) ;
r . in . key_handle = handle ;
r . in . values_in = r . out . values_out = talloc_zero_array ( tctx , struct QueryMultipleValue , 0 ) ;
r . in . buffer_size = r . out . buffer_size = & bufsize ;
torture_assert_ntstatus_ok ( tctx ,
dcerpc_winreg_QueryMultipleValues_r ( b , tctx , & r ) ,
" QueryMultipleValues failed " ) ;
torture_assert_werr_ok ( tctx , r . out . result ,
" QueryMultipleValues failed " ) ;
/* this test crashes w2k8 remote registry */
#if 0
r . in . num_values = num_values ;
r . in . values_in = r . out . values_out = talloc_zero_array ( tctx , struct QueryMultipleValue , num_values ) ;
torture_assert_ntstatus_ok ( tctx ,
dcerpc_winreg_QueryMultipleValues_r ( b , tctx , & r ) ,
" QueryMultipleValues failed " ) ;
torture_assert_werr_ok ( tctx , r . out . result ,
" QueryMultipleValues failed " ) ;
# endif
r . in . num_values = num_values ;
r . in . values_in = r . out . values_out = talloc_zero_array ( tctx , struct QueryMultipleValue , num_values ) ;
for ( i = 0 ; i < r . in . num_values ; i + + ) {
r . in . values_in [ i ] . ve_valuename = talloc_zero ( tctx , struct winreg_ValNameBuf ) ;
r . in . values_in [ i ] . ve_valuename - > name = talloc_strdup ( tctx , valuenames [ i ] ) ;
r . in . values_in [ i ] . ve_valuename - > size = strlen_m_term ( r . in . values_in [ i ] . ve_valuename - > name ) * 2 ;
}
torture_assert_ntstatus_ok ( tctx ,
dcerpc_winreg_QueryMultipleValues_r ( b , tctx , & r ) ,
" QueryMultipleValues failed " ) ;
2015-12-03 17:24:12 +03:00
torture_assert_werr_equal ( tctx , r . out . result , existing_value ? WERR_MORE_DATA : WERR_FILE_NOT_FOUND ,
2010-06-29 23:53:00 +04:00
" QueryMultipleValues failed " ) ;
2015-12-03 17:24:12 +03:00
if ( W_ERROR_EQUAL ( r . out . result , WERR_FILE_NOT_FOUND ) ) {
2010-06-29 23:53:00 +04:00
return true ;
}
if ( W_ERROR_EQUAL ( r . out . result , WERR_MORE_DATA ) ) {
* r . in . buffer_size = 0xff ;
r . in . buffer = r . out . buffer = talloc_zero_array ( tctx , uint8_t , * r . in . buffer_size ) ;
torture_assert_ntstatus_ok ( tctx ,
dcerpc_winreg_QueryMultipleValues_r ( b , tctx , & r ) ,
" QueryMultipleValues failed " ) ;
}
torture_assert_werr_ok ( tctx , r . out . result ,
" QueryMultipleValues failed " ) ;
return true ;
}
static bool test_QueryMultipleValues2_full ( struct dcerpc_binding_handle * b ,
struct torture_context * tctx ,
struct policy_handle * handle ,
uint32_t num_values ,
2010-08-01 13:17:14 +04:00
const char * const * valuenames ,
2010-06-29 23:53:00 +04:00
bool existing_value )
{
struct winreg_QueryMultipleValues2 r ;
uint32_t offered = 0 , needed ;
int i ;
torture_comment ( tctx , " Testing QueryMultipleValues2 \n " ) ;
ZERO_STRUCT ( r ) ;
r . in . key_handle = handle ;
r . in . offered = & offered ;
r . in . values_in = r . out . values_out = talloc_zero_array ( tctx , struct QueryMultipleValue , 0 ) ;
r . out . needed = & needed ;
torture_assert_ntstatus_ok ( tctx ,
dcerpc_winreg_QueryMultipleValues2_r ( b , tctx , & r ) ,
" QueryMultipleValues2 failed " ) ;
torture_assert_werr_ok ( tctx , r . out . result ,
" QueryMultipleValues2 failed " ) ;
/* this test crashes w2k8 remote registry */
#if 0
r . in . num_values = num_values ;
r . in . values_in = r . out . values_out = talloc_zero_array ( tctx , struct QueryMultipleValue , num_values ) ;
torture_assert_ntstatus_ok ( tctx ,
dcerpc_winreg_QueryMultipleValues2_r ( b , tctx , & r ) ,
" QueryMultipleValues2 failed " ) ;
torture_assert_werr_ok ( tctx , r . out . result ,
" QueryMultipleValues2 failed " ) ;
# endif
r . in . num_values = num_values ;
r . in . values_in = r . out . values_out = talloc_zero_array ( tctx , struct QueryMultipleValue , num_values ) ;
for ( i = 0 ; i < r . in . num_values ; i + + ) {
r . in . values_in [ i ] . ve_valuename = talloc_zero ( tctx , struct winreg_ValNameBuf ) ;
r . in . values_in [ i ] . ve_valuename - > name = talloc_strdup ( tctx , valuenames [ i ] ) ;
r . in . values_in [ i ] . ve_valuename - > size = strlen_m_term ( r . in . values_in [ i ] . ve_valuename - > name ) * 2 ;
}
torture_assert_ntstatus_ok ( tctx ,
dcerpc_winreg_QueryMultipleValues2_r ( b , tctx , & r ) ,
" QueryMultipleValues2 failed " ) ;
2015-12-03 17:24:12 +03:00
torture_assert_werr_equal ( tctx , r . out . result , existing_value ? WERR_MORE_DATA : WERR_FILE_NOT_FOUND ,
2010-06-29 23:53:00 +04:00
" QueryMultipleValues2 failed " ) ;
2015-12-03 17:24:12 +03:00
if ( W_ERROR_EQUAL ( r . out . result , WERR_FILE_NOT_FOUND ) ) {
2010-06-29 23:53:00 +04:00
return true ;
}
if ( W_ERROR_EQUAL ( r . out . result , WERR_MORE_DATA ) ) {
* r . in . offered = * r . out . needed ;
r . in . buffer = r . out . buffer = talloc_zero_array ( tctx , uint8_t , * r . in . offered ) ;
torture_assert_ntstatus_ok ( tctx ,
dcerpc_winreg_QueryMultipleValues2_r ( b , tctx , & r ) ,
" QueryMultipleValues2 failed " ) ;
}
torture_assert_werr_ok ( tctx , r . out . result ,
" QueryMultipleValues2 failed " ) ;
return true ;
}
2010-06-29 14:14:02 +04:00
static bool test_QueryMultipleValues2 ( struct dcerpc_binding_handle * b ,
struct torture_context * tctx ,
struct policy_handle * handle ,
const char * valuename )
{
struct winreg_QueryMultipleValues2 r ;
uint32_t offered = 0 , needed ;
ZERO_STRUCT ( r ) ;
r . in . key_handle = handle ;
r . in . values_in = r . out . values_out = talloc_zero_array ( tctx , struct QueryMultipleValue , 1 ) ;
r . in . values_in [ 0 ] . ve_valuename = talloc ( tctx , struct winreg_ValNameBuf ) ;
r . in . values_in [ 0 ] . ve_valuename - > name = valuename ;
/* size needs to be set manually for winreg_ValNameBuf */
r . in . values_in [ 0 ] . ve_valuename - > size = strlen_m_term ( valuename ) * 2 ;
r . in . num_values = 1 ;
r . in . offered = & offered ;
r . out . needed = & needed ;
torture_assert_ntstatus_ok ( tctx ,
dcerpc_winreg_QueryMultipleValues2_r ( b , tctx , & r ) ,
" QueryMultipleValues2 failed " ) ;
if ( W_ERROR_EQUAL ( r . out . result , WERR_MORE_DATA ) ) {
* r . in . offered = * r . out . needed ;
r . in . buffer = r . out . buffer = talloc_zero_array ( tctx , uint8_t , * r . in . offered ) ;
torture_assert_ntstatus_ok ( tctx ,
dcerpc_winreg_QueryMultipleValues2_r ( b , tctx , & r ) ,
" QueryMultipleValues2 failed " ) ;
}
torture_assert_werr_ok ( tctx , r . out . result ,
" QueryMultipleValues2 failed " ) ;
return true ;
}
2010-03-15 19:56:14 +03:00
static bool test_QueryValue ( struct dcerpc_binding_handle * b ,
2007-10-06 00:45:16 +04:00
struct torture_context * tctx ,
struct policy_handle * handle ,
const char * valuename )
2004-12-09 01:02:49 +03:00
{
struct winreg_QueryValue r ;
NTSTATUS status ;
2006-04-30 17:54:03 +04:00
enum winreg_Type zero_type = 0 ;
2005-02-10 08:09:35 +03:00
uint32_t offered = 0xfff ;
2006-04-30 17:54:03 +04:00
uint32_t zero = 0 ;
2004-12-09 01:02:49 +03:00
2008-09-15 23:09:32 +04:00
ZERO_STRUCT ( r ) ;
2004-12-09 01:02:49 +03:00
r . in . handle = handle ;
2004-12-12 03:22:30 +03:00
r . in . data = NULL ;
2008-10-15 19:34:55 +04:00
r . in . value_name = talloc_zero ( tctx , struct winreg_String ) ;
r . in . value_name - > name = valuename ;
2006-04-30 17:54:03 +04:00
r . in . type = & zero_type ;
2008-10-15 19:38:51 +04:00
r . in . data_size = & offered ;
r . in . data_length = & zero ;
2004-12-09 01:02:49 +03:00
2010-03-15 19:56:14 +03:00
status = dcerpc_winreg_QueryValue_r ( b , tctx , & r ) ;
2007-08-26 19:16:40 +04:00
if ( NT_STATUS_IS_ERR ( status ) ) {
torture_fail ( tctx , " QueryValue failed " ) ;
2004-12-09 01:02:49 +03:00
}
2007-08-26 19:16:40 +04:00
torture_assert_werr_ok ( tctx , r . out . result , " QueryValue failed " ) ;
2004-12-09 01:02:49 +03:00
2007-04-18 18:43:05 +04:00
return true ;
2004-12-09 01:02:49 +03:00
}
2010-03-15 19:56:14 +03:00
static bool test_QueryValue_full ( struct dcerpc_binding_handle * b ,
2010-03-10 02:17:59 +03:00
struct torture_context * tctx ,
struct policy_handle * handle ,
const char * valuename ,
bool existing_value )
{
struct winreg_QueryValue r ;
struct winreg_String value_name ;
enum winreg_Type type = REG_NONE ;
uint32_t data_size = 0 ;
uint32_t real_data_size = 0 ;
uint32_t data_length = 0 ;
uint8_t * data = NULL ;
2015-12-03 17:24:12 +03:00
WERROR expected_error = WERR_FILE_NOT_FOUND ;
const char * errmsg_nonexisting = " expected WERR_FILE_NOT_FOUND for nonexisting value " ;
2010-03-10 02:17:59 +03:00
if ( valuename = = NULL ) {
2015-12-03 17:24:27 +03:00
expected_error = WERR_INVALID_PARAMETER ;
errmsg_nonexisting = " expected WERR_INVALID_PARAMETER for NULL valuename " ;
2010-03-10 02:17:59 +03:00
}
ZERO_STRUCT ( r ) ;
init_winreg_String ( & value_name , NULL ) ;
torture_comment ( tctx , " Testing QueryValue(%s) \n " , valuename ) ;
r . in . handle = handle ;
r . in . value_name = & value_name ;
2010-03-15 19:56:14 +03:00
torture_assert_ntstatus_ok ( tctx , dcerpc_winreg_QueryValue_r ( b , tctx , & r ) , " QueryValue failed " ) ;
2015-12-03 17:24:27 +03:00
torture_assert_werr_equal ( tctx , r . out . result , WERR_INVALID_PARAMETER ,
" expected WERR_INVALID_PARAMETER for NULL winreg_String.name " ) ;
2010-03-10 02:17:59 +03:00
init_winreg_String ( & value_name , valuename ) ;
r . in . value_name = & value_name ;
2010-03-15 19:56:14 +03:00
torture_assert_ntstatus_ok ( tctx , dcerpc_winreg_QueryValue_r ( b , tctx , & r ) ,
2010-03-10 02:17:59 +03:00
" QueryValue failed " ) ;
2015-12-03 17:24:27 +03:00
torture_assert_werr_equal ( tctx , r . out . result , WERR_INVALID_PARAMETER ,
" expected WERR_INVALID_PARAMETER for missing type length and size " ) ;
2010-03-10 02:17:59 +03:00
r . in . type = & type ;
r . out . type = & type ;
2010-03-15 19:56:14 +03:00
torture_assert_ntstatus_ok ( tctx , dcerpc_winreg_QueryValue_r ( b , tctx , & r ) ,
2010-03-10 02:17:59 +03:00
" QueryValue failed " ) ;
2015-12-03 17:24:27 +03:00
torture_assert_werr_equal ( tctx , r . out . result , WERR_INVALID_PARAMETER ,
" expected WERR_INVALID_PARAMETER for missing length and size " ) ;
2010-03-10 02:17:59 +03:00
r . in . data_length = & data_length ;
r . out . data_length = & data_length ;
2010-03-15 19:56:14 +03:00
torture_assert_ntstatus_ok ( tctx , dcerpc_winreg_QueryValue_r ( b , tctx , & r ) ,
2010-03-10 02:17:59 +03:00
" QueryValue failed " ) ;
2015-12-03 17:24:27 +03:00
torture_assert_werr_equal ( tctx , r . out . result , WERR_INVALID_PARAMETER ,
" expected WERR_INVALID_PARAMETER for missing size " ) ;
2010-03-10 02:17:59 +03:00
r . in . data_size = & data_size ;
r . out . data_size = & data_size ;
2010-03-15 19:56:14 +03:00
torture_assert_ntstatus_ok ( tctx , dcerpc_winreg_QueryValue_r ( b , tctx , & r ) ,
2010-03-10 02:17:59 +03:00
" QueryValue failed " ) ;
if ( existing_value ) {
torture_assert_werr_ok ( tctx , r . out . result ,
" QueryValue failed " ) ;
} else {
torture_assert_werr_equal ( tctx , r . out . result , expected_error ,
2010-05-21 12:53:35 +04:00
errmsg_nonexisting ) ;
2010-03-10 02:17:59 +03:00
}
real_data_size = * r . out . data_size ;
data = talloc_zero_array ( tctx , uint8_t , 0 ) ;
r . in . data = data ;
r . out . data = data ;
* r . in . data_size = 0 ;
* r . out . data_size = 0 ;
2010-03-15 19:56:14 +03:00
torture_assert_ntstatus_ok ( tctx , dcerpc_winreg_QueryValue_r ( b , tctx , & r ) ,
2010-03-10 02:17:59 +03:00
" QueryValue failed " ) ;
if ( existing_value ) {
torture_assert_werr_equal ( tctx , r . out . result , WERR_MORE_DATA ,
2010-05-21 12:53:35 +04:00
" expected WERR_MORE_DATA for query with too small buffer " ) ;
2010-03-10 02:17:59 +03:00
} else {
torture_assert_werr_equal ( tctx , r . out . result , expected_error ,
2010-05-21 12:53:35 +04:00
errmsg_nonexisting ) ;
2010-03-10 02:17:59 +03:00
}
data = talloc_zero_array ( tctx , uint8_t , real_data_size ) ;
r . in . data = data ;
r . out . data = data ;
r . in . data_size = & real_data_size ;
r . out . data_size = & real_data_size ;
2010-03-15 19:56:14 +03:00
torture_assert_ntstatus_ok ( tctx , dcerpc_winreg_QueryValue_r ( b , tctx , & r ) ,
2010-03-10 02:17:59 +03:00
" QueryValue failed " ) ;
if ( existing_value ) {
torture_assert_werr_ok ( tctx , r . out . result ,
" QueryValue failed " ) ;
} else {
torture_assert_werr_equal ( tctx , r . out . result , expected_error ,
2010-05-21 12:53:35 +04:00
errmsg_nonexisting ) ;
2010-03-10 02:17:59 +03:00
}
return true ;
}
2023-11-15 19:36:46 +03:00
static bool test_EnumValue_one ( struct dcerpc_binding_handle * b ,
struct torture_context * tctx ,
struct policy_handle * handle ,
int max_valnamelen )
{
struct winreg_EnumValue r ;
bool ret = true ;
DATA_BLOB blob ;
blob = data_blob_string_const ( " data_1 " ) ;
torture_assert_goto ( tctx ,
test_SetValue ( b , tctx , handle , " v1 " , REG_BINARY , blob . data , blob . length ) ,
ret , done ,
" test_SetValue failed " ) ;
blob = data_blob_string_const ( " data_2 " ) ;
torture_assert_goto ( tctx ,
test_SetValue ( b , tctx , handle , " v2 " , REG_BINARY , blob . data , blob . length ) ,
ret , done ,
" test_SetValue failed " ) ;
ZERO_STRUCT ( r ) ;
r . in . handle = handle ;
r . in . enum_index = 0 ;
do {
enum winreg_Type type = REG_NONE ;
uint32_t size = 0 , zero = 0 ;
struct winreg_ValNameBuf name ;
char n = ' \0 ' ;
r . in . name = & name ;
r . in . type = & type ;
r . in . length = & zero ;
r . in . size = & size ;
r . out . name = & name ;
r . out . size = & size ;
name . name = & n ;
name . size = max_valnamelen + 2 ;
name . length = 0 ;
r . in . value = talloc_array ( tctx , uint8_t , 0 ) ;
torture_assert ( tctx , r . in . value , " nomem " ) ;
torture_assert_ntstatus_ok_goto ( tctx ,
dcerpc_winreg_EnumValue_r ( b , tctx , & r ) ,
ret , done ,
" EnumValue failed " ) ;
if ( W_ERROR_EQUAL ( r . out . result , WERR_NO_MORE_ITEMS ) ) {
break ;
}
torture_assert_werr_equal_goto ( tctx ,
r . out . result , WERR_MORE_DATA ,
ret , done ,
" unexpected return code " ) ;
* r . in . size = * r . out . size ;
r . in . value = talloc_zero_array ( tctx , uint8_t , * r . in . size ) ;
torture_assert ( tctx , r . in . value , " nomem " ) ;
torture_assert_ntstatus_ok_goto ( tctx ,
dcerpc_winreg_EnumValue_r ( b , tctx , & r ) ,
ret , done ,
" EnumValue failed " ) ;
torture_assert_werr_ok_goto ( tctx , r . out . result ,
ret , done ,
" unexpected return code " ) ;
r . in . enum_index + + ;
} while ( W_ERROR_IS_OK ( r . out . result ) ) ;
torture_assert_werr_equal_goto ( tctx , r . out . result , WERR_NO_MORE_ITEMS ,
ret , done ,
" EnumValue failed " ) ;
done :
test_DeleteValue ( b , tctx , handle , " v1 " ) ;
test_DeleteValue ( b , tctx , handle , " v2 " ) ;
return ret ;
}
2010-03-15 19:56:14 +03:00
static bool test_EnumValue ( struct dcerpc_binding_handle * b ,
struct torture_context * tctx ,
2007-10-06 00:45:16 +04:00
struct policy_handle * handle , int max_valnamelen ,
int max_valbufsize )
2003-12-12 14:49:29 +03:00
{
struct winreg_EnumValue r ;
2006-04-30 17:54:03 +04:00
enum winreg_Type type = 0 ;
2005-02-10 08:09:35 +03:00
uint32_t size = max_valbufsize , zero = 0 ;
2007-04-18 18:43:05 +04:00
bool ret = true ;
2010-08-05 17:24:20 +04:00
uint8_t * data = NULL ;
2009-01-16 02:25:57 +03:00
struct winreg_ValNameBuf name ;
2010-08-05 17:24:20 +04:00
char n = ' \0 ' ;
2005-08-17 05:25:58 +04:00
2008-09-15 23:09:32 +04:00
ZERO_STRUCT ( r ) ;
2004-10-11 03:03:12 +04:00
r . in . handle = handle ;
r . in . enum_index = 0 ;
2005-08-17 05:25:58 +04:00
r . in . name = & name ;
r . out . name = & name ;
2004-10-11 03:03:12 +04:00
r . in . type = & type ;
2004-12-09 10:52:00 +03:00
r . in . length = & zero ;
r . in . size = & size ;
2007-10-06 00:45:16 +04:00
2003-11-22 08:34:25 +03:00
do {
2010-08-05 17:24:20 +04:00
name . name = & n ;
name . size = max_valnamelen + 2 ;
name . length = 0 ;
data = NULL ;
if ( size ) {
2017-08-25 15:17:54 +03:00
data = talloc_array ( tctx , uint8_t , size ) ;
2010-08-05 17:24:20 +04:00
}
r . in . value = data ;
2007-10-10 15:23:06 +04:00
torture_assert_ntstatus_ok ( tctx ,
2010-03-15 19:56:14 +03:00
dcerpc_winreg_EnumValue_r ( b , tctx , & r ) ,
2007-10-06 01:22:07 +04:00
" EnumValue failed " ) ;
2004-10-11 03:03:12 +04:00
2004-12-09 01:02:49 +03:00
if ( W_ERROR_IS_OK ( r . out . result ) ) {
2010-03-15 19:56:14 +03:00
ret & = test_QueryValue ( b , tctx , handle ,
2007-10-10 15:23:06 +04:00
r . out . name - > name ) ;
2010-03-15 19:56:14 +03:00
ret & = test_QueryMultipleValues ( b , tctx , handle ,
2007-10-10 15:23:06 +04:00
r . out . name - > name ) ;
2010-06-29 14:14:02 +04:00
ret & = test_QueryMultipleValues2 ( b , tctx , handle ,
r . out . name - > name ) ;
2004-12-09 01:02:49 +03:00
}
2010-08-05 17:24:20 +04:00
talloc_free ( data ) ;
2003-12-12 14:49:29 +03:00
r . in . enum_index + + ;
2003-11-22 08:34:25 +03:00
} while ( W_ERROR_IS_OK ( r . out . result ) ) ;
2004-04-13 01:59:41 +04:00
2007-08-26 19:16:40 +04:00
torture_assert_werr_equal ( tctx , r . out . result , WERR_NO_MORE_ITEMS ,
2007-10-06 01:22:07 +04:00
" EnumValue failed " ) ;
2004-10-11 03:03:12 +04:00
2004-12-09 01:02:49 +03:00
return ret ;
2003-11-22 08:34:25 +03:00
}
2010-03-15 19:56:14 +03:00
static bool test_AbortSystemShutdown ( struct dcerpc_binding_handle * b ,
2007-10-06 00:45:16 +04:00
struct torture_context * tctx )
2004-04-09 02:39:47 +04:00
{
2007-08-26 19:16:40 +04:00
struct winreg_AbortSystemShutdown r ;
uint16_t server = 0x0 ;
2004-04-09 02:39:47 +04:00
2008-09-15 23:09:32 +04:00
ZERO_STRUCT ( r ) ;
2007-08-26 19:16:40 +04:00
r . in . server = & server ;
2007-10-06 00:45:16 +04:00
torture_assert_ntstatus_ok ( tctx ,
2010-03-15 19:56:14 +03:00
dcerpc_winreg_AbortSystemShutdown_r ( b , tctx , & r ) ,
2007-10-06 00:45:16 +04:00
" AbortSystemShutdown failed " ) ;
2004-04-09 02:39:47 +04:00
2007-10-10 15:23:06 +04:00
torture_assert_werr_ok ( tctx , r . out . result ,
" AbortSystemShutdown failed " ) ;
2004-04-09 02:39:47 +04:00
2007-04-18 18:43:05 +04:00
return true ;
2004-04-09 02:39:47 +04:00
}
2007-10-06 00:45:16 +04:00
static bool test_InitiateSystemShutdown ( struct torture_context * tctx ,
2007-08-31 19:43:03 +04:00
struct dcerpc_pipe * p )
2004-12-13 14:00:24 +03:00
{
2007-08-26 19:16:40 +04:00
struct winreg_InitiateSystemShutdown r ;
2005-03-17 23:28:01 +03:00
uint16_t hostname = 0x0 ;
2010-03-15 19:56:14 +03:00
struct dcerpc_binding_handle * b = p - > binding_handle ;
2007-08-26 19:16:40 +04:00
2008-09-15 23:09:32 +04:00
ZERO_STRUCT ( r ) ;
2005-03-17 23:28:01 +03:00
r . in . hostname = & hostname ;
2008-02-19 13:57:32 +03:00
r . in . message = talloc ( tctx , struct lsa_StringLarge ) ;
init_lsa_StringLarge ( r . in . message , " spottyfood " ) ;
2004-12-13 14:00:24 +03:00
r . in . force_apps = 1 ;
2007-08-26 19:16:40 +04:00
r . in . timeout = 30 ;
2008-10-15 18:25:06 +04:00
r . in . do_reboot = 1 ;
2004-12-13 14:00:24 +03:00
2007-10-06 00:45:16 +04:00
torture_assert_ntstatus_ok ( tctx ,
2010-03-15 19:56:14 +03:00
dcerpc_winreg_InitiateSystemShutdown_r ( b , tctx , & r ) ,
2007-10-06 00:45:16 +04:00
" InitiateSystemShutdown failed " ) ;
2004-12-13 14:00:24 +03:00
2007-10-10 15:23:06 +04:00
torture_assert_werr_ok ( tctx , r . out . result ,
" InitiateSystemShutdown failed " ) ;
2004-12-13 14:00:24 +03:00
2010-03-15 19:56:14 +03:00
return test_AbortSystemShutdown ( b , tctx ) ;
2004-12-13 14:00:24 +03:00
}
2007-08-26 19:16:40 +04:00
static bool test_InitiateSystemShutdownEx ( struct torture_context * tctx ,
2007-10-06 00:45:16 +04:00
struct dcerpc_pipe * p )
2004-04-09 02:39:47 +04:00
{
2007-08-26 19:16:40 +04:00
struct winreg_InitiateSystemShutdownEx r ;
uint16_t hostname = 0x0 ;
2010-03-15 19:56:14 +03:00
struct dcerpc_binding_handle * b = p - > binding_handle ;
2004-04-09 02:39:47 +04:00
2008-09-15 23:09:32 +04:00
ZERO_STRUCT ( r ) ;
2007-08-26 19:16:40 +04:00
r . in . hostname = & hostname ;
2008-02-19 13:57:32 +03:00
r . in . message = talloc ( tctx , struct lsa_StringLarge ) ;
init_lsa_StringLarge ( r . in . message , " spottyfood " ) ;
2007-08-26 19:16:40 +04:00
r . in . force_apps = 1 ;
r . in . timeout = 30 ;
2008-10-15 18:25:06 +04:00
r . in . do_reboot = 1 ;
2007-08-26 19:16:40 +04:00
r . in . reason = 0 ;
2004-04-09 02:39:47 +04:00
2007-10-06 00:45:16 +04:00
torture_assert_ntstatus_ok ( tctx ,
2010-03-15 19:56:14 +03:00
dcerpc_winreg_InitiateSystemShutdownEx_r ( b , tctx , & r ) ,
2007-08-26 19:16:40 +04:00
" InitiateSystemShutdownEx failed " ) ;
2004-04-09 02:39:47 +04:00
2007-10-06 00:45:16 +04:00
torture_assert_werr_ok ( tctx , r . out . result ,
" InitiateSystemShutdownEx failed " ) ;
2004-04-09 02:39:47 +04:00
2010-03-15 19:56:14 +03:00
return test_AbortSystemShutdown ( b , tctx ) ;
2004-04-09 02:39:47 +04:00
}
2003-11-23 14:57:15 +03:00
# define MAX_DEPTH 2 /* Only go this far down the tree */
2003-11-23 09:31:10 +03:00
2007-10-06 00:45:16 +04:00
static bool test_key ( struct dcerpc_pipe * p , struct torture_context * tctx ,
2008-02-19 18:18:10 +03:00
struct policy_handle * handle , int depth ,
bool test_security )
2003-11-23 09:31:10 +03:00
{
2010-03-15 19:56:14 +03:00
struct dcerpc_binding_handle * b = p - > binding_handle ;
2010-08-05 17:24:20 +04:00
uint32_t max_valnamelen = 0 ;
uint32_t max_valbufsize = 0 ;
2010-03-15 19:56:14 +03:00
2003-11-23 14:57:15 +03:00
if ( depth = = MAX_DEPTH )
2007-04-18 18:43:05 +04:00
return true ;
2003-11-23 09:38:37 +03:00
2010-08-05 17:24:20 +04:00
if ( ! test_QueryInfoKey ( b , tctx , handle , NULL ,
& max_valnamelen , & max_valbufsize ) ) {
2003-11-23 09:31:10 +03:00
}
2010-03-15 19:56:14 +03:00
if ( ! test_NotifyChangeKeyValue ( b , tctx , handle ) ) {
2004-12-13 05:04:34 +03:00
}
2007-10-06 00:45:16 +04:00
2008-02-19 18:18:10 +03:00
if ( test_security & & ! test_GetKeySecurity ( p , tctx , handle , NULL ) ) {
2004-12-12 02:28:48 +03:00
}
2008-02-19 18:18:10 +03:00
if ( ! test_EnumKey ( p , tctx , handle , depth , test_security ) ) {
2003-12-12 14:49:29 +03:00
}
2003-11-23 09:31:10 +03:00
2010-08-05 17:24:20 +04:00
if ( ! test_EnumValue ( b , tctx , handle , max_valnamelen , max_valbufsize ) ) {
}
if ( ! test_EnumValue ( b , tctx , handle , max_valnamelen , 0xFFFF ) ) {
2003-12-12 14:49:29 +03:00
}
2003-12-12 09:29:21 +03:00
2023-11-15 19:36:46 +03:00
if ( ! test_EnumValue_one ( b , tctx , handle , 0xff ) ) {
return false ;
}
2010-03-15 19:56:14 +03:00
test_CloseKey ( b , tctx , handle ) ;
2003-11-23 14:57:15 +03:00
2007-04-18 18:43:05 +04:00
return true ;
2003-11-23 14:57:15 +03:00
}
2010-03-17 02:05:02 +03:00
static bool test_SetValue_simple ( struct dcerpc_binding_handle * b ,
2010-03-11 20:37:02 +03:00
struct torture_context * tctx ,
struct policy_handle * handle )
2010-03-10 15:04:17 +03:00
{
const char * value_name = TEST_VALUE ;
uint32_t value = 0x12345678 ;
2010-03-19 21:50:17 +03:00
uint64_t value2 = 0x12345678 ;
2010-03-11 20:37:02 +03:00
const char * string = " torture " ;
2010-05-20 22:49:44 +04:00
const char * array [ 2 ] ;
2010-03-11 20:37:02 +03:00
DATA_BLOB blob ;
enum winreg_Type types [ ] = {
REG_DWORD ,
2010-03-19 21:40:07 +03:00
REG_DWORD_BIG_ENDIAN ,
2010-03-19 21:50:17 +03:00
REG_QWORD ,
2010-03-11 20:37:02 +03:00
REG_BINARY ,
REG_SZ ,
REG_MULTI_SZ
} ;
int t ;
2010-05-20 22:49:44 +04:00
array [ 0 ] = " array0 " ;
array [ 1 ] = NULL ;
2010-03-11 20:37:02 +03:00
torture_comment ( tctx , " Testing SetValue (standard formats) \n " ) ;
for ( t = 0 ; t < ARRAY_SIZE ( types ) ; t + + ) {
enum winreg_Type w_type ;
uint32_t w_size , w_length ;
uint8_t * w_data ;
switch ( types [ t ] ) {
case REG_DWORD :
2010-03-19 21:40:07 +03:00
case REG_DWORD_BIG_ENDIAN :
2010-03-11 20:37:02 +03:00
blob = data_blob_talloc_zero ( tctx , 4 ) ;
SIVAL ( blob . data , 0 , value ) ;
break ;
2010-03-19 21:50:17 +03:00
case REG_QWORD :
blob = data_blob_talloc_zero ( tctx , 8 ) ;
SBVAL ( blob . data , 0 , value2 ) ;
2010-03-23 18:43:41 +03:00
break ;
2010-03-11 20:37:02 +03:00
case REG_BINARY :
blob = data_blob_string_const ( " binary_blob " ) ;
break ;
case REG_SZ :
2010-05-20 22:49:44 +04:00
torture_assert ( tctx , push_reg_sz ( tctx , & blob , string ) , " failed to push REG_SZ " ) ;
2010-03-11 20:37:02 +03:00
break ;
case REG_MULTI_SZ :
2010-05-20 22:49:44 +04:00
torture_assert ( tctx , push_reg_multi_sz ( tctx , & blob , array ) , " failed to push REG_MULTI_SZ " ) ;
2010-03-11 20:37:02 +03:00
break ;
default :
break ;
}
2010-03-10 15:04:17 +03:00
2010-03-11 20:37:02 +03:00
torture_assert ( tctx ,
2010-03-15 19:56:14 +03:00
test_SetValue ( b , tctx , handle , value_name , types [ t ] , blob . data , blob . length ) ,
2010-03-11 20:37:02 +03:00
" test_SetValue failed " ) ;
torture_assert ( tctx ,
2010-03-15 19:56:14 +03:00
test_QueryValue_full ( b , tctx , handle , value_name , true ) ,
2010-03-11 20:37:02 +03:00
talloc_asprintf ( tctx , " test_QueryValue_full for %s value failed " , value_name ) ) ;
torture_assert ( tctx ,
2010-03-15 19:56:14 +03:00
test_winreg_QueryValue ( tctx , b , handle , value_name , & w_type , & w_size , & w_length , & w_data ) ,
2010-03-11 20:37:02 +03:00
" test_winreg_QueryValue failed " ) ;
torture_assert ( tctx ,
2010-03-15 19:56:14 +03:00
test_DeleteValue ( b , tctx , handle , value_name ) ,
2010-03-11 20:37:02 +03:00
" test_DeleteValue failed " ) ;
torture_assert_int_equal ( tctx , w_type , types [ t ] , " winreg type mismatch " ) ;
torture_assert_int_equal ( tctx , w_size , blob . length , " winreg size mismatch " ) ;
torture_assert_int_equal ( tctx , w_length , blob . length , " winreg length mismatch " ) ;
torture_assert_mem_equal ( tctx , w_data , blob . data , blob . length , " winreg buffer mismatch " ) ;
}
2010-03-10 15:04:17 +03:00
2010-03-11 20:37:02 +03:00
torture_comment ( tctx , " Testing SetValue (standard formats) succeeded \n " ) ;
2010-03-10 15:04:17 +03:00
return true ;
}
2010-06-23 14:09:35 +04:00
static bool test_SetValue_values ( struct dcerpc_binding_handle * b ,
struct torture_context * tctx ,
struct policy_handle * handle )
{
DATA_BLOB blob ;
const char * values [ ] = {
" torture_value " ,
" torture value " ,
" torture,value " ,
" torture;value " ,
" torture/value " ,
2010-06-23 16:59:27 +04:00
" torture \\ value " ,
" torture_value_name " ,
" torture value name " ,
" torture,value,name " ,
" torture;value;name " ,
" torture/value/name " ,
" torture \\ value \\ name " ,
2010-06-23 14:09:35 +04:00
} ;
int i ;
torture_comment ( tctx , " Testing SetValue (values) \n " ) ;
for ( i = 0 ; i < ARRAY_SIZE ( values ) ; i + + ) {
enum winreg_Type w_type ;
uint32_t w_size , w_length ;
uint8_t * w_data ;
2010-06-23 16:59:27 +04:00
blob = data_blob_talloc ( tctx , NULL , 32 ) ;
generate_random_buffer ( blob . data , 32 ) ;
2010-06-23 14:09:35 +04:00
torture_assert ( tctx ,
test_SetValue ( b , tctx , handle , values [ i ] , REG_BINARY , blob . data , blob . length ) ,
" test_SetValue failed " ) ;
torture_assert ( tctx ,
test_QueryValue_full ( b , tctx , handle , values [ i ] , true ) ,
talloc_asprintf ( tctx , " test_QueryValue_full for %s value failed " , values [ i ] ) ) ;
torture_assert ( tctx ,
test_winreg_QueryValue ( tctx , b , handle , values [ i ] , & w_type , & w_size , & w_length , & w_data ) ,
" test_winreg_QueryValue failed " ) ;
torture_assert ( tctx ,
test_DeleteValue ( b , tctx , handle , values [ i ] ) ,
" test_DeleteValue failed " ) ;
torture_assert_int_equal ( tctx , w_type , REG_BINARY , " winreg type mismatch " ) ;
torture_assert_int_equal ( tctx , w_size , blob . length , " winreg size mismatch " ) ;
torture_assert_int_equal ( tctx , w_length , blob . length , " winreg length mismatch " ) ;
torture_assert_mem_equal ( tctx , w_data , blob . data , blob . length , " winreg buffer mismatch " ) ;
}
torture_comment ( tctx , " Testing SetValue (values) succeeded \n " ) ;
return true ;
}
2010-03-15 19:56:14 +03:00
typedef NTSTATUS ( * winreg_open_fn ) ( struct dcerpc_binding_handle * , TALLOC_CTX * , void * ) ;
2003-11-23 14:57:15 +03:00
2010-03-15 19:56:14 +03:00
static bool test_SetValue_extended ( struct dcerpc_binding_handle * b ,
2010-03-11 20:52:38 +03:00
struct torture_context * tctx ,
struct policy_handle * handle )
{
const char * value_name = TEST_VALUE ;
enum winreg_Type types [ ] = {
REG_NONE ,
REG_SZ ,
REG_EXPAND_SZ ,
REG_BINARY ,
REG_DWORD ,
REG_DWORD_BIG_ENDIAN ,
REG_LINK ,
REG_MULTI_SZ ,
REG_RESOURCE_LIST ,
REG_FULL_RESOURCE_DESCRIPTOR ,
REG_RESOURCE_REQUIREMENTS_LIST ,
REG_QWORD ,
12 ,
13 ,
14 ,
55 ,
123456 ,
2010-03-13 03:37:32 +03:00
653210 ,
__LINE__
2010-03-11 20:52:38 +03:00
} ;
2010-03-13 03:37:32 +03:00
int t , l ;
2010-03-11 20:52:38 +03:00
2010-07-01 05:04:39 +04:00
if ( torture_setting_bool ( tctx , " samba4 " , false ) ) {
torture_skip ( tctx , " skipping extended SetValue test against Samba4 " ) ;
2010-03-11 22:23:13 +03:00
}
2010-03-11 20:52:38 +03:00
torture_comment ( tctx , " Testing SetValue (extended formats) \n " ) ;
for ( t = 0 ; t < ARRAY_SIZE ( types ) ; t + + ) {
2010-06-30 19:13:42 +04:00
for ( l = 0 ; l < 16 ; l + + ) {
2010-03-11 20:52:38 +03:00
enum winreg_Type w_type ;
uint32_t w_size , w_length ;
uint8_t * w_data ;
2010-03-16 18:05:07 +03:00
uint32_t size ;
uint8_t * data ;
size = l ;
data = talloc_array ( tctx , uint8_t , size ) ;
generate_random_buffer ( data , size ) ;
2010-03-11 20:52:38 +03:00
torture_assert ( tctx ,
2010-03-16 18:05:07 +03:00
test_SetValue ( b , tctx , handle , value_name , types [ t ] , data , size ) ,
2010-03-11 20:52:38 +03:00
" test_SetValue failed " ) ;
torture_assert ( tctx ,
2010-03-15 19:56:14 +03:00
test_winreg_QueryValue ( tctx , b , handle , value_name , & w_type , & w_size , & w_length , & w_data ) ,
2010-03-11 20:52:38 +03:00
" test_winreg_QueryValue failed " ) ;
torture_assert ( tctx ,
2010-03-15 19:56:14 +03:00
test_DeleteValue ( b , tctx , handle , value_name ) ,
2010-03-11 20:52:38 +03:00
" test_DeleteValue failed " ) ;
torture_assert_int_equal ( tctx , w_type , types [ t ] , " winreg type mismatch " ) ;
2010-03-16 18:05:07 +03:00
torture_assert_int_equal ( tctx , w_size , size , " winreg size mismatch " ) ;
torture_assert_int_equal ( tctx , w_length , size , " winreg length mismatch " ) ;
torture_assert_mem_equal ( tctx , w_data , data , size , " winreg buffer mismatch " ) ;
2010-03-11 20:52:38 +03:00
}
}
torture_comment ( tctx , " Testing SetValue (extended formats) succeeded \n " ) ;
return true ;
}
2010-06-23 17:00:06 +04:00
static bool test_create_keynames ( struct dcerpc_binding_handle * b ,
struct torture_context * tctx ,
struct policy_handle * handle )
{
const char * keys [ ] = {
" torture_key " ,
" torture key " ,
" torture,key " ,
" torture/key " ,
" torture \\ key " ,
} ;
int i ;
for ( i = 0 ; i < ARRAY_SIZE ( keys ) ; i + + ) {
enum winreg_CreateAction action_taken ;
struct policy_handle new_handle ;
char * q , * tmp ;
torture_assert ( tctx ,
test_CreateKey_opts ( tctx , b , handle , keys [ i ] , NULL ,
REG_OPTION_NON_VOLATILE ,
SEC_FLAG_MAXIMUM_ALLOWED ,
NULL ,
WERR_OK ,
& action_taken ,
& new_handle ) ,
talloc_asprintf ( tctx , " failed to create '%s' key " , keys [ i ] ) ) ;
torture_assert_int_equal ( tctx , action_taken , REG_CREATED_NEW_KEY , " unexpected action " ) ;
torture_assert ( tctx ,
test_DeleteKey_opts ( b , tctx , handle , keys [ i ] , WERR_OK ) ,
" failed to delete key " ) ;
torture_assert ( tctx ,
2015-12-03 17:24:12 +03:00
test_DeleteKey_opts ( b , tctx , handle , keys [ i ] , WERR_FILE_NOT_FOUND ) ,
2010-06-23 17:00:06 +04:00
" failed 2nd delete key " ) ;
tmp = talloc_strdup ( tctx , keys [ i ] ) ;
q = strchr ( tmp , ' \\ ' ) ;
if ( q ! = NULL ) {
* q = ' \0 ' ;
q + + ;
torture_assert ( tctx ,
test_DeleteKey_opts ( b , tctx , handle , tmp , WERR_OK ) ,
" failed to delete key " ) ;
torture_assert ( tctx ,
2015-12-03 17:24:12 +03:00
test_DeleteKey_opts ( b , tctx , handle , tmp , WERR_FILE_NOT_FOUND ) ,
2010-06-23 17:00:06 +04:00
" failed 2nd delete key " ) ;
}
}
return true ;
}
2010-03-10 02:43:57 +03:00
# define KEY_CURRENT_VERSION "SOFTWARE\\MICROSOFT\\WINDOWS NT\\CURRENTVERSION"
# define VALUE_CURRENT_VERSION "CurrentVersion"
2010-06-29 23:53:00 +04:00
# define VALUE_SYSTEM_ROOT "SystemRoot"
2010-03-10 02:43:57 +03:00
2010-09-09 23:26:43 +04:00
static const struct {
const char * values [ 3 ] ;
uint32_t num_values ;
bool existing_value ;
const char * error_message ;
} multiple_values_tests [ ] = {
{
2010-09-10 21:28:07 +04:00
. values = { VALUE_CURRENT_VERSION , NULL , NULL } ,
2010-09-09 23:26:43 +04:00
. num_values = 1 ,
. existing_value = true ,
. error_message = NULL
} , {
2010-09-10 21:28:07 +04:00
. values = { VALUE_SYSTEM_ROOT , NULL , NULL } ,
2010-09-09 23:26:43 +04:00
. num_values = 1 ,
. existing_value = true ,
. error_message = NULL
} , {
2010-09-10 21:28:07 +04:00
. values = { VALUE_CURRENT_VERSION , VALUE_SYSTEM_ROOT , NULL } ,
2010-09-09 23:26:43 +04:00
. num_values = 2 ,
. existing_value = true ,
. error_message = NULL
} , {
2010-09-10 21:28:07 +04:00
. values = { VALUE_CURRENT_VERSION , VALUE_SYSTEM_ROOT ,
VALUE_CURRENT_VERSION } ,
2010-09-09 23:26:43 +04:00
. num_values = 3 ,
. existing_value = true ,
. error_message = NULL
} , {
2010-09-10 21:28:07 +04:00
. values = { VALUE_CURRENT_VERSION , NULL , VALUE_SYSTEM_ROOT } ,
2010-09-09 23:26:43 +04:00
. num_values = 3 ,
. existing_value = false ,
. error_message = NULL
} , {
2010-09-10 21:28:07 +04:00
. values = { VALUE_CURRENT_VERSION , " " , VALUE_SYSTEM_ROOT } ,
2010-09-09 23:26:43 +04:00
. num_values = 3 ,
. existing_value = false ,
. error_message = NULL
} , {
2010-09-10 21:28:07 +04:00
. values = { " IDoNotExist " , NULL , NULL } ,
2010-09-09 23:26:43 +04:00
. num_values = 1 ,
. existing_value = false ,
. error_message = NULL
} , {
2010-09-10 21:28:07 +04:00
. values = { " IDoNotExist " , VALUE_CURRENT_VERSION , NULL } ,
2010-09-09 23:26:43 +04:00
. num_values = 2 ,
. existing_value = false ,
. error_message = NULL
} , {
2010-09-10 21:28:07 +04:00
. values = { VALUE_CURRENT_VERSION , " IDoNotExist " , NULL } ,
2010-09-09 23:26:43 +04:00
. num_values = 2 ,
. existing_value = false ,
. error_message = NULL
}
} ;
2010-03-17 02:05:52 +03:00
static bool test_HKLM_wellknown ( struct torture_context * tctx ,
struct dcerpc_binding_handle * b ,
struct policy_handle * handle )
{
struct policy_handle newhandle ;
2010-06-29 23:53:00 +04:00
int i ;
2010-03-17 02:05:52 +03:00
/* FIXME: s3 does not support SEC_FLAG_MAXIMUM_ALLOWED yet */
if ( torture_setting_bool ( tctx , " samba3 " , false ) ) {
2010-03-17 02:55:41 +03:00
torture_assert ( tctx , test_OpenKey_opts ( tctx , b , handle ,
KEY_CURRENT_VERSION ,
2010-04-09 15:51:42 +04:00
REG_OPTION_NON_VOLATILE ,
2010-03-17 02:55:41 +03:00
KEY_QUERY_VALUE ,
& newhandle ,
WERR_OK ) ,
2010-03-17 02:05:52 +03:00
" failed to open current version key " ) ;
} else {
torture_assert ( tctx , test_OpenKey ( b , tctx , handle , KEY_CURRENT_VERSION , & newhandle ) ,
" failed to open current version key " ) ;
}
torture_assert ( tctx , test_QueryValue_full ( b , tctx , & newhandle , VALUE_CURRENT_VERSION , true ) ,
" failed to query current version " ) ;
torture_assert ( tctx , test_QueryValue_full ( b , tctx , & newhandle , " IDoNotExist " , false ) ,
2010-05-21 12:56:37 +04:00
" succeeded to query nonexistent value " ) ;
2010-03-17 02:05:52 +03:00
torture_assert ( tctx , test_QueryValue_full ( b , tctx , & newhandle , NULL , false ) ,
2010-05-21 12:56:37 +04:00
" succeeded to query value with NULL name " ) ;
2010-03-17 02:05:52 +03:00
torture_assert ( tctx , test_QueryValue_full ( b , tctx , & newhandle , " " , false ) ,
2010-05-21 12:56:37 +04:00
" succeeded to query nonexistent default value ( \" \" ) " ) ;
2010-03-17 02:05:52 +03:00
2010-06-30 04:07:15 +04:00
if ( torture_setting_bool ( tctx , " samba4 " , false ) ) {
torture_comment ( tctx , " skipping QueryMultipleValues{2} tests against Samba4 \n " ) ;
2010-06-29 23:53:00 +04:00
goto close_key ;
}
for ( i = 0 ; i < ARRAY_SIZE ( multiple_values_tests ) ; i + + ) {
const char * msg ;
msg = talloc_asprintf ( tctx ,
" failed to query %d %sexisting values \n " ,
multiple_values_tests [ i ] . num_values ,
multiple_values_tests [ i ] . existing_value ? " " : " non " ) ;
torture_assert ( tctx ,
test_QueryMultipleValues_full ( b , tctx , & newhandle ,
multiple_values_tests [ i ] . num_values ,
multiple_values_tests [ i ] . values ,
multiple_values_tests [ i ] . existing_value ) ,
msg ) ;
torture_assert ( tctx ,
test_QueryMultipleValues2_full ( b , tctx , & newhandle ,
multiple_values_tests [ i ] . num_values ,
multiple_values_tests [ i ] . values ,
multiple_values_tests [ i ] . existing_value ) ,
msg ) ;
}
close_key :
2010-03-17 02:05:52 +03:00
torture_assert ( tctx , test_CloseKey ( b , tctx , & newhandle ) ,
" failed to close current version key " ) ;
return true ;
}
2010-05-21 02:28:36 +04:00
static bool test_OpenHive ( struct torture_context * tctx ,
struct dcerpc_binding_handle * b ,
struct policy_handle * handle ,
int hkey )
{
struct winreg_OpenHKLM r ;
r . in . system_name = 0 ;
r . in . access_mask = SEC_FLAG_MAXIMUM_ALLOWED ;
r . out . handle = handle ;
switch ( hkey ) {
case HKEY_LOCAL_MACHINE :
torture_assert_ntstatus_ok ( tctx ,
dcerpc_winreg_OpenHKLM_r ( b , tctx , & r ) ,
" failed to open HKLM " ) ;
torture_assert_werr_ok ( tctx , r . out . result ,
" failed to open HKLM " ) ;
break ;
case HKEY_CURRENT_USER :
torture_assert_ntstatus_ok ( tctx ,
2010-08-01 13:18:05 +04:00
dcerpc_winreg_OpenHKCU_r ( b , tctx , ( struct winreg_OpenHKCU * ) ( void * ) & r ) ,
2010-05-21 02:28:36 +04:00
" failed to open HKCU " ) ;
torture_assert_werr_ok ( tctx , r . out . result ,
" failed to open HKCU " ) ;
break ;
case HKEY_USERS :
torture_assert_ntstatus_ok ( tctx ,
2010-08-01 13:18:05 +04:00
dcerpc_winreg_OpenHKU_r ( b , tctx , ( struct winreg_OpenHKU * ) ( void * ) & r ) ,
2010-05-21 02:28:36 +04:00
" failed to open HKU " ) ;
torture_assert_werr_ok ( tctx , r . out . result ,
" failed to open HKU " ) ;
break ;
case HKEY_CLASSES_ROOT :
torture_assert_ntstatus_ok ( tctx ,
2010-08-01 13:18:05 +04:00
dcerpc_winreg_OpenHKCR_r ( b , tctx , ( struct winreg_OpenHKCR * ) ( void * ) & r ) ,
2010-05-21 02:28:36 +04:00
" failed to open HKCR " ) ;
torture_assert_werr_ok ( tctx , r . out . result ,
" failed to open HKCR " ) ;
break ;
default :
torture_warning ( tctx , " unsupported hkey: 0x%08x \n " , hkey ) ;
return false ;
}
return true ;
}
2010-03-17 02:57:22 +03:00
static bool test_volatile_keys ( struct torture_context * tctx ,
struct dcerpc_binding_handle * b ,
2010-05-20 22:50:31 +04:00
struct policy_handle * handle ,
int hkey )
2010-03-17 02:57:22 +03:00
{
2010-08-05 17:35:52 +04:00
struct policy_handle new_handle , hive_handle ;
2013-12-04 17:01:49 +04:00
enum winreg_CreateAction action_taken = REG_ACTION_NONE ;
ZERO_STRUCT ( new_handle ) ;
ZERO_STRUCT ( hive_handle ) ;
2010-03-17 02:57:22 +03:00
2010-05-21 02:28:36 +04:00
torture_comment ( tctx , " Testing VOLATILE key \n " ) ;
test_DeleteKey ( b , tctx , handle , TEST_KEY_VOLATILE ) ;
2010-03-17 02:57:22 +03:00
torture_assert ( tctx ,
test_CreateKey_opts ( tctx , b , handle , TEST_KEY_VOLATILE , NULL ,
2010-04-09 15:51:42 +04:00
REG_OPTION_VOLATILE ,
2010-03-17 02:57:22 +03:00
SEC_FLAG_MAXIMUM_ALLOWED ,
NULL ,
WERR_OK ,
& action_taken ,
& new_handle ) ,
2010-04-09 15:51:42 +04:00
" failed to create REG_OPTION_VOLATILE type key " ) ;
2010-03-17 02:57:22 +03:00
torture_assert_int_equal ( tctx , action_taken , REG_CREATED_NEW_KEY , " unexpected action " ) ;
torture_assert ( tctx ,
test_CreateKey_opts ( tctx , b , & new_handle , TEST_SUBKEY_VOLATILE , NULL ,
2010-04-09 15:51:42 +04:00
REG_OPTION_NON_VOLATILE ,
2010-03-17 02:57:22 +03:00
SEC_FLAG_MAXIMUM_ALLOWED ,
NULL ,
WERR_CHILD_MUST_BE_VOLATILE ,
NULL ,
NULL ) ,
2010-04-09 15:51:42 +04:00
" failed to fail create REG_OPTION_VOLATILE type key " ) ;
2010-03-17 02:57:22 +03:00
torture_assert ( tctx ,
test_CloseKey ( b , tctx , & new_handle ) ,
" failed to close " ) ;
torture_assert ( tctx ,
test_OpenKey_opts ( tctx , b , handle , TEST_KEY_VOLATILE ,
2010-04-09 15:51:42 +04:00
REG_OPTION_NON_VOLATILE ,
2010-03-17 02:57:22 +03:00
SEC_FLAG_MAXIMUM_ALLOWED ,
& new_handle ,
WERR_OK ) ,
" failed to open volatile key " ) ;
torture_assert ( tctx ,
test_DeleteKey ( b , tctx , handle , TEST_KEY_VOLATILE ) ,
" failed to delete key " ) ;
torture_assert ( tctx ,
test_CreateKey_opts ( tctx , b , handle , TEST_KEY_VOLATILE , NULL ,
2010-04-09 15:51:42 +04:00
REG_OPTION_VOLATILE ,
2010-03-17 02:57:22 +03:00
SEC_FLAG_MAXIMUM_ALLOWED ,
NULL ,
WERR_OK ,
& action_taken ,
& new_handle ) ,
2010-04-09 15:51:42 +04:00
" failed to create REG_OPTION_VOLATILE type key " ) ;
2010-03-17 02:57:22 +03:00
torture_assert_int_equal ( tctx , action_taken , REG_CREATED_NEW_KEY , " unexpected action " ) ;
torture_assert ( tctx ,
test_CloseKey ( b , tctx , & new_handle ) ,
" failed to close " ) ;
torture_assert ( tctx ,
test_OpenKey_opts ( tctx , b , handle , TEST_KEY_VOLATILE ,
2010-04-09 15:51:42 +04:00
REG_OPTION_VOLATILE ,
2010-03-17 02:57:22 +03:00
SEC_FLAG_MAXIMUM_ALLOWED ,
& new_handle ,
WERR_OK ) ,
" failed to open volatile key " ) ;
torture_assert ( tctx ,
2010-05-21 02:28:36 +04:00
test_CloseKey ( b , tctx , & new_handle ) ,
" failed to close " ) ;
2010-03-17 02:57:22 +03:00
torture_assert ( tctx ,
2010-08-05 17:35:52 +04:00
test_OpenHive ( tctx , b , & hive_handle , hkey ) ,
2010-05-21 02:28:36 +04:00
" failed top open hive " ) ;
torture_assert ( tctx ,
2010-08-05 17:35:52 +04:00
test_OpenKey_opts ( tctx , b , & hive_handle , TEST_KEY_VOLATILE ,
2010-05-21 02:28:36 +04:00
REG_OPTION_VOLATILE ,
SEC_FLAG_MAXIMUM_ALLOWED ,
& new_handle ,
2015-12-03 17:24:12 +03:00
WERR_FILE_NOT_FOUND ) ,
2010-05-21 02:28:36 +04:00
" failed to open volatile key " ) ;
torture_assert ( tctx ,
2010-08-05 17:35:52 +04:00
test_OpenKey_opts ( tctx , b , & hive_handle , TEST_KEY_VOLATILE ,
2010-05-21 02:28:36 +04:00
REG_OPTION_NON_VOLATILE ,
SEC_FLAG_MAXIMUM_ALLOWED ,
& new_handle ,
2015-12-03 17:24:12 +03:00
WERR_FILE_NOT_FOUND ) ,
2010-05-21 02:28:36 +04:00
" failed to open volatile key " ) ;
2010-08-05 17:35:52 +04:00
torture_assert ( tctx ,
test_CloseKey ( b , tctx , & hive_handle ) ,
" failed to close " ) ;
torture_assert ( tctx ,
test_DeleteKey ( b , tctx , handle , TEST_KEY_VOLATILE ) ,
" failed to delete key " ) ;
2010-05-21 02:28:36 +04:00
torture_comment ( tctx , " Testing VOLATILE key succeeded \n " ) ;
2010-03-17 02:57:22 +03:00
return true ;
}
2010-05-21 03:25:16 +04:00
static const char * kernel_mode_registry_path ( struct torture_context * tctx ,
int hkey ,
const char * sid_string ,
const char * path )
{
switch ( hkey ) {
case HKEY_LOCAL_MACHINE :
return talloc_asprintf ( tctx , " \\ Registry \\ MACHINE \\ %s " , path ) ;
case HKEY_CURRENT_USER :
return talloc_asprintf ( tctx , " \\ Registry \\ USER \\ %s \\ %s " , sid_string , path ) ;
case HKEY_USERS :
return talloc_asprintf ( tctx , " \\ Registry \\ USER \\ %s " , path ) ;
case HKEY_CLASSES_ROOT :
return talloc_asprintf ( tctx , " \\ Registry \\ MACHINE \\ Software \\ Classes \\ %s " , path ) ;
default :
torture_warning ( tctx , " unsupported hkey: 0x%08x \n " , hkey ) ;
return NULL ;
}
}
2010-03-17 02:57:22 +03:00
static bool test_symlink_keys ( struct torture_context * tctx ,
struct dcerpc_binding_handle * b ,
2010-05-20 22:50:31 +04:00
struct policy_handle * handle ,
2010-05-20 16:00:57 +04:00
const char * key ,
2010-05-20 22:50:31 +04:00
int hkey )
2010-03-17 02:57:22 +03:00
{
struct policy_handle new_handle ;
enum winreg_CreateAction action_taken ;
2010-04-09 03:07:39 +04:00
DATA_BLOB blob ;
2010-05-20 16:00:57 +04:00
uint32_t value = 42 ;
const char * test_key_symlink_dest ;
const char * test_key_symlink ;
const char * kernel_mode_path ;
2010-03-17 02:57:22 +03:00
2010-05-20 16:00:57 +04:00
/* disable until we know how to delete a symbolic link */
2010-03-17 02:57:22 +03:00
torture_skip ( tctx , " symlink test disabled " ) ;
2010-04-09 15:51:42 +04:00
torture_comment ( tctx , " Testing REG_OPTION_CREATE_LINK key \n " ) ;
2010-03-17 02:57:22 +03:00
2010-05-20 16:00:57 +04:00
/* create destination key with testvalue */
test_key_symlink = talloc_asprintf ( tctx , " %s \\ %s " ,
key , TEST_KEY_SYMLINK ) ;
test_key_symlink_dest = talloc_asprintf ( tctx , " %s \\ %s " ,
key , TEST_KEY_SYMLINK_DEST ) ;
test_DeleteKey ( b , tctx , handle , test_key_symlink ) ;
torture_assert ( tctx ,
test_CreateKey_opts ( tctx , b , handle , test_key_symlink_dest , NULL ,
0 ,
SEC_FLAG_MAXIMUM_ALLOWED ,
NULL ,
WERR_OK ,
& action_taken ,
& new_handle ) ,
" failed to create symlink destination " ) ;
blob = data_blob_talloc_zero ( tctx , 4 ) ;
SIVAL ( blob . data , 0 , value ) ;
torture_assert ( tctx ,
test_SetValue ( b , tctx , & new_handle , " TestValue " , REG_DWORD , blob . data , blob . length ) ,
" failed to create TestValue " ) ;
torture_assert ( tctx ,
test_CloseKey ( b , tctx , & new_handle ) ,
" failed to close " ) ;
/* create symlink */
2010-03-17 02:57:22 +03:00
torture_assert ( tctx ,
2010-05-20 16:00:57 +04:00
test_CreateKey_opts ( tctx , b , handle , test_key_symlink , NULL ,
2010-04-09 15:51:42 +04:00
REG_OPTION_CREATE_LINK | REG_OPTION_VOLATILE ,
2010-03-17 02:57:22 +03:00
SEC_FLAG_MAXIMUM_ALLOWED ,
NULL ,
WERR_OK ,
& action_taken ,
& new_handle ) ,
2010-04-09 15:51:42 +04:00
" failed to create REG_OPTION_CREATE_LINK type key " ) ;
2010-03-17 02:57:22 +03:00
torture_assert_int_equal ( tctx , action_taken , REG_CREATED_NEW_KEY , " unexpected action " ) ;
2010-05-20 16:00:57 +04:00
kernel_mode_path = kernel_mode_registry_path ( tctx , hkey , NULL , test_key_symlink_dest ) ;
2010-04-09 03:07:39 +04:00
torture_assert ( tctx ,
convert_string_talloc ( tctx , CH_UNIX , CH_UTF16 ,
2010-05-20 16:00:57 +04:00
kernel_mode_path ,
strlen ( kernel_mode_path ) , /* not NULL terminated */
2011-03-24 02:59:41 +03:00
& blob . data , & blob . length ) ,
2010-04-09 03:07:39 +04:00
" failed to convert " ) ;
torture_assert ( tctx ,
test_SetValue ( b , tctx , & new_handle , " SymbolicLinkValue " , REG_LINK , blob . data , blob . length ) ,
" failed to create SymbolicLinkValue value " ) ;
2010-03-17 02:57:22 +03:00
torture_assert ( tctx ,
test_CloseKey ( b , tctx , & new_handle ) ,
" failed to close " ) ;
2010-05-20 16:00:57 +04:00
/* test follow symlink */
torture_assert ( tctx ,
test_OpenKey_opts ( tctx , b , handle , test_key_symlink ,
0 ,
SEC_FLAG_MAXIMUM_ALLOWED ,
& new_handle ,
WERR_OK ) ,
" failed to follow symlink key " ) ;
torture_assert ( tctx ,
test_QueryValue ( b , tctx , & new_handle , " TestValue " ) ,
" failed to query value " ) ;
torture_assert ( tctx ,
test_CloseKey ( b , tctx , & new_handle ) ,
" failed to close " ) ;
/* delete link */
2010-03-17 02:57:22 +03:00
torture_assert ( tctx ,
2010-05-20 16:00:57 +04:00
test_OpenKey_opts ( tctx , b , handle , test_key_symlink ,
2010-04-09 15:51:42 +04:00
REG_OPTION_OPEN_LINK | REG_OPTION_VOLATILE ,
2010-03-17 02:57:22 +03:00
SEC_FLAG_MAXIMUM_ALLOWED ,
& new_handle ,
WERR_OK ) ,
" failed to open symlink key " ) ;
torture_assert ( tctx ,
2010-05-20 16:00:57 +04:00
test_DeleteValue ( b , tctx , & new_handle , " SymbolicLinkValue " ) ,
" failed to delete value SymbolicLinkValue " ) ;
torture_assert ( tctx ,
test_CloseKey ( b , tctx , & new_handle ) ,
" failed to close " ) ;
torture_assert ( tctx ,
test_DeleteKey ( b , tctx , handle , test_key_symlink ) ,
" failed to delete key " ) ;
/* delete destination */
torture_assert ( tctx ,
test_DeleteKey ( b , tctx , handle , test_key_symlink_dest ) ,
2010-03-17 02:57:22 +03:00
" failed to delete key " ) ;
return true ;
}
static bool test_CreateKey_keytypes ( struct torture_context * tctx ,
struct dcerpc_binding_handle * b ,
2010-05-20 22:50:31 +04:00
struct policy_handle * handle ,
2010-05-20 16:00:57 +04:00
const char * key ,
2010-05-20 22:50:31 +04:00
int hkey )
2010-03-17 02:57:22 +03:00
{
if ( torture_setting_bool ( tctx , " samba3 " , false ) | |
torture_setting_bool ( tctx , " samba4 " , false ) ) {
torture_skip ( tctx , " skipping CreateKey keytypes test against Samba " ) ;
}
torture_assert ( tctx ,
2010-05-20 22:50:31 +04:00
test_volatile_keys ( tctx , b , handle , hkey ) ,
2010-03-17 02:57:22 +03:00
" failed to test volatile keys " ) ;
torture_assert ( tctx ,
2010-05-20 16:00:57 +04:00
test_symlink_keys ( tctx , b , handle , key , hkey ) ,
2010-03-17 02:57:22 +03:00
" failed to test symlink keys " ) ;
return true ;
}
2010-03-17 03:25:42 +03:00
static bool test_key_base ( struct torture_context * tctx ,
struct dcerpc_binding_handle * b ,
2010-05-20 22:50:31 +04:00
struct policy_handle * handle ,
2010-05-21 14:42:55 +04:00
const char * base_key ,
2010-05-20 22:50:31 +04:00
int hkey )
2003-11-23 14:57:15 +03:00
{
2010-03-17 03:25:42 +03:00
struct policy_handle newhandle ;
2008-02-19 18:18:10 +03:00
bool ret = true , created = false , deleted = false ;
2010-03-17 03:25:42 +03:00
bool created3 = false ;
2010-05-21 14:42:55 +04:00
const char * test_key1 ;
const char * test_key3 ;
2010-05-21 14:49:23 +04:00
const char * test_subkey ;
2003-11-23 14:57:15 +03:00
2010-05-21 14:42:55 +04:00
test_Cleanup ( b , tctx , handle , base_key ) ;
2005-08-24 15:01:10 +04:00
2010-05-21 14:42:55 +04:00
if ( ! test_CreateKey ( b , tctx , handle , base_key , NULL ) ) {
2008-02-19 18:03:32 +03:00
torture_comment ( tctx ,
2010-05-21 14:42:55 +04:00
" CreateKey(%s) failed \n " , base_key ) ;
2008-02-19 18:03:32 +03:00
}
2010-05-21 14:42:55 +04:00
test_key1 = talloc_asprintf ( tctx , " %s \\ %s " , base_key , TEST_KEY1 ) ;
if ( ! test_CreateKey ( b , tctx , handle , test_key1 , NULL ) ) {
2007-10-10 15:23:06 +04:00
torture_comment ( tctx ,
" CreateKey failed - not considering a failure \n " ) ;
2005-05-25 01:59:01 +04:00
} else {
2007-04-18 18:43:05 +04:00
created = true ;
2003-11-23 09:31:10 +03:00
}
2010-03-17 03:25:42 +03:00
if ( created ) {
if ( ! test_FlushKey ( b , tctx , handle ) ) {
torture_comment ( tctx , " FlushKey failed \n " ) ;
ret = false ;
}
2004-04-12 03:16:47 +04:00
2010-05-21 14:42:55 +04:00
if ( ! test_OpenKey ( b , tctx , handle , test_key1 , & newhandle ) ) {
2010-03-17 03:25:42 +03:00
torture_fail ( tctx ,
" CreateKey failed (OpenKey after Create didn't work) \n " ) ;
}
2004-04-06 00:44:33 +04:00
2010-05-21 02:28:36 +04:00
if ( hkey = = HKEY_CURRENT_USER ) {
torture_assert ( tctx , test_SetValue_simple ( b , tctx , & newhandle ) ,
" simple SetValue test failed " ) ;
2010-06-23 14:09:35 +04:00
torture_assert ( tctx , test_SetValue_values ( b , tctx , & newhandle ) ,
" values SetValue test failed " ) ;
2010-05-21 02:28:36 +04:00
torture_assert ( tctx , test_SetValue_extended ( b , tctx , & newhandle ) ,
" extended SetValue test failed " ) ;
2010-06-23 17:00:06 +04:00
torture_assert ( tctx , test_create_keynames ( b , tctx , & newhandle ) ,
" keyname CreateKey test failed " ) ;
2010-05-20 16:00:57 +04:00
} else {
torture_assert ( tctx , test_CreateKey_keytypes ( tctx , b , & newhandle , test_key1 , hkey ) ,
2010-05-21 02:28:36 +04:00
" keytype test failed " ) ;
2023-11-15 19:36:46 +03:00
torture_assert ( tctx , test_EnumValue_one ( b , tctx , & newhandle , 0xff ) ,
" simple EnumValue test failed " ) ;
2010-05-21 02:28:36 +04:00
}
2010-03-17 03:25:42 +03:00
if ( ! test_CloseKey ( b , tctx , & newhandle ) ) {
torture_fail ( tctx ,
" CreateKey failed (CloseKey after Open didn't work) \n " ) ;
}
2010-05-21 14:42:55 +04:00
if ( ! test_DeleteKey ( b , tctx , handle , test_key1 ) ) {
2010-08-05 18:05:31 +04:00
torture_comment ( tctx , " DeleteKey(%s) failed \n " ,
test_key1 ) ;
2010-03-17 03:25:42 +03:00
ret = false ;
} else {
deleted = true ;
}
if ( ! test_FlushKey ( b , tctx , handle ) ) {
torture_comment ( tctx , " FlushKey failed \n " ) ;
ret = false ;
}
if ( deleted ) {
2010-05-21 14:42:55 +04:00
if ( ! test_OpenKey_opts ( tctx , b , handle , test_key1 ,
2010-04-09 15:51:42 +04:00
REG_OPTION_NON_VOLATILE ,
2010-03-17 03:25:42 +03:00
SEC_FLAG_MAXIMUM_ALLOWED ,
& newhandle ,
2015-12-03 17:24:12 +03:00
WERR_FILE_NOT_FOUND ) ) {
2010-03-17 03:25:42 +03:00
torture_comment ( tctx ,
" DeleteKey failed (OpenKey after Delete "
2015-12-03 17:24:12 +03:00
" did not return WERR_FILE_NOT_FOUND) \n " ) ;
2010-03-17 03:25:42 +03:00
ret = false ;
}
}
2010-05-21 14:42:55 +04:00
test_key3 = talloc_asprintf ( tctx , " %s \\ %s " , base_key , TEST_KEY3 ) ;
if ( test_CreateKey ( b , tctx , handle , test_key3 , NULL ) ) {
2010-03-17 03:25:42 +03:00
created3 = true ;
}
2010-05-21 14:49:23 +04:00
test_subkey = talloc_asprintf ( tctx , " %s \\ %s " , test_key3 , TEST_SUBKEY ) ;
2010-03-17 03:25:42 +03:00
if ( created3 ) {
2010-05-21 14:49:23 +04:00
if ( test_CreateKey ( b , tctx , handle , test_subkey , NULL ) ) {
if ( ! test_DeleteKey ( b , tctx , handle , test_subkey ) ) {
2010-08-05 18:05:31 +04:00
torture_comment ( tctx , " DeleteKey(%s) failed \n " , test_subkey ) ;
2010-03-17 03:25:42 +03:00
ret = false ;
}
}
2010-05-21 14:42:55 +04:00
if ( ! test_DeleteKey ( b , tctx , handle , test_key3 ) ) {
2010-08-05 18:05:31 +04:00
torture_comment ( tctx , " DeleteKey(%s) failed \n " , test_key3 ) ;
2010-03-17 03:25:42 +03:00
ret = false ;
}
}
2010-03-10 15:04:17 +03:00
}
2010-05-21 14:42:55 +04:00
test_Cleanup ( b , tctx , handle , base_key ) ;
2007-11-02 16:18:07 +03:00
2010-03-17 03:25:42 +03:00
return ret ;
}
static bool test_key_base_sd ( struct torture_context * tctx ,
struct dcerpc_pipe * p ,
2010-05-21 14:42:55 +04:00
struct policy_handle * handle ,
const char * base_key )
2010-03-17 03:25:42 +03:00
{
struct policy_handle newhandle ;
bool ret = true , created2 = false , created4 = false ;
struct dcerpc_binding_handle * b = p - > binding_handle ;
2010-05-21 14:42:55 +04:00
const char * test_key2 ;
const char * test_key4 ;
2010-03-17 03:25:42 +03:00
2010-05-21 14:49:23 +04:00
torture_skip ( tctx , " security descriptor test disabled \n " ) ;
2010-03-17 13:31:43 +03:00
if ( torture_setting_bool ( tctx , " samba3 " , false ) | |
torture_setting_bool ( tctx , " samba4 " , false ) ) {
torture_skip ( tctx , " skipping security descriptor tests against Samba " ) ;
}
2010-05-21 14:42:55 +04:00
test_Cleanup ( b , tctx , handle , base_key ) ;
2010-03-17 03:25:42 +03:00
2010-05-21 14:42:55 +04:00
if ( ! test_CreateKey ( b , tctx , handle , base_key , NULL ) ) {
2010-03-17 03:25:42 +03:00
torture_comment ( tctx ,
2010-05-21 14:42:55 +04:00
" CreateKey(%s) failed \n " , base_key ) ;
2010-03-17 03:25:42 +03:00
}
2010-05-21 14:42:55 +04:00
test_key2 = talloc_asprintf ( tctx , " %s \\ %s " , base_key , TEST_KEY2 ) ;
if ( test_CreateKey_sd ( b , tctx , handle , test_key2 ,
2010-03-17 03:25:42 +03:00
NULL , & newhandle ) ) {
created2 = true ;
}
if ( created2 & & ! test_CloseKey ( b , tctx , & newhandle ) ) {
torture_comment ( tctx , " CloseKey failed \n " ) ;
2007-04-18 18:43:05 +04:00
ret = false ;
2003-11-23 14:57:15 +03:00
}
2010-05-21 14:42:55 +04:00
test_key4 = talloc_asprintf ( tctx , " %s \\ %s " , base_key , TEST_KEY4 ) ;
if ( test_CreateKey_sd ( b , tctx , handle , test_key4 , NULL , & newhandle ) ) {
2010-03-17 03:25:42 +03:00
created4 = true ;
}
if ( created4 & & ! test_CloseKey ( b , tctx , & newhandle ) ) {
torture_comment ( tctx , " CloseKey failed \n " ) ;
2007-04-18 18:43:05 +04:00
ret = false ;
2004-04-12 03:16:47 +04:00
}
2010-05-21 14:42:55 +04:00
if ( created4 & & ! test_SecurityDescriptors ( p , tctx , handle , test_key4 ) ) {
2010-03-17 03:25:42 +03:00
ret = false ;
}
2010-05-21 14:42:55 +04:00
if ( created4 & & ! test_DeleteKey ( b , tctx , handle , test_key4 ) ) {
2010-08-05 18:05:31 +04:00
torture_comment ( tctx , " DeleteKey(%s) failed \n " , test_key4 ) ;
2010-03-17 03:25:42 +03:00
ret = false ;
}
2010-05-21 14:42:55 +04:00
if ( created2 & & ! test_DeleteKey ( b , tctx , handle , test_key4 ) ) {
2010-08-05 18:05:31 +04:00
torture_comment ( tctx , " DeleteKey(%s) failed \n " , test_key4 ) ;
2007-04-18 18:43:05 +04:00
ret = false ;
2004-04-06 00:44:33 +04:00
}
2010-05-21 14:42:55 +04:00
test_Cleanup ( b , tctx , handle , base_key ) ;
2010-03-17 03:25:42 +03:00
return ret ;
}
static bool test_Open ( struct torture_context * tctx , struct dcerpc_pipe * p ,
void * userdata )
{
struct policy_handle handle ;
bool ret = true ;
struct winreg_OpenHKLM r ;
struct dcerpc_binding_handle * b = p - > binding_handle ;
2010-05-21 14:42:55 +04:00
const char * torture_base_key ;
2010-05-20 22:50:31 +04:00
int hkey = 0 ;
2010-03-17 03:25:42 +03:00
2010-04-13 19:36:51 +04:00
winreg_open_fn open_fn = ( winreg_open_fn ) userdata ;
2010-03-17 03:25:42 +03:00
r . in . system_name = 0 ;
r . in . access_mask = SEC_FLAG_MAXIMUM_ALLOWED ;
r . out . handle = & handle ;
torture_assert_ntstatus_ok ( tctx , open_fn ( b , tctx , & r ) ,
" open " ) ;
2010-03-15 19:56:14 +03:00
if ( ! test_GetVersion ( b , tctx , & handle ) ) {
2007-08-26 19:16:40 +04:00
torture_comment ( tctx , " GetVersion failed \n " ) ;
2007-04-18 18:43:05 +04:00
ret = false ;
2004-04-09 02:39:47 +04:00
}
2010-04-13 19:36:51 +04:00
if ( open_fn = = ( winreg_open_fn ) dcerpc_winreg_OpenHKLM_r ) {
2010-05-20 22:50:31 +04:00
hkey = HKEY_LOCAL_MACHINE ;
2010-05-21 14:42:55 +04:00
torture_base_key = " SOFTWARE \\ Samba \\ " TEST_KEY_BASE ;
2010-05-20 22:50:31 +04:00
} else if ( open_fn = = ( winreg_open_fn ) dcerpc_winreg_OpenHKU_r ) {
hkey = HKEY_USERS ;
2010-05-21 14:42:55 +04:00
torture_base_key = TEST_KEY_BASE ;
2010-05-20 22:50:31 +04:00
} else if ( open_fn = = ( winreg_open_fn ) dcerpc_winreg_OpenHKCR_r ) {
hkey = HKEY_CLASSES_ROOT ;
2010-05-21 14:42:55 +04:00
torture_base_key = TEST_KEY_BASE ;
2010-05-20 22:50:31 +04:00
} else if ( open_fn = = ( winreg_open_fn ) dcerpc_winreg_OpenHKCU_r ) {
hkey = HKEY_CURRENT_USER ;
2010-05-21 14:42:55 +04:00
torture_base_key = TEST_KEY_BASE ;
2010-05-20 22:50:31 +04:00
} else {
torture_fail ( tctx , " unsupported hkey " ) ;
}
if ( hkey = = HKEY_LOCAL_MACHINE ) {
2010-03-17 03:25:42 +03:00
torture_assert ( tctx ,
test_HKLM_wellknown ( tctx , b , & handle ) ,
" failed to test HKLM wellknown keys " ) ;
2007-07-11 01:35:20 +04:00
}
2010-05-21 14:42:55 +04:00
if ( ! test_key_base ( tctx , b , & handle , torture_base_key , hkey ) ) {
torture_warning ( tctx , " failed to test TEST_KEY_BASE(%s) " ,
torture_base_key ) ;
2010-03-17 03:25:42 +03:00
ret = false ;
2007-07-11 01:35:20 +04:00
}
2010-05-21 14:42:55 +04:00
if ( ! test_key_base_sd ( tctx , p , & handle , torture_base_key ) ) {
torture_warning ( tctx , " failed to test TEST_KEY_BASE(%s) sd " ,
torture_base_key ) ;
2007-07-11 01:35:20 +04:00
ret = false ;
}
2003-11-23 14:57:15 +03:00
/* The HKCR hive has a very large fanout */
2010-05-20 22:50:31 +04:00
if ( hkey = = HKEY_CLASSES_ROOT ) {
2008-02-19 18:18:10 +03:00
if ( ! test_key ( p , tctx , & handle , MAX_DEPTH - 1 , false ) ) {
2007-04-18 18:43:05 +04:00
ret = false ;
2004-04-05 17:50:45 +04:00
}
2010-05-21 14:42:55 +04:00
} else if ( hkey = = HKEY_LOCAL_MACHINE ) {
/* FIXME we are not allowed to enum values in the HKLM root */
2008-02-19 18:03:32 +03:00
} else {
2008-02-19 18:18:10 +03:00
if ( ! test_key ( p , tctx , & handle , 0 , false ) ) {
2008-02-19 18:03:32 +03:00
ret = false ;
}
2004-04-05 17:50:45 +04:00
}
return ret ;
2003-11-23 09:31:10 +03:00
}
2003-11-22 08:34:25 +03:00
2007-08-26 19:16:40 +04:00
struct torture_suite * torture_rpc_winreg ( TALLOC_CTX * mem_ctx )
2003-11-21 08:28:36 +03:00
{
2007-08-28 20:24:18 +04:00
struct torture_rpc_tcase * tcase ;
2010-12-11 05:26:31 +03:00
struct torture_suite * suite = torture_suite_create ( mem_ctx , " winreg " ) ;
2007-08-31 19:43:03 +04:00
struct torture_test * test ;
2003-11-21 08:28:36 +03:00
2007-10-06 00:45:16 +04:00
tcase = torture_suite_add_rpc_iface_tcase ( suite , " winreg " ,
2007-08-31 19:43:03 +04:00
& ndr_table_winreg ) ;
2003-11-23 09:31:10 +03:00
2007-10-06 00:45:16 +04:00
test = torture_rpc_tcase_add_test ( tcase , " InitiateSystemShutdown " ,
2007-08-31 19:43:03 +04:00
test_InitiateSystemShutdown ) ;
test - > dangerous = true ;
2003-11-21 08:28:36 +03:00
2007-10-06 00:45:16 +04:00
test = torture_rpc_tcase_add_test ( tcase , " InitiateSystemShutdownEx " ,
2007-08-31 19:43:03 +04:00
test_InitiateSystemShutdownEx ) ;
test - > dangerous = true ;
2004-04-11 20:04:06 +04:00
2010-03-17 03:25:42 +03:00
torture_rpc_tcase_add_test_ex ( tcase , " HKLM " ,
2008-02-19 18:18:10 +03:00
test_Open ,
2010-07-31 22:59:02 +04:00
( void * ) dcerpc_winreg_OpenHKLM_r ) ;
2010-03-17 03:25:42 +03:00
torture_rpc_tcase_add_test_ex ( tcase , " HKU " ,
2008-02-19 18:18:10 +03:00
test_Open ,
2010-07-31 22:59:02 +04:00
( void * ) dcerpc_winreg_OpenHKU_r ) ;
2010-03-17 03:25:42 +03:00
torture_rpc_tcase_add_test_ex ( tcase , " HKCR " ,
2008-02-19 18:18:10 +03:00
test_Open ,
2010-07-31 22:59:02 +04:00
( void * ) dcerpc_winreg_OpenHKCR_r ) ;
2010-03-17 03:25:42 +03:00
torture_rpc_tcase_add_test_ex ( tcase , " HKCU " ,
2008-02-19 18:18:10 +03:00
test_Open ,
2010-07-31 22:59:02 +04:00
( void * ) dcerpc_winreg_OpenHKCU_r ) ;
2008-02-19 18:18:10 +03:00
2007-08-26 19:16:40 +04:00
return suite ;
2003-11-21 08:28:36 +03:00
}