⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 spoolss_win.c

📁 samba最新软件
💻 C
📖 第 1 页 / 共 2 页
字号:
			"GetPrinterDriver2 failed.");	return true;}static bool test_EnumForms(struct torture_context *tctx,				struct dcerpc_pipe *p,				struct policy_handle *handle,				uint32_t initial_blob_size){	NTSTATUS status;	struct spoolss_EnumForms ef;	DATA_BLOB blob = data_blob_talloc_zero(tctx, initial_blob_size);	torture_comment(tctx, "Testing EnumForms\n");	ef.in.handle = handle;	ef.in.level = 1;	ef.in.buffer = (initial_blob_size == 0)?NULL:&blob;	ef.in.offered = initial_blob_size;	status = dcerpc_spoolss_EnumForms(p, tctx, &ef);	torture_assert_ntstatus_ok(tctx, status, "EnumForms failed");	if (W_ERROR_EQUAL(ef.out.result, WERR_INSUFFICIENT_BUFFER)) {		blob = data_blob_talloc_zero(tctx, ef.out.needed);		ef.in.buffer = &blob;		ef.in.offered = ef.out.needed;		status = dcerpc_spoolss_EnumForms(p, tctx, &ef);		torture_assert_ntstatus_ok(tctx, status, "EnumForms failed");	}	torture_assert_werr_ok(tctx, ef.out.result, "EnumForms failed");	return true;}static bool test_EnumPrinterKey(struct torture_context *tctx,				struct dcerpc_pipe *p,				struct policy_handle *handle,				const char* key,				struct test_spoolss_win_context *ctx){	NTSTATUS status;	struct spoolss_EnumPrinterKey epk;	uint32_t needed = 0;	torture_comment(tctx, "Testing EnumPrinterKey(%s)\n", key);	epk.in.handle = handle;	epk.in.key_name = talloc_strdup(tctx, key);	epk.in.needed = needed;	status = dcerpc_spoolss_EnumPrinterKey(p, tctx, &epk);	torture_assert_ntstatus_ok(tctx, status, "EnumPrinterKey failed");	if (W_ERROR_EQUAL(epk.out.result, WERR_MORE_DATA)) {		epk.in.needed = epk.out.needed;		status = dcerpc_spoolss_EnumPrinterKey(p, tctx, &epk);		torture_assert_ntstatus_ok(tctx, status,				"EnumPrinterKey failed");	}	torture_assert_werr_ok(tctx, epk.out.result, "EnumPrinterKey failed");	convert_string_talloc(ctx, lp_iconv_convenience(tctx->lp_ctx), CH_UTF16,			CH_UNIX, epk.out.key_buffer, epk.out.needed,			(void**)&ctx->printer_keys);	return true;}static bool test_EnumPrinterDataEx(struct torture_context *tctx,					struct dcerpc_pipe *p,					struct policy_handle *handle,					const char *key,					uint32_t initial_blob_size,					WERROR expected_error){	NTSTATUS status;	struct spoolss_EnumPrinterDataEx epde;	torture_comment(tctx, "Testing EnumPrinterDataEx(%s)\n", key);	epde.in.handle = handle;	epde.in.key_name = talloc_strdup(tctx, key);	epde.in.offered = 0;	status = dcerpc_spoolss_EnumPrinterDataEx(p, tctx, &epde);	torture_assert_ntstatus_ok(tctx, status, "EnumPrinterDataEx failed.");	if (W_ERROR_EQUAL(epde.out.result, WERR_MORE_DATA)) {		epde.in.offered = epde.out.needed;		status = dcerpc_spoolss_EnumPrinterDataEx(p, tctx, &epde);		torture_assert_ntstatus_ok(tctx, status,				"EnumPrinterDataEx failed.");	}	torture_assert_werr_equal(tctx, epde.out.result, expected_error,			"EnumPrinterDataEx failed.");	return true;}static bool test_ClosePrinter(struct torture_context *tctx,				struct dcerpc_pipe *p,				struct policy_handle *handle){	NTSTATUS status;	struct spoolss_ClosePrinter cp;	cp.in.handle  = handle;	cp.out.handle = handle;	status = dcerpc_spoolss_ClosePrinter(p, tctx, &cp);	torture_assert_ntstatus_ok(tctx, status, "ClosePrinter failed");	return true;}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;	char *key_pointer;	ntvfs_init(tctx->lp_ctx);	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, p, &handle01,"UISingleJobStatusString",			WERR_INVALID_PARAM, 0);	torture_comment(tctx, "Skip RemoteFindNextPrinterChangeNotifyEx test\n");	server_name = talloc_asprintf(ctx, "\\\\%s", dcerpc_server_name(p));	ret &= test_OpenPrinterEx(tctx, p, &unused_handle1, server_name, 0);	ret &= test_EnumPrinters(tctx, p, ctx, 1024);	ret &= test_OpenPrinterEx(tctx, p, &handle02, server_name, 0);	ret &= test_GetPrinterData(tctx, p, &handle02, "MajorVersion", WERR_OK,			3);	ret &= test_ClosePrinter(tctx, p, &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, p, &handle02,			ctx->printer_info[0].info2.printername,			PRINTER_ACCESS_USE);	ret &= test_GetPrinter(tctx, p, &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, p, &handle03,			ctx->printer_info[0].info2.printername, 0);	ret &= test_GetPrinter(tctx, p, &handle03, ctx, 0, 1164);	ret &= test_GetPrinter(tctx, p, &handle03, ctx, 2, 0);	ret &= test_OpenPrinterEx(tctx, p, &handle04,			ctx->printer_info[0].info2.printername, 0);	ret &= test_GetPrinter(tctx, p, &handle04, ctx, 2, 0);	ret &= test_ClosePrinter(tctx, p, &handle04);	ret &= test_OpenPrinterEx(tctx, p, &handle04,			ctx->printer_info[0].info2.printername, 0);	ret &= test_GetPrinter(tctx, p, &handle04, ctx, 2, 4096);	ret &= test_ClosePrinter(tctx, p, &handle04);	ret &= test_OpenPrinterAsAdmin(tctx, p,			ctx->printer_info[0].info2.printername);	ret &= test_OpenPrinterEx(tctx, p, &handle04,			ctx->printer_info[0].info2.printername, PRINTER_READ);	ret &= test_GetPrinterData(tctx, p, &handle04,"UISingleJobStatusString",			WERR_BADFILE, 0);	torture_comment(tctx, "Skip RemoteFindNextPrinterChangeNotifyEx test\n");	ret &= test_OpenPrinterEx(tctx, p, &unused_handle2,			ctx->printer_info[0].info2.printername, 0);	ret &= test_EnumJobs(tctx, p, &handle04);	ret &= test_GetPrinter(tctx, p, &handle04, ctx, 2, 4096);	ret &= test_ClosePrinter(tctx, p, &unused_handle2);	ret &= test_ClosePrinter(tctx, p, &handle04);	ret &= test_EnumPrinters(tctx, p, ctx, 1556);	ret &= test_GetPrinterDriver2(tctx, p, &handle03);	ret &= test_EnumForms(tctx, p, &handle03, 0);	ret &= test_EnumPrinterKey(tctx, p, &handle03, "", ctx);	key_pointer = ctx->printer_keys;	while(*key_pointer != '\0') {		char *end_pointer;		char *key_name;		for(end_pointer = key_pointer; *end_pointer != '\0';				++end_pointer) {			/* Do nothing, just move the pointer */		}		key_name = talloc_strndup(tctx, key_pointer,				end_pointer - key_pointer);		ret &= test_EnumPrinterKey(tctx, p, &handle03, key_name,				tmp_ctx);		ret &= test_EnumPrinterDataEx(tctx, p, &handle03, key_name, 0,				WERR_OK);		key_pointer = ++end_pointer;	}	ret &= test_EnumPrinterDataEx(tctx, p, &handle03, "", 0,			WERR_INVALID_PARAM);	ret &= test_GetPrinter(tctx, p, &handle03, tmp_ctx, 2, 0);	ret &= test_OpenPrinterEx(tctx, p, &unused_handle2,			ctx->printer_info[0].info2.printername, 0);	ret &= test_ClosePrinter(tctx, p, &unused_handle2);	ret &= test_GetPrinter(tctx, p, &handle03, tmp_ctx, 2, 2556);	ret &= test_OpenPrinterEx(tctx, p, &unused_handle2,			ctx->printer_info[0].info2.printername, 0);	ret &= test_ClosePrinter(tctx, p, &unused_handle2);	ret &= test_OpenPrinterEx(tctx, p, &unused_handle2,			ctx->printer_info[0].info2.printername, 0);	ret &= test_ClosePrinter(tctx, p, &unused_handle2);	ret &= test_GetPrinter(tctx, p, &handle03, tmp_ctx, 7, 0);	ret &= test_OpenPrinterEx(tctx, p, &unused_handle2,			ctx->printer_info[0].info2.printername, 0);	ret &= test_ClosePrinter(tctx, p, &unused_handle2);	ret &= test_ClosePrinter(tctx, p, &handle03);	ret &= test_OpenPrinterEx(tctx, p, &unused_handle2,			ctx->printer_info[0].info2.printername, 0);	ret &= test_ClosePrinter(tctx, p, &unused_handle2);	ret &= test_OpenPrinterEx(tctx, p, &handle03, server_name, 0);	ret &= test_GetPrinterData(tctx, p, &handle03, "W3SvcInstalled",			WERR_OK, 0);	ret &= test_ClosePrinter(tctx, p, &handle03);	ret &= test_ClosePrinter(tctx, p, &unused_handle1);	ret &= test_ClosePrinter(tctx, p, &handle02);	ret &= test_OpenPrinterEx(tctx, p, &handle02,			ctx->printer_info[0].info2.sharename, 0);	ret &= test_GetPrinter(tctx, p, &handle02, tmp_ctx, 2, 0);	ret &= test_ClosePrinter(tctx, p, &handle02);end_testWinXP:	ret &= test_ClosePrinter(tctx, p, &handle01);	talloc_free(tmp_ctx);	talloc_free(ctx);	return ret;}struct torture_suite *torture_rpc_spoolss_win(TALLOC_CTX *mem_ctx){	struct torture_suite *suite = torture_suite_create(mem_ctx, "SPOOLSS-WIN");	struct torture_rpc_tcase *tcase = torture_suite_add_rpc_iface_tcase(suite, 							"win", &ndr_table_spoolss);	torture_rpc_tcase_add_test(tcase, "testWinXP", test_WinXP);	return suite;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -