s4:rpc_server: make it possible to specify ncacn_np_secondary_endpoint
[gd/samba-autobuild/.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 "librpc/gen_ndr/ndr_spoolss_c.h"
26 #include "librpc/gen_ndr/ndr_spoolss.h"
27 #include "torture/rpc/torture_rpc.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_connection_context *context,
37                                  const struct dcesrv_interface *iface)
38 {
39         return NT_STATUS_OK;
40 }
41
42 static void spoolss__op_unbind(struct dcesrv_connection_context *context, const struct dcesrv_interface *iface)
43 {
44 }
45
46 static NTSTATUS spoolss__op_ndr_pull(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct ndr_pull *pull, void **r)
47 {
48         enum ndr_err_code ndr_err;
49         uint16_t opnum = dce_call->pkt.u.request.opnum;
50
51         dce_call->fault_code = 0;
52
53         if (opnum >= ndr_table_spoolss.num_calls) {
54                 dce_call->fault_code = DCERPC_FAULT_OP_RNG_ERROR;
55                 return NT_STATUS_NET_WRITE_FAULT;
56         }
57
58         *r = talloc_size(mem_ctx, ndr_table_spoolss.calls[opnum].struct_size);
59         NT_STATUS_HAVE_NO_MEMORY(*r);
60
61         /* unravel the NDR for the packet */
62         ndr_err = ndr_table_spoolss.calls[opnum].ndr_pull(pull, NDR_IN, *r);
63         if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
64                 dcerpc_log_packet(dce_call->conn->packet_log_dir,
65                                                   &ndr_table_spoolss, opnum, NDR_IN,
66                                   &dce_call->pkt.u.request.stub_and_verifier);
67                 dce_call->fault_code = DCERPC_FAULT_NDR;
68                 return NT_STATUS_NET_WRITE_FAULT;
69         }
70
71         return NT_STATUS_OK;
72 }
73
74 /* Note that received_packets are allocated on the NULL context
75  * because no other context appears to stay around long enough. */
76 static struct received_packet {
77         uint16_t opnum;
78         void *r;
79         struct received_packet *prev, *next;
80 } *received_packets = NULL;
81
82 static void free_received_packets(void)
83 {
84         struct received_packet *rp;
85         struct received_packet *rp_next;
86
87         for (rp = received_packets; rp; rp = rp_next) {
88                 rp_next = rp->next;
89                 DLIST_REMOVE(received_packets, rp);
90                 talloc_unlink(rp, rp->r);
91                 talloc_free(rp);
92         }
93         received_packets = NULL;
94 }
95
96 static WERROR _spoolss_ReplyOpenPrinter(struct dcesrv_call_state *dce_call,
97                                         TALLOC_CTX *mem_ctx,
98                                         struct spoolss_ReplyOpenPrinter *r)
99 {
100         DEBUG(1,("_spoolss_ReplyOpenPrinter\n"));
101
102         NDR_PRINT_IN_DEBUG(spoolss_ReplyOpenPrinter, r);
103
104         r->out.handle = talloc(r, struct policy_handle);
105         r->out.handle->handle_type = 42;
106         r->out.handle->uuid = GUID_random();
107         r->out.result = WERR_OK;
108
109         NDR_PRINT_OUT_DEBUG(spoolss_ReplyOpenPrinter, r);
110
111         return WERR_OK;
112 }
113
114 static WERROR _spoolss_ReplyClosePrinter(struct dcesrv_call_state *dce_call,
115                                          TALLOC_CTX *mem_ctx,
116                                          struct spoolss_ReplyClosePrinter *r)
117 {
118         DEBUG(1,("_spoolss_ReplyClosePrinter\n"));
119
120         NDR_PRINT_IN_DEBUG(spoolss_ReplyClosePrinter, r);
121
122         ZERO_STRUCTP(r->out.handle);
123         r->out.result = WERR_OK;
124
125         NDR_PRINT_OUT_DEBUG(spoolss_ReplyClosePrinter, r);
126
127         return WERR_OK;
128 }
129
130 static WERROR _spoolss_RouterReplyPrinterEx(struct dcesrv_call_state *dce_call,
131                                             TALLOC_CTX *mem_ctx,
132                                             struct spoolss_RouterReplyPrinterEx *r)
133 {
134         DEBUG(1,("_spoolss_RouterReplyPrinterEx\n"));
135
136         NDR_PRINT_IN_DEBUG(spoolss_RouterReplyPrinterEx, r);
137
138         r->out.reply_result = talloc(r, uint32_t);
139         *r->out.reply_result = 0;
140         r->out.result = WERR_OK;
141
142         NDR_PRINT_OUT_DEBUG(spoolss_RouterReplyPrinterEx, r);
143
144         return WERR_OK;
145 }
146
147 static NTSTATUS spoolss__op_dispatch(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, void *r)
148 {
149         uint16_t opnum = dce_call->pkt.u.request.opnum;
150         struct received_packet *rp;
151
152         rp = talloc_zero(NULL, struct received_packet);
153         rp->opnum = opnum;
154         rp->r = talloc_reference(rp, r);
155
156         DLIST_ADD_END(received_packets, rp);
157
158         switch (opnum) {
159         case 58: {
160                 struct spoolss_ReplyOpenPrinter *r2 = (struct spoolss_ReplyOpenPrinter *)r;
161                 r2->out.result = _spoolss_ReplyOpenPrinter(dce_call, mem_ctx, r2);
162                 break;
163         }
164         case 60: {
165                 struct spoolss_ReplyClosePrinter *r2 = (struct spoolss_ReplyClosePrinter *)r;
166                 r2->out.result = _spoolss_ReplyClosePrinter(dce_call, mem_ctx, r2);
167                 break;
168         }
169         case 66: {
170                 struct spoolss_RouterReplyPrinterEx *r2 = (struct spoolss_RouterReplyPrinterEx *)r;
171                 r2->out.result = _spoolss_RouterReplyPrinterEx(dce_call, mem_ctx, r2);
172                 break;
173         }
174
175         default:
176                 dce_call->fault_code = DCERPC_FAULT_OP_RNG_ERROR;
177                 break;
178         }
179
180         if (dce_call->fault_code != 0) {
181                 dcerpc_log_packet(dce_call->conn->packet_log_dir,
182                                                   &ndr_table_spoolss, opnum, NDR_IN,
183                                   &dce_call->pkt.u.request.stub_and_verifier);
184                 return NT_STATUS_NET_WRITE_FAULT;
185         }
186         return NT_STATUS_OK;
187 }
188
189
190 static NTSTATUS spoolss__op_reply(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, void *r)
191 {
192         return NT_STATUS_OK;
193 }
194
195
196 static NTSTATUS spoolss__op_ndr_push(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct ndr_push *push, const void *r)
197 {
198         enum ndr_err_code ndr_err;
199         uint16_t opnum = dce_call->pkt.u.request.opnum;
200
201         ndr_err = ndr_table_spoolss.calls[opnum].ndr_push(push, NDR_OUT, r);
202         if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
203                 dce_call->fault_code = DCERPC_FAULT_NDR;
204                 return NT_STATUS_NET_WRITE_FAULT;
205         }
206
207         return NT_STATUS_OK;
208 }
209
210 const static struct dcesrv_interface notify_test_spoolss_interface = {
211         .name           = "spoolss",
212         .syntax_id  = {{0x12345678,0x1234,0xabcd,{0xef,0x00},{0x01,0x23,0x45,0x67,0x89,0xab}},1.0},
213         .bind           = spoolss__op_bind,
214         .unbind         = spoolss__op_unbind,
215         .ndr_pull       = spoolss__op_ndr_pull,
216         .dispatch       = spoolss__op_dispatch,
217         .reply          = spoolss__op_reply,
218         .ndr_push       = spoolss__op_ndr_push
219 };
220
221 static bool spoolss__op_interface_by_uuid(struct dcesrv_interface *iface, const struct GUID *uuid, uint32_t if_version)
222 {
223         if (notify_test_spoolss_interface.syntax_id.if_version == if_version &&
224                 GUID_equal(&notify_test_spoolss_interface.syntax_id.uuid, uuid)) {
225                 memcpy(iface,&notify_test_spoolss_interface, sizeof(*iface));
226                 return true;
227         }
228
229         return false;
230 }
231
232 static bool spoolss__op_interface_by_name(struct dcesrv_interface *iface, const char *name)
233 {
234         if (strcmp(notify_test_spoolss_interface.name, name)==0) {
235                 memcpy(iface, &notify_test_spoolss_interface, sizeof(*iface));
236                 return true;
237         }
238
239         return false;
240 }
241
242 static NTSTATUS spoolss__op_init_server(struct dcesrv_context *dce_ctx, const struct dcesrv_endpoint_server *ep_server)
243 {
244         int i;
245
246         for (i=0;i<ndr_table_spoolss.endpoints->count;i++) {
247                 NTSTATUS ret;
248                 const char *name = ndr_table_spoolss.endpoints->names[i];
249
250                 ret = dcesrv_interface_register(dce_ctx,
251                                                 name,
252                                                 NULL,
253                                                 &notify_test_spoolss_interface,
254                                                 NULL);
255                 if (!NT_STATUS_IS_OK(ret)) {
256                         DEBUG(1,("spoolss_op_init_server: failed to register endpoint '%s'\n",name));
257                         return ret;
258                 }
259         }
260
261         return NT_STATUS_OK;
262 }
263
264 static bool test_OpenPrinter(struct torture_context *tctx,
265                              struct dcerpc_pipe *p,
266                              struct policy_handle *handle,
267                              const char *printername)
268 {
269         struct spoolss_OpenPrinter r;
270         struct dcerpc_binding_handle *b = p->binding_handle;
271
272         ZERO_STRUCT(r);
273
274         r.in.printername        = printername;
275         r.in.datatype           = NULL;
276         r.in.devmode_ctr.devmode= NULL;
277         r.in.access_mask        = SEC_FLAG_MAXIMUM_ALLOWED;
278         r.out.handle            = handle;
279
280         torture_comment(tctx, "Testing OpenPrinter(%s)\n", r.in.printername);
281
282         torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_OpenPrinter_r(b, tctx, &r),
283                 "OpenPrinter failed");
284         torture_assert_werr_ok(tctx, r.out.result,
285                 "OpenPrinter failed");
286
287         return true;
288 }
289
290 static struct spoolss_NotifyOption *setup_printserver_NotifyOption(struct torture_context *tctx)
291 {
292         struct spoolss_NotifyOption *o;
293
294         o = talloc_zero(tctx, struct spoolss_NotifyOption);
295
296         o->version = 2;
297         o->flags = PRINTER_NOTIFY_OPTIONS_REFRESH;
298
299         o->count = 2;
300         o->types = talloc_zero_array(o, struct spoolss_NotifyOptionType, o->count);
301
302         o->types[0].type = PRINTER_NOTIFY_TYPE;
303         o->types[0].count = 1;
304         o->types[0].fields = talloc_array(o->types, union spoolss_Field, o->types[0].count);
305         o->types[0].fields[0].field = PRINTER_NOTIFY_FIELD_SERVER_NAME;
306
307         o->types[1].type = JOB_NOTIFY_TYPE;
308         o->types[1].count = 1;
309         o->types[1].fields = talloc_array(o->types, union spoolss_Field, o->types[1].count);
310         o->types[1].fields[0].field = JOB_NOTIFY_FIELD_MACHINE_NAME;
311
312         return o;
313 }
314
315 #if 0
316 static struct spoolss_NotifyOption *setup_printer_NotifyOption(struct torture_context *tctx)
317 {
318         struct spoolss_NotifyOption *o;
319
320         o = talloc_zero(tctx, struct spoolss_NotifyOption);
321
322         o->version = 2;
323         o->flags = PRINTER_NOTIFY_OPTIONS_REFRESH;
324
325         o->count = 1;
326         o->types = talloc_zero_array(o, struct spoolss_NotifyOptionType, o->count);
327
328         o->types[0].type = PRINTER_NOTIFY_TYPE;
329         o->types[0].count = 1;
330         o->types[0].fields = talloc_array(o->types, union spoolss_Field, o->types[0].count);
331         o->types[0].fields[0].field = PRINTER_NOTIFY_FIELD_COMMENT;
332
333         return o;
334 }
335 #endif
336
337 static bool test_RemoteFindFirstPrinterChangeNotifyEx(struct torture_context *tctx,
338                                                       struct dcerpc_binding_handle *b,
339                                                       struct policy_handle *handle,
340                                                       const char *address,
341                                                       struct spoolss_NotifyOption *option)
342 {
343         struct spoolss_RemoteFindFirstPrinterChangeNotifyEx r;
344         const char *local_machine = talloc_asprintf(tctx, "\\\\%s", address);
345
346         torture_comment(tctx, "Testing RemoteFindFirstPrinterChangeNotifyEx(%s)\n", local_machine);
347
348         r.in.flags = 0;
349         r.in.local_machine = local_machine;
350         r.in.options = 0;
351         r.in.printer_local = 0;
352         r.in.notify_options = option;
353         r.in.handle = handle;
354
355         torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_RemoteFindFirstPrinterChangeNotifyEx_r(b, tctx, &r),
356                 "RemoteFindFirstPrinterChangeNotifyEx failed");
357         torture_assert_werr_ok(tctx, r.out.result,
358                 "error return code for RemoteFindFirstPrinterChangeNotifyEx");
359
360         return true;
361 }
362
363 static bool test_RouterRefreshPrinterChangeNotify(struct torture_context *tctx,
364                                                   struct dcerpc_binding_handle *b,
365                                                   struct policy_handle *handle,
366                                                   struct spoolss_NotifyOption *options,
367                                                   struct spoolss_NotifyInfo **info)
368 {
369         struct spoolss_RouterRefreshPrinterChangeNotify r;
370
371         torture_comment(tctx, "Testing RouterRefreshPrinterChangeNotify\n");
372
373         r.in.handle = handle;
374         r.in.change_low = 0;
375         r.in.options = options;
376         r.out.info = info;
377
378         torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_RouterRefreshPrinterChangeNotify_r(b, tctx, &r),
379                 "RouterRefreshPrinterChangeNotify failed");
380         torture_assert_werr_ok(tctx, r.out.result,
381                 "error return code for RouterRefreshPrinterChangeNotify");
382
383         return true;
384 }
385
386 #if 0
387 static bool test_SetPrinter(struct torture_context *tctx,
388                             struct dcerpc_pipe *p,
389                             struct policy_handle *handle)
390 {
391         union spoolss_PrinterInfo info;
392         struct spoolss_SetPrinter r;
393         struct spoolss_SetPrinterInfo2 info2;
394         struct spoolss_SetPrinterInfoCtr info_ctr;
395         struct spoolss_DevmodeContainer devmode_ctr;
396         struct sec_desc_buf secdesc_ctr;
397         struct dcerpc_binding_handle *b = p->binding_handle;
398
399         torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, 2, &info), "");
400
401         ZERO_STRUCT(devmode_ctr);
402         ZERO_STRUCT(secdesc_ctr);
403
404         info2.servername        = info.info2.servername;
405         info2.printername       = info.info2.printername;
406         info2.sharename         = info.info2.sharename;
407         info2.portname          = info.info2.portname;
408         info2.drivername        = info.info2.drivername;
409         info2.comment           = talloc_asprintf(tctx, "torture_comment %d\n", (int)time(NULL));
410         info2.location          = info.info2.location;
411         info2.devmode_ptr       = 0;
412         info2.sepfile           = info.info2.sepfile;
413         info2.printprocessor    = info.info2.printprocessor;
414         info2.datatype          = info.info2.datatype;
415         info2.parameters        = info.info2.parameters;
416         info2.secdesc_ptr       = 0;
417         info2.attributes        = info.info2.attributes;
418         info2.priority          = info.info2.priority;
419         info2.defaultpriority   = info.info2.defaultpriority;
420         info2.starttime         = info.info2.starttime;
421         info2.untiltime         = info.info2.untiltime;
422         info2.status            = info.info2.status;
423         info2.cjobs             = info.info2.cjobs;
424         info2.averageppm        = info.info2.averageppm;
425
426         info_ctr.level = 2;
427         info_ctr.info.info2 = &info2;
428
429         r.in.handle = handle;
430         r.in.info_ctr = &info_ctr;
431         r.in.devmode_ctr = &devmode_ctr;
432         r.in.secdesc_ctr = &secdesc_ctr;
433         r.in.command = 0;
434
435         torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_SetPrinter_r(b, tctx, &r), "SetPrinter failed");
436         torture_assert_werr_ok(tctx, r.out.result, "SetPrinter failed");
437
438         return true;
439 }
440 #endif
441
442 static bool test_start_dcerpc_server(struct torture_context *tctx,
443                                      struct tevent_context *event_ctx,
444                                      struct dcesrv_context **dce_ctx_p,
445                                      const char **address_p)
446 {
447         struct dcesrv_endpoint_server ep_server;
448         NTSTATUS status;
449         struct dcesrv_context *dce_ctx;
450         const char *endpoints[] = { "spoolss", NULL };
451         struct dcesrv_endpoint *e;
452         const char *address;
453         struct interface *ifaces;
454
455         ntvfs_init(tctx->lp_ctx);
456
457         /* fill in our name */
458         ep_server.name = "spoolss";
459
460         /* fill in all the operations */
461         ep_server.init_server = spoolss__op_init_server;
462
463         ep_server.interface_by_uuid = spoolss__op_interface_by_uuid;
464         ep_server.interface_by_name = spoolss__op_interface_by_name;
465
466         torture_assert_ntstatus_ok(tctx, dcerpc_register_ep_server(&ep_server),
467                                   "unable to register spoolss server");
468
469         lpcfg_set_cmdline(tctx->lp_ctx, "dcerpc endpoint servers", "spoolss");
470
471         load_interface_list(tctx, tctx->lp_ctx, &ifaces);
472         address = iface_list_first_v4(ifaces);
473
474         torture_comment(tctx, "Listening for callbacks on %s\n", address);
475
476         status = process_model_init(tctx->lp_ctx);
477         torture_assert_ntstatus_ok(tctx, status,
478                                    "unable to initialize process models");
479
480         status = smbsrv_add_socket(tctx, event_ctx, tctx->lp_ctx,
481                                    process_model_startup("single"),
482                                    address, NULL);
483         torture_assert_ntstatus_ok(tctx, status, "starting smb server");
484
485         status = dcesrv_init_context(tctx, tctx->lp_ctx, endpoints, &dce_ctx);
486         torture_assert_ntstatus_ok(tctx, status,
487                                    "unable to initialize DCE/RPC server");
488
489         for (e=dce_ctx->endpoint_list;e;e=e->next) {
490                 status = dcesrv_add_ep(dce_ctx, tctx->lp_ctx,
491                                        e, tctx->ev,
492                                        process_model_startup("single"), NULL);
493                 torture_assert_ntstatus_ok(tctx, status,
494                                 "unable listen on dcerpc endpoint server");
495         }
496
497         *dce_ctx_p = dce_ctx;
498         *address_p = address;
499
500         return true;
501 }
502
503 static struct received_packet *last_packet(struct received_packet *p)
504 {
505         struct received_packet *tmp;
506         for (tmp = p; tmp->next; tmp = tmp->next) {
507         }
508         return tmp;
509 }
510
511 static bool test_RFFPCNEx(struct torture_context *tctx,
512                           struct dcerpc_pipe *p)
513 {
514         struct dcesrv_context *dce_ctx;
515         struct policy_handle handle;
516         const char *address;
517         struct received_packet *tmp;
518         struct spoolss_NotifyOption *server_option = setup_printserver_NotifyOption(tctx);
519 #if 0
520         struct spoolss_NotifyOption *printer_option = setup_printer_NotifyOption(tctx);
521 #endif
522         struct dcerpc_binding_handle *b = p->binding_handle;
523         const char *printername = NULL;
524         struct spoolss_NotifyInfo *info = NULL;
525
526         free_received_packets();
527
528         /* Start DCE/RPC server */
529         torture_assert(tctx, test_start_dcerpc_server(tctx, tctx->ev, &dce_ctx, &address), "");
530
531         printername     = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
532
533         torture_assert(tctx, test_OpenPrinter(tctx, p, &handle, printername), "");
534         torture_assert(tctx, test_RemoteFindFirstPrinterChangeNotifyEx(tctx, b, &handle, address, server_option), "");
535         torture_assert(tctx, received_packets, "no packets received");
536         torture_assert_int_equal(tctx, received_packets->opnum, NDR_SPOOLSS_REPLYOPENPRINTER,
537                 "no ReplyOpenPrinter packet after RemoteFindFirstPrinterChangeNotifyEx");
538         torture_assert(tctx, test_RouterRefreshPrinterChangeNotify(tctx, b, &handle, NULL, &info), "");
539         torture_assert(tctx, test_RouterRefreshPrinterChangeNotify(tctx, b, &handle, server_option, &info), "");
540         torture_assert(tctx, test_ClosePrinter(tctx, b, &handle), "");
541         tmp = last_packet(received_packets);
542         torture_assert_int_equal(tctx, tmp->opnum, NDR_SPOOLSS_REPLYCLOSEPRINTER,
543                 "no ReplyClosePrinter packet after ClosePrinter");
544 #if 0
545         printername     = talloc_asprintf(tctx, "\\\\%s\\%s", dcerpc_server_name(p), name);
546
547         torture_assert(tctx, test_OpenPrinter(tctx, p, &handle, "Epson AL-2600"), "");
548         torture_assert(tctx, test_RemoteFindFirstPrinterChangeNotifyEx(tctx, p, &handle, address, printer_option), "");
549         tmp = last_packet(received_packets);
550         torture_assert_int_equal(tctx, tmp->opnum, NDR_SPOOLSS_REPLYOPENPRINTER,
551                 "no ReplyOpenPrinter packet after RemoteFindFirstPrinterChangeNotifyEx");
552         torture_assert(tctx, test_RouterRefreshPrinterChangeNotify(tctx, p, &handle, NULL, &info), "");
553         torture_assert(tctx, test_RouterRefreshPrinterChangeNotify(tctx, p, &handle, printer_option, &info), "");
554         torture_assert(tctx, test_SetPrinter(tctx, p, &handle), "");
555         tmp = last_packet(received_packets);
556         torture_assert_int_equal(tctx, tmp->opnum, NDR_SPOOLSS_ROUTERREPLYPRINTEREX,
557                 "no RouterReplyPrinterEx packet after ClosePrinter");
558         torture_assert(tctx, test_ClosePrinter(tctx, p, &handle), "");
559         tmp = last_packet(received_packets);
560         torture_assert_int_equal(tctx, tmp->opnum, NDR_SPOOLSS_REPLYCLOSEPRINTER,
561                 "no ReplyClosePrinter packet after ClosePrinter");
562 #endif
563         /* Shut down DCE/RPC server */
564         talloc_free(dce_ctx);
565         free_received_packets();
566
567         return true;
568 }
569
570 /** Test that makes sure that calling ReplyOpenPrinter()
571  * on Samba 4 will cause an irpc broadcast call.
572  */
573 static bool test_ReplyOpenPrinter(struct torture_context *tctx,
574                                   struct dcerpc_pipe *p)
575 {
576         struct spoolss_ReplyOpenPrinter r;
577         struct spoolss_ReplyClosePrinter s;
578         struct policy_handle h;
579         struct dcerpc_binding_handle *b = p->binding_handle;
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_r(b, 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_r(b, 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 }