2004-08-02 00:24:04 +00:00
/*
Unix SMB / CIFS implementation .
test suite for srvsvc rpc operations
Copyright ( C ) Jelmer Vernooij 2004
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 02:07:03 +00:00
the Free Software Foundation ; either version 3 of the License , or
2004-08-02 00:24:04 +00: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 02:07:03 +00:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2004-08-02 00:24:04 +00:00
*/
# include "includes.h"
2006-01-03 13:41:17 +00:00
# include "torture/torture.h"
2006-03-14 23:35:30 +00:00
# include "librpc/gen_ndr/ndr_svcctl_c.h"
2006-03-14 15:02:05 +00:00
# include "torture/rpc/rpc.h"
2004-08-02 00:24:04 +00:00
static BOOL test_EnumServicesStatus ( struct dcerpc_pipe * p , TALLOC_CTX * mem_ctx , struct policy_handle * h )
{
2004-08-10 20:55:42 +00:00
struct svcctl_EnumServicesStatusW r ;
2004-08-02 00:24:04 +00:00
int i ;
NTSTATUS status ;
2005-02-10 05:09:35 +00:00
uint32_t resume_handle = 0 ;
2004-08-03 23:06:15 +00:00
struct ENUM_SERVICE_STATUS * service = NULL ;
2004-08-02 00:24:04 +00:00
r . in . handle = h ;
r . in . type = SERVICE_TYPE_WIN32 ;
r . in . state = SERVICE_STATE_ALL ;
2004-08-03 23:06:15 +00:00
r . in . buf_size = 0 ;
2004-08-02 00:24:04 +00:00
r . in . resume_handle = & resume_handle ;
2004-08-03 23:06:15 +00:00
r . out . service = NULL ;
2004-08-02 00:24:04 +00:00
r . out . resume_handle = & resume_handle ;
2004-08-03 23:06:15 +00:00
r . out . services_returned = 0 ;
r . out . bytes_needed = 0 ;
2004-08-02 00:24:04 +00:00
2004-08-10 20:55:42 +00:00
status = dcerpc_svcctl_EnumServicesStatusW ( p , mem_ctx , & r ) ;
2004-08-02 00:24:04 +00:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " <EFBFBD> numServicesStatus failed!\n " ) ;
return False ;
}
if ( W_ERROR_EQUAL ( r . out . result , WERR_MORE_DATA ) ) {
2004-08-03 23:06:15 +00:00
r . in . buf_size = r . out . bytes_needed ;
2005-01-06 03:06:58 +00:00
r . out . service = talloc_size ( mem_ctx , r . out . bytes_needed ) ;
2004-08-02 00:24:04 +00:00
2004-08-10 20:55:42 +00:00
status = dcerpc_svcctl_EnumServicesStatusW ( p , mem_ctx , & r ) ;
2004-08-02 00:24:04 +00:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " <EFBFBD> numServicesStatus failed!\n " ) ;
return False ;
}
if ( ! W_ERROR_IS_OK ( r . out . result ) ) {
printf ( " EnumServicesStatus failed \n " ) ;
return False ;
}
2004-08-03 23:06:15 +00:00
service = ( struct ENUM_SERVICE_STATUS * ) r . out . service ;
2004-08-02 00:24:04 +00:00
}
for ( i = 0 ; i < r . out . services_returned ; i + + ) {
2004-08-03 23:06:15 +00:00
printf ( " Type: %d, State: %d \n " , service [ i ] . status . type , service [ i ] . status . state ) ;
2004-08-02 00:24:04 +00:00
}
return True ;
}
static BOOL test_OpenSCManager ( struct dcerpc_pipe * p , TALLOC_CTX * mem_ctx , struct policy_handle * h )
{
2004-08-10 20:55:42 +00:00
struct svcctl_OpenSCManagerW r ;
2004-08-02 00:24:04 +00:00
NTSTATUS status ;
r . in . MachineName = NULL ;
r . in . DatabaseName = NULL ;
2004-12-02 04:37:36 +00:00
r . in . access_mask = SEC_FLAG_MAXIMUM_ALLOWED ;
2004-08-02 00:24:04 +00:00
r . out . handle = h ;
2004-08-10 20:55:42 +00:00
status = dcerpc_svcctl_OpenSCManagerW ( p , mem_ctx , & r ) ;
2004-08-02 00:24:04 +00:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " OpenSCManager failed! \n " ) ;
return False ;
}
return True ;
}
static BOOL test_CloseServiceHandle ( struct dcerpc_pipe * p , TALLOC_CTX * mem_ctx , struct policy_handle * h )
{
struct svcctl_CloseServiceHandle r ;
NTSTATUS status ;
r . in . handle = h ;
r . out . handle = h ;
status = dcerpc_svcctl_CloseServiceHandle ( p , mem_ctx , & r ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " CloseServiceHandle failed \n " ) ;
return False ;
}
return True ;
}
2006-03-25 16:01:28 +00:00
BOOL torture_rpc_svcctl ( struct torture_context * torture )
2004-08-02 00:24:04 +00:00
{
NTSTATUS status ;
struct dcerpc_pipe * p ;
struct policy_handle h ;
TALLOC_CTX * mem_ctx ;
BOOL ret = True ;
mem_ctx = talloc_init ( " torture_rpc_svcctl " ) ;
2005-12-27 14:28:01 +00:00
status = torture_rpc_connection ( mem_ctx , & p , & dcerpc_table_svcctl ) ;
2004-08-02 00:24:04 +00:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2005-03-22 08:00:45 +00:00
talloc_free ( mem_ctx ) ;
2004-08-02 00:24:04 +00:00
return False ;
}
if ( ! test_OpenSCManager ( p , mem_ctx , & h ) ) {
ret = False ;
}
if ( ! test_EnumServicesStatus ( p , mem_ctx , & h ) ) {
ret = False ;
}
if ( ! test_CloseServiceHandle ( p , mem_ctx , & h ) ) {
ret = False ;
}
2005-01-27 07:08:20 +00:00
talloc_free ( mem_ctx ) ;
2004-08-02 00:24:04 +00:00
return ret ;
}