2015-04-20 16:35:14 +03:00
/*
2003-11-24 04:24:29 +03:00
Unix SMB / CIFS implementation .
test suite for mgmt rpc operations
Copyright ( C ) Andrew Tridgell 2003
2015-04-20 16:35:14 +03:00
2003-11-24 04:24:29 +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-24 04:24:29 +03:00
( at your option ) any later version .
2015-04-20 16:35:14 +03:00
2003-11-24 04:24:29 +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 .
2015-04-20 16:35:14 +03:00
2003-11-24 04:24:29 +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-24 04:24:29 +03:00
*/
# include "includes.h"
2006-03-15 02:35:30 +03:00
# include "librpc/gen_ndr/ndr_mgmt_c.h"
2005-12-28 18:38:36 +03:00
# include "auth/gensec/gensec.h"
2007-08-21 23:35:43 +04:00
# include "librpc/ndr/ndr_table.h"
2010-04-14 00:06:51 +04:00
# include "torture/rpc/torture_rpc.h"
2007-09-08 16:42:09 +04:00
# include "param/param.h"
2003-11-24 04:24:29 +03:00
2003-11-27 08:34:28 +03:00
/*
ask the server what interface IDs are available on this endpoint
*/
2015-04-20 16:35:14 +03:00
bool test_inq_if_ids ( struct torture_context * tctx ,
2010-03-16 12:43:39 +03:00
struct dcerpc_binding_handle * b ,
TALLOC_CTX * mem_ctx ,
2007-10-07 02:28:14 +04:00
bool ( * per_id_test ) ( struct torture_context * ,
2007-08-28 16:54:27 +04:00
const struct ndr_interface_table * iface ,
2007-03-05 04:23:44 +03:00
TALLOC_CTX * mem_ctx ,
2007-08-18 10:57:49 +04:00
struct ndr_syntax_id * id ) ,
2007-03-05 04:23:44 +03:00
const void * priv )
2003-11-24 04:24:29 +03:00
{
struct mgmt_inq_if_ids r ;
2007-01-16 17:44:23 +03:00
struct rpc_if_id_vector_t * vector ;
2003-11-24 04:24:29 +03:00
int i ;
2007-01-16 17:44:23 +03:00
vector = talloc ( mem_ctx , struct rpc_if_id_vector_t ) ;
r . out . if_id_vector = & vector ;
2015-04-20 16:35:14 +03:00
2015-04-20 17:28:25 +03:00
torture_assert_ntstatus_ok ( tctx ,
dcerpc_mgmt_inq_if_ids_r ( b , mem_ctx , & r ) ,
" inq_if_ids failed " ) ;
2003-11-24 04:24:29 +03:00
2015-04-20 17:28:25 +03:00
torture_assert_werr_ok ( tctx ,
r . out . result ,
" inq_if_ids gave unexpected error code " ) ;
2003-11-24 04:24:29 +03:00
2007-01-16 17:44:23 +03:00
if ( ! vector ) {
2015-04-20 17:27:52 +03:00
torture_comment ( tctx , " inq_if_ids gave NULL if_id_vector \n " ) ;
2007-10-07 02:28:14 +04:00
return false ;
2003-11-24 04:24:29 +03:00
}
2007-01-16 17:44:23 +03:00
for ( i = 0 ; i < vector - > count ; i + + ) {
2007-08-18 10:57:49 +04:00
struct ndr_syntax_id * id = vector - > if_id [ i ] . id ;
2003-11-24 04:24:29 +03:00
if ( ! id ) continue ;
2003-11-28 08:20:11 +03:00
2015-04-20 17:27:52 +03:00
torture_comment ( tctx , " \t uuid %s version 0x%08x '%s' \n " ,
2005-12-27 19:22:35 +03:00
GUID_string ( mem_ctx , & id - > uuid ) ,
2007-08-21 23:35:43 +04:00
id - > if_version ,
ndr_interface_name ( & id - > uuid , id - > if_version ) ) ;
2007-03-05 04:23:44 +03:00
if ( per_id_test ) {
2007-08-28 16:54:27 +04:00
per_id_test ( tctx , priv , mem_ctx , id ) ;
2007-03-05 04:23:44 +03:00
}
2003-11-24 04:24:29 +03:00
}
2007-10-07 02:28:14 +04:00
return true ;
2003-11-24 04:24:29 +03:00
}
2015-04-20 16:41:44 +03:00
static bool test_inq_stats ( struct torture_context * tctx ,
struct dcerpc_binding_handle * b ,
2003-11-24 06:21:49 +03:00
TALLOC_CTX * mem_ctx )
{
struct mgmt_inq_stats r ;
2007-01-16 17:44:23 +03:00
struct mgmt_statistics statistics ;
2003-11-24 06:21:49 +03:00
2003-11-27 07:01:18 +03:00
r . in . max_count = MGMT_STATS_ARRAY_MAX_SIZE ;
2003-11-24 06:21:49 +03:00
r . in . unknown = 0 ;
2007-01-16 17:44:23 +03:00
r . out . statistics = & statistics ;
2003-11-24 06:21:49 +03:00
2015-04-20 17:28:25 +03:00
torture_assert_ntstatus_ok ( tctx ,
dcerpc_mgmt_inq_stats_r ( b , mem_ctx , & r ) ,
" inq_stats failed " ) ;
2003-11-24 06:21:49 +03:00
2007-01-16 17:44:23 +03:00
if ( statistics . count ! = MGMT_STATS_ARRAY_MAX_SIZE ) {
2015-04-20 17:27:52 +03:00
torture_comment ( tctx , " Unexpected array size %d \n " , statistics . count ) ;
2007-10-07 02:28:14 +04:00
return false ;
2003-11-24 06:21:49 +03:00
}
2015-04-20 17:27:52 +03:00
torture_comment ( tctx , " \t calls_in %6d calls_out %6d \n \t pkts_in %6d pkts_out %6d \n " ,
2007-01-16 17:44:23 +03:00
statistics . statistics [ MGMT_STATS_CALLS_IN ] ,
statistics . statistics [ MGMT_STATS_CALLS_OUT ] ,
statistics . statistics [ MGMT_STATS_PKTS_IN ] ,
statistics . statistics [ MGMT_STATS_PKTS_OUT ] ) ;
2003-11-24 06:21:49 +03:00
2007-10-07 02:28:14 +04:00
return true ;
2003-11-24 06:21:49 +03:00
}
2015-04-21 12:18:30 +03:00
static bool test_inq_princ_name_size ( struct torture_context * tctx ,
struct dcerpc_binding_handle * b ,
uint32_t authn_proto ,
const char * expected_princ_name )
{
struct mgmt_inq_princ_name r ;
uint32_t len , i ;
len = strlen ( expected_princ_name ) ;
r . in . authn_proto = authn_proto ;
/*
* 0 gives NT_STATUS_RPC_BAD_STUB_DATA
*/
for ( i = 1 ; i < = len ; i + + ) {
r . in . princ_name_size = i ;
torture_assert_ntstatus_ok ( tctx ,
dcerpc_mgmt_inq_princ_name_r ( b , tctx , & r ) ,
" mgmt_inq_princ_name failed " ) ;
torture_assert_werr_equal ( tctx ,
r . out . result ,
WERR_INSUFFICIENT_BUFFER ,
" mgmt_inq_princ_name failed " ) ;
}
r . in . princ_name_size = len + 1 ;
torture_assert_ntstatus_ok ( tctx ,
dcerpc_mgmt_inq_princ_name_r ( b , tctx , & r ) ,
" mgmt_inq_princ_name failed " ) ;
torture_assert_werr_ok ( tctx ,
r . out . result ,
" mgmt_inq_princ_name failed " ) ;
return true ;
}
2015-04-20 16:41:44 +03:00
static bool test_inq_princ_name ( struct torture_context * tctx ,
struct dcerpc_binding_handle * b ,
2003-11-24 06:21:49 +03:00
TALLOC_CTX * mem_ctx )
{
NTSTATUS status ;
struct mgmt_inq_princ_name r ;
2003-11-27 07:01:18 +03:00
int i ;
2007-10-07 02:28:14 +04:00
bool ret = false ;
2003-11-27 07:01:18 +03:00
2014-01-24 13:36:37 +04:00
for ( i = 0 ; i < 256 ; i + + ) {
2003-11-27 07:01:18 +03:00
r . in . authn_proto = i ; /* DCERPC_AUTH_TYPE_* */
r . in . princ_name_size = 100 ;
2010-03-16 12:43:39 +03:00
status = dcerpc_mgmt_inq_princ_name_r ( b , mem_ctx , & r ) ;
2003-11-27 07:01:18 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
continue ;
}
if ( W_ERROR_IS_OK ( r . out . result ) ) {
2008-11-03 01:58:49 +03:00
const char * name = gensec_get_name_by_authtype ( NULL , i ) ;
2007-10-07 02:28:14 +04:00
ret = true ;
2004-08-10 08:28:00 +04:00
if ( name ) {
2015-04-20 17:27:52 +03:00
torture_comment ( tctx , " \t principle name for proto %u (%s) is '%s' \n " ,
2004-08-10 08:28:00 +04:00
i , name , r . out . princ_name ) ;
} else {
2015-04-20 17:27:52 +03:00
torture_comment ( tctx , " \t principle name for proto %u is '%s' \n " ,
2004-08-10 08:28:00 +04:00
i , r . out . princ_name ) ;
}
2015-04-21 12:18:30 +03:00
switch ( i ) {
case DCERPC_AUTH_TYPE_KRB5 :
case DCERPC_AUTH_TYPE_NTLMSSP :
case DCERPC_AUTH_TYPE_SPNEGO :
torture_assert ( tctx ,
test_inq_princ_name_size ( tctx , b , i , r . out . princ_name ) ,
" failed " ) ;
break ;
case DCERPC_AUTH_TYPE_SCHANNEL :
/*
* for some reason schannel behaves differently
*
*/
default :
break ;
}
2003-11-27 07:01:18 +03:00
}
}
2003-11-24 06:21:49 +03:00
2003-11-27 07:01:18 +03:00
if ( ! ret ) {
2015-04-20 17:27:52 +03:00
torture_comment ( tctx , " \t no principle names? \n " ) ;
2003-11-24 06:21:49 +03:00
}
2007-10-07 02:28:14 +04:00
return true ;
2003-11-24 06:21:49 +03:00
}
2015-04-20 16:41:44 +03:00
static bool test_is_server_listening ( struct torture_context * tctx ,
struct dcerpc_binding_handle * b ,
2003-11-24 06:21:49 +03:00
TALLOC_CTX * mem_ctx )
{
struct mgmt_is_server_listening r ;
2007-01-16 17:44:23 +03:00
r . out . status = talloc ( mem_ctx , uint32_t ) ;
2003-11-24 06:21:49 +03:00
2015-04-20 17:28:25 +03:00
torture_assert_ntstatus_ok ( tctx ,
dcerpc_mgmt_is_server_listening_r ( b , mem_ctx , & r ) ,
" is_server_listening failed " ) ;
2003-11-24 06:21:49 +03:00
2007-01-15 01:28:29 +03:00
if ( * r . out . status ! = 0 | | r . out . result = = 0 ) {
2015-04-20 17:27:52 +03:00
torture_comment ( tctx , " \t server is NOT listening \n " ) ;
2003-11-24 06:21:49 +03:00
} else {
2015-04-20 17:27:52 +03:00
torture_comment ( tctx , " \t server is listening \n " ) ;
2003-11-24 06:21:49 +03:00
}
2007-10-07 02:28:14 +04:00
return true ;
2003-11-24 06:21:49 +03:00
}
2015-04-20 16:41:44 +03:00
static bool test_stop_server_listening ( struct torture_context * tctx ,
struct dcerpc_binding_handle * b ,
2003-11-24 06:21:49 +03:00
TALLOC_CTX * mem_ctx )
{
struct mgmt_stop_server_listening r ;
2015-04-20 17:28:25 +03:00
torture_assert_ntstatus_ok ( tctx ,
dcerpc_mgmt_stop_server_listening_r ( b , mem_ctx , & r ) ,
" stop_server_listening failed " ) ;
2003-11-24 06:21:49 +03:00
2003-11-27 07:01:18 +03:00
if ( ! W_ERROR_IS_OK ( r . out . result ) ) {
2015-04-20 17:27:52 +03:00
torture_comment ( tctx , " \t server refused to stop listening - %s \n " , win_errstr ( r . out . result ) ) ;
2003-11-24 06:21:49 +03:00
} else {
2015-04-20 17:27:52 +03:00
torture_comment ( tctx , " \t server allowed a stop_server_listening request \n " ) ;
2007-10-07 02:28:14 +04:00
return false ;
2003-11-24 06:21:49 +03:00
}
2007-10-07 02:28:14 +04:00
return true ;
2003-11-24 06:21:49 +03:00
}
2015-04-20 16:34:34 +03:00
bool torture_rpc_mgmt ( struct torture_context * tctx )
2003-11-24 04:24:29 +03:00
{
NTSTATUS status ;
struct dcerpc_pipe * p ;
2005-03-22 11:00:45 +03:00
TALLOC_CTX * mem_ctx , * loop_ctx ;
2007-10-07 02:28:14 +04:00
bool ret = true ;
2007-08-20 00:46:45 +04:00
const struct ndr_interface_list * l ;
r5902: A rather large change...
I wanted to add a simple 'workstation' argument to the DCERPC
authenticated binding calls, but this patch kind of grew from there.
With SCHANNEL, the 'workstation' name (the netbios name of the client)
matters, as this is what ties the session between the NETLOGON ops and
the SCHANNEL bind. This changes a lot of files, and these will again
be changed when jelmer does the credentials work.
I also correct some schannel IDL to distinguish between workstation
names and account names. The distinction matters for domain trust
accounts.
Issues in handling this (issues with lifetime of talloc pointers)
caused me to change the 'creds_CredentialsState' and 'struct
dcerpc_binding' pointers to always be talloc()ed pointers.
In the schannel DB, we now store both the domain and computername, and
query on both. This should ensure we fault correctly when the domain
is specified incorrectly in the SCHANNEL bind.
In the RPC-SCHANNEL test, I finally fixed a bug that vl pointed out,
where the comment claimed we re-used a connection, but in fact we made
a new connection.
This was achived by breaking apart some of the
dcerpc_secondary_connection() logic.
The addition of workstation handling was also propogated to NTLMSSP
and GENSEC, for completeness.
The RPC-SAMSYNC test has been cleaned up a little, using a loop over
usernames/passwords rather than manually expanded tests. This will be
expanded further (the code in #if 0 in this patch) to use a newly
created user account for testing.
In making this test pass test_rpc.sh, I found a bug in the RPC-ECHO
server, caused by the removal of [ref] and the assoicated pointer from
the IDL. This has been re-added, until the underlying pidl issues are
solved.
(This used to be commit 824289dcc20908ddec957a4a892a103eec2da9b9)
2005-03-19 11:34:43 +03:00
struct dcerpc_binding * b ;
2003-11-24 04:24:29 +03:00
mem_ctx = talloc_init ( " torture_rpc_mgmt " ) ;
2015-04-20 16:34:34 +03:00
status = torture_rpc_binding ( tctx , & b ) ;
2003-12-16 13:57:17 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2005-03-22 11:00:45 +03:00
talloc_free ( mem_ctx ) ;
2007-10-07 02:28:14 +04:00
return false ;
2003-12-16 13:57:17 +03:00
}
2003-11-27 08:34:28 +03:00
2015-04-20 16:35:14 +03:00
for ( l = ndr_table_list ( ) ; l ; l = l - > next ) {
2010-03-16 12:43:39 +03:00
struct dcerpc_binding_handle * bh ;
2005-03-22 11:00:45 +03:00
loop_ctx = talloc_named ( mem_ctx , 0 , " torture_rpc_mgmt loop context " ) ;
2015-04-20 16:35:14 +03:00
2003-11-24 04:24:29 +03:00
/* some interfaces are not mappable */
2004-11-17 00:07:08 +03:00
if ( l - > table - > num_calls = = 0 | |
strcmp ( l - > table - > name , " mgmt " ) = = 0 ) {
2005-03-22 11:00:45 +03:00
talloc_free ( loop_ctx ) ;
2003-11-24 04:24:29 +03:00
continue ;
}
2015-04-20 17:27:52 +03:00
torture_comment ( tctx , " \n Testing pipe '%s' \n " , l - > table - > name ) ;
2003-11-24 04:24:29 +03:00
2014-01-24 13:31:32 +04:00
status = dcerpc_epm_map_binding ( loop_ctx , b , l - > table ,
2015-04-20 16:34:34 +03:00
tctx - > ev , tctx - > lp_ctx ) ;
2007-01-16 17:44:23 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2015-04-20 17:27:52 +03:00
torture_comment ( tctx , " Failed to map port for uuid %s \n " ,
2007-01-16 17:44:23 +03:00
GUID_string ( loop_ctx , & l - > table - > syntax_id . uuid ) ) ;
talloc_free ( loop_ctx ) ;
continue ;
2003-11-27 08:34:28 +03:00
}
2003-12-16 13:57:17 +03:00
2015-04-20 16:34:34 +03:00
lpcfg_set_cmdline ( tctx - > lp_ctx , " torture:binding " , dcerpc_binding_string ( loop_ctx , b ) ) ;
2003-11-27 08:34:28 +03:00
2015-04-20 16:34:34 +03:00
status = torture_rpc_connection ( tctx , & p , & ndr_table_mgmt ) ;
2007-01-16 17:44:23 +03:00
if ( NT_STATUS_EQUAL ( status , NT_STATUS_OBJECT_NAME_NOT_FOUND ) ) {
2015-04-20 17:27:52 +03:00
torture_comment ( tctx , " Interface not available - skipping \n " ) ;
2007-01-16 17:44:23 +03:00
talloc_free ( loop_ctx ) ;
continue ;
}
2003-11-24 04:24:29 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2005-03-22 11:00:45 +03:00
talloc_free ( loop_ctx ) ;
2015-04-21 13:07:08 +03:00
torture_comment ( tctx , " Interface not available (%s) - skipping \n " , nt_errstr ( status ) ) ;
2007-10-07 02:28:14 +04:00
ret = false ;
2003-11-24 04:24:29 +03:00
continue ;
}
2015-04-21 13:07:08 +03:00
bh = p - > binding_handle ;
2007-01-16 17:44:23 +03:00
2015-04-20 16:41:44 +03:00
if ( ! test_is_server_listening ( tctx , bh , loop_ctx ) ) {
2007-10-07 02:28:14 +04:00
ret = false ;
2003-11-24 06:21:49 +03:00
}
2015-04-20 16:41:44 +03:00
if ( ! test_stop_server_listening ( tctx , bh , loop_ctx ) ) {
2007-10-07 02:28:14 +04:00
ret = false ;
2003-11-24 06:21:49 +03:00
}
2015-04-20 16:41:44 +03:00
if ( ! test_inq_stats ( tctx , bh , loop_ctx ) ) {
2007-10-07 02:28:14 +04:00
ret = false ;
2003-11-24 06:21:49 +03:00
}
2015-04-20 16:41:44 +03:00
if ( ! test_inq_princ_name ( tctx , bh , loop_ctx ) ) {
2007-10-07 02:28:14 +04:00
ret = false ;
2003-11-24 06:21:49 +03:00
}
2015-04-20 16:34:34 +03:00
if ( ! test_inq_if_ids ( tctx , bh , loop_ctx , NULL , NULL ) ) {
2007-10-07 02:28:14 +04:00
ret = false ;
2003-11-24 04:24:29 +03:00
}
}
return ret ;
}