2005-06-06 13:00:37 +04:00
/*
Unix SMB / CIFS implementation .
Test suite for libnet calls .
Copyright ( C ) Rafal Szczesniak 2005
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
2005-06-06 13:00:37 +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
2007-07-10 06:07:03 +04:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2005-06-06 13:00:37 +04:00
*/
# include "includes.h"
2006-03-14 18:02:05 +03:00
# include "torture/rpc/rpc.h"
2006-05-16 01:50:53 +04:00
# include "lib/events/events.h"
2005-12-28 18:38:36 +03:00
# include "libnet/libnet.h"
2006-03-15 02:35:30 +03:00
# include "librpc/gen_ndr/ndr_samr_c.h"
2007-09-08 16:42:09 +04:00
# include "param/param.h"
2005-06-06 13:00:37 +04:00
2007-10-07 02:28:14 +04:00
static bool test_domainopen ( struct libnet_context * net_ctx , TALLOC_CTX * mem_ctx ,
2005-07-08 12:09:02 +04:00
struct lsa_String * domname ,
2005-06-06 13:00:37 +04:00
struct policy_handle * domain_handle )
{
NTSTATUS status ;
2006-05-16 01:50:53 +04:00
struct libnet_DomainOpen io ;
2005-06-06 13:00:37 +04:00
printf ( " opening domain \n " ) ;
io . in . domain_name = talloc_strdup ( mem_ctx , domname - > string ) ;
io . in . access_mask = SEC_FLAG_MAXIMUM_ALLOWED ;
2006-05-16 01:50:53 +04:00
status = libnet_DomainOpen ( net_ctx , mem_ctx , & io ) ;
2005-06-06 13:00:37 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " Composite domain open failed - %s \n " , nt_errstr ( status ) ) ;
2007-10-07 02:28:14 +04:00
return false ;
2005-06-06 13:00:37 +04:00
}
* domain_handle = io . out . domain_handle ;
2007-10-07 02:28:14 +04:00
return true ;
2005-06-06 13:00:37 +04:00
}
2007-10-07 02:28:14 +04:00
static bool test_cleanup ( struct dcerpc_pipe * p , TALLOC_CTX * mem_ctx ,
2005-06-06 13:00:37 +04:00
struct policy_handle * domain_handle )
{
NTSTATUS status ;
struct samr_Close r ;
struct policy_handle handle ;
r . in . handle = domain_handle ;
r . out . handle = & handle ;
printf ( " closing domain handle \n " ) ;
status = dcerpc_samr_Close ( p , mem_ctx , & r ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " Close failed - %s \n " , nt_errstr ( status ) ) ;
2007-10-07 02:28:14 +04:00
return false ;
2005-06-06 13:00:37 +04:00
}
2007-10-07 02:28:14 +04:00
return true ;
2005-06-06 13:00:37 +04:00
}
2007-10-07 02:28:14 +04:00
bool torture_domainopen ( struct torture_context * torture )
2005-06-06 13:00:37 +04:00
{
NTSTATUS status ;
2006-05-16 01:50:53 +04:00
struct libnet_context * net_ctx ;
struct event_context * evt_ctx ;
2005-06-06 13:00:37 +04:00
TALLOC_CTX * mem_ctx ;
2007-10-07 02:28:14 +04:00
bool ret = true ;
2005-06-06 13:00:37 +04:00
struct policy_handle h ;
2005-07-08 12:09:02 +04:00
struct lsa_String name ;
2005-06-06 13:00:37 +04:00
mem_ctx = talloc_init ( " test_domain_open " ) ;
2006-05-16 01:50:53 +04:00
evt_ctx = event_context_find ( torture ) ;
net_ctx = libnet_context_init ( evt_ctx ) ;
2007-08-28 16:54:27 +04:00
status = torture_rpc_connection ( torture ,
2006-08-22 01:03:28 +04:00
& net_ctx - > samr . pipe ,
2007-08-20 01:23:03 +04:00
& ndr_table_samr ) ;
2005-06-06 13:00:37 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2005-06-06 13:00:37 +04:00
}
2007-09-28 05:17:46 +04:00
name . string = lp_workgroup ( global_loadparm ) ;
2005-06-06 13:00:37 +04:00
/*
* Testing synchronous version
*/
2006-05-16 01:50:53 +04:00
if ( ! test_domainopen ( net_ctx , mem_ctx , & name , & h ) ) {
2007-10-07 02:28:14 +04:00
ret = false ;
2005-06-06 13:00:37 +04:00
goto done ;
}
2006-08-22 01:03:28 +04:00
if ( ! test_cleanup ( net_ctx - > samr . pipe , mem_ctx , & h ) ) {
2007-10-07 02:28:14 +04:00
ret = false ;
2005-06-06 13:00:37 +04:00
goto done ;
}
done :
talloc_free ( mem_ctx ) ;
return ret ;
}