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