From 5b1179d7a8887de8cd357ac1c986961dd21e1ec7 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Tue, 10 Jan 2017 18:25:22 +0100 Subject: [PATCH 1/4] s3-spoolss: Fix architecture handling in spoolss_DeletePrinterDriverEx call Pair-Programmed-With: Guenther Deschner Signed-off-by: Andreas Schneider Signed-off-by: Guenther Deschner (cherry picked from commit 34218e0448bca3fda9661c67f18bbd0b9886d079) --- source3/printing/nt_printing.c | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/source3/printing/nt_printing.c b/source3/printing/nt_printing.c index 394a3e5e7e1..c05fb04c836 100644 --- a/source3/printing/nt_printing.c +++ b/source3/printing/nt_printing.c @@ -1374,7 +1374,7 @@ bool printer_driver_in_use(TALLOC_CTX *mem_ctx, { int snum; int n_services = lp_numservices(); - bool in_use = False; + bool in_use = false; struct spoolss_PrinterInfo2 *pinfo2 = NULL; WERROR result; @@ -1399,7 +1399,7 @@ bool printer_driver_in_use(TALLOC_CTX *mem_ctx, } if (strequal(r->driver_name, pinfo2->drivername)) { - in_use = True; + in_use = true; } TALLOC_FREE(pinfo2); @@ -1416,26 +1416,31 @@ bool printer_driver_in_use(TALLOC_CTX *mem_ctx, /* we can still remove the driver if there is one of "Windows NT x86" version 2 or 3 left */ - if (!strequal("Windows NT x86", r->architecture)) { + if (strequal(SPOOLSS_ARCHITECTURE_NT_X86, r->architecture)) { + if (r->version == 2) { + werr = winreg_get_driver(mem_ctx, b, + r->architecture, + r->driver_name, + 3, &driver); + } else if (r->version == 3) { + werr = winreg_get_driver(mem_ctx, b, + r->architecture, + r->driver_name, + 2, &driver); + } else { + DBG_ERR("Unknown driver version (%d)\n", + r->version); + werr = WERR_UNKNOWN_PRINTER_DRIVER; + } + } else if (strequal(SPOOLSS_ARCHITECTURE_x64, r->architecture)) { werr = winreg_get_driver(mem_ctx, b, - "Windows NT x86", + SPOOLSS_ARCHITECTURE_NT_X86, r->driver_name, DRIVER_ANY_VERSION, &driver); - } else if (r->version == 2) { - werr = winreg_get_driver(mem_ctx, b, - "Windows NT x86", - r->driver_name, - 3, &driver); - } else if (r->version == 3) { - werr = winreg_get_driver(mem_ctx, b, - "Windows NT x86", - r->driver_name, - 2, &driver); } else { - DEBUG(0, ("printer_driver_in_use: ERROR!" - " unknown driver version (%d)\n", - r->version)); + DBG_ERR("Unknown driver architecture: %s\n", + r->architecture); werr = WERR_UNKNOWN_PRINTER_DRIVER; } @@ -1443,7 +1448,7 @@ bool printer_driver_in_use(TALLOC_CTX *mem_ctx, if ( W_ERROR_IS_OK(werr) ) { /* it's ok to remove the driver, we have other architctures left */ - in_use = False; + in_use = false; talloc_free(driver); } } -- 2.13.2 From 68074d9b9153f206cfa4d0b2d34a4128b4e35ab7 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Thu, 4 May 2017 17:48:42 +0200 Subject: [PATCH 2/4] s3:printing: Change to GUID dir if we deal with COPY_FROM_DIRECTORY BUG: https://bugzilla.samba.org/show_bug.cgi?id=12761 Signed-off-by: Andreas Schneider Reviewed-by: Guenther Deschner (cherry picked from commit 5b15c7e8908697b157d2593b7caa9be760594a05) --- source3/printing/nt_printing.c | 51 +++++++++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 16 deletions(-) diff --git a/source3/printing/nt_printing.c b/source3/printing/nt_printing.c index c05fb04c836..0c2e326db29 100644 --- a/source3/printing/nt_printing.c +++ b/source3/printing/nt_printing.c @@ -666,16 +666,18 @@ Determine the correct cVersion associated with an architecture and driver static uint32_t get_correct_cversion(struct auth_session_info *session_info, const char *architecture, const char *driverpath_in, + const char *driver_directory, WERROR *perr) { int cversion = -1; NTSTATUS nt_status; struct smb_filename *smb_fname = NULL; - char *driverpath = NULL; files_struct *fsp = NULL; connection_struct *conn = NULL; char *oldcwd; char *printdollar = NULL; + char *printdollar_path = NULL; + char *working_dir = NULL; int printdollar_snum; *perr = WERR_INVALID_PARAMETER; @@ -704,12 +706,33 @@ static uint32_t get_correct_cversion(struct auth_session_info *session_info, return -1; } + printdollar_path = lp_path(talloc_tos(), printdollar_snum); + if (printdollar_path == NULL) { + *perr = WERR_NOT_ENOUGH_MEMORY; + return -1; + } + + working_dir = talloc_asprintf(talloc_tos(), + "%s/%s", + printdollar_path, + architecture); + /* + * If the driver has been uploaded into a temorpary driver + * directory, switch to the driver directory. + */ + if (driver_directory != NULL) { + working_dir = talloc_asprintf(talloc_tos(), "%s/%s/%s", + printdollar_path, + architecture, + driver_directory); + } + nt_status = create_conn_struct_cwd(talloc_tos(), server_event_context(), server_messaging_context(), &conn, printdollar_snum, - lp_path(talloc_tos(), printdollar_snum), + working_dir, session_info, &oldcwd); if (!NT_STATUS_IS_OK(nt_status)) { DEBUG(0,("get_correct_cversion: create_conn_struct " @@ -731,18 +754,11 @@ static uint32_t get_correct_cversion(struct auth_session_info *session_info, goto error_free_conn; } - /* Open the driver file (Portable Executable format) and determine the - * deriver the cversion. */ - driverpath = talloc_asprintf(talloc_tos(), - "%s/%s", - architecture, - driverpath_in); - if (!driverpath) { - *perr = WERR_NOT_ENOUGH_MEMORY; - goto error_exit; - } - - nt_status = driver_unix_convert(conn, driverpath, &smb_fname); + /* + * We switch to the directory where the driver files are located, + * so only work on the file names + */ + nt_status = driver_unix_convert(conn, driverpath_in, &smb_fname); if (!NT_STATUS_IS_OK(nt_status)) { *perr = ntstatus_to_werror(nt_status); goto error_exit; @@ -956,8 +972,11 @@ static WERROR clean_up_driver_struct_level(TALLOC_CTX *mem_ctx, * NT2K: cversion=3 */ - *version = get_correct_cversion(session_info, short_architecture, - *driver_path, &err); + *version = get_correct_cversion(session_info, + short_architecture, + *driver_path, + *driver_directory, + &err); if (*version == -1) { return err; } -- 2.13.2 From d5ce214e4a2898d587c16c19c14fb6eedf88f045 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Fri, 5 May 2017 11:11:25 +0200 Subject: [PATCH 3/4] smbtorture:spoolss: Rename the copy_from_directory test for 64bit BUG: https://bugzilla.samba.org/show_bug.cgi?id=12761 Signed-off-by: Andreas Schneider Reviewed-by: Guenther Deschner (cherry picked from commit 86798a0fa16b4cc89c35d698bffe0b436fc4eb2e) --- source4/torture/rpc/spoolss.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/source4/torture/rpc/spoolss.c b/source4/torture/rpc/spoolss.c index 409ba5777b3..c4b7bf19351 100644 --- a/source4/torture/rpc/spoolss.c +++ b/source4/torture/rpc/spoolss.c @@ -11109,7 +11109,8 @@ static bool test_multiple_drivers(struct torture_context *tctx, } static bool test_driver_copy_from_directory(struct torture_context *tctx, - struct dcerpc_pipe *p) + struct dcerpc_pipe *p, + const char *architecture) { struct torture_driver_context *d; struct spoolss_StringArray *a; @@ -11125,8 +11126,7 @@ static bool test_driver_copy_from_directory(struct torture_context *tctx, d = talloc_zero(tctx, struct torture_driver_context); torture_assert_not_null(tctx, d, "ENOMEM"); - d->local.environment = - talloc_asprintf(d, SPOOLSS_ARCHITECTURE_x64); + d->local.environment = talloc_strdup(d, architecture); torture_assert_not_null_goto(tctx, d->local.environment, ok, done, "ENOMEM"); d->local.driver_directory = @@ -11208,6 +11208,12 @@ done: return ok; } +static bool test_driver_copy_from_directory_64(struct torture_context *tctx, + struct dcerpc_pipe *p) +{ + return test_driver_copy_from_directory(tctx, p, SPOOLSS_ARCHITECTURE_x64); +} + static bool test_del_driver_all_files(struct torture_context *tctx, struct dcerpc_pipe *p) { @@ -11401,8 +11407,8 @@ struct torture_suite *torture_rpc_spoolss_driver(TALLOC_CTX *mem_ctx) torture_rpc_tcase_add_test(tcase, "multiple_drivers", test_multiple_drivers); torture_rpc_tcase_add_test(tcase, - "test_driver_copy_from_directory", - test_driver_copy_from_directory); + "test_driver_copy_from_directory_64", + test_driver_copy_from_directory_64); torture_rpc_tcase_add_test(tcase, "del_driver_all_files", test_del_driver_all_files); -- 2.13.2 From 647ac34b9d432a1ee28cf64bac7504dff6c3afac Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Fri, 5 May 2017 11:12:02 +0200 Subject: [PATCH 4/4] smbtorture:spoolss: Add a 32bit test for copy_from_directory BUG: https://bugzilla.samba.org/show_bug.cgi?id=12761 Signed-off-by: Andreas Schneider Reviewed-by: Guenther Deschner (cherry picked from commit 23009b97bf2f831811c4690141db7355537659d0) --- source4/torture/rpc/spoolss.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/source4/torture/rpc/spoolss.c b/source4/torture/rpc/spoolss.c index c4b7bf19351..e17ac6fc848 100644 --- a/source4/torture/rpc/spoolss.c +++ b/source4/torture/rpc/spoolss.c @@ -11129,8 +11129,13 @@ static bool test_driver_copy_from_directory(struct torture_context *tctx, d->local.environment = talloc_strdup(d, architecture); torture_assert_not_null_goto(tctx, d->local.environment, ok, done, "ENOMEM"); - d->local.driver_directory = - talloc_asprintf(d, "/usr/share/cups/drivers/x64"); + if (strequal(architecture, SPOOLSS_ARCHITECTURE_x64)) { + d->local.driver_directory = + talloc_strdup(d, "/usr/share/cups/drivers/x64"); + } else { + d->local.driver_directory = + talloc_strdup(d, "/usr/share/cups/drivers/i386"); + } torture_assert_not_null_goto(tctx, d->local.driver_directory, ok, done, "ENOMEM"); d->remote.driver_upload_directory = GUID_string2(d, &guid); @@ -11214,6 +11219,12 @@ static bool test_driver_copy_from_directory_64(struct torture_context *tctx, return test_driver_copy_from_directory(tctx, p, SPOOLSS_ARCHITECTURE_x64); } +static bool test_driver_copy_from_directory_32(struct torture_context *tctx, + struct dcerpc_pipe *p) +{ + return test_driver_copy_from_directory(tctx, p, SPOOLSS_ARCHITECTURE_NT_X86); +} + static bool test_del_driver_all_files(struct torture_context *tctx, struct dcerpc_pipe *p) { @@ -11410,6 +11421,10 @@ struct torture_suite *torture_rpc_spoolss_driver(TALLOC_CTX *mem_ctx) "test_driver_copy_from_directory_64", test_driver_copy_from_directory_64); + torture_rpc_tcase_add_test(tcase, + "test_driver_copy_from_directory_32", + test_driver_copy_from_directory_32); + torture_rpc_tcase_add_test(tcase, "del_driver_all_files", test_del_driver_all_files); torture_rpc_tcase_add_test(tcase, "del_driver_unused_files", test_del_driver_unused_files); -- 2.13.2