Example #1
0
int main(int argc, char *argv[])
{
	BOOL ret = FALSE;
	LPSTR servername;
	LPSTR architecture = "Windows NT x86";
	HANDLE server_handle;
	PRINTER_DEFAULTS defaults_admin, defaults_use;
	struct torture_context *tctx;

	if (argc < 2) {
		fprintf(stderr, "usage: %s <servername> [print]\n", argv[0]);
		exit(-1);
	}

	tctx = malloc(sizeof(struct torture_context));
	if (!tctx) {
		fprintf(stderr, "out of memory\n");
		exit(-1);
	}
	memset(tctx, '\0', sizeof(*tctx));

	servername = argv[1];

	if (argc >= 3) {
		if (strcmp(argv[2], "print") == 0) {
			tctx->print = TRUE;
		}
	}

	defaults_admin.pDatatype = NULL;
	defaults_admin.pDevMode = NULL;
	defaults_admin.DesiredAccess = PRINTER_ACCESS_ADMINISTER;

	defaults_use.pDatatype = NULL;
	defaults_use.pDevMode = NULL;
	defaults_use.DesiredAccess = PRINTER_ACCESS_USE;

	ret &= test_EnumPrinters(tctx, servername);
	ret &= test_EnumDrivers(tctx, servername, architecture);
	ret &= test_OpenPrinter(tctx, servername, NULL, &server_handle);
/*	ret &= test_EnumPrinterKey(tctx, servername, server_handle, ""); */
	ret &= test_PrinterData(tctx, servername, server_handle);
	ret &= test_EnumForms(tctx, servername, server_handle);
	ret &= test_ClosePrinter(tctx, server_handle);
	ret &= test_EnumPorts(tctx, servername);
	ret &= test_EnumMonitors(tctx, servername);
	ret &= test_EnumPrintProcessors(tctx, servername, architecture);
	ret &= test_EnumPrintProcessorDatatypes(tctx, servername);
	ret &= test_GetPrintProcessorDirectory(tctx, servername, architecture);
	ret &= test_GetPrinterDriverDirectory(tctx, servername, architecture);
	ret &= test_EachPrinter(tctx, servername, architecture, NULL);

	if (!ret) {
		if (tctx->last_reason) {
			fprintf(stderr, "failed: %s\n", tctx->last_reason);
		}
		free(tctx);
		return -1;
	}

	printf("%s run successfully\n", argv[0]);

	free(tctx);
	return 0;
}
Example #2
0
static bool test_WinXP(struct torture_context *tctx, struct dcerpc_pipe *p)
{
	bool ret = true;
	struct test_spoolss_win_context *ctx, *tmp_ctx;
	struct policy_handle handle01, handle02, handle03, handle04;
	/* Sometimes a handle stays unused. In order to make this clear in the
	 * code, the unused_handle structures are used for that. */
	struct policy_handle unused_handle1, unused_handle2;
	char *server_name;
	uint32_t i;
	struct dcerpc_binding_handle *b = p->binding_handle;

	ctx = talloc_zero(tctx, struct test_spoolss_win_context);
	tmp_ctx = talloc_zero(tctx, struct test_spoolss_win_context);

	ret &= test_OpenPrinterSequence(tctx, p, &handle01);
	ret &= test_GetPrinterData(tctx, b, &handle01,"UISingleJobStatusString",
			WERR_INVALID_PARAMETER, 0);
	torture_comment(tctx, "Skip RemoteFindNextPrinterChangeNotifyEx test\n");

	server_name = talloc_asprintf(ctx, "\\\\%s", dcerpc_server_name(p));
	ret &= test_OpenPrinterEx(tctx, b, &unused_handle1, server_name, 0);

	ret &= test_EnumPrinters(tctx, p, ctx, 1024);

	ret &= test_OpenPrinterEx(tctx, b, &handle02, server_name, 0);
	ret &= test_GetPrinterData(tctx, b, &handle02, "MajorVersion", WERR_OK,
			3);
	ret &= test_ClosePrinter(tctx, b, &handle02);

	/* If no printers were found, skip all tests that need a printer */
	if (ctx->printer_count == 0) {
		goto end_testWinXP;
	}

	ret &= test_OpenPrinterEx(tctx, b, &handle02,
			ctx->printer_info[0].info2.printername,
			PRINTER_ACCESS_USE);
	ret &= test_GetPrinter(tctx, b, &handle02, ctx, 2, 0);

	torture_assert_str_equal(tctx, ctx->current_info->info2.printername,
			ctx->printer_info[0].info2.printername,
			"GetPrinter returned unexpected printername");
	/*FIXME: Test more components of the PrinterInfo2 struct */

	ret &= test_OpenPrinterEx(tctx, b, &handle03,
			ctx->printer_info[0].info2.printername, 0);
	ret &= test_GetPrinter(tctx, b, &handle03, ctx, 0, 1164);
	ret &= test_GetPrinter(tctx, b, &handle03, ctx, 2, 0);

	ret &= test_OpenPrinterEx(tctx, b, &handle04,
			ctx->printer_info[0].info2.printername, 0);
	ret &= test_GetPrinter(tctx, b, &handle04, ctx, 2, 0);
	ret &= test_ClosePrinter(tctx, b, &handle04);

	ret &= test_OpenPrinterEx(tctx, b, &handle04,
			ctx->printer_info[0].info2.printername, 0);
	ret &= test_GetPrinter(tctx, b, &handle04, ctx, 2, 4096);
	ret &= test_ClosePrinter(tctx, b, &handle04);

	ret &= test_OpenPrinterAsAdmin(tctx, b,
			ctx->printer_info[0].info2.printername);

	ret &= test_OpenPrinterEx(tctx, b, &handle04,
			ctx->printer_info[0].info2.printername, PRINTER_READ);
	ret &= test_GetPrinterData(tctx, b, &handle04,"UISingleJobStatusString",
			WERR_FILE_NOT_FOUND, 0);
	torture_comment(tctx, "Skip RemoteFindNextPrinterChangeNotifyEx test\n");

	ret &= test_OpenPrinterEx(tctx, b, &unused_handle2,
			ctx->printer_info[0].info2.printername, 0);

	ret &= test_EnumJobs(tctx, b, &handle04);
	ret &= test_GetPrinter(tctx, b, &handle04, ctx, 2, 4096);

	ret &= test_ClosePrinter(tctx, b, &unused_handle2);
	ret &= test_ClosePrinter(tctx, b, &handle04);

	ret &= test_EnumPrinters(tctx, p, ctx, 1556);
	ret &= test_GetPrinterDriver2(tctx, b, ctx, &handle03);
	ret &= test_EnumForms(tctx, b, &handle03, 0);

	ret &= test_EnumPrinterKey(tctx, b, &handle03, "", ctx);

	for (i=0; ctx->printer_keys && ctx->printer_keys[i] != NULL; i++) {

		ret &= test_EnumPrinterKey(tctx, b, &handle03,
					   ctx->printer_keys[i],
					   tmp_ctx);
		ret &= test_EnumPrinterDataEx(tctx, b, &handle03,
					      ctx->printer_keys[i], 0,
					      WERR_OK);
	}

	ret &= test_EnumPrinterDataEx(tctx, b, &handle03, "", 0,
			WERR_INVALID_PARAMETER);

	ret &= test_GetPrinter(tctx, b, &handle03, tmp_ctx, 2, 0);

	ret &= test_OpenPrinterEx(tctx, b, &unused_handle2,
			ctx->printer_info[0].info2.printername, 0);
	ret &= test_ClosePrinter(tctx, b, &unused_handle2);

	ret &= test_GetPrinter(tctx, b, &handle03, tmp_ctx, 2, 2556);

	ret &= test_OpenPrinterEx(tctx, b, &unused_handle2,
			ctx->printer_info[0].info2.printername, 0);
	ret &= test_ClosePrinter(tctx, b, &unused_handle2);

	ret &= test_OpenPrinterEx(tctx, b, &unused_handle2,
			ctx->printer_info[0].info2.printername, 0);
	ret &= test_ClosePrinter(tctx, b, &unused_handle2);

	ret &= test_GetPrinter(tctx, b, &handle03, tmp_ctx, 7, 0);

	ret &= test_OpenPrinterEx(tctx, b, &unused_handle2,
			ctx->printer_info[0].info2.printername, 0);
	ret &= test_ClosePrinter(tctx, b, &unused_handle2);

	ret &= test_ClosePrinter(tctx, b, &handle03);

	ret &= test_OpenPrinterEx(tctx, b, &unused_handle2,
			ctx->printer_info[0].info2.printername, 0);
	ret &= test_ClosePrinter(tctx, b, &unused_handle2);

	ret &= test_OpenPrinterEx(tctx, b, &handle03, server_name, 0);
	ret &= test_GetPrinterData(tctx, b, &handle03, "W3SvcInstalled",
			WERR_OK, 0);
	ret &= test_ClosePrinter(tctx, b, &handle03);

	ret &= test_ClosePrinter(tctx, b, &unused_handle1);
	ret &= test_ClosePrinter(tctx, b, &handle02);

	ret &= test_OpenPrinterEx(tctx, b, &handle02,
			ctx->printer_info[0].info2.sharename, 0);
	ret &= test_GetPrinter(tctx, b, &handle02, tmp_ctx, 2, 0);
	ret &= test_ClosePrinter(tctx, b, &handle02);

end_testWinXP:
	ret &= test_ClosePrinter(tctx, b, &handle01);

	talloc_free(tmp_ctx);
	talloc_free(ctx);
	return ret;
}