8927
static bool check_printer_driver_file(struct torture_context *tctx,
8928
struct smbcli_state *cli,
8929
struct torture_driver_context *d,
8930
const char *file_name)
8932
const char *remote_arch_dir = driver_directory_dir(d->remote.driver_directory);
8933
const char *remote_name = talloc_asprintf(tctx, "%s\\%d\\%s",
8939
torture_assert(tctx, (file_name && strlen(file_name) != 0), "invalid filename");
8941
torture_comment(tctx, "checking for driver file at %s\n", remote_name);
8943
fnum = smbcli_open(cli->tree, remote_name, O_RDONLY, DENY_NONE);
8948
torture_assert_ntstatus_ok(tctx,
8949
smbcli_close(cli->tree, fnum),
8950
"failed to close driver file");
8955
static bool check_printer_driver_files(struct torture_context *tctx,
8956
const char *server_name,
8957
struct torture_driver_context *d,
8960
struct smbcli_state *cli;
8961
const char *share_name = driver_directory_share(tctx, d->remote.driver_directory);
8964
torture_assert(tctx,
8965
connect_printer_driver_share(tctx, server_name, share_name, &cli),
8966
"failed to connect to driver share");
8968
torture_comment(tctx, "checking %sexistent driver files at \\\\%s\\%s\n",
8969
(expect_exist ? "": "non-"),
8970
server_name, share_name);
8972
if (d->info8.driver_path && d->info8.driver_path[0]) {
8973
torture_assert(tctx,
8974
check_printer_driver_file(tctx, cli, d, d->info8.driver_path) == expect_exist,
8975
"failed driver_path check");
8977
if (d->info8.data_file && d->info8.data_file[0]) {
8978
torture_assert(tctx,
8979
check_printer_driver_file(tctx, cli, d, d->info8.data_file) == expect_exist,
8980
"failed data_file check");
8982
if (d->info8.config_file && d->info8.config_file[0]) {
8983
torture_assert(tctx,
8984
check_printer_driver_file(tctx, cli, d, d->info8.config_file) == expect_exist,
8985
"failed config_file check");
8987
if (d->info8.help_file && d->info8.help_file[0]) {
8988
torture_assert(tctx,
8989
check_printer_driver_file(tctx, cli, d, d->info8.help_file) == expect_exist,
8990
"failed help_file check");
8992
if (d->info8.dependent_files) {
8993
for (i=0; d->info8.dependent_files->string && d->info8.dependent_files->string[i] != NULL; i++) {
8994
torture_assert(tctx,
8995
check_printer_driver_file(tctx, cli, d, d->info8.dependent_files->string[i]) == expect_exist,
8996
"failed dependent_files check");
8925
9005
static bool remove_printer_driver_file(struct torture_context *tctx,
8926
9006
struct smbcli_state *cli,
8927
9007
struct torture_driver_context *d,
9458
static bool test_del_driver_all_files(struct torture_context *tctx,
9459
struct dcerpc_pipe *p)
9461
struct torture_driver_context *d;
9462
struct spoolss_StringArray *a;
9463
uint32_t add_flags = APD_COPY_NEW_FILES;
9464
uint32_t delete_flags = DPD_DELETE_ALL_FILES;
9465
struct dcerpc_binding_handle *b = p->binding_handle;
9466
const char *server_name_slash = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
9468
d = talloc_zero(tctx, struct torture_driver_context);
9471
d->info8.version = SPOOLSS_DRIVER_VERSION_200X;
9472
d->info8.driver_name = TORTURE_DRIVER_DELETER;
9473
d->info8.architecture = NULL;
9474
d->info8.driver_path = talloc_strdup(d, "pscript5.dll");
9475
d->info8.data_file = talloc_strdup(d, "cups6.ppd");
9476
d->info8.config_file = talloc_strdup(d, "cupsui6.dll");
9477
d->info8.help_file = talloc_strdup(d, "pscript.hlp");
9478
d->local.environment = talloc_strdup(d, SPOOLSS_ARCHITECTURE_x64);
9479
d->local.driver_directory = talloc_strdup(d, "/usr/share/cups/drivers/x64");
9481
a = talloc_zero(d, struct spoolss_StringArray);
9482
a->string = talloc_zero_array(a, const char *, 3);
9483
a->string[0] = talloc_strdup(a->string, "cups6.inf");
9484
a->string[1] = talloc_strdup(a->string, "cups6.ini");
9486
d->info8.dependent_files = a;
9487
d->info8.architecture = d->local.environment;
9489
torture_assert(tctx,
9490
fillup_printserver_info(tctx, p, d),
9491
"failed to fillup printserver info");
9493
if (!directory_exist(d->local.driver_directory)) {
9494
torture_skip(tctx, "Skipping Printer Driver test as no local driver is available");
9497
torture_assert(tctx,
9498
upload_printer_driver(tctx, dcerpc_server_name(p), d),
9499
"failed to upload printer driver");
9501
torture_assert(tctx,
9502
test_AddPrinterDriver_args_level_3(tctx, b, server_name_slash, &d->info8, add_flags, true, NULL),
9503
"failed to add driver");
9505
torture_assert(tctx,
9506
test_DeletePrinterDriverEx(tctx, b, server_name_slash,
9507
d->info8.driver_name,
9508
d->local.environment,
9511
"failed to delete driver");
9513
torture_assert(tctx,
9514
check_printer_driver_files(tctx, dcerpc_server_name(p), d, false),
9515
"printer driver file check failed");
9521
static bool test_del_driver_unused_files(struct torture_context *tctx,
9522
struct dcerpc_pipe *p)
9524
struct torture_driver_context *d1;
9525
struct torture_driver_context *d2;
9526
uint32_t add_flags = APD_COPY_NEW_FILES;
9527
struct dcerpc_binding_handle *b = p->binding_handle;
9528
const char *server_name_slash = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
9530
d1 = talloc_zero(tctx, struct torture_driver_context);
9532
d1->info8.version = SPOOLSS_DRIVER_VERSION_200X;
9533
d1->info8.driver_name = TORTURE_DRIVER_DELETER;
9534
d1->info8.architecture = NULL;
9535
d1->info8.driver_path = talloc_strdup(d1, "pscript5.dll");
9536
d1->info8.data_file = talloc_strdup(d1, "cups6.ppd");
9537
d1->info8.config_file = talloc_strdup(d1, "cupsui6.dll");
9538
d1->info8.help_file = talloc_strdup(d1, "pscript.hlp");
9539
d1->local.environment = talloc_strdup(d1, SPOOLSS_ARCHITECTURE_x64);
9540
d1->local.driver_directory = talloc_strdup(d1, "/usr/share/cups/drivers/x64");
9541
d1->info8.architecture = d1->local.environment;
9543
d2 = talloc_zero(tctx, struct torture_driver_context);
9545
d2->info8.version = SPOOLSS_DRIVER_VERSION_200X;
9546
d2->info8.driver_name = TORTURE_DRIVER_DELETERIN;
9547
d2->info8.architecture = NULL;
9548
d2->info8.driver_path = talloc_strdup(d2, "pscript5.dll"); /* overlapping */
9549
d2->info8.data_file = talloc_strdup(d2, "cupsps6.dll");
9550
d2->info8.config_file = talloc_strdup(d2, "cups6.ini");
9551
d2->info8.help_file = talloc_strdup(d2, "pscript.hlp"); /* overlapping */
9552
d2->local.environment = talloc_strdup(d2, SPOOLSS_ARCHITECTURE_x64);
9553
d2->local.driver_directory = talloc_strdup(d2, "/usr/share/cups/drivers/x64");
9554
d2->info8.architecture = d2->local.environment;
9556
torture_assert(tctx,
9557
fillup_printserver_info(tctx, p, d1),
9558
"failed to fillup printserver info");
9559
torture_assert(tctx,
9560
fillup_printserver_info(tctx, p, d2),
9561
"failed to fillup printserver info");
9563
if (!directory_exist(d1->local.driver_directory)) {
9564
torture_skip(tctx, "Skipping Printer Driver test as no local driver is available");
9567
torture_assert(tctx,
9568
upload_printer_driver(tctx, dcerpc_server_name(p), d1),
9569
"failed to upload printer driver");
9570
torture_assert(tctx,
9571
test_AddPrinterDriver_args_level_3(tctx, b, server_name_slash, &d1->info8, add_flags, true, NULL),
9572
"failed to add driver");
9574
torture_assert(tctx,
9575
upload_printer_driver(tctx, dcerpc_server_name(p), d2),
9576
"failed to upload printer driver");
9577
torture_assert(tctx,
9578
test_AddPrinterDriver_args_level_3(tctx, b, server_name_slash, &d2->info8, add_flags, true, NULL),
9579
"failed to add driver");
9581
/* some files are in use by a separate driver, should fail */
9582
torture_assert(tctx,
9583
test_DeletePrinterDriverEx_exp(tctx, b, server_name_slash,
9584
d1->info8.driver_name,
9585
d1->local.environment,
9586
DPD_DELETE_ALL_FILES,
9588
WERR_PRINTER_DRIVER_IN_USE),
9589
"invalid delete driver response");
9591
/* should only delete files not in use by other driver */
9592
torture_assert(tctx,
9593
test_DeletePrinterDriverEx_exp(tctx, b, server_name_slash,
9594
d1->info8.driver_name,
9595
d1->local.environment,
9596
DPD_DELETE_UNUSED_FILES,
9599
"failed to delete driver (unused files)");
9601
/* check non-overlapping were deleted */
9602
d1->info8.driver_path = NULL;
9603
d1->info8.help_file = NULL;
9604
torture_assert(tctx,
9605
check_printer_driver_files(tctx, dcerpc_server_name(p), d1, false),
9606
"printer driver file check failed");
9607
/* d2 files should be uneffected */
9608
torture_assert(tctx,
9609
check_printer_driver_files(tctx, dcerpc_server_name(p), d2, true),
9610
"printer driver file check failed");
9612
torture_assert(tctx,
9613
test_DeletePrinterDriverEx_exp(tctx, b, server_name_slash,
9614
d2->info8.driver_name,
9615
d2->local.environment,
9616
DPD_DELETE_ALL_FILES,
9619
"failed to delete driver");
9621
torture_assert(tctx,
9622
check_printer_driver_files(tctx, dcerpc_server_name(p), d2, false),
9623
"printer driver file check failed");
9374
9630
struct torture_suite *torture_rpc_spoolss_driver(TALLOC_CTX *mem_ctx)
9376
9632
struct torture_suite *suite = torture_suite_create(mem_ctx, "spoolss.driver");