2007-12-11 12:48:33 +03:00
/*
Unix SMB / CIFS implementation .
test suite for spoolss rpc operations as performed by various win versions
Copyright ( C ) Kai Blin 2007
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
the Free Software Foundation ; either version 3 of the License , or
( 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
along with this program . If not , see < http : //www.gnu.org/licenses/>.
*/
# include "includes.h"
2010-04-14 00:06:51 +04:00
# include "torture/rpc/torture_rpc.h"
2007-12-11 12:48:33 +03:00
# include "librpc/gen_ndr/ndr_spoolss_c.h"
2009-11-23 15:35:32 +03:00
# include "librpc/gen_ndr/ndr_misc.h"
# include "param/param.h"
2007-12-11 12:48:33 +03:00
struct test_spoolss_win_context {
/* EnumPrinters */
uint32_t printer_count ;
union spoolss_PrinterInfo * printer_info ;
union spoolss_PrinterInfo * current_info ;
/* EnumPrinterKeys */
2009-03-18 05:00:37 +03:00
const char * * printer_keys ;
2009-04-08 15:49:14 +04:00
bool printer_has_driver ;
2007-12-11 12:48:33 +03:00
} ;
/* This is a convenience function for all OpenPrinterEx calls */
static bool test_OpenPrinterEx ( struct torture_context * tctx ,
2010-03-12 13:09:00 +03:00
struct dcerpc_binding_handle * b ,
2007-12-11 12:48:33 +03:00
struct policy_handle * handle ,
const char * printer_name ,
uint32_t access_mask )
{
NTSTATUS status ;
struct spoolss_OpenPrinterEx op ;
struct spoolss_UserLevel1 ul_1 ;
torture_comment ( tctx , " Opening printer '%s' \n " , printer_name ) ;
op . in . printername = talloc_strdup ( tctx , printer_name ) ;
op . in . datatype = NULL ;
op . in . devmode_ctr . devmode = NULL ;
op . in . access_mask = access_mask ;
2013-01-14 20:26:31 +04:00
op . in . userlevel_ctr . level = 1 ;
op . in . userlevel_ctr . user_info . level1 = & ul_1 ;
2007-12-11 12:48:33 +03:00
op . out . handle = handle ;
ul_1 . size = 1234 ;
ul_1 . client = " \\ clientname " ;
ul_1 . user = " username " ;
ul_1 . build = 1 ;
ul_1 . major = 2 ;
ul_1 . minor = 3 ;
ul_1 . processor = 4567 ;
2010-03-12 13:09:00 +03:00
status = dcerpc_spoolss_OpenPrinterEx_r ( b , tctx , & op ) ;
2007-12-11 12:48:33 +03:00
torture_assert_ntstatus_ok ( tctx , status , " OpenPrinterEx failed " ) ;
torture_assert_werr_ok ( tctx , op . out . result , " OpenPrinterEx failed " ) ;
return true ;
}
static bool test_OpenPrinterAsAdmin ( struct torture_context * tctx ,
2010-03-12 13:09:00 +03:00
struct dcerpc_binding_handle * b ,
2007-12-11 12:48:33 +03:00
const char * printername )
{
NTSTATUS status ;
struct spoolss_OpenPrinterEx op ;
struct spoolss_ClosePrinter cp ;
struct spoolss_UserLevel1 ul_1 ;
struct policy_handle handle ;
ul_1 . size = 1234 ;
ul_1 . client = " \\ clientname " ;
ul_1 . user = " username " ;
ul_1 . build = 1 ;
ul_1 . major = 2 ;
ul_1 . minor = 3 ;
ul_1 . processor = 4567 ;
op . in . printername = talloc_strdup ( tctx , printername ) ;
op . in . datatype = NULL ;
op . in . devmode_ctr . devmode = NULL ;
op . in . access_mask = SERVER_ALL_ACCESS ;
2013-01-14 20:26:31 +04:00
op . in . userlevel_ctr . level = 1 ;
op . in . userlevel_ctr . user_info . level1 = & ul_1 ;
2007-12-11 12:48:33 +03:00
op . out . handle = & handle ;
cp . in . handle = & handle ;
cp . out . handle = & handle ;
torture_comment ( tctx , " Testing OpenPrinterEx(%s) with admin rights \n " ,
op . in . printername ) ;
2010-03-12 13:09:00 +03:00
status = dcerpc_spoolss_OpenPrinterEx_r ( b , tctx , & op ) ;
2007-12-11 12:48:33 +03:00
if ( NT_STATUS_IS_OK ( status ) & & W_ERROR_IS_OK ( op . out . result ) ) {
2010-03-12 13:09:00 +03:00
status = dcerpc_spoolss_ClosePrinter_r ( b , tctx , & cp ) ;
2007-12-11 12:48:33 +03:00
torture_assert_ntstatus_ok ( tctx , status , " ClosePrinter failed " ) ;
}
return true ;
}
/* This replicates the opening sequence of OpenPrinterEx calls XP does */
static bool test_OpenPrinterSequence ( struct torture_context * tctx ,
struct dcerpc_pipe * p ,
struct policy_handle * handle )
{
bool ret ;
char * printername = talloc_asprintf ( tctx , " \\ \\ %s " ,
dcerpc_server_name ( p ) ) ;
2010-03-12 13:09:00 +03:00
struct dcerpc_binding_handle * b = p - > binding_handle ;
2007-12-11 12:48:33 +03:00
/* First, see if we can open the printer read_only */
2010-03-12 13:09:00 +03:00
ret = test_OpenPrinterEx ( tctx , b , handle , printername , 0 ) ;
2007-12-11 12:48:33 +03:00
torture_assert ( tctx , ret = = true , " OpenPrinterEx failed. " ) ;
2010-03-12 13:09:00 +03:00
ret = test_ClosePrinter ( tctx , b , handle ) ;
2007-12-11 12:48:33 +03:00
torture_assert ( tctx , ret , " ClosePrinter failed " ) ;
/* Now let's see if we have admin rights to it. */
2010-03-12 13:09:00 +03:00
ret = test_OpenPrinterAsAdmin ( tctx , b , printername ) ;
2007-12-11 12:48:33 +03:00
torture_assert ( tctx , ret = = true ,
" OpenPrinterEx as admin failed unexpectedly. " ) ;
2010-03-12 13:09:00 +03:00
ret = test_OpenPrinterEx ( tctx , b , handle , printername , SERVER_EXECUTE ) ;
2007-12-11 12:48:33 +03:00
torture_assert ( tctx , ret = = true , " OpenPrinterEx failed. " ) ;
return true ;
}
static bool test_GetPrinterData ( struct torture_context * tctx ,
2010-03-12 13:09:00 +03:00
struct dcerpc_binding_handle * b ,
2007-12-11 12:48:33 +03:00
struct policy_handle * handle ,
const char * value_name ,
WERROR expected_werr ,
uint32_t expected_value )
{
NTSTATUS status ;
struct spoolss_GetPrinterData gpd ;
2009-02-06 19:09:30 +03:00
uint32_t needed ;
2009-03-16 18:01:10 +03:00
enum winreg_Type type ;
2010-03-05 22:32:16 +03:00
uint8_t * data = talloc_zero_array ( tctx , uint8_t , 4 ) ;
2007-12-11 12:48:33 +03:00
torture_comment ( tctx , " Testing GetPrinterData(%s). \n " , value_name ) ;
gpd . in . handle = handle ;
gpd . in . value_name = value_name ;
gpd . in . offered = 4 ;
2009-02-06 19:09:30 +03:00
gpd . out . needed = & needed ;
2009-02-06 20:32:24 +03:00
gpd . out . type = & type ;
2010-03-05 22:32:16 +03:00
gpd . out . data = data ;
2007-12-11 12:48:33 +03:00
2010-03-12 13:09:00 +03:00
status = dcerpc_spoolss_GetPrinterData_r ( b , tctx , & gpd ) ;
2007-12-11 12:48:33 +03:00
torture_assert_ntstatus_ok ( tctx , status , " GetPrinterData failed. " ) ;
torture_assert_werr_equal ( tctx , gpd . out . result , expected_werr ,
" GetPrinterData did not return expected error value. " ) ;
if ( W_ERROR_IS_OK ( expected_werr ) ) {
2010-03-05 22:32:16 +03:00
uint32_t value = IVAL ( data , 0 ) ;
torture_assert_int_equal ( tctx , value ,
2007-12-11 12:48:33 +03:00
expected_value ,
2009-11-23 15:35:32 +03:00
talloc_asprintf ( tctx , " GetPrinterData for %s did not return expected value. " , value_name ) ) ;
2007-12-11 12:48:33 +03:00
}
return true ;
}
static bool test_EnumPrinters ( struct torture_context * tctx ,
struct dcerpc_pipe * p ,
struct test_spoolss_win_context * ctx ,
uint32_t initial_blob_size )
{
NTSTATUS status ;
struct spoolss_EnumPrinters ep ;
DATA_BLOB blob = data_blob_talloc_zero ( ctx , initial_blob_size ) ;
2009-02-06 19:09:30 +03:00
uint32_t needed ;
2009-02-16 18:42:21 +03:00
uint32_t count ;
2009-03-02 19:58:13 +03:00
union spoolss_PrinterInfo * info ;
2010-03-12 13:09:00 +03:00
struct dcerpc_binding_handle * b = p - > binding_handle ;
2007-12-11 12:48:33 +03:00
ep . in . flags = PRINTER_ENUM_NAME ;
ep . in . server = talloc_asprintf ( tctx , " \\ \\ %s " , dcerpc_server_name ( p ) ) ;
ep . in . level = 2 ;
ep . in . buffer = & blob ;
ep . in . offered = initial_blob_size ;
2009-02-06 19:09:30 +03:00
ep . out . needed = & needed ;
2009-02-16 18:42:21 +03:00
ep . out . count = & count ;
2009-03-02 19:58:13 +03:00
ep . out . info = & info ;
2007-12-11 12:48:33 +03:00
2010-03-12 13:09:00 +03:00
status = dcerpc_spoolss_EnumPrinters_r ( b , ctx , & ep ) ;
2007-12-11 12:48:33 +03:00
torture_assert_ntstatus_ok ( tctx , status , " EnumPrinters failed. " ) ;
if ( W_ERROR_EQUAL ( ep . out . result , WERR_INSUFFICIENT_BUFFER ) ) {
2009-02-06 19:09:30 +03:00
blob = data_blob_talloc_zero ( ctx , needed ) ;
2007-12-11 12:48:33 +03:00
ep . in . buffer = & blob ;
2009-02-06 19:09:30 +03:00
ep . in . offered = needed ;
2010-03-12 13:09:00 +03:00
status = dcerpc_spoolss_EnumPrinters_r ( b , ctx , & ep ) ;
2007-12-11 12:48:33 +03:00
torture_assert_ntstatus_ok ( tctx , status , " EnumPrinters failed. " ) ;
}
torture_assert_werr_ok ( tctx , ep . out . result , " EnumPrinters failed. " ) ;
2009-02-16 18:42:21 +03:00
ctx - > printer_count = count ;
2009-03-02 19:58:13 +03:00
ctx - > printer_info = info ;
2007-12-11 12:48:33 +03:00
torture_comment ( tctx , " Found %d printer(s). \n " , ctx - > printer_count ) ;
return true ;
}
static bool test_GetPrinter ( struct torture_context * tctx ,
2010-03-12 13:09:00 +03:00
struct dcerpc_binding_handle * b ,
2007-12-11 12:48:33 +03:00
struct policy_handle * handle ,
struct test_spoolss_win_context * ctx ,
uint32_t level ,
uint32_t initial_blob_size )
{
NTSTATUS status ;
struct spoolss_GetPrinter gp ;
DATA_BLOB blob = data_blob_talloc_zero ( ctx , initial_blob_size ) ;
2009-02-06 14:25:47 +03:00
uint32_t needed ;
2007-12-11 12:48:33 +03:00
torture_comment ( tctx , " Test GetPrinter level %d \n " , level ) ;
gp . in . handle = handle ;
gp . in . level = level ;
gp . in . buffer = ( initial_blob_size = = 0 ) ? NULL : & blob ;
gp . in . offered = initial_blob_size ;
2009-02-06 14:25:47 +03:00
gp . out . needed = & needed ;
2007-12-11 12:48:33 +03:00
2010-03-12 13:09:00 +03:00
status = dcerpc_spoolss_GetPrinter_r ( b , tctx , & gp ) ;
2007-12-11 12:48:33 +03:00
torture_assert_ntstatus_ok ( tctx , status , " GetPrinter failed " ) ;
if ( W_ERROR_EQUAL ( gp . out . result , WERR_INSUFFICIENT_BUFFER ) ) {
2009-02-06 14:25:47 +03:00
blob = data_blob_talloc_zero ( ctx , needed ) ;
2007-12-11 12:48:33 +03:00
gp . in . buffer = & blob ;
2009-02-06 14:25:47 +03:00
gp . in . offered = needed ;
2010-03-12 13:09:00 +03:00
status = dcerpc_spoolss_GetPrinter_r ( b , tctx , & gp ) ;
2007-12-11 12:48:33 +03:00
torture_assert_ntstatus_ok ( tctx , status , " GetPrinter failed " ) ;
}
torture_assert_werr_ok ( tctx , gp . out . result , " GetPrinter failed " ) ;
ctx - > current_info = gp . out . info ;
2009-04-08 15:49:14 +04:00
if ( level = = 2 & & gp . out . info ) {
ctx - > printer_has_driver = gp . out . info - > info2 . drivername & &
strlen ( gp . out . info - > info2 . drivername ) ;
}
2007-12-11 12:48:33 +03:00
return true ;
}
static bool test_EnumJobs ( struct torture_context * tctx ,
2010-03-12 13:09:00 +03:00
struct dcerpc_binding_handle * b ,
2007-12-11 12:48:33 +03:00
struct policy_handle * handle )
{
NTSTATUS status ;
struct spoolss_EnumJobs ej ;
DATA_BLOB blob = data_blob_talloc_zero ( tctx , 1024 ) ;
2009-02-07 04:33:48 +03:00
uint32_t needed ;
2009-02-16 18:42:21 +03:00
uint32_t count ;
2009-03-02 19:58:13 +03:00
union spoolss_JobInfo * info ;
2007-12-11 12:48:33 +03:00
torture_comment ( tctx , " Test EnumJobs \n " ) ;
2013-09-18 15:10:20 +04:00
ZERO_STRUCT ( ej ) ;
2007-12-11 12:48:33 +03:00
ej . in . handle = handle ;
2013-09-18 15:10:20 +04:00
ej . in . firstjob = 0 ;
ej . in . numjobs = 0 ;
2007-12-11 12:48:33 +03:00
ej . in . level = 2 ;
ej . in . buffer = & blob ;
ej . in . offered = 1024 ;
2009-02-07 04:33:48 +03:00
ej . out . needed = & needed ;
2009-02-16 18:42:21 +03:00
ej . out . count = & count ;
2009-03-02 19:58:13 +03:00
ej . out . info = & info ;
2007-12-11 12:48:33 +03:00
2010-03-12 13:09:00 +03:00
status = dcerpc_spoolss_EnumJobs_r ( b , tctx , & ej ) ;
2007-12-11 12:48:33 +03:00
torture_assert_ntstatus_ok ( tctx , status , " EnumJobs failed " ) ;
2009-04-17 19:14:20 +04:00
if ( W_ERROR_EQUAL ( ej . out . result , WERR_INSUFFICIENT_BUFFER ) ) {
blob = data_blob_talloc_zero ( tctx , needed ) ;
ej . in . offered = needed ;
ej . in . buffer = & blob ;
2010-03-12 13:09:00 +03:00
status = dcerpc_spoolss_EnumJobs_r ( b , tctx , & ej ) ;
2009-04-17 19:14:20 +04:00
torture_assert_ntstatus_ok ( tctx , status , " EnumJobs failed " ) ;
}
2007-12-11 12:48:33 +03:00
torture_assert_werr_ok ( tctx , ej . out . result , " EnumJobs failed " ) ;
return true ;
}
static bool test_GetPrinterDriver2 ( struct torture_context * tctx ,
2010-03-12 13:09:00 +03:00
struct dcerpc_binding_handle * b ,
2009-04-08 15:49:14 +04:00
struct test_spoolss_win_context * ctx ,
2007-12-11 12:48:33 +03:00
struct policy_handle * handle )
{
NTSTATUS status ;
struct spoolss_GetPrinterDriver2 gpd2 ;
DATA_BLOB blob = data_blob_talloc_zero ( tctx , 87424 ) ;
2009-02-06 15:28:48 +03:00
uint32_t needed ;
uint32_t server_major_version ;
uint32_t server_minor_version ;
2007-12-11 12:48:33 +03:00
torture_comment ( tctx , " Testing GetPrinterDriver2 \n " ) ;
gpd2 . in . handle = handle ;
gpd2 . in . architecture = " Windows NT x86 " ;
gpd2 . in . level = 101 ;
gpd2 . in . buffer = & blob ;
gpd2 . in . offered = 87424 ;
gpd2 . in . client_major_version = 3 ;
gpd2 . in . client_minor_version = 0 ;
2009-02-06 15:28:48 +03:00
gpd2 . out . needed = & needed ;
gpd2 . out . server_major_version = & server_major_version ;
gpd2 . out . server_minor_version = & server_minor_version ;
2007-12-11 12:48:33 +03:00
2010-03-12 13:09:00 +03:00
status = dcerpc_spoolss_GetPrinterDriver2_r ( b , tctx , & gpd2 ) ;
2007-12-11 12:48:33 +03:00
torture_assert_ntstatus_ok ( tctx , status , " GetPrinterDriver2 failed " ) ;
2009-04-08 15:49:14 +04:00
if ( ctx - > printer_has_driver ) {
torture_assert_werr_ok ( tctx , gpd2 . out . result ,
" GetPrinterDriver2 failed. " ) ;
}
2007-12-11 12:48:33 +03:00
return true ;
}
static bool test_EnumForms ( struct torture_context * tctx ,
2010-03-12 13:09:00 +03:00
struct dcerpc_binding_handle * b ,
2007-12-11 12:48:33 +03:00
struct policy_handle * handle ,
uint32_t initial_blob_size )
{
NTSTATUS status ;
struct spoolss_EnumForms ef ;
DATA_BLOB blob = data_blob_talloc_zero ( tctx , initial_blob_size ) ;
2009-02-06 19:09:30 +03:00
uint32_t needed ;
2009-02-16 18:42:21 +03:00
uint32_t count ;
2009-03-02 19:58:13 +03:00
union spoolss_FormInfo * info ;
2007-12-11 12:48:33 +03:00
torture_comment ( tctx , " Testing EnumForms \n " ) ;
ef . in . handle = handle ;
ef . in . level = 1 ;
ef . in . buffer = ( initial_blob_size = = 0 ) ? NULL : & blob ;
ef . in . offered = initial_blob_size ;
2009-02-06 19:09:30 +03:00
ef . out . needed = & needed ;
2009-02-16 18:42:21 +03:00
ef . out . count = & count ;
2009-03-02 19:58:13 +03:00
ef . out . info = & info ;
2007-12-11 12:48:33 +03:00
2010-03-12 13:09:00 +03:00
status = dcerpc_spoolss_EnumForms_r ( b , tctx , & ef ) ;
2007-12-11 12:48:33 +03:00
torture_assert_ntstatus_ok ( tctx , status , " EnumForms failed " ) ;
if ( W_ERROR_EQUAL ( ef . out . result , WERR_INSUFFICIENT_BUFFER ) ) {
2009-02-06 19:09:30 +03:00
blob = data_blob_talloc_zero ( tctx , needed ) ;
2007-12-11 12:48:33 +03:00
ef . in . buffer = & blob ;
2009-02-06 19:09:30 +03:00
ef . in . offered = needed ;
2010-03-12 13:09:00 +03:00
status = dcerpc_spoolss_EnumForms_r ( b , tctx , & ef ) ;
2007-12-11 12:48:33 +03:00
torture_assert_ntstatus_ok ( tctx , status , " EnumForms failed " ) ;
}
torture_assert_werr_ok ( tctx , ef . out . result , " EnumForms failed " ) ;
return true ;
}
static bool test_EnumPrinterKey ( struct torture_context * tctx ,
2010-03-12 13:09:00 +03:00
struct dcerpc_binding_handle * b ,
2007-12-11 12:48:33 +03:00
struct policy_handle * handle ,
const char * key ,
struct test_spoolss_win_context * ctx )
{
NTSTATUS status ;
struct spoolss_EnumPrinterKey epk ;
uint32_t needed = 0 ;
2009-12-10 16:21:12 +03:00
union spoolss_KeyNames key_buffer ;
uint32_t _ndr_size ;
2007-12-11 12:48:33 +03:00
torture_comment ( tctx , " Testing EnumPrinterKey(%s) \n " , key ) ;
epk . in . handle = handle ;
epk . in . key_name = talloc_strdup ( tctx , key ) ;
2009-03-17 05:08:34 +03:00
epk . in . offered = 0 ;
2009-02-06 15:53:16 +03:00
epk . out . needed = & needed ;
2009-12-02 16:25:31 +03:00
epk . out . key_buffer = & key_buffer ;
2009-12-10 16:21:12 +03:00
epk . out . _ndr_size = & _ndr_size ;
2007-12-11 12:48:33 +03:00
2010-03-12 13:09:00 +03:00
status = dcerpc_spoolss_EnumPrinterKey_r ( b , tctx , & epk ) ;
2007-12-11 12:48:33 +03:00
torture_assert_ntstatus_ok ( tctx , status , " EnumPrinterKey failed " ) ;
if ( W_ERROR_EQUAL ( epk . out . result , WERR_MORE_DATA ) ) {
2009-03-17 05:08:34 +03:00
epk . in . offered = needed ;
2010-03-12 13:09:00 +03:00
status = dcerpc_spoolss_EnumPrinterKey_r ( b , tctx , & epk ) ;
2007-12-11 12:48:33 +03:00
torture_assert_ntstatus_ok ( tctx , status ,
" EnumPrinterKey failed " ) ;
}
torture_assert_werr_ok ( tctx , epk . out . result , " EnumPrinterKey failed " ) ;
2009-12-10 16:21:12 +03:00
ctx - > printer_keys = key_buffer . string_array ;
2007-12-11 12:48:33 +03:00
return true ;
}
static bool test_EnumPrinterDataEx ( struct torture_context * tctx ,
2010-03-12 13:09:00 +03:00
struct dcerpc_binding_handle * b ,
2007-12-11 12:48:33 +03:00
struct policy_handle * handle ,
const char * key ,
uint32_t initial_blob_size ,
WERROR expected_error )
{
NTSTATUS status ;
struct spoolss_EnumPrinterDataEx epde ;
2009-03-18 03:39:49 +03:00
struct spoolss_PrinterEnumValues * info ;
2009-02-06 15:44:44 +03:00
uint32_t needed ;
uint32_t count ;
2007-12-11 12:48:33 +03:00
torture_comment ( tctx , " Testing EnumPrinterDataEx(%s) \n " , key ) ;
epde . in . handle = handle ;
epde . in . key_name = talloc_strdup ( tctx , key ) ;
epde . in . offered = 0 ;
2009-02-06 15:44:44 +03:00
epde . out . needed = & needed ;
epde . out . count = & count ;
2009-03-18 03:39:49 +03:00
epde . out . info = & info ;
2007-12-11 12:48:33 +03:00
2010-03-12 13:09:00 +03:00
status = dcerpc_spoolss_EnumPrinterDataEx_r ( b , tctx , & epde ) ;
2007-12-11 12:48:33 +03:00
torture_assert_ntstatus_ok ( tctx , status , " EnumPrinterDataEx failed. " ) ;
if ( W_ERROR_EQUAL ( epde . out . result , WERR_MORE_DATA ) ) {
2009-02-06 15:44:44 +03:00
epde . in . offered = needed ;
2010-03-12 13:09:00 +03:00
status = dcerpc_spoolss_EnumPrinterDataEx_r ( b , tctx , & epde ) ;
2007-12-11 12:48:33 +03:00
torture_assert_ntstatus_ok ( tctx , status ,
" EnumPrinterDataEx failed. " ) ;
}
torture_assert_werr_equal ( tctx , epde . out . result , expected_error ,
" EnumPrinterDataEx failed. " ) ;
return true ;
}
static bool test_WinXP ( struct torture_context * tctx , struct dcerpc_pipe * p )
{
bool ret = true ;
struct test_spoolss_win_context * ctx , * tmp_ctx ;
struct policy_handle handle01 , handle02 , handle03 , handle04 ;
/* Sometimes a handle stays unused. In order to make this clear in the
* code , the unused_handle structures are used for that . */
struct policy_handle unused_handle1 , unused_handle2 ;
char * server_name ;
2009-03-18 05:00:37 +03:00
uint32_t i ;
2010-03-12 13:09:00 +03:00
struct dcerpc_binding_handle * b = p - > binding_handle ;
2007-12-11 12:48:33 +03:00
ctx = talloc_zero ( tctx , struct test_spoolss_win_context ) ;
tmp_ctx = talloc_zero ( tctx , struct test_spoolss_win_context ) ;
ret & = test_OpenPrinterSequence ( tctx , p , & handle01 ) ;
2010-03-12 13:09:00 +03:00
ret & = test_GetPrinterData ( tctx , b , & handle01 , " UISingleJobStatusString " ,
2015-12-03 17:24:27 +03:00
WERR_INVALID_PARAMETER , 0 ) ;
2007-12-11 12:48:33 +03:00
torture_comment ( tctx , " Skip RemoteFindNextPrinterChangeNotifyEx test \n " ) ;
server_name = talloc_asprintf ( ctx , " \\ \\ %s " , dcerpc_server_name ( p ) ) ;
2010-03-12 13:09:00 +03:00
ret & = test_OpenPrinterEx ( tctx , b , & unused_handle1 , server_name , 0 ) ;
2007-12-11 12:48:33 +03:00
ret & = test_EnumPrinters ( tctx , p , ctx , 1024 ) ;
2010-03-12 13:09:00 +03:00
ret & = test_OpenPrinterEx ( tctx , b , & handle02 , server_name , 0 ) ;
ret & = test_GetPrinterData ( tctx , b , & handle02 , " MajorVersion " , WERR_OK ,
2007-12-11 12:48:33 +03:00
3 ) ;
2010-03-12 13:09:00 +03:00
ret & = test_ClosePrinter ( tctx , b , & handle02 ) ;
2007-12-11 12:48:33 +03:00
/* If no printers were found, skip all tests that need a printer */
if ( ctx - > printer_count = = 0 ) {
goto end_testWinXP ;
}
2010-03-12 13:09:00 +03:00
ret & = test_OpenPrinterEx ( tctx , b , & handle02 ,
2007-12-11 12:48:33 +03:00
ctx - > printer_info [ 0 ] . info2 . printername ,
PRINTER_ACCESS_USE ) ;
2010-03-12 13:09:00 +03:00
ret & = test_GetPrinter ( tctx , b , & handle02 , ctx , 2 , 0 ) ;
2007-12-11 12:48:33 +03:00
torture_assert_str_equal ( tctx , ctx - > current_info - > info2 . printername ,
ctx - > printer_info [ 0 ] . info2 . printername ,
" GetPrinter returned unexpected printername " ) ;
/*FIXME: Test more components of the PrinterInfo2 struct */
2010-03-12 13:09:00 +03:00
ret & = test_OpenPrinterEx ( tctx , b , & handle03 ,
2007-12-11 12:48:33 +03:00
ctx - > printer_info [ 0 ] . info2 . printername , 0 ) ;
2010-03-12 13:09:00 +03:00
ret & = test_GetPrinter ( tctx , b , & handle03 , ctx , 0 , 1164 ) ;
ret & = test_GetPrinter ( tctx , b , & handle03 , ctx , 2 , 0 ) ;
2007-12-11 12:48:33 +03:00
2010-03-12 13:09:00 +03:00
ret & = test_OpenPrinterEx ( tctx , b , & handle04 ,
2007-12-11 12:48:33 +03:00
ctx - > printer_info [ 0 ] . info2 . printername , 0 ) ;
2010-03-12 13:09:00 +03:00
ret & = test_GetPrinter ( tctx , b , & handle04 , ctx , 2 , 0 ) ;
ret & = test_ClosePrinter ( tctx , b , & handle04 ) ;
2007-12-11 12:48:33 +03:00
2010-03-12 13:09:00 +03:00
ret & = test_OpenPrinterEx ( tctx , b , & handle04 ,
2007-12-11 12:48:33 +03:00
ctx - > printer_info [ 0 ] . info2 . printername , 0 ) ;
2010-03-12 13:09:00 +03:00
ret & = test_GetPrinter ( tctx , b , & handle04 , ctx , 2 , 4096 ) ;
ret & = test_ClosePrinter ( tctx , b , & handle04 ) ;
2007-12-11 12:48:33 +03:00
2010-03-12 13:09:00 +03:00
ret & = test_OpenPrinterAsAdmin ( tctx , b ,
2007-12-11 12:48:33 +03:00
ctx - > printer_info [ 0 ] . info2 . printername ) ;
2010-03-12 13:09:00 +03:00
ret & = test_OpenPrinterEx ( tctx , b , & handle04 ,
2007-12-11 12:48:33 +03:00
ctx - > printer_info [ 0 ] . info2 . printername , PRINTER_READ ) ;
2010-03-12 13:09:00 +03:00
ret & = test_GetPrinterData ( tctx , b , & handle04 , " UISingleJobStatusString " ,
2015-12-03 17:24:12 +03:00
WERR_FILE_NOT_FOUND , 0 ) ;
2007-12-11 12:48:33 +03:00
torture_comment ( tctx , " Skip RemoteFindNextPrinterChangeNotifyEx test \n " ) ;
2010-03-12 13:09:00 +03:00
ret & = test_OpenPrinterEx ( tctx , b , & unused_handle2 ,
2007-12-11 12:48:33 +03:00
ctx - > printer_info [ 0 ] . info2 . printername , 0 ) ;
2010-03-12 13:09:00 +03:00
ret & = test_EnumJobs ( tctx , b , & handle04 ) ;
ret & = test_GetPrinter ( tctx , b , & handle04 , ctx , 2 , 4096 ) ;
2007-12-11 12:48:33 +03:00
2010-03-12 13:09:00 +03:00
ret & = test_ClosePrinter ( tctx , b , & unused_handle2 ) ;
ret & = test_ClosePrinter ( tctx , b , & handle04 ) ;
2007-12-11 12:48:33 +03:00
ret & = test_EnumPrinters ( tctx , p , ctx , 1556 ) ;
2010-03-12 13:09:00 +03:00
ret & = test_GetPrinterDriver2 ( tctx , b , ctx , & handle03 ) ;
ret & = test_EnumForms ( tctx , b , & handle03 , 0 ) ;
2007-12-11 12:48:33 +03:00
2010-03-12 13:09:00 +03:00
ret & = test_EnumPrinterKey ( tctx , b , & handle03 , " " , ctx ) ;
2009-03-18 05:00:37 +03:00
2009-12-03 01:38:05 +03:00
for ( i = 0 ; ctx - > printer_keys & & ctx - > printer_keys [ i ] ! = NULL ; i + + ) {
2009-03-18 05:00:37 +03:00
2010-03-12 13:09:00 +03:00
ret & = test_EnumPrinterKey ( tctx , b , & handle03 ,
2009-03-18 05:00:37 +03:00
ctx - > printer_keys [ i ] ,
tmp_ctx ) ;
2010-03-12 13:09:00 +03:00
ret & = test_EnumPrinterDataEx ( tctx , b , & handle03 ,
2009-03-18 05:00:37 +03:00
ctx - > printer_keys [ i ] , 0 ,
WERR_OK ) ;
2007-12-11 12:48:33 +03:00
}
2010-03-12 13:09:00 +03:00
ret & = test_EnumPrinterDataEx ( tctx , b , & handle03 , " " , 0 ,
2015-12-03 17:24:27 +03:00
WERR_INVALID_PARAMETER ) ;
2007-12-11 12:48:33 +03:00
2010-03-12 13:09:00 +03:00
ret & = test_GetPrinter ( tctx , b , & handle03 , tmp_ctx , 2 , 0 ) ;
2007-12-11 12:48:33 +03:00
2010-03-12 13:09:00 +03:00
ret & = test_OpenPrinterEx ( tctx , b , & unused_handle2 ,
2007-12-11 12:48:33 +03:00
ctx - > printer_info [ 0 ] . info2 . printername , 0 ) ;
2010-03-12 13:09:00 +03:00
ret & = test_ClosePrinter ( tctx , b , & unused_handle2 ) ;
2007-12-11 12:48:33 +03:00
2010-03-12 13:09:00 +03:00
ret & = test_GetPrinter ( tctx , b , & handle03 , tmp_ctx , 2 , 2556 ) ;
2007-12-11 12:48:33 +03:00
2010-03-12 13:09:00 +03:00
ret & = test_OpenPrinterEx ( tctx , b , & unused_handle2 ,
2007-12-11 12:48:33 +03:00
ctx - > printer_info [ 0 ] . info2 . printername , 0 ) ;
2010-03-12 13:09:00 +03:00
ret & = test_ClosePrinter ( tctx , b , & unused_handle2 ) ;
2007-12-11 12:48:33 +03:00
2010-03-12 13:09:00 +03:00
ret & = test_OpenPrinterEx ( tctx , b , & unused_handle2 ,
2007-12-11 12:48:33 +03:00
ctx - > printer_info [ 0 ] . info2 . printername , 0 ) ;
2010-03-12 13:09:00 +03:00
ret & = test_ClosePrinter ( tctx , b , & unused_handle2 ) ;
2007-12-11 12:48:33 +03:00
2010-03-12 13:09:00 +03:00
ret & = test_GetPrinter ( tctx , b , & handle03 , tmp_ctx , 7 , 0 ) ;
2007-12-11 12:48:33 +03:00
2010-03-12 13:09:00 +03:00
ret & = test_OpenPrinterEx ( tctx , b , & unused_handle2 ,
2007-12-11 12:48:33 +03:00
ctx - > printer_info [ 0 ] . info2 . printername , 0 ) ;
2010-03-12 13:09:00 +03:00
ret & = test_ClosePrinter ( tctx , b , & unused_handle2 ) ;
2007-12-11 12:48:33 +03:00
2010-03-12 13:09:00 +03:00
ret & = test_ClosePrinter ( tctx , b , & handle03 ) ;
2007-12-11 12:48:33 +03:00
2010-03-12 13:09:00 +03:00
ret & = test_OpenPrinterEx ( tctx , b , & unused_handle2 ,
2007-12-11 12:48:33 +03:00
ctx - > printer_info [ 0 ] . info2 . printername , 0 ) ;
2010-03-12 13:09:00 +03:00
ret & = test_ClosePrinter ( tctx , b , & unused_handle2 ) ;
2007-12-11 12:48:33 +03:00
2010-03-12 13:09:00 +03:00
ret & = test_OpenPrinterEx ( tctx , b , & handle03 , server_name , 0 ) ;
ret & = test_GetPrinterData ( tctx , b , & handle03 , " W3SvcInstalled " ,
2007-12-11 12:48:33 +03:00
WERR_OK , 0 ) ;
2010-03-12 13:09:00 +03:00
ret & = test_ClosePrinter ( tctx , b , & handle03 ) ;
2007-12-11 12:48:33 +03:00
2010-03-12 13:09:00 +03:00
ret & = test_ClosePrinter ( tctx , b , & unused_handle1 ) ;
ret & = test_ClosePrinter ( tctx , b , & handle02 ) ;
2007-12-11 12:48:33 +03:00
2010-03-12 13:09:00 +03:00
ret & = test_OpenPrinterEx ( tctx , b , & handle02 ,
2007-12-11 12:48:33 +03:00
ctx - > printer_info [ 0 ] . info2 . sharename , 0 ) ;
2010-03-12 13:09:00 +03:00
ret & = test_GetPrinter ( tctx , b , & handle02 , tmp_ctx , 2 , 0 ) ;
ret & = test_ClosePrinter ( tctx , b , & handle02 ) ;
2007-12-11 12:48:33 +03:00
end_testWinXP :
2010-03-12 13:09:00 +03:00
ret & = test_ClosePrinter ( tctx , b , & handle01 ) ;
2007-12-11 12:48:33 +03:00
talloc_free ( tmp_ctx ) ;
talloc_free ( ctx ) ;
return ret ;
}
struct torture_suite * torture_rpc_spoolss_win ( TALLOC_CTX * mem_ctx )
{
2010-12-11 05:26:31 +03:00
struct torture_suite * suite = torture_suite_create ( mem_ctx , " spoolss.win " ) ;
2007-12-11 12:48:33 +03:00
struct torture_rpc_tcase * tcase = torture_suite_add_rpc_iface_tcase ( suite ,
" win " , & ndr_table_spoolss ) ;
torture_rpc_tcase_add_test ( tcase , " testWinXP " , test_WinXP ) ;
return suite ;
}