2007-02-28 02:35:38 +03:00
/*
Unix SMB / CIFS implementation .
test suite for behaviour of rpc policy handles
Copyright ( C ) Andrew Tridgell 2007
This program is free software ; you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
2007-07-10 06:07:03 +04:00
the Free Software Foundation ; either version 3 of the License , or
2007-02-28 02:35:38 +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/>.
2007-02-28 02:35:38 +03:00
*/
# include "includes.h"
# include "librpc/gen_ndr/ndr_samr_c.h"
# include "librpc/gen_ndr/ndr_lsa_c.h"
# include "librpc/gen_ndr/ndr_drsuapi_c.h"
2010-04-14 00:06:51 +04:00
# include "torture/rpc/torture_rpc.h"
2007-02-28 02:35:38 +03:00
/*
this tests the use of policy handles between connections
*/
static bool test_handles_lsa ( struct torture_context * torture )
{
NTSTATUS status ;
struct dcerpc_pipe * p1 , * p2 ;
2010-03-18 11:56:32 +03:00
struct dcerpc_binding_handle * b1 , * b2 ;
2007-02-28 02:35:38 +03:00
struct policy_handle handle ;
struct policy_handle handle2 ;
struct lsa_ObjectAttribute attr ;
struct lsa_QosInfo qos ;
struct lsa_OpenPolicy r ;
struct lsa_Close c ;
uint16_t system_name = ' \\ ' ;
TALLOC_CTX * mem_ctx = talloc_new ( torture ) ;
2007-02-28 18:57:52 +03:00
torture_comment ( torture , " RPC-HANDLE-LSARPC \n " ) ;
2007-08-28 16:54:27 +04:00
status = torture_rpc_connection ( torture , & p1 , & ndr_table_lsarpc ) ;
2007-02-28 02:35:38 +03:00
torture_assert_ntstatus_ok ( torture , status , " opening lsa pipe1 " ) ;
2010-03-18 11:56:32 +03:00
b1 = p1 - > binding_handle ;
2007-02-28 02:35:38 +03:00
2007-08-28 16:54:27 +04:00
status = torture_rpc_connection ( torture , & p2 , & ndr_table_lsarpc ) ;
2007-02-28 02:35:38 +03:00
torture_assert_ntstatus_ok ( torture , status , " opening lsa pipe1 " ) ;
2010-03-18 11:56:32 +03:00
b2 = p2 - > binding_handle ;
2007-02-28 02:35:38 +03:00
qos . len = 0 ;
qos . impersonation_level = 2 ;
qos . context_mode = 1 ;
qos . effective_only = 0 ;
attr . len = 0 ;
attr . root_dir = NULL ;
attr . object_name = NULL ;
attr . attributes = 0 ;
attr . sec_desc = NULL ;
attr . sec_qos = & qos ;
r . in . system_name = & system_name ;
r . in . attr = & attr ;
r . in . access_mask = SEC_FLAG_MAXIMUM_ALLOWED ;
r . out . handle = & handle ;
2010-03-19 17:35:36 +03:00
torture_assert_ntstatus_ok ( torture , dcerpc_lsa_OpenPolicy_r ( b1 , mem_ctx , & r ) ,
" OpenPolicy failed " ) ;
if ( ! NT_STATUS_IS_OK ( r . out . result ) ) {
2007-02-28 02:35:38 +03:00
torture_comment ( torture , " lsa_OpenPolicy not supported - skipping \n " ) ;
talloc_free ( mem_ctx ) ;
return true ;
}
c . in . handle = & handle ;
c . out . handle = & handle2 ;
2010-03-18 11:56:32 +03:00
status = dcerpc_lsa_Close_r ( b2 , mem_ctx , & c ) ;
2010-03-30 00:36:22 +04:00
torture_assert_ntstatus_equal ( torture , status , NT_STATUS_RPC_SS_CONTEXT_MISMATCH ,
2007-02-28 02:35:38 +03:00
" closing policy handle on p2 " ) ;
2010-03-19 17:35:36 +03:00
torture_assert_ntstatus_ok ( torture , dcerpc_lsa_Close_r ( b1 , mem_ctx , & c ) ,
" Close failed " ) ;
torture_assert_ntstatus_ok ( torture , c . out . result , " closing policy handle on p1 " ) ;
2007-02-28 02:35:38 +03:00
2010-03-18 11:56:32 +03:00
status = dcerpc_lsa_Close_r ( b1 , mem_ctx , & c ) ;
2010-03-30 00:36:22 +04:00
torture_assert_ntstatus_equal ( torture , status , NT_STATUS_RPC_SS_CONTEXT_MISMATCH ,
2007-02-28 02:35:38 +03:00
" closing policy handle on p1 again " ) ;
2010-03-30 00:36:22 +04:00
2007-02-28 02:35:38 +03:00
talloc_free ( mem_ctx ) ;
return true ;
}
2007-02-28 18:57:52 +03:00
static bool test_handles_lsa_shared ( struct torture_context * torture )
{
NTSTATUS status ;
struct dcerpc_pipe * p1 , * p2 , * p3 , * p4 , * p5 ;
2010-03-18 11:56:32 +03:00
struct dcerpc_binding_handle * b1 , * b2 , * b3 , * b4 ;
2024-09-18 00:04:23 +03:00
const struct dcerpc_binding * bd1 = NULL , * bd2 = NULL ;
2007-02-28 18:57:52 +03:00
struct policy_handle handle ;
struct policy_handle handle2 ;
struct lsa_ObjectAttribute attr ;
struct lsa_QosInfo qos ;
struct lsa_OpenPolicy r ;
struct lsa_Close c ;
struct lsa_QuerySecurity qsec ;
2008-10-21 00:39:06 +04:00
struct sec_desc_buf * sdbuf = NULL ;
2007-02-28 18:57:52 +03:00
uint16_t system_name = ' \\ ' ;
TALLOC_CTX * mem_ctx = talloc_new ( torture ) ;
enum dcerpc_transport_t transport ;
uint32_t assoc_group_id ;
torture_comment ( torture , " RPC-HANDLE-LSARPC-SHARED \n " ) ;
torture_comment ( torture , " connect lsa pipe1 \n " ) ;
2007-08-28 16:54:27 +04:00
status = torture_rpc_connection ( torture , & p1 , & ndr_table_lsarpc ) ;
2007-02-28 18:57:52 +03:00
torture_assert_ntstatus_ok ( torture , status , " opening lsa pipe1 " ) ;
2010-03-18 11:56:32 +03:00
b1 = p1 - > binding_handle ;
2024-09-18 00:04:23 +03:00
bd1 = dcerpc_binding_handle_get_binding ( b1 ) ;
2007-02-28 18:57:52 +03:00
2024-09-18 00:04:23 +03:00
transport = dcerpc_binding_get_transport ( bd1 ) ;
assoc_group_id = dcerpc_binding_get_assoc_group_id ( bd1 ) ;
2007-02-28 18:57:52 +03:00
torture_comment ( torture , " use assoc_group_id[0x%08X] for new connections \n " , assoc_group_id ) ;
torture_comment ( torture , " connect lsa pipe2 \n " ) ;
2007-08-28 16:54:27 +04:00
status = torture_rpc_connection_transport ( torture , & p2 , & ndr_table_lsarpc ,
2007-02-28 18:57:52 +03:00
transport ,
2016-09-15 09:36:32 +03:00
assoc_group_id ,
0 ) ;
2007-02-28 18:57:52 +03:00
torture_assert_ntstatus_ok ( torture , status , " opening lsa pipe2 " ) ;
2010-03-18 11:56:32 +03:00
b2 = p2 - > binding_handle ;
2024-09-18 00:04:23 +03:00
bd2 = dcerpc_binding_handle_get_binding ( b2 ) ;
2007-02-28 18:57:52 +03:00
2009-09-22 11:18:25 +04:00
torture_comment ( torture , " got assoc_group_id[0x%08X] for p2 \n " ,
2024-09-18 00:04:23 +03:00
dcerpc_binding_get_assoc_group_id ( bd2 ) ) ;
2009-09-22 11:18:25 +04:00
2007-02-28 18:57:52 +03:00
qos . len = 0 ;
qos . impersonation_level = 2 ;
qos . context_mode = 1 ;
qos . effective_only = 0 ;
attr . len = 0 ;
attr . root_dir = NULL ;
attr . object_name = NULL ;
attr . attributes = 0 ;
attr . sec_desc = NULL ;
attr . sec_qos = & qos ;
r . in . system_name = & system_name ;
r . in . attr = & attr ;
r . in . access_mask = SEC_FLAG_MAXIMUM_ALLOWED ;
r . out . handle = & handle ;
torture_comment ( torture , " open lsa policy handle \n " ) ;
2010-03-19 17:35:36 +03:00
torture_assert_ntstatus_ok ( torture , dcerpc_lsa_OpenPolicy_r ( b1 , mem_ctx , & r ) ,
" OpenPolicy failed " ) ;
if ( ! NT_STATUS_IS_OK ( r . out . result ) ) {
2007-02-28 18:57:52 +03:00
torture_comment ( torture , " lsa_OpenPolicy not supported - skipping \n " ) ;
talloc_free ( mem_ctx ) ;
return true ;
}
/*
* connect p3 after the policy handle is opened
*/
torture_comment ( torture , " connect lsa pipe3 after the policy handle is opened \n " ) ;
2007-08-28 16:54:27 +04:00
status = torture_rpc_connection_transport ( torture , & p3 , & ndr_table_lsarpc ,
2007-02-28 18:57:52 +03:00
transport ,
2016-09-15 09:36:32 +03:00
assoc_group_id ,
0 ) ;
2007-02-28 18:57:52 +03:00
torture_assert_ntstatus_ok ( torture , status , " opening lsa pipe3 " ) ;
2010-03-18 11:56:32 +03:00
b3 = p3 - > binding_handle ;
2007-02-28 18:57:52 +03:00
qsec . in . handle = & handle ;
qsec . in . sec_info = 0 ;
2008-10-21 00:39:06 +04:00
qsec . out . sdbuf = & sdbuf ;
2007-02-28 18:57:52 +03:00
c . in . handle = & handle ;
c . out . handle = & handle2 ;
/*
* use policy handle on all 3 connections
*/
torture_comment ( torture , " use the policy handle on p1,p2,p3 \n " ) ;
2010-03-19 17:35:36 +03:00
torture_assert_ntstatus_ok ( torture , dcerpc_lsa_QuerySecurity_r ( b1 , mem_ctx , & qsec ) ,
" QuerySecurity failed " ) ;
torture_assert_ntstatus_equal ( torture , qsec . out . result , NT_STATUS_OK ,
2007-02-28 18:57:52 +03:00
" use policy handle on p1 " ) ;
2010-03-19 17:35:36 +03:00
torture_assert_ntstatus_ok ( torture , dcerpc_lsa_QuerySecurity_r ( b2 , mem_ctx , & qsec ) ,
" QuerySecurity failed " ) ;
torture_assert_ntstatus_equal ( torture , qsec . out . result , NT_STATUS_OK ,
2007-02-28 18:57:52 +03:00
" use policy handle on p2 " ) ;
2010-03-19 17:35:36 +03:00
torture_assert_ntstatus_ok ( torture , dcerpc_lsa_QuerySecurity_r ( b3 , mem_ctx , & qsec ) ,
" QuerySecurity failed " ) ;
torture_assert_ntstatus_equal ( torture , qsec . out . result , NT_STATUS_OK ,
2007-02-28 18:57:52 +03:00
" use policy handle on p3 " ) ;
/*
* close policy handle on connection 2 and the others get a fault
*/
torture_comment ( torture , " close the policy handle on p2 others get a fault \n " ) ;
2010-03-19 17:35:36 +03:00
torture_assert_ntstatus_ok ( torture , dcerpc_lsa_Close_r ( b2 , mem_ctx , & c ) ,
" Close failed " ) ;
torture_assert_ntstatus_equal ( torture , c . out . result , NT_STATUS_OK ,
2007-02-28 18:57:52 +03:00
" closing policy handle on p2 " ) ;
2010-03-18 11:56:32 +03:00
status = dcerpc_lsa_Close_r ( b1 , mem_ctx , & c ) ;
2010-03-19 17:35:36 +03:00
2010-03-30 00:36:22 +04:00
torture_assert_ntstatus_equal ( torture , status , NT_STATUS_RPC_SS_CONTEXT_MISMATCH ,
2007-02-28 18:57:52 +03:00
" closing policy handle on p1 again " ) ;
2010-03-18 11:56:32 +03:00
status = dcerpc_lsa_Close_r ( b3 , mem_ctx , & c ) ;
2010-03-30 00:36:22 +04:00
torture_assert_ntstatus_equal ( torture , status , NT_STATUS_RPC_SS_CONTEXT_MISMATCH ,
2007-02-28 18:57:52 +03:00
" closing policy handle on p3 " ) ;
2010-03-18 11:56:32 +03:00
status = dcerpc_lsa_Close_r ( b2 , mem_ctx , & c ) ;
2010-03-30 00:36:22 +04:00
torture_assert_ntstatus_equal ( torture , status , NT_STATUS_RPC_SS_CONTEXT_MISMATCH ,
2007-02-28 18:57:52 +03:00
" closing policy handle on p2 again " ) ;
/*
* open a new policy handle on p3
*/
torture_comment ( torture , " open a new policy handle on p3 \n " ) ;
2010-03-19 17:35:36 +03:00
torture_assert_ntstatus_ok ( torture , dcerpc_lsa_OpenPolicy_r ( b3 , mem_ctx , & r ) ,
" OpenPolicy failed " ) ;
torture_assert_ntstatus_equal ( torture , r . out . result , NT_STATUS_OK ,
2007-02-28 18:57:52 +03:00
" open policy handle on p3 " ) ;
/*
* use policy handle on all 3 connections
*/
torture_comment ( torture , " use the policy handle on p1,p2,p3 \n " ) ;
2010-03-19 17:35:36 +03:00
torture_assert_ntstatus_ok ( torture , dcerpc_lsa_QuerySecurity_r ( b1 , mem_ctx , & qsec ) ,
" Query Security failed " ) ;
2007-02-28 18:57:52 +03:00
torture_assert_ntstatus_equal ( torture , status , NT_STATUS_OK ,
" use policy handle on p1 " ) ;
2010-03-19 17:35:36 +03:00
torture_assert_ntstatus_ok ( torture , dcerpc_lsa_QuerySecurity_r ( b2 , mem_ctx , & qsec ) ,
" Query Security failed " ) ;
2007-02-28 18:57:52 +03:00
torture_assert_ntstatus_equal ( torture , status , NT_STATUS_OK ,
" use policy handle on p2 " ) ;
2010-03-19 17:35:36 +03:00
torture_assert_ntstatus_ok ( torture , dcerpc_lsa_QuerySecurity_r ( b3 , mem_ctx , & qsec ) ,
" Query Security failed " ) ;
2007-02-28 18:57:52 +03:00
torture_assert_ntstatus_equal ( torture , status , NT_STATUS_OK ,
" use policy handle on p3 " ) ;
/*
* close policy handle on connection 2 and the others get a fault
*/
torture_comment ( torture , " close the policy handle on p2 others get a fault \n " ) ;
2010-03-19 17:35:36 +03:00
torture_assert_ntstatus_ok ( torture , dcerpc_lsa_Close_r ( b2 , mem_ctx , & c ) ,
" Close failed " ) ;
torture_assert_ntstatus_equal ( torture , c . out . result , NT_STATUS_OK ,
2007-02-28 18:57:52 +03:00
" closing policy handle on p2 " ) ;
2010-03-18 11:56:32 +03:00
status = dcerpc_lsa_Close_r ( b1 , mem_ctx , & c ) ;
2010-03-30 00:36:22 +04:00
torture_assert_ntstatus_equal ( torture , status , NT_STATUS_RPC_SS_CONTEXT_MISMATCH ,
2007-02-28 18:57:52 +03:00
" closing policy handle on p1 again " ) ;
2010-03-18 11:56:32 +03:00
status = dcerpc_lsa_Close_r ( b3 , mem_ctx , & c ) ;
2010-03-30 00:36:22 +04:00
torture_assert_ntstatus_equal ( torture , status , NT_STATUS_RPC_SS_CONTEXT_MISMATCH ,
2007-02-28 18:57:52 +03:00
" closing policy handle on p3 " ) ;
2010-03-18 11:56:32 +03:00
status = dcerpc_lsa_Close_r ( b2 , mem_ctx , & c ) ;
2010-03-30 00:36:22 +04:00
torture_assert_ntstatus_equal ( torture , status , NT_STATUS_RPC_SS_CONTEXT_MISMATCH ,
2007-02-28 18:57:52 +03:00
" closing policy handle on p2 again " ) ;
/*
* open a new policy handle
*/
torture_comment ( torture , " open a new policy handle on p1 and use it \n " ) ;
2010-03-19 17:35:36 +03:00
torture_assert_ntstatus_ok ( torture , dcerpc_lsa_OpenPolicy_r ( b1 , mem_ctx , & r ) ,
" OpenPolicy failed " ) ;
torture_assert_ntstatus_equal ( torture , r . out . result , NT_STATUS_OK ,
2007-02-28 18:57:52 +03:00
" open 2nd policy handle on p1 " ) ;
2010-03-19 17:35:36 +03:00
torture_assert_ntstatus_ok ( torture , dcerpc_lsa_QuerySecurity_r ( b1 , mem_ctx , & qsec ) ,
" QuerySecurity failed " ) ;
torture_assert_ntstatus_equal ( torture , qsec . out . result , NT_STATUS_OK ,
2007-02-28 18:57:52 +03:00
" QuerySecurity handle on p1 " ) ;
/* close first connection */
torture_comment ( torture , " disconnect p1 \n " ) ;
talloc_free ( p1 ) ;
2010-09-16 23:36:37 +04:00
smb_msleep ( 5 ) ;
2007-02-28 18:57:52 +03:00
/*
* and it ' s still available on p2 , p3
*/
torture_comment ( torture , " use policy handle on p2,p3 \n " ) ;
2010-03-19 17:35:36 +03:00
torture_assert_ntstatus_ok ( torture , dcerpc_lsa_QuerySecurity_r ( b2 , mem_ctx , & qsec ) ,
" QuerySecurity failed " ) ;
torture_assert_ntstatus_equal ( torture , qsec . out . result , NT_STATUS_OK ,
2007-02-28 18:57:52 +03:00
" QuerySecurity handle on p2 after p1 was disconnected " ) ;
2010-03-19 17:35:36 +03:00
torture_assert_ntstatus_ok ( torture , dcerpc_lsa_QuerySecurity_r ( b3 , mem_ctx , & qsec ) ,
" QuerySecurity failed " ) ;
torture_assert_ntstatus_equal ( torture , qsec . out . result , NT_STATUS_OK ,
2007-02-28 18:57:52 +03:00
" QuerySecurity handle on p3 after p1 was disconnected " ) ;
/*
* now open p4
* and use the handle on it
*/
torture_comment ( torture , " connect lsa pipe4 and use policy handle \n " ) ;
2007-08-28 16:54:27 +04:00
status = torture_rpc_connection_transport ( torture , & p4 , & ndr_table_lsarpc ,
2007-02-28 18:57:52 +03:00
transport ,
2016-09-15 09:36:32 +03:00
assoc_group_id ,
0 ) ;
2007-02-28 18:57:52 +03:00
torture_assert_ntstatus_ok ( torture , status , " opening lsa pipe4 " ) ;
2010-03-18 11:56:32 +03:00
b4 = p4 - > binding_handle ;
2007-02-28 18:57:52 +03:00
2010-03-19 17:35:36 +03:00
torture_assert_ntstatus_ok ( torture , dcerpc_lsa_QuerySecurity_r ( b4 , mem_ctx , & qsec ) ,
" QuerySecurity failed " ) ;
torture_assert_ntstatus_equal ( torture , qsec . out . result , NT_STATUS_OK ,
2007-02-28 18:57:52 +03:00
" using policy handle on p4 " ) ;
/*
* now close p2 , p3 , p4
* without closing the policy handle
*/
torture_comment ( torture , " disconnect p2,p3,p4 \n " ) ;
talloc_free ( p2 ) ;
talloc_free ( p3 ) ;
talloc_free ( p4 ) ;
2010-09-16 23:36:37 +04:00
smb_msleep ( 10 ) ;
2007-02-28 18:57:52 +03:00
/*
* now open p5
*/
torture_comment ( torture , " connect lsa pipe5 - should fail \n " ) ;
2007-08-28 16:54:27 +04:00
status = torture_rpc_connection_transport ( torture , & p5 , & ndr_table_lsarpc ,
2007-02-28 18:57:52 +03:00
transport ,
2016-09-15 09:36:32 +03:00
assoc_group_id ,
0 ) ;
2007-02-28 18:57:52 +03:00
torture_assert_ntstatus_equal ( torture , status , NT_STATUS_UNSUCCESSFUL ,
" opening lsa pipe5 " ) ;
talloc_free ( mem_ctx ) ;
return true ;
}
2007-02-28 02:35:38 +03:00
static bool test_handles_samr ( struct torture_context * torture )
{
NTSTATUS status ;
struct dcerpc_pipe * p1 , * p2 ;
2010-03-18 11:56:32 +03:00
struct dcerpc_binding_handle * b1 , * b2 ;
2007-02-28 02:35:38 +03:00
struct policy_handle handle ;
struct policy_handle handle2 ;
struct samr_Connect r ;
struct samr_Close c ;
TALLOC_CTX * mem_ctx = talloc_new ( torture ) ;
2007-02-28 18:57:52 +03:00
torture_comment ( torture , " RPC-HANDLE-SAMR \n " ) ;
2007-08-28 16:54:27 +04:00
status = torture_rpc_connection ( torture , & p1 , & ndr_table_samr ) ;
2007-02-28 02:35:38 +03:00
torture_assert_ntstatus_ok ( torture , status , " opening samr pipe1 " ) ;
2010-03-18 11:56:32 +03:00
b1 = p1 - > binding_handle ;
2007-02-28 02:35:38 +03:00
2007-08-28 16:54:27 +04:00
status = torture_rpc_connection ( torture , & p2 , & ndr_table_samr ) ;
2010-05-22 20:40:13 +04:00
torture_assert_ntstatus_ok ( torture , status , " opening samr pipe2 " ) ;
2010-03-18 11:56:32 +03:00
b2 = p2 - > binding_handle ;
2007-02-28 02:35:38 +03:00
r . in . system_name = 0 ;
r . in . access_mask = SEC_FLAG_MAXIMUM_ALLOWED ;
r . out . connect_handle = & handle ;
2010-03-19 17:35:36 +03:00
torture_assert_ntstatus_ok ( torture , dcerpc_samr_Connect_r ( b1 , mem_ctx , & r ) ,
" Connect failed " ) ;
torture_assert_ntstatus_ok ( torture , r . out . result , " opening policy handle on p1 " ) ;
2007-02-28 02:35:38 +03:00
c . in . handle = & handle ;
c . out . handle = & handle2 ;
2010-03-18 11:56:32 +03:00
status = dcerpc_samr_Close_r ( b2 , mem_ctx , & c ) ;
2010-03-30 00:36:22 +04:00
torture_assert_ntstatus_equal ( torture , status , NT_STATUS_RPC_SS_CONTEXT_MISMATCH ,
2007-02-28 02:35:38 +03:00
" closing policy handle on p2 " ) ;
2010-03-19 17:35:36 +03:00
torture_assert_ntstatus_ok ( torture , dcerpc_samr_Close_r ( b1 , mem_ctx , & c ) ,
" Close failed " ) ;
torture_assert_ntstatus_ok ( torture , c . out . result , " closing policy handle on p1 " ) ;
2007-02-28 02:35:38 +03:00
2010-03-18 11:56:32 +03:00
status = dcerpc_samr_Close_r ( b1 , mem_ctx , & c ) ;
2010-03-30 00:36:22 +04:00
torture_assert_ntstatus_equal ( torture , status , NT_STATUS_RPC_SS_CONTEXT_MISMATCH ,
2007-02-28 02:35:38 +03:00
" closing policy handle on p1 again " ) ;
talloc_free ( mem_ctx ) ;
return true ;
}
2007-02-28 20:06:01 +03:00
static bool test_handles_mixed_shared ( struct torture_context * torture )
{
NTSTATUS status ;
struct dcerpc_pipe * p1 , * p2 , * p3 , * p4 , * p5 , * p6 ;
2010-03-18 11:56:32 +03:00
struct dcerpc_binding_handle * b1 , * b2 ;
2024-09-18 00:04:23 +03:00
const struct dcerpc_binding * bd1 = NULL , * bd2 = NULL ;
2007-02-28 20:06:01 +03:00
struct policy_handle handle ;
struct policy_handle handle2 ;
struct samr_Connect r ;
struct lsa_Close lc ;
struct samr_Close sc ;
TALLOC_CTX * mem_ctx = talloc_new ( torture ) ;
enum dcerpc_transport_t transport ;
uint32_t assoc_group_id ;
torture_comment ( torture , " RPC-HANDLE-MIXED-SHARED \n " ) ;
torture_comment ( torture , " connect samr pipe1 \n " ) ;
2007-08-28 16:54:27 +04:00
status = torture_rpc_connection ( torture , & p1 , & ndr_table_samr ) ;
2007-02-28 20:06:01 +03:00
torture_assert_ntstatus_ok ( torture , status , " opening samr pipe1 " ) ;
2010-03-18 11:56:32 +03:00
b1 = p1 - > binding_handle ;
2024-09-18 00:04:23 +03:00
bd1 = dcerpc_binding_handle_get_binding ( b1 ) ;
2007-02-28 20:06:01 +03:00
2024-09-18 00:04:23 +03:00
transport = dcerpc_binding_get_transport ( bd1 ) ;
assoc_group_id = dcerpc_binding_get_assoc_group_id ( bd1 ) ;
2007-02-28 20:06:01 +03:00
torture_comment ( torture , " use assoc_group_id[0x%08X] for new connections \n " , assoc_group_id ) ;
torture_comment ( torture , " connect lsa pipe2 \n " ) ;
2007-08-28 16:54:27 +04:00
status = torture_rpc_connection_transport ( torture , & p2 , & ndr_table_lsarpc ,
2007-02-28 20:06:01 +03:00
transport ,
2016-09-15 09:36:32 +03:00
assoc_group_id ,
0 ) ;
2007-02-28 20:06:01 +03:00
torture_assert_ntstatus_ok ( torture , status , " opening lsa pipe2 " ) ;
2010-03-18 11:56:32 +03:00
b2 = p2 - > binding_handle ;
2024-09-18 00:04:23 +03:00
bd2 = dcerpc_binding_handle_get_binding ( b2 ) ;
2007-02-28 20:06:01 +03:00
2009-09-22 11:18:25 +04:00
torture_comment ( torture , " got assoc_group_id[0x%08X] for p2 \n " ,
2024-09-18 00:04:23 +03:00
dcerpc_binding_get_assoc_group_id ( bd2 ) ) ;
2007-02-28 20:06:01 +03:00
r . in . system_name = 0 ;
r . in . access_mask = SEC_FLAG_MAXIMUM_ALLOWED ;
r . out . connect_handle = & handle ;
torture_comment ( torture , " samr_Connect to open a policy handle on samr p1 \n " ) ;
2010-03-19 17:35:36 +03:00
torture_assert_ntstatus_ok ( torture , dcerpc_samr_Connect_r ( b1 , mem_ctx , & r ) ,
" Connect failed " ) ;
torture_assert_ntstatus_ok ( torture , r . out . result , " opening policy handle on p1 " ) ;
2007-02-28 20:06:01 +03:00
lc . in . handle = & handle ;
lc . out . handle = & handle2 ;
sc . in . handle = & handle ;
sc . out . handle = & handle2 ;
torture_comment ( torture , " use policy handle on lsa p2 - should fail \n " ) ;
2010-03-18 11:56:32 +03:00
status = dcerpc_lsa_Close_r ( b2 , mem_ctx , & lc ) ;
2010-03-30 00:36:22 +04:00
torture_assert_ntstatus_equal ( torture , status , NT_STATUS_RPC_SS_CONTEXT_MISMATCH ,
2007-02-28 20:06:01 +03:00
" closing handle on lsa p2 " ) ;
torture_comment ( torture , " closing policy handle on samr p1 \n " ) ;
2010-03-19 17:35:36 +03:00
torture_assert_ntstatus_ok ( torture , dcerpc_samr_Close_r ( b1 , mem_ctx , & sc ) ,
" Close failed " ) ;
torture_assert_ntstatus_ok ( torture , sc . out . result , " closing policy handle on p1 " ) ;
2007-02-28 20:06:01 +03:00
talloc_free ( p1 ) ;
talloc_free ( p2 ) ;
2010-09-16 23:36:37 +04:00
smb_msleep ( 10 ) ;
2007-02-28 20:06:01 +03:00
torture_comment ( torture , " connect samr pipe3 - should fail \n " ) ;
2007-08-28 16:54:27 +04:00
status = torture_rpc_connection_transport ( torture , & p3 , & ndr_table_samr ,
2007-02-28 20:06:01 +03:00
transport ,
2016-09-15 09:36:32 +03:00
assoc_group_id ,
0 ) ;
2007-02-28 20:06:01 +03:00
torture_assert_ntstatus_equal ( torture , status , NT_STATUS_UNSUCCESSFUL ,
" opening samr pipe3 " ) ;
torture_comment ( torture , " connect lsa pipe4 - should fail \n " ) ;
2007-08-28 16:54:27 +04:00
status = torture_rpc_connection_transport ( torture , & p4 , & ndr_table_lsarpc ,
2007-02-28 20:06:01 +03:00
transport ,
2016-09-15 09:36:32 +03:00
assoc_group_id ,
0 ) ;
2007-02-28 20:06:01 +03:00
torture_assert_ntstatus_equal ( torture , status , NT_STATUS_UNSUCCESSFUL ,
" opening lsa pipe4 " ) ;
2012-11-24 14:28:57 +04:00
/*
* We use ~ assoc_group_id instead of p1 - > assoc_group_id , because
* this way we are less likely to use an id which is already in use .
*/
assoc_group_id = ~ assoc_group_id ;
2007-02-28 20:06:01 +03:00
torture_comment ( torture , " connect samr pipe5 with assoc_group_id[0x%08X]- should fail \n " , + + assoc_group_id ) ;
2007-08-28 16:54:27 +04:00
status = torture_rpc_connection_transport ( torture , & p5 , & ndr_table_samr ,
2007-02-28 20:06:01 +03:00
transport ,
2016-09-15 09:36:32 +03:00
assoc_group_id ,
0 ) ;
2007-02-28 20:06:01 +03:00
torture_assert_ntstatus_equal ( torture , status , NT_STATUS_UNSUCCESSFUL ,
" opening samr pipe5 " ) ;
torture_comment ( torture , " connect lsa pipe6 with assoc_group_id[0x%08X]- should fail \n " , + + assoc_group_id ) ;
2007-08-28 16:54:27 +04:00
status = torture_rpc_connection_transport ( torture , & p6 , & ndr_table_lsarpc ,
2007-02-28 20:06:01 +03:00
transport ,
2016-09-15 09:36:32 +03:00
assoc_group_id ,
0 ) ;
2007-02-28 20:06:01 +03:00
torture_assert_ntstatus_equal ( torture , status , NT_STATUS_UNSUCCESSFUL ,
" opening lsa pipe6 " ) ;
talloc_free ( mem_ctx ) ;
return true ;
}
static bool test_handles_random_assoc ( struct torture_context * torture )
{
NTSTATUS status ;
struct dcerpc_pipe * p1 , * p2 , * p3 ;
TALLOC_CTX * mem_ctx = talloc_new ( torture ) ;
2024-09-18 00:04:23 +03:00
const struct dcerpc_binding * bd1 = NULL ;
2007-02-28 20:06:01 +03:00
enum dcerpc_transport_t transport ;
uint32_t assoc_group_id ;
torture_comment ( torture , " RPC-HANDLE-RANDOM-ASSOC \n " ) ;
torture_comment ( torture , " connect samr pipe1 \n " ) ;
2007-08-28 16:54:27 +04:00
status = torture_rpc_connection ( torture , & p1 , & ndr_table_samr ) ;
2007-02-28 20:06:01 +03:00
torture_assert_ntstatus_ok ( torture , status , " opening samr pipe1 " ) ;
2024-09-18 00:04:23 +03:00
bd1 = dcerpc_binding_handle_get_binding ( p1 - > binding_handle ) ;
assoc_group_id = dcerpc_binding_get_assoc_group_id ( bd1 ) ;
2012-11-20 17:13:16 +04:00
torture_comment ( torture , " pipe1 uses assoc_group_id[0x%08X] \n " ,
2024-09-18 00:04:23 +03:00
assoc_group_id ) ;
transport = dcerpc_binding_get_transport ( bd1 ) ;
2012-11-20 17:13:16 +04:00
2012-11-14 11:45:10 +04:00
/*
* We use ~ p1 - > assoc_group_id instead of p1 - > assoc_group_id , because
* this way we are less likely to use an id which is already in use .
2019-08-16 13:50:21 +03:00
*
* And make sure it doesn ' t wrap .
2012-11-14 11:45:10 +04:00
*/
s4:torture: make rpc.handles.random-assoc test even more robust
This improves commit bebee47e6386476e9948089484f89d213fcc2660 a bit
further.
I just got this:
connect samr pipe1
use assoc_group_id[0x00000001] for new connections
connect lsa pipe2
got assoc_group_id[0x00000001] for p2
samr_Connect to open a policy handle on samr p1
use policy handle on lsa p2 - should fail
closing policy handle on samr p1
connect samr pipe3 - should fail
Failed to bind to uuid 12345778-1234-abcd-ef00-0123456789ac for ncacn_np:localdc[\pipe\samr,validate,assoc_group_id=0x00000001,abstract_syntax=12345778-1234-abcd-ef00-0123456789ac/0x00000001] NT_STATUS_UNSUCCESSFUL
connect lsa pipe4 - should fail
Failed to bind to uuid 12345778-1234-abcd-ef00-0123456789ab for ncacn_np:localdc[\pipe\lsarpc,validate,assoc_group_id=0x00000001,abstract_syntax=12345778-1234-abcd-ef00-0123456789ab/0x00000000] NT_STATUS_UNSUCCESSFUL
connect samr pipe5 with assoc_group_id[0xFFFFFFFF]- should fail
Failed to bind to uuid 12345778-1234-abcd-ef00-0123456789ac for ncacn_np:localdc[\pipe\samr,validate,assoc_group_id=0xffffffff,abstract_syntax=12345778-1234-abcd-ef00-0123456789ac/0x00000001] NT_STATUS_UNSUCCESSFUL
connect lsa pipe6 with assoc_group_id[0x00000000]- should fail
UNEXPECTED(failure): samba4.rpc.handles on ncacn_np with validate.mixed-shared(ad_dc_ntvfs)
REASON: Exception: Exception: ../../source4/torture/rpc/handles.c:500: status was NT_STATUS_OK, expected NT_STATUS_UNSUCCESSFUL: opening lsa pipe6
FAILED (1 failures, 0 errors and 0 unexpected successes in 0 testsuites)
A summary with detailed information can be found in:
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
2020-01-27 18:45:44 +03:00
assoc_group_id = ~ MIN ( assoc_group_id , UINT32_MAX - 3 ) ;
2007-02-28 20:06:01 +03:00
torture_comment ( torture , " connect samr pipe2 with assoc_group_id[0x%08X]- should fail \n " , + + assoc_group_id ) ;
2007-08-28 16:54:27 +04:00
status = torture_rpc_connection_transport ( torture , & p2 , & ndr_table_samr ,
2007-02-28 20:06:01 +03:00
transport ,
2016-09-15 09:36:32 +03:00
assoc_group_id ,
0 ) ;
2007-02-28 20:06:01 +03:00
torture_assert_ntstatus_equal ( torture , status , NT_STATUS_UNSUCCESSFUL ,
" opening samr pipe2 " ) ;
torture_comment ( torture , " connect samr pipe3 with assoc_group_id[0x%08X]- should fail \n " , + + assoc_group_id ) ;
2007-08-28 16:54:27 +04:00
status = torture_rpc_connection_transport ( torture , & p3 , & ndr_table_samr ,
2007-02-28 20:06:01 +03:00
transport ,
2016-09-15 09:36:32 +03:00
assoc_group_id ,
0 ) ;
2007-02-28 20:06:01 +03:00
torture_assert_ntstatus_equal ( torture , status , NT_STATUS_UNSUCCESSFUL ,
" opening samr pipe3 " ) ;
talloc_free ( mem_ctx ) ;
return true ;
}
2007-02-28 02:35:38 +03:00
static bool test_handles_drsuapi ( struct torture_context * torture )
{
NTSTATUS status ;
struct dcerpc_pipe * p1 , * p2 ;
2010-03-18 11:56:32 +03:00
struct dcerpc_binding_handle * b1 , * b2 ;
2007-02-28 02:35:38 +03:00
struct policy_handle handle ;
struct policy_handle handle2 ;
struct GUID bind_guid ;
struct drsuapi_DsBind r ;
struct drsuapi_DsUnbind c ;
TALLOC_CTX * mem_ctx = talloc_new ( torture ) ;
2007-02-28 18:57:52 +03:00
torture_comment ( torture , " RPC-HANDLE-DRSUAPI \n " ) ;
2007-08-28 16:54:27 +04:00
status = torture_rpc_connection ( torture , & p1 , & ndr_table_drsuapi ) ;
2007-02-28 02:35:38 +03:00
torture_assert_ntstatus_ok ( torture , status , " opening drsuapi pipe1 " ) ;
2010-03-18 11:56:32 +03:00
b1 = p1 - > binding_handle ;
2007-02-28 02:35:38 +03:00
2007-08-28 16:54:27 +04:00
status = torture_rpc_connection ( torture , & p2 , & ndr_table_drsuapi ) ;
2007-02-28 02:35:38 +03:00
torture_assert_ntstatus_ok ( torture , status , " opening drsuapi pipe1 " ) ;
2010-03-18 11:56:32 +03:00
b2 = p2 - > binding_handle ;
2007-02-28 02:35:38 +03:00
GUID_from_string ( DRSUAPI_DS_BIND_GUID , & bind_guid ) ;
r . in . bind_guid = & bind_guid ;
r . in . bind_info = NULL ;
r . out . bind_handle = & handle ;
2010-03-18 11:56:32 +03:00
status = dcerpc_drsuapi_DsBind_r ( b1 , mem_ctx , & r ) ;
2007-02-28 02:35:38 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
torture_comment ( torture , " drsuapi_DsBind not supported - skipping \n " ) ;
talloc_free ( mem_ctx ) ;
return true ;
}
c . in . bind_handle = & handle ;
c . out . bind_handle = & handle2 ;
2010-03-18 11:56:32 +03:00
status = dcerpc_drsuapi_DsUnbind_r ( b2 , mem_ctx , & c ) ;
2010-03-30 00:36:22 +04:00
torture_assert_ntstatus_equal ( torture , status , NT_STATUS_RPC_SS_CONTEXT_MISMATCH ,
2007-02-28 02:35:38 +03:00
" closing policy handle on p2 " ) ;
2010-03-18 11:56:32 +03:00
status = dcerpc_drsuapi_DsUnbind_r ( b1 , mem_ctx , & c ) ;
2007-02-28 02:35:38 +03:00
torture_assert_ntstatus_ok ( torture , status , " closing policy handle on p1 " ) ;
2010-03-18 11:56:32 +03:00
status = dcerpc_drsuapi_DsUnbind_r ( b1 , mem_ctx , & c ) ;
2010-03-30 00:36:22 +04:00
torture_assert_ntstatus_equal ( torture , status , NT_STATUS_RPC_SS_CONTEXT_MISMATCH ,
2007-02-28 02:35:38 +03:00
" closing policy handle on p1 again " ) ;
talloc_free ( mem_ctx ) ;
return true ;
}
2007-08-26 19:16:40 +04:00
struct torture_suite * torture_rpc_handles ( TALLOC_CTX * mem_ctx )
2007-02-28 02:35:38 +03:00
{
struct torture_suite * suite ;
2010-12-11 05:26:31 +03:00
suite = torture_suite_create ( mem_ctx , " handles " ) ;
2007-02-28 02:35:38 +03:00
torture_suite_add_simple_test ( suite , " lsarpc " , test_handles_lsa ) ;
2007-02-28 18:57:52 +03:00
torture_suite_add_simple_test ( suite , " lsarpc-shared " , test_handles_lsa_shared ) ;
2007-02-28 02:35:38 +03:00
torture_suite_add_simple_test ( suite , " samr " , test_handles_samr ) ;
2007-02-28 20:06:01 +03:00
torture_suite_add_simple_test ( suite , " mixed-shared " , test_handles_mixed_shared ) ;
torture_suite_add_simple_test ( suite , " random-assoc " , test_handles_random_assoc ) ;
2007-02-28 02:35:38 +03:00
torture_suite_add_simple_test ( suite , " drsuapi " , test_handles_drsuapi ) ;
return suite ;
}