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