2010-03-23 16:04:30 +01:00
/*
2005-06-06 09:00:37 +00:00
Unix SMB / CIFS implementation .
Test suite for libnet calls .
Copyright ( C ) Rafal Szczesniak 2005
2010-03-23 16:04:30 +01:00
2005-06-06 09:00:37 +00:00
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
2005-06-06 09:00:37 +00:00
( at your option ) any later version .
2010-03-23 16:04:30 +01:00
2005-06-06 09:00:37 +00:00
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 .
2010-03-23 16:04:30 +01:00
2005-06-06 09:00:37 +00:00
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/>.
2005-06-06 09:00:37 +00:00
*/
# include "includes.h"
2006-03-14 15:02:05 +00:00
# include "torture/rpc/rpc.h"
2005-12-28 15:38:36 +00:00
# include "libnet/libnet.h"
2006-03-14 23:35:30 +00:00
# include "librpc/gen_ndr/ndr_samr_c.h"
2007-09-08 12:42:09 +00:00
# include "param/param.h"
2005-06-06 09:00:37 +00:00
2010-03-23 16:30:05 +01:00
static bool test_domainopen ( struct torture_context * tctx ,
struct libnet_context * net_ctx , TALLOC_CTX * mem_ctx ,
2005-07-08 08:09:02 +00:00
struct lsa_String * domname ,
2005-06-06 09:00:37 +00:00
struct policy_handle * domain_handle )
{
NTSTATUS status ;
2006-05-15 21:50:53 +00:00
struct libnet_DomainOpen io ;
2010-03-23 16:04:30 +01:00
2010-03-23 16:30:05 +01:00
torture_comment ( tctx , " opening domain \n " ) ;
2010-03-23 16:04:30 +01:00
2005-06-06 09:00:37 +00:00
io . in . domain_name = talloc_strdup ( mem_ctx , domname - > string ) ;
io . in . access_mask = SEC_FLAG_MAXIMUM_ALLOWED ;
2006-05-15 21:50:53 +00:00
status = libnet_DomainOpen ( net_ctx , mem_ctx , & io ) ;
2005-06-06 09:00:37 +00:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2010-03-23 16:30:05 +01:00
torture_comment ( tctx , " Composite domain open failed - %s \n " , nt_errstr ( status ) ) ;
2007-10-06 22:28:14 +00:00
return false ;
2005-06-06 09:00:37 +00:00
}
* domain_handle = io . out . domain_handle ;
2007-10-06 22:28:14 +00:00
return true ;
2005-06-06 09:00:37 +00:00
}
2010-03-23 16:30:05 +01:00
static bool test_cleanup ( struct torture_context * tctx ,
struct dcerpc_binding_handle * b , TALLOC_CTX * mem_ctx ,
2005-06-06 09:00:37 +00: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 ;
2010-03-23 16:04:30 +01:00
2010-03-23 16:30:05 +01:00
torture_comment ( tctx , " closing domain handle \n " ) ;
2010-03-23 16:04:30 +01:00
2010-03-11 11:33:10 +01:00
status = dcerpc_samr_Close_r ( b , mem_ctx , & r ) ;
2005-06-06 09:00:37 +00:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2010-03-23 16:30:05 +01:00
torture_comment ( tctx , " Close failed - %s \n " , nt_errstr ( status ) ) ;
2007-10-06 22:28:14 +00:00
return false ;
2005-06-06 09:00:37 +00:00
}
2010-03-23 16:04:30 +01:00
2007-10-06 22:28:14 +00:00
return true ;
2005-06-06 09:00:37 +00:00
}
2007-10-06 22:28:14 +00:00
bool torture_domainopen ( struct torture_context * torture )
2005-06-06 09:00:37 +00:00
{
NTSTATUS status ;
2006-05-15 21:50:53 +00:00
struct libnet_context * net_ctx ;
2005-06-06 09:00:37 +00:00
TALLOC_CTX * mem_ctx ;
2007-10-06 22:28:14 +00:00
bool ret = true ;
2005-06-06 09:00:37 +00:00
struct policy_handle h ;
2005-07-08 08:09:02 +00:00
struct lsa_String name ;
2005-06-06 09:00:37 +00:00
mem_ctx = talloc_init ( " test_domain_open " ) ;
2008-04-17 01:37:02 +02:00
net_ctx = libnet_context_init ( torture - > ev , torture - > lp_ctx ) ;
2006-05-15 21:50:53 +00:00
2010-03-23 16:04:30 +01:00
status = torture_rpc_connection ( torture ,
2006-08-21 21:03:28 +00:00
& net_ctx - > samr . pipe ,
2007-08-19 21:23:03 +00:00
& ndr_table_samr ) ;
2010-03-23 16:04:30 +01:00
2005-06-06 09:00:37 +00:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2007-10-06 22:28:14 +00:00
return false ;
2005-06-06 09:00:37 +00:00
}
2007-12-03 00:28:22 +01:00
name . string = lp_workgroup ( torture - > lp_ctx ) ;
2005-06-06 09:00:37 +00:00
/*
* Testing synchronous version
*/
2010-03-23 16:30:05 +01:00
if ( ! test_domainopen ( torture , net_ctx , mem_ctx , & name , & h ) ) {
2007-10-06 22:28:14 +00:00
ret = false ;
2005-06-06 09:00:37 +00:00
goto done ;
}
2010-03-23 16:30:05 +01:00
if ( ! test_cleanup ( torture , net_ctx - > samr . pipe - > binding_handle , mem_ctx , & h ) ) {
2007-10-06 22:28:14 +00:00
ret = false ;
2005-06-06 09:00:37 +00:00
goto done ;
}
done :
talloc_free ( mem_ctx ) ;
return ret ;
}