+ r.in.handle = handle;
+ r.in.level = 1;
+ r.in.info.info1 = &addform;
+ addform.flags = SPOOLSS_FORM_USER;
+ addform.form_name = form_name;
+ addform.size.width = 50;
+ addform.size.height = 25;
+ addform.area.left = 5;
+ addform.area.top = 10;
+ addform.area.right = 45;
+ addform.area.bottom = 15;
+
+ status = dcerpc_spoolss_AddForm(p, tctx, &r);
+
+ torture_assert_ntstatus_ok(tctx, status, "AddForm failed");
+
+ torture_assert_werr_ok(tctx, r.out.result, "AddForm failed");
+
+ if (!print_server) ret &= test_GetForm(tctx, p, handle, form_name, 1);
+
+ {
+ struct spoolss_SetForm sf;
+ struct spoolss_AddFormInfo1 setform;
+
+ sf.in.handle = handle;
+ sf.in.form_name = form_name;
+ sf.in.level = 1;
+ sf.in.info.info1= &setform;
+ setform.flags = addform.flags;
+ setform.form_name = addform.form_name;
+ setform.size = addform.size;
+ setform.area = addform.area;
+
+ setform.size.width = 1234;
+
+ status = dcerpc_spoolss_SetForm(p, tctx, &sf);
+
+ torture_assert_ntstatus_ok(tctx, status, "SetForm failed");
+
+ torture_assert_werr_ok(tctx, r.out.result, "SetForm failed");
+ }
+
+ if (!print_server) ret &= test_GetForm(tctx, p, handle, form_name, 1);
+
+ {
+ struct spoolss_EnumForms e;
+ union spoolss_FormInfo *info;
+ uint32_t needed;
+ uint32_t count;
+ bool found = false;
+
+ e.in.handle = handle;
+ e.in.level = 1;
+ e.in.buffer = NULL;
+ e.in.offered = 0;
+ e.out.needed = &needed;
+ e.out.count = &count;
+ e.out.info = &info;
+
+ torture_comment(tctx, "Testing EnumForms level 1\n");
+
+ status = dcerpc_spoolss_EnumForms(p, tctx, &e);
+ torture_assert_ntstatus_ok(tctx, status, "EnumForms failed");
+
+ if (print_server && W_ERROR_EQUAL(e.out.result, WERR_BADFID))
+ torture_fail(tctx, "EnumForms on the PrintServer isn't supported by test server (NT4)");
+
+ if (W_ERROR_EQUAL(e.out.result, WERR_INSUFFICIENT_BUFFER)) {
+ int j;
+ DATA_BLOB blob = data_blob_talloc(tctx, NULL, needed);
+ data_blob_clear(&blob);
+ e.in.buffer = &blob;
+ e.in.offered = needed;
+
+ status = dcerpc_spoolss_EnumForms(p, tctx, &e);
+
+ torture_assert(tctx, info, "No forms returned");
+
+ for (j = 0; j < count; j++) {
+ if (strequal(form_name, info[j].info1.form_name)) {
+ found = true;
+ break;
+ }
+ }
+ }
+ torture_assert(tctx, found, "Newly added form not found in enum call");
+ }
+
+ if (!test_DeleteForm(tctx, p, handle, form_name)) {
+ ret = false;
+ }
+
+ return ret;
+}
+
+static bool test_EnumPorts_old(struct torture_context *tctx,
+ struct dcerpc_pipe *p)
+{
+ NTSTATUS status;
+ struct spoolss_EnumPorts r;
+ uint32_t needed;
+ uint32_t count;
+ union spoolss_PortInfo *info;
+
+ r.in.servername = talloc_asprintf(tctx, "\\\\%s",
+ dcerpc_server_name(p));
+ r.in.level = 2;
+ r.in.buffer = NULL;
+ r.in.offered = 0;
+ r.out.needed = &needed;
+ r.out.count = &count;
+ r.out.info = &info;
+
+ torture_comment(tctx, "Testing EnumPorts\n");
+
+ status = dcerpc_spoolss_EnumPorts(p, tctx, &r);
+
+ torture_assert_ntstatus_ok(tctx, status, "EnumPorts failed");
+
+ if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
+ DATA_BLOB blob = data_blob_talloc(tctx, NULL, needed);
+ data_blob_clear(&blob);
+ r.in.buffer = &blob;
+ r.in.offered = needed;
+
+ status = dcerpc_spoolss_EnumPorts(p, tctx, &r);
+ torture_assert_ntstatus_ok(tctx, status, "EnumPorts failed");
+ torture_assert_werr_ok(tctx, r.out.result, "EnumPorts failed");
+
+ torture_assert(tctx, info, "No ports returned");
+ }
+
+ torture_assert_werr_ok(tctx, r.out.result, "EnumPorts failed");
+
+ CHECK_NEEDED_SIZE_ENUM_LEVEL(spoolss_EnumPorts, info, 2, count, lp_iconv_convenience(tctx->lp_ctx), needed, 4);
+
+ return true;
+}
+
+static bool test_AddPort(struct torture_context *tctx,
+ struct dcerpc_pipe *p)
+{
+ NTSTATUS status;
+ struct spoolss_AddPort r;
+
+ r.in.server_name = talloc_asprintf(tctx, "\\\\%s",
+ dcerpc_server_name(p));
+ r.in.unknown = 0;
+ r.in.monitor_name = "foo";
+
+ torture_comment(tctx, "Testing AddPort\n");
+
+ status = dcerpc_spoolss_AddPort(p, tctx, &r);
+
+ torture_assert_ntstatus_ok(tctx, status, "AddPort failed");
+
+ /* win2k3 returns WERR_NOT_SUPPORTED */
+
+#if 0
+
+ if (!W_ERROR_IS_OK(r.out.result)) {
+ printf("AddPort failed - %s\n", win_errstr(r.out.result));
+ return false;
+ }
+
+#endif
+
+ return true;
+}
+
+static bool test_GetJob(struct torture_context *tctx,
+ struct dcerpc_pipe *p,
+ struct policy_handle *handle, uint32_t job_id)
+{
+ NTSTATUS status;
+ struct spoolss_GetJob r;
+ union spoolss_JobInfo info;
+ uint32_t needed;
+ uint32_t levels[] = {1, 2 /* 3, 4 */};
+ uint32_t i;
+
+ r.in.handle = handle;
+ r.in.job_id = job_id;
+ r.in.level = 0;
+ r.in.buffer = NULL;
+ r.in.offered = 0;
+ r.out.needed = &needed;
+ r.out.info = &info;
+
+ torture_comment(tctx, "Testing GetJob level %d\n", r.in.level);
+
+ status = dcerpc_spoolss_GetJob(p, tctx, &r);
+ torture_assert_werr_equal(tctx, r.out.result, WERR_UNKNOWN_LEVEL, "Unexpected return code");
+
+ for (i = 0; i < ARRAY_SIZE(levels); i++) {
+
+ torture_comment(tctx, "Testing GetJob level %d\n", r.in.level);
+
+ needed = 0;
+
+ r.in.level = levels[i];
+ r.in.offered = 0;
+ r.in.buffer = NULL;
+
+ status = dcerpc_spoolss_GetJob(p, tctx, &r);
+ torture_assert_ntstatus_ok(tctx, status, "GetJob failed");
+
+ if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
+ DATA_BLOB blob = data_blob_talloc(tctx, NULL, needed);
+ data_blob_clear(&blob);
+ r.in.buffer = &blob;
+ r.in.offered = needed;
+
+ status = dcerpc_spoolss_GetJob(p, tctx, &r);
+ torture_assert_ntstatus_ok(tctx, status, "GetJob failed");
+
+ }
+ torture_assert(tctx, r.out.info, "No job info returned");
+ torture_assert_werr_ok(tctx, r.out.result, "GetJob failed");
+
+ CHECK_NEEDED_SIZE_LEVEL(spoolss_JobInfo, r.out.info, r.in.level, lp_iconv_convenience(tctx->lp_ctx), needed, 4);
+ }
+
+ return true;
+}
+
+static bool test_SetJob(struct torture_context *tctx,
+ struct dcerpc_pipe *p,
+ struct policy_handle *handle, uint32_t job_id,
+ enum spoolss_JobControl command)
+{
+ NTSTATUS status;
+ struct spoolss_SetJob r;
+
+ r.in.handle = handle;
+ r.in.job_id = job_id;
+ r.in.ctr = NULL;
+ r.in.command = command;
+
+ switch (command) {
+ case SPOOLSS_JOB_CONTROL_PAUSE:
+ torture_comment(tctx, "Testing SetJob: SPOOLSS_JOB_CONTROL_PAUSE\n");
+ break;
+ case SPOOLSS_JOB_CONTROL_RESUME:
+ torture_comment(tctx, "Testing SetJob: SPOOLSS_JOB_CONTROL_RESUME\n");
+ break;
+ case SPOOLSS_JOB_CONTROL_CANCEL:
+ torture_comment(tctx, "Testing SetJob: SPOOLSS_JOB_CONTROL_CANCEL\n");
+ break;
+ case SPOOLSS_JOB_CONTROL_RESTART:
+ torture_comment(tctx, "Testing SetJob: SPOOLSS_JOB_CONTROL_RESTART\n");
+ break;
+ case SPOOLSS_JOB_CONTROL_DELETE:
+ torture_comment(tctx, "Testing SetJob: SPOOLSS_JOB_CONTROL_DELETE\n");
+ break;
+ case SPOOLSS_JOB_CONTROL_SEND_TO_PRINTER:
+ torture_comment(tctx, "Testing SetJob: SPOOLSS_JOB_CONTROL_SEND_TO_PRINTER\n");
+ break;
+ case SPOOLSS_JOB_CONTROL_LAST_PAGE_EJECTED:
+ torture_comment(tctx, "Testing SetJob: SPOOLSS_JOB_CONTROL_LAST_PAGE_EJECTED\n");
+ break;
+ case SPOOLSS_JOB_CONTROL_RETAIN:
+ torture_comment(tctx, "Testing SetJob: SPOOLSS_JOB_CONTROL_RETAIN\n");
+ break;
+ case SPOOLSS_JOB_CONTROL_RELEASE:
+ torture_comment(tctx, "Testing SetJob: SPOOLSS_JOB_CONTROL_RELEASE\n");
+ break;
+ default:
+ torture_comment(tctx, "Testing SetJob\n");
+ break;
+ }
+
+ status = dcerpc_spoolss_SetJob(p, tctx, &r);
+ torture_assert_ntstatus_ok(tctx, status, "SetJob failed");
+ torture_assert_werr_ok(tctx, r.out.result, "SetJob failed");
+
+ return true;
+}
+
+static bool test_AddJob(struct torture_context *tctx,
+ struct dcerpc_pipe *p,
+ struct policy_handle *handle)
+{
+ NTSTATUS status;
+ struct spoolss_AddJob r;
+ uint32_t needed;
+
+ r.in.level = 0;
+ r.in.handle = handle;
+ r.in.offered = 0;
+ r.out.needed = &needed;
+ r.in.buffer = r.out.buffer = NULL;
+
+ torture_comment(tctx, "Testing AddJob\n");
+
+ status = dcerpc_spoolss_AddJob(p, tctx, &r);
+ torture_assert_werr_equal(tctx, r.out.result, WERR_UNKNOWN_LEVEL, "AddJob failed");
+
+ r.in.level = 1;
+
+ status = dcerpc_spoolss_AddJob(p, tctx, &r);
+ torture_assert_werr_equal(tctx, r.out.result, WERR_INVALID_PARAM, "AddJob failed");
+
+ return true;
+}
+
+
+static bool test_EnumJobs(struct torture_context *tctx,
+ struct dcerpc_pipe *p,
+ struct policy_handle *handle)
+{
+ NTSTATUS status;
+ struct spoolss_EnumJobs r;
+ uint32_t needed;
+ uint32_t count;
+ union spoolss_JobInfo *info;
+
+ r.in.handle = handle;
+ r.in.firstjob = 0;
+ r.in.numjobs = 0xffffffff;
+ r.in.level = 1;
+ r.in.buffer = NULL;
+ r.in.offered = 0;
+ r.out.needed = &needed;
+ r.out.count = &count;
+ r.out.info = &info;
+
+ torture_comment(tctx, "Testing EnumJobs\n");
+
+ status = dcerpc_spoolss_EnumJobs(p, tctx, &r);
+
+ torture_assert_ntstatus_ok(tctx, status, "EnumJobs failed");
+
+ if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
+ int j;
+ DATA_BLOB blob = data_blob_talloc(tctx, NULL, needed);
+ data_blob_clear(&blob);
+ r.in.buffer = &blob;
+ r.in.offered = needed;
+
+ status = dcerpc_spoolss_EnumJobs(p, tctx, &r);
+
+ torture_assert_ntstatus_ok(tctx, status, "EnumJobs failed");
+ torture_assert_werr_ok(tctx, r.out.result, "EnumJobs failed");
+ torture_assert(tctx, info, "No jobs returned");
+
+ CHECK_NEEDED_SIZE_ENUM_LEVEL(spoolss_EnumJobs, *r.out.info, r.in.level, count, lp_iconv_convenience(tctx->lp_ctx), needed, 4);
+
+ for (j = 0; j < count; j++) {
+
+ torture_assert(tctx, test_GetJob(tctx, p, handle, info[j].info1.job_id),
+ "failed to call test_GetJob");
+
+ /* FIXME - gd */
+ if (!torture_setting_bool(tctx, "samba3", false)) {
+ test_SetJob(tctx, p, handle, info[j].info1.job_id, SPOOLSS_JOB_CONTROL_PAUSE);
+ test_SetJob(tctx, p, handle, info[j].info1.job_id, SPOOLSS_JOB_CONTROL_RESUME);
+ }
+ }
+
+ } else {
+ torture_assert_werr_ok(tctx, r.out.result, "EnumJobs failed");
+ }
+
+ return true;
+}
+
+static bool test_DoPrintTest(struct torture_context *tctx,
+ struct dcerpc_pipe *p,
+ struct policy_handle *handle)
+{
+ bool ret = true;
+ NTSTATUS status;
+ struct spoolss_StartDocPrinter s;
+ struct spoolss_DocumentInfo1 info1;
+ struct spoolss_StartPagePrinter sp;
+ struct spoolss_WritePrinter w;
+ struct spoolss_EndPagePrinter ep;
+ struct spoolss_EndDocPrinter e;
+ int i;
+ uint32_t job_id;
+ uint32_t num_written;
+
+ torture_comment(tctx, "Testing StartDocPrinter\n");
+
+ s.in.handle = handle;
+ s.in.level = 1;
+ s.in.info.info1 = &info1;
+ s.out.job_id = &job_id;
+ info1.document_name = "TorturePrintJob";
+ info1.output_file = NULL;
+ info1.datatype = "RAW";
+
+ status = dcerpc_spoolss_StartDocPrinter(p, tctx, &s);
+ torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_StartDocPrinter failed");
+ torture_assert_werr_ok(tctx, s.out.result, "StartDocPrinter failed");
+
+ for (i=1; i < 4; i++) {
+ torture_comment(tctx, "Testing StartPagePrinter: Page[%d]\n", i);
+
+ sp.in.handle = handle;
+
+ status = dcerpc_spoolss_StartPagePrinter(p, tctx, &sp);
+ torture_assert_ntstatus_ok(tctx, status,
+ "dcerpc_spoolss_StartPagePrinter failed");
+ torture_assert_werr_ok(tctx, sp.out.result, "StartPagePrinter failed");
+
+ torture_comment(tctx, "Testing WritePrinter: Page[%d]\n", i);
+
+ w.in.handle = handle;
+ w.in.data = data_blob_string_const(talloc_asprintf(tctx,"TortureTestPage: %d\nData\n",i));
+ w.out.num_written = &num_written;
+
+ status = dcerpc_spoolss_WritePrinter(p, tctx, &w);
+ torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_WritePrinter failed");
+ torture_assert_werr_ok(tctx, w.out.result, "WritePrinter failed");
+
+ torture_comment(tctx, "Testing EndPagePrinter: Page[%d]\n", i);
+
+ ep.in.handle = handle;
+
+ status = dcerpc_spoolss_EndPagePrinter(p, tctx, &ep);
+ torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EndPagePrinter failed");
+ torture_assert_werr_ok(tctx, ep.out.result, "EndPagePrinter failed");
+ }
+
+ torture_comment(tctx, "Testing EndDocPrinter\n");
+
+ e.in.handle = handle;
+
+ status = dcerpc_spoolss_EndDocPrinter(p, tctx, &e);
+ torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EndDocPrinter failed");
+ torture_assert_werr_ok(tctx, e.out.result, "EndDocPrinter failed");
+
+ ret &= test_AddJob(tctx, p, handle);
+ ret &= test_EnumJobs(tctx, p, handle);
+
+ ret &= test_SetJob(tctx, p, handle, job_id, SPOOLSS_JOB_CONTROL_DELETE);
+
+ return ret;
+}
+
+static bool test_PausePrinter(struct torture_context *tctx,
+ struct dcerpc_pipe *p,
+ struct policy_handle *handle)
+{
+ NTSTATUS status;
+ struct spoolss_SetPrinter r;
+ struct spoolss_SetPrinterInfoCtr info_ctr;
+ struct spoolss_DevmodeContainer devmode_ctr;
+ struct sec_desc_buf secdesc_ctr;
+
+ info_ctr.level = 0;
+ info_ctr.info.info0 = NULL;
+
+ ZERO_STRUCT(devmode_ctr);
+ ZERO_STRUCT(secdesc_ctr);
+
+ 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 = SPOOLSS_PRINTER_CONTROL_PAUSE;
+
+ torture_comment(tctx, "Testing SetPrinter: SPOOLSS_PRINTER_CONTROL_PAUSE\n");
+
+ status = dcerpc_spoolss_SetPrinter(p, tctx, &r);
+
+ torture_assert_ntstatus_ok(tctx, status, "SetPrinter failed");
+
+ torture_assert_werr_ok(tctx, r.out.result, "SetPrinter failed");
+
+ return true;
+}
+
+static bool test_ResumePrinter(struct torture_context *tctx,
+ struct dcerpc_pipe *p,
+ struct policy_handle *handle)
+{
+ NTSTATUS status;
+ struct spoolss_SetPrinter r;
+ struct spoolss_SetPrinterInfoCtr info_ctr;
+ struct spoolss_DevmodeContainer devmode_ctr;
+ struct sec_desc_buf secdesc_ctr;
+
+ info_ctr.level = 0;
+ info_ctr.info.info0 = NULL;
+
+ ZERO_STRUCT(devmode_ctr);
+ ZERO_STRUCT(secdesc_ctr);
+
+ 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 = SPOOLSS_PRINTER_CONTROL_RESUME;
+
+ torture_comment(tctx, "Testing SetPrinter: SPOOLSS_PRINTER_CONTROL_RESUME\n");
+
+ status = dcerpc_spoolss_SetPrinter(p, tctx, &r);
+
+ torture_assert_ntstatus_ok(tctx, status, "SetPrinter failed");
+
+ torture_assert_werr_ok(tctx, r.out.result, "SetPrinter failed");
+
+ return true;
+}
+
+static bool test_GetPrinterData(struct torture_context *tctx,
+ struct dcerpc_pipe *p,
+ struct policy_handle *handle,
+ const char *value_name,
+ enum winreg_Type *type_p,
+ union spoolss_PrinterData *data_p)
+{
+ NTSTATUS status;
+ struct spoolss_GetPrinterData r;
+ uint32_t needed;
+ enum winreg_Type type;
+ union spoolss_PrinterData data;
+
+ r.in.handle = handle;
+ r.in.value_name = value_name;
+ r.in.offered = 0;
+ r.out.needed = &needed;
+ r.out.type = &type;
+ r.out.data = &data;
+
+ torture_comment(tctx, "Testing GetPrinterData(%s)\n", r.in.value_name);
+
+ status = dcerpc_spoolss_GetPrinterData(p, tctx, &r);
+ torture_assert_ntstatus_ok(tctx, status, "GetPrinterData failed");
+
+ if (W_ERROR_EQUAL(r.out.result, WERR_MORE_DATA)) {
+ r.in.offered = needed;
+
+ status = dcerpc_spoolss_GetPrinterData(p, tctx, &r);
+ torture_assert_ntstatus_ok(tctx, status, "GetPrinterData failed");
+ }
+
+ torture_assert_werr_ok(tctx, r.out.result,
+ talloc_asprintf(tctx, "GetPrinterData(%s) failed", r.in.value_name));
+
+ CHECK_NEEDED_SIZE_LEVEL(spoolss_PrinterData, &data, type, lp_iconv_convenience(tctx->lp_ctx), needed, 1);
+
+ if (type_p) {
+ *type_p = type;
+ }
+
+ if (data_p) {
+ *data_p = data;
+ }
+
+ return true;
+}
+
+static bool test_GetPrinterDataEx(struct torture_context *tctx,
+ struct dcerpc_pipe *p,
+ struct policy_handle *handle,
+ const char *key_name,
+ const char *value_name,
+ enum winreg_Type *type_p,
+ union spoolss_PrinterData *data_p)
+{
+ NTSTATUS status;
+ struct spoolss_GetPrinterDataEx r;
+ enum winreg_Type type;
+ uint32_t needed;
+ union spoolss_PrinterData data;
+
+ r.in.handle = handle;
+ r.in.key_name = key_name;
+ r.in.value_name = value_name;
+ r.in.offered = 0;
+ r.out.type = &type;
+ r.out.needed = &needed;
+ r.out.data = &data;
+
+ torture_comment(tctx, "Testing GetPrinterDataEx(%s - %s)\n",
+ r.in.key_name, r.in.value_name);
+
+ status = dcerpc_spoolss_GetPrinterDataEx(p, tctx, &r);
+ if (!NT_STATUS_IS_OK(status)) {
+ if (NT_STATUS_EQUAL(status,NT_STATUS_NET_WRITE_FAULT) &&
+ p->last_fault_code == DCERPC_FAULT_OP_RNG_ERROR) {
+ torture_skip(tctx, "GetPrinterDataEx not supported by server\n");
+ }
+ torture_assert_ntstatus_ok(tctx, status, "GetPrinterDataEx failed");
+ }
+
+ if (W_ERROR_EQUAL(r.out.result, WERR_MORE_DATA)) {
+ r.in.offered = needed;
+ status = dcerpc_spoolss_GetPrinterDataEx(p, tctx, &r);
+ torture_assert_ntstatus_ok(tctx, status, "GetPrinterDataEx failed");
+ }
+
+ torture_assert_werr_ok(tctx, r.out.result,
+ talloc_asprintf(tctx, "GetPrinterDataEx(%s - %s) failed", r.in.key_name, r.in.value_name));
+
+ CHECK_NEEDED_SIZE_LEVEL(spoolss_PrinterData, &data, type, lp_iconv_convenience(tctx->lp_ctx), needed, 1);
+
+ if (type_p) {
+ *type_p = type;
+ }
+
+ if (data_p) {
+ *data_p = data;
+ }
+
+ return true;
+}
+
+static bool test_GetPrinterData_list(struct torture_context *tctx,
+ struct dcerpc_pipe *p,
+ struct policy_handle *handle)
+{
+ const char *list[] = {
+ "W3SvcInstalled",
+ "BeepEnabled",
+ "EventLog",
+ /* "NetPopup", not on w2k8 */
+ /* "NetPopupToComputer", not on w2k8 */
+ "MajorVersion",
+ "MinorVersion",
+ "DefaultSpoolDirectory",
+ "Architecture",
+ "DsPresent",
+ "OSVersion",
+ /* "OSVersionEx", not on s3 */
+ "DNSMachineName"
+ };
+ int i;
+
+ for (i=0; i < ARRAY_SIZE(list); i++) {
+ enum winreg_Type type, type_ex;
+ union spoolss_PrinterData data, data_ex;
+
+ torture_assert(tctx, test_GetPrinterData(tctx, p, handle, list[i], &type, &data),
+ talloc_asprintf(tctx, "GetPrinterData failed on %s\n", list[i]));
+ torture_assert(tctx, test_GetPrinterDataEx(tctx, p, handle, "random_string", list[i], &type_ex, &data_ex),
+ talloc_asprintf(tctx, "GetPrinterDataEx failed on %s\n", list[i]));
+ torture_assert_int_equal(tctx, type, type_ex, "type mismatch");
+ switch (type) {
+ case REG_SZ:
+ torture_assert_str_equal(tctx, data.string, data_ex.string, "REG_SZ mismatch");
+ break;
+ case REG_DWORD:
+ torture_assert_int_equal(tctx, data.value, data_ex.value, "REG_DWORD mismatch");
+ break;
+ case REG_BINARY:
+ torture_assert_data_blob_equal(tctx, data.binary, data_ex.binary, "REG_BINARY mismatch");
+ break;
+ default:
+ break;
+ }
+ }
+
+ return true;
+}
+
+static bool test_EnumPrinterData(struct torture_context *tctx, struct dcerpc_pipe *p,
+ struct policy_handle *handle)
+{
+ NTSTATUS status;
+ struct spoolss_EnumPrinterData r;
+
+ ZERO_STRUCT(r);
+ r.in.handle = handle;
+ r.in.enum_index = 0;
+
+ do {
+ uint32_t value_size = 0;
+ uint32_t data_size = 0;
+ enum winreg_Type type = 0;
+
+ r.in.value_offered = value_size;
+ r.out.value_needed = &value_size;
+ r.in.data_offered = data_size;
+ r.out.data_needed = &data_size;
+
+ r.out.type = &type;
+ r.out.data = talloc_zero_array(tctx, uint8_t, 0);
+
+ torture_comment(tctx, "Testing EnumPrinterData\n");
+
+ status = dcerpc_spoolss_EnumPrinterData(p, tctx, &r);
+
+ torture_assert_ntstatus_ok(tctx, status, "EnumPrinterData failed");
+ if (W_ERROR_EQUAL(r.out.result, WERR_NO_MORE_ITEMS)) {
+ break;
+ }
+ torture_assert_werr_ok(tctx, r.out.result, "EnumPrinterData");
+
+ r.in.value_offered = value_size;
+ r.out.value_name = talloc_zero_array(tctx, const char, value_size);
+ r.in.data_offered = data_size;
+ r.out.data = talloc_zero_array(tctx, uint8_t, data_size);
+
+ status = dcerpc_spoolss_EnumPrinterData(p, tctx, &r);
+
+ torture_assert_ntstatus_ok(tctx, status, "EnumPrinterData failed");
+ if (W_ERROR_EQUAL(r.out.result, WERR_NO_MORE_ITEMS)) {
+ break;
+ }
+
+ torture_assert_werr_ok(tctx, r.out.result, "EnumPrinterData failed");
+
+ torture_assert(tctx, test_GetPrinterData(tctx, p, handle, r.out.value_name, NULL, NULL),
+ talloc_asprintf(tctx, "failed to call GetPrinterData for %s\n", r.out.value_name));
+
+ torture_assert(tctx, test_GetPrinterDataEx(tctx, p, handle, "PrinterDriverData", r.out.value_name, NULL, NULL),
+ talloc_asprintf(tctx, "failed to call GetPrinterDataEx on PrinterDriverData for %s\n", r.out.value_name));
+
+ r.in.enum_index++;
+
+ } while (W_ERROR_IS_OK(r.out.result));
+
+ return true;
+}
+
+static bool test_EnumPrinterDataEx(struct torture_context *tctx,
+ struct dcerpc_pipe *p,
+ struct policy_handle *handle,
+ const char *key_name)
+{
+ struct spoolss_EnumPrinterDataEx r;
+ struct spoolss_PrinterEnumValues *info;
+ uint32_t needed;
+ uint32_t count;
+
+ r.in.handle = handle;
+ r.in.key_name = key_name;
+ r.in.offered = 0;
+ r.out.needed = &needed;
+ r.out.count = &count;
+ r.out.info = &info;
+
+ torture_comment(tctx, "Testing EnumPrinterDataEx(%s)\n", key_name);
+
+ torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_EnumPrinterDataEx(p, tctx, &r),
+ "EnumPrinterDataEx failed");
+ if (W_ERROR_EQUAL(r.out.result, WERR_MORE_DATA)) {
+ r.in.offered = needed;
+ torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_EnumPrinterDataEx(p, tctx, &r),
+ "EnumPrinterDataEx failed");
+ }
+
+ torture_assert_werr_ok(tctx, r.out.result, "EnumPrinterDataEx failed");
+
+ CHECK_NEEDED_SIZE_ENUM(spoolss_EnumPrinterDataEx, info, count, lp_iconv_convenience(tctx->lp_ctx), needed, 1);
+
+ return true;
+}
+
+
+static bool test_DeletePrinterData(struct torture_context *tctx,
+ struct dcerpc_pipe *p,
+ struct policy_handle *handle,
+ const char *value_name)
+{
+ NTSTATUS status;
+ struct spoolss_DeletePrinterData r;
+
+ r.in.handle = handle;
+ r.in.value_name = value_name;
+
+ torture_comment(tctx, "Testing DeletePrinterData(%s)\n",
+ r.in.value_name);
+
+ status = dcerpc_spoolss_DeletePrinterData(p, tctx, &r);
+
+ torture_assert_ntstatus_ok(tctx, status, "DeletePrinterData failed");
+ torture_assert_werr_ok(tctx, r.out.result, "DeletePrinterData failed");
+
+ return true;
+}
+
+static bool test_DeletePrinterDataEx(struct torture_context *tctx,
+ struct dcerpc_pipe *p,
+ struct policy_handle *handle,
+ const char *key_name,
+ const char *value_name)
+{
+ struct spoolss_DeletePrinterDataEx r;
+
+ r.in.handle = handle;
+ r.in.key_name = key_name;
+ r.in.value_name = value_name;
+
+ torture_comment(tctx, "Testing DeletePrinterDataEx(%s - %s)\n",
+ r.in.key_name, r.in.value_name);
+
+ torture_assert_ntstatus_ok(tctx,
+ dcerpc_spoolss_DeletePrinterDataEx(p, tctx, &r),
+ "DeletePrinterDataEx failed");
+ torture_assert_werr_ok(tctx, r.out.result,
+ "DeletePrinterDataEx failed");
+
+ return true;
+}
+
+static bool test_DeletePrinterKey(struct torture_context *tctx,
+ struct dcerpc_pipe *p,
+ struct policy_handle *handle,
+ const char *key_name)
+{
+ struct spoolss_DeletePrinterKey r;
+
+ r.in.handle = handle;
+ r.in.key_name = key_name;
+
+ torture_comment(tctx, "Testing DeletePrinterKey(%s)\n", r.in.key_name);
+
+ if (strequal(key_name, "") && !torture_setting_bool(tctx, "dangerous", false)) {
+ torture_skip(tctx, "not wiping out printer registry - enable dangerous tests to use\n");
+ return true;
+ }
+
+ torture_assert_ntstatus_ok(tctx,
+ dcerpc_spoolss_DeletePrinterKey(p, tctx, &r),
+ "DeletePrinterKey failed");
+ torture_assert_werr_ok(tctx, r.out.result,
+ "DeletePrinterKey failed");
+
+ return true;
+}
+
+static bool test_SetPrinterData(struct torture_context *tctx,
+ struct dcerpc_pipe *p,
+ struct policy_handle *handle)
+{
+ NTSTATUS status;
+ struct spoolss_SetPrinterData r;
+ const char *values[] = {
+ "spootyfoot",
+ "spooty\\foot",
+#if 0
+ /* FIXME: not working with s3 atm. */
+ "spooty,foot",
+ "spooty,fo,ot",
+#endif
+ "spooty foot",
+#if 0
+ /* FIXME: not working with s3 atm. */
+ "spooty\\fo,ot",
+ "spooty,fo\\ot"
+#endif
+ };
+ int i;
+
+ for (i=0; i < ARRAY_SIZE(values); i++) {
+
+ enum winreg_Type type;
+ union spoolss_PrinterData data;
+
+ r.in.handle = handle;
+ r.in.value_name = values[i];
+ r.in.type = REG_SZ;
+ r.in.data.string = "dog";
+
+ torture_comment(tctx, "Testing SetPrinterData(%s)\n",
+ r.in.value_name);
+
+ status = dcerpc_spoolss_SetPrinterData(p, tctx, &r);
+
+ torture_assert_ntstatus_ok(tctx, status, "SetPrinterData failed");
+ torture_assert_werr_ok(tctx, r.out.result, "SetPrinterData failed");
+
+ if (!test_GetPrinterData(tctx, p, handle, r.in.value_name, &type, &data)) {
+ return false;
+ }
+
+ torture_assert_int_equal(tctx, r.in.type, type, "type mismatch");
+ torture_assert_str_equal(tctx, r.in.data.string, data.string, "data mismatch");
+
+ if (!test_DeletePrinterData(tctx, p, handle, r.in.value_name)) {
+ return false;
+ }
+ }
+
+ return true;
+}
+
+static bool test_EnumPrinterKey(struct torture_context *tctx,
+ struct dcerpc_pipe *p,
+ struct policy_handle *handle,
+ const char *key_name,
+ const char ***array);
+
+static bool test_SetPrinterDataEx(struct torture_context *tctx,
+ struct dcerpc_pipe *p,
+ struct policy_handle *handle)
+{
+ NTSTATUS status;
+ struct spoolss_SetPrinterDataEx r;
+ const char *value_name = "dog";
+ const char *keys[] = {
+ "torturedataex",
+ "torture data ex",
+#if 0
+ /* FIXME: not working with s3 atm. */
+ "torturedataex_with_subkey\\subkey",
+ "torturedataex_with_subkey\\subkey:0",
+ "torturedataex_with_subkey\\subkey:1",
+ "torturedataex_with_subkey\\subkey\\subsubkey",
+ "torturedataex_with_subkey\\subkey\\subsubkey:0",
+ "torturedataex_with_subkey\\subkey\\subsubkey:1",
+#endif
+ "torture,data",
+#if 0
+ /* FIXME: not working with s3 atm. */
+
+ "torture,data,ex",
+ "torture,data\\ex",
+ "torture\\data,ex"
+#endif
+ };
+ int i;
+ DATA_BLOB blob = data_blob_string_const("catfoobar");
+
+
+ for (i=0; i < ARRAY_SIZE(keys); i++) {
+
+ char *c;
+ const char *key;
+ enum winreg_Type type;
+ const char **subkeys;
+ union spoolss_PrinterData data;
+
+ r.in.handle = handle;
+ r.in.key_name = keys[i];
+ r.in.value_name = value_name;
+ r.in.type = REG_BINARY;
+ r.in.data.binary = blob;
+
+ torture_comment(tctx, "Testing SetPrinterDataEx(%s - %s)\n", r.in.key_name, value_name);
+
+ status = dcerpc_spoolss_SetPrinterDataEx(p, tctx, &r);
+
+ torture_assert_ntstatus_ok(tctx, status, "SetPrinterDataEx failed");
+ torture_assert_werr_ok(tctx, r.out.result, "SetPrinterDataEx failed");
+
+ key = talloc_strdup(tctx, r.in.key_name);
+
+ if (!test_GetPrinterDataEx(tctx, p, handle, r.in.key_name, value_name, &type, &data)) {
+ return false;
+ }
+
+ torture_assert_int_equal(tctx, r.in.type, type, "type mismatch");
+ torture_assert_data_blob_equal(tctx, blob, data.binary, "data mismatch");
+
+ if (!test_EnumPrinterDataEx(tctx, p, handle, r.in.key_name)) {
+ return false;
+ }
+
+ if (!test_DeletePrinterDataEx(tctx, p, handle, r.in.key_name, value_name)) {
+ return false;
+ }
+
+ c = strchr(key, '\\');
+ if (c) {
+ int i;
+
+ /* we have subkeys */
+
+ *c = 0;
+
+ if (!test_EnumPrinterKey(tctx, p, handle, key, &subkeys)) {
+ return false;
+ }
+
+ for (i=0; subkeys && subkeys[i]; i++) {
+
+ const char *current_key = talloc_asprintf(tctx, "%s\\%s", key, subkeys[i]);
+
+ if (!test_DeletePrinterKey(tctx, p, handle, current_key)) {
+ return false;
+ }
+ }
+
+ if (!test_DeletePrinterKey(tctx, p, handle, key)) {
+ return false;
+ }
+
+ } else {
+ if (!test_DeletePrinterKey(tctx, p, handle, key)) {
+ return false;
+ }
+ }
+ }
+
+ return true;
+}
+
+static bool test_GetChangeID_PrinterData(struct torture_context *tctx,
+ struct dcerpc_pipe *p,
+ struct policy_handle *handle,
+ uint32_t *change_id)
+{
+ enum winreg_Type type;
+ union spoolss_PrinterData data;
+
+ torture_assert(tctx,
+ test_GetPrinterData(tctx, p, handle, "ChangeID", &type, &data),
+ "failed to call GetPrinterData");
+
+ torture_assert(tctx, type == REG_DWORD, "unexpected type");
+
+ *change_id = data.value;
+
+ return true;
+}
+
+static bool test_GetChangeID_PrinterDataEx(struct torture_context *tctx,
+ struct dcerpc_pipe *p,
+ struct policy_handle *handle,
+ uint32_t *change_id)
+{
+ enum winreg_Type type;
+ union spoolss_PrinterData data;
+
+ torture_assert(tctx,
+ test_GetPrinterDataEx(tctx, p, handle, "PrinterDriverData", "ChangeID", &type, &data),
+ "failed to call GetPrinterData");
+
+ torture_assert(tctx, type == REG_DWORD, "unexpected type");
+
+ *change_id = data.value;
+
+ return true;
+}
+
+static bool test_GetChangeID_PrinterInfo(struct torture_context *tctx,
+ struct dcerpc_pipe *p,
+ struct policy_handle *handle,
+ uint32_t *change_id)
+{
+ union spoolss_PrinterInfo info;
+
+ torture_assert(tctx, test_GetPrinter_level(tctx, p, handle, 0, &info),
+ "failed to query Printer level 0");
+
+ *change_id = info.info0.change_id;
+
+ return true;
+}
+
+static bool test_ChangeID(struct torture_context *tctx,
+ struct dcerpc_pipe *p,
+ struct policy_handle *handle)
+{
+ uint32_t change_id, change_id_ex, change_id_info;
+ uint32_t change_id2, change_id_ex2, change_id_info2;
+ union spoolss_PrinterInfo info;
+ const char *comment;
+
+
+ torture_comment(tctx, "Testing ChangeID: id change test #1\n");
+
+ torture_assert(tctx, test_GetChangeID_PrinterData(tctx, p, handle, &change_id),
+ "failed to query for ChangeID");
+ torture_assert(tctx, test_GetChangeID_PrinterDataEx(tctx, p, handle, &change_id_ex),
+ "failed to query for ChangeID");
+ torture_assert(tctx, test_GetChangeID_PrinterInfo(tctx, p, handle, &change_id_info),
+ "failed to query for ChangeID");
+
+ torture_assert_int_equal(tctx, change_id, change_id_ex,
+ "change_ids should all be equal");
+ torture_assert_int_equal(tctx, change_id_ex, change_id_info,
+ "change_ids should all be equal");
+
+
+ torture_comment(tctx, "Testing ChangeID: id change test #2\n");
+
+ torture_assert(tctx, test_GetChangeID_PrinterData(tctx, p, handle, &change_id),
+ "failed to query for ChangeID");
+ torture_assert(tctx, test_GetPrinter_level(tctx, p, handle, 2, &info),
+ "failed to query Printer level 2");
+ torture_assert(tctx, test_GetChangeID_PrinterDataEx(tctx, p, handle, &change_id_ex),
+ "failed to query for ChangeID");
+ torture_assert(tctx, test_GetChangeID_PrinterInfo(tctx, p, handle, &change_id_info),
+ "failed to query for ChangeID");
+ torture_assert_int_equal(tctx, change_id, change_id_ex,
+ "change_id should not have changed");
+ torture_assert_int_equal(tctx, change_id_ex, change_id_info,
+ "change_id should not have changed");
+
+
+ torture_comment(tctx, "Testing ChangeID: id change test #3\n");
+
+ torture_assert(tctx, test_GetChangeID_PrinterData(tctx, p, handle, &change_id),
+ "failed to query for ChangeID");
+ torture_assert(tctx, test_GetChangeID_PrinterDataEx(tctx, p, handle, &change_id_ex),
+ "failed to query for ChangeID");
+ torture_assert(tctx, test_GetChangeID_PrinterInfo(tctx, p, handle, &change_id_info),
+ "failed to query for ChangeID");
+ torture_assert(tctx, test_GetPrinter_level(tctx, p, handle, 2, &info),
+ "failed to query Printer level 2");
+ comment = talloc_strdup(tctx, info.info2.comment);
+
+ {
+ struct spoolss_SetPrinterInfoCtr info_ctr;
+ struct spoolss_DevmodeContainer devmode_ctr;
+ struct sec_desc_buf secdesc_ctr;
+ struct spoolss_SetPrinterInfo2 info2;
+
+ ZERO_STRUCT(info_ctr);
+ ZERO_STRUCT(devmode_ctr);
+ ZERO_STRUCT(secdesc_ctr);
+
+ 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 = "torture_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;
+
+ torture_assert(tctx, test_SetPrinter(tctx, p, handle, &info_ctr, &devmode_ctr, &secdesc_ctr, 0),
+ "failed to call SetPrinter");
+
+ info2.comment = comment;
+
+ torture_assert(tctx, test_SetPrinter(tctx, p, handle, &info_ctr, &devmode_ctr, &secdesc_ctr, 0),
+ "failed to call SetPrinter");
+
+ }
+
+ torture_assert(tctx, test_GetChangeID_PrinterData(tctx, p, handle, &change_id2),
+ "failed to query for ChangeID");
+ torture_assert(tctx, test_GetChangeID_PrinterDataEx(tctx, p, handle, &change_id_ex2),
+ "failed to query for ChangeID");
+ torture_assert(tctx, test_GetChangeID_PrinterInfo(tctx, p, handle, &change_id_info2),
+ "failed to query for ChangeID");
+
+ torture_assert_int_equal(tctx, change_id2, change_id_ex2,
+ "change_ids should all be equal");
+ torture_assert_int_equal(tctx, change_id_ex2, change_id_info2,
+ "change_ids should all be equal");
+
+ torture_assert(tctx, (change_id < change_id2),
+ talloc_asprintf(tctx, "change_id %d needs to be larger than change_id %d",
+ change_id2, change_id));
+ torture_assert(tctx, (change_id_ex < change_id_ex2),
+ talloc_asprintf(tctx, "change_id %d needs to be larger than change_id %d",
+ change_id_ex2, change_id_ex));
+ torture_assert(tctx, (change_id_info < change_id_info2),
+ talloc_asprintf(tctx, "change_id %d needs to be larger than change_id %d",
+ change_id_info2, change_id_info));
+
+ return true;
+}
+
+static bool test_SecondaryClosePrinter(struct torture_context *tctx,
+ struct dcerpc_pipe *p,
+ struct policy_handle *handle)
+{
+ NTSTATUS status;
+ struct dcerpc_binding *b;
+ struct dcerpc_pipe *p2;
+ struct spoolss_ClosePrinter cp;
+
+ /* only makes sense on SMB */
+ if (p->conn->transport.transport != NCACN_NP) {
+ return true;
+ }
+
+ torture_comment(tctx, "testing close on secondary pipe\n");
+
+ status = dcerpc_parse_binding(tctx, p->conn->binding_string, &b);
+ torture_assert_ntstatus_ok(tctx, status, "Failed to parse dcerpc binding");
+
+ status = dcerpc_secondary_connection(p, &p2, b);
+ torture_assert_ntstatus_ok(tctx, status, "Failed to create secondary connection");
+
+ status = dcerpc_bind_auth_none(p2, &ndr_table_spoolss);
+ torture_assert_ntstatus_ok(tctx, status, "Failed to create bind on secondary connection");
+
+ cp.in.handle = handle;
+ cp.out.handle = handle;
+
+ status = dcerpc_spoolss_ClosePrinter(p2, tctx, &cp);
+ torture_assert_ntstatus_equal(tctx, status, NT_STATUS_NET_WRITE_FAULT,
+ "ERROR: Allowed close on secondary connection");
+
+ torture_assert_int_equal(tctx, p2->last_fault_code, DCERPC_FAULT_CONTEXT_MISMATCH,
+ "Unexpected fault code");
+
+ talloc_free(p2);
+
+ return true;
+}
+
+static bool test_OpenPrinter_badname(struct torture_context *tctx,
+ struct dcerpc_pipe *p, const char *name)
+{
+ NTSTATUS status;
+ struct spoolss_OpenPrinter op;
+ struct spoolss_OpenPrinterEx opEx;
+ struct policy_handle handle;
+ bool ret = true;
+
+ op.in.printername = name;
+ op.in.datatype = NULL;
+ op.in.devmode_ctr.devmode= NULL;
+ op.in.access_mask = 0;
+ op.out.handle = &handle;
+
+ torture_comment(tctx, "\nTesting OpenPrinter(%s) with bad name\n", op.in.printername);
+
+ status = dcerpc_spoolss_OpenPrinter(p, tctx, &op);
+ torture_assert_ntstatus_ok(tctx, status, "OpenPrinter failed");
+ if (!W_ERROR_EQUAL(WERR_INVALID_PRINTER_NAME,op.out.result)) {
+ torture_comment(tctx, "OpenPrinter(%s) unexpected result[%s] should be WERR_INVALID_PRINTER_NAME\n",
+ name, win_errstr(op.out.result));
+ }
+
+ if (W_ERROR_IS_OK(op.out.result)) {
+ ret &=test_ClosePrinter(tctx, p, &handle);
+ }
+
+ opEx.in.printername = name;
+ opEx.in.datatype = NULL;
+ opEx.in.devmode_ctr.devmode = NULL;
+ opEx.in.access_mask = 0;
+ opEx.in.level = 1;
+ opEx.in.userlevel.level1 = NULL;
+ opEx.out.handle = &handle;
+
+ torture_comment(tctx, "Testing OpenPrinterEx(%s) with bad name\n", opEx.in.printername);
+
+ status = dcerpc_spoolss_OpenPrinterEx(p, tctx, &opEx);
+ torture_assert_ntstatus_ok(tctx, status, "OpenPrinterEx failed");
+ if (!W_ERROR_EQUAL(WERR_INVALID_PARAM,opEx.out.result)) {
+ torture_comment(tctx, "OpenPrinterEx(%s) unexpected result[%s] should be WERR_INVALID_PARAM\n",