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"
2006-01-03 16:41:17 +03:00
# include "torture/torture.h"
2005-01-09 12:38:16 +03:00
# include "librpc/gen_ndr/ndr_lsa.h"
# include "librpc/gen_ndr/ndr_dssetup.h"
2006-03-18 18:42:57 +03:00
# include "librpc/rpc/dcerpc.h"
2006-03-14 18:02:05 +03:00
# include "torture/rpc/rpc.h"
2005-01-09 12:38:16 +03:00
2006-03-25 19:01:28 +03:00
BOOL torture_rpc_alter_context ( struct torture_context * torture )
2005-01-09 12:38:16 +03:00
{
NTSTATUS status ;
struct dcerpc_pipe * p , * p2 ;
TALLOC_CTX * mem_ctx ;
BOOL ret = True ;
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 ;
2007-08-18 10:57:49 +04:00
struct ndr_syntax_id syntax ;
struct ndr_syntax_id transfer_syntax ;
2005-01-09 12:38:16 +03:00
mem_ctx = talloc_init ( " torture_rpc_alter_context " ) ;
printf ( " opening LSA connection \n " ) ;
2007-08-28 16:54:27 +04:00
status = torture_rpc_connection ( torture , & p , & ndr_table_lsarpc ) ;
2005-01-09 12:38:16 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2005-03-22 11:00:45 +03:00
talloc_free ( mem_ctx ) ;
2005-01-09 12:38:16 +03:00
return False ;
}
if ( ! test_lsa_OpenPolicy2 ( p , mem_ctx , & handle ) ) {
ret = False ;
}
printf ( " Opening secondary DSSETUP context \n " ) ;
2007-08-20 01:23:03 +04:00
status = dcerpc_secondary_context ( p , & p2 , & ndr_table_dssetup ) ;
2005-01-09 12:38:16 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2005-03-22 11:00:45 +03:00
talloc_free ( mem_ctx ) ;
2005-01-09 12:38:16 +03:00
printf ( " dcerpc_alter_context failed - %s \n " , nt_errstr ( status ) ) ;
return False ;
}
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 ;
2005-01-09 14:32:12 +03:00
printf ( " Opening bad secondary connection \n " ) ;
2005-12-27 17:28:01 +03:00
status = dcerpc_secondary_context ( p , & p2 , & tmptbl ) ;
2005-01-09 14:32:12 +03:00
if ( NT_STATUS_IS_OK ( status ) ) {
2005-03-22 11:00:45 +03:00
talloc_free ( mem_ctx ) ;
2005-01-09 14:32:12 +03:00
printf ( " dcerpc_alter_context with wrong version should fail \n " ) ;
return False ;
}
2005-01-09 12:38:16 +03:00
printf ( " testing DSSETUP pipe operations \n " ) ;
ret & = test_DsRoleGetPrimaryDomainInformation ( p2 , mem_ctx ) ;
2005-10-25 16:14:08 +04:00
if ( handle ) {
if ( ! test_lsa_Close ( p , mem_ctx , handle ) ) {
ret = False ;
}
2005-01-09 12:38:16 +03:00
}
2005-01-10 06:48:19 +03:00
syntax = p - > syntax ;
transfer_syntax = p - > transfer_syntax ;
printf ( " Testing change of primary context \n " ) ;
status = dcerpc_alter_context ( p , mem_ctx , & p2 - > syntax , & p2 - > transfer_syntax ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
2005-03-22 11:00:45 +03:00
talloc_free ( mem_ctx ) ;
2005-01-10 06:48:19 +03:00
printf ( " dcerpc_alter_context failed - %s \n " , nt_errstr ( status ) ) ;
return False ;
}
printf ( " testing DSSETUP pipe operations - should fault \n " ) ;
if ( test_DsRoleGetPrimaryDomainInformation ( p , mem_ctx ) ) {
ret = False ;
}
if ( ! test_lsa_OpenPolicy2 ( p , mem_ctx , & handle ) ) {
ret = False ;
}
2005-10-25 16:14:08 +04:00
if ( handle ) {
if ( ! test_lsa_Close ( p , mem_ctx , handle ) ) {
ret = False ;
}
2005-01-10 06:48:19 +03:00
}
printf ( " testing DSSETUP pipe operations \n " ) ;
ret & = test_DsRoleGetPrimaryDomainInformation ( p2 , mem_ctx ) ;
2005-01-27 10:08:20 +03:00
talloc_free ( mem_ctx ) ;
2005-01-09 12:38:16 +03:00
return ret ;
}