2005-05-19 19:45:25 +04:00
/*
Unix SMB / CIFS implementation .
test suite for unixinfo rpc operations
Copyright ( C ) Volker Lendecke 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-05-19 19:45:25 +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-05-19 19:45:25 +04:00
*/
# include "includes.h"
2010-04-14 00:06:51 +04:00
# include "torture/rpc/torture_rpc.h"
2006-03-15 02:35:30 +03:00
# include "librpc/gen_ndr/ndr_unixinfo_c.h"
2006-09-11 20:54:54 +04:00
# include "libcli/security/security.h"
2005-05-19 19:45:25 +04:00
2006-11-22 21:06:08 +03:00
/**
2006-09-11 20:54:54 +04:00
test the SidToUid interface
*/
2007-04-12 15:59:38 +04:00
static bool test_sidtouid ( struct torture_context * tctx , struct dcerpc_pipe * p )
2006-09-11 20:54:54 +04:00
{
struct unixinfo_SidToUid r ;
struct dom_sid * sid ;
2007-04-12 19:06:24 +04:00
uint64_t uid ;
2010-03-12 13:25:01 +03:00
struct dcerpc_binding_handle * b = p - > binding_handle ;
2006-09-11 20:54:54 +04:00
2007-04-12 15:59:38 +04:00
sid = dom_sid_parse_talloc ( tctx , " S-1-5-32-1234-5432 " ) ;
2006-09-11 20:54:54 +04:00
r . in . sid = * sid ;
2007-04-12 19:06:24 +04:00
r . out . uid = & uid ;
2006-09-11 20:54:54 +04:00
2010-03-19 02:21:01 +03:00
torture_assert_ntstatus_ok ( tctx , dcerpc_unixinfo_SidToUid_r ( b , tctx , & r ) ,
" SidToUid failed " ) ;
if ( NT_STATUS_EQUAL ( NT_STATUS_NONE_MAPPED , r . out . result ) ) {
} else torture_assert_ntstatus_ok ( tctx , r . out . result , " SidToUid failed " ) ;
2006-09-11 20:54:54 +04:00
2007-10-07 02:28:14 +04:00
return true ;
2006-09-11 20:54:54 +04:00
}
2005-05-19 19:45:25 +04:00
/*
test the UidToSid interface
*/
2007-04-12 15:59:38 +04:00
static bool test_uidtosid ( struct torture_context * tctx , struct dcerpc_pipe * p )
2005-05-19 19:45:25 +04:00
{
struct unixinfo_UidToSid r ;
2006-11-22 21:06:08 +03:00
struct dom_sid sid ;
2010-03-12 13:25:01 +03:00
struct dcerpc_binding_handle * b = p - > binding_handle ;
2005-05-19 19:45:25 +04:00
r . in . uid = 1000 ;
2006-11-22 21:06:08 +03:00
r . out . sid = & sid ;
2005-05-19 19:45:25 +04:00
2010-03-12 13:25:01 +03:00
torture_assert_ntstatus_ok ( tctx , dcerpc_unixinfo_UidToSid_r ( b , tctx , & r ) ,
2007-04-12 15:59:38 +04:00
" UidToSid failed " ) ;
2010-03-19 02:21:01 +03:00
torture_assert_ntstatus_ok ( tctx , r . out . result , " UidToSid failed " ) ;
2006-10-16 17:06:41 +04:00
return true ;
2005-05-19 19:45:25 +04:00
}
2006-10-16 17:06:41 +04:00
static bool test_getpwuid ( struct torture_context * tctx ,
2007-04-12 15:59:38 +04:00
struct dcerpc_pipe * p )
2005-05-19 19:45:25 +04:00
{
uint64_t uids [ 512 ] ;
2006-05-08 01:56:26 +04:00
uint32_t num_uids = ARRAY_SIZE ( uids ) ;
uint32_t i ;
2005-05-19 19:45:25 +04:00
struct unixinfo_GetPWUid r ;
2010-03-12 13:25:01 +03:00
struct dcerpc_binding_handle * b = p - > binding_handle ;
2005-05-19 19:45:25 +04:00
for ( i = 0 ; i < num_uids ; i + + ) {
uids [ i ] = i ;
}
2006-05-08 01:56:26 +04:00
r . in . count = & num_uids ;
2005-05-19 19:45:25 +04:00
r . in . uids = uids ;
2006-09-11 19:43:31 +04:00
r . out . count = & num_uids ;
2006-10-16 17:06:41 +04:00
r . out . infos = talloc_array ( tctx , struct unixinfo_GetPWUidInfo , num_uids ) ;
2005-05-19 19:45:25 +04:00
2010-03-19 02:21:01 +03:00
torture_assert_ntstatus_ok ( tctx , dcerpc_unixinfo_GetPWUid_r ( b , tctx , & r ) ,
" GetPWUid failed " ) ;
2005-05-19 19:45:25 +04:00
2010-03-19 02:21:01 +03:00
torture_assert_ntstatus_ok ( tctx , r . out . result , " GetPWUid failed " ) ;
2006-10-16 17:06:41 +04:00
return true ;
2005-05-19 19:45:25 +04:00
}
2006-09-11 20:54:54 +04:00
/*
test the SidToGid interface
*/
2007-04-12 15:59:38 +04:00
static bool test_sidtogid ( struct torture_context * tctx , struct dcerpc_pipe * p )
2006-09-11 20:54:54 +04:00
{
struct unixinfo_SidToGid r ;
struct dom_sid * sid ;
2007-04-12 19:06:24 +04:00
uint64_t gid ;
2010-03-12 13:25:01 +03:00
struct dcerpc_binding_handle * b = p - > binding_handle ;
2007-04-12 15:59:38 +04:00
sid = dom_sid_parse_talloc ( tctx , " S-1-5-32-1234-5432 " ) ;
2006-09-11 20:54:54 +04:00
r . in . sid = * sid ;
2007-04-12 19:06:24 +04:00
r . out . gid = & gid ;
2006-09-11 20:54:54 +04:00
2010-03-19 02:21:01 +03:00
torture_assert_ntstatus_ok ( tctx , dcerpc_unixinfo_SidToGid_r ( b , tctx , & r ) ,
" SidToGid failed " ) ;
if ( NT_STATUS_EQUAL ( NT_STATUS_NONE_MAPPED , r . out . result ) ) {
} else torture_assert_ntstatus_ok ( tctx , r . out . result , " SidToGid failed " ) ;
2006-09-11 20:54:54 +04:00
2007-04-12 15:59:38 +04:00
return true ;
2006-09-11 20:54:54 +04:00
}
2006-09-11 20:45:34 +04:00
/*
test the GidToSid interface
*/
2007-04-12 15:59:38 +04:00
static bool test_gidtosid ( struct torture_context * tctx , struct dcerpc_pipe * p )
2006-09-11 20:45:34 +04:00
{
struct unixinfo_GidToSid r ;
2006-11-22 21:06:08 +03:00
struct dom_sid sid ;
2010-03-12 13:25:01 +03:00
struct dcerpc_binding_handle * b = p - > binding_handle ;
2006-09-11 20:45:34 +04:00
r . in . gid = 1000 ;
2006-11-22 21:06:08 +03:00
r . out . sid = & sid ;
2006-09-11 20:45:34 +04:00
2010-03-12 13:25:01 +03:00
torture_assert_ntstatus_ok ( tctx , dcerpc_unixinfo_GidToSid_r ( b , tctx , & r ) ,
2007-04-12 15:59:38 +04:00
" GidToSid failed " ) ;
2010-03-19 02:21:01 +03:00
torture_assert_ntstatus_ok ( tctx , r . out . result , " GidToSid failed " ) ;
2006-09-11 20:45:34 +04:00
2006-10-16 17:06:41 +04:00
return true ;
2006-09-11 20:45:34 +04:00
}
2007-09-01 02:34:52 +04:00
struct torture_suite * torture_rpc_unixinfo ( TALLOC_CTX * mem_ctx )
2005-05-19 19:45:25 +04:00
{
2006-10-16 17:06:41 +04:00
struct torture_suite * suite ;
2007-08-28 20:24:18 +04:00
struct torture_rpc_tcase * tcase ;
2005-05-19 19:45:25 +04:00
2010-12-11 05:26:31 +03:00
suite = torture_suite_create ( mem_ctx , " unixinfo " ) ;
2006-10-16 17:06:41 +04:00
tcase = torture_suite_add_rpc_iface_tcase ( suite , " unixinfo " ,
2007-08-20 01:23:03 +04:00
& ndr_table_unixinfo ) ;
2005-05-19 19:45:25 +04:00
2007-04-12 15:59:38 +04:00
torture_rpc_tcase_add_test ( tcase , " sidtouid " , test_sidtouid ) ;
2006-10-16 17:06:41 +04:00
torture_rpc_tcase_add_test ( tcase , " uidtosid " , test_uidtosid ) ;
torture_rpc_tcase_add_test ( tcase , " getpwuid " , test_getpwuid ) ;
2007-04-12 15:59:38 +04:00
torture_rpc_tcase_add_test ( tcase , " sidtogid " , test_sidtogid ) ;
2006-10-16 17:06:41 +04:00
torture_rpc_tcase_add_test ( tcase , " gidtosid " , test_gidtosid ) ;
2005-05-19 19:45:25 +04:00
2006-10-16 17:06:41 +04:00
return suite ;
2005-05-19 19:45:25 +04:00
}