2010-03-23 16:04:30 +01:00
/*
2005-03-01 23:53:18 +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-03-01 23:53:18 +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-03-01 23:53:18 +00:00
( at your option ) any later version .
2010-03-23 16:04:30 +01:00
2005-03-01 23:53:18 +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-03-01 23:53:18 +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-03-01 23:53:18 +00:00
*/
# include "includes.h"
2010-04-13 22:06:51 +02:00
# include "torture/rpc/torture_rpc.h"
2005-12-28 15:38:36 +00:00
# include "libnet/libnet.h"
2006-04-02 12:02:01 +00:00
# include "libcli/security/security.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"
2010-05-28 05:14:47 +03:00
# include "torture/libnet/proto.h"
2005-03-07 05:12:33 +00:00
2007-09-27 15:51:07 +00:00
# define TEST_USERNAME "libnetuserinfotest"
2005-03-07 05:12:33 +00:00
2010-03-23 15:31:27 +01:00
static bool test_userinfo ( struct torture_context * tctx ,
struct dcerpc_pipe * p , TALLOC_CTX * mem_ctx ,
2005-03-07 05:12:33 +00:00
struct policy_handle * domain_handle ,
2005-03-07 12:27:03 +00:00
struct dom_sid2 * domain_sid , const char * user_name ,
2005-03-07 05:12:33 +00:00
uint32_t * rid )
{
2006-05-29 21:59:55 +00:00
const uint16_t level = 5 ;
2005-03-07 05:12:33 +00:00
NTSTATUS status ;
2005-06-11 10:33:31 +00:00
struct libnet_rpc_userinfo user ;
2005-03-07 05:12:33 +00:00
struct dom_sid * user_sid ;
2010-03-23 16:04:30 +01:00
2005-03-07 05:12:33 +00:00
user_sid = dom_sid_add_rid ( mem_ctx , domain_sid , * rid ) ;
2010-03-23 16:04:30 +01:00
2005-03-07 05:12:33 +00:00
user . in . domain_handle = * domain_handle ;
user . in . sid = dom_sid_string ( mem_ctx , user_sid ) ;
2006-05-29 21:59:55 +00:00
user . in . level = level ; /* this should be extended */
2005-03-07 05:12:33 +00:00
2010-03-23 15:31:27 +01:00
torture_comment ( tctx , " Testing sync libnet_rpc_userinfo (SID argument) \n " ) ;
2006-05-29 21:59:55 +00:00
status = libnet_rpc_userinfo ( p , mem_ctx , & user ) ;
2010-05-27 17:24:10 +03:00
torture_assert_ntstatus_ok ( tctx , status , " Calling sync libnet_rpc_userinfo() failed " ) ;
2006-05-29 21:59:55 +00:00
ZERO_STRUCT ( user ) ;
user . in . domain_handle = * domain_handle ;
user . in . sid = NULL ;
2010-05-27 17:10:31 +03:00
user . in . username = user_name ;
2006-05-29 21:59:55 +00:00
user . in . level = level ;
2010-03-23 15:31:27 +01:00
torture_comment ( tctx , " Testing sync libnet_rpc_userinfo (username argument) \n " ) ;
2005-06-11 10:33:31 +00:00
status = libnet_rpc_userinfo ( p , mem_ctx , & user ) ;
2010-05-27 17:24:10 +03:00
torture_assert_ntstatus_ok ( tctx , status , " Calling sync libnet_rpc_userinfo failed " ) ;
2005-03-07 05:12:33 +00:00
2007-10-06 22:28:14 +00:00
return true ;
2005-03-01 23:53:18 +00:00
}
2010-03-23 15:31:27 +01:00
static bool test_userinfo_async ( struct torture_context * tctx ,
struct dcerpc_pipe * p , TALLOC_CTX * mem_ctx ,
2005-05-06 19:36:49 +00:00
struct policy_handle * domain_handle ,
struct dom_sid2 * domain_sid , const char * user_name ,
uint32_t * rid )
{
2006-05-29 21:59:55 +00:00
const uint16_t level = 10 ;
2005-05-06 19:36:49 +00:00
NTSTATUS status ;
struct composite_context * c ;
2005-06-11 10:33:31 +00:00
struct libnet_rpc_userinfo user ;
2005-05-06 19:36:49 +00:00
struct dom_sid * user_sid ;
user_sid = dom_sid_add_rid ( mem_ctx , domain_sid , * rid ) ;
user . in . domain_handle = * domain_handle ;
user . in . sid = dom_sid_string ( mem_ctx , user_sid ) ;
2006-05-29 21:59:55 +00:00
user . in . level = level ; /* this should be extended */
2010-03-23 15:31:27 +01:00
torture_comment ( tctx , " Testing async libnet_rpc_userinfo (SID argument) \n " ) ;
2006-05-29 21:59:55 +00:00
c = libnet_rpc_userinfo_send ( p , & user , msg_handler ) ;
2010-05-27 17:24:10 +03:00
torture_assert ( tctx , c ! = NULL , " Failed to call async libnet_rpc_userinfo_send " ) ;
2006-05-29 21:59:55 +00:00
status = libnet_rpc_userinfo_recv ( c , mem_ctx , & user ) ;
2010-05-27 17:24:10 +03:00
torture_assert_ntstatus_ok ( tctx , status , " Calling async libnet_rpc_userinfo_recv failed " ) ;
2006-05-29 21:59:55 +00:00
ZERO_STRUCT ( user ) ;
user . in . domain_handle = * domain_handle ;
user . in . sid = NULL ;
2010-05-27 17:10:31 +03:00
user . in . username = user_name ;
2006-05-29 21:59:55 +00:00
user . in . level = level ;
2005-05-06 19:36:49 +00:00
2010-03-23 15:31:27 +01:00
torture_comment ( tctx , " Testing async libnet_rpc_userinfo (username argument) \n " ) ;
2005-05-06 19:36:49 +00:00
2005-06-11 10:33:31 +00:00
c = libnet_rpc_userinfo_send ( p , & user , msg_handler ) ;
2010-05-27 17:24:10 +03:00
torture_assert ( tctx , c ! = NULL , " Failed to call async libnet_rpc_userinfo_send " ) ;
2005-05-06 19:36:49 +00:00
2005-06-11 10:33:31 +00:00
status = libnet_rpc_userinfo_recv ( c , mem_ctx , & user ) ;
2010-05-27 17:24:10 +03:00
torture_assert_ntstatus_ok ( tctx , status , " Calling async libnet_rpc_userinfo_recv failed " ) ;
2005-05-06 19:36:49 +00:00
2007-10-06 22:28:14 +00:00
return true ;
2005-05-06 19:36:49 +00:00
}
2007-09-08 16:46:30 +00:00
bool torture_userinfo ( struct torture_context * torture )
2005-03-01 23:53:18 +00:00
{
NTSTATUS status ;
struct dcerpc_pipe * p ;
TALLOC_CTX * mem_ctx ;
2007-10-06 22:28:14 +00:00
bool ret = true ;
2005-03-07 12:27:03 +00:00
struct policy_handle h ;
2005-07-08 08:09:02 +00:00
struct lsa_String name ;
2005-03-07 05:12:33 +00:00
struct dom_sid2 sid ;
uint32_t rid ;
2010-03-15 09:37:42 +01:00
struct dcerpc_binding_handle * b ;
2005-03-01 23:53:18 +00:00
mem_ctx = talloc_init ( " test_userinfo " ) ;
2005-03-04 00:24:21 +00:00
2010-03-23 16:04:30 +01:00
status = torture_rpc_connection ( torture ,
2005-03-22 08:00:45 +00:00
& p ,
2007-08-19 21:23:03 +00:00
& ndr_table_samr ) ;
2010-03-23 16:04:30 +01:00
2005-04-22 15:13:01 +00:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2007-10-06 22:28:14 +00:00
return false ;
2005-04-22 15:13:01 +00:00
}
2010-03-15 09:37:42 +01:00
b = p - > binding_handle ;
2005-03-01 23:53:18 +00:00
2010-07-16 14:32:42 +10:00
name . string = lpcfg_workgroup ( torture - > lp_ctx ) ;
2005-03-04 00:24:21 +00:00
2005-05-06 19:36:49 +00:00
/*
* Testing synchronous version
*/
2010-05-28 05:06:55 +03:00
if ( ! test_domain_open ( torture , b , & name , mem_ctx , & h , & sid ) ) {
2007-10-06 22:28:14 +00:00
ret = false ;
2005-03-07 05:12:33 +00:00
goto done ;
2005-03-01 23:53:18 +00:00
}
2010-03-15 09:37:42 +01:00
if ( ! test_user_create ( torture , b , mem_ctx , & h , TEST_USERNAME , & rid ) ) {
2007-10-06 22:28:14 +00:00
ret = false ;
2005-03-07 05:12:33 +00:00
goto done ;
}
2010-03-23 15:31:27 +01:00
if ( ! test_userinfo ( torture , p , mem_ctx , & h , & sid , TEST_USERNAME , & rid ) ) {
2007-10-06 22:28:14 +00:00
ret = false ;
2005-03-07 05:12:33 +00:00
goto done ;
}
2010-03-15 09:37:42 +01:00
if ( ! test_user_cleanup ( torture , b , mem_ctx , & h , TEST_USERNAME ) ) {
2007-10-06 22:28:14 +00:00
ret = false ;
2005-03-07 05:12:33 +00:00
goto done ;
}
2005-05-06 19:36:49 +00:00
/*
* Testing asynchronous version and monitor messages
*/
2010-05-28 05:06:55 +03:00
if ( ! test_domain_open ( torture , b , & name , mem_ctx , & h , & sid ) ) {
2007-10-06 22:28:14 +00:00
ret = false ;
2005-05-06 19:36:49 +00:00
goto done ;
}
2010-03-15 09:37:42 +01:00
if ( ! test_user_create ( torture , b , mem_ctx , & h , TEST_USERNAME , & rid ) ) {
2007-10-06 22:28:14 +00:00
ret = false ;
2005-05-06 19:36:49 +00:00
goto done ;
}
2010-03-23 15:31:27 +01:00
if ( ! test_userinfo_async ( torture , p , mem_ctx , & h , & sid , TEST_USERNAME , & rid ) ) {
2007-10-06 22:28:14 +00:00
ret = false ;
2005-05-06 19:36:49 +00:00
goto done ;
}
2010-03-15 09:37:42 +01:00
if ( ! test_user_cleanup ( torture , b , mem_ctx , & h , TEST_USERNAME ) ) {
2007-10-06 22:28:14 +00:00
ret = false ;
2005-05-06 19:36:49 +00:00
goto done ;
}
2005-03-04 00:24:21 +00:00
done :
2005-03-01 23:53:18 +00:00
talloc_free ( mem_ctx ) ;
return ret ;
}