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
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 .
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/>.
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
*/
2007-10-07 02:28:14 +04: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
{
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
2010-03-16 12:43:39 +03:00
status = dcerpc_mgmt_inq_if_ids_r ( b , mem_ctx , & r ) ;
2003-11-24 04:24:29 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " inq_if_ids failed - %s \n " , nt_errstr ( status ) ) ;
2007-10-07 02:28:14 +04:00
return false ;
2003-11-24 04:24:29 +03:00
}
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 ) ) ;
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
if ( ! vector ) {
2003-11-24 04:24:29 +03:00
printf ( " 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
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 ) ,
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
}
2010-03-16 12:43:39 +03:00
static bool test_inq_stats ( struct dcerpc_binding_handle * b ,
2003-11-24 06:21:49 +03:00
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
2010-03-16 12:43:39 +03:00
status = dcerpc_mgmt_inq_stats_r ( b , mem_ctx , & r ) ;
2003-11-24 06:21:49 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " inq_stats failed - %s \n " , nt_errstr ( status ) ) ;
2007-10-07 02:28:14 +04:00
return false ;
2003-11-24 06:21:49 +03:00
}
2007-01-16 17:44:23 +03:00
if ( statistics . count ! = MGMT_STATS_ARRAY_MAX_SIZE ) {
printf ( " 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
}
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
2007-10-07 02:28:14 +04:00
return true ;
2003-11-24 06:21:49 +03:00
}
2010-03-16 12:43:39 +03:00
static bool test_inq_princ_name ( 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 ) {
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
}
2007-10-07 02:28:14 +04:00
return true ;
2003-11-24 06:21:49 +03:00
}
2010-03-16 12:43:39 +03:00
static bool test_is_server_listening ( struct dcerpc_binding_handle * b ,
2003-11-24 06:21:49 +03:00
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
2010-03-16 12:43:39 +03:00
status = dcerpc_mgmt_is_server_listening_r ( b , mem_ctx , & r ) ;
2003-11-24 06:21:49 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " is_server_listening failed - %s \n " , nt_errstr ( status ) ) ;
2007-10-07 02:28:14 +04:00
return false ;
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 ) {
2003-11-24 06:21:49 +03:00
printf ( " \t server is NOT listening \n " ) ;
} else {
printf ( " \t server is listening \n " ) ;
}
2007-10-07 02:28:14 +04:00
return true ;
2003-11-24 06:21:49 +03:00
}
2010-03-16 12:43:39 +03:00
static bool test_stop_server_listening ( struct dcerpc_binding_handle * b ,
2003-11-24 06:21:49 +03:00
TALLOC_CTX * mem_ctx )
{
NTSTATUS status ;
struct mgmt_stop_server_listening r ;
2010-03-16 12:43:39 +03:00
status = dcerpc_mgmt_stop_server_listening_r ( b , mem_ctx , & r ) ;
2003-11-24 06:21:49 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " stop_server_listening failed - %s \n " , nt_errstr ( status ) ) ;
2007-10-07 02:28:14 +04:00
return false ;
2003-11-24 06:21:49 +03:00
}
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 " ) ;
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
}
2007-10-07 02:28:14 +04: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 ;
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 " ) ;
2007-08-28 23:03:08 +04:00
status = torture_rpc_binding ( torture , & 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
2007-08-21 23:35:43 +04: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 " ) ;
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
2014-01-24 13:31:32 +04:00
status = dcerpc_epm_map_binding ( loop_ctx , b , l - > table ,
torture - > ev , torture - > lp_ctx ) ;
2007-01-16 17:44:23 +03:00
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
2010-07-16 08:32:42 +04:00
lpcfg_set_cmdline ( torture - > lp_ctx , " torture:binding " , dcerpc_binding_string ( loop_ctx , b ) ) ;
2003-11-27 08:34:28 +03:00
2007-08-28 16:54:27 +04:00
status = torture_rpc_connection ( torture , & p , & ndr_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 ;
}
2010-03-16 12:43:39 +03:00
bh = p - > binding_handle ;
2007-01-16 17:44:23 +03:00
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 ) ;
2007-10-07 02:28:14 +04:00
ret = false ;
2003-11-24 04:24:29 +03:00
continue ;
}
2007-01-16 17:44:23 +03:00
2010-03-16 12:43:39 +03:00
if ( ! test_is_server_listening ( bh , loop_ctx ) ) {
2007-10-07 02:28:14 +04:00
ret = false ;
2003-11-24 06:21:49 +03:00
}
2010-03-16 12:43:39 +03:00
if ( ! test_stop_server_listening ( bh , loop_ctx ) ) {
2007-10-07 02:28:14 +04:00
ret = false ;
2003-11-24 06:21:49 +03:00
}
2010-03-16 12:43:39 +03:00
if ( ! test_inq_stats ( bh , loop_ctx ) ) {
2007-10-07 02:28:14 +04:00
ret = false ;
2003-11-24 06:21:49 +03:00
}
2010-03-16 12:43:39 +03:00
if ( ! test_inq_princ_name ( bh , loop_ctx ) ) {
2007-10-07 02:28:14 +04:00
ret = false ;
2003-11-24 06:21:49 +03:00
}
2010-03-16 12:43:39 +03:00
if ( ! test_inq_if_ids ( torture , 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 ;
}