summaryrefslogtreecommitdiff
path: root/source4/torture/rpc
diff options
context:
space:
mode:
authorGünther Deschner <gd@samba.org>2016-09-05 22:49:39 +0200
committerJeremy Allison <jra@samba.org>2016-11-15 01:14:22 +0100
commit887e00cb0f993139fad722df9ba43fd7052fcf91 (patch)
treea1122f2088954bf087d46636a1b9bf8e93f9704e /source4/torture/rpc
parent20b4b2bdca670ec3b51a643a5f439d2948ee8176 (diff)
downloadsamba-887e00cb0f993139fad722df9ba43fd7052fcf91.tar.gz
s4-torture: add test for spoolss vs. iremotewinspool context handles
This test demonstrates that one cannot use a handle retrieved via iremotewinspool in a spoolss context. Guenther Signed-off-by: Guenther Deschner <gd@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
Diffstat (limited to 'source4/torture/rpc')
-rw-r--r--source4/torture/rpc/iremotewinspool.c63
1 files changed, 63 insertions, 0 deletions
diff --git a/source4/torture/rpc/iremotewinspool.c b/source4/torture/rpc/iremotewinspool.c
index fb7d7d4e802..b3e45f0cf6d 100644
--- a/source4/torture/rpc/iremotewinspool.c
+++ b/source4/torture/rpc/iremotewinspool.c
@@ -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"
@@ -610,6 +611,60 @@ static bool test_AsyncGetPrinterData(struct torture_context *tctx,
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_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));
+
+ torture_assert(tctx,
+ test_AsyncOpenPrinter_byprinter(tctx, ctx, p, printer_name, &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;
+}
+
struct torture_suite *torture_rpc_iremotewinspool(TALLOC_CTX *mem_ctx)
{
struct torture_suite *suite = torture_suite_create(mem_ctx, "iremotewinspool");
@@ -627,5 +682,13 @@ struct torture_suite *torture_rpc_iremotewinspool(TALLOC_CTX *mem_ctx)
torture_tcase_add_simple_test(tcase, "AsyncEnumPrinters", test_AsyncEnumPrinters);
torture_tcase_add_simple_test(tcase, "AsyncGetPrinterData", test_AsyncGetPrinterData);
+ 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;
}