2007-10-16 15:44:43 +04:00
/*
Unix SMB / CIFS implementation .
test suite for rpc frsapi operations
Copyright ( C ) Guenther Deschner 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
2008-03-28 09:08:49 +03:00
the Free Software Foundation ; either version 3 of the License , or
2007-10-16 15:44:43 +04: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
along with this program ; if not , write to the Free Software
Foundation , Inc . , 675 Mass Ave , Cambridge , MA 0213 9 , USA .
*/
# include "includes.h"
# include "torture/rpc/rpc.h"
# include "librpc/gen_ndr/ndr_frsapi_c.h"
2007-10-18 23:23:25 +04:00
# include "param/param.h"
2007-10-16 15:44:43 +04:00
static bool test_GetDsPollingIntervalW ( struct torture_context * tctx ,
struct dcerpc_pipe * p ,
uint32_t * CurrentInterval ,
uint32_t * DsPollingLongInterval ,
uint32_t * DsPollingShortInterval )
{
struct frsapi_GetDsPollingIntervalW r ;
ZERO_STRUCT ( r ) ;
r . out . CurrentInterval = CurrentInterval ;
r . out . DsPollingLongInterval = DsPollingLongInterval ;
r . out . DsPollingShortInterval = DsPollingShortInterval ;
torture_assert_ntstatus_ok ( tctx ,
dcerpc_frsapi_GetDsPollingIntervalW ( p , tctx , & r ) ,
" GetDsPollingIntervalW failed " ) ;
torture_assert_werr_ok ( tctx , r . out . result ,
" GetDsPollingIntervalW failed " ) ;
return true ;
}
static bool test_SetDsPollingIntervalW ( struct torture_context * tctx ,
struct dcerpc_pipe * p ,
uint32_t CurrentInterval ,
uint32_t DsPollingLongInterval ,
uint32_t DsPollingShortInterval )
{
struct frsapi_SetDsPollingIntervalW r ;
ZERO_STRUCT ( r ) ;
r . in . CurrentInterval = CurrentInterval ;
r . in . DsPollingLongInterval = DsPollingLongInterval ;
r . in . DsPollingShortInterval = DsPollingShortInterval ;
torture_assert_ntstatus_ok ( tctx ,
dcerpc_frsapi_SetDsPollingIntervalW ( p , tctx , & r ) ,
" SetDsPollingIntervalW failed " ) ;
torture_assert_werr_ok ( tctx , r . out . result ,
" SetDsPollingIntervalW failed " ) ;
return true ;
}
static bool test_DsPollingIntervalW ( struct torture_context * tctx ,
struct dcerpc_pipe * p )
{
uint32_t i1 , i2 , i3 ;
uint32_t k1 , k2 , k3 ;
if ( ! test_GetDsPollingIntervalW ( tctx , p , & i1 , & i2 , & i3 ) ) {
return false ;
}
if ( ! test_SetDsPollingIntervalW ( tctx , p , i1 , i2 , i3 ) ) {
return false ;
}
k1 = i1 ;
k2 = k3 = 0 ;
if ( ! test_SetDsPollingIntervalW ( tctx , p , k1 , k2 , k3 ) ) {
return false ;
}
if ( ! test_GetDsPollingIntervalW ( tctx , p , & k1 , & k2 , & k3 ) ) {
return false ;
}
if ( ( i1 ! = k1 ) | | ( i2 ! = k2 ) | | ( i3 ! = k3 ) ) {
return false ;
}
return true ;
}
2007-10-16 16:33:34 +04:00
static bool test_IsPathReplicated_err ( struct torture_context * tctx ,
struct dcerpc_pipe * p ,
const char * path ,
uint32_t type ,
WERROR werr )
{
struct frsapi_IsPathReplicated r ;
struct GUID guid ;
2009-07-21 18:04:07 +04:00
uint32_t replicated , primary , root ;
2007-10-16 16:33:34 +04:00
ZERO_STRUCT ( r ) ;
r . in . path = path ;
r . in . replica_set_type = type ;
2009-07-21 18:04:07 +04:00
r . out . replicated = & replicated ;
r . out . primary = & primary ;
r . out . root = & root ;
2007-10-16 16:33:34 +04:00
r . out . replica_set_guid = & guid ;
torture_assert_ntstatus_ok ( tctx ,
dcerpc_frsapi_IsPathReplicated ( p , tctx , & r ) ,
" IsPathReplicated failed " ) ;
torture_assert_werr_equal ( tctx , r . out . result , werr ,
" GetDsPollingIntervalW failed " ) ;
return true ;
}
static bool _test_IsPathReplicated ( struct torture_context * tctx ,
struct dcerpc_pipe * p ,
const char * path ,
uint32_t type )
{
return test_IsPathReplicated_err ( tctx , p , path , type , WERR_OK ) ;
}
static bool test_IsPathReplicated ( struct torture_context * tctx ,
struct dcerpc_pipe * p )
{
const uint32_t lvls [ ] = {
FRSAPI_REPLICA_SET_TYPE_0 ,
FRSAPI_REPLICA_SET_TYPE_DOMAIN ,
FRSAPI_REPLICA_SET_TYPE_DFS } ;
int i ;
2007-10-18 23:23:25 +04:00
bool ret = true ;
2007-10-16 16:33:34 +04:00
if ( ! test_IsPathReplicated_err ( tctx , p , NULL , 0 ,
WERR_FRS_INVALID_SERVICE_PARAMETER ) ) {
2007-10-18 23:23:25 +04:00
ret = false ;
2007-10-16 16:33:34 +04:00
}
for ( i = 0 ; i < ARRAY_SIZE ( lvls ) ; i + + ) {
if ( ! _test_IsPathReplicated ( tctx , p , dcerpc_server_name ( p ) ,
lvls [ i ] ) ) {
2007-10-18 23:23:25 +04:00
ret = false ;
2007-10-16 16:33:34 +04:00
}
}
for ( i = 0 ; i < ARRAY_SIZE ( lvls ) ; i + + ) {
const char * path = talloc_asprintf ( tctx , " \\ \\ %s \\ SYSVOL " ,
dcerpc_server_name ( p ) ) ;
if ( ! _test_IsPathReplicated ( tctx , p , path , lvls [ i ] ) ) {
2007-10-18 23:23:25 +04:00
ret = false ;
2007-10-16 16:33:34 +04:00
}
}
for ( i = 0 ; i < ARRAY_SIZE ( lvls ) ; i + + ) {
if ( ! _test_IsPathReplicated ( tctx , p ,
" C: \\ windows \\ sysvol \\ domain " ,
lvls [ i ] ) ) {
2007-10-18 23:23:25 +04:00
ret = false ;
2007-10-16 16:33:34 +04:00
}
}
2007-10-18 23:23:25 +04:00
return ret ;
}
static bool test_ForceReplication ( struct torture_context * tctx ,
struct dcerpc_pipe * p )
{
struct frsapi_ForceReplication r ;
ZERO_STRUCT ( r ) ;
2009-07-21 18:04:07 +04:00
r . in . replica_set_guid = NULL ;
r . in . connection_guid = NULL ;
2009-10-12 21:09:18 +04:00
r . in . replica_set_name = lp_dnsdomain ( tctx - > lp_ctx ) ;
2009-07-21 18:04:07 +04:00
r . in . partner_dns_name = dcerpc_server_name ( p ) ;
2007-10-18 23:23:25 +04:00
torture_assert_ntstatus_ok ( tctx ,
dcerpc_frsapi_ForceReplication ( p , tctx , & r ) ,
" ForceReplication failed " ) ;
torture_assert_werr_ok ( tctx , r . out . result ,
" ForceReplication failed " ) ;
2007-10-16 16:33:34 +04:00
return true ;
}
2007-11-02 17:43:09 +03:00
static bool test_InfoW ( struct torture_context * tctx ,
struct dcerpc_pipe * p )
{
int i ;
for ( i = 0 ; i < 10 ; i + + ) {
struct frsapi_InfoW r ;
struct frsapi_Info * info ;
int d ;
DATA_BLOB blob ;
ZERO_STRUCT ( r ) ;
info = talloc_zero ( tctx , struct frsapi_Info ) ;
r . in . length = 0x1000 ;
r . in . info = r . out . info = info ;
info - > length = r . in . length ;
info - > length2 = r . in . length ;
info - > level = i ;
info - > offset = 0x2c ;
info - > blob_len = 0x2c ;
torture_assert_ntstatus_ok ( tctx ,
dcerpc_frsapi_InfoW ( p , tctx , & r ) ,
" InfoW failed " ) ;
torture_assert_werr_ok ( tctx , r . out . result , " InfoW failed " ) ;
/* display the formatted blob text */
blob = r . out . info - > blob ;
for ( d = 0 ; d < blob . length ; d + + ) {
if ( blob . data [ d ] ) {
printf ( " %c " , blob . data [ d ] ) ;
}
}
printf ( " \n " ) ;
}
return true ;
}
2007-10-16 15:44:43 +04:00
struct torture_suite * torture_rpc_frsapi ( TALLOC_CTX * mem_ctx )
{
struct torture_rpc_tcase * tcase ;
struct torture_suite * suite = torture_suite_create ( mem_ctx , " FRSAPI " ) ;
struct torture_test * test ;
tcase = torture_suite_add_rpc_iface_tcase ( suite , " frsapi " ,
& ndr_table_frsapi ) ;
test = torture_rpc_tcase_add_test ( tcase , " DsPollingIntervalW " ,
test_DsPollingIntervalW ) ;
2007-10-16 16:33:34 +04:00
test = torture_rpc_tcase_add_test ( tcase , " IsPathReplicated " ,
test_IsPathReplicated ) ;
2007-10-18 23:23:25 +04:00
test = torture_rpc_tcase_add_test ( tcase , " ForceReplication " ,
test_ForceReplication ) ;
2007-11-02 17:43:09 +03:00
test = torture_rpc_tcase_add_test ( tcase , " InfoW " ,
test_InfoW ) ;
2007-10-16 15:44:43 +04:00
return suite ;
}