2005-01-09 12:38:16 +03:00
/*
Unix SMB / CIFS implementation .
test suite for dcerpc alter_context operations
Copyright ( C ) Andrew Tridgell 2005
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
2005-01-09 12:38:16 +03:00
( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
2007-07-10 06:07:03 +04:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2005-01-09 12:38:16 +03:00
*/
# include "includes.h"
# include "librpc/gen_ndr/ndr_lsa.h"
# include "librpc/gen_ndr/ndr_dssetup.h"
2010-04-14 00:06:51 +04:00
# include "torture/rpc/torture_rpc.h"
2005-01-09 12:38:16 +03:00
2007-08-29 04:56:13 +04:00
bool torture_rpc_alter_context ( struct torture_context * torture )
2005-01-09 12:38:16 +03:00
{
2007-09-02 21:27:40 +04:00
NTSTATUS status ;
struct dcerpc_pipe * p , * p2 , * p3 ;
2005-10-25 16:14:08 +04:00
struct policy_handle * handle ;
2007-08-20 00:46:45 +04:00
struct ndr_interface_table tmptbl ;
2024-09-19 00:27:17 +03:00
const struct dcerpc_binding * bd = NULL ;
const struct dcerpc_binding * bd2 = NULL ;
struct ndr_syntax_id syntax = { . if_version = 0 , } ;
struct ndr_syntax_id syntax2 = { . if_version = 0 , } ;
const struct ndr_syntax_id * transfer_syntax = NULL ;
const struct ndr_syntax_id * transfer_syntax2 = NULL ;
uint32_t flags = 0 ;
uint32_t flags2 = 0 ;
2007-09-02 17:30:28 +04:00
bool ret = true ;
2005-01-09 12:38:16 +03:00
2007-08-29 04:56:13 +04:00
torture_comment ( torture , " opening LSA connection \n " ) ;
2007-08-28 16:54:27 +04:00
status = torture_rpc_connection ( torture , & p , & ndr_table_lsarpc ) ;
2007-09-02 17:30:28 +04:00
torture_assert_ntstatus_ok ( torture , status , " connecting " ) ;
2005-01-09 12:38:16 +03:00
2024-09-19 00:27:17 +03:00
bd = dcerpc_binding_handle_get_binding ( p - > binding_handle ) ;
syntax = dcerpc_binding_get_abstract_syntax ( bd ) ;
flags = dcerpc_binding_get_flags ( bd ) ;
if ( flags & DCERPC_NDR64 ) {
transfer_syntax = & ndr_transfer_syntax_ndr64 ;
} else {
transfer_syntax = & ndr_transfer_syntax_ndr ;
}
2010-04-09 11:03:43 +04:00
torture_comment ( torture , " Testing change of primary context \n " ) ;
2024-09-19 00:27:17 +03:00
status = dcerpc_alter_context ( p , torture , & syntax , transfer_syntax ) ;
2010-04-09 11:03:43 +04:00
torture_assert_ntstatus_ok ( torture , status , " dcerpc_alter_context failed " ) ;
2010-03-11 14:00:34 +03:00
if ( ! test_lsa_OpenPolicy2 ( p - > binding_handle , torture , & handle ) ) {
2007-09-02 17:30:28 +04:00
ret = false ;
2005-01-09 12:38:16 +03:00
}
2010-04-09 11:03:43 +04:00
torture_comment ( torture , " Testing change of primary context \n " ) ;
2024-09-19 00:27:17 +03:00
status = dcerpc_alter_context ( p , torture , & syntax , transfer_syntax ) ;
2010-04-09 11:03:43 +04:00
torture_assert_ntstatus_ok ( torture , status , " dcerpc_alter_context failed " ) ;
2007-08-29 04:56:13 +04:00
torture_comment ( torture , " Opening secondary DSSETUP context \n " ) ;
2007-08-20 01:23:03 +04:00
status = dcerpc_secondary_context ( p , & p2 , & ndr_table_dssetup ) ;
2007-09-02 17:30:28 +04:00
torture_assert_ntstatus_ok ( torture , status , " dcerpc_alter_context failed " ) ;
2005-01-09 12:38:16 +03:00
2024-09-19 00:27:17 +03:00
bd2 = dcerpc_binding_handle_get_binding ( p2 - > binding_handle ) ;
syntax2 = dcerpc_binding_get_abstract_syntax ( bd2 ) ;
flags2 = dcerpc_binding_get_flags ( bd2 ) ;
if ( flags2 & DCERPC_NDR64 ) {
transfer_syntax2 = & ndr_transfer_syntax_ndr64 ;
} else {
transfer_syntax2 = & ndr_transfer_syntax_ndr ;
}
2010-04-09 11:03:43 +04:00
torture_comment ( torture , " Testing change of primary context \n " ) ;
2024-09-19 00:27:17 +03:00
status = dcerpc_alter_context ( p2 , torture , & syntax2 , transfer_syntax2 ) ;
2010-04-09 11:03:43 +04:00
torture_assert_ntstatus_ok ( torture , status , " dcerpc_alter_context failed " ) ;
2007-08-20 01:23:03 +04:00
tmptbl = ndr_table_dssetup ;
2006-03-26 04:59:17 +04:00
tmptbl . syntax_id . if_version + = 100 ;
2007-08-29 04:56:13 +04:00
torture_comment ( torture , " Opening bad secondary connection \n " ) ;
2007-09-02 21:27:40 +04:00
status = dcerpc_secondary_context ( p , & p3 , & tmptbl ) ;
2007-09-02 19:02:17 +04:00
torture_assert_ntstatus_equal ( torture , status , NT_STATUS_RPC_UNSUPPORTED_NAME_SYNTAX ,
" dcerpc_alter_context with wrong version should fail " ) ;
2005-01-09 14:32:12 +03:00
2010-04-11 03:39:06 +04:00
torture_comment ( torture , " Testing DSSETUP pipe operations \n " ) ;
2007-09-02 17:30:28 +04:00
ret & = test_DsRoleGetPrimaryDomainInformation ( torture , p2 ) ;
2005-01-09 12:38:16 +03:00
2005-10-25 16:14:08 +04:00
if ( handle ) {
2010-03-11 14:00:34 +03:00
ret & = test_lsa_Close ( p - > binding_handle , torture , handle ) ;
2005-01-09 12:38:16 +03:00
}
2010-04-09 11:03:43 +04:00
torture_comment ( torture , " Testing change of primary context \n " ) ;
2024-09-19 00:27:17 +03:00
status = dcerpc_alter_context ( p , torture , & syntax , transfer_syntax ) ;
2010-04-09 11:03:43 +04:00
torture_assert_ntstatus_ok ( torture , status , " dcerpc_alter_context failed " ) ;
ret & = test_lsa_OpenPolicy2 ( p - > binding_handle , torture , & handle ) ;
if ( handle ) {
ret & = test_lsa_Close ( p - > binding_handle , torture , handle ) ;
}
2007-08-29 04:56:13 +04:00
torture_comment ( torture , " Testing change of primary context \n " ) ;
2024-09-19 00:27:17 +03:00
status = dcerpc_alter_context ( p , torture , & syntax2 , transfer_syntax2 ) ;
2010-04-10 13:04:04 +04:00
if ( NT_STATUS_EQUAL ( status , NT_STATUS_RPC_PROTOCOL_ERROR ) ) {
2010-04-09 11:03:43 +04:00
ret & = test_lsa_OpenPolicy2_ex ( p - > binding_handle , torture , & handle ,
2019-05-15 07:07:16 +03:00
NT_STATUS_CONNECTION_DISCONNECTED ,
NT_STATUS_CONNECTION_RESET ) ;
2014-01-22 14:18:35 +04:00
torture_assert ( torture , ! dcerpc_binding_handle_is_connected ( p - > binding_handle ) ,
2023-08-03 16:45:20 +03:00
" dcerpc disconnected " ) ;
2014-01-22 14:18:35 +04:00
2010-04-09 11:03:43 +04:00
return ret ;
}
2007-09-02 17:30:28 +04:00
torture_assert_ntstatus_ok ( torture , status , " dcerpc_alter_context failed " ) ;
2005-01-10 06:48:19 +03:00
2010-04-11 03:39:06 +04:00
torture_comment ( torture , " Testing DSSETUP pipe operations - should fault \n " ) ;
2010-03-30 00:45:05 +04:00
ret & = test_DsRoleGetPrimaryDomainInformation_ext ( torture , p , NT_STATUS_RPC_BAD_STUB_DATA ) ;
2005-01-10 06:48:19 +03:00
2010-03-11 14:00:34 +03:00
ret & = test_lsa_OpenPolicy2 ( p - > binding_handle , torture , & handle ) ;
2005-01-10 06:48:19 +03:00
2005-10-25 16:14:08 +04:00
if ( handle ) {
2010-03-11 14:00:34 +03:00
ret & = test_lsa_Close ( p - > binding_handle , torture , handle ) ;
2005-01-10 06:48:19 +03:00
}
2010-04-11 03:39:06 +04:00
torture_comment ( torture , " Testing DSSETUP pipe operations \n " ) ;
2007-08-29 04:56:13 +04:00
2007-09-02 17:30:28 +04:00
ret & = test_DsRoleGetPrimaryDomainInformation ( torture , p2 ) ;
2005-01-09 12:38:16 +03:00
return ret ;
}