2005-03-01 23:53:18 +00: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 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 .
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/>.
2005-03-01 23:53:18 +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-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"
2007-09-27 15:51:07 +00:00
# include "torture/libnet/utils.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
2007-10-06 22:28:14 +00:00
static bool test_userinfo ( 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 ;
2005-05-06 19:36:49 +00:00
2005-03-07 05:12:33 +00:00
user_sid = dom_sid_add_rid ( mem_ctx , domain_sid , * rid ) ;
2005-05-06 19:36:49 +00: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
2006-05-29 21:59:55 +00:00
printf ( " Testing sync libnet_rpc_userinfo (SID argument) \n " ) ;
status = libnet_rpc_userinfo ( p , mem_ctx , & user ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " Failed to call sync libnet_rpc_userinfo - %s \n " , nt_errstr ( status ) ) ;
2007-10-06 22:28:14 +00:00
return false ;
2006-05-29 21:59:55 +00:00
}
ZERO_STRUCT ( user ) ;
user . in . domain_handle = * domain_handle ;
user . in . sid = NULL ;
user . in . username = TEST_USERNAME ;
user . in . level = level ;
printf ( " Testing sync libnet_rpc_userinfo (username argument) \n " ) ;
2005-06-11 10:33:31 +00:00
status = libnet_rpc_userinfo ( p , mem_ctx , & user ) ;
2005-03-07 05:12:33 +00:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2005-06-11 10:33:31 +00:00
printf ( " Failed to call sync libnet_rpc_userinfo - %s \n " , nt_errstr ( status ) ) ;
2007-10-06 22:28:14 +00:00
return false ;
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
}
2007-10-06 22:28:14 +00:00
static bool test_userinfo_async ( 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 */
printf ( " Testing async libnet_rpc_userinfo (SID argument) \n " ) ;
c = libnet_rpc_userinfo_send ( p , & user , msg_handler ) ;
if ( ! c ) {
printf ( " Failed to call sync libnet_rpc_userinfo_send \n " ) ;
2007-10-06 22:28:14 +00:00
return false ;
2006-05-29 21:59:55 +00:00
}
status = libnet_rpc_userinfo_recv ( c , mem_ctx , & user ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " Calling async libnet_rpc_userinfo failed - %s \n " , nt_errstr ( status ) ) ;
2007-10-06 22:28:14 +00:00
return false ;
2006-05-29 21:59:55 +00:00
}
ZERO_STRUCT ( user ) ;
user . in . domain_handle = * domain_handle ;
user . in . sid = NULL ;
user . in . username = TEST_USERNAME ;
user . in . level = level ;
2005-05-06 19:36:49 +00:00
2006-05-29 21:59:55 +00:00
printf ( " 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 ) ;
2005-05-06 19:36:49 +00:00
if ( ! c ) {
2005-06-11 10:33:31 +00:00
printf ( " Failed to call sync libnet_rpc_userinfo_send \n " ) ;
2007-10-06 22:28:14 +00:00
return false ;
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 ) ;
2005-05-06 19:36:49 +00:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2005-06-11 10:33:31 +00:00
printf ( " Calling async libnet_rpc_userinfo failed - %s \n " , nt_errstr ( status ) ) ;
2007-10-06 22:28:14 +00:00
return false ;
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
2007-08-28 12:54:27 +00: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 ) ;
2005-03-01 23:53:18 +00: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
2007-12-03 00:28:22 +01:00
name . string = lp_workgroup ( torture - > lp_ctx ) ;
2005-03-04 00:24:21 +00:00
2005-05-06 19:36:49 +00:00
/*
* Testing synchronous version
*/
2010-03-15 09:37:42 +01:00
if ( ! test_opendomain ( torture , b , mem_ctx , & h , & name , & 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 ;
}
if ( ! test_userinfo ( 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-03-15 09:37:42 +01:00
if ( ! test_opendomain ( torture , b , mem_ctx , & h , & name , & 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 ;
}
if ( ! test_userinfo_async ( 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 ;
}