s4-smbtorture: unify test list to run against single created printers in RPC-SPOOLSS...
[ira/wip.git] / source4 / torture / rpc / spoolss.c
index 5303c942ce557f7eb65f17372432b5c426ea22f3..0c9c076fda35f0884fb49249bd29533f00bdba08 100644 (file)
@@ -951,7 +951,7 @@ static bool test_SetPrinter(struct torture_context *tctx,
        r.in.secdesc_ctr = secdesc_ctr;
        r.in.command = command;
 
-       torture_comment(tctx, "Testing SetPrinter Level %d\n", r.in.info_ctr->level);
+       torture_comment(tctx, "Testing SetPrinter level %d\n", r.in.info_ctr->level);
 
        torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_SetPrinter(p, tctx, &r),
                "failed to call SetPrinter");
@@ -1578,7 +1578,6 @@ static bool test_sd_set_level(struct torture_context *tctx,
                              uint32_t level,
                              struct security_descriptor *sd)
 {
-       struct spoolss_SetPrinter r;
        struct spoolss_SetPrinterInfoCtr info_ctr;
        struct spoolss_DevmodeContainer devmode_ctr;
        struct sec_desc_buf secdesc_ctr;
@@ -1635,14 +1634,8 @@ static bool test_sd_set_level(struct torture_context *tctx,
 
        secdesc_ctr.sd = sd;
 
-       r.in.handle = handle;
-       r.in.info_ctr = &info_ctr;
-       r.in.devmode_ctr = &devmode_ctr;
-       r.in.secdesc_ctr = &secdesc_ctr;
-       r.in.command = 0;
-
-       torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_SetPrinter(p, tctx, &r), "SetPrinter failed");
-       torture_assert_werr_ok(tctx, r.out.result, "SetPrinter failed");
+       torture_assert(tctx,
+               test_SetPrinter(tctx, p, handle, &info_ctr, &devmode_ctr, &secdesc_ctr, 0), "");
 
        return true;
 }
@@ -1652,32 +1645,57 @@ static bool test_PrinterInfo_SDs(struct torture_context *tctx,
                                 struct policy_handle *handle)
 {
        union spoolss_PrinterInfo info;
-       union spoolss_PrinterInfo info_2;
        struct security_descriptor *sd1, *sd2;
        int i;
 
-       /* level 2 */
+       /* just compare level 2 and level 3 */
 
        torture_assert(tctx, test_GetPrinter_level(tctx, p, handle, 2, &info), "");
 
-       sd1 = security_descriptor_copy(tctx, info.info2.secdesc);
+       sd1 = info.info2.secdesc;
 
-       torture_assert(tctx, test_sd_set_level(tctx, p, handle, 2, sd1), "");
+       torture_assert(tctx, test_GetPrinter_level(tctx, p, handle, 3, &info), "");
+
+       sd2 = info.info3.secdesc;
+
+       torture_assert(tctx, test_security_descriptor_equal(tctx, sd1, sd2), "");
+
+
+       /* query level 2, set level 2, query level 2 */
 
-       torture_assert(tctx, test_GetPrinter_level(tctx, p, handle, 2, &info_2), "");
+       torture_assert(tctx, test_GetPrinter_level(tctx, p, handle, 2, &info), "");
+
+       sd1 = info.info2.secdesc;
+
+       torture_assert(tctx, test_sd_set_level(tctx, p, handle, 2, sd1), "");
 
-       sd2 = security_descriptor_copy(tctx, info_2.info2.secdesc);
+       torture_assert(tctx, test_GetPrinter_level(tctx, p, handle, 2, &info), "");
 
+       sd2 = info.info2.secdesc;
        if (sd1->type & SEC_DESC_DACL_DEFAULTED) {
-               torture_comment(tctx, "removing SEC_DESC_DACL_DEFAULTED from 1st for comparison\n");
+               torture_comment(tctx, "removing SEC_DESC_DACL_DEFAULTED\n");
                sd1->type &= ~SEC_DESC_DACL_DEFAULTED;
        }
 
        torture_assert(tctx, test_security_descriptor_equal(tctx, sd1, sd2), "");
 
-       /* level 3 */
 
-       sd1 = sd2;
+       /* query level 2, set level 3, query level 2 */
+
+       torture_assert(tctx, test_GetPrinter_level(tctx, p, handle, 2, &info), "");
+
+       sd1 = info.info2.secdesc;
+
+       torture_assert(tctx, test_sd_set_level(tctx, p, handle, 3, sd1), "");
+
+       torture_assert(tctx, test_GetPrinter_level(tctx, p, handle, 2, &info), "");
+
+       sd2 = info.info2.secdesc;
+
+       torture_assert(tctx, test_security_descriptor_equal(tctx, sd1, sd2), "");
+
+
+       /* set modified sd level 3, query level 2 */
 
        for (i=0; i < 93; i++) {
                struct security_ace a;
@@ -1692,8 +1710,13 @@ static bool test_PrinterInfo_SDs(struct torture_context *tctx,
 
        torture_assert(tctx, test_sd_set_level(tctx, p, handle, 3, sd1), "");
 
-       torture_assert(tctx, test_GetPrinter_level(tctx, p, handle, 2, &info_2), "");
-       sd2 = security_descriptor_copy(tctx, info_2.info2.secdesc);
+       torture_assert(tctx, test_GetPrinter_level(tctx, p, handle, 2, &info), "");
+       sd2 = info.info2.secdesc;
+
+       if (sd1->type & SEC_DESC_DACL_DEFAULTED) {
+               torture_comment(tctx, "removing SEC_DESC_DACL_DEFAULTED\n");
+               sd1->type &= ~SEC_DESC_DACL_DEFAULTED;
+       }
 
        torture_assert(tctx, test_security_descriptor_equal(tctx, sd1, sd2), "");
 
@@ -1709,7 +1732,6 @@ static bool test_PrinterInfo_SD(struct torture_context *tctx,
                                struct policy_handle *handle)
 {
        union spoolss_PrinterInfo info;
-       struct spoolss_SetPrinter r;
        struct spoolss_SetPrinterInfo3 info3;
        struct spoolss_SetPrinterInfoCtr info_ctr;
        struct spoolss_DevmodeContainer devmode_ctr;
@@ -1739,14 +1761,283 @@ static bool test_PrinterInfo_SD(struct torture_context *tctx,
 
        secdesc_ctr.sd = sd;
 
-       r.in.handle = handle;
-       r.in.info_ctr = &info_ctr;
-       r.in.devmode_ctr = &devmode_ctr;
-       r.in.secdesc_ctr = &secdesc_ctr;
-       r.in.command = 0;
+       torture_assert(tctx,
+               test_SetPrinter(tctx, p, handle, &info_ctr, &devmode_ctr, &secdesc_ctr, 0), "");
 
-       torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_SetPrinter(p, tctx, &r), "SetPrinter failed");
-       torture_assert_werr_ok(tctx, r.out.result, "SetPrinter failed");
+       return ret;
+}
+
+static bool test_devmode_set_level(struct torture_context *tctx,
+                                  struct dcerpc_pipe *p,
+                                  struct policy_handle *handle,
+                                  uint32_t level,
+                                  struct spoolss_DeviceMode *devmode)
+{
+       struct spoolss_SetPrinterInfoCtr info_ctr;
+       struct spoolss_DevmodeContainer devmode_ctr;
+       struct sec_desc_buf secdesc_ctr;
+
+       ZERO_STRUCT(devmode_ctr);
+       ZERO_STRUCT(secdesc_ctr);
+
+       switch (level) {
+       case 2: {
+               union spoolss_PrinterInfo info;
+               struct spoolss_SetPrinterInfo2 info2;
+               torture_assert(tctx, test_GetPrinter_level(tctx, p, handle, 2, &info), "");
+
+               info2.servername        = info.info2.servername;
+               info2.printername       = info.info2.printername;
+               info2.sharename         = info.info2.sharename;
+               info2.portname          = info.info2.portname;
+               info2.drivername        = info.info2.drivername;
+               info2.comment           = info.info2.comment;
+               info2.location          = info.info2.location;
+               info2.devmode_ptr       = 0;
+               info2.sepfile           = info.info2.sepfile;
+               info2.printprocessor    = info.info2.printprocessor;
+               info2.datatype          = info.info2.datatype;
+               info2.parameters        = info.info2.parameters;
+               info2.secdesc_ptr       = 0;
+               info2.attributes        = info.info2.attributes;
+               info2.priority          = info.info2.priority;
+               info2.defaultpriority   = info.info2.defaultpriority;
+               info2.starttime         = info.info2.starttime;
+               info2.untiltime         = info.info2.untiltime;
+               info2.status            = info.info2.status;
+               info2.cjobs             = info.info2.cjobs;
+               info2.averageppm        = info.info2.averageppm;
+
+               info_ctr.level = 2;
+               info_ctr.info.info2 = &info2;
+
+               break;
+       }
+       case 8: {
+               struct spoolss_SetPrinterInfo8 info8;
+
+               info8.devmode_ptr = 0;
+
+               info_ctr.level = 8;
+               info_ctr.info.info8 = &info8;
+
+               break;
+       }
+       default:
+               return false;
+       }
+
+       devmode_ctr.devmode = devmode;
+
+       torture_assert(tctx,
+               test_SetPrinter(tctx, p, handle, &info_ctr, &devmode_ctr, &secdesc_ctr, 0), "");
+
+       return true;
+}
+
+
+static bool test_devicemode_equal(struct torture_context *tctx,
+                                 const struct spoolss_DeviceMode *d1,
+                                 const struct spoolss_DeviceMode *d2)
+{
+       if (d1 == d2) {
+               return true;
+       }
+
+       if (!d1 || !d2) {
+               torture_comment(tctx, "%s\n", __location__);
+               return false;
+       }
+       torture_assert_str_equal(tctx, d1->devicename, d2->devicename, "devicename mismatch");
+       torture_assert_int_equal(tctx, d1->specversion, d2->specversion, "specversion mismatch");
+       torture_assert_int_equal(tctx, d1->driverversion, d2->driverversion, "driverversion mismatch");
+       torture_assert_int_equal(tctx, d1->size, d2->size, "size mismatch");
+       torture_assert_int_equal(tctx, d1->__driverextra_length, d2->__driverextra_length, "__driverextra_length mismatch");
+       torture_assert_int_equal(tctx, d1->fields, d2->fields, "fields mismatch");
+       torture_assert_int_equal(tctx, d1->orientation, d2->orientation, "orientation mismatch");
+       torture_assert_int_equal(tctx, d1->papersize, d2->papersize, "papersize mismatch");
+       torture_assert_int_equal(tctx, d1->paperlength, d2->paperlength, "paperlength mismatch");
+       torture_assert_int_equal(tctx, d1->paperwidth, d2->paperwidth, "paperwidth mismatch");
+       torture_assert_int_equal(tctx, d1->scale, d2->scale, "scale mismatch");
+       torture_assert_int_equal(tctx, d1->copies, d2->copies, "copies mismatch");
+       torture_assert_int_equal(tctx, d1->defaultsource, d2->defaultsource, "defaultsource mismatch");
+       torture_assert_int_equal(tctx, d1->printquality, d2->printquality, "printquality mismatch");
+       torture_assert_int_equal(tctx, d1->color, d2->color, "color mismatch");
+       torture_assert_int_equal(tctx, d1->duplex, d2->duplex, "duplex mismatch");
+       torture_assert_int_equal(tctx, d1->yresolution, d2->yresolution, "yresolution mismatch");
+       torture_assert_int_equal(tctx, d1->ttoption, d2->ttoption, "ttoption mismatch");
+       torture_assert_int_equal(tctx, d1->collate, d2->collate, "collate mismatch");
+       torture_assert_str_equal(tctx, d1->formname, d2->formname, "formname mismatch");
+       torture_assert_int_equal(tctx, d1->logpixels, d2->logpixels, "logpixels mismatch");
+       torture_assert_int_equal(tctx, d1->bitsperpel, d2->bitsperpel, "bitsperpel mismatch");
+       torture_assert_int_equal(tctx, d1->pelswidth, d2->pelswidth, "pelswidth mismatch");
+       torture_assert_int_equal(tctx, d1->pelsheight, d2->pelsheight, "pelsheight mismatch");
+       torture_assert_int_equal(tctx, d1->displayflags, d2->displayflags, "displayflags mismatch");
+       torture_assert_int_equal(tctx, d1->displayfrequency, d2->displayfrequency, "displayfrequency mismatch");
+       torture_assert_int_equal(tctx, d1->icmmethod, d2->icmmethod, "icmmethod mismatch");
+       torture_assert_int_equal(tctx, d1->icmintent, d2->icmintent, "icmintent mismatch");
+       torture_assert_int_equal(tctx, d1->mediatype, d2->mediatype, "mediatype mismatch");
+       torture_assert_int_equal(tctx, d1->dithertype, d2->dithertype, "dithertype mismatch");
+       torture_assert_int_equal(tctx, d1->reserved1, d2->reserved1, "reserved1 mismatch");
+       torture_assert_int_equal(tctx, d1->reserved2, d2->reserved2, "reserved2 mismatch");
+       torture_assert_int_equal(tctx, d1->panningwidth, d2->panningwidth, "panningwidth mismatch");
+       torture_assert_int_equal(tctx, d1->panningheight, d2->panningheight, "panningheight mismatch");
+       torture_assert_data_blob_equal(tctx, d1->driverextra_data, d2->driverextra_data, "driverextra_data mismatch");
+
+       return true;
+}
+
+static bool call_OpenPrinterEx(struct torture_context *tctx,
+                              struct dcerpc_pipe *p,
+                              const char *name,
+                              struct spoolss_DeviceMode *devmode,
+                              struct policy_handle *handle);
+
+static bool test_ClosePrinter(struct torture_context *tctx,
+                             struct dcerpc_pipe *p,
+                             struct policy_handle *handle);
+
+static bool test_PrinterInfo_DevModes(struct torture_context *tctx,
+                                     struct dcerpc_pipe *p,
+                                     struct policy_handle *handle,
+                                     const char *name)
+{
+       union spoolss_PrinterInfo info;
+       struct spoolss_DeviceMode *devmode;
+       struct spoolss_DeviceMode *devmode2;
+       struct policy_handle handle_devmode;
+
+       /* simply compare level8 and level2 devmode */
+
+       torture_assert(tctx, test_GetPrinter_level(tctx, p, handle, 8, &info), "");
+
+       devmode = info.info8.devmode;
+
+       torture_assert(tctx, test_GetPrinter_level(tctx, p, handle, 2, &info), "");
+
+       devmode2 = info.info2.devmode;
+
+       torture_assert(tctx, test_devicemode_equal(tctx, devmode, devmode2), "");
+
+
+       /* change formname upon open and see if it persists in getprinter calls */
+
+       devmode->formname = talloc_strdup(tctx, "A4");
+
+       torture_assert(tctx, call_OpenPrinterEx(tctx, p, name, devmode, &handle_devmode),
+               "failed to open printer handle");
+
+       torture_assert(tctx, test_GetPrinter_level(tctx, p, &handle_devmode, 8, &info), "");
+
+       devmode2 = info.info8.devmode;
+
+       if (strequal(devmode->devicename, devmode2->devicename)) {
+               torture_fail(tctx, "devicename is the same");
+       }
+
+       if (strequal(devmode->formname, devmode2->formname)) {
+               torture_fail(tctx, "formname is the same");
+       }
+
+       torture_assert(tctx, test_GetPrinter_level(tctx, p, &handle_devmode, 2, &info), "");
+
+       devmode2 = info.info2.devmode;
+
+       if (strequal(devmode->devicename, devmode2->devicename)) {
+               torture_fail(tctx, "devicename is the same");
+       }
+
+       if (strequal(devmode->formname, devmode2->formname)) {
+               torture_fail(tctx, "formname is the same");
+       }
+
+       test_ClosePrinter(tctx, p, &handle_devmode);
+
+
+       /* set devicemode level 8 and see if it persists */
+
+       devmode->copies = 93;
+       devmode->formname = talloc_strdup(tctx, "Legal");
+
+       torture_assert(tctx, test_devmode_set_level(tctx, p, handle, 8, devmode), "");
+
+       torture_assert(tctx, test_GetPrinter_level(tctx, p, handle, 8, &info), "");
+
+       devmode2 = info.info8.devmode;
+
+       torture_assert(tctx, test_devicemode_equal(tctx, devmode, devmode2), "");
+
+       torture_assert(tctx, test_GetPrinter_level(tctx, p, handle, 2, &info), "");
+
+       devmode2 = info.info2.devmode;
+
+       torture_assert(tctx, test_devicemode_equal(tctx, devmode, devmode2), "");
+
+
+       /* set devicemode level 2 and see if it persists */
+
+       devmode->copies = 39;
+       devmode->formname = talloc_strdup(tctx, "Letter");
+
+       torture_assert(tctx, test_devmode_set_level(tctx, p, handle, 8, devmode), "");
+
+       torture_assert(tctx, test_GetPrinter_level(tctx, p, handle, 8, &info), "");
+
+       devmode2 = info.info8.devmode;
+
+       torture_assert(tctx, test_devicemode_equal(tctx, devmode, devmode2), "");
+
+       torture_assert(tctx, test_GetPrinter_level(tctx, p, handle, 2, &info), "");
+
+       devmode2 = info.info2.devmode;
+
+       torture_assert(tctx, test_devicemode_equal(tctx, devmode, devmode2), "");
+
+
+       return true;
+}
+
+/*
+ * wrapper call that saves original devmode, runs tests, and restores devmode
+ */
+
+static bool test_PrinterInfo_DevMode(struct torture_context *tctx,
+                                    struct dcerpc_pipe *p,
+                                    struct policy_handle *handle,
+                                    const char *name)
+{
+       union spoolss_PrinterInfo info;
+       struct spoolss_SetPrinterInfo8 info8;
+       struct spoolss_SetPrinterInfoCtr info_ctr;
+       struct spoolss_DevmodeContainer devmode_ctr;
+       struct sec_desc_buf secdesc_ctr;
+       struct spoolss_DeviceMode *devmode;
+       bool ret = true;
+
+       /* save original devmode */
+
+       torture_assert(tctx, test_GetPrinter_level(tctx, p, handle, 8, &info), "");
+
+       devmode = info.info8.devmode;
+
+       /* run tests */
+
+       ret = test_PrinterInfo_DevModes(tctx, p, handle, name);
+
+       /* restore original devmode */
+
+       ZERO_STRUCT(devmode_ctr);
+       ZERO_STRUCT(secdesc_ctr);
+
+       info8.devmode_ptr = 0;
+
+       info_ctr.level = 8;
+       info_ctr.info.info8 = &info8;
+
+       devmode_ctr.devmode = devmode;
+
+       torture_assert(tctx,
+               test_SetPrinter(tctx, p, handle, &info_ctr, &devmode_ctr, &secdesc_ctr, 0), "");
 
        return ret;
 }
@@ -3209,7 +3500,9 @@ static bool test_OpenPrinter(struct torture_context *tctx,
 
 static bool call_OpenPrinterEx(struct torture_context *tctx,
                               struct dcerpc_pipe *p,
-                              const char *name, struct policy_handle *handle)
+                              const char *name,
+                              struct spoolss_DeviceMode *devmode,
+                              struct policy_handle *handle)
 {
        struct spoolss_OpenPrinterEx r;
        struct spoolss_UserLevel1 userlevel1;
@@ -3224,7 +3517,7 @@ static bool call_OpenPrinterEx(struct torture_context *tctx,
        }
 
        r.in.datatype           = NULL;
-       r.in.devmode_ctr.devmode= NULL;
+       r.in.devmode_ctr.devmode= devmode;
        r.in.access_mask        = SEC_FLAG_MAXIMUM_ALLOWED;
        r.in.level              = 1;
        r.in.userlevel.level1   = &userlevel1;
@@ -3256,7 +3549,7 @@ static bool test_OpenPrinterEx(struct torture_context *tctx,
        struct policy_handle handle;
        bool ret = true;
 
-       if (!call_OpenPrinterEx(tctx, p, name, &handle)) {
+       if (!call_OpenPrinterEx(tctx, p, name, NULL, &handle)) {
                return false;
        }
 
@@ -3785,7 +4078,7 @@ static bool test_AddPrinter_normal(struct torture_context *tctx,
        if (W_ERROR_EQUAL(result, WERR_PRINTER_ALREADY_EXISTS)) {
                struct policy_handle printer_handle;
 
-               torture_assert(tctx, call_OpenPrinterEx(tctx, p, printername, &printer_handle),
+               torture_assert(tctx, call_OpenPrinterEx(tctx, p, printername, NULL, &printer_handle),
                        "failed to open printer handle");
 
                torture_assert(tctx, test_DeletePrinter(tctx, p, &printer_handle),
@@ -4029,6 +4322,32 @@ bool test_printer_keys(struct torture_context *tctx,
        return true;
 }
 
+static bool test_one_printer(struct torture_context *tctx,
+                            struct dcerpc_pipe *p,
+                            struct policy_handle *handle,
+                            const char *name)
+{
+       bool ret = true;
+
+       if (!test_printer_info(tctx, p, handle)) {
+               ret = false;
+       }
+
+       if (!test_PrinterInfo_SD(tctx, p, handle)) {
+               ret = false;
+       }
+
+       if (!test_PrinterInfo_DevMode(tctx, p, handle, name)) {
+               ret = false;
+       }
+
+       if (!test_printer_keys(tctx, p, handle)) {
+               ret = false;
+       }
+
+       return ret;
+}
+
 static bool test_printer(struct torture_context *tctx,
                         struct dcerpc_pipe *p)
 {
@@ -4044,15 +4363,7 @@ static bool test_printer(struct torture_context *tctx,
                return false;
        }
 
-       if (!test_printer_info(tctx, p, &handle[0])) {
-               ret = false;
-       }
-
-       if (!test_PrinterInfo_SD(tctx, p, &handle[0])) {
-               ret = false;
-       }
-
-       if (!test_printer_keys(tctx, p, &handle[0])) {
+       if (!test_one_printer(tctx, p, &handle[0], TORTURE_PRINTER)) {
                ret = false;
        }
 
@@ -4073,11 +4384,7 @@ static bool test_printer(struct torture_context *tctx,
                return false;
        }
 
-       if (!test_printer_info(tctx, p, &handle[1])) {
-               ret = false;
-       }
-
-       if (!test_printer_keys(tctx, p, &handle[1])) {
+       if (!test_one_printer(tctx, p, &handle[1], TORTURE_PRINTER_EX)) {
                ret = false;
        }