2010-03-23 16:04:30 +01:00
/*
2005-06-07 23:41:23 +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-07 23:41:23 +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-07 23:41:23 +00:00
( at your option ) any later version .
2010-03-23 16:04:30 +01:00
2005-06-07 23:41:23 +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-07 23:41:23 +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-07 23:41:23 +00:00
*/
# include "includes.h"
2006-08-09 22:09:47 +00:00
# include "system/time.h"
2005-06-07 23:41:23 +00:00
# include "lib/cmdline/popt_common.h"
# include "libnet/libnet.h"
2006-03-14 23:35:30 +00:00
# include "librpc/gen_ndr/ndr_samr_c.h"
2006-11-06 23:22:57 +00:00
# include "librpc/gen_ndr/ndr_lsa_c.h"
2010-04-13 22:06:51 +02:00
# include "torture/rpc/torture_rpc.h"
2006-09-19 19:15:36 +00:00
# include "torture/libnet/usertest.h"
2010-05-28 05:20:18 +03:00
# include "torture/libnet/proto.h"
2007-09-08 12:42:09 +00:00
# include "param/param.h"
2010-03-23 16:04:30 +01:00
2005-06-07 23:41:23 +00:00
2007-10-06 22:28:14 +00:00
bool torture_createuser ( struct torture_context * torture )
2005-06-07 23:41:23 +00:00
{
NTSTATUS status ;
TALLOC_CTX * mem_ctx ;
2010-06-10 18:23:06 +03:00
struct libnet_context * ctx = NULL ;
2005-06-07 23:41:23 +00:00
struct libnet_CreateUser req ;
2007-10-06 22:28:14 +00:00
bool ret = true ;
2005-06-07 23:41:23 +00:00
mem_ctx = talloc_init ( " test_createuser " ) ;
2010-06-10 18:23:06 +03:00
if ( ! test_libnet_context_init ( torture , true , & ctx ) ) {
return false ;
}
2005-06-07 23:41:23 +00:00
req . in . user_name = TEST_USERNAME ;
2010-07-16 14:32:42 +10:00
req . in . domain_name = lpcfg_workgroup ( torture - > lp_ctx ) ;
2006-05-21 21:25:31 +00:00
req . out . error_string = NULL ;
2005-06-07 23:41:23 +00:00
status = libnet_CreateUser ( ctx , mem_ctx , & req ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
2010-03-23 15:31:27 +01:00
torture_comment ( torture , " libnet_CreateUser call failed: %s \n " , nt_errstr ( status ) ) ;
2007-10-06 22:28:14 +00:00
ret = false ;
2006-09-18 20:08:28 +00:00
goto done ;
2005-06-07 23:41:23 +00:00
}
2010-06-07 18:44:14 +03:00
if ( ! test_user_cleanup ( torture , ctx - > samr . pipe - > binding_handle ,
mem_ctx , & ctx - > samr . handle , TEST_USERNAME ) ) {
2010-03-23 15:31:27 +01:00
torture_comment ( torture , " cleanup failed \n " ) ;
2007-10-06 22:28:14 +00:00
ret = false ;
2006-09-18 20:08:28 +00:00
goto done ;
2005-06-07 23:41:23 +00:00
}
2010-05-28 22:14:39 +03:00
if ( ! test_samr_close_handle ( torture ,
ctx - > samr . pipe - > binding_handle , mem_ctx , & ctx - > samr . handle ) ) {
2010-03-23 15:31:27 +01:00
torture_comment ( torture , " domain close failed \n " ) ;
2007-10-06 22:28:14 +00:00
ret = false ;
2006-09-18 20:08:28 +00:00
}
done :
talloc_free ( ctx ) ;
talloc_free ( mem_ctx ) ;
return ret ;
2005-06-07 23:41:23 +00:00
}
2006-05-17 21:44:06 +00:00
2007-10-06 22:28:14 +00:00
bool torture_deleteuser ( struct torture_context * torture )
2006-05-17 21:44:06 +00:00
{
NTSTATUS status ;
struct dcerpc_pipe * p ;
2010-09-05 23:28:06 +03:00
TALLOC_CTX * mem_ctx ;
2006-05-17 21:44:06 +00:00
struct policy_handle h ;
struct lsa_String domain_name ;
const char * name = TEST_USERNAME ;
2010-06-10 18:23:06 +03:00
struct libnet_context * ctx = NULL ;
2006-05-17 21:44:06 +00:00
struct libnet_DeleteUser req ;
2010-09-05 23:28:06 +03:00
bool ret = false ;
2006-05-17 21:44:06 +00:00
2007-08-28 12:54:27 +00:00
status = torture_rpc_connection ( torture ,
2006-05-17 21:44:06 +00:00
& p ,
2007-08-19 21:23:03 +00:00
& ndr_table_samr ) ;
2010-09-05 23:28:06 +03:00
torture_assert_ntstatus_ok ( torture , status , " torture_rpc_connection() failed " ) ;
mem_ctx = talloc_init ( " torture_deleteuser " ) ;
2006-05-17 21:44:06 +00:00
2010-09-05 23:28:06 +03:00
/*
* Pre - create a user to be deleted later
*/
2010-07-16 14:32:42 +10:00
domain_name . string = lpcfg_workgroup ( torture - > lp_ctx ) ;
2010-09-05 23:28:06 +03:00
ret = test_domain_open ( torture , p - > binding_handle , & domain_name , mem_ctx , & h , NULL ) ;
torture_assert_goto ( torture , ret , ret , done , " test_domain_open() failed " ) ;
2006-05-17 21:44:06 +00:00
2010-09-05 23:28:06 +03:00
ret = test_user_create ( torture , p - > binding_handle , mem_ctx , & h , name , NULL ) ;
torture_assert_goto ( torture , ret , ret , done , " test_user_create() failed " ) ;
2006-05-17 21:44:06 +00:00
2010-09-05 23:28:06 +03:00
/*
* Delete the user using libnet layer
*/
ret = test_libnet_context_init ( torture , true , & ctx ) ;
torture_assert_goto ( torture , ret , ret , done , " test_libnet_context_init() failed " ) ;
2006-05-17 21:44:06 +00:00
2010-09-05 23:28:06 +03:00
req . in . user_name = TEST_USERNAME ;
req . in . domain_name = lpcfg_workgroup ( torture - > lp_ctx ) ;
2010-06-10 18:23:06 +03:00
2006-05-17 21:44:06 +00:00
status = libnet_DeleteUser ( ctx , mem_ctx , & req ) ;
2010-09-05 23:28:06 +03:00
torture_assert_ntstatus_ok_goto ( torture , status , ret , done , " libnet_DeleteUser() failed " ) ;
2006-05-17 21:44:06 +00:00
2010-09-05 23:28:06 +03:00
/* mark test as successful */
ret = true ;
2006-08-30 22:05:59 +00:00
2006-05-17 21:44:06 +00:00
done :
2006-09-18 20:08:28 +00:00
talloc_free ( ctx ) ;
2010-09-05 23:28:06 +03:00
talloc_free ( mem_ctx ) ;
2006-05-17 21:44:06 +00:00
return ret ;
}
2006-06-18 22:26:30 +00:00
2006-08-09 22:09:47 +00:00
/*
Generate testing set of random changes
*/
2010-03-23 15:31:27 +01:00
static void set_test_changes ( struct torture_context * tctx ,
TALLOC_CTX * mem_ctx , struct libnet_ModifyUser * r ,
2006-10-09 07:59:19 +00:00
int num_changes , char * * user_name , enum test_fields req_change )
2006-08-09 22:09:47 +00:00
{
const char * logon_scripts [ ] = { " start_login.cmd " , " login.bat " , " start.cmd " } ;
const char * home_dirs [ ] = { " \\ \\ srv \\ home " , " \\ \\ homesrv \\ home \\ user " , " \\ \\ pdcsrv \\ domain " } ;
const char * home_drives [ ] = { " H: " , " z: " , " I: " , " J: " , " n: " } ;
2008-03-07 09:05:24 +11:00
const uint32_t flags [ ] = { ( ACB_DISABLED | ACB_NORMAL | ACB_PW_EXPIRED ) ,
2008-02-28 10:32:06 +11:00
( ACB_NORMAL | ACB_PWNOEXP ) ,
2008-03-07 09:05:24 +11:00
( ACB_NORMAL | ACB_PW_EXPIRED ) } ;
2006-08-10 20:42:07 +00:00
const char * homedir , * homedrive , * logonscript ;
2006-08-09 22:09:47 +00:00
struct timeval now ;
2006-09-18 20:08:28 +00:00
int i , testfld ;
2006-08-09 22:09:47 +00:00
2010-03-23 15:31:27 +01:00
torture_comment ( tctx , " Fields to change: [ " ) ;
2006-08-09 22:09:47 +00:00
2010-05-22 05:03:16 +03:00
for ( i = 0 ; i < num_changes & & i < = USER_FIELD_LAST ; i + + ) {
2006-08-10 20:42:07 +00:00
const char * fldname ;
2006-09-18 20:08:28 +00:00
2010-05-22 05:03:16 +03:00
testfld = ( req_change = = none ) ? ( random ( ) % USER_FIELD_LAST ) + 1 : req_change ;
2006-08-09 22:09:47 +00:00
2006-08-10 20:42:07 +00:00
/* get one in case we hit time field this time */
2006-08-09 22:09:47 +00:00
gettimeofday ( & now , NULL ) ;
2010-03-23 16:04:30 +01:00
2006-09-18 20:08:28 +00:00
switch ( testfld ) {
2010-05-25 17:24:45 +03:00
case acct_name :
2006-08-10 20:42:07 +00:00
continue_if_field_set ( r - > in . account_name ) ;
r - > in . account_name = talloc_asprintf ( mem_ctx , TEST_CHG_ACCOUNTNAME ,
2006-10-02 06:00:14 +00:00
( int ) ( random ( ) % 100 ) ) ;
2006-08-10 20:42:07 +00:00
fldname = " account_name " ;
2010-03-23 16:04:30 +01:00
2006-09-18 20:08:28 +00:00
/* update the test's user name in case it's about to change */
2006-10-02 06:00:14 +00:00
* user_name = talloc_strdup ( mem_ctx , r - > in . account_name ) ;
2006-08-10 20:42:07 +00:00
break ;
2010-05-25 17:24:45 +03:00
case acct_full_name :
2006-08-10 20:42:07 +00:00
continue_if_field_set ( r - > in . full_name ) ;
r - > in . full_name = talloc_asprintf ( mem_ctx , TEST_CHG_FULLNAME ,
( unsigned int ) random ( ) , ( unsigned int ) random ( ) ) ;
fldname = " full_name " ;
break ;
2010-05-25 17:24:45 +03:00
case acct_description :
2006-08-10 20:42:07 +00:00
continue_if_field_set ( r - > in . description ) ;
r - > in . description = talloc_asprintf ( mem_ctx , TEST_CHG_DESCRIPTION ,
( long ) random ( ) ) ;
fldname = " description " ;
break ;
2010-05-25 17:24:45 +03:00
case acct_home_directory :
2006-08-10 20:42:07 +00:00
continue_if_field_set ( r - > in . home_directory ) ;
2008-02-28 10:32:06 +11:00
homedir = home_dirs [ random ( ) % ARRAY_SIZE ( home_dirs ) ] ;
2006-08-10 20:42:07 +00:00
r - > in . home_directory = talloc_strdup ( mem_ctx , homedir ) ;
fldname = " home_dir " ;
break ;
2010-05-25 17:24:45 +03:00
case acct_home_drive :
2006-08-10 20:42:07 +00:00
continue_if_field_set ( r - > in . home_drive ) ;
2008-02-28 10:32:06 +11:00
homedrive = home_drives [ random ( ) % ARRAY_SIZE ( home_drives ) ] ;
2006-08-10 20:42:07 +00:00
r - > in . home_drive = talloc_strdup ( mem_ctx , homedrive ) ;
fldname = " home_drive " ;
break ;
2010-05-25 17:24:45 +03:00
case acct_comment :
2006-08-10 20:42:07 +00:00
continue_if_field_set ( r - > in . comment ) ;
r - > in . comment = talloc_asprintf ( mem_ctx , TEST_CHG_COMMENT ,
( unsigned long ) random ( ) , ( unsigned long ) random ( ) ) ;
fldname = " comment " ;
break ;
2010-05-25 17:24:45 +03:00
case acct_logon_script :
2006-08-10 20:42:07 +00:00
continue_if_field_set ( r - > in . logon_script ) ;
2008-02-28 10:32:06 +11:00
logonscript = logon_scripts [ random ( ) % ARRAY_SIZE ( logon_scripts ) ] ;
2006-08-10 20:42:07 +00:00
r - > in . logon_script = talloc_strdup ( mem_ctx , logonscript ) ;
fldname = " logon_script " ;
break ;
2010-03-23 16:04:30 +01:00
2010-05-25 17:24:45 +03:00
case acct_profile_path :
2006-08-10 20:42:07 +00:00
continue_if_field_set ( r - > in . profile_path ) ;
r - > in . profile_path = talloc_asprintf ( mem_ctx , TEST_CHG_PROFILEPATH ,
( unsigned long ) random ( ) , ( unsigned int ) random ( ) ) ;
fldname = " profile_path " ;
break ;
case acct_expiry :
continue_if_field_set ( r - > in . acct_expiry ) ;
now = timeval_add ( & now , ( random ( ) % ( 31 * 24 * 60 * 60 ) ) , 0 ) ;
2007-09-08 16:46:30 +00:00
r - > in . acct_expiry = ( struct timeval * ) talloc_memdup ( mem_ctx , & now , sizeof ( now ) ) ;
2006-08-10 20:42:07 +00:00
fldname = " acct_expiry " ;
break ;
2008-02-28 10:32:06 +11:00
case acct_flags :
continue_if_field_set ( r - > in . acct_flags ) ;
r - > in . acct_flags = flags [ random ( ) % ARRAY_SIZE ( flags ) ] ;
fldname = " acct_flags " ;
break ;
2006-08-30 22:05:59 +00:00
default :
fldname = " unknown_field " ;
2006-08-10 20:42:07 +00:00
}
2010-03-23 16:04:30 +01:00
2010-03-23 15:31:27 +01:00
torture_comment ( tctx , ( ( i < num_changes - 1 ) ? " %s, " : " %s " ) , fldname ) ;
2006-09-18 20:08:28 +00:00
/* disable requested field (it's supposed to be the only one used) */
if ( req_change ! = none ) req_change = none ;
2006-08-10 20:42:07 +00:00
}
2010-03-23 15:31:27 +01:00
torture_comment ( tctx , " ] \n " ) ;
2006-08-09 22:09:47 +00:00
}
2006-10-02 06:00:14 +00:00
# define TEST_STR_FLD(fld) \
if ( ! strequal ( req . in . fld , user_req . out . fld ) ) { \
2010-03-23 15:31:27 +01:00
torture_comment ( torture , " failed to change '%s' \n " , # fld ) ; \
2007-10-06 22:28:14 +00:00
ret = false ; \
2006-10-02 06:00:14 +00:00
goto cleanup ; \
}
# define TEST_TIME_FLD(fld) \
if ( timeval_compare ( req . in . fld , user_req . out . fld ) ) { \
2010-03-23 15:31:27 +01:00
torture_comment ( torture , " failed to change '%s' \n " , # fld ) ; \
2007-10-06 22:28:14 +00:00
ret = false ; \
2006-10-02 06:00:14 +00:00
goto cleanup ; \
}
# define TEST_NUM_FLD(fld) \
if ( req . in . fld ! = user_req . out . fld ) { \
2010-03-23 15:31:27 +01:00
torture_comment ( torture , " failed to change '%s' \n " , # fld ) ; \
2007-10-06 22:28:14 +00:00
ret = false ; \
2006-10-02 06:00:14 +00:00
goto cleanup ; \
}
2007-10-06 22:28:14 +00:00
bool torture_modifyuser ( struct torture_context * torture )
2006-06-18 22:26:30 +00:00
{
NTSTATUS status ;
struct dcerpc_pipe * p ;
2007-12-03 02:58:12 +01:00
TALLOC_CTX * prep_mem_ctx ;
2006-06-18 22:26:30 +00:00
struct policy_handle h ;
struct lsa_String domain_name ;
2006-09-18 20:08:28 +00:00
char * name ;
2010-06-10 18:23:06 +03:00
struct libnet_context * ctx = NULL ;
2006-06-18 22:26:30 +00:00
struct libnet_ModifyUser req ;
2006-10-02 06:00:14 +00:00
struct libnet_UserInfo user_req ;
2006-09-19 00:27:49 +00:00
int fld ;
2007-10-06 22:28:14 +00:00
bool ret = true ;
2010-03-11 11:33:10 +01:00
struct dcerpc_binding_handle * b ;
2006-06-18 22:26:30 +00:00
prep_mem_ctx = talloc_init ( " prepare test_deleteuser " ) ;
2007-08-28 12:54:27 +00:00
status = torture_rpc_connection ( torture ,
2006-06-18 22:26:30 +00:00
& p ,
2007-08-19 21:23:03 +00:00
& ndr_table_samr ) ;
2006-06-18 22:26:30 +00:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2007-10-06 22:28:14 +00:00
ret = false ;
2006-09-18 20:08:28 +00:00
goto done ;
2006-06-18 22:26:30 +00:00
}
2010-03-11 11:33:10 +01:00
b = p - > binding_handle ;
2006-06-18 22:26:30 +00:00
2006-09-18 20:08:28 +00:00
name = talloc_strdup ( prep_mem_ctx , TEST_USERNAME ) ;
2010-07-16 14:32:42 +10:00
domain_name . string = lpcfg_workgroup ( torture - > lp_ctx ) ;
2010-05-28 05:20:18 +03:00
if ( ! test_domain_open ( torture , b , & domain_name , prep_mem_ctx , & h , NULL ) ) {
2007-10-06 22:28:14 +00:00
ret = false ;
2006-06-18 22:26:30 +00:00
goto done ;
}
2010-05-28 21:20:03 +03:00
if ( ! test_user_create ( torture , b , prep_mem_ctx , & h , name , NULL ) ) {
2007-10-06 22:28:14 +00:00
ret = false ;
2006-06-18 22:26:30 +00:00
goto done ;
}
2010-03-23 15:31:27 +01:00
torture_comment ( torture , " Testing change of all fields - each single one in turn \n " ) ;
2006-09-19 00:27:49 +00:00
2010-06-10 18:23:06 +03:00
if ( ! test_libnet_context_init ( torture , true , & ctx ) ) {
2010-05-26 04:22:34 +03:00
return false ;
}
2010-05-22 05:03:16 +03:00
for ( fld = USER_FIELD_FIRST ; fld < = USER_FIELD_LAST ; fld + + ) {
2006-09-19 00:27:49 +00:00
ZERO_STRUCT ( req ) ;
2010-07-16 14:32:42 +10:00
req . in . domain_name = lpcfg_workgroup ( torture - > lp_ctx ) ;
2006-09-19 00:27:49 +00:00
req . in . user_name = name ;
2010-03-23 15:31:27 +01:00
set_test_changes ( torture , torture , & req , 1 , & name , fld ) ;
2006-09-19 00:27:49 +00:00
2007-12-03 02:58:12 +01:00
status = libnet_ModifyUser ( ctx , torture , & req ) ;
2006-09-19 00:27:49 +00:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2010-03-23 15:31:27 +01:00
torture_comment ( torture , " libnet_ModifyUser call failed: %s \n " , nt_errstr ( status ) ) ;
2007-10-06 22:28:14 +00:00
ret = false ;
2006-10-02 06:00:14 +00:00
continue ;
}
ZERO_STRUCT ( user_req ) ;
2010-07-16 14:32:42 +10:00
user_req . in . domain_name = lpcfg_workgroup ( torture - > lp_ctx ) ;
2008-04-19 14:09:18 +02:00
user_req . in . data . user_name = name ;
user_req . in . level = USER_INFO_BY_NAME ;
2006-10-02 06:00:14 +00:00
2007-12-03 02:58:12 +01:00
status = libnet_UserInfo ( ctx , torture , & user_req ) ;
2006-10-02 06:00:14 +00:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2010-03-23 15:31:27 +01:00
torture_comment ( torture , " libnet_UserInfo call failed: %s \n " , nt_errstr ( status ) ) ;
2007-10-06 22:28:14 +00:00
ret = false ;
2006-10-02 06:00:14 +00:00
continue ;
}
switch ( fld ) {
2010-05-25 17:24:45 +03:00
case acct_name : TEST_STR_FLD ( account_name ) ;
2006-10-02 06:00:14 +00:00
break ;
2010-05-25 17:24:45 +03:00
case acct_full_name : TEST_STR_FLD ( full_name ) ;
2006-10-02 06:00:14 +00:00
break ;
2010-05-25 17:24:45 +03:00
case acct_comment : TEST_STR_FLD ( comment ) ;
2006-10-02 06:00:14 +00:00
break ;
2010-05-25 17:24:45 +03:00
case acct_description : TEST_STR_FLD ( description ) ;
2006-10-02 06:00:14 +00:00
break ;
2010-05-25 17:24:45 +03:00
case acct_home_directory : TEST_STR_FLD ( home_directory ) ;
2006-10-02 06:00:14 +00:00
break ;
2010-05-25 17:24:45 +03:00
case acct_home_drive : TEST_STR_FLD ( home_drive ) ;
2006-10-02 06:00:14 +00:00
break ;
2010-05-25 17:24:45 +03:00
case acct_logon_script : TEST_STR_FLD ( logon_script ) ;
2006-10-02 06:00:14 +00:00
break ;
2010-05-25 17:24:45 +03:00
case acct_profile_path : TEST_STR_FLD ( profile_path ) ;
2006-10-02 06:00:14 +00:00
break ;
case acct_expiry : TEST_TIME_FLD ( acct_expiry ) ;
break ;
case acct_flags : TEST_NUM_FLD ( acct_flags ) ;
break ;
default :
break ;
2006-09-19 00:27:49 +00:00
}
2006-06-18 22:26:30 +00:00
}
2006-10-02 06:00:14 +00:00
cleanup :
2010-06-07 18:44:14 +03:00
if ( ! test_user_cleanup ( torture , ctx - > samr . pipe - > binding_handle ,
2010-06-11 16:02:10 +03:00
torture , & ctx - > samr . handle , TEST_USERNAME ) ) {
2010-03-23 15:31:27 +01:00
torture_comment ( torture , " cleanup failed \n " ) ;
2007-10-06 22:28:14 +00:00
ret = false ;
2006-09-18 20:08:28 +00:00
goto done ;
}
2010-05-28 22:14:39 +03:00
if ( ! test_samr_close_handle ( torture ,
ctx - > samr . pipe - > binding_handle , torture , & ctx - > samr . handle ) ) {
2010-03-23 15:31:27 +01:00
torture_comment ( torture , " domain close failed \n " ) ;
2007-10-06 22:28:14 +00:00
ret = false ;
2006-06-26 21:21:59 +00:00
}
2006-06-18 22:26:30 +00:00
done :
2006-09-18 20:08:28 +00:00
talloc_free ( ctx ) ;
2006-06-18 22:26:30 +00:00
talloc_free ( prep_mem_ctx ) ;
return ret ;
}
2006-08-27 20:39:50 +00:00
2007-10-06 22:28:14 +00:00
bool torture_userinfo_api ( struct torture_context * torture )
2006-08-27 20:39:50 +00:00
{
const char * name = TEST_USERNAME ;
2007-10-06 22:28:14 +00:00
bool ret = true ;
2006-08-27 20:39:50 +00:00
NTSTATUS status ;
2006-11-06 23:22:57 +00:00
TALLOC_CTX * mem_ctx = NULL , * prep_mem_ctx ;
2010-06-10 18:23:06 +03:00
struct libnet_context * ctx = NULL ;
2006-08-27 20:39:50 +00:00
struct dcerpc_pipe * p ;
struct policy_handle h ;
struct lsa_String domain_name ;
struct libnet_UserInfo req ;
2010-03-11 11:33:10 +01:00
struct dcerpc_binding_handle * b ;
2006-08-27 20:39:50 +00:00
2006-08-30 22:05:59 +00:00
prep_mem_ctx = talloc_init ( " prepare torture user info " ) ;
2006-08-27 20:39:50 +00:00
2007-08-28 12:54:27 +00:00
status = torture_rpc_connection ( torture ,
2006-08-27 20:39:50 +00:00
& p ,
2007-08-19 21:23:03 +00:00
& ndr_table_samr ) ;
2006-08-27 20:39:50 +00:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2007-10-06 22:28:14 +00:00
return false ;
2006-08-27 20:39:50 +00:00
}
2010-03-11 11:33:10 +01:00
b = p - > binding_handle ;
2006-08-27 20:39:50 +00:00
2010-07-16 14:32:42 +10:00
domain_name . string = lpcfg_workgroup ( torture - > lp_ctx ) ;
2010-05-28 05:20:18 +03:00
if ( ! test_domain_open ( torture , b , & domain_name , prep_mem_ctx , & h , NULL ) ) {
2007-10-06 22:28:14 +00:00
ret = false ;
2006-08-27 20:39:50 +00:00
goto done ;
}
2010-05-28 21:20:03 +03:00
if ( ! test_user_create ( torture , b , prep_mem_ctx , & h , name , NULL ) ) {
2007-10-06 22:28:14 +00:00
ret = false ;
2006-08-27 20:39:50 +00:00
goto done ;
}
2006-08-30 22:05:59 +00:00
mem_ctx = talloc_init ( " torture user info " ) ;
2010-06-10 18:23:06 +03:00
if ( ! test_libnet_context_init ( torture , true , & ctx ) ) {
return false ;
}
2006-08-27 20:39:50 +00:00
ZERO_STRUCT ( req ) ;
2010-03-23 16:04:30 +01:00
2006-08-27 20:39:50 +00:00
req . in . domain_name = domain_name . string ;
2008-04-19 14:09:18 +02:00
req . in . data . user_name = name ;
req . in . level = USER_INFO_BY_NAME ;
2006-08-27 20:39:50 +00:00
status = libnet_UserInfo ( ctx , mem_ctx , & req ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
2010-03-23 15:31:27 +01:00
torture_comment ( torture , " libnet_UserInfo call failed: %s \n " , nt_errstr ( status ) ) ;
2007-10-06 22:28:14 +00:00
ret = false ;
2006-08-30 22:05:59 +00:00
goto done ;
2006-08-27 20:39:50 +00:00
}
2010-06-07 18:44:14 +03:00
if ( ! test_user_cleanup ( torture , ctx - > samr . pipe - > binding_handle ,
mem_ctx , & ctx - > samr . handle , TEST_USERNAME ) ) {
2010-03-23 15:31:27 +01:00
torture_comment ( torture , " cleanup failed \n " ) ;
2007-10-06 22:28:14 +00:00
ret = false ;
2006-09-18 20:08:28 +00:00
goto done ;
}
2010-05-28 22:14:39 +03:00
if ( ! test_samr_close_handle ( torture ,
ctx - > samr . pipe - > binding_handle , mem_ctx , & ctx - > samr . handle ) ) {
2010-03-23 15:31:27 +01:00
torture_comment ( torture , " domain close failed \n " ) ;
2007-10-06 22:28:14 +00:00
ret = false ;
2006-11-06 23:22:57 +00:00
}
done :
2010-06-10 18:23:06 +03:00
talloc_free ( ctx ) ;
2006-11-06 23:22:57 +00:00
talloc_free ( mem_ctx ) ;
return ret ;
}
2007-10-06 22:28:14 +00:00
bool torture_userlist ( struct torture_context * torture )
2006-11-06 23:22:57 +00:00
{
2007-10-06 22:28:14 +00:00
bool ret = true ;
2006-11-06 23:22:57 +00:00
NTSTATUS status ;
TALLOC_CTX * mem_ctx = NULL ;
struct libnet_context * ctx ;
struct lsa_String domain_name ;
struct libnet_UserList req ;
2006-11-27 23:48:19 +00:00
int i ;
2006-11-06 23:22:57 +00:00
2008-04-14 12:43:37 -04:00
ctx = libnet_context_init ( torture - > ev , torture - > lp_ctx ) ;
2017-05-09 16:10:03 -07:00
ctx - > cred = popt_get_cmdline_credentials ( ) ;
2006-11-06 23:22:57 +00:00
2010-07-16 14:32:42 +10:00
domain_name . string = lpcfg_workgroup ( torture - > lp_ctx ) ;
2006-11-06 23:22:57 +00:00
mem_ctx = talloc_init ( " torture user list " ) ;
ZERO_STRUCT ( req ) ;
2006-11-27 23:48:19 +00:00
2010-03-23 15:31:27 +01:00
torture_comment ( torture , " listing user accounts: \n " ) ;
2010-03-23 16:04:30 +01:00
2006-11-27 22:40:53 +00:00
do {
2006-11-06 23:22:57 +00:00
2006-11-27 22:40:53 +00:00
req . in . domain_name = domain_name . string ;
req . in . page_size = 128 ;
req . in . resume_index = req . out . resume_index ;
status = libnet_UserList ( ctx , mem_ctx , & req ) ;
2007-12-19 00:45:07 +01:00
if ( ! NT_STATUS_IS_OK ( status ) & &
! NT_STATUS_EQUAL ( status , STATUS_MORE_ENTRIES ) ) break ;
2006-11-27 22:40:53 +00:00
2006-11-27 23:48:19 +00:00
for ( i = 0 ; i < req . out . count ; i + + ) {
2010-03-23 15:31:27 +01:00
torture_comment ( torture , " \t user: %s, sid=%s \n " ,
2010-06-11 16:02:10 +03:00
req . out . users [ i ] . username , req . out . users [ i ] . sid ) ;
2006-11-27 23:48:19 +00:00
}
2006-11-27 22:40:53 +00:00
} while ( NT_STATUS_EQUAL ( status , STATUS_MORE_ENTRIES ) ) ;
if ( ! ( NT_STATUS_IS_OK ( status ) | |
NT_STATUS_EQUAL ( status , NT_STATUS_NO_MORE_ENTRIES ) ) ) {
2010-03-23 15:31:27 +01:00
torture_comment ( torture , " libnet_UserList call failed: %s \n " , nt_errstr ( status ) ) ;
2007-10-06 22:28:14 +00:00
ret = false ;
2006-11-06 23:22:57 +00:00
goto done ;
}
2010-05-28 22:14:39 +03:00
if ( ! test_samr_close_handle ( torture ,
ctx - > samr . pipe - > binding_handle , mem_ctx , & ctx - > samr . handle ) ) {
2010-03-23 15:31:27 +01:00
torture_comment ( torture , " samr domain close failed \n " ) ;
2007-10-06 22:28:14 +00:00
ret = false ;
2006-11-27 22:40:53 +00:00
goto done ;
}
2010-06-11 15:11:01 +03:00
if ( ! test_lsa_close_handle ( torture ,
ctx - > lsa . pipe - > binding_handle , mem_ctx , & ctx - > lsa . handle ) ) {
2010-03-23 15:31:27 +01:00
torture_comment ( torture , " lsa domain close failed \n " ) ;
2007-10-06 22:28:14 +00:00
ret = false ;
2006-08-27 20:39:50 +00:00
}
talloc_free ( ctx ) ;
2006-08-30 22:05:59 +00:00
done :
2006-08-27 20:39:50 +00:00
talloc_free ( mem_ctx ) ;
return ret ;
}