iremotewinspool-tests: Add client os build number validation test
[vlendec/samba-autobuild/.git] / source4 / torture / rpc / iremotewinspool.c
index 08b282420303499b08eda1ca178f005ac66064c3..805f46c8b89bcfff9d1b2d046df49c7f4df343f8 100644 (file)
@@ -22,6 +22,7 @@
 #include "torture/torture.h"
 #include "librpc/gen_ndr/ndr_winspool.h"
 #include "librpc/gen_ndr/ndr_winspool_c.h"
+#include "librpc/gen_ndr/ndr_spoolss_c.h"
 #include "torture/rpc/torture_rpc.h"
 #include "libcli/registry/util_reg.h"
 
@@ -32,31 +33,77 @@ struct test_iremotewinspool_context {
        const char *environment;
 };
 
+enum client_os_version
+{
+       WIN_2000,
+       WIN_VISTA,
+       WIN_SERVER_2008,
+       WIN_7,
+       WIN_SERVER_2008R2,
+       WIN_8,
+       WIN_SERVER_2012,
+       WIN_10,
+       WIN_SERVER_2016
+};
+
+static struct spoolss_UserLevel1 test_get_client_info(struct torture_context *tctx,
+                                                     enum client_os_version os,
+                                                     enum spoolss_MajorVersion major_number,
+                                                     enum spoolss_MinorVersion minor_number)
+{
+       struct spoolss_UserLevel1 level1;
+
+       level1.size     = 28;
+       level1.client   = talloc_asprintf(tctx, "\\\\%s", "mthelena");
+       level1.user     = "GD";
+       level1.processor = PROCESSOR_ARCHITECTURE_AMD64;
+       level1.major    = major_number;
+       level1.minor    = minor_number;
+
+       switch (os) {
+               case WIN_SERVER_2016:
+               case WIN_10:
+                       level1.build = 10586;
+                       break;
+               case WIN_SERVER_2012:
+               case WIN_8:
+                       level1.build = 9200;
+                       break;
+               case WIN_SERVER_2008R2:
+               case WIN_7:
+                       level1.build = 7007;
+                       break;
+               case WIN_SERVER_2008:
+               case WIN_VISTA:
+                       level1.build = 6000;
+                       break;
+               case WIN_2000:
+                       level1.build = 1382;
+                       break;
+               default:
+                       level1.build = 7007;
+       }
+
+       return level1;
+}
+
 static bool test_AsyncOpenPrinter_byprinter(struct torture_context *tctx,
                                            struct test_iremotewinspool_context *ctx,
                                            struct dcerpc_pipe *p,
                                            const char *printer_name,
+                                           struct spoolss_UserLevel1 cinfo,
                                            struct policy_handle *handle)
 {
        struct dcerpc_binding_handle *b = p->binding_handle;
        struct spoolss_DevmodeContainer devmode_ctr;
        struct spoolss_UserLevelCtr client_info_ctr;
-       struct spoolss_UserLevel1 level1;
        uint32_t access_mask = SERVER_ALL_ACCESS;
        struct winspool_AsyncOpenPrinter r;
 
        ZERO_STRUCT(devmode_ctr);
 
-       level1.size     = 28;
-       level1.client   = talloc_asprintf(tctx, "\\\\%s", "mthelena");
-       level1.user     = "GD";
-       level1.build    = 1381;
-       level1.major    = 3;
-       level1.minor    = 0;
-       level1.processor = PROCESSOR_ARCHITECTURE_AMD64;
-
        client_info_ctr.level = 1;
-       client_info_ctr.user_info.level1 = &level1;
+       client_info_ctr.user_info.level1 = &cinfo;
 
        r.in.pPrinterName       = printer_name;
        r.in.pDatatype          = NULL;
@@ -152,13 +199,13 @@ static bool test_AsyncGetPrinterData_checktype(struct torture_context *tctx,
        return true;
 }
 
-static bool test_AsyncGetPrinterData(struct torture_context *tctx,
-                                    struct dcerpc_binding_handle *b,
-                                    struct policy_handle *handle,
-                                    const char *value_name,
-                                    enum winreg_Type *type_p,
-                                    uint8_t **data_p,
-                                    uint32_t *needed_p)
+static bool test_AsyncGetPrinterData_args(struct torture_context *tctx,
+                                         struct dcerpc_binding_handle *b,
+                                         struct policy_handle *handle,
+                                         const char *value_name,
+                                         enum winreg_Type *type_p,
+                                         uint8_t **data_p,
+                                         uint32_t *needed_p)
 {
        return test_AsyncGetPrinterData_checktype(tctx, b, handle,
                                                  value_name,
@@ -177,7 +224,7 @@ static bool test_get_environment(struct torture_context *tctx,
        uint32_t needed;
 
        torture_assert(tctx,
-               test_AsyncGetPrinterData(tctx, b, handle, "Architecture", &type, &data, &needed),
+               test_AsyncGetPrinterData_args(tctx, b, handle, "Architecture", &type, &data, &needed),
                "failed to get Architecture");
 
        torture_assert_int_equal(tctx, type, REG_SZ, "unexpected type");
@@ -195,6 +242,7 @@ static bool torture_rpc_iremotewinspool_setup_common(struct torture_context *tct
                                                     struct test_iremotewinspool_context *t)
 {
        const char *printer_name;
+       struct spoolss_UserLevel1 client_info;
        struct dcerpc_binding *binding;
 
        torture_assert_ntstatus_ok(tctx,
@@ -215,10 +263,12 @@ static bool torture_rpc_iremotewinspool_setup_common(struct torture_context *tct
 
        printer_name = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(t->iremotewinspool_pipe));
 
+       client_info = test_get_client_info(tctx, WIN_2000, 3, SPOOLSS_MINOR_VERSION_0);
+
        torture_assert(tctx,
                test_AsyncOpenPrinter_byprinter(tctx, t,
                                                t->iremotewinspool_pipe, printer_name,
-                                               &t->server_handle),
+                                               client_info, &t->server_handle),
                                                "failed to open printserver");
        torture_assert(tctx,
                test_get_environment(tctx,
@@ -268,12 +318,15 @@ static bool test_AsyncClosePrinter(struct torture_context *tctx,
 
        struct dcerpc_pipe *p = ctx->iremotewinspool_pipe;
        const char *printer_name;
+       struct spoolss_UserLevel1 client_info;
        struct policy_handle handle;
 
        printer_name = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
 
+       client_info = test_get_client_info(tctx, WIN_2000, 3, SPOOLSS_MINOR_VERSION_0);
+
        torture_assert(tctx,
-               test_AsyncOpenPrinter_byprinter(tctx, ctx, p, printer_name, &handle),
+               test_AsyncOpenPrinter_byprinter(tctx, ctx, p, printer_name, client_info, &handle),
                "failed to test AsyncOpenPrinter");
 
        torture_assert(tctx,
@@ -291,12 +344,15 @@ static bool test_AsyncOpenPrinter(struct torture_context *tctx,
 
        struct dcerpc_pipe *p = ctx->iremotewinspool_pipe;
        const char *printer_name;
+       struct spoolss_UserLevel1 client_info;
        struct policy_handle handle;
 
        printer_name = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
 
+       client_info = test_get_client_info(tctx, WIN_2000, 3, SPOOLSS_MINOR_VERSION_0);
+
        torture_assert(tctx,
-               test_AsyncOpenPrinter_byprinter(tctx, ctx, p, printer_name, &handle),
+               test_AsyncOpenPrinter_byprinter(tctx, ctx, p, printer_name, client_info, &handle),
                "failed to test AsyncOpenPrinter");
 
        test_AsyncClosePrinter_byhandle(tctx, ctx, p, &handle);
@@ -304,6 +360,70 @@ static bool test_AsyncOpenPrinter(struct torture_context *tctx,
        return true;
 }
 
+/*
+ * Validate the result of AsyncOpenPrinter calls based on client info
+ * build number. Windows Server 2016 rejects an advertised build
+ * number less than 6000(Windows Vista and Windows Server 2008, or older)
+ */
+static bool test_AsyncOpenPrinterValidateBuildNumber(struct torture_context *tctx,
+                                                    void *private_data)
+{
+       struct test_iremotewinspool_context *ctx =
+               talloc_get_type_abort(private_data, struct test_iremotewinspool_context);
+
+       struct dcerpc_pipe *p = ctx->iremotewinspool_pipe;
+       const char *printer_name;
+       struct spoolss_UserLevel1 client_info;
+       struct policy_handle handle;
+       struct dcerpc_binding_handle *b = p->binding_handle;
+       struct spoolss_DevmodeContainer devmode_ctr;
+       struct spoolss_UserLevelCtr client_info_ctr = {
+               .level = 1,
+       };
+       uint32_t access_mask = SERVER_ALL_ACCESS;
+       struct winspool_AsyncOpenPrinter r;
+       NTSTATUS status;
+       bool ok = false;
+
+       printer_name = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
+       torture_assert_not_null(tctx, printer_name, "Cannot allocate memory");
+
+       /* fail with Windows 2000 build number */
+       client_info = test_get_client_info(tctx, WIN_2000, 3, SPOOLSS_MINOR_VERSION_0);
+
+       ZERO_STRUCT(devmode_ctr);
+
+       client_info_ctr.user_info.level1 = &client_info;
+
+       r.in.pPrinterName       = printer_name;
+       r.in.pDatatype          = NULL;
+       r.in.pDevModeContainer  = &devmode_ctr;
+       r.in.AccessRequired     = access_mask;
+       r.in.pClientInfo        = &client_info_ctr;
+       r.out.pHandle           = &handle;
+
+       status = dcerpc_winspool_AsyncOpenPrinter_r(b, tctx, &r);
+       torture_assert_ntstatus_ok(tctx, status, "AsyncOpenPrinter failed");
+       torture_assert_werr_equal(tctx, r.out.result, WERR_ACCESS_DENIED,
+               "AsyncOpenPrinter should have failed");
+
+       /* succeed with Windows 7 build number */
+       client_info = test_get_client_info(tctx, WIN_7, 3, SPOOLSS_MINOR_VERSION_0);
+       client_info_ctr.user_info.level1 = &client_info;
+       r.in.pClientInfo        = &client_info_ctr;
+
+       status = dcerpc_winspool_AsyncOpenPrinter_r(b, tctx, &r);
+       torture_assert_ntstatus_ok(tctx, status, "AsyncOpenPrinter failed");
+       torture_assert_werr_ok(tctx, r.out.result,
+               "AsyncOpenPrinter failed");
+
+       ok = test_AsyncClosePrinter_byhandle(tctx, ctx, p, &handle);
+       torture_assert(tctx, ok, "failed to AsyncClosePrinter handle");
+
+       return true;
+
+}
+
 static struct spoolss_NotifyOption *setup_printserver_NotifyOption(struct torture_context *tctx)
 {
        struct spoolss_NotifyOption *o;
@@ -344,6 +464,53 @@ static struct spoolss_NotifyOption *setup_printserver_NotifyOption(struct tortur
        return o;
 }
 
+static bool test_SyncUnRegisterForRemoteNotifications_args(struct torture_context *tctx,
+                                                          struct dcerpc_pipe *p,
+                                                          struct policy_handle *notify_handle)
+{
+       struct winspool_SyncUnRegisterForRemoteNotifications r;
+       struct dcerpc_binding_handle *b = p->binding_handle;
+
+       r.in.phRpcHandle = notify_handle;
+       r.out.phRpcHandle = notify_handle;
+
+       torture_assert_ntstatus_ok(tctx,
+               dcerpc_winspool_SyncUnRegisterForRemoteNotifications_r(b, tctx, &r),
+               "SyncUnRegisterForRemoteNotifications failed");
+       torture_assert_hresult_ok(tctx, r.out.result,
+               "SyncUnRegisterForRemoteNotifications failed");
+
+       return true;
+}
+
+static bool test_SyncRegisterForRemoteNotifications_args(struct torture_context *tctx,
+                                                        struct dcerpc_pipe *p,
+                                                        struct policy_handle *server_handle,
+                                                        struct policy_handle *notify_handle);
+
+static bool test_SyncUnRegisterForRemoteNotifications(struct torture_context *tctx,
+                                                     void *private_data)
+{
+       struct test_iremotewinspool_context *ctx =
+               talloc_get_type_abort(private_data, struct test_iremotewinspool_context);
+       struct policy_handle notify_handle;
+
+       torture_assert(tctx,
+               test_SyncRegisterForRemoteNotifications_args(tctx,
+                                                            ctx->iremotewinspool_pipe,
+                                                            &ctx->server_handle,
+                                                            &notify_handle),
+               "failed to test SyncRegisterForRemoteNotifications");
+
+       torture_assert(tctx,
+               test_SyncUnRegisterForRemoteNotifications_args(tctx,
+                                                              ctx->iremotewinspool_pipe,
+                                                              &notify_handle),
+               "failed to test UnSyncRegisterForRemoteNotifications");
+
+       return true;
+}
+
 static bool test_SyncRegisterForRemoteNotifications_args(struct torture_context *tctx,
                                                         struct dcerpc_pipe *p,
                                                         struct policy_handle *server_handle,
@@ -410,6 +577,457 @@ static bool test_SyncRegisterForRemoteNotifications(struct torture_context *tctx
                                                             &notify_handle),
                "failed to test SyncRegisterForRemoteNotifications");
 
+       test_SyncUnRegisterForRemoteNotifications_args(tctx, ctx->iremotewinspool_pipe, &notify_handle);
+
+       return true;
+}
+
+static bool test_AsyncUploadPrinterDriverPackage(struct torture_context *tctx,
+                                                void *private_data)
+{
+       struct test_iremotewinspool_context *ctx =
+               talloc_get_type_abort(private_data, struct test_iremotewinspool_context);
+
+       struct dcerpc_pipe *p = ctx->iremotewinspool_pipe;
+       struct dcerpc_binding_handle *b = p->binding_handle;
+
+       struct winspool_AsyncUploadPrinterDriverPackage r;
+       uint32_t pcchDestInfPath = 0;
+
+       r.in.pszServer = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
+       r.in.pszInfPath = "";
+       r.in.pszEnvironment = "";
+       r.in.dwFlags = 0;
+       r.in.pszDestInfPath = NULL;
+       r.in.pcchDestInfPath = &pcchDestInfPath;
+       r.out.pszDestInfPath = NULL;
+       r.out.pcchDestInfPath = &pcchDestInfPath;
+
+       torture_assert_ntstatus_ok(tctx,
+               dcerpc_winspool_AsyncUploadPrinterDriverPackage_r(b, tctx, &r),
+               "AsyncUploadPrinterDriverPackage failed");
+       torture_assert_hresult_equal(tctx, r.out.result, HRES_E_INVALIDARG,
+               "AsyncUploadPrinterDriverPackage failed");
+
+       pcchDestInfPath = 260;
+       r.in.pszDestInfPath = talloc_zero_array(tctx, uint16_t, pcchDestInfPath);
+       r.out.pszDestInfPath = talloc_zero_array(tctx, uint16_t, pcchDestInfPath);
+
+       torture_assert_ntstatus_ok(tctx,
+               dcerpc_winspool_AsyncUploadPrinterDriverPackage_r(b, tctx, &r),
+               "AsyncUploadPrinterDriverPackage failed");
+       torture_assert_werr_equal(tctx,
+               W_ERROR(WIN32_FROM_HRESULT(r.out.result)), WERR_INVALID_ENVIRONMENT,
+               "AsyncUploadPrinterDriverPackage failed");
+
+       r.in.pszEnvironment = SPOOLSS_ARCHITECTURE_x64;
+
+       torture_assert_ntstatus_ok(tctx,
+               dcerpc_winspool_AsyncUploadPrinterDriverPackage_r(b, tctx, &r),
+               "AsyncUploadPrinterDriverPackage failed");
+       torture_assert_werr_equal(tctx,
+               W_ERROR(WIN32_FROM_HRESULT(r.out.result)), WERR_FILE_NOT_FOUND,
+               "AsyncUploadPrinterDriverPackage failed");
+
+       r.in.pszInfPath = "\\\\mthelena\\print$\\x64\\{BD443844-ED00-4D96-8CAE-95E49492312A}\\prnbrcl1.inf";
+
+       torture_assert_ntstatus_ok(tctx,
+               dcerpc_winspool_AsyncUploadPrinterDriverPackage_r(b, tctx, &r),
+               "AsyncUploadPrinterDriverPackage failed");
+       torture_assert_werr_equal(tctx,
+               W_ERROR(WIN32_FROM_HRESULT(r.out.result)), WERR_FILE_NOT_FOUND,
+               "AsyncUploadPrinterDriverPackage failed");
+
+       return true;
+}
+
+static bool test_AsyncEnumPrinters(struct torture_context *tctx,
+                                  void *private_data)
+{
+       struct test_iremotewinspool_context *ctx =
+               talloc_get_type_abort(private_data, struct test_iremotewinspool_context);
+
+       struct dcerpc_pipe *p = ctx->iremotewinspool_pipe;
+       struct dcerpc_binding_handle *b = p->binding_handle;
+
+       struct winspool_AsyncEnumPrinters r;
+       uint32_t levels[] = { 1, 2, /*3,*/ 4, 5 };
+       int i;
+
+       uint32_t needed;
+       uint32_t returned;
+
+       for (i = 0; i < ARRAY_SIZE(levels); i++) {
+
+               r.in.Flags = PRINTER_ENUM_LOCAL;
+               r.in.pName = NULL;
+               r.in.Level = levels[i];
+               r.in.cbBuf = 0;
+               r.in.pPrinterEnum = NULL;
+               r.out.pcbNeeded = &needed;
+               r.out.pcReturned = &returned;
+               r.out.pPrinterEnum = NULL;
+
+               torture_assert_ntstatus_ok(tctx,
+                       dcerpc_winspool_AsyncEnumPrinters_r(b, tctx, &r),
+                       "AsyncEnumPrinters failed");
+               torture_assert_werr_equal(tctx, r.out.result, WERR_INSUFFICIENT_BUFFER,
+                       "AsyncEnumPrinters failed");
+
+               r.in.cbBuf = needed;
+               r.in.pPrinterEnum = talloc_zero_array(tctx, uint8_t, r.in.cbBuf);
+               r.out.pPrinterEnum = r.in.pPrinterEnum;
+
+               torture_assert_ntstatus_ok(tctx,
+                       dcerpc_winspool_AsyncEnumPrinters_r(b, tctx, &r),
+                       "AsyncEnumPrinters failed");
+               torture_assert_werr_ok(tctx, r.out.result,
+                       "AsyncEnumPrinters failed");
+       }
+
+       return true;
+}
+
+static bool test_AsyncGetPrinterData(struct torture_context *tctx,
+                                    void *private_data)
+{
+       struct test_iremotewinspool_context *ctx =
+               talloc_get_type_abort(private_data, struct test_iremotewinspool_context);
+
+       struct dcerpc_pipe *p = ctx->iremotewinspool_pipe;
+       struct dcerpc_binding_handle *b = p->binding_handle;
+       DATA_BLOB blob;
+       const char *s;
+       bool ok;
+
+       uint32_t pType;
+       uint32_t pcbNeeded;
+       uint8_t *pData;
+
+       torture_assert(tctx,
+               test_AsyncGetPrinterData_args(tctx, b, &ctx->server_handle,
+                                             "MajorVersion",
+                                             &pType, &pData, &pcbNeeded),
+               "failed to check for MajorVersion");
+
+       torture_assert_int_equal(tctx, pcbNeeded, 4, "pcbNeeded");
+       torture_assert_int_equal(tctx, pType, REG_DWORD, "pType");
+       torture_assert_int_equal(tctx, IVAL(pData, 0), 3, "pData");
+
+       torture_assert(tctx,
+               test_AsyncGetPrinterData_args(tctx, b, &ctx->server_handle,
+                                             "Architecture",
+                                             &pType, &pData, &pcbNeeded),
+               "failed to check for Architecture");
+
+       blob = data_blob_const(pData, pcbNeeded);
+
+       torture_assert_int_equal(tctx, pType, REG_SZ, "pType");
+       torture_assert(tctx, pull_reg_sz(tctx, &blob, &s), "");
+       ok = strequal(s, SPOOLSS_ARCHITECTURE_x64) || strequal(s, SPOOLSS_ARCHITECTURE_NT_X86);
+       torture_assert(tctx, ok, "unexpected architecture returned");
+
+       return true;
+}
+
+static bool test_AsyncCorePrinterDriverInstalled(struct torture_context *tctx,
+                                                void *private_data)
+{
+       struct test_iremotewinspool_context *ctx =
+               talloc_get_type_abort(private_data, struct test_iremotewinspool_context);
+
+       struct dcerpc_pipe *p = ctx->iremotewinspool_pipe;
+       struct dcerpc_binding_handle *b = p->binding_handle;
+
+       struct winspool_AsyncCorePrinterDriverInstalled r;
+       int32_t pbDriverInstalled;
+       struct GUID guid;
+
+       r.in.pszServer = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
+       r.in.pszEnvironment = "";
+       r.in.CoreDriverGUID = GUID_zero();
+       r.in.ftDriverDate = 0;
+       r.in.dwlDriverVersion = 0;
+       r.out.pbDriverInstalled = &pbDriverInstalled;
+
+       torture_assert_ntstatus_ok(tctx,
+               dcerpc_winspool_AsyncCorePrinterDriverInstalled_r(b, tctx, &r),
+               "AsyncCorePrinterDriverInstalled failed");
+       torture_assert_werr_equal(tctx,
+               W_ERROR(WIN32_FROM_HRESULT(r.out.result)), WERR_INVALID_ENVIRONMENT,
+               "AsyncCorePrinterDriverInstalled failed");
+
+       r.in.pszEnvironment = SPOOLSS_ARCHITECTURE_x64;
+
+       torture_assert_ntstatus_ok(tctx,
+               dcerpc_winspool_AsyncCorePrinterDriverInstalled_r(b, tctx, &r),
+               "AsyncCorePrinterDriverInstalled failed");
+       torture_assert_hresult_ok(tctx, r.out.result,
+               "AsyncCorePrinterDriverInstalled failed");
+       torture_assert_int_equal(tctx, *r.out.pbDriverInstalled, false,
+                               "unexpected driver installed");
+
+       r.in.CoreDriverGUID = GUID_random();
+
+       torture_assert_ntstatus_ok(tctx,
+               dcerpc_winspool_AsyncCorePrinterDriverInstalled_r(b, tctx, &r),
+               "AsyncCorePrinterDriverInstalled failed");
+       torture_assert_hresult_ok(tctx, r.out.result,
+               "AsyncCorePrinterDriverInstalled failed");
+       torture_assert_int_equal(tctx, *r.out.pbDriverInstalled, false,
+                               "unexpected driver installed");
+
+       torture_assert_ntstatus_ok(tctx,
+               GUID_from_string(SPOOLSS_CORE_PRINT_PACKAGE_FILES_XPSDRV, &guid), "");
+
+       r.in.CoreDriverGUID = guid;
+
+       torture_assert_ntstatus_ok(tctx,
+               dcerpc_winspool_AsyncCorePrinterDriverInstalled_r(b, tctx, &r),
+               "AsyncCorePrinterDriverInstalled failed");
+       torture_assert_hresult_ok(tctx, r.out.result,
+               "AsyncCorePrinterDriverInstalled failed");
+       torture_assert_int_equal(tctx, *r.out.pbDriverInstalled, true,
+                               "xps core driver not installed?");
+
+       r.in.dwlDriverVersion = 0xffffffff;
+
+       torture_assert_ntstatus_ok(tctx,
+               dcerpc_winspool_AsyncCorePrinterDriverInstalled_r(b, tctx, &r),
+               "AsyncCorePrinterDriverInstalled failed");
+       torture_assert_hresult_ok(tctx, r.out.result,
+               "AsyncCorePrinterDriverInstalled failed");
+       torture_assert_int_equal(tctx, *r.out.pbDriverInstalled, true,
+                               "xps core driver not installed?");
+
+       r.in.dwlDriverVersion = 1234;
+
+       torture_assert_ntstatus_ok(tctx,
+               dcerpc_winspool_AsyncCorePrinterDriverInstalled_r(b, tctx, &r),
+               "AsyncCorePrinterDriverInstalled failed");
+       torture_assert_hresult_ok(tctx, r.out.result,
+               "AsyncCorePrinterDriverInstalled failed");
+       torture_assert_int_equal(tctx, *r.out.pbDriverInstalled, true,
+                               "xps core driver not installed?");
+
+       r.in.ftDriverDate = unix_timespec_to_nt_time(timespec_current());
+
+       torture_assert_ntstatus_ok(tctx,
+               dcerpc_winspool_AsyncCorePrinterDriverInstalled_r(b, tctx, &r),
+               "AsyncCorePrinterDriverInstalled failed");
+       torture_assert_hresult_ok(tctx, r.out.result,
+               "AsyncCorePrinterDriverInstalled failed");
+       torture_assert_int_equal(tctx, *r.out.pbDriverInstalled, false,
+                               "driver too old ?");
+
+       r.in.dwlDriverVersion = 0;
+
+       torture_assert_ntstatus_ok(tctx,
+               dcerpc_winspool_AsyncCorePrinterDriverInstalled_r(b, tctx, &r),
+               "AsyncCorePrinterDriverInstalled failed");
+       torture_assert_hresult_ok(tctx, r.out.result,
+               "AsyncCorePrinterDriverInstalled failed");
+       torture_assert_int_equal(tctx, *r.out.pbDriverInstalled, false,
+                               "unexpected driver installed");
+
+       return true;
+}
+
+static bool test_get_core_printer_drivers_arch_guid(struct torture_context *tctx,
+                                                   struct dcerpc_pipe *p,
+                                                   const char *architecture,
+                                                   const char *guid_str,
+                                                   const char **package_id)
+{
+       struct winspool_AsyncGetCorePrinterDrivers r;
+       DATA_BLOB blob;
+       const char **s;
+       struct dcerpc_binding_handle *b = p->binding_handle;
+
+       s = talloc_zero_array(tctx, const char *, 2);
+       s[0] = guid_str;
+
+       torture_assert(tctx,
+               push_reg_multi_sz(tctx, &blob, s),
+               "push_reg_multi_sz failed");
+
+       r.in.pszServer = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
+       r.in.pszEnvironment = architecture;
+       r.in.cchCoreDrivers = blob.length/2;
+       r.in.pszzCoreDriverDependencies = (uint16_t *)blob.data;
+       r.in.cCorePrinterDrivers = 1;
+       r.out.pCorePrinterDrivers = talloc_zero_array(tctx, struct spoolss_CorePrinterDriver, r.in.cCorePrinterDrivers);
+
+       torture_assert_ntstatus_ok(tctx,
+               dcerpc_winspool_AsyncGetCorePrinterDrivers_r(b, tctx, &r),
+               "winspool_AsyncCorePrinterDrivers failed");
+       torture_assert_hresult_ok(tctx, r.out.result,
+               "winspool_AsyncCorePrinterDrivers failed");
+
+       if (package_id) {
+               *package_id = r.out.pCorePrinterDrivers[0].szPackageID;
+       }
+
+       return true;
+}
+
+static bool test_AsyncDeletePrintDriverPackage(struct torture_context *tctx,
+                                              void *private_data)
+{
+       struct test_iremotewinspool_context *ctx =
+               talloc_get_type_abort(private_data, struct test_iremotewinspool_context);
+
+       struct dcerpc_pipe *p = ctx->iremotewinspool_pipe;
+       struct dcerpc_binding_handle *b = p->binding_handle;
+       struct winspool_AsyncDeletePrinterDriverPackage r;
+
+       const char *architectures[] = {
+/*             SPOOLSS_ARCHITECTURE_NT_X86, */
+               SPOOLSS_ARCHITECTURE_x64
+       };
+       int i;
+
+       for (i=0; i < ARRAY_SIZE(architectures); i++) {
+
+               const char *package_id;
+
+               torture_assert(tctx,
+                       test_get_core_printer_drivers_arch_guid(tctx, p,
+                                                               architectures[i],
+                                                               SPOOLSS_CORE_PRINT_PACKAGE_FILES_XPSDRV,
+                                                               &package_id),
+                       "failed to get core printer driver");
+
+               r.in.pszServer = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
+               r.in.pszEnvironment = "";
+               r.in.pszInfPath = "";
+
+               torture_comment(tctx, "Testing AsyncDeletePrinterDriverPackage(%s, %s, %s)\n",
+                       r.in.pszServer, architectures[i], package_id);
+
+               torture_assert_ntstatus_ok(tctx,
+                       dcerpc_winspool_AsyncDeletePrinterDriverPackage_r(b, tctx, &r),
+                       "AsyncDeletePrinterDriverPackage failed");
+               torture_assert_werr_equal(tctx,
+                       W_ERROR(WIN32_FROM_HRESULT(r.out.result)), WERR_NOT_FOUND,
+                       "AsyncDeletePrinterDriverPackage failed");
+
+               r.in.pszInfPath = package_id;
+
+               torture_assert_ntstatus_ok(tctx,
+                       dcerpc_winspool_AsyncDeletePrinterDriverPackage_r(b, tctx, &r),
+                       "AsyncDeletePrinterDriverPackage failed");
+               torture_assert_werr_equal(tctx,
+                       W_ERROR(WIN32_FROM_HRESULT(r.out.result)), WERR_INVALID_ENVIRONMENT,
+                       "AsyncDeletePrinterDriverPackage failed");
+
+               r.in.pszEnvironment = architectures[i];
+
+               torture_assert_ntstatus_ok(tctx,
+                       dcerpc_winspool_AsyncDeletePrinterDriverPackage_r(b, tctx, &r),
+                       "AsyncDeletePrinterDriverPackage failed");
+               torture_assert_hresult_equal(tctx, r.out.result, HRES_E_ACCESSDENIED,
+                       "AsyncDeletePrinterDriverPackage failed");
+       }
+
+       return true;
+}
+
+static bool test_AsyncGetPrinterDriverDirectory(struct torture_context *tctx,
+                                               void *private_data)
+{
+       struct test_iremotewinspool_context *ctx =
+               talloc_get_type_abort(private_data, struct test_iremotewinspool_context);
+
+       struct dcerpc_pipe *p = ctx->iremotewinspool_pipe;
+       struct dcerpc_binding_handle *b = p->binding_handle;
+       struct winspool_AsyncGetPrinterDriverDirectory r;
+       uint32_t pcbNeeded;
+       DATA_BLOB blob;
+       const char *s;
+
+       r.in.pName = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
+       r.in.pEnvironment = ctx->environment;
+       r.in.Level = 1;
+       r.in.cbBuf = 0x200;
+       r.in.pDriverDirectory = talloc_zero_array(tctx, uint8_t, r.in.cbBuf);
+       r.out.pcbNeeded = &pcbNeeded;
+       r.out.pDriverDirectory = r.in.pDriverDirectory;
+
+       torture_comment(tctx, "Testing AsyncGetPrinterDriverDirectory(%s, %s)\n",
+               r.in.pName, r.in.pEnvironment);
+
+       torture_assert_ntstatus_ok(tctx,
+               dcerpc_winspool_AsyncGetPrinterDriverDirectory_r(b, tctx, &r),
+               "AsyncGetPrinterDriverDirectory failed");
+       torture_assert_werr_ok(tctx, r.out.result,
+               "AsyncGetPrinterDriverDirectory failed");
+
+       blob = data_blob_const(r.out.pDriverDirectory, pcbNeeded);
+
+       torture_assert(tctx,
+               pull_reg_sz(tctx, &blob, &s),
+               "failed to pull reg_sz");
+
+       torture_comment(tctx, "got: %s\n", s);
+
+       return true;
+}
+
+/*
+ * Test if one can close a printserver handle that has been acquired via
+ * winspool_AsyncOpenPrinter with a spoolss_ClosePrinter operation.
+ */
+
+static bool test_OpenPrinter(struct torture_context *tctx,
+                            void *private_data)
+{
+       struct test_iremotewinspool_context *ctx =
+               talloc_get_type_abort(private_data, struct test_iremotewinspool_context);
+
+       struct dcerpc_pipe *p = ctx->iremotewinspool_pipe;
+       const char *printer_name;
+       struct policy_handle handle;
+       struct dcerpc_pipe *s;
+       struct dcerpc_binding *binding;
+       struct spoolss_UserLevel1 client_info;
+       struct spoolss_ClosePrinter r;
+
+       torture_assert_ntstatus_ok(tctx,
+               torture_rpc_binding(tctx, &binding),
+               "failed to get binding");
+
+       torture_assert_ntstatus_ok(tctx,
+               dcerpc_binding_set_transport(binding, NCACN_NP),
+               "failed to set ncacn_np transport");
+
+       torture_assert_ntstatus_ok(tctx,
+               dcerpc_binding_set_object(binding, GUID_zero()),
+               "failed to set object uuid to zero");
+
+       torture_assert_ntstatus_ok(tctx,
+               torture_rpc_connection_with_binding(tctx, binding, &s, &ndr_table_spoolss),
+               "failed to connect to spoolss");
+
+       printer_name = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
+
+       client_info = test_get_client_info(tctx, WIN_2000, 3, SPOOLSS_MINOR_VERSION_0);
+
+       torture_assert(tctx,
+               test_AsyncOpenPrinter_byprinter(tctx, ctx, p, printer_name, client_info, &handle),
+               "failed to open printserver via winspool");
+
+
+       r.in.handle = &handle;
+       r.out.handle = &handle;
+
+       torture_assert_ntstatus_equal(tctx,
+               dcerpc_spoolss_ClosePrinter_r(s->binding_handle, tctx, &r),
+               NT_STATUS_RPC_SS_CONTEXT_MISMATCH,
+               "ClosePrinter failed");
+
+       talloc_free(s);
+
        return true;
 }
 
@@ -424,7 +1042,23 @@ struct torture_suite *torture_rpc_iremotewinspool(TALLOC_CTX *mem_ctx)
 
        torture_tcase_add_simple_test(tcase, "AsyncOpenPrinter", test_AsyncOpenPrinter);
        torture_tcase_add_simple_test(tcase, "SyncRegisterForRemoteNotifications", test_SyncRegisterForRemoteNotifications);
+       torture_tcase_add_simple_test(tcase, "SyncUnRegisterForRemoteNotifications", test_SyncUnRegisterForRemoteNotifications);
        torture_tcase_add_simple_test(tcase, "AsyncClosePrinter", test_AsyncClosePrinter);
+       torture_tcase_add_simple_test(tcase, "AsyncUploadPrinterDriverPackage", test_AsyncUploadPrinterDriverPackage);
+       torture_tcase_add_simple_test(tcase, "AsyncEnumPrinters", test_AsyncEnumPrinters);
+       torture_tcase_add_simple_test(tcase, "AsyncGetPrinterData", test_AsyncGetPrinterData);
+       torture_tcase_add_simple_test(tcase, "AsyncCorePrinterDriverInstalled", test_AsyncCorePrinterDriverInstalled);
+       torture_tcase_add_simple_test(tcase, "AsyncDeletePrintDriverPackage", test_AsyncDeletePrintDriverPackage);
+       torture_tcase_add_simple_test(tcase, "AsyncGetPrinterDriverDirectory", test_AsyncGetPrinterDriverDirectory);
+       torture_tcase_add_simple_test(tcase, "AsyncOpenPrinterValidateBuildNumber", test_AsyncOpenPrinterValidateBuildNumber);
+
+       tcase = torture_suite_add_tcase(suite, "handles");
+
+       torture_tcase_set_fixture(tcase,
+                                 torture_rpc_iremotewinspool_setup,
+                                 torture_rpc_iremotewinspool_teardown);
+
+       torture_tcase_add_simple_test(tcase, "OpenPrinter", test_OpenPrinter);
 
        return suite;
 }