2003-11-24 04:24:29 +03:00
/*
Unix SMB / CIFS implementation .
test suite for mgmt rpc operations
Copyright ( C ) Andrew Tridgell 2003
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
the Free Software Foundation ; either version 2 of the License , or
( 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
along with this program ; if not , write to the Free Software
Foundation , Inc . , 675 Mass Ave , Cambridge , MA 0213 9 , USA .
*/
# include "includes.h"
2006-01-03 16:41:17 +03:00
# include "torture/torture.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"
2005-12-31 02:18:27 +03:00
# include "librpc/rpc/dcerpc_table.h"
2006-03-14 18:02:05 +03:00
# include "torture/rpc/rpc.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
*/
2007-03-05 04:23:44 +03:00
BOOL test_inq_if_ids ( struct dcerpc_pipe * p , TALLOC_CTX * mem_ctx ,
BOOL ( * per_id_test ) ( const struct dcerpc_interface_table * iface ,
TALLOC_CTX * mem_ctx ,
struct dcerpc_syntax_id * id ) ,
const void * priv )
2003-11-24 04:24:29 +03:00
{
NTSTATUS status ;
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 ;
2003-11-24 06:21:49 +03:00
2003-11-24 04:24:29 +03:00
status = dcerpc_mgmt_inq_if_ids ( p , mem_ctx , & r ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " inq_if_ids failed - %s \n " , nt_errstr ( status ) ) ;
return False ;
}
2003-11-27 07:01:18 +03:00
if ( ! W_ERROR_IS_OK ( r . out . result ) ) {
printf ( " inq_if_ids gave error code %s \n " , win_errstr ( r . out . result ) ) ;
2003-11-24 04:24:29 +03:00
return False ;
}
2007-01-16 17:44:23 +03:00
if ( ! vector ) {
2003-11-24 04:24:29 +03:00
printf ( " inq_if_ids gave NULL if_id_vector \n " ) ;
return False ;
}
2007-01-16 17:44:23 +03:00
for ( i = 0 ; i < vector - > count ; i + + ) {
struct dcerpc_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
2003-12-16 12:02:58 +03:00
printf ( " \t uuid %s version 0x%08x '%s' \n " ,
2005-12-27 19:22:35 +03:00
GUID_string ( mem_ctx , & id - > uuid ) ,
id - > if_version , idl_pipe_name ( & id - > uuid , id - > if_version ) ) ;
2007-03-05 04:23:44 +03:00
if ( per_id_test ) {
per_id_test ( priv , mem_ctx , id ) ;
}
2003-11-24 04:24:29 +03:00
}
return True ;
}
2003-11-24 06:21:49 +03:00
static BOOL test_inq_stats ( struct dcerpc_pipe * p ,
TALLOC_CTX * mem_ctx )
{
NTSTATUS status ;
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
status = dcerpc_mgmt_inq_stats ( p , mem_ctx , & r ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " inq_stats failed - %s \n " , nt_errstr ( status ) ) ;
return False ;
}
2007-01-16 17:44:23 +03:00
if ( statistics . count ! = MGMT_STATS_ARRAY_MAX_SIZE ) {
printf ( " Unexpected array size %d \n " , statistics . count ) ;
2003-11-24 06:21:49 +03:00
return False ;
}
printf ( " \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
return True ;
}
static BOOL test_inq_princ_name ( struct dcerpc_pipe * p ,
TALLOC_CTX * mem_ctx )
{
NTSTATUS status ;
struct mgmt_inq_princ_name r ;
2003-11-27 07:01:18 +03:00
int i ;
BOOL ret = False ;
2003-11-27 10:28:46 +03:00
for ( i = 0 ; i < 100 ; i + + ) {
2003-11-27 07:01:18 +03:00
r . in . authn_proto = i ; /* DCERPC_AUTH_TYPE_* */
r . in . princ_name_size = 100 ;
status = dcerpc_mgmt_inq_princ_name ( p , mem_ctx , & r ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
continue ;
}
if ( W_ERROR_IS_OK ( r . out . result ) ) {
2004-08-10 08:28:00 +04:00
const char * name = gensec_get_name_by_authtype ( i ) ;
2003-11-27 07:01:18 +03:00
ret = True ;
2004-08-10 08:28:00 +04:00
if ( name ) {
printf ( " \t principle name for proto %u (%s) is '%s' \n " ,
i , name , r . out . princ_name ) ;
} else {
printf ( " \t principle name for proto %u is '%s' \n " ,
i , r . out . princ_name ) ;
}
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 ) {
printf ( " \t no principle names? \n " ) ;
2003-11-24 06:21:49 +03:00
}
return True ;
}
static BOOL test_is_server_listening ( struct dcerpc_pipe * p ,
TALLOC_CTX * mem_ctx )
{
NTSTATUS status ;
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
status = dcerpc_mgmt_is_server_listening ( p , mem_ctx , & r ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " is_server_listening failed - %s \n " , nt_errstr ( status ) ) ;
return False ;
}
2007-01-15 01:28:29 +03:00
if ( * r . out . status ! = 0 | | r . out . result = = 0 ) {
2003-11-24 06:21:49 +03:00
printf ( " \t server is NOT listening \n " ) ;
} else {
printf ( " \t server is listening \n " ) ;
}
return True ;
}
static BOOL test_stop_server_listening ( struct dcerpc_pipe * p ,
TALLOC_CTX * mem_ctx )
{
NTSTATUS status ;
struct mgmt_stop_server_listening r ;
status = dcerpc_mgmt_stop_server_listening ( p , mem_ctx , & r ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " stop_server_listening failed - %s \n " , nt_errstr ( status ) ) ;
return False ;
}
2003-11-27 07:01:18 +03:00
if ( ! W_ERROR_IS_OK ( r . out . result ) ) {
printf ( " \t server refused to stop listening - %s \n " , win_errstr ( r . out . result ) ) ;
2003-11-24 06:21:49 +03:00
} else {
printf ( " \t server allowed a stop_server_listening request \n " ) ;
return False ;
}
return True ;
}
2006-03-25 19:01:28 +03:00
BOOL torture_rpc_mgmt ( struct torture_context * torture )
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 ;
2003-11-24 04:24:29 +03:00
BOOL ret = True ;
2006-10-18 18:23:19 +04:00
const char * binding = torture_setting_string ( torture , " binding " , NULL ) ;
2005-01-09 11:34:05 +03:00
const struct dcerpc_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 " ) ;
2003-12-16 13:57:17 +03:00
if ( ! binding ) {
printf ( " You must supply a ncacn binding string \n " ) ;
return False ;
}
status = dcerpc_parse_binding ( mem_ctx , binding , & b ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
2005-03-22 11:00:45 +03:00
talloc_free ( mem_ctx ) ;
2003-12-16 13:57:17 +03:00
printf ( " Failed to parse binding '%s' \n " , binding ) ;
return False ;
}
2003-11-27 08:34:28 +03:00
2005-01-09 11:34:05 +03:00
for ( l = librpc_dcerpc_pipes ( ) ; l ; l = l - > next ) {
2005-03-22 11:00:45 +03:00
loop_ctx = talloc_named ( mem_ctx , 0 , " torture_rpc_mgmt loop context " ) ;
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 ;
}
2004-11-17 00:07:08 +03:00
printf ( " \n Testing pipe '%s' \n " , l - > table - > name ) ;
2003-11-24 04:24:29 +03:00
2007-01-16 17:44:23 +03:00
status = dcerpc_epm_map_binding ( loop_ctx , b , l - > table , NULL ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " Failed to map port for uuid %s \n " ,
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
2005-03-22 11:00:45 +03:00
lp_set_cmdline ( " torture:binding " , dcerpc_binding_string ( loop_ctx , b ) ) ;
2003-11-27 08:34:28 +03:00
2005-12-27 17:28:01 +03:00
status = torture_rpc_connection ( loop_ctx , & p , & dcerpc_table_mgmt ) ;
2007-01-16 17:44:23 +03:00
if ( NT_STATUS_EQUAL ( status , NT_STATUS_OBJECT_NAME_NOT_FOUND ) ) {
printf ( " Interface not available - skipping \n " ) ;
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 ) ;
2003-11-24 04:24:29 +03:00
ret = False ;
continue ;
}
2007-01-16 17:44:23 +03:00
2005-03-22 11:00:45 +03:00
if ( ! test_is_server_listening ( p , loop_ctx ) ) {
2003-11-24 06:21:49 +03:00
ret = False ;
}
2005-03-22 11:00:45 +03:00
if ( ! test_stop_server_listening ( p , loop_ctx ) ) {
2003-11-24 06:21:49 +03:00
ret = False ;
}
2005-03-22 11:00:45 +03:00
if ( ! test_inq_stats ( p , loop_ctx ) ) {
2003-11-24 06:21:49 +03:00
ret = False ;
}
2005-03-22 11:00:45 +03:00
if ( ! test_inq_princ_name ( p , loop_ctx ) ) {
2003-11-24 06:21:49 +03:00
ret = False ;
}
2007-03-05 04:23:44 +03:00
if ( ! test_inq_if_ids ( p , loop_ctx , NULL , NULL ) ) {
2003-11-24 04:24:29 +03:00
ret = False ;
}
}
return ret ;
}