s4-smbtorture: check for RouterReplyPrinterEx packets inside backchannel in RPC-SPOOL...
[ira/wip.git] / source4 / torture / rpc / spoolss_notify.c
1 /*
2    Unix SMB/CIFS implementation.
3    test suite for spoolss rpc notify operations
4
5    Copyright (C) Jelmer Vernooij 2007
6    Copyright (C) Guenther Deschner 2010
7
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 3 of the License, or
11    (at your option) any later version.
12
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23 #include "includes.h"
24 #include "system/filesys.h"
25 #include "torture/rpc/rpc.h"
26 #include "librpc/gen_ndr/ndr_spoolss_c.h"
27 #include "librpc/gen_ndr/ndr_spoolss.h"
28 #include "rpc_server/dcerpc_server.h"
29 #include "rpc_server/service_rpc.h"
30 #include "smbd/process_model.h"
31 #include "smb_server/smb_server.h"
32 #include "lib/socket/netif.h"
33 #include "ntvfs/ntvfs.h"
34 #include "param/param.h"
35
36 static NTSTATUS spoolss__op_bind(struct dcesrv_call_state *dce_call, const struct dcesrv_interface *iface)
37 {
38         return NT_STATUS_OK;
39 }
40
41 static void spoolss__op_unbind(struct dcesrv_connection_context *context, const struct dcesrv_interface *iface)
42 {
43 }
44
45 static NTSTATUS spoolss__op_ndr_pull(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct ndr_pull *pull, void **r)
46 {
47         enum ndr_err_code ndr_err;
48         uint16_t opnum = dce_call->pkt.u.request.opnum;
49
50         dce_call->fault_code = 0;
51
52         if (opnum >= ndr_table_spoolss.num_calls) {
53                 dce_call->fault_code = DCERPC_FAULT_OP_RNG_ERROR;
54                 return NT_STATUS_NET_WRITE_FAULT;
55         }
56
57         *r = talloc_size(mem_ctx, ndr_table_spoolss.calls[opnum].struct_size);
58         NT_STATUS_HAVE_NO_MEMORY(*r);
59
60         /* unravel the NDR for the packet */
61         ndr_err = ndr_table_spoolss.calls[opnum].ndr_pull(pull, NDR_IN, *r);
62         if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
63                 dcerpc_log_packet(dce_call->conn->packet_log_dir,
64                                                   &ndr_table_spoolss, opnum, NDR_IN,
65                                   &dce_call->pkt.u.request.stub_and_verifier);
66                 dce_call->fault_code = DCERPC_FAULT_NDR;
67                 return NT_STATUS_NET_WRITE_FAULT;
68         }
69
70         return NT_STATUS_OK;
71 }
72
73 /* Note that received_packets are allocated in talloc_autofree_context(),
74  * because no other context appears to stay around long enough. */
75 static struct received_packet {
76         uint16_t opnum;
77         void *r;
78         struct received_packet *prev, *next;
79 } *received_packets = NULL;
80
81 static WERROR _spoolss_ReplyOpenPrinter(struct dcesrv_call_state *dce_call,
82                                         TALLOC_CTX *mem_ctx,
83                                         struct spoolss_ReplyOpenPrinter *r)
84 {
85         DEBUG(1,("_spoolss_ReplyOpenPrinter\n"));
86
87         NDR_PRINT_IN_DEBUG(spoolss_ReplyOpenPrinter, r);
88
89         r->out.handle = talloc(r, struct policy_handle);
90         r->out.handle->handle_type = 42;
91         r->out.handle->uuid = GUID_random();
92         r->out.result = WERR_OK;
93
94         NDR_PRINT_OUT_DEBUG(spoolss_ReplyOpenPrinter, r);
95
96         return WERR_OK;
97 }
98
99 static WERROR _spoolss_ReplyClosePrinter(struct dcesrv_call_state *dce_call,
100                                          TALLOC_CTX *mem_ctx,
101                                          struct spoolss_ReplyClosePrinter *r)
102 {
103         DEBUG(1,("_spoolss_ReplyClosePrinter\n"));
104
105         NDR_PRINT_IN_DEBUG(spoolss_ReplyClosePrinter, r);
106
107         ZERO_STRUCTP(r->out.handle);
108         r->out.result = WERR_OK;
109
110         NDR_PRINT_OUT_DEBUG(spoolss_ReplyClosePrinter, r);
111
112         return WERR_OK;
113 }
114
115 static WERROR _spoolss_RouterReplyPrinterEx(struct dcesrv_call_state *dce_call,
116                                             TALLOC_CTX *mem_ctx,
117                                             struct spoolss_RouterReplyPrinterEx *r)
118 {
119         DEBUG(1,("_spoolss_RouterReplyPrinterEx\n"));
120
121         NDR_PRINT_IN_DEBUG(spoolss_RouterReplyPrinterEx, r);
122
123         r->out.reply_result = talloc(r, uint32_t);
124         *r->out.reply_result = 0;
125         r->out.result = WERR_OK;
126
127         NDR_PRINT_OUT_DEBUG(spoolss_RouterReplyPrinterEx, r);
128
129         return WERR_OK;
130 }
131
132 static NTSTATUS spoolss__op_dispatch(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, void *r)
133 {
134         uint16_t opnum = dce_call->pkt.u.request.opnum;
135         struct received_packet *rp;
136
137         rp = talloc_zero(talloc_autofree_context(), struct received_packet);
138         rp->opnum = opnum;
139         rp->r = talloc_reference(rp, r);
140
141         DLIST_ADD_END(received_packets, rp, struct received_packet *);
142
143         switch (opnum) {
144         case 58: {
145                 struct spoolss_ReplyOpenPrinter *r2 = (struct spoolss_ReplyOpenPrinter *)r;
146                 r2->out.result = _spoolss_ReplyOpenPrinter(dce_call, mem_ctx, r2);
147                 break;
148         }
149         case 60: {
150                 struct spoolss_ReplyClosePrinter *r2 = (struct spoolss_ReplyClosePrinter *)r;
151                 r2->out.result = _spoolss_ReplyClosePrinter(dce_call, mem_ctx, r2);
152                 break;
153         }
154         case 66: {
155                 struct spoolss_RouterReplyPrinterEx *r2 = (struct spoolss_RouterReplyPrinterEx *)r;
156                 r2->out.result = _spoolss_RouterReplyPrinterEx(dce_call, mem_ctx, r2);
157                 break;
158         }
159
160         default:
161                 dce_call->fault_code = DCERPC_FAULT_OP_RNG_ERROR;
162                 break;
163         }
164
165         if (dce_call->fault_code != 0) {
166                 dcerpc_log_packet(dce_call->conn->packet_log_dir,
167                                                   &ndr_table_spoolss, opnum, NDR_IN,
168                                   &dce_call->pkt.u.request.stub_and_verifier);
169                 return NT_STATUS_NET_WRITE_FAULT;
170         }
171         return NT_STATUS_OK;
172 }
173
174
175 static NTSTATUS spoolss__op_reply(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, void *r)
176 {
177         return NT_STATUS_OK;
178 }
179
180
181 static NTSTATUS spoolss__op_ndr_push(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct ndr_push *push, const void *r)
182 {
183         enum ndr_err_code ndr_err;
184         uint16_t opnum = dce_call->pkt.u.request.opnum;
185
186         ndr_err = ndr_table_spoolss.calls[opnum].ndr_push(push, NDR_OUT, r);
187         if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
188                 dce_call->fault_code = DCERPC_FAULT_NDR;
189                 return NT_STATUS_NET_WRITE_FAULT;
190         }
191
192         return NT_STATUS_OK;
193 }
194
195 const static struct dcesrv_interface notify_test_spoolss_interface = {
196         .name           = "spoolss",
197         .syntax_id  = {{0x12345678,0x1234,0xabcd,{0xef,0x00},{0x01,0x23,0x45,0x67,0x89,0xab}},1.0},
198         .bind           = spoolss__op_bind,
199         .unbind         = spoolss__op_unbind,
200         .ndr_pull       = spoolss__op_ndr_pull,
201         .dispatch       = spoolss__op_dispatch,
202         .reply          = spoolss__op_reply,
203         .ndr_push       = spoolss__op_ndr_push
204 };
205
206 static bool spoolss__op_interface_by_uuid(struct dcesrv_interface *iface, const struct GUID *uuid, uint32_t if_version)
207 {
208         if (notify_test_spoolss_interface.syntax_id.if_version == if_version &&
209                 GUID_equal(&notify_test_spoolss_interface.syntax_id.uuid, uuid)) {
210                 memcpy(iface,&notify_test_spoolss_interface, sizeof(*iface));
211                 return true;
212         }
213
214         return false;
215 }
216
217 static bool spoolss__op_interface_by_name(struct dcesrv_interface *iface, const char *name)
218 {
219         if (strcmp(notify_test_spoolss_interface.name, name)==0) {
220                 memcpy(iface, &notify_test_spoolss_interface, sizeof(*iface));
221                 return true;
222         }
223
224         return false;
225 }
226
227 static NTSTATUS spoolss__op_init_server(struct dcesrv_context *dce_ctx, const struct dcesrv_endpoint_server *ep_server)
228 {
229         int i;
230
231         for (i=0;i<ndr_table_spoolss.endpoints->count;i++) {
232                 NTSTATUS ret;
233                 const char *name = ndr_table_spoolss.endpoints->names[i];
234
235                 ret = dcesrv_interface_register(dce_ctx, name, &notify_test_spoolss_interface, NULL);
236                 if (!NT_STATUS_IS_OK(ret)) {
237                         DEBUG(1,("spoolss_op_init_server: failed to register endpoint '%s'\n",name));
238                         return ret;
239                 }
240         }
241
242         return NT_STATUS_OK;
243 }
244
245 static bool test_OpenPrinter(struct torture_context *tctx,
246                              struct dcerpc_pipe *p,
247                              struct policy_handle *handle,
248                              const char *name)
249 {
250         struct spoolss_OpenPrinter r;
251         const char *printername;
252
253         ZERO_STRUCT(r);
254
255         if (name) {
256                 printername     = talloc_asprintf(tctx, "\\\\%s\\%s", dcerpc_server_name(p), name);
257         } else {
258                 printername     = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
259         }
260
261         r.in.printername        = printername;
262         r.in.datatype           = NULL;
263         r.in.devmode_ctr.devmode= NULL;
264         r.in.access_mask        = SEC_FLAG_MAXIMUM_ALLOWED;
265         r.out.handle            = handle;
266
267         torture_comment(tctx, "Testing OpenPrinter(%s)\n", r.in.printername);
268
269         torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_OpenPrinter(p, tctx, &r),
270                 "OpenPrinter failed");
271         torture_assert_werr_ok(tctx, r.out.result,
272                 "OpenPrinter failed");
273
274         return true;
275 }
276
277 static struct spoolss_NotifyOption *setup_printserver_NotifyOption(struct torture_context *tctx)
278 {
279         struct spoolss_NotifyOption *o;
280
281         o = talloc_zero(tctx, struct spoolss_NotifyOption);
282
283         o->version = 2;
284         o->flags = PRINTER_NOTIFY_OPTIONS_REFRESH;
285
286         o->count = 2;
287         o->types = talloc_zero_array(o, struct spoolss_NotifyOptionType, o->count);
288
289         o->types[0].type = PRINTER_NOTIFY_TYPE;
290         o->types[0].count = 1;
291         o->types[0].fields = talloc_array(o->types, union spoolss_Field, o->types[0].count);
292         o->types[0].fields[0].field = PRINTER_NOTIFY_FIELD_SERVER_NAME;
293
294         o->types[1].type = JOB_NOTIFY_TYPE;
295         o->types[1].count = 1;
296         o->types[1].fields = talloc_array(o->types, union spoolss_Field, o->types[1].count);
297         o->types[1].fields[0].field = JOB_NOTIFY_FIELD_MACHINE_NAME;
298
299         return o;
300 }
301
302 static struct spoolss_NotifyOption *setup_printer_NotifyOption(struct torture_context *tctx)
303 {
304         struct spoolss_NotifyOption *o;
305
306         o = talloc_zero(tctx, struct spoolss_NotifyOption);
307
308         o->version = 2;
309         o->flags = PRINTER_NOTIFY_OPTIONS_REFRESH;
310
311         o->count = 1;
312         o->types = talloc_zero_array(o, struct spoolss_NotifyOptionType, o->count);
313
314         o->types[0].type = PRINTER_NOTIFY_TYPE;
315         o->types[0].count = 1;
316         o->types[0].fields = talloc_array(o->types, union spoolss_Field, o->types[0].count);
317         o->types[0].fields[0].field = PRINTER_NOTIFY_FIELD_COMMENT;
318
319         return o;
320 }
321
322
323 static bool test_RemoteFindFirstPrinterChangeNotifyEx(struct torture_context *tctx,
324                                                       struct dcerpc_pipe *p,
325                                                       struct policy_handle *handle,
326                                                       const char *address,
327                                                       struct spoolss_NotifyOption *option)
328 {
329         struct spoolss_RemoteFindFirstPrinterChangeNotifyEx r;
330
331         torture_comment(tctx, "Testing RemoteFindFirstPrinterChangeNotifyEx\n");
332
333         r.in.flags = 0;
334         r.in.local_machine = talloc_asprintf(tctx, "\\\\%s", address);
335         r.in.options = 0;
336         r.in.printer_local = 0;
337         r.in.notify_options = option;
338         r.in.handle = handle;
339
340         torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_RemoteFindFirstPrinterChangeNotifyEx(p, tctx, &r),
341                 "RemoteFindFirstPrinterChangeNotifyEx failed");
342         torture_assert_werr_ok(tctx, r.out.result,
343                 "error return code for RemoteFindFirstPrinterChangeNotifyEx");
344
345         return true;
346 }
347
348 static bool test_RouterRefreshPrinterChangeNotify(struct torture_context *tctx,
349                                                   struct dcerpc_pipe *p,
350                                                   struct policy_handle *handle,
351                                                   struct spoolss_NotifyOption *options)
352 {
353         struct spoolss_RouterRefreshPrinterChangeNotify r;
354         struct spoolss_NotifyInfo *info;
355
356         torture_comment(tctx, "Testing RouterRefreshPrinterChangeNotify\n");
357
358         r.in.handle = handle;
359         r.in.change_low = 0;
360         r.in.options = options;
361         r.out.info = &info;
362
363         torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_RouterRefreshPrinterChangeNotify(p, tctx, &r),
364                 "RouterRefreshPrinterChangeNotify failed");
365         torture_assert_werr_ok(tctx, r.out.result,
366                 "error return code for RouterRefreshPrinterChangeNotify");
367
368         return true;
369 }
370
371 static bool test_ClosePrinter(struct torture_context *tctx,
372                               struct dcerpc_pipe *p,
373                               struct policy_handle *handle)
374 {
375         struct spoolss_ClosePrinter r;
376
377         r.in.handle = handle;
378         r.out.handle = handle;
379
380         torture_comment(tctx, "Testing ClosePrinter\n");
381
382         torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_ClosePrinter(p, tctx, &r),
383                 "ClosePrinter failed");
384         torture_assert_werr_ok(tctx, r.out.result,
385                 "ClosePrinter failed");
386
387         return true;
388 }
389
390 static bool test_SetPrinter(struct torture_context *tctx,
391                             struct dcerpc_pipe *p,
392                             struct policy_handle *handle)
393 {
394         struct spoolss_GetPrinter g;
395         struct spoolss_SetPrinter r;
396         struct spoolss_SetPrinterInfo2 info2;
397         struct spoolss_SetPrinterInfoCtr info_ctr;
398         struct spoolss_DevmodeContainer devmode_ctr;
399         struct sec_desc_buf secdesc_ctr;
400
401         {
402                 uint32_t needed;
403
404                 g.in.handle = handle;
405                 g.in.level = 2;
406                 g.in.buffer = NULL;
407                 g.in.offered = 0;
408                 g.out.needed = &needed;
409
410                 torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_GetPrinter(p, tctx, &g), "GetPrinter failed");
411                 if (W_ERROR_EQUAL(g.out.result, WERR_INSUFFICIENT_BUFFER)) {
412                         DATA_BLOB blob = data_blob_talloc_zero(tctx, needed);
413                         g.in.offered = needed;
414                         g.in.buffer = &blob;
415                         torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_GetPrinter(p, tctx, &g), "GetPrinter failed");
416                 }
417                 torture_assert_werr_ok(tctx, g.out.result, "GetPrinter failed");
418         }
419
420
421         ZERO_STRUCT(devmode_ctr);
422         ZERO_STRUCT(secdesc_ctr);
423
424         info2.servername        = g.out.info->info2.servername;
425         info2.printername       = g.out.info->info2.printername;
426         info2.sharename         = g.out.info->info2.sharename;
427         info2.portname          = g.out.info->info2.portname;
428         info2.drivername        = g.out.info->info2.drivername;
429         info2.comment           = talloc_asprintf(tctx, "torture_comment %d\n", (int)time(NULL));
430         info2.location          = g.out.info->info2.location;
431         info2.devmode_ptr       = 0;
432         info2.sepfile           = g.out.info->info2.sepfile;
433         info2.printprocessor    = g.out.info->info2.printprocessor;
434         info2.datatype          = g.out.info->info2.datatype;
435         info2.parameters        = g.out.info->info2.parameters;
436         info2.secdesc_ptr       = 0;
437         info2.attributes        = g.out.info->info2.attributes;
438         info2.priority          = g.out.info->info2.priority;
439         info2.defaultpriority   = g.out.info->info2.defaultpriority;
440         info2.starttime         = g.out.info->info2.starttime;
441         info2.untiltime         = g.out.info->info2.untiltime;
442         info2.status            = g.out.info->info2.status;
443         info2.cjobs             = g.out.info->info2.cjobs;
444         info2.averageppm        = g.out.info->info2.averageppm;
445
446         info_ctr.level = 2;
447         info_ctr.info.info2 = &info2;
448
449         r.in.handle = handle;
450         r.in.info_ctr = &info_ctr;
451         r.in.devmode_ctr = &devmode_ctr;
452         r.in.secdesc_ctr = &secdesc_ctr;
453         r.in.command = 0;
454
455         torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_SetPrinter(p, tctx, &r), "SetPrinter failed");
456         torture_assert_werr_ok(tctx, r.out.result, "SetPrinter failed");
457
458         return true;
459 }
460
461 static bool test_start_dcerpc_server(struct torture_context *tctx,
462                                      struct tevent_context *event_ctx,
463                                      struct dcesrv_context **dce_ctx_p,
464                                      const char **address_p)
465 {
466         struct dcesrv_endpoint_server ep_server;
467         NTSTATUS status;
468         struct dcesrv_context *dce_ctx;
469         const char *endpoints[] = { "spoolss", NULL };
470         struct dcesrv_endpoint *e;
471         const char *address;
472         struct interface *ifaces;
473
474         ntvfs_init(tctx->lp_ctx);
475
476         /* fill in our name */
477         ep_server.name = "spoolss";
478
479         /* fill in all the operations */
480         ep_server.init_server = spoolss__op_init_server;
481
482         ep_server.interface_by_uuid = spoolss__op_interface_by_uuid;
483         ep_server.interface_by_name = spoolss__op_interface_by_name;
484
485         torture_assert_ntstatus_ok(tctx, dcerpc_register_ep_server(&ep_server),
486                                   "unable to register spoolss server");
487
488         lp_set_cmdline(tctx->lp_ctx, "dcerpc endpoint servers", "spoolss");
489
490         load_interfaces(tctx, lp_interfaces(tctx->lp_ctx), &ifaces);
491         address = iface_n_ip(ifaces, 0);
492
493         torture_comment(tctx, "Listening for callbacks on %s\n", address);
494
495         status = smbsrv_add_socket(event_ctx, tctx->lp_ctx, &single_ops, address);
496         torture_assert_ntstatus_ok(tctx, status, "starting smb server");
497
498         status = dcesrv_init_context(tctx, tctx->lp_ctx, endpoints, &dce_ctx);
499         torture_assert_ntstatus_ok(tctx, status,
500                                    "unable to initialize DCE/RPC server");
501
502         for (e=dce_ctx->endpoint_list;e;e=e->next) {
503                 status = dcesrv_add_ep(dce_ctx, tctx->lp_ctx,
504                                        e, tctx->ev, &single_ops);
505                 torture_assert_ntstatus_ok(tctx, status,
506                                 "unable listen on dcerpc endpoint server");
507         }
508
509         *dce_ctx_p = dce_ctx;
510         *address_p = address;
511
512         return true;
513 }
514
515 static struct received_packet *last_packet(struct received_packet *p)
516 {
517         struct received_packet *tmp;
518         for (tmp = p; tmp->next; tmp = tmp->next) ;;
519         return tmp;
520 }
521
522 static bool test_RFFPCNEx(struct torture_context *tctx,
523                           struct dcerpc_pipe *p)
524 {
525         struct dcesrv_context *dce_ctx;
526         struct policy_handle handle;
527         const char *address;
528         struct received_packet *tmp;
529         struct spoolss_NotifyOption *server_option = setup_printserver_NotifyOption(tctx);
530         struct spoolss_NotifyOption *printer_option = setup_printer_NotifyOption(tctx);
531
532         received_packets = NULL;
533
534         /* Start DCE/RPC server */
535         torture_assert(tctx, test_start_dcerpc_server(tctx, p->conn->event_ctx, &dce_ctx, &address), "");
536
537         torture_assert(tctx, test_OpenPrinter(tctx, p, &handle, NULL), "");
538         torture_assert(tctx, test_RemoteFindFirstPrinterChangeNotifyEx(tctx, p, &handle, address, server_option), "");
539         torture_assert(tctx, received_packets, "no packets received");
540         torture_assert_int_equal(tctx, received_packets->opnum, NDR_SPOOLSS_REPLYOPENPRINTER,
541                 "no ReplyOpenPrinter packet after RemoteFindFirstPrinterChangeNotifyEx");
542         torture_assert(tctx, test_RouterRefreshPrinterChangeNotify(tctx, p, &handle, NULL), "");
543         torture_assert(tctx, test_RouterRefreshPrinterChangeNotify(tctx, p, &handle, server_option), "");
544         torture_assert(tctx, test_ClosePrinter(tctx, p, &handle), "");
545         tmp = last_packet(received_packets);
546         torture_assert_int_equal(tctx, tmp->opnum, NDR_SPOOLSS_REPLYCLOSEPRINTER,
547                 "no ReplyClosePrinter packet after ClosePrinter");
548 #if 0
549         torture_assert(tctx, test_OpenPrinter(tctx, p, &handle, "Epson AL-2600"), "");
550         torture_assert(tctx, test_RemoteFindFirstPrinterChangeNotifyEx(tctx, p, &handle, address, printer_option), "");
551         tmp = last_packet(received_packets);
552         torture_assert_int_equal(tctx, tmp->opnum, NDR_SPOOLSS_REPLYOPENPRINTER,
553                 "no ReplyOpenPrinter packet after RemoteFindFirstPrinterChangeNotifyEx");
554         torture_assert(tctx, test_RouterRefreshPrinterChangeNotify(tctx, p, &handle, NULL), "");
555         torture_assert(tctx, test_RouterRefreshPrinterChangeNotify(tctx, p, &handle, printer_option), "");
556         torture_assert(tctx, test_SetPrinter(tctx, p, &handle), "");
557         tmp = last_packet(received_packets);
558         torture_assert_int_equal(tctx, tmp->opnum, NDR_SPOOLSS_ROUTERREPLYPRINTEREX,
559                 "no RouterReplyPrinterEx packet after ClosePrinter");
560         torture_assert(tctx, test_ClosePrinter(tctx, p, &handle), "");
561         tmp = last_packet(received_packets);
562         torture_assert_int_equal(tctx, tmp->opnum, NDR_SPOOLSS_REPLYCLOSEPRINTER,
563                 "no ReplyClosePrinter packet after ClosePrinter");
564 #endif
565         /* Shut down DCE/RPC server */
566         talloc_free(dce_ctx);
567
568         return true;
569 }
570
571 /** Test that makes sure that calling ReplyOpenPrinter()
572  * on Samba 4 will cause an irpc broadcast call.
573  */
574 static bool test_ReplyOpenPrinter(struct torture_context *tctx,
575                                   struct dcerpc_pipe *p)
576 {
577         struct spoolss_ReplyOpenPrinter r;
578         struct spoolss_ReplyClosePrinter s;
579         struct policy_handle h;
580
581         if (torture_setting_bool(tctx, "samba3", false)) {
582                 torture_skip(tctx, "skipping ReplyOpenPrinter server implementation test against s3\n");
583         }
584
585         r.in.server_name = "earth";
586         r.in.printer_local = 2;
587         r.in.type = REG_DWORD;
588         r.in.bufsize = 0;
589         r.in.buffer = NULL;
590         r.out.handle = &h;
591
592         torture_assert_ntstatus_ok(tctx,
593                         dcerpc_spoolss_ReplyOpenPrinter(p, tctx, &r),
594                         "spoolss_ReplyOpenPrinter call failed");
595
596         torture_assert_werr_ok(tctx, r.out.result, "error return code");
597
598         s.in.handle = &h;
599         s.out.handle = &h;
600
601         torture_assert_ntstatus_ok(tctx,
602                         dcerpc_spoolss_ReplyClosePrinter(p, tctx, &s),
603                         "spoolss_ReplyClosePrinter call failed");
604
605         torture_assert_werr_ok(tctx, r.out.result, "error return code");
606
607         return true;
608 }
609
610 struct torture_suite *torture_rpc_spoolss_notify(TALLOC_CTX *mem_ctx)
611 {
612         struct torture_suite *suite = torture_suite_create(mem_ctx, "SPOOLSS-NOTIFY");
613
614         struct torture_rpc_tcase *tcase = torture_suite_add_rpc_iface_tcase(suite,
615                                                         "notify", &ndr_table_spoolss);
616
617         torture_rpc_tcase_add_test(tcase, "testRFFPCNEx", test_RFFPCNEx);
618         torture_rpc_tcase_add_test(tcase, "testReplyOpenPrinter", test_ReplyOpenPrinter);
619
620         return suite;
621 }