s4:rpc_server: only pass context to op_bind() hooks
[samba.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, name, &notify_test_spoolss_interface, NULL);
251                 if (!NT_STATUS_IS_OK(ret)) {
252                         DEBUG(1,("spoolss_op_init_server: failed to register endpoint '%s'\n",name));
253                         return ret;
254                 }
255         }
256
257         return NT_STATUS_OK;
258 }
259
260 static bool test_OpenPrinter(struct torture_context *tctx,
261                              struct dcerpc_pipe *p,
262                              struct policy_handle *handle,
263                              const char *printername)
264 {
265         struct spoolss_OpenPrinter r;
266         struct dcerpc_binding_handle *b = p->binding_handle;
267
268         ZERO_STRUCT(r);
269
270         r.in.printername        = printername;
271         r.in.datatype           = NULL;
272         r.in.devmode_ctr.devmode= NULL;
273         r.in.access_mask        = SEC_FLAG_MAXIMUM_ALLOWED;
274         r.out.handle            = handle;
275
276         torture_comment(tctx, "Testing OpenPrinter(%s)\n", r.in.printername);
277
278         torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_OpenPrinter_r(b, tctx, &r),
279                 "OpenPrinter failed");
280         torture_assert_werr_ok(tctx, r.out.result,
281                 "OpenPrinter failed");
282
283         return true;
284 }
285
286 static struct spoolss_NotifyOption *setup_printserver_NotifyOption(struct torture_context *tctx)
287 {
288         struct spoolss_NotifyOption *o;
289
290         o = talloc_zero(tctx, struct spoolss_NotifyOption);
291
292         o->version = 2;
293         o->flags = PRINTER_NOTIFY_OPTIONS_REFRESH;
294
295         o->count = 2;
296         o->types = talloc_zero_array(o, struct spoolss_NotifyOptionType, o->count);
297
298         o->types[0].type = PRINTER_NOTIFY_TYPE;
299         o->types[0].count = 1;
300         o->types[0].fields = talloc_array(o->types, union spoolss_Field, o->types[0].count);
301         o->types[0].fields[0].field = PRINTER_NOTIFY_FIELD_SERVER_NAME;
302
303         o->types[1].type = JOB_NOTIFY_TYPE;
304         o->types[1].count = 1;
305         o->types[1].fields = talloc_array(o->types, union spoolss_Field, o->types[1].count);
306         o->types[1].fields[0].field = JOB_NOTIFY_FIELD_MACHINE_NAME;
307
308         return o;
309 }
310
311 #if 0
312 static struct spoolss_NotifyOption *setup_printer_NotifyOption(struct torture_context *tctx)
313 {
314         struct spoolss_NotifyOption *o;
315
316         o = talloc_zero(tctx, struct spoolss_NotifyOption);
317
318         o->version = 2;
319         o->flags = PRINTER_NOTIFY_OPTIONS_REFRESH;
320
321         o->count = 1;
322         o->types = talloc_zero_array(o, struct spoolss_NotifyOptionType, o->count);
323
324         o->types[0].type = PRINTER_NOTIFY_TYPE;
325         o->types[0].count = 1;
326         o->types[0].fields = talloc_array(o->types, union spoolss_Field, o->types[0].count);
327         o->types[0].fields[0].field = PRINTER_NOTIFY_FIELD_COMMENT;
328
329         return o;
330 }
331 #endif
332
333 static bool test_RemoteFindFirstPrinterChangeNotifyEx(struct torture_context *tctx,
334                                                       struct dcerpc_binding_handle *b,
335                                                       struct policy_handle *handle,
336                                                       const char *address,
337                                                       struct spoolss_NotifyOption *option)
338 {
339         struct spoolss_RemoteFindFirstPrinterChangeNotifyEx r;
340         const char *local_machine = talloc_asprintf(tctx, "\\\\%s", address);
341
342         torture_comment(tctx, "Testing RemoteFindFirstPrinterChangeNotifyEx(%s)\n", local_machine);
343
344         r.in.flags = 0;
345         r.in.local_machine = local_machine;
346         r.in.options = 0;
347         r.in.printer_local = 0;
348         r.in.notify_options = option;
349         r.in.handle = handle;
350
351         torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_RemoteFindFirstPrinterChangeNotifyEx_r(b, tctx, &r),
352                 "RemoteFindFirstPrinterChangeNotifyEx failed");
353         torture_assert_werr_ok(tctx, r.out.result,
354                 "error return code for RemoteFindFirstPrinterChangeNotifyEx");
355
356         return true;
357 }
358
359 static bool test_RouterRefreshPrinterChangeNotify(struct torture_context *tctx,
360                                                   struct dcerpc_binding_handle *b,
361                                                   struct policy_handle *handle,
362                                                   struct spoolss_NotifyOption *options,
363                                                   struct spoolss_NotifyInfo **info)
364 {
365         struct spoolss_RouterRefreshPrinterChangeNotify r;
366
367         torture_comment(tctx, "Testing RouterRefreshPrinterChangeNotify\n");
368
369         r.in.handle = handle;
370         r.in.change_low = 0;
371         r.in.options = options;
372         r.out.info = info;
373
374         torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_RouterRefreshPrinterChangeNotify_r(b, tctx, &r),
375                 "RouterRefreshPrinterChangeNotify failed");
376         torture_assert_werr_ok(tctx, r.out.result,
377                 "error return code for RouterRefreshPrinterChangeNotify");
378
379         return true;
380 }
381
382 #if 0
383 static bool test_SetPrinter(struct torture_context *tctx,
384                             struct dcerpc_pipe *p,
385                             struct policy_handle *handle)
386 {
387         union spoolss_PrinterInfo info;
388         struct spoolss_SetPrinter r;
389         struct spoolss_SetPrinterInfo2 info2;
390         struct spoolss_SetPrinterInfoCtr info_ctr;
391         struct spoolss_DevmodeContainer devmode_ctr;
392         struct sec_desc_buf secdesc_ctr;
393         struct dcerpc_binding_handle *b = p->binding_handle;
394
395         torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, 2, &info), "");
396
397         ZERO_STRUCT(devmode_ctr);
398         ZERO_STRUCT(secdesc_ctr);
399
400         info2.servername        = info.info2.servername;
401         info2.printername       = info.info2.printername;
402         info2.sharename         = info.info2.sharename;
403         info2.portname          = info.info2.portname;
404         info2.drivername        = info.info2.drivername;
405         info2.comment           = talloc_asprintf(tctx, "torture_comment %d\n", (int)time(NULL));
406         info2.location          = info.info2.location;
407         info2.devmode_ptr       = 0;
408         info2.sepfile           = info.info2.sepfile;
409         info2.printprocessor    = info.info2.printprocessor;
410         info2.datatype          = info.info2.datatype;
411         info2.parameters        = info.info2.parameters;
412         info2.secdesc_ptr       = 0;
413         info2.attributes        = info.info2.attributes;
414         info2.priority          = info.info2.priority;
415         info2.defaultpriority   = info.info2.defaultpriority;
416         info2.starttime         = info.info2.starttime;
417         info2.untiltime         = info.info2.untiltime;
418         info2.status            = info.info2.status;
419         info2.cjobs             = info.info2.cjobs;
420         info2.averageppm        = info.info2.averageppm;
421
422         info_ctr.level = 2;
423         info_ctr.info.info2 = &info2;
424
425         r.in.handle = handle;
426         r.in.info_ctr = &info_ctr;
427         r.in.devmode_ctr = &devmode_ctr;
428         r.in.secdesc_ctr = &secdesc_ctr;
429         r.in.command = 0;
430
431         torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_SetPrinter_r(b, tctx, &r), "SetPrinter failed");
432         torture_assert_werr_ok(tctx, r.out.result, "SetPrinter failed");
433
434         return true;
435 }
436 #endif
437
438 static bool test_start_dcerpc_server(struct torture_context *tctx,
439                                      struct tevent_context *event_ctx,
440                                      struct dcesrv_context **dce_ctx_p,
441                                      const char **address_p)
442 {
443         struct dcesrv_endpoint_server ep_server;
444         NTSTATUS status;
445         struct dcesrv_context *dce_ctx;
446         const char *endpoints[] = { "spoolss", NULL };
447         struct dcesrv_endpoint *e;
448         const char *address;
449         struct interface *ifaces;
450
451         ntvfs_init(tctx->lp_ctx);
452
453         /* fill in our name */
454         ep_server.name = "spoolss";
455
456         /* fill in all the operations */
457         ep_server.init_server = spoolss__op_init_server;
458
459         ep_server.interface_by_uuid = spoolss__op_interface_by_uuid;
460         ep_server.interface_by_name = spoolss__op_interface_by_name;
461
462         torture_assert_ntstatus_ok(tctx, dcerpc_register_ep_server(&ep_server),
463                                   "unable to register spoolss server");
464
465         lpcfg_set_cmdline(tctx->lp_ctx, "dcerpc endpoint servers", "spoolss");
466
467         load_interface_list(tctx, tctx->lp_ctx, &ifaces);
468         address = iface_list_first_v4(ifaces);
469
470         torture_comment(tctx, "Listening for callbacks on %s\n", address);
471
472         status = process_model_init(tctx->lp_ctx);
473         torture_assert_ntstatus_ok(tctx, status,
474                                    "unable to initialize process models");
475
476         status = smbsrv_add_socket(tctx, event_ctx, tctx->lp_ctx,
477                                    process_model_startup("single"),
478                                    address, NULL);
479         torture_assert_ntstatus_ok(tctx, status, "starting smb server");
480
481         status = dcesrv_init_context(tctx, tctx->lp_ctx, endpoints, &dce_ctx);
482         torture_assert_ntstatus_ok(tctx, status,
483                                    "unable to initialize DCE/RPC server");
484
485         for (e=dce_ctx->endpoint_list;e;e=e->next) {
486                 status = dcesrv_add_ep(dce_ctx, tctx->lp_ctx,
487                                        e, tctx->ev,
488                                        process_model_startup("single"), NULL);
489                 torture_assert_ntstatus_ok(tctx, status,
490                                 "unable listen on dcerpc endpoint server");
491         }
492
493         *dce_ctx_p = dce_ctx;
494         *address_p = address;
495
496         return true;
497 }
498
499 static struct received_packet *last_packet(struct received_packet *p)
500 {
501         struct received_packet *tmp;
502         for (tmp = p; tmp->next; tmp = tmp->next) {
503         }
504         return tmp;
505 }
506
507 static bool test_RFFPCNEx(struct torture_context *tctx,
508                           struct dcerpc_pipe *p)
509 {
510         struct dcesrv_context *dce_ctx;
511         struct policy_handle handle;
512         const char *address;
513         struct received_packet *tmp;
514         struct spoolss_NotifyOption *server_option = setup_printserver_NotifyOption(tctx);
515 #if 0
516         struct spoolss_NotifyOption *printer_option = setup_printer_NotifyOption(tctx);
517 #endif
518         struct dcerpc_binding_handle *b = p->binding_handle;
519         const char *printername = NULL;
520         struct spoolss_NotifyInfo *info = NULL;
521
522         free_received_packets();
523
524         /* Start DCE/RPC server */
525         torture_assert(tctx, test_start_dcerpc_server(tctx, tctx->ev, &dce_ctx, &address), "");
526
527         printername     = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
528
529         torture_assert(tctx, test_OpenPrinter(tctx, p, &handle, printername), "");
530         torture_assert(tctx, test_RemoteFindFirstPrinterChangeNotifyEx(tctx, b, &handle, address, server_option), "");
531         torture_assert(tctx, received_packets, "no packets received");
532         torture_assert_int_equal(tctx, received_packets->opnum, NDR_SPOOLSS_REPLYOPENPRINTER,
533                 "no ReplyOpenPrinter packet after RemoteFindFirstPrinterChangeNotifyEx");
534         torture_assert(tctx, test_RouterRefreshPrinterChangeNotify(tctx, b, &handle, NULL, &info), "");
535         torture_assert(tctx, test_RouterRefreshPrinterChangeNotify(tctx, b, &handle, server_option, &info), "");
536         torture_assert(tctx, test_ClosePrinter(tctx, b, &handle), "");
537         tmp = last_packet(received_packets);
538         torture_assert_int_equal(tctx, tmp->opnum, NDR_SPOOLSS_REPLYCLOSEPRINTER,
539                 "no ReplyClosePrinter packet after ClosePrinter");
540 #if 0
541         printername     = talloc_asprintf(tctx, "\\\\%s\\%s", dcerpc_server_name(p), name);
542
543         torture_assert(tctx, test_OpenPrinter(tctx, p, &handle, "Epson AL-2600"), "");
544         torture_assert(tctx, test_RemoteFindFirstPrinterChangeNotifyEx(tctx, p, &handle, address, printer_option), "");
545         tmp = last_packet(received_packets);
546         torture_assert_int_equal(tctx, tmp->opnum, NDR_SPOOLSS_REPLYOPENPRINTER,
547                 "no ReplyOpenPrinter packet after RemoteFindFirstPrinterChangeNotifyEx");
548         torture_assert(tctx, test_RouterRefreshPrinterChangeNotify(tctx, p, &handle, NULL, &info), "");
549         torture_assert(tctx, test_RouterRefreshPrinterChangeNotify(tctx, p, &handle, printer_option, &info), "");
550         torture_assert(tctx, test_SetPrinter(tctx, p, &handle), "");
551         tmp = last_packet(received_packets);
552         torture_assert_int_equal(tctx, tmp->opnum, NDR_SPOOLSS_ROUTERREPLYPRINTEREX,
553                 "no RouterReplyPrinterEx packet after ClosePrinter");
554         torture_assert(tctx, test_ClosePrinter(tctx, p, &handle), "");
555         tmp = last_packet(received_packets);
556         torture_assert_int_equal(tctx, tmp->opnum, NDR_SPOOLSS_REPLYCLOSEPRINTER,
557                 "no ReplyClosePrinter packet after ClosePrinter");
558 #endif
559         /* Shut down DCE/RPC server */
560         talloc_free(dce_ctx);
561         free_received_packets();
562
563         return true;
564 }
565
566 /** Test that makes sure that calling ReplyOpenPrinter()
567  * on Samba 4 will cause an irpc broadcast call.
568  */
569 static bool test_ReplyOpenPrinter(struct torture_context *tctx,
570                                   struct dcerpc_pipe *p)
571 {
572         struct spoolss_ReplyOpenPrinter r;
573         struct spoolss_ReplyClosePrinter s;
574         struct policy_handle h;
575         struct dcerpc_binding_handle *b = p->binding_handle;
576
577         if (torture_setting_bool(tctx, "samba3", false)) {
578                 torture_skip(tctx, "skipping ReplyOpenPrinter server implementation test against s3\n");
579         }
580
581         r.in.server_name = "earth";
582         r.in.printer_local = 2;
583         r.in.type = REG_DWORD;
584         r.in.bufsize = 0;
585         r.in.buffer = NULL;
586         r.out.handle = &h;
587
588         torture_assert_ntstatus_ok(tctx,
589                         dcerpc_spoolss_ReplyOpenPrinter_r(b, tctx, &r),
590                         "spoolss_ReplyOpenPrinter call failed");
591
592         torture_assert_werr_ok(tctx, r.out.result, "error return code");
593
594         s.in.handle = &h;
595         s.out.handle = &h;
596
597         torture_assert_ntstatus_ok(tctx,
598                         dcerpc_spoolss_ReplyClosePrinter_r(b, tctx, &s),
599                         "spoolss_ReplyClosePrinter call failed");
600
601         torture_assert_werr_ok(tctx, r.out.result, "error return code");
602
603         return true;
604 }
605
606 struct torture_suite *torture_rpc_spoolss_notify(TALLOC_CTX *mem_ctx)
607 {
608         struct torture_suite *suite = torture_suite_create(mem_ctx, "spoolss.notify");
609
610         struct torture_rpc_tcase *tcase = torture_suite_add_rpc_iface_tcase(suite,
611                                                         "notify", &ndr_table_spoolss);
612
613         torture_rpc_tcase_add_test(tcase, "testRFFPCNEx", test_RFFPCNEx);
614         torture_rpc_tcase_add_test(tcase, "testReplyOpenPrinter", test_ReplyOpenPrinter);
615
616         return suite;
617 }