| 1 |
/* |
| 2 |
Unix SMB/CIFS implementation. |
| 3 |
test suite for spoolss rpc operations |
| 4 |
|
| 5 |
Copyright (C) Tim Potter 2003 |
| 6 |
Copyright (C) Stefan Metzmacher 2005 |
| 7 |
Copyright (C) Jelmer Vernooij 2007 |
| 8 |
Copyright (C) Guenther Deschner 2009-2011,2013 |
| 9 |
|
| 10 |
This program is free software; you can redistribute it and/or modify |
| 11 |
it under the terms of the GNU General Public License as published by |
| 12 |
the Free Software Foundation; either version 3 of the License, or |
| 13 |
(at your option) any later version. |
| 14 |
|
| 15 |
This program is distributed in the hope that it will be useful, |
| 16 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 |
GNU General Public License for more details. |
| 19 |
|
| 20 |
You should have received a copy of the GNU General Public License |
| 21 |
along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 22 |
*/ |
| 23 |
|
| 24 |
#include "includes.h" |
| 25 |
#include "torture/torture.h" |
| 26 |
#include "librpc/gen_ndr/ndr_misc.h" |
| 27 |
#include "librpc/gen_ndr/ndr_spoolss.h" |
| 28 |
#include "librpc/gen_ndr/ndr_spoolss_c.h" |
| 29 |
#include "librpc/gen_ndr/ndr_winreg_c.h" |
| 30 |
#include "librpc/gen_ndr/ndr_security.h" |
| 31 |
#include "libcli/security/security.h" |
| 32 |
#include "torture/rpc/torture_rpc.h" |
| 33 |
#include "param/param.h" |
| 34 |
#include "lib/registry/registry.h" |
| 35 |
#include "libcli/libcli.h" |
| 36 |
#include "libcli/raw/raw_proto.h" |
| 37 |
#include "libcli/resolve/resolve.h" |
| 38 |
#include "libcli/smb2/smb2.h" |
| 39 |
#include "libcli/smb2/smb2_calls.h" |
| 40 |
#include "lib/cmdline/cmdline.h" |
| 41 |
#include "system/filesys.h" |
| 42 |
#include "torture/ndr/ndr.h" |
| 43 |
#include "torture/smb2/proto.h" |
| 44 |
|
| 45 |
#define TORTURE_WELLKNOWN_PRINTER "torture_wkn_printer" |
| 46 |
#define TORTURE_PRINTER "torture_printer" |
| 47 |
#define TORTURE_WELLKNOWN_PRINTER_EX "torture_wkn_printer_ex" |
| 48 |
#define TORTURE_PRINTER_EX "torture_printer_ex" |
| 49 |
#define TORTURE_DRIVER "torture_driver" |
| 50 |
#define TORTURE_DRIVER_ADD "torture_driver_add" |
| 51 |
#define TORTURE_DRIVER_EX "torture_driver_ex" |
| 52 |
#define TORTURE_DRIVER_ADOBE "torture_driver_adobe" |
| 53 |
#define TORTURE_DRIVER_EX_ADOBE "torture_driver_ex_adobe" |
| 54 |
#define TORTURE_DRIVER_ADOBE_CUPSADDSMB "torture_driver_adobe_cupsaddsmb" |
| 55 |
#define TORTURE_DRIVER_TIMESTAMPS "torture_driver_timestamps" |
| 56 |
#define TORTURE_DRIVER_DELETER "torture_driver_deleter" |
| 57 |
#define TORTURE_DRIVER_COPY_DIR "torture_driver_copy_from_directory" |
| 58 |
#define TORTURE_DRIVER_DELETERIN "torture_driver_deleterin" |
| 59 |
#define TORTURE_PRINTER_STATIC1 "print1" |
| 60 |
|
| 61 |
#define TOP_LEVEL_PRINT_KEY "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Print" |
| 62 |
#define TOP_LEVEL_PRINT_PRINTERS_KEY TOP_LEVEL_PRINT_KEY "\\Printers" |
| 63 |
#define TOP_LEVEL_CONTROL_KEY "SYSTEM\\CurrentControlSet\\Control\\Print" |
| 64 |
#define TOP_LEVEL_CONTROL_FORMS_KEY TOP_LEVEL_CONTROL_KEY "\\Forms" |
| 65 |
#define TOP_LEVEL_CONTROL_PRINTERS_KEY TOP_LEVEL_CONTROL_KEY "\\Printers" |
| 66 |
#define TOP_LEVEL_CONTROL_ENVIRONMENTS_KEY TOP_LEVEL_CONTROL_KEY "\\Environments" |
| 67 |
|
| 68 |
struct test_spoolss_context { |
| 69 |
struct dcerpc_pipe *spoolss_pipe; |
| 70 |
|
| 71 |
/* server environment */ |
| 72 |
const char *environment; |
| 73 |
|
| 74 |
/* print server handle */ |
| 75 |
struct policy_handle server_handle; |
| 76 |
|
| 77 |
/* for EnumPorts */ |
| 78 |
uint32_t port_count[3]; |
| 79 |
union spoolss_PortInfo *ports[3]; |
| 80 |
|
| 81 |
/* for EnumPrinterDrivers */ |
| 82 |
uint32_t driver_count[9]; |
| 83 |
union spoolss_DriverInfo *drivers[9]; |
| 84 |
|
| 85 |
/* for EnumMonitors */ |
| 86 |
uint32_t monitor_count[3]; |
| 87 |
union spoolss_MonitorInfo *monitors[3]; |
| 88 |
|
| 89 |
/* for EnumPrintProcessors */ |
| 90 |
uint32_t print_processor_count[2]; |
| 91 |
union spoolss_PrintProcessorInfo *print_processors[2]; |
| 92 |
|
| 93 |
/* for EnumPrinters */ |
| 94 |
uint32_t printer_count[6]; |
| 95 |
union spoolss_PrinterInfo *printers[6]; |
| 96 |
}; |
| 97 |
|
| 98 |
struct torture_driver_context { |
| 99 |
struct { |
| 100 |
const char *driver_directory; |
| 101 |
const char *environment; |
| 102 |
} local; |
| 103 |
struct { |
| 104 |
const char *driver_directory; |
| 105 |
const char *driver_upload_directory; |
| 106 |
const char *environment; |
| 107 |
} remote; |
| 108 |
struct spoolss_AddDriverInfo8 info8; |
| 109 |
bool ex; |
| 110 |
}; |
| 111 |
|
| 112 |
struct torture_printer_context { |
| 113 |
struct dcerpc_pipe *spoolss_pipe; |
| 114 |
struct spoolss_SetPrinterInfo2 info2; |
| 115 |
struct torture_driver_context driver; |
| 116 |
bool ex; |
| 117 |
bool wellknown; |
| 118 |
bool added_driver; |
| 119 |
bool have_driver; |
| 120 |
struct spoolss_DeviceMode *devmode; |
| 121 |
struct policy_handle handle; |
| 122 |
}; |
| 123 |
|
| 124 |
static bool upload_printer_driver(struct torture_context *tctx, |
| 125 |
const char *server_name, |
| 126 |
struct torture_driver_context *d); |
| 127 |
static bool remove_printer_driver(struct torture_context *tctx, |
| 128 |
const char *server_name, |
| 129 |
struct torture_driver_context *d); |
| 130 |
static bool fillup_printserver_info(struct torture_context *tctx, |
| 131 |
struct dcerpc_pipe *p, |
| 132 |
struct torture_driver_context *d); |
| 133 |
static bool test_AddPrinterDriver_args_level_3(struct torture_context *tctx, |
| 134 |
struct dcerpc_binding_handle *b, |
| 135 |
const char *server_name, |
| 136 |
struct spoolss_AddDriverInfo8 *r, |
| 137 |
uint32_t flags, |
| 138 |
bool ex, |
| 139 |
const char *remote_driver_dir); |
| 140 |
|
| 141 |
#define COMPARE_STRING(tctx, c,r,e) \ |
| 142 |
torture_assert_str_equal(tctx, c.e, r.e, "invalid value") |
| 143 |
|
| 144 |
/* not every compiler supports __typeof__() */ |
| 145 |
#if (__GNUC__ >= 3) |
| 146 |
#define _CHECK_FIELD_SIZE(c,r,e,type) do {\ |
| 147 |
if (sizeof(__typeof__(c.e)) != sizeof(type)) { \ |
| 148 |
torture_fail(tctx, #c "." #e "field is not " #type "\n"); \ |
| 149 |
}\ |
| 150 |
if (sizeof(__typeof__(r.e)) != sizeof(type)) { \ |
| 151 |
torture_fail(tctx, #r "." #e "field is not " #type "\n"); \ |
| 152 |
}\ |
| 153 |
} while(0) |
| 154 |
#else |
| 155 |
#define _CHECK_FIELD_SIZE(c,r,e,type) do {} while(0) |
| 156 |
#endif |
| 157 |
|
| 158 |
#define COMPARE_UINT32(tctx, c, r, e) do {\ |
| 159 |
_CHECK_FIELD_SIZE(c, r, e, uint32_t); \ |
| 160 |
torture_assert_int_equal(tctx, c.e, r.e, "invalid value"); \ |
| 161 |
} while(0) |
| 162 |
|
| 163 |
#define COMPARE_UINT64(tctx, c, r, e) do {\ |
| 164 |
_CHECK_FIELD_SIZE(c, r, e, uint64_t); \ |
| 165 |
torture_assert_int_equal(tctx, c.e, r.e, "invalid value"); \ |
| 166 |
} while(0) |
| 167 |
|
| 168 |
|
| 169 |
#define COMPARE_NTTIME(tctx, c, r, e) do {\ |
| 170 |
_CHECK_FIELD_SIZE(c, r, e, NTTIME); \ |
| 171 |
torture_assert_int_equal(tctx, c.e, r.e, "invalid value"); \ |
| 172 |
} while(0) |
| 173 |
|
| 174 |
#define COMPARE_STRING_ARRAY(tctx, c,r,e) do {\ |
| 175 |
int __i; \ |
| 176 |
if (!c.e && !r.e) { \ |
| 177 |
break; \ |
| 178 |
} \ |
| 179 |
if (c.e && !r.e) { \ |
| 180 |
torture_fail(tctx, #r "." #e " field is NULL and " #c "." #e " is not\n"); \ |
| 181 |
} \ |
| 182 |
if (!c.e && r.e) { \ |
| 183 |
torture_fail(tctx, #c "." #e " field is NULL and " #r "." #e " is not\n"); \ |
| 184 |
} \ |
| 185 |
for (__i=0;c.e[__i] != NULL; __i++) { \ |
| 186 |
torture_assert_str_equal(tctx, c.e[__i], r.e[__i], "invalid value"); \ |
| 187 |
} \ |
| 188 |
} while(0) |
| 189 |
|
| 190 |
#define CHECK_ALIGN(size, n) do {\ |
| 191 |
if (size % n) {\ |
| 192 |
torture_warning(tctx, "%d is *NOT* %d byte aligned, should be %d",\ |
| 193 |
size, n, size + n - (size % n));\ |
| 194 |
}\ |
| 195 |
} while(0) |
| 196 |
|
| 197 |
#define DO_ROUND(size, n) (((size)+((n)-1)) & ~((n)-1)) |
| 198 |
|
| 199 |
#define CHECK_NEEDED_SIZE_ENUM_LEVEL(fn, info, level, count, needed, align) do { \ |
| 200 |
if (torture_setting_bool(tctx, "spoolss_check_size", false)) {\ |
| 201 |
uint32_t size = ndr_size_##fn##_info(tctx, level, count, info);\ |
| 202 |
uint32_t round_size = DO_ROUND(size, align);\ |
| 203 |
if (round_size != needed) {\ |
| 204 |
torture_warning(tctx, __location__": "#fn" level %d (count: %d) got unexpected needed size: %d, we calculated: %d", level, count, needed, round_size);\ |
| 205 |
CHECK_ALIGN(size, align);\ |
| 206 |
}\ |
| 207 |
}\ |
| 208 |
} while(0) |
| 209 |
|
| 210 |
#define CHECK_NEEDED_SIZE_ENUM(fn, info, count, needed, align) do { \ |
| 211 |
if (torture_setting_bool(tctx, "spoolss_check_size", false)) {\ |
| 212 |
uint32_t size = ndr_size_##fn##_info(tctx, count, info);\ |
| 213 |
uint32_t round_size = DO_ROUND(size, align);\ |
| 214 |
if (round_size != needed) {\ |
| 215 |
torture_warning(tctx, __location__": "#fn" (count: %d) got unexpected needed size: %d, we calculated: %d", count, needed, round_size);\ |
| 216 |
CHECK_ALIGN(size, align);\ |
| 217 |
}\ |
| 218 |
}\ |
| 219 |
} while(0) |
| 220 |
|
| 221 |
#define CHECK_NEEDED_SIZE_LEVEL(fn, info, level, needed, align) do { \ |
| 222 |
if (torture_setting_bool(tctx, "spoolss_check_size", false)) {\ |
| 223 |
uint32_t size = ndr_size_##fn(info, level, 0);\ |
| 224 |
uint32_t round_size = DO_ROUND(size, align);\ |
| 225 |
if (round_size != needed) {\ |
| 226 |
torture_warning(tctx, __location__": "#fn" level %d got unexpected needed size: %d, we calculated: %d", level, needed, round_size);\ |
| 227 |
CHECK_ALIGN(size, align);\ |
| 228 |
}\ |
| 229 |
}\ |
| 230 |
} while(0) |
| 231 |
|
| 232 |
static bool PrinterInfo_to_SetPrinterInfo(struct torture_context *tctx, |
| 233 |
const union spoolss_PrinterInfo *i, |
| 234 |
uint32_t level, |
| 235 |
union spoolss_SetPrinterInfo *s) |
| 236 |
{ |
| 237 |
switch (level) { |
| 238 |
case 0: |
| 239 |
s->info0 = talloc(tctx, struct spoolss_SetPrinterInfo0); |
| 240 |
break; |
| 241 |
case 2: |
| 242 |
s->info2 = talloc(tctx, struct spoolss_SetPrinterInfo2); |
| 243 |
s->info2->servername = i->info2.servername; |
| 244 |
s->info2->printername = i->info2.printername; |
| 245 |
s->info2->sharename = i->info2.sharename; |
| 246 |
s->info2->portname = i->info2.portname; |
| 247 |
s->info2->drivername = i->info2.drivername; |
| 248 |
s->info2->comment = i->info2.comment; |
| 249 |
s->info2->location = i->info2.location; |
| 250 |
s->info2->devmode_ptr = 0; |
| 251 |
s->info2->sepfile = i->info2.sepfile; |
| 252 |
s->info2->printprocessor = i->info2.printprocessor; |
| 253 |
s->info2->datatype = i->info2.datatype; |
| 254 |
s->info2->parameters = i->info2.parameters; |
| 255 |
s->info2->secdesc_ptr = 0; |
| 256 |
s->info2->attributes = i->info2.attributes; |
| 257 |
s->info2->priority = i->info2.priority; |
| 258 |
s->info2->defaultpriority = i->info2.defaultpriority; |
| 259 |
s->info2->starttime = i->info2.starttime; |
| 260 |
s->info2->untiltime = i->info2.untiltime; |
| 261 |
s->info2->status = i->info2.status; |
| 262 |
s->info2->cjobs = i->info2.cjobs; |
| 263 |
s->info2->averageppm = i->info2.averageppm; |
| 264 |
break; |
| 265 |
case 3: |
| 266 |
case 4: |
| 267 |
case 5: |
| 268 |
case 6: |
| 269 |
case 7: |
| 270 |
case 8: |
| 271 |
case 9: |
| 272 |
default: |
| 273 |
return false; |
| 274 |
} |
| 275 |
|
| 276 |
return true; |
| 277 |
} |
| 278 |
|
| 279 |
static bool test_OpenPrinter_server(struct torture_context *tctx, |
| 280 |
struct dcerpc_pipe *p, |
| 281 |
struct policy_handle *server_handle) |
| 282 |
{ |
| 283 |
NTSTATUS status; |
| 284 |
struct spoolss_OpenPrinter op; |
| 285 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 286 |
|
| 287 |
op.in.printername = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p)); |
| 288 |
op.in.datatype = NULL; |
| 289 |
op.in.devmode_ctr.devmode= NULL; |
| 290 |
op.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED; |
| 291 |
op.out.handle = server_handle; |
| 292 |
|
| 293 |
torture_comment(tctx, "Testing OpenPrinter(%s)\n", op.in.printername); |
| 294 |
|
| 295 |
status = dcerpc_spoolss_OpenPrinter_r(b, tctx, &op); |
| 296 |
torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_OpenPrinter failed"); |
| 297 |
torture_assert_werr_ok(tctx, op.out.result, "dcerpc_spoolss_OpenPrinter failed"); |
| 298 |
|
| 299 |
return true; |
| 300 |
} |
| 301 |
|
| 302 |
static bool test_EnumPorts(struct torture_context *tctx, |
| 303 |
void *private_data) |
| 304 |
{ |
| 305 |
struct test_spoolss_context *ctx = |
| 306 |
talloc_get_type_abort(private_data, struct test_spoolss_context); |
| 307 |
struct dcerpc_pipe *p = ctx->spoolss_pipe; |
| 308 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 309 |
NTSTATUS status; |
| 310 |
struct spoolss_EnumPorts r; |
| 311 |
uint16_t levels[] = { 1, 2 }; |
| 312 |
int i, j; |
| 313 |
|
| 314 |
for (i=0;i<ARRAY_SIZE(levels);i++) { |
| 315 |
int level = levels[i]; |
| 316 |
DATA_BLOB blob; |
| 317 |
uint32_t needed; |
| 318 |
uint32_t count; |
| 319 |
union spoolss_PortInfo *info; |
| 320 |
|
| 321 |
r.in.servername = ""; |
| 322 |
r.in.level = level; |
| 323 |
r.in.buffer = NULL; |
| 324 |
r.in.offered = 0; |
| 325 |
r.out.needed = &needed; |
| 326 |
r.out.count = &count; |
| 327 |
r.out.info = &info; |
| 328 |
|
| 329 |
torture_comment(tctx, "Testing EnumPorts level %u\n", r.in.level); |
| 330 |
|
| 331 |
status = dcerpc_spoolss_EnumPorts_r(b, ctx, &r); |
| 332 |
torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EnumPorts failed"); |
| 333 |
if (W_ERROR_IS_OK(r.out.result)) { |
| 334 |
/* TODO: do some more checks here */ |
| 335 |
continue; |
| 336 |
} |
| 337 |
torture_assert_werr_equal(tctx, r.out.result, WERR_INSUFFICIENT_BUFFER, |
| 338 |
"EnumPorts unexpected return code"); |
| 339 |
|
| 340 |
blob = data_blob_talloc_zero(ctx, needed); |
| 341 |
r.in.buffer = &blob; |
| 342 |
r.in.offered = needed; |
| 343 |
|
| 344 |
status = dcerpc_spoolss_EnumPorts_r(b, ctx, &r); |
| 345 |
torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EnumPorts failed"); |
| 346 |
|
| 347 |
torture_assert_werr_ok(tctx, r.out.result, "EnumPorts failed"); |
| 348 |
|
| 349 |
torture_assert(tctx, info, "EnumPorts returned no info"); |
| 350 |
|
| 351 |
CHECK_NEEDED_SIZE_ENUM_LEVEL(spoolss_EnumPorts, info, r.in.level, count, needed, 4); |
| 352 |
|
| 353 |
ctx->port_count[level] = count; |
| 354 |
ctx->ports[level] = info; |
| 355 |
} |
| 356 |
|
| 357 |
for (i=1;i<ARRAY_SIZE(levels);i++) { |
| 358 |
int level = levels[i]; |
| 359 |
int old_level = levels[i-1]; |
| 360 |
torture_assert_int_equal(tctx, ctx->port_count[level], ctx->port_count[old_level], |
| 361 |
"EnumPorts invalid value"); |
| 362 |
} |
| 363 |
/* if the array sizes are not the same we would maybe segfault in the following code */ |
| 364 |
|
| 365 |
for (i=0;i<ARRAY_SIZE(levels);i++) { |
| 366 |
int level = levels[i]; |
| 367 |
for (j=0;j<ctx->port_count[level];j++) { |
| 368 |
union spoolss_PortInfo *cur = &ctx->ports[level][j]; |
| 369 |
union spoolss_PortInfo *ref = &ctx->ports[2][j]; |
| 370 |
switch (level) { |
| 371 |
case 1: |
| 372 |
COMPARE_STRING(tctx, cur->info1, ref->info2, port_name); |
| 373 |
break; |
| 374 |
case 2: |
| 375 |
/* level 2 is our reference, and it makes no sense to compare it to itself */ |
| 376 |
break; |
| 377 |
} |
| 378 |
} |
| 379 |
} |
| 380 |
|
| 381 |
return true; |
| 382 |
} |
| 383 |
|
| 384 |
static bool test_GetPrintProcessorDirectory(struct torture_context *tctx, |
| 385 |
void *private_data) |
| 386 |
{ |
| 387 |
struct test_spoolss_context *ctx = |
| 388 |
talloc_get_type_abort(private_data, struct test_spoolss_context); |
| 389 |
|
| 390 |
NTSTATUS status; |
| 391 |
struct dcerpc_pipe *p = ctx->spoolss_pipe; |
| 392 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 393 |
struct spoolss_GetPrintProcessorDirectory r; |
| 394 |
struct { |
| 395 |
uint16_t level; |
| 396 |
const char *server; |
| 397 |
} levels[] = {{ |
| 398 |
.level = 1, |
| 399 |
.server = NULL |
| 400 |
},{ |
| 401 |
.level = 1, |
| 402 |
.server = "" |
| 403 |
},{ |
| 404 |
.level = 78, |
| 405 |
.server = "" |
| 406 |
},{ |
| 407 |
.level = 1, |
| 408 |
.server = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p)) |
| 409 |
},{ |
| 410 |
.level = 1024, |
| 411 |
.server = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p)) |
| 412 |
} |
| 413 |
}; |
| 414 |
int i; |
| 415 |
uint32_t needed; |
| 416 |
|
| 417 |
for (i=0;i<ARRAY_SIZE(levels);i++) { |
| 418 |
int level = levels[i].level; |
| 419 |
DATA_BLOB blob; |
| 420 |
|
| 421 |
r.in.server = levels[i].server; |
| 422 |
r.in.environment = ctx->environment; |
| 423 |
r.in.level = level; |
| 424 |
r.in.buffer = NULL; |
| 425 |
r.in.offered = 0; |
| 426 |
r.out.needed = &needed; |
| 427 |
|
| 428 |
torture_comment(tctx, "Testing GetPrintProcessorDirectory level %u\n", r.in.level); |
| 429 |
|
| 430 |
status = dcerpc_spoolss_GetPrintProcessorDirectory_r(b, tctx, &r); |
| 431 |
torture_assert_ntstatus_ok(tctx, status, |
| 432 |
"dcerpc_spoolss_GetPrintProcessorDirectory failed"); |
| 433 |
torture_assert_werr_equal(tctx, r.out.result, WERR_INSUFFICIENT_BUFFER, |
| 434 |
"GetPrintProcessorDirectory unexpected return code"); |
| 435 |
|
| 436 |
blob = data_blob_talloc_zero(tctx, needed); |
| 437 |
r.in.buffer = &blob; |
| 438 |
r.in.offered = needed; |
| 439 |
|
| 440 |
status = dcerpc_spoolss_GetPrintProcessorDirectory_r(b, tctx, &r); |
| 441 |
torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_GetPrintProcessorDirectory failed"); |
| 442 |
|
| 443 |
torture_assert_werr_ok(tctx, r.out.result, "GetPrintProcessorDirectory failed"); |
| 444 |
|
| 445 |
CHECK_NEEDED_SIZE_LEVEL(spoolss_PrintProcessorDirectoryInfo, r.out.info, r.in.level, needed, 2); |
| 446 |
} |
| 447 |
|
| 448 |
return true; |
| 449 |
} |
| 450 |
|
| 451 |
|
| 452 |
static bool test_GetPrinterDriverDirectory(struct torture_context *tctx, |
| 453 |
void *private_data) |
| 454 |
{ |
| 455 |
struct test_spoolss_context *ctx = |
| 456 |
talloc_get_type_abort(private_data, struct test_spoolss_context); |
| 457 |
|
| 458 |
NTSTATUS status; |
| 459 |
struct dcerpc_pipe *p = ctx->spoolss_pipe; |
| 460 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 461 |
struct spoolss_GetPrinterDriverDirectory r; |
| 462 |
struct { |
| 463 |
uint16_t level; |
| 464 |
const char *server; |
| 465 |
} levels[] = {{ |
| 466 |
.level = 1, |
| 467 |
.server = NULL |
| 468 |
},{ |
| 469 |
.level = 1, |
| 470 |
.server = "" |
| 471 |
},{ |
| 472 |
.level = 78, |
| 473 |
.server = "" |
| 474 |
},{ |
| 475 |
.level = 1, |
| 476 |
.server = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p)) |
| 477 |
},{ |
| 478 |
.level = 1024, |
| 479 |
.server = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p)) |
| 480 |
} |
| 481 |
}; |
| 482 |
int i; |
| 483 |
uint32_t needed; |
| 484 |
|
| 485 |
for (i=0;i<ARRAY_SIZE(levels);i++) { |
| 486 |
int level = levels[i].level; |
| 487 |
DATA_BLOB blob; |
| 488 |
|
| 489 |
r.in.server = levels[i].server; |
| 490 |
r.in.environment = ctx->environment; |
| 491 |
r.in.level = level; |
| 492 |
r.in.buffer = NULL; |
| 493 |
r.in.offered = 0; |
| 494 |
r.out.needed = &needed; |
| 495 |
|
| 496 |
torture_comment(tctx, "Testing GetPrinterDriverDirectory level %u\n", r.in.level); |
| 497 |
|
| 498 |
status = dcerpc_spoolss_GetPrinterDriverDirectory_r(b, tctx, &r); |
| 499 |
torture_assert_ntstatus_ok(tctx, status, |
| 500 |
"dcerpc_spoolss_GetPrinterDriverDirectory failed"); |
| 501 |
torture_assert_werr_equal(tctx, r.out.result, WERR_INSUFFICIENT_BUFFER, |
| 502 |
"GetPrinterDriverDirectory unexpected return code"); |
| 503 |
|
| 504 |
blob = data_blob_talloc_zero(tctx, needed); |
| 505 |
r.in.buffer = &blob; |
| 506 |
r.in.offered = needed; |
| 507 |
|
| 508 |
status = dcerpc_spoolss_GetPrinterDriverDirectory_r(b, tctx, &r); |
| 509 |
torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_GetPrinterDriverDirectory failed"); |
| 510 |
|
| 511 |
torture_assert_werr_ok(tctx, r.out.result, "GetPrinterDriverDirectory failed"); |
| 512 |
|
| 513 |
CHECK_NEEDED_SIZE_LEVEL(spoolss_DriverDirectoryInfo, r.out.info, r.in.level, needed, 2); |
| 514 |
} |
| 515 |
|
| 516 |
return true; |
| 517 |
} |
| 518 |
|
| 519 |
static bool test_EnumPrinterDrivers_buffers(struct torture_context *tctx, |
| 520 |
struct dcerpc_binding_handle *b, |
| 521 |
const char *server_name, |
| 522 |
const char *environment, |
| 523 |
uint32_t level, |
| 524 |
uint32_t offered, |
| 525 |
uint32_t *count_p, |
| 526 |
union spoolss_DriverInfo **info_p) |
| 527 |
{ |
| 528 |
struct spoolss_EnumPrinterDrivers r; |
| 529 |
uint32_t needed; |
| 530 |
uint32_t count; |
| 531 |
union spoolss_DriverInfo *info; |
| 532 |
DATA_BLOB buffer; |
| 533 |
|
| 534 |
if (offered > 0) { |
| 535 |
buffer = data_blob_talloc_zero(tctx, offered); |
| 536 |
} |
| 537 |
|
| 538 |
r.in.server = server_name; |
| 539 |
r.in.environment = environment; |
| 540 |
r.in.level = level; |
| 541 |
r.in.buffer = offered ? &buffer : NULL; |
| 542 |
r.in.offered = offered; |
| 543 |
r.out.needed = &needed; |
| 544 |
r.out.count = &count; |
| 545 |
r.out.info = &info; |
| 546 |
|
| 547 |
torture_comment(tctx, "Testing EnumPrinterDrivers(%s) level %u, offered: %u\n", |
| 548 |
r.in.environment, r.in.level, r.in.offered); |
| 549 |
|
| 550 |
torture_assert_ntstatus_ok(tctx, |
| 551 |
dcerpc_spoolss_EnumPrinterDrivers_r(b, tctx, &r), |
| 552 |
"EnumPrinterDrivers failed"); |
| 553 |
if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) { |
| 554 |
DATA_BLOB blob = data_blob_talloc_zero(tctx, needed); |
| 555 |
r.in.buffer = &blob; |
| 556 |
r.in.offered = needed; |
| 557 |
|
| 558 |
torture_assert_ntstatus_ok(tctx, |
| 559 |
dcerpc_spoolss_EnumPrinterDrivers_r(b, tctx, &r), |
| 560 |
"EnumPrinterDrivers failed"); |
| 561 |
} |
| 562 |
|
| 563 |
torture_assert_werr_ok(tctx, r.out.result, |
| 564 |
"EnumPrinterDrivers failed"); |
| 565 |
|
| 566 |
if (count_p) { |
| 567 |
*count_p = count; |
| 568 |
} |
| 569 |
if (info_p) { |
| 570 |
*info_p = info; |
| 571 |
} |
| 572 |
|
| 573 |
CHECK_NEEDED_SIZE_ENUM_LEVEL(spoolss_EnumPrinterDrivers, info, r.in.level, count, needed, 4); |
| 574 |
|
| 575 |
return true; |
| 576 |
|
| 577 |
} |
| 578 |
|
| 579 |
|
| 580 |
static bool test_EnumPrinterDrivers_args(struct torture_context *tctx, |
| 581 |
struct dcerpc_binding_handle *b, |
| 582 |
const char *server_name, |
| 583 |
const char *environment, |
| 584 |
uint32_t level, |
| 585 |
uint32_t *count_p, |
| 586 |
union spoolss_DriverInfo **info_p) |
| 587 |
{ |
| 588 |
return test_EnumPrinterDrivers_buffers(tctx, b, server_name, |
| 589 |
environment, level, 0, |
| 590 |
count_p, info_p); |
| 591 |
} |
| 592 |
|
| 593 |
static bool test_EnumPrinterDrivers_findone(struct torture_context *tctx, |
| 594 |
struct dcerpc_binding_handle *b, |
| 595 |
const char *server_name, |
| 596 |
const char *environment, |
| 597 |
uint32_t level, |
| 598 |
const char *driver_name, |
| 599 |
union spoolss_DriverInfo *info_p) |
| 600 |
{ |
| 601 |
uint32_t count; |
| 602 |
union spoolss_DriverInfo *info; |
| 603 |
int i; |
| 604 |
const char *environment_ret = NULL; |
| 605 |
|
| 606 |
torture_assert(tctx, |
| 607 |
test_EnumPrinterDrivers_args(tctx, b, server_name, environment, level, &count, &info), |
| 608 |
"failed to enumerate printer drivers"); |
| 609 |
|
| 610 |
for (i=0; i < count; i++) { |
| 611 |
const char *driver_name_ret = ""; |
| 612 |
switch (level) { |
| 613 |
case 1: |
| 614 |
driver_name_ret = info[i].info1.driver_name; |
| 615 |
break; |
| 616 |
case 2: |
| 617 |
driver_name_ret = info[i].info2.driver_name; |
| 618 |
environment_ret = info[i].info2.architecture; |
| 619 |
break; |
| 620 |
case 3: |
| 621 |
driver_name_ret = info[i].info3.driver_name; |
| 622 |
environment_ret = info[i].info3.architecture; |
| 623 |
break; |
| 624 |
case 4: |
| 625 |
driver_name_ret = info[i].info4.driver_name; |
| 626 |
environment_ret = info[i].info4.architecture; |
| 627 |
break; |
| 628 |
case 5: |
| 629 |
driver_name_ret = info[i].info5.driver_name; |
| 630 |
environment_ret = info[i].info5.architecture; |
| 631 |
break; |
| 632 |
case 6: |
| 633 |
driver_name_ret = info[i].info6.driver_name; |
| 634 |
environment_ret = info[i].info6.architecture; |
| 635 |
break; |
| 636 |
case 7: |
| 637 |
driver_name_ret = info[i].info7.driver_name; |
| 638 |
break; |
| 639 |
case 8: |
| 640 |
driver_name_ret = info[i].info8.driver_name; |
| 641 |
environment_ret = info[i].info8.architecture; |
| 642 |
break; |
| 643 |
default: |
| 644 |
break; |
| 645 |
} |
| 646 |
if (environment_ret) { |
| 647 |
torture_assert_str_equal(tctx, environment, environment_ret, "architecture mismatch"); |
| 648 |
} |
| 649 |
if (strequal(driver_name, driver_name_ret)) { |
| 650 |
if (info_p) { |
| 651 |
*info_p = info[i]; |
| 652 |
} |
| 653 |
return true; |
| 654 |
} |
| 655 |
} |
| 656 |
|
| 657 |
return false; |
| 658 |
} |
| 659 |
|
| 660 |
static bool test_EnumPrinterDrivers(struct torture_context *tctx, |
| 661 |
void *private_data) |
| 662 |
{ |
| 663 |
struct test_spoolss_context *ctx = |
| 664 |
talloc_get_type_abort(private_data, struct test_spoolss_context); |
| 665 |
struct dcerpc_pipe *p = ctx->spoolss_pipe; |
| 666 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 667 |
uint16_t levels[] = { 1, 2, 3, 4, 5, 6, 8 }; |
| 668 |
uint16_t buffer_sizes[] = { 0, 1024, 6040, 0xffff }; |
| 669 |
int i, j, a; |
| 670 |
|
| 671 |
/* FIXME: gd, come back and fix "" as server, and handle |
| 672 |
* priority of returned error codes in torture test and samba 3 |
| 673 |
* server */ |
| 674 |
const char *server_name = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p)); |
| 675 |
const char *environments[2]; |
| 676 |
|
| 677 |
environments[0] = SPOOLSS_ARCHITECTURE_ALL; |
| 678 |
environments[1] = ctx->environment; |
| 679 |
|
| 680 |
for (a=0;a<ARRAY_SIZE(environments);a++) { |
| 681 |
|
| 682 |
for (i=0;i<ARRAY_SIZE(buffer_sizes);i++) { |
| 683 |
torture_assert(tctx, |
| 684 |
test_EnumPrinterDrivers_buffers(tctx, b, server_name, |
| 685 |
environments[a], 3, |
| 686 |
buffer_sizes[i], |
| 687 |
NULL, NULL), |
| 688 |
"failed to enumerate drivers"); |
| 689 |
} |
| 690 |
|
| 691 |
for (i=0;i<ARRAY_SIZE(levels);i++) { |
| 692 |
int level = levels[i]; |
| 693 |
uint32_t count; |
| 694 |
union spoolss_DriverInfo *info; |
| 695 |
|
| 696 |
torture_assert(tctx, |
| 697 |
test_EnumPrinterDrivers_args(tctx, b, server_name, environments[a], level, &count, &info), |
| 698 |
"failed to enumerate drivers"); |
| 699 |
|
| 700 |
ctx->driver_count[level] = count; |
| 701 |
ctx->drivers[level] = info; |
| 702 |
} |
| 703 |
|
| 704 |
for (i=1;i<ARRAY_SIZE(levels);i++) { |
| 705 |
int level = levels[i]; |
| 706 |
int old_level = levels[i-1]; |
| 707 |
|
| 708 |
torture_assert_int_equal(tctx, ctx->driver_count[level], ctx->driver_count[old_level], |
| 709 |
"EnumPrinterDrivers invalid value"); |
| 710 |
} |
| 711 |
|
| 712 |
for (i=0;i<ARRAY_SIZE(levels);i++) { |
| 713 |
int level = levels[i]; |
| 714 |
|
| 715 |
for (j=0;j<ctx->driver_count[level - 1];j++) { |
| 716 |
union spoolss_DriverInfo *cur = &ctx->drivers[level - 1][j]; |
| 717 |
union spoolss_DriverInfo *ref = &ctx->drivers[8][j]; |
| 718 |
|
| 719 |
switch (level) { |
| 720 |
case 1: |
| 721 |
COMPARE_STRING(tctx, cur->info1, ref->info8, driver_name); |
| 722 |
break; |
| 723 |
case 2: |
| 724 |
COMPARE_UINT32(tctx, cur->info2, ref->info8, version); |
| 725 |
COMPARE_STRING(tctx, cur->info2, ref->info8, driver_name); |
| 726 |
COMPARE_STRING(tctx, cur->info2, ref->info8, architecture); |
| 727 |
COMPARE_STRING(tctx, cur->info2, ref->info8, driver_path); |
| 728 |
COMPARE_STRING(tctx, cur->info2, ref->info8, data_file); |
| 729 |
COMPARE_STRING(tctx, cur->info2, ref->info8, config_file); |
| 730 |
break; |
| 731 |
case 3: |
| 732 |
COMPARE_UINT32(tctx, cur->info3, ref->info8, version); |
| 733 |
COMPARE_STRING(tctx, cur->info3, ref->info8, driver_name); |
| 734 |
COMPARE_STRING(tctx, cur->info3, ref->info8, architecture); |
| 735 |
COMPARE_STRING(tctx, cur->info3, ref->info8, driver_path); |
| 736 |
COMPARE_STRING(tctx, cur->info3, ref->info8, data_file); |
| 737 |
COMPARE_STRING(tctx, cur->info3, ref->info8, config_file); |
| 738 |
COMPARE_STRING(tctx, cur->info3, ref->info8, help_file); |
| 739 |
COMPARE_STRING_ARRAY(tctx, cur->info3, ref->info8, dependent_files); |
| 740 |
COMPARE_STRING(tctx, cur->info3, ref->info8, monitor_name); |
| 741 |
COMPARE_STRING(tctx, cur->info3, ref->info8, default_datatype); |
| 742 |
break; |
| 743 |
case 4: |
| 744 |
COMPARE_UINT32(tctx, cur->info4, ref->info8, version); |
| 745 |
COMPARE_STRING(tctx, cur->info4, ref->info8, driver_name); |
| 746 |
COMPARE_STRING(tctx, cur->info4, ref->info8, architecture); |
| 747 |
COMPARE_STRING(tctx, cur->info4, ref->info8, driver_path); |
| 748 |
COMPARE_STRING(tctx, cur->info4, ref->info8, data_file); |
| 749 |
COMPARE_STRING(tctx, cur->info4, ref->info8, config_file); |
| 750 |
COMPARE_STRING(tctx, cur->info4, ref->info8, help_file); |
| 751 |
COMPARE_STRING_ARRAY(tctx, cur->info4, ref->info8, dependent_files); |
| 752 |
COMPARE_STRING(tctx, cur->info4, ref->info8, monitor_name); |
| 753 |
COMPARE_STRING(tctx, cur->info4, ref->info8, default_datatype); |
| 754 |
COMPARE_STRING_ARRAY(tctx, cur->info4, ref->info8, previous_names); |
| 755 |
break; |
| 756 |
case 5: |
| 757 |
COMPARE_UINT32(tctx, cur->info5, ref->info8, version); |
| 758 |
COMPARE_STRING(tctx, cur->info5, ref->info8, driver_name); |
| 759 |
COMPARE_STRING(tctx, cur->info5, ref->info8, architecture); |
| 760 |
COMPARE_STRING(tctx, cur->info5, ref->info8, driver_path); |
| 761 |
COMPARE_STRING(tctx, cur->info5, ref->info8, data_file); |
| 762 |
COMPARE_STRING(tctx, cur->info5, ref->info8, config_file); |
| 763 |
/*COMPARE_UINT32(tctx, cur->info5, ref->info8, driver_attributes);*/ |
| 764 |
/*COMPARE_UINT32(tctx, cur->info5, ref->info8, config_version);*/ |
| 765 |
/*TODO: ! COMPARE_UINT32(tctx, cur->info5, ref->info8, driver_version); */ |
| 766 |
break; |
| 767 |
case 6: |
| 768 |
COMPARE_UINT32(tctx, cur->info6, ref->info8, version); |
| 769 |
COMPARE_STRING(tctx, cur->info6, ref->info8, driver_name); |
| 770 |
COMPARE_STRING(tctx, cur->info6, ref->info8, architecture); |
| 771 |
COMPARE_STRING(tctx, cur->info6, ref->info8, driver_path); |
| 772 |
COMPARE_STRING(tctx, cur->info6, ref->info8, data_file); |
| 773 |
COMPARE_STRING(tctx, cur->info6, ref->info8, config_file); |
| 774 |
COMPARE_STRING(tctx, cur->info6, ref->info8, help_file); |
| 775 |
COMPARE_STRING_ARRAY(tctx, cur->info6, ref->info8, dependent_files); |
| 776 |
COMPARE_STRING(tctx, cur->info6, ref->info8, monitor_name); |
| 777 |
COMPARE_STRING(tctx, cur->info6, ref->info8, default_datatype); |
| 778 |
COMPARE_STRING_ARRAY(tctx, cur->info6, ref->info8, previous_names); |
| 779 |
COMPARE_NTTIME(tctx, cur->info6, ref->info8, driver_date); |
| 780 |
COMPARE_UINT64(tctx, cur->info6, ref->info8, driver_version); |
| 781 |
COMPARE_STRING(tctx, cur->info6, ref->info8, manufacturer_name); |
| 782 |
COMPARE_STRING(tctx, cur->info6, ref->info8, manufacturer_url); |
| 783 |
COMPARE_STRING(tctx, cur->info6, ref->info8, hardware_id); |
| 784 |
COMPARE_STRING(tctx, cur->info6, ref->info8, provider); |
| 785 |
break; |
| 786 |
case 8: |
| 787 |
/* level 8 is our reference, and it makes no sense to compare it to itself */ |
| 788 |
break; |
| 789 |
} |
| 790 |
} |
| 791 |
} |
| 792 |
} |
| 793 |
|
| 794 |
return true; |
| 795 |
} |
| 796 |
|
| 797 |
static bool test_EnumMonitors(struct torture_context *tctx, |
| 798 |
void *private_data) |
| 799 |
{ |
| 800 |
struct test_spoolss_context *ctx = |
| 801 |
talloc_get_type_abort(private_data, struct test_spoolss_context); |
| 802 |
struct dcerpc_pipe *p = ctx->spoolss_pipe; |
| 803 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 804 |
NTSTATUS status; |
| 805 |
struct spoolss_EnumMonitors r; |
| 806 |
uint16_t levels[] = { 1, 2 }; |
| 807 |
int i, j; |
| 808 |
|
| 809 |
for (i=0;i<ARRAY_SIZE(levels);i++) { |
| 810 |
int level = levels[i]; |
| 811 |
DATA_BLOB blob; |
| 812 |
uint32_t needed; |
| 813 |
uint32_t count; |
| 814 |
union spoolss_MonitorInfo *info; |
| 815 |
|
| 816 |
r.in.servername = ""; |
| 817 |
r.in.level = level; |
| 818 |
r.in.buffer = NULL; |
| 819 |
r.in.offered = 0; |
| 820 |
r.out.needed = &needed; |
| 821 |
r.out.count = &count; |
| 822 |
r.out.info = &info; |
| 823 |
|
| 824 |
torture_comment(tctx, "Testing EnumMonitors level %u\n", r.in.level); |
| 825 |
|
| 826 |
status = dcerpc_spoolss_EnumMonitors_r(b, ctx, &r); |
| 827 |
torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EnumMonitors failed"); |
| 828 |
if (W_ERROR_IS_OK(r.out.result)) { |
| 829 |
/* TODO: do some more checks here */ |
| 830 |
continue; |
| 831 |
} |
| 832 |
torture_assert_werr_equal(tctx, r.out.result, WERR_INSUFFICIENT_BUFFER, |
| 833 |
"EnumMonitors failed"); |
| 834 |
|
| 835 |
blob = data_blob_talloc_zero(ctx, needed); |
| 836 |
r.in.buffer = &blob; |
| 837 |
r.in.offered = needed; |
| 838 |
|
| 839 |
status = dcerpc_spoolss_EnumMonitors_r(b, ctx, &r); |
| 840 |
torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EnumMonitors failed"); |
| 841 |
|
| 842 |
torture_assert_werr_ok(tctx, r.out.result, "EnumMonitors failed"); |
| 843 |
|
| 844 |
CHECK_NEEDED_SIZE_ENUM_LEVEL(spoolss_EnumMonitors, info, r.in.level, count, needed, 4); |
| 845 |
|
| 846 |
ctx->monitor_count[level] = count; |
| 847 |
ctx->monitors[level] = info; |
| 848 |
} |
| 849 |
|
| 850 |
for (i=1;i<ARRAY_SIZE(levels);i++) { |
| 851 |
int level = levels[i]; |
| 852 |
int old_level = levels[i-1]; |
| 853 |
torture_assert_int_equal(tctx, ctx->monitor_count[level], ctx->monitor_count[old_level], |
| 854 |
"EnumMonitors invalid value"); |
| 855 |
} |
| 856 |
|
| 857 |
for (i=0;i<ARRAY_SIZE(levels);i++) { |
| 858 |
int level = levels[i]; |
| 859 |
for (j=0;j<ctx->monitor_count[level];j++) { |
| 860 |
union spoolss_MonitorInfo *cur = &ctx->monitors[level][j]; |
| 861 |
union spoolss_MonitorInfo *ref = &ctx->monitors[2][j]; |
| 862 |
switch (level) { |
| 863 |
case 1: |
| 864 |
COMPARE_STRING(tctx, cur->info1, ref->info2, monitor_name); |
| 865 |
break; |
| 866 |
case 2: |
| 867 |
torture_assert_str_equal(tctx, ref->info2.environment, ctx->environment, "invalid environment"); |
| 868 |
/* level 2 is our reference, and it makes no sense to compare it to itself */ |
| 869 |
break; |
| 870 |
} |
| 871 |
} |
| 872 |
} |
| 873 |
|
| 874 |
return true; |
| 875 |
} |
| 876 |
|
| 877 |
static bool test_EnumPrintProcessors_level(struct torture_context *tctx, |
| 878 |
struct dcerpc_binding_handle *b, |
| 879 |
const char *environment, |
| 880 |
uint32_t level, |
| 881 |
uint32_t *count_p, |
| 882 |
union spoolss_PrintProcessorInfo **info_p, |
| 883 |
WERROR expected_result) |
| 884 |
{ |
| 885 |
struct spoolss_EnumPrintProcessors r; |
| 886 |
DATA_BLOB blob; |
| 887 |
uint32_t needed; |
| 888 |
uint32_t count; |
| 889 |
union spoolss_PrintProcessorInfo *info; |
| 890 |
|
| 891 |
r.in.servername = ""; |
| 892 |
r.in.environment = environment; |
| 893 |
r.in.level = level; |
| 894 |
r.in.buffer = NULL; |
| 895 |
r.in.offered = 0; |
| 896 |
r.out.needed = &needed; |
| 897 |
r.out.count = &count; |
| 898 |
r.out.info = &info; |
| 899 |
|
| 900 |
torture_comment(tctx, "Testing EnumPrintProcessors(%s) level %u\n", |
| 901 |
r.in.environment, r.in.level); |
| 902 |
|
| 903 |
torture_assert_ntstatus_ok(tctx, |
| 904 |
dcerpc_spoolss_EnumPrintProcessors_r(b, tctx, &r), |
| 905 |
"EnumPrintProcessors failed"); |
| 906 |
if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) { |
| 907 |
blob = data_blob_talloc_zero(tctx, needed); |
| 908 |
r.in.buffer = &blob; |
| 909 |
r.in.offered = needed; |
| 910 |
torture_assert_ntstatus_ok(tctx, |
| 911 |
dcerpc_spoolss_EnumPrintProcessors_r(b, tctx, &r), |
| 912 |
"EnumPrintProcessors failed"); |
| 913 |
} |
| 914 |
torture_assert_werr_equal(tctx, r.out.result, expected_result, |
| 915 |
"EnumPrintProcessors failed"); |
| 916 |
|
| 917 |
CHECK_NEEDED_SIZE_ENUM_LEVEL(spoolss_EnumPrintProcessors, info, level, count, needed, 4); |
| 918 |
|
| 919 |
if (count_p) { |
| 920 |
*count_p = count; |
| 921 |
} |
| 922 |
if (info_p) { |
| 923 |
*info_p = info; |
| 924 |
} |
| 925 |
|
| 926 |
return true; |
| 927 |
} |
| 928 |
|
| 929 |
static bool test_EnumPrintProcessors(struct torture_context *tctx, |
| 930 |
void *private_data) |
| 931 |
{ |
| 932 |
struct test_spoolss_context *ctx = |
| 933 |
talloc_get_type_abort(private_data, struct test_spoolss_context); |
| 934 |
|
| 935 |
uint16_t levels[] = {0, 1, 2, 3, 32, 256 }; |
| 936 |
uint16_t ok[] = {0, 1, 0, 0, 0, 0 }; |
| 937 |
int i; |
| 938 |
struct dcerpc_pipe *p = ctx->spoolss_pipe; |
| 939 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 940 |
|
| 941 |
torture_assert(tctx, |
| 942 |
test_EnumPrintProcessors_level(tctx, b, "phantasy", 1, NULL, NULL, WERR_INVALID_ENVIRONMENT), |
| 943 |
"test_EnumPrintProcessors_level failed"); |
| 944 |
|
| 945 |
for (i=0;i<ARRAY_SIZE(levels);i++) { |
| 946 |
union spoolss_PrintProcessorInfo *info; |
| 947 |
uint32_t count; |
| 948 |
WERROR expected_result = ok[i] ? WERR_OK : WERR_INVALID_LEVEL; |
| 949 |
|
| 950 |
torture_assert(tctx, |
| 951 |
test_EnumPrintProcessors_level(tctx, b, ctx->environment, levels[i], &count, &info, expected_result), |
| 952 |
"test_EnumPrintProcessors_level failed"); |
| 953 |
} |
| 954 |
|
| 955 |
return true; |
| 956 |
} |
| 957 |
|
| 958 |
static bool test_EnumPrintProcessorDataTypes_level(struct torture_context *tctx, |
| 959 |
struct dcerpc_binding_handle *b, |
| 960 |
const char *print_processor_name, |
| 961 |
uint32_t level, |
| 962 |
uint32_t *count_p, |
| 963 |
union spoolss_PrintProcDataTypesInfo **info_p, |
| 964 |
WERROR expected_result) |
| 965 |
{ |
| 966 |
struct spoolss_EnumPrintProcessorDataTypes r; |
| 967 |
DATA_BLOB blob; |
| 968 |
uint32_t needed; |
| 969 |
uint32_t count; |
| 970 |
union spoolss_PrintProcDataTypesInfo *info; |
| 971 |
|
| 972 |
r.in.servername = ""; |
| 973 |
r.in.print_processor_name = print_processor_name; |
| 974 |
r.in.level = level; |
| 975 |
r.in.buffer = NULL; |
| 976 |
r.in.offered = 0; |
| 977 |
r.out.needed = &needed; |
| 978 |
r.out.count = &count; |
| 979 |
r.out.info = &info; |
| 980 |
|
| 981 |
torture_comment(tctx, "Testing EnumPrintProcessorDataTypes(%s) level %u\n", |
| 982 |
r.in.print_processor_name, r.in.level); |
| 983 |
|
| 984 |
torture_assert_ntstatus_ok(tctx, |
| 985 |
dcerpc_spoolss_EnumPrintProcessorDataTypes_r(b, tctx, &r), |
| 986 |
"EnumPrintProcessorDataTypes failed"); |
| 987 |
if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) { |
| 988 |
blob = data_blob_talloc_zero(tctx, needed); |
| 989 |
r.in.buffer = &blob; |
| 990 |
r.in.offered = needed; |
| 991 |
torture_assert_ntstatus_ok(tctx, |
| 992 |
dcerpc_spoolss_EnumPrintProcessorDataTypes_r(b, tctx, &r), |
| 993 |
"EnumPrintProcessorDataTypes failed"); |
| 994 |
} |
| 995 |
torture_assert_werr_equal(tctx, r.out.result, expected_result, |
| 996 |
"EnumPrintProcessorDataTypes failed"); |
| 997 |
|
| 998 |
CHECK_NEEDED_SIZE_ENUM_LEVEL(spoolss_EnumPrintProcessorDataTypes, info, level, count, needed, 4); |
| 999 |
|
| 1000 |
if (count_p) { |
| 1001 |
*count_p = count; |
| 1002 |
} |
| 1003 |
if (info_p) { |
| 1004 |
*info_p = info; |
| 1005 |
} |
| 1006 |
|
| 1007 |
return true; |
| 1008 |
} |
| 1009 |
|
| 1010 |
static bool test_EnumPrintProcessorDataTypes(struct torture_context *tctx, |
| 1011 |
void *private_data) |
| 1012 |
{ |
| 1013 |
struct test_spoolss_context *ctx = |
| 1014 |
talloc_get_type_abort(private_data, struct test_spoolss_context); |
| 1015 |
|
| 1016 |
uint16_t levels[] = {0, 1, 2, 3, 32, 256 }; |
| 1017 |
uint16_t ok[] = {0, 1, 0, 0, 0, 0 }; |
| 1018 |
int i; |
| 1019 |
struct dcerpc_pipe *p = ctx->spoolss_pipe; |
| 1020 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 1021 |
|
| 1022 |
torture_assert(tctx, |
| 1023 |
test_EnumPrintProcessorDataTypes_level(tctx, b, NULL, 1, NULL, NULL, WERR_UNKNOWN_PRINTPROCESSOR), |
| 1024 |
"test_EnumPrintProcessorDataTypes_level failed"); |
| 1025 |
|
| 1026 |
torture_assert(tctx, |
| 1027 |
test_EnumPrintProcessorDataTypes_level(tctx, b, "nonexisting", 1, NULL, NULL, WERR_UNKNOWN_PRINTPROCESSOR), |
| 1028 |
"test_EnumPrintProcessorDataTypes_level failed"); |
| 1029 |
|
| 1030 |
for (i=0;i<ARRAY_SIZE(levels);i++) { |
| 1031 |
int level = levels[i]; |
| 1032 |
uint32_t count; |
| 1033 |
union spoolss_PrintProcDataTypesInfo *info; |
| 1034 |
WERROR expected_result = ok[i] ? WERR_OK : WERR_INVALID_LEVEL; |
| 1035 |
|
| 1036 |
torture_assert(tctx, |
| 1037 |
test_EnumPrintProcessorDataTypes_level(tctx, b, "winprint", level, &count, &info, expected_result), |
| 1038 |
"test_EnumPrintProcessorDataTypes_level failed"); |
| 1039 |
} |
| 1040 |
|
| 1041 |
{ |
| 1042 |
union spoolss_PrintProcessorInfo *info; |
| 1043 |
uint32_t count; |
| 1044 |
|
| 1045 |
torture_assert(tctx, |
| 1046 |
test_EnumPrintProcessors_level(tctx, b, ctx->environment, 1, &count, &info, WERR_OK), |
| 1047 |
"test_EnumPrintProcessors_level failed"); |
| 1048 |
|
| 1049 |
for (i=0; i < count; i++) { |
| 1050 |
torture_assert(tctx, |
| 1051 |
test_EnumPrintProcessorDataTypes_level(tctx, b, info[i].info1.print_processor_name, 1, NULL, NULL, WERR_OK), |
| 1052 |
"test_EnumPrintProcessorDataTypes_level failed"); |
| 1053 |
} |
| 1054 |
} |
| 1055 |
|
| 1056 |
|
| 1057 |
return true; |
| 1058 |
} |
| 1059 |
|
| 1060 |
static bool test_EnumPrinters(struct torture_context *tctx, |
| 1061 |
void *private_data) |
| 1062 |
{ |
| 1063 |
struct test_spoolss_context *ctx = |
| 1064 |
talloc_get_type_abort(private_data, struct test_spoolss_context); |
| 1065 |
struct dcerpc_pipe *p = ctx->spoolss_pipe; |
| 1066 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 1067 |
struct spoolss_EnumPrinters r; |
| 1068 |
NTSTATUS status; |
| 1069 |
uint16_t levels[] = { 0, 1, 2, 4, 5 }; |
| 1070 |
int i, j; |
| 1071 |
|
| 1072 |
for (i=0;i<ARRAY_SIZE(levels);i++) { |
| 1073 |
int level = levels[i]; |
| 1074 |
DATA_BLOB blob; |
| 1075 |
uint32_t needed; |
| 1076 |
uint32_t count; |
| 1077 |
union spoolss_PrinterInfo *info; |
| 1078 |
|
| 1079 |
r.in.flags = PRINTER_ENUM_LOCAL; |
| 1080 |
r.in.server = ""; |
| 1081 |
r.in.level = level; |
| 1082 |
r.in.buffer = NULL; |
| 1083 |
r.in.offered = 0; |
| 1084 |
r.out.needed = &needed; |
| 1085 |
r.out.count = &count; |
| 1086 |
r.out.info = &info; |
| 1087 |
|
| 1088 |
torture_comment(tctx, "Testing EnumPrinters level %u\n", r.in.level); |
| 1089 |
|
| 1090 |
status = dcerpc_spoolss_EnumPrinters_r(b, ctx, &r); |
| 1091 |
torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EnumPrinters failed"); |
| 1092 |
if (W_ERROR_IS_OK(r.out.result)) { |
| 1093 |
/* TODO: do some more checks here */ |
| 1094 |
continue; |
| 1095 |
} |
| 1096 |
torture_assert_werr_equal(tctx, r.out.result, WERR_INSUFFICIENT_BUFFER, |
| 1097 |
"EnumPrinters unexpected return code"); |
| 1098 |
|
| 1099 |
blob = data_blob_talloc_zero(ctx, needed); |
| 1100 |
r.in.buffer = &blob; |
| 1101 |
r.in.offered = needed; |
| 1102 |
|
| 1103 |
status = dcerpc_spoolss_EnumPrinters_r(b, ctx, &r); |
| 1104 |
torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EnumPrinters failed"); |
| 1105 |
|
| 1106 |
torture_assert_werr_ok(tctx, r.out.result, "EnumPrinters failed"); |
| 1107 |
|
| 1108 |
CHECK_NEEDED_SIZE_ENUM_LEVEL(spoolss_EnumPrinters, info, r.in.level, count, needed, 4); |
| 1109 |
|
| 1110 |
ctx->printer_count[level] = count; |
| 1111 |
ctx->printers[level] = info; |
| 1112 |
} |
| 1113 |
|
| 1114 |
for (i=1;i<ARRAY_SIZE(levels);i++) { |
| 1115 |
int level = levels[i]; |
| 1116 |
int old_level = levels[i-1]; |
| 1117 |
torture_assert_int_equal(tctx, ctx->printer_count[level], ctx->printer_count[old_level], |
| 1118 |
"EnumPrinters invalid value"); |
| 1119 |
} |
| 1120 |
|
| 1121 |
for (i=0;i<ARRAY_SIZE(levels);i++) { |
| 1122 |
int level = levels[i]; |
| 1123 |
for (j=0;j<ctx->printer_count[level];j++) { |
| 1124 |
union spoolss_PrinterInfo *cur = &ctx->printers[level][j]; |
| 1125 |
union spoolss_PrinterInfo *ref = &ctx->printers[2][j]; |
| 1126 |
switch (level) { |
| 1127 |
case 0: |
| 1128 |
COMPARE_STRING(tctx, cur->info0, ref->info2, printername); |
| 1129 |
COMPARE_STRING(tctx, cur->info0, ref->info2, servername); |
| 1130 |
COMPARE_UINT32(tctx, cur->info0, ref->info2, cjobs); |
| 1131 |
/*COMPARE_UINT32(tctx, cur->info0, ref->info2, total_jobs); |
| 1132 |
COMPARE_UINT32(tctx, cur->info0, ref->info2, total_bytes); |
| 1133 |
COMPARE_SPOOLSS_TIME(cur->info0, ref->info2, spoolss_Time time); |
| 1134 |
COMPARE_UINT32(tctx, cur->info0, ref->info2, global_counter); |
| 1135 |
COMPARE_UINT32(tctx, cur->info0, ref->info2, total_pages); |
| 1136 |
COMPARE_UINT32(tctx, cur->info0, ref->info2, version); |
| 1137 |
COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown10); |
| 1138 |
COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown11); |
| 1139 |
COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown12); |
| 1140 |
COMPARE_UINT32(tctx, cur->info0, ref->info2, session_counter); |
| 1141 |
COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown14); |
| 1142 |
COMPARE_UINT32(tctx, cur->info0, ref->info2, printer_errors); |
| 1143 |
COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown16); |
| 1144 |
COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown17); |
| 1145 |
COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown18); |
| 1146 |
COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown19); |
| 1147 |
COMPARE_UINT32(tctx, cur->info0, ref->info2, change_id); |
| 1148 |
COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown21);*/ |
| 1149 |
COMPARE_UINT32(tctx, cur->info0, ref->info2, status); |
| 1150 |
/*COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown23); |
| 1151 |
COMPARE_UINT32(tctx, cur->info0, ref->info2, c_setprinter); |
| 1152 |
COMPARE_UINT16(cur->info0, ref->info2, unknown25); |
| 1153 |
COMPARE_UINT16(cur->info0, ref->info2, unknown26); |
| 1154 |
COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown27); |
| 1155 |
COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown28); |
| 1156 |
COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown29);*/ |
| 1157 |
break; |
| 1158 |
case 1: |
| 1159 |
/*COMPARE_UINT32(tctx, cur->info1, ref->info2, flags);*/ |
| 1160 |
/*COMPARE_STRING(tctx, cur->info1, ref->info2, name);*/ |
| 1161 |
/*COMPARE_STRING(tctx, cur->info1, ref->info2, description);*/ |
| 1162 |
COMPARE_STRING(tctx, cur->info1, ref->info2, comment); |
| 1163 |
break; |
| 1164 |
case 2: |
| 1165 |
/* level 2 is our reference, and it makes no sense to compare it to itself */ |
| 1166 |
break; |
| 1167 |
case 4: |
| 1168 |
COMPARE_STRING(tctx, cur->info4, ref->info2, printername); |
| 1169 |
COMPARE_STRING(tctx, cur->info4, ref->info2, servername); |
| 1170 |
COMPARE_UINT32(tctx, cur->info4, ref->info2, attributes); |
| 1171 |
break; |
| 1172 |
case 5: |
| 1173 |
COMPARE_STRING(tctx, cur->info5, ref->info2, printername); |
| 1174 |
COMPARE_STRING(tctx, cur->info5, ref->info2, portname); |
| 1175 |
COMPARE_UINT32(tctx, cur->info5, ref->info2, attributes); |
| 1176 |
/*COMPARE_UINT32(tctx, cur->info5, ref->info2, device_not_selected_timeout); |
| 1177 |
COMPARE_UINT32(tctx, cur->info5, ref->info2, transmission_retry_timeout);*/ |
| 1178 |
break; |
| 1179 |
} |
| 1180 |
} |
| 1181 |
} |
| 1182 |
|
| 1183 |
/* TODO: |
| 1184 |
* - verify that the port of a printer was in the list returned by EnumPorts |
| 1185 |
*/ |
| 1186 |
|
| 1187 |
return true; |
| 1188 |
} |
| 1189 |
|
| 1190 |
static bool test_GetPrinterDriver2(struct torture_context *tctx, |
| 1191 |
struct dcerpc_binding_handle *b, |
| 1192 |
struct policy_handle *handle, |
| 1193 |
const char *driver_name, |
| 1194 |
const char *environment); |
| 1195 |
|
| 1196 |
bool test_GetPrinter_level_exp(struct torture_context *tctx, |
| 1197 |
struct dcerpc_binding_handle *b, |
| 1198 |
struct policy_handle *handle, |
| 1199 |
uint32_t level, |
| 1200 |
WERROR expected_werror, |
| 1201 |
union spoolss_PrinterInfo *info) |
| 1202 |
{ |
| 1203 |
struct spoolss_GetPrinter r; |
| 1204 |
uint32_t needed; |
| 1205 |
|
| 1206 |
r.in.handle = handle; |
| 1207 |
r.in.level = level; |
| 1208 |
r.in.buffer = NULL; |
| 1209 |
r.in.offered = 0; |
| 1210 |
r.out.needed = &needed; |
| 1211 |
|
| 1212 |
torture_comment(tctx, "Testing GetPrinter level %u\n", r.in.level); |
| 1213 |
|
| 1214 |
torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_GetPrinter_r(b, tctx, &r), |
| 1215 |
"GetPrinter failed"); |
| 1216 |
|
| 1217 |
if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) { |
| 1218 |
DATA_BLOB blob = data_blob_talloc_zero(tctx, needed); |
| 1219 |
r.in.buffer = &blob; |
| 1220 |
r.in.offered = needed; |
| 1221 |
|
| 1222 |
torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_GetPrinter_r(b, tctx, &r), |
| 1223 |
"GetPrinter failed"); |
| 1224 |
} |
| 1225 |
|
| 1226 |
torture_assert_werr_equal(tctx, |
| 1227 |
r.out.result, expected_werror, |
| 1228 |
"GetPrinter failed"); |
| 1229 |
|
| 1230 |
CHECK_NEEDED_SIZE_LEVEL(spoolss_PrinterInfo, r.out.info, r.in.level, needed, 4); |
| 1231 |
|
| 1232 |
if (info && r.out.info) { |
| 1233 |
*info = *r.out.info; |
| 1234 |
} |
| 1235 |
|
| 1236 |
return true; |
| 1237 |
} |
| 1238 |
|
| 1239 |
bool test_GetPrinter_level(struct torture_context *tctx, |
| 1240 |
struct dcerpc_binding_handle *b, |
| 1241 |
struct policy_handle *handle, |
| 1242 |
uint32_t level, |
| 1243 |
union spoolss_PrinterInfo *info) |
| 1244 |
{ |
| 1245 |
return test_GetPrinter_level_exp(tctx, b, handle, level, WERR_OK, info); |
| 1246 |
} |
| 1247 |
|
| 1248 |
static bool test_GetPrinter(struct torture_context *tctx, |
| 1249 |
struct dcerpc_binding_handle *b, |
| 1250 |
struct policy_handle *handle, |
| 1251 |
const char *environment) |
| 1252 |
{ |
| 1253 |
uint32_t levels[] = {0, 1, 2, 3, 4, 5, 6, 7, 8}; |
| 1254 |
int i; |
| 1255 |
|
| 1256 |
for (i=0;i<ARRAY_SIZE(levels);i++) { |
| 1257 |
|
| 1258 |
union spoolss_PrinterInfo info; |
| 1259 |
|
| 1260 |
ZERO_STRUCT(info); |
| 1261 |
|
| 1262 |
torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, levels[i], &info), |
| 1263 |
"failed to call GetPrinter"); |
| 1264 |
|
| 1265 |
if ((levels[i] == 2) && info.info2.drivername && strlen(info.info2.drivername)) { |
| 1266 |
torture_assert(tctx, |
| 1267 |
test_GetPrinterDriver2(tctx, b, handle, info.info2.drivername, environment), |
| 1268 |
"failed to call test_GetPrinterDriver2"); |
| 1269 |
} |
| 1270 |
} |
| 1271 |
|
| 1272 |
return true; |
| 1273 |
} |
| 1274 |
|
| 1275 |
static bool test_SetPrinter(struct torture_context *tctx, |
| 1276 |
struct dcerpc_binding_handle *b, |
| 1277 |
struct policy_handle *handle, |
| 1278 |
struct spoolss_SetPrinterInfoCtr *info_ctr, |
| 1279 |
struct spoolss_DevmodeContainer *devmode_ctr, |
| 1280 |
struct sec_desc_buf *secdesc_ctr, |
| 1281 |
enum spoolss_PrinterControl command) |
| 1282 |
{ |
| 1283 |
struct spoolss_SetPrinter r; |
| 1284 |
|
| 1285 |
r.in.handle = handle; |
| 1286 |
r.in.info_ctr = info_ctr; |
| 1287 |
r.in.devmode_ctr = devmode_ctr; |
| 1288 |
r.in.secdesc_ctr = secdesc_ctr; |
| 1289 |
r.in.command = command; |
| 1290 |
|
| 1291 |
torture_comment(tctx, "Testing SetPrinter level %d\n", r.in.info_ctr->level); |
| 1292 |
|
| 1293 |
torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_SetPrinter_r(b, tctx, &r), |
| 1294 |
"failed to call SetPrinter"); |
| 1295 |
torture_assert(tctx, (W_ERROR_EQUAL(r.out.result, WERR_OK) |
| 1296 |
|| W_ERROR_EQUAL(r.out.result, WERR_IO_PENDING)), |
| 1297 |
"SetPrinter failed"); |
| 1298 |
|
| 1299 |
return true; |
| 1300 |
} |
| 1301 |
|
| 1302 |
static bool test_SetPrinter_errors(struct torture_context *tctx, |
| 1303 |
struct dcerpc_binding_handle *b, |
| 1304 |
struct policy_handle *handle) |
| 1305 |
{ |
| 1306 |
struct spoolss_SetPrinter r; |
| 1307 |
uint16_t levels[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; |
| 1308 |
int i; |
| 1309 |
|
| 1310 |
struct spoolss_SetPrinterInfoCtr info_ctr; |
| 1311 |
struct spoolss_DevmodeContainer devmode_ctr; |
| 1312 |
struct sec_desc_buf secdesc_ctr; |
| 1313 |
|
| 1314 |
info_ctr.level = 0; |
| 1315 |
info_ctr.info.info0 = NULL; |
| 1316 |
|
| 1317 |
ZERO_STRUCT(devmode_ctr); |
| 1318 |
ZERO_STRUCT(secdesc_ctr); |
| 1319 |
|
| 1320 |
r.in.handle = handle; |
| 1321 |
r.in.info_ctr = &info_ctr; |
| 1322 |
r.in.devmode_ctr = &devmode_ctr; |
| 1323 |
r.in.secdesc_ctr = &secdesc_ctr; |
| 1324 |
r.in.command = 0; |
| 1325 |
|
| 1326 |
torture_comment(tctx, "Testing SetPrinter all zero\n"); |
| 1327 |
|
| 1328 |
torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_SetPrinter_r(b, tctx, &r), |
| 1329 |
"failed to call SetPrinter"); |
| 1330 |
torture_assert_werr_equal(tctx, r.out.result, WERR_INVALID_PARAMETER, |
| 1331 |
"failed to call SetPrinter"); |
| 1332 |
|
| 1333 |
again: |
| 1334 |
for (i=0; i < ARRAY_SIZE(levels); i++) { |
| 1335 |
|
| 1336 |
struct spoolss_SetPrinterInfo0 info0; |
| 1337 |
struct spoolss_SetPrinterInfo1 info1; |
| 1338 |
struct spoolss_SetPrinterInfo2 info2; |
| 1339 |
struct spoolss_SetPrinterInfo3 info3; |
| 1340 |
struct spoolss_SetPrinterInfo4 info4; |
| 1341 |
struct spoolss_SetPrinterInfo5 info5; |
| 1342 |
struct spoolss_SetPrinterInfo6 info6; |
| 1343 |
struct spoolss_SetPrinterInfo7 info7; |
| 1344 |
struct spoolss_SetPrinterInfo8 info8; |
| 1345 |
struct spoolss_SetPrinterInfo9 info9; |
| 1346 |
|
| 1347 |
|
| 1348 |
info_ctr.level = levels[i]; |
| 1349 |
switch (levels[i]) { |
| 1350 |
case 0: |
| 1351 |
ZERO_STRUCT(info0); |
| 1352 |
info_ctr.info.info0 = &info0; |
| 1353 |
break; |
| 1354 |
case 1: |
| 1355 |
ZERO_STRUCT(info1); |
| 1356 |
info_ctr.info.info1 = &info1; |
| 1357 |
break; |
| 1358 |
case 2: |
| 1359 |
ZERO_STRUCT(info2); |
| 1360 |
info_ctr.info.info2 = &info2; |
| 1361 |
break; |
| 1362 |
case 3: |
| 1363 |
ZERO_STRUCT(info3); |
| 1364 |
info_ctr.info.info3 = &info3; |
| 1365 |
break; |
| 1366 |
case 4: |
| 1367 |
ZERO_STRUCT(info4); |
| 1368 |
info_ctr.info.info4 = &info4; |
| 1369 |
break; |
| 1370 |
case 5: |
| 1371 |
ZERO_STRUCT(info5); |
| 1372 |
info_ctr.info.info5 = &info5; |
| 1373 |
break; |
| 1374 |
case 6: |
| 1375 |
ZERO_STRUCT(info6); |
| 1376 |
info_ctr.info.info6 = &info6; |
| 1377 |
break; |
| 1378 |
case 7: |
| 1379 |
ZERO_STRUCT(info7); |
| 1380 |
info_ctr.info.info7 = &info7; |
| 1381 |
break; |
| 1382 |
case 8: |
| 1383 |
ZERO_STRUCT(info8); |
| 1384 |
info_ctr.info.info8 = &info8; |
| 1385 |
break; |
| 1386 |
case 9: |
| 1387 |
ZERO_STRUCT(info9); |
| 1388 |
info_ctr.info.info9 = &info9; |
| 1389 |
break; |
| 1390 |
} |
| 1391 |
|
| 1392 |
torture_comment(tctx, "Testing SetPrinter level %d, command %d\n", |
| 1393 |
info_ctr.level, r.in.command); |
| 1394 |
|
| 1395 |
torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_SetPrinter_r(b, tctx, &r), |
| 1396 |
"failed to call SetPrinter"); |
| 1397 |
|
| 1398 |
switch (r.in.command) { |
| 1399 |
case SPOOLSS_PRINTER_CONTROL_UNPAUSE: /* 0 */ |
| 1400 |
/* is ignored for all levels other then 0 */ |
| 1401 |
if (info_ctr.level > 0) { |
| 1402 |
/* ignored then */ |
| 1403 |
break; |
| 1404 |
} |
| 1405 |
|
| 1406 |
FALL_THROUGH; |
| 1407 |
case SPOOLSS_PRINTER_CONTROL_PAUSE: /* 1 */ |
| 1408 |
case SPOOLSS_PRINTER_CONTROL_RESUME: /* 2 */ |
| 1409 |
case SPOOLSS_PRINTER_CONTROL_PURGE: /* 3 */ |
| 1410 |
if (info_ctr.level > 0) { |
| 1411 |
/* is invalid for all levels other then 0 */ |
| 1412 |
torture_assert_werr_equal(tctx, r.out.result, WERR_INVALID_PRINTER_COMMAND, |
| 1413 |
"unexpected error code returned"); |
| 1414 |
continue; |
| 1415 |
} else { |
| 1416 |
torture_assert_werr_ok(tctx, r.out.result, |
| 1417 |
"failed to call SetPrinter with non 0 command"); |
| 1418 |
continue; |
| 1419 |
} |
| 1420 |
break; |
| 1421 |
|
| 1422 |
case SPOOLSS_PRINTER_CONTROL_SET_STATUS: /* 4 */ |
| 1423 |
/* FIXME: gd needs further investigation */ |
| 1424 |
default: |
| 1425 |
torture_assert_werr_equal(tctx, r.out.result, WERR_INVALID_PRINTER_COMMAND, |
| 1426 |
"unexpected error code returned"); |
| 1427 |
continue; |
| 1428 |
} |
| 1429 |
|
| 1430 |
switch (info_ctr.level) { |
| 1431 |
case 1: |
| 1432 |
torture_assert_werr_equal(tctx, r.out.result, WERR_INVALID_LEVEL, |
| 1433 |
"unexpected error code returned"); |
| 1434 |
break; |
| 1435 |
case 2: |
| 1436 |
torture_assert_werr_equal(tctx, r.out.result, WERR_UNKNOWN_PRINTER_DRIVER, |
| 1437 |
"unexpected error code returned"); |
| 1438 |
break; |
| 1439 |
case 3: |
| 1440 |
case 4: |
| 1441 |
case 5: |
| 1442 |
case 7: |
| 1443 |
torture_assert_werr_equal(tctx, r.out.result, WERR_INVALID_PARAMETER, |
| 1444 |
"unexpected error code returned"); |
| 1445 |
break; |
| 1446 |
case 9: |
| 1447 |
torture_assert_werr_equal(tctx, r.out.result, WERR_NOT_SUPPORTED, |
| 1448 |
"unexpected error code returned"); |
| 1449 |
break; |
| 1450 |
default: |
| 1451 |
torture_assert_werr_ok(tctx, r.out.result, |
| 1452 |
"failed to call SetPrinter"); |
| 1453 |
break; |
| 1454 |
} |
| 1455 |
} |
| 1456 |
|
| 1457 |
if (r.in.command < 5) { |
| 1458 |
r.in.command++; |
| 1459 |
goto again; |
| 1460 |
} |
| 1461 |
|
| 1462 |
return true; |
| 1463 |
} |
| 1464 |
|
| 1465 |
static void clear_info2(struct spoolss_SetPrinterInfoCtr *r) |
| 1466 |
{ |
| 1467 |
if ((r->level == 2) && (r->info.info2)) { |
| 1468 |
r->info.info2->secdesc_ptr = 0; |
| 1469 |
r->info.info2->devmode_ptr = 0; |
| 1470 |
} |
| 1471 |
} |
| 1472 |
|
| 1473 |
static bool test_PrinterInfo(struct torture_context *tctx, |
| 1474 |
struct dcerpc_binding_handle *b, |
| 1475 |
struct policy_handle *handle) |
| 1476 |
{ |
| 1477 |
NTSTATUS status; |
| 1478 |
struct spoolss_SetPrinter s; |
| 1479 |
struct spoolss_GetPrinter q; |
| 1480 |
struct spoolss_GetPrinter q0; |
| 1481 |
struct spoolss_SetPrinterInfoCtr info_ctr; |
| 1482 |
union spoolss_PrinterInfo info; |
| 1483 |
struct spoolss_DevmodeContainer devmode_ctr; |
| 1484 |
struct sec_desc_buf secdesc_ctr; |
| 1485 |
uint32_t needed = 0; |
| 1486 |
DATA_BLOB blob = data_blob_null; |
| 1487 |
bool ret = true; |
| 1488 |
int i; |
| 1489 |
|
| 1490 |
uint32_t status_list[] = { |
| 1491 |
/* these do not stick |
| 1492 |
PRINTER_STATUS_PAUSED, |
| 1493 |
PRINTER_STATUS_ERROR, |
| 1494 |
PRINTER_STATUS_PENDING_DELETION, */ |
| 1495 |
PRINTER_STATUS_PAPER_JAM, |
| 1496 |
PRINTER_STATUS_PAPER_OUT, |
| 1497 |
PRINTER_STATUS_MANUAL_FEED, |
| 1498 |
PRINTER_STATUS_PAPER_PROBLEM, |
| 1499 |
PRINTER_STATUS_OFFLINE, |
| 1500 |
PRINTER_STATUS_IO_ACTIVE, |
| 1501 |
PRINTER_STATUS_BUSY, |
| 1502 |
PRINTER_STATUS_PRINTING, |
| 1503 |
PRINTER_STATUS_OUTPUT_BIN_FULL, |
| 1504 |
PRINTER_STATUS_NOT_AVAILABLE, |
| 1505 |
PRINTER_STATUS_WAITING, |
| 1506 |
PRINTER_STATUS_PROCESSING, |
| 1507 |
PRINTER_STATUS_INITIALIZING, |
| 1508 |
PRINTER_STATUS_WARMING_UP, |
| 1509 |
PRINTER_STATUS_TONER_LOW, |
| 1510 |
PRINTER_STATUS_NO_TONER, |
| 1511 |
PRINTER_STATUS_PAGE_PUNT, |
| 1512 |
PRINTER_STATUS_USER_INTERVENTION, |
| 1513 |
PRINTER_STATUS_OUT_OF_MEMORY, |
| 1514 |
PRINTER_STATUS_DOOR_OPEN, |
| 1515 |
PRINTER_STATUS_SERVER_UNKNOWN, |
| 1516 |
PRINTER_STATUS_POWER_SAVE, |
| 1517 |
/* these do not stick |
| 1518 |
0x02000000, |
| 1519 |
0x04000000, |
| 1520 |
0x08000000, |
| 1521 |
0x10000000, |
| 1522 |
0x20000000, |
| 1523 |
0x40000000, |
| 1524 |
0x80000000 */ |
| 1525 |
}; |
| 1526 |
uint32_t default_attribute = PRINTER_ATTRIBUTE_LOCAL; |
| 1527 |
uint32_t attribute_list[] = { |
| 1528 |
PRINTER_ATTRIBUTE_QUEUED, |
| 1529 |
/* fails with WERR_INVALID_DATATYPE: |
| 1530 |
PRINTER_ATTRIBUTE_DIRECT, */ |
| 1531 |
/* does not stick |
| 1532 |
PRINTER_ATTRIBUTE_DEFAULT, */ |
| 1533 |
PRINTER_ATTRIBUTE_SHARED, |
| 1534 |
/* does not stick |
| 1535 |
PRINTER_ATTRIBUTE_NETWORK, */ |
| 1536 |
PRINTER_ATTRIBUTE_HIDDEN, |
| 1537 |
PRINTER_ATTRIBUTE_LOCAL, |
| 1538 |
PRINTER_ATTRIBUTE_ENABLE_DEVQ, |
| 1539 |
PRINTER_ATTRIBUTE_KEEPPRINTEDJOBS, |
| 1540 |
PRINTER_ATTRIBUTE_DO_COMPLETE_FIRST, |
| 1541 |
PRINTER_ATTRIBUTE_WORK_OFFLINE, |
| 1542 |
/* does not stick |
| 1543 |
PRINTER_ATTRIBUTE_ENABLE_BIDI, */ |
| 1544 |
/* fails with WERR_INVALID_DATATYPE: |
| 1545 |
PRINTER_ATTRIBUTE_RAW_ONLY, */ |
| 1546 |
/* these do not stick |
| 1547 |
PRINTER_ATTRIBUTE_PUBLISHED, |
| 1548 |
PRINTER_ATTRIBUTE_FAX, |
| 1549 |
PRINTER_ATTRIBUTE_TS, |
| 1550 |
0x00010000, |
| 1551 |
0x00020000, |
| 1552 |
0x00040000, |
| 1553 |
0x00080000, |
| 1554 |
0x00100000, |
| 1555 |
0x00200000, |
| 1556 |
0x00400000, |
| 1557 |
0x00800000, |
| 1558 |
0x01000000, |
| 1559 |
0x02000000, |
| 1560 |
0x04000000, |
| 1561 |
0x08000000, |
| 1562 |
0x10000000, |
| 1563 |
0x20000000, |
| 1564 |
0x40000000, |
| 1565 |
0x80000000 */ |
| 1566 |
}; |
| 1567 |
|
| 1568 |
torture_skip(tctx, "Printer Info test is currently broken, skipping"); |
| 1569 |
|
| 1570 |
|
| 1571 |
ZERO_STRUCT(devmode_ctr); |
| 1572 |
ZERO_STRUCT(secdesc_ctr); |
| 1573 |
|
| 1574 |
s.in.handle = handle; |
| 1575 |
s.in.command = 0; |
| 1576 |
s.in.info_ctr = &info_ctr; |
| 1577 |
s.in.devmode_ctr = &devmode_ctr; |
| 1578 |
s.in.secdesc_ctr = &secdesc_ctr; |
| 1579 |
|
| 1580 |
q.in.handle = handle; |
| 1581 |
q.out.info = &info; |
| 1582 |
q0 = q; |
| 1583 |
|
| 1584 |
#define TESTGETCALL(call, r, needed, blob) \ |
| 1585 |
r.in.buffer = NULL; \ |
| 1586 |
r.in.offered = 0;\ |
| 1587 |
r.out.needed = &needed; \ |
| 1588 |
status = dcerpc_spoolss_ ##call## _r(b, tctx, &r); \ |
| 1589 |
if (!NT_STATUS_IS_OK(status)) { \ |
| 1590 |
torture_comment(tctx, #call " level %u failed - %s (%s)\n", \ |
| 1591 |
r.in.level, nt_errstr(status), __location__); \ |
| 1592 |
ret = false; \ |
| 1593 |
break; \ |
| 1594 |
}\ |
| 1595 |
if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {\ |
| 1596 |
blob = data_blob_talloc_zero(tctx, needed); \ |
| 1597 |
r.in.buffer = &blob; \ |
| 1598 |
r.in.offered = needed; \ |
| 1599 |
}\ |
| 1600 |
status = dcerpc_spoolss_ ##call## _r(b, tctx, &r); \ |
| 1601 |
if (!NT_STATUS_IS_OK(status)) { \ |
| 1602 |
torture_comment(tctx, #call " level %u failed - %s (%s)\n", \ |
| 1603 |
r.in.level, nt_errstr(status), __location__); \ |
| 1604 |
ret = false; \ |
| 1605 |
break; \ |
| 1606 |
} \ |
| 1607 |
if (!W_ERROR_IS_OK(r.out.result)) { \ |
| 1608 |
torture_comment(tctx, #call " level %u failed - %s (%s)\n", \ |
| 1609 |
r.in.level, win_errstr(r.out.result), __location__); \ |
| 1610 |
ret = false; \ |
| 1611 |
break; \ |
| 1612 |
} |
| 1613 |
|
| 1614 |
|
| 1615 |
#define TESTSETCALL_EXP(call, r, err) \ |
| 1616 |
clear_info2(&info_ctr);\ |
| 1617 |
status = dcerpc_spoolss_ ##call## _r(b, tctx, &r); \ |
| 1618 |
if (!NT_STATUS_IS_OK(status)) { \ |
| 1619 |
torture_comment(tctx, #call " level %u failed - %s (%s)\n", \ |
| 1620 |
r.in.info_ctr->level, nt_errstr(status), __location__); \ |
| 1621 |
ret = false; \ |
| 1622 |
break; \ |
| 1623 |
} \ |
| 1624 |
if (!W_ERROR_IS_OK(err)) { \ |
| 1625 |
if (!W_ERROR_EQUAL(err, r.out.result)) { \ |
| 1626 |
torture_comment(tctx, #call " level %u failed - %s, expected %s (%s)\n", \ |
| 1627 |
r.in.info_ctr->level, win_errstr(r.out.result), win_errstr(err), __location__); \ |
| 1628 |
ret = false; \ |
| 1629 |
} \ |
| 1630 |
break; \ |
| 1631 |
} \ |
| 1632 |
if (!W_ERROR_IS_OK(r.out.result)) { \ |
| 1633 |
torture_comment(tctx, #call " level %u failed - %s (%s)\n", \ |
| 1634 |
r.in.info_ctr->level, win_errstr(r.out.result), __location__); \ |
| 1635 |
ret = false; \ |
| 1636 |
break; \ |
| 1637 |
} |
| 1638 |
|
| 1639 |
#define TESTSETCALL(call, r) \ |
| 1640 |
TESTSETCALL_EXP(call, r, WERR_OK) |
| 1641 |
|
| 1642 |
#define STRING_EQUAL(s1, s2, field) \ |
| 1643 |
if ((s1 && !s2) || (s2 && !s1) || strcmp(s1, s2)) { \ |
| 1644 |
torture_comment(tctx, "Failed to set %s to '%s' (%s)\n", \ |
| 1645 |
#field, s2, __location__); \ |
| 1646 |
ret = false; \ |
| 1647 |
break; \ |
| 1648 |
} |
| 1649 |
|
| 1650 |
#define MEM_EQUAL(s1, s2, length, field) \ |
| 1651 |
if ((s1 && !s2) || (s2 && !s1) || memcmp(s1, s2, length)) { \ |
| 1652 |
torture_comment(tctx, "Failed to set %s to '%s' (%s)\n", \ |
| 1653 |
#field, (const char *)s2, __location__); \ |
| 1654 |
ret = false; \ |
| 1655 |
break; \ |
| 1656 |
} |
| 1657 |
|
| 1658 |
#define INT_EQUAL(i1, i2, field) \ |
| 1659 |
if (i1 != i2) { \ |
| 1660 |
torture_comment(tctx, "Failed to set %s to 0x%llx - got 0x%llx (%s)\n", \ |
| 1661 |
#field, (unsigned long long)i2, (unsigned long long)i1, __location__); \ |
| 1662 |
ret = false; \ |
| 1663 |
break; \ |
| 1664 |
} |
| 1665 |
|
| 1666 |
#define SD_EQUAL(sd1, sd2, field) \ |
| 1667 |
if (!security_descriptor_equal(sd1, sd2)) { \ |
| 1668 |
torture_comment(tctx, "Failed to set %s (%s)\n", \ |
| 1669 |
#field, __location__); \ |
| 1670 |
ret = false; \ |
| 1671 |
break; \ |
| 1672 |
} |
| 1673 |
|
| 1674 |
#define TEST_PRINTERINFO_STRING_EXP_ERR(q, s, needed, blob, lvl1, field1, lvl2, field2, value, err) do { \ |
| 1675 |
void *p; \ |
| 1676 |
torture_comment(tctx, "field test %d/%s vs %d/%s\n", lvl1, #field1, lvl2, #field2); \ |
| 1677 |
q.in.level = lvl1; \ |
| 1678 |
TESTGETCALL(GetPrinter, q, needed, blob) \ |
| 1679 |
info_ctr.level = lvl1; \ |
| 1680 |
p = (void *)&q.out.info->info ## lvl1; \ |
| 1681 |
info_ctr.info.info ## lvl1 = (struct spoolss_SetPrinterInfo ## lvl1 *)p; \ |
| 1682 |
info_ctr.info.info ## lvl1->field1 = value;\ |
| 1683 |
TESTSETCALL_EXP(SetPrinter, s, err) \ |
| 1684 |
info_ctr.info.info ## lvl1->field1 = ""; \ |
| 1685 |
TESTGETCALL(GetPrinter, q, needed, blob) \ |
| 1686 |
info_ctr.info.info ## lvl1->field1 = value; \ |
| 1687 |
STRING_EQUAL(info_ctr.info.info ## lvl1->field1, value, field1); \ |
| 1688 |
q.in.level = lvl2; \ |
| 1689 |
TESTGETCALL(GetPrinter, q, needed, blob) \ |
| 1690 |
p = (void *)&q.out.info->info ## lvl2; \ |
| 1691 |
info_ctr.info.info ## lvl2 = (struct spoolss_SetPrinterInfo ## lvl2 *)p; \ |
| 1692 |
STRING_EQUAL(info_ctr.info.info ## lvl2->field2, value, field2); \ |
| 1693 |
} while (0) |
| 1694 |
|
| 1695 |
#define TEST_PRINTERINFO_STRING(q, s, needed, blob, lvl1, field1, lvl2, field2, value) do { \ |
| 1696 |
TEST_PRINTERINFO_STRING_EXP_ERR(q, s, needed, blob, lvl1, field1, lvl2, field2, value, WERR_OK); \ |
| 1697 |
} while (0); |
| 1698 |
|
| 1699 |
#define TEST_PRINTERINFO_INT_EXP(q, s, needed, blob, lvl1, field1, lvl2, field2, value, exp_value) do { \ |
| 1700 |
void *p; \ |
| 1701 |
torture_comment(tctx, "field test %d/%s vs %d/%s\n", lvl1, #field1, lvl2, #field2); \ |
| 1702 |
q.in.level = lvl1; \ |
| 1703 |
TESTGETCALL(GetPrinter, q, needed, blob) \ |
| 1704 |
info_ctr.level = lvl1; \ |
| 1705 |
p = (void *)&q.out.info->info ## lvl1; \ |
| 1706 |
info_ctr.info.info ## lvl1 = (struct spoolss_SetPrinterInfo ## lvl1 *)p; \ |
| 1707 |
info_ctr.info.info ## lvl1->field1 = value; \ |
| 1708 |
TESTSETCALL(SetPrinter, s) \ |
| 1709 |
info_ctr.info.info ## lvl1->field1 = 0; \ |
| 1710 |
TESTGETCALL(GetPrinter, q, needed, blob) \ |
| 1711 |
p = (void *)&q.out.info->info ## lvl1; \ |
| 1712 |
info_ctr.info.info ## lvl1 = (struct spoolss_SetPrinterInfo ## lvl1 *)p; \ |
| 1713 |
INT_EQUAL(info_ctr.info.info ## lvl1->field1, exp_value, field1); \ |
| 1714 |
q.in.level = lvl2; \ |
| 1715 |
TESTGETCALL(GetPrinter, q, needed, blob) \ |
| 1716 |
p = (void *)&q.out.info->info ## lvl2; \ |
| 1717 |
info_ctr.info.info ## lvl2 = (struct spoolss_SetPrinterInfo ## lvl2 *)p; \ |
| 1718 |
INT_EQUAL(info_ctr.info.info ## lvl2->field2, exp_value, field1); \ |
| 1719 |
} while (0) |
| 1720 |
|
| 1721 |
#define TEST_PRINTERINFO_INT(q, s, needed, blob, lvl1, field1, lvl2, field2, value) do { \ |
| 1722 |
TEST_PRINTERINFO_INT_EXP(q, s, needed, blob, lvl1, field1, lvl2, field2, value, value); \ |
| 1723 |
} while (0) |
| 1724 |
|
| 1725 |
q0.in.level = 0; |
| 1726 |
do { TESTGETCALL(GetPrinter, q0, needed, blob) } while (0); |
| 1727 |
|
| 1728 |
TEST_PRINTERINFO_STRING(q, s, needed, blob, 2, comment, 1, comment, "xx2-1 comment"); |
| 1729 |
TEST_PRINTERINFO_STRING(q, s, needed, blob, 2, comment, 2, comment, "xx2-2 comment"); |
| 1730 |
|
| 1731 |
/* level 0 printername does not stick */ |
| 1732 |
/* TEST_PRINTERINFO_STRING(q, s, needed, blob, 2, printername, 0, printername, "xx2-0 printer"); */ |
| 1733 |
TEST_PRINTERINFO_STRING(q, s, needed, blob, 2, printername, 1, name, "xx2-1 printer"); |
| 1734 |
TEST_PRINTERINFO_STRING(q, s, needed, blob, 2, printername, 2, printername, "xx2-2 printer"); |
| 1735 |
TEST_PRINTERINFO_STRING(q, s, needed, blob, 2, printername, 4, printername, "xx2-4 printer"); |
| 1736 |
TEST_PRINTERINFO_STRING(q, s, needed, blob, 2, printername, 5, printername, "xx2-5 printer"); |
| 1737 |
/* TEST_PRINTERINFO_STRING(q, s, needed, blob, 4, printername, 0, printername, "xx4-0 printer"); */ |
| 1738 |
TEST_PRINTERINFO_STRING(q, s, needed, blob, 4, printername, 1, name, "xx4-1 printer"); |
| 1739 |
TEST_PRINTERINFO_STRING(q, s, needed, blob, 4, printername, 2, printername, "xx4-2 printer"); |
| 1740 |
TEST_PRINTERINFO_STRING(q, s, needed, blob, 4, printername, 4, printername, "xx4-4 printer"); |
| 1741 |
TEST_PRINTERINFO_STRING(q, s, needed, blob, 4, printername, 5, printername, "xx4-5 printer"); |
| 1742 |
/* TEST_PRINTERINFO_STRING(q, s, needed, blob, 5, printername, 0, printername, "xx5-0 printer"); */ |
| 1743 |
TEST_PRINTERINFO_STRING(q, s, needed, blob, 5, printername, 1, name, "xx5-1 printer"); |
| 1744 |
TEST_PRINTERINFO_STRING(q, s, needed, blob, 5, printername, 2, printername, "xx5-2 printer"); |
| 1745 |
TEST_PRINTERINFO_STRING(q, s, needed, blob, 5, printername, 4, printername, "xx5-4 printer"); |
| 1746 |
TEST_PRINTERINFO_STRING(q, s, needed, blob, 5, printername, 5, printername, "xx5-5 printer"); |
| 1747 |
|
| 1748 |
/* servername can be set but does not stick |
| 1749 |
TEST_PRINTERINFO_STRING(q, 2, servername, 0, servername, "xx2-0 servername"); |
| 1750 |
TEST_PRINTERINFO_STRING(q, 2, servername, 2, servername, "xx2-2 servername"); |
| 1751 |
TEST_PRINTERINFO_STRING(q, 2, servername, 4, servername, "xx2-4 servername"); |
| 1752 |
*/ |
| 1753 |
|
| 1754 |
/* passing an invalid port will result in WERR_UNKNOWN_PORT */ |
| 1755 |
TEST_PRINTERINFO_STRING_EXP_ERR(q, s, needed, blob, 2, portname, 2, portname, "xx2-2 portname", WERR_UNKNOWN_PORT); |
| 1756 |
TEST_PRINTERINFO_STRING_EXP_ERR(q, s, needed, blob, 2, portname, 5, portname, "xx2-5 portname", WERR_UNKNOWN_PORT); |
| 1757 |
TEST_PRINTERINFO_STRING_EXP_ERR(q, s, needed, blob, 5, portname, 2, portname, "xx5-2 portname", WERR_UNKNOWN_PORT); |
| 1758 |
TEST_PRINTERINFO_STRING_EXP_ERR(q, s, needed, blob, 5, portname, 5, portname, "xx5-5 portname", WERR_UNKNOWN_PORT); |
| 1759 |
|
| 1760 |
TEST_PRINTERINFO_STRING(q, s, needed, blob, 2, sharename, 2, sharename, "xx2-2 sharename"); |
| 1761 |
/* passing an invalid driver will result in WERR_UNKNOWN_PRINTER_DRIVER */ |
| 1762 |
TEST_PRINTERINFO_STRING_EXP_ERR(q, s, needed, blob, 2, drivername, 2, drivername, "xx2-2 drivername", WERR_UNKNOWN_PRINTER_DRIVER); |
| 1763 |
TEST_PRINTERINFO_STRING(q, s, needed, blob, 2, location, 2, location, "xx2-2 location"); |
| 1764 |
/* passing an invalid sepfile will result in WERR_INVALID_SEPARATOR_FILE */ |
| 1765 |
TEST_PRINTERINFO_STRING_EXP_ERR(q, s, needed, blob, 2, sepfile, 2, sepfile, "xx2-2 sepfile", WERR_INVALID_SEPARATOR_FILE); |
| 1766 |
/* passing an invalid printprocessor will result in WERR_UNKNOWN_PRINTPROCESSOR */ |
| 1767 |
TEST_PRINTERINFO_STRING_EXP_ERR(q, s, needed, blob, 2, printprocessor, 2, printprocessor, "xx2-2 printprocessor", WERR_UNKNOWN_PRINTPROCESSOR); |
| 1768 |
TEST_PRINTERINFO_STRING(q, s, needed, blob, 2, datatype, 2, datatype, "xx2-2 datatype"); |
| 1769 |
TEST_PRINTERINFO_STRING(q, s, needed, blob, 2, parameters, 2, parameters, "xx2-2 parameters"); |
| 1770 |
|
| 1771 |
for (i=0; i < ARRAY_SIZE(attribute_list); i++) { |
| 1772 |
/* TEST_PRINTERINFO_INT_EXP(q, s, needed, blob, 2, attributes, 1, flags, |
| 1773 |
attribute_list[i], |
| 1774 |
(attribute_list[i] | default_attribute) |
| 1775 |
); */ |
| 1776 |
TEST_PRINTERINFO_INT_EXP(q, s, needed, blob, 2, attributes, 2, attributes, |
| 1777 |
attribute_list[i], |
| 1778 |
(attribute_list[i] | default_attribute) |
| 1779 |
); |
| 1780 |
TEST_PRINTERINFO_INT_EXP(q, s, needed, blob, 2, attributes, 4, attributes, |
| 1781 |
attribute_list[i], |
| 1782 |
(attribute_list[i] | default_attribute) |
| 1783 |
); |
| 1784 |
TEST_PRINTERINFO_INT_EXP(q, s, needed, blob, 2, attributes, 5, attributes, |
| 1785 |
attribute_list[i], |
| 1786 |
(attribute_list[i] | default_attribute) |
| 1787 |
); |
| 1788 |
/* TEST_PRINTERINFO_INT_EXP(q, s, needed, blob, 4, attributes, 1, flags, |
| 1789 |
attribute_list[i], |
| 1790 |
(attribute_list[i] | default_attribute) |
| 1791 |
); */ |
| 1792 |
TEST_PRINTERINFO_INT_EXP(q, s, needed, blob, 4, attributes, 2, attributes, |
| 1793 |
attribute_list[i], |
| 1794 |
(attribute_list[i] | default_attribute) |
| 1795 |
); |
| 1796 |
TEST_PRINTERINFO_INT_EXP(q, s, needed, blob, 4, attributes, 4, attributes, |
| 1797 |
attribute_list[i], |
| 1798 |
(attribute_list[i] | default_attribute) |
| 1799 |
); |
| 1800 |
TEST_PRINTERINFO_INT_EXP(q, s, needed, blob, 4, attributes, 5, attributes, |
| 1801 |
attribute_list[i], |
| 1802 |
(attribute_list[i] | default_attribute) |
| 1803 |
); |
| 1804 |
/* TEST_PRINTERINFO_INT_EXP(q, s, needed, blob, 5, attributes, 1, flags, |
| 1805 |
attribute_list[i], |
| 1806 |
(attribute_list[i] | default_attribute) |
| 1807 |
); */ |
| 1808 |
TEST_PRINTERINFO_INT_EXP(q, s, needed, blob, 5, attributes, 2, attributes, |
| 1809 |
attribute_list[i], |
| 1810 |
(attribute_list[i] | default_attribute) |
| 1811 |
); |
| 1812 |
TEST_PRINTERINFO_INT_EXP(q, s, needed, blob, 5, attributes, 4, attributes, |
| 1813 |
attribute_list[i], |
| 1814 |
(attribute_list[i] | default_attribute) |
| 1815 |
); |
| 1816 |
TEST_PRINTERINFO_INT_EXP(q, s, needed, blob, 5, attributes, 5, attributes, |
| 1817 |
attribute_list[i], |
| 1818 |
(attribute_list[i] | default_attribute) |
| 1819 |
); |
| 1820 |
} |
| 1821 |
|
| 1822 |
for (i=0; i < ARRAY_SIZE(status_list); i++) { |
| 1823 |
/* level 2 sets do not stick |
| 1824 |
TEST_PRINTERINFO_INT(q, s, needed, blob, 2, status, 0, status, status_list[i]); |
| 1825 |
TEST_PRINTERINFO_INT(q, s, needed, blob, 2, status, 2, status, status_list[i]); |
| 1826 |
TEST_PRINTERINFO_INT(q, s, needed, blob, 2, status, 6, status, status_list[i]); */ |
| 1827 |
TEST_PRINTERINFO_INT(q, s, needed, blob, 6, status, 0, status, status_list[i]); |
| 1828 |
TEST_PRINTERINFO_INT(q, s, needed, blob, 6, status, 2, status, status_list[i]); |
| 1829 |
TEST_PRINTERINFO_INT(q, s, needed, blob, 6, status, 6, status, status_list[i]); |
| 1830 |
} |
| 1831 |
|
| 1832 |
/* priorities need to be between 0 and 99 |
| 1833 |
passing an invalid priority will result in WERR_INVALID_PRIORITY */ |
| 1834 |
TEST_PRINTERINFO_INT(q, s, needed, blob, 2, priority, 2, priority, 0); |
| 1835 |
TEST_PRINTERINFO_INT(q, s, needed, blob, 2, priority, 2, priority, 1); |
| 1836 |
TEST_PRINTERINFO_INT(q, s, needed, blob, 2, priority, 2, priority, 99); |
| 1837 |
/* TEST_PRINTERINFO_INT(q, s, needed, blob, 2, priority, 2, priority, 100); */ |
| 1838 |
TEST_PRINTERINFO_INT(q, s, needed, blob, 2, defaultpriority,2, defaultpriority, 0); |
| 1839 |
TEST_PRINTERINFO_INT(q, s, needed, blob, 2, defaultpriority,2, defaultpriority, 1); |
| 1840 |
TEST_PRINTERINFO_INT(q, s, needed, blob, 2, defaultpriority,2, defaultpriority, 99); |
| 1841 |
/* TEST_PRINTERINFO_INT(q, s, needed, blob, 2, defaultpriority,2, defaultpriority, 100); */ |
| 1842 |
|
| 1843 |
TEST_PRINTERINFO_INT(q, s, needed, blob, 2, starttime, 2, starttime, __LINE__); |
| 1844 |
TEST_PRINTERINFO_INT(q, s, needed, blob, 2, untiltime, 2, untiltime, __LINE__); |
| 1845 |
|
| 1846 |
/* does not stick |
| 1847 |
TEST_PRINTERINFO_INT(q, s, needed, blob, 2, cjobs, 2, cjobs, __LINE__); |
| 1848 |
TEST_PRINTERINFO_INT(q, s, needed, blob, 2, averageppm, 2, averageppm, __LINE__); */ |
| 1849 |
|
| 1850 |
/* does not stick |
| 1851 |
TEST_PRINTERINFO_INT(q, s, needed, blob, 5, device_not_selected_timeout, 5, device_not_selected_timeout, __LINE__); |
| 1852 |
TEST_PRINTERINFO_INT(q, s, needed, blob, 5, transmission_retry_timeout, 5, transmission_retry_timeout, __LINE__); */ |
| 1853 |
|
| 1854 |
/* FIXME: gd also test devmode and secdesc behavior */ |
| 1855 |
|
| 1856 |
{ |
| 1857 |
/* verify composition of level 1 description field */ |
| 1858 |
const char *description; |
| 1859 |
const char *tmp; |
| 1860 |
|
| 1861 |
q0.in.level = 1; |
| 1862 |
do { TESTGETCALL(GetPrinter, q0, needed, blob) } while (0); |
| 1863 |
|
| 1864 |
description = talloc_strdup(tctx, q0.out.info->info1.description); |
| 1865 |
|
| 1866 |
q0.in.level = 2; |
| 1867 |
do { TESTGETCALL(GetPrinter, q0, needed, blob) } while (0); |
| 1868 |
|
| 1869 |
tmp = talloc_asprintf(tctx, "%s,%s,%s", |
| 1870 |
q0.out.info->info2.printername, |
| 1871 |
q0.out.info->info2.drivername, |
| 1872 |
q0.out.info->info2.location); |
| 1873 |
|
| 1874 |
do { STRING_EQUAL(description, tmp, "description")} while (0); |
| 1875 |
} |
| 1876 |
|
| 1877 |
return ret; |
| 1878 |
} |
| 1879 |
|
| 1880 |
static bool test_security_descriptor_equal(struct torture_context *tctx, |
| 1881 |
const struct security_descriptor *sd1, |
| 1882 |
const struct security_descriptor *sd2) |
| 1883 |
{ |
| 1884 |
if (sd1 == sd2) { |
| 1885 |
return true; |
| 1886 |
} |
| 1887 |
|
| 1888 |
if (!sd1 || !sd2) { |
| 1889 |
torture_comment(tctx, "%s\n", __location__); |
| 1890 |
return false; |
| 1891 |
} |
| 1892 |
|
| 1893 |
torture_assert_int_equal(tctx, sd1->revision, sd2->revision, "revision mismatch"); |
| 1894 |
torture_assert_int_equal(tctx, sd1->type, sd2->type, "type mismatch"); |
| 1895 |
|
| 1896 |
torture_assert_sid_equal(tctx, sd1->owner_sid, sd2->owner_sid, "owner mismatch"); |
| 1897 |
torture_assert_sid_equal(tctx, sd1->group_sid, sd2->group_sid, "group mismatch"); |
| 1898 |
|
| 1899 |
if (!security_acl_equal(sd1->sacl, sd2->sacl)) { |
| 1900 |
torture_comment(tctx, "%s: sacl mismatch\n", __location__); |
| 1901 |
NDR_PRINT_DEBUG(security_acl, sd1->sacl); |
| 1902 |
NDR_PRINT_DEBUG(security_acl, sd2->sacl); |
| 1903 |
return false; |
| 1904 |
} |
| 1905 |
if (!security_acl_equal(sd1->dacl, sd2->dacl)) { |
| 1906 |
torture_comment(tctx, "%s: dacl mismatch\n", __location__); |
| 1907 |
NDR_PRINT_DEBUG(security_acl, sd1->dacl); |
| 1908 |
NDR_PRINT_DEBUG(security_acl, sd2->dacl); |
| 1909 |
return false; |
| 1910 |
} |
| 1911 |
|
| 1912 |
return true; |
| 1913 |
} |
| 1914 |
|
| 1915 |
static bool test_sd_set_level(struct torture_context *tctx, |
| 1916 |
struct dcerpc_binding_handle *b, |
| 1917 |
struct policy_handle *handle, |
| 1918 |
uint32_t level, |
| 1919 |
struct security_descriptor *sd) |
| 1920 |
{ |
| 1921 |
struct spoolss_SetPrinterInfoCtr info_ctr; |
| 1922 |
struct spoolss_DevmodeContainer devmode_ctr; |
| 1923 |
struct sec_desc_buf secdesc_ctr; |
| 1924 |
union spoolss_SetPrinterInfo sinfo; |
| 1925 |
union spoolss_PrinterInfo info; |
| 1926 |
struct spoolss_SetPrinterInfo3 info3; |
| 1927 |
|
| 1928 |
ZERO_STRUCT(devmode_ctr); |
| 1929 |
ZERO_STRUCT(secdesc_ctr); |
| 1930 |
|
| 1931 |
switch (level) { |
| 1932 |
case 2: { |
| 1933 |
torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, 2, &info), ""); |
| 1934 |
torture_assert(tctx, PrinterInfo_to_SetPrinterInfo(tctx, &info, 2, &sinfo), ""); |
| 1935 |
|
| 1936 |
info_ctr.level = 2; |
| 1937 |
info_ctr.info = sinfo; |
| 1938 |
|
| 1939 |
break; |
| 1940 |
} |
| 1941 |
case 3: { |
| 1942 |
|
| 1943 |
info3.sec_desc_ptr = 0; |
| 1944 |
|
| 1945 |
info_ctr.level = 3; |
| 1946 |
info_ctr.info.info3 = &info3; |
| 1947 |
|
| 1948 |
break; |
| 1949 |
} |
| 1950 |
default: |
| 1951 |
return false; |
| 1952 |
} |
| 1953 |
|
| 1954 |
secdesc_ctr.sd = sd; |
| 1955 |
|
| 1956 |
torture_assert(tctx, |
| 1957 |
test_SetPrinter(tctx, b, handle, &info_ctr, &devmode_ctr, &secdesc_ctr, 0), ""); |
| 1958 |
|
| 1959 |
return true; |
| 1960 |
} |
| 1961 |
|
| 1962 |
static bool test_PrinterInfo_SDs(struct torture_context *tctx, |
| 1963 |
struct dcerpc_binding_handle *b, |
| 1964 |
struct policy_handle *handle) |
| 1965 |
{ |
| 1966 |
union spoolss_PrinterInfo info; |
| 1967 |
struct security_descriptor *sd1, *sd2; |
| 1968 |
int i; |
| 1969 |
|
| 1970 |
/* just compare level 2 and level 3 */ |
| 1971 |
|
| 1972 |
torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, 2, &info), ""); |
| 1973 |
|
| 1974 |
sd1 = info.info2.secdesc; |
| 1975 |
|
| 1976 |
torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, 3, &info), ""); |
| 1977 |
|
| 1978 |
sd2 = info.info3.secdesc; |
| 1979 |
|
| 1980 |
torture_assert(tctx, test_security_descriptor_equal(tctx, sd1, sd2), |
| 1981 |
"SD level 2 != SD level 3"); |
| 1982 |
|
| 1983 |
|
| 1984 |
/* query level 2, set level 2, query level 2 */ |
| 1985 |
|
| 1986 |
torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, 2, &info), ""); |
| 1987 |
|
| 1988 |
sd1 = info.info2.secdesc; |
| 1989 |
|
| 1990 |
torture_assert(tctx, test_sd_set_level(tctx, b, handle, 2, sd1), ""); |
| 1991 |
|
| 1992 |
torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, 2, &info), ""); |
| 1993 |
|
| 1994 |
sd2 = info.info2.secdesc; |
| 1995 |
if (sd1->type & SEC_DESC_DACL_DEFAULTED) { |
| 1996 |
torture_comment(tctx, "removing SEC_DESC_DACL_DEFAULTED\n"); |
| 1997 |
sd1->type &= ~SEC_DESC_DACL_DEFAULTED; |
| 1998 |
} |
| 1999 |
|
| 2000 |
torture_assert(tctx, test_security_descriptor_equal(tctx, sd1, sd2), |
| 2001 |
"SD level 2 != SD level 2 after SD has been set via level 2"); |
| 2002 |
|
| 2003 |
|
| 2004 |
/* query level 2, set level 3, query level 2 */ |
| 2005 |
|
| 2006 |
torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, 2, &info), ""); |
| 2007 |
|
| 2008 |
sd1 = info.info2.secdesc; |
| 2009 |
|
| 2010 |
torture_assert(tctx, test_sd_set_level(tctx, b, handle, 3, sd1), ""); |
| 2011 |
|
| 2012 |
torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, 2, &info), ""); |
| 2013 |
|
| 2014 |
sd2 = info.info2.secdesc; |
| 2015 |
|
| 2016 |
torture_assert(tctx, test_security_descriptor_equal(tctx, sd1, sd2), |
| 2017 |
"SD level 2 != SD level 2 after SD has been set via level 3"); |
| 2018 |
|
| 2019 |
/* set modified sd level 3, query level 2 */ |
| 2020 |
|
| 2021 |
for (i=0; i < 93; i++) { |
| 2022 |
struct security_ace a = {}; |
| 2023 |
const char *sid_string = talloc_asprintf(tctx, "S-1-5-32-9999%i", i); |
| 2024 |
a.type = SEC_ACE_TYPE_ACCESS_ALLOWED; |
| 2025 |
a.flags = 0; |
| 2026 |
a.size = 0; /* autogenerated */ |
| 2027 |
a.access_mask = 0; |
| 2028 |
a.trustee = *dom_sid_parse_talloc(tctx, sid_string); |
| 2029 |
torture_assert_ntstatus_ok(tctx, security_descriptor_dacl_add(sd1, &a), ""); |
| 2030 |
} |
| 2031 |
|
| 2032 |
torture_assert(tctx, test_sd_set_level(tctx, b, handle, 3, sd1), ""); |
| 2033 |
|
| 2034 |
torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, 2, &info), ""); |
| 2035 |
sd2 = info.info2.secdesc; |
| 2036 |
|
| 2037 |
if (sd1->type & SEC_DESC_DACL_DEFAULTED) { |
| 2038 |
torture_comment(tctx, "removing SEC_DESC_DACL_DEFAULTED\n"); |
| 2039 |
sd1->type &= ~SEC_DESC_DACL_DEFAULTED; |
| 2040 |
} |
| 2041 |
|
| 2042 |
torture_assert(tctx, test_security_descriptor_equal(tctx, sd1, sd2), |
| 2043 |
"modified SD level 2 != SD level 2 after SD has been set via level 3"); |
| 2044 |
|
| 2045 |
|
| 2046 |
return true; |
| 2047 |
} |
| 2048 |
|
| 2049 |
/* |
| 2050 |
* wrapper call that saves original sd, runs tests, and restores sd |
| 2051 |
*/ |
| 2052 |
|
| 2053 |
static bool test_PrinterInfo_SD(struct torture_context *tctx, |
| 2054 |
struct dcerpc_binding_handle *b, |
| 2055 |
struct policy_handle *handle) |
| 2056 |
{ |
| 2057 |
union spoolss_PrinterInfo info; |
| 2058 |
struct security_descriptor *sd; |
| 2059 |
bool ret = true; |
| 2060 |
|
| 2061 |
torture_comment(tctx, "Testing Printer Security Descriptors\n"); |
| 2062 |
|
| 2063 |
/* save original sd */ |
| 2064 |
|
| 2065 |
torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, 2, &info), |
| 2066 |
"failed to get initial security descriptor"); |
| 2067 |
|
| 2068 |
sd = security_descriptor_copy(tctx, info.info2.secdesc); |
| 2069 |
|
| 2070 |
/* run tests */ |
| 2071 |
|
| 2072 |
ret = test_PrinterInfo_SDs(tctx, b, handle); |
| 2073 |
|
| 2074 |
/* restore original sd */ |
| 2075 |
|
| 2076 |
torture_assert(tctx, test_sd_set_level(tctx, b, handle, 3, sd), |
| 2077 |
"failed to restore initial security descriptor"); |
| 2078 |
|
| 2079 |
torture_comment(tctx, "Printer Security Descriptors test %s\n\n", |
| 2080 |
ret ? "succeeded" : "failed"); |
| 2081 |
|
| 2082 |
|
| 2083 |
return ret; |
| 2084 |
} |
| 2085 |
|
| 2086 |
static bool test_devmode_set_level(struct torture_context *tctx, |
| 2087 |
struct dcerpc_binding_handle *b, |
| 2088 |
struct policy_handle *handle, |
| 2089 |
uint32_t level, |
| 2090 |
struct spoolss_DeviceMode *devmode) |
| 2091 |
{ |
| 2092 |
struct spoolss_SetPrinterInfo8 info8; |
| 2093 |
struct spoolss_SetPrinterInfoCtr info_ctr; |
| 2094 |
struct spoolss_DevmodeContainer devmode_ctr; |
| 2095 |
struct sec_desc_buf secdesc_ctr; |
| 2096 |
union spoolss_SetPrinterInfo sinfo; |
| 2097 |
|
| 2098 |
ZERO_STRUCT(devmode_ctr); |
| 2099 |
ZERO_STRUCT(secdesc_ctr); |
| 2100 |
|
| 2101 |
switch (level) { |
| 2102 |
case 2: { |
| 2103 |
union spoolss_PrinterInfo info; |
| 2104 |
torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, 2, &info), ""); |
| 2105 |
torture_assert(tctx, PrinterInfo_to_SetPrinterInfo(tctx, &info, 2, &sinfo), ""); |
| 2106 |
|
| 2107 |
info_ctr.level = 2; |
| 2108 |
info_ctr.info = sinfo; |
| 2109 |
|
| 2110 |
break; |
| 2111 |
} |
| 2112 |
case 8: { |
| 2113 |
info8.devmode_ptr = 0; |
| 2114 |
|
| 2115 |
info_ctr.level = 8; |
| 2116 |
info_ctr.info.info8 = &info8; |
| 2117 |
|
| 2118 |
break; |
| 2119 |
} |
| 2120 |
default: |
| 2121 |
return false; |
| 2122 |
} |
| 2123 |
|
| 2124 |
devmode_ctr.devmode = devmode; |
| 2125 |
|
| 2126 |
torture_assert(tctx, |
| 2127 |
test_SetPrinter(tctx, b, handle, &info_ctr, &devmode_ctr, &secdesc_ctr, 0), ""); |
| 2128 |
|
| 2129 |
return true; |
| 2130 |
} |
| 2131 |
|
| 2132 |
|
| 2133 |
static bool test_devicemode_equal(struct torture_context *tctx, |
| 2134 |
const struct spoolss_DeviceMode *d1, |
| 2135 |
const struct spoolss_DeviceMode *d2) |
| 2136 |
{ |
| 2137 |
if (d1 == d2) { |
| 2138 |
return true; |
| 2139 |
} |
| 2140 |
|
| 2141 |
if (!d1 || !d2) { |
| 2142 |
torture_comment(tctx, "%s\n", __location__); |
| 2143 |
return false; |
| 2144 |
} |
| 2145 |
torture_assert_str_equal(tctx, d1->devicename, d2->devicename, "devicename mismatch"); |
| 2146 |
torture_assert_int_equal(tctx, d1->specversion, d2->specversion, "specversion mismatch"); |
| 2147 |
torture_assert_int_equal(tctx, d1->driverversion, d2->driverversion, "driverversion mismatch"); |
| 2148 |
torture_assert_int_equal(tctx, d1->size, d2->size, "size mismatch"); |
| 2149 |
torture_assert_int_equal(tctx, d1->__driverextra_length, d2->__driverextra_length, "__driverextra_length mismatch"); |
| 2150 |
torture_assert_int_equal(tctx, d1->fields, d2->fields, "fields mismatch"); |
| 2151 |
torture_assert_int_equal(tctx, d1->orientation, d2->orientation, "orientation mismatch"); |
| 2152 |
torture_assert_int_equal(tctx, d1->papersize, d2->papersize, "papersize mismatch"); |
| 2153 |
torture_assert_int_equal(tctx, d1->paperlength, d2->paperlength, "paperlength mismatch"); |
| 2154 |
torture_assert_int_equal(tctx, d1->paperwidth, d2->paperwidth, "paperwidth mismatch"); |
| 2155 |
torture_assert_int_equal(tctx, d1->scale, d2->scale, "scale mismatch"); |
| 2156 |
torture_assert_int_equal(tctx, d1->copies, d2->copies, "copies mismatch"); |
| 2157 |
torture_assert_int_equal(tctx, d1->defaultsource, d2->defaultsource, "defaultsource mismatch"); |
| 2158 |
torture_assert_int_equal(tctx, d1->printquality, d2->printquality, "printquality mismatch"); |
| 2159 |
torture_assert_int_equal(tctx, d1->color, d2->color, "color mismatch"); |
| 2160 |
torture_assert_int_equal(tctx, d1->duplex, d2->duplex, "duplex mismatch"); |
| 2161 |
torture_assert_int_equal(tctx, d1->yresolution, d2->yresolution, "yresolution mismatch"); |
| 2162 |
torture_assert_int_equal(tctx, d1->ttoption, d2->ttoption, "ttoption mismatch"); |
| 2163 |
torture_assert_int_equal(tctx, d1->collate, d2->collate, "collate mismatch"); |
| 2164 |
torture_assert_str_equal(tctx, d1->formname, d2->formname, "formname mismatch"); |
| 2165 |
torture_assert_int_equal(tctx, d1->logpixels, d2->logpixels, "logpixels mismatch"); |
| 2166 |
torture_assert_int_equal(tctx, d1->bitsperpel, d2->bitsperpel, "bitsperpel mismatch"); |
| 2167 |
torture_assert_int_equal(tctx, d1->pelswidth, d2->pelswidth, "pelswidth mismatch"); |
| 2168 |
torture_assert_int_equal(tctx, d1->pelsheight, d2->pelsheight, "pelsheight mismatch"); |
| 2169 |
torture_assert_int_equal(tctx, d1->displayflags, d2->displayflags, "displayflags mismatch"); |
| 2170 |
torture_assert_int_equal(tctx, d1->displayfrequency, d2->displayfrequency, "displayfrequency mismatch"); |
| 2171 |
torture_assert_int_equal(tctx, d1->icmmethod, d2->icmmethod, "icmmethod mismatch"); |
| 2172 |
torture_assert_int_equal(tctx, d1->icmintent, d2->icmintent, "icmintent mismatch"); |
| 2173 |
torture_assert_int_equal(tctx, d1->mediatype, d2->mediatype, "mediatype mismatch"); |
| 2174 |
torture_assert_int_equal(tctx, d1->dithertype, d2->dithertype, "dithertype mismatch"); |
| 2175 |
torture_assert_int_equal(tctx, d1->reserved1, d2->reserved1, "reserved1 mismatch"); |
| 2176 |
torture_assert_int_equal(tctx, d1->reserved2, d2->reserved2, "reserved2 mismatch"); |
| 2177 |
torture_assert_int_equal(tctx, d1->panningwidth, d2->panningwidth, "panningwidth mismatch"); |
| 2178 |
torture_assert_int_equal(tctx, d1->panningheight, d2->panningheight, "panningheight mismatch"); |
| 2179 |
torture_assert_data_blob_equal(tctx, d1->driverextra_data, d2->driverextra_data, "driverextra_data mismatch"); |
| 2180 |
|
| 2181 |
return true; |
| 2182 |
} |
| 2183 |
|
| 2184 |
static bool test_devicemode_full(struct torture_context *tctx, |
| 2185 |
struct dcerpc_binding_handle *b, |
| 2186 |
struct policy_handle *handle) |
| 2187 |
{ |
| 2188 |
struct spoolss_SetPrinter s; |
| 2189 |
struct spoolss_GetPrinter q; |
| 2190 |
struct spoolss_SetPrinterInfoCtr info_ctr; |
| 2191 |
struct spoolss_SetPrinterInfo8 info8; |
| 2192 |
union spoolss_PrinterInfo info; |
| 2193 |
struct spoolss_DevmodeContainer devmode_ctr; |
| 2194 |
struct sec_desc_buf secdesc_ctr; |
| 2195 |
uint32_t needed = 0; |
| 2196 |
DATA_BLOB blob = data_blob_null; |
| 2197 |
bool ret = true; |
| 2198 |
NTSTATUS status; |
| 2199 |
|
| 2200 |
#define TEST_DEVMODE_INT_EXP_RESULT(q, s, needed, blob, lvl1, field1, lvl2, field2, value, exp_value, expected_result) do { \ |
| 2201 |
torture_comment(tctx, "field test %d/%s vs %d/%s\n", lvl1, #field1, lvl2, #field2); \ |
| 2202 |
q.in.level = lvl1; \ |
| 2203 |
TESTGETCALL(GetPrinter, q, needed, blob) \ |
| 2204 |
info_ctr.level = lvl1; \ |
| 2205 |
if (lvl1 == 2) {\ |
| 2206 |
void *p = (void *)&q.out.info->info ## lvl1; \ |
| 2207 |
info_ctr.info.info ## lvl1 = (struct spoolss_SetPrinterInfo ## lvl1 *)p; \ |
| 2208 |
} else if (lvl1 == 8) {\ |
| 2209 |
info_ctr.info.info ## lvl1 = &info8; \ |
| 2210 |
}\ |
| 2211 |
devmode_ctr.devmode = q.out.info->info ## lvl1.devmode; \ |
| 2212 |
devmode_ctr.devmode->field1 = value; \ |
| 2213 |
TESTSETCALL_EXP(SetPrinter, s, expected_result) \ |
| 2214 |
if (W_ERROR_IS_OK(expected_result)) { \ |
| 2215 |
TESTGETCALL(GetPrinter, q, needed, blob) \ |
| 2216 |
INT_EQUAL(q.out.info->info ## lvl1.devmode->field1, exp_value, field1); \ |
| 2217 |
q.in.level = lvl2; \ |
| 2218 |
TESTGETCALL(GetPrinter, q, needed, blob) \ |
| 2219 |
INT_EQUAL(q.out.info->info ## lvl2.devmode->field2, exp_value, field1); \ |
| 2220 |
}\ |
| 2221 |
} while (0) |
| 2222 |
|
| 2223 |
#define TEST_DEVMODE_INT_EXP(q, s, needed, blob, lvl1, field1, lvl2, field2, value, expected_result) do { \ |
| 2224 |
TEST_DEVMODE_INT_EXP_RESULT(q, s, needed, blob, lvl1, field1, lvl2, field2, value, value, expected_result); \ |
| 2225 |
} while (0) |
| 2226 |
|
| 2227 |
#define TEST_DEVMODE_INT(q, s, needed, blob, lvl1, field1, lvl2, field2, value) do { \ |
| 2228 |
TEST_DEVMODE_INT_EXP_RESULT(q, s, needed, blob, lvl1, field1, lvl2, field2, value, value, WERR_OK); \ |
| 2229 |
} while (0) |
| 2230 |
|
| 2231 |
ZERO_STRUCT(devmode_ctr); |
| 2232 |
ZERO_STRUCT(secdesc_ctr); |
| 2233 |
ZERO_STRUCT(info8); |
| 2234 |
|
| 2235 |
s.in.handle = handle; |
| 2236 |
s.in.command = 0; |
| 2237 |
s.in.info_ctr = &info_ctr; |
| 2238 |
s.in.devmode_ctr = &devmode_ctr; |
| 2239 |
s.in.secdesc_ctr = &secdesc_ctr; |
| 2240 |
|
| 2241 |
q.in.handle = handle; |
| 2242 |
q.out.info = &info; |
| 2243 |
|
| 2244 |
#if 0 |
| 2245 |
const char *devicename;/* [charset(UTF16)] */ |
| 2246 |
enum spoolss_DeviceModeSpecVersion specversion; |
| 2247 |
uint16_t driverversion; |
| 2248 |
uint16_t __driverextra_length;/* [value(r->driverextra_data.length)] */ |
| 2249 |
uint32_t fields; |
| 2250 |
#endif |
| 2251 |
TEST_DEVMODE_INT_EXP(q, s, needed, blob, 8, size, 8, size, __LINE__, WERR_INVALID_PARAMETER); |
| 2252 |
TEST_DEVMODE_INT_EXP(q, s, needed, blob, 8, size, 8, size, 0, WERR_INVALID_PARAMETER); |
| 2253 |
TEST_DEVMODE_INT_EXP(q, s, needed, blob, 8, size, 8, size, 0xffff, WERR_INVALID_PARAMETER); |
| 2254 |
TEST_DEVMODE_INT_EXP(q, s, needed, blob, 8, size, 8, size, ndr_size_spoolss_DeviceMode(devmode_ctr.devmode, 0), (devmode_ctr.devmode->__driverextra_length > 0 ) ? WERR_INVALID_PARAMETER : WERR_OK); |
| 2255 |
TEST_DEVMODE_INT(q, s, needed, blob, 8, size, 8, size, ndr_size_spoolss_DeviceMode(devmode_ctr.devmode, 0) - devmode_ctr.devmode->__driverextra_length); |
| 2256 |
|
| 2257 |
devmode_ctr.devmode->driverextra_data = data_blob_string_const("foobar"); |
| 2258 |
torture_assert(tctx, |
| 2259 |
test_devmode_set_level(tctx, b, handle, 8, devmode_ctr.devmode), |
| 2260 |
"failed to set devmode"); |
| 2261 |
|
| 2262 |
TEST_DEVMODE_INT_EXP(q, s, needed, blob, 8, size, 8, size, ndr_size_spoolss_DeviceMode(devmode_ctr.devmode, 0), (devmode_ctr.devmode->__driverextra_length > 0 ) ? WERR_INVALID_PARAMETER : WERR_OK); |
| 2263 |
TEST_DEVMODE_INT(q, s, needed, blob, 8, size, 8, size, ndr_size_spoolss_DeviceMode(devmode_ctr.devmode, 0) - devmode_ctr.devmode->__driverextra_length); |
| 2264 |
|
| 2265 |
TEST_DEVMODE_INT(q, s, needed, blob, 8, orientation, 8, orientation, __LINE__); |
| 2266 |
TEST_DEVMODE_INT(q, s, needed, blob, 8, papersize, 8, papersize, __LINE__); |
| 2267 |
TEST_DEVMODE_INT(q, s, needed, blob, 8, paperlength, 8, paperlength, __LINE__); |
| 2268 |
TEST_DEVMODE_INT(q, s, needed, blob, 8, paperwidth, 8, paperwidth, __LINE__); |
| 2269 |
TEST_DEVMODE_INT(q, s, needed, blob, 8, scale, 8, scale, __LINE__); |
| 2270 |
TEST_DEVMODE_INT(q, s, needed, blob, 8, copies, 8, copies, __LINE__); |
| 2271 |
TEST_DEVMODE_INT(q, s, needed, blob, 8, defaultsource, 8, defaultsource, __LINE__); |
| 2272 |
TEST_DEVMODE_INT(q, s, needed, blob, 8, printquality, 8, printquality, __LINE__); |
| 2273 |
TEST_DEVMODE_INT(q, s, needed, blob, 8, color, 8, color, __LINE__); |
| 2274 |
TEST_DEVMODE_INT(q, s, needed, blob, 8, duplex, 8, duplex, __LINE__); |
| 2275 |
TEST_DEVMODE_INT(q, s, needed, blob, 8, yresolution, 8, yresolution, __LINE__); |
| 2276 |
TEST_DEVMODE_INT(q, s, needed, blob, 8, ttoption, 8, ttoption, __LINE__); |
| 2277 |
TEST_DEVMODE_INT(q, s, needed, blob, 8, collate, 8, collate, __LINE__); |
| 2278 |
#if 0 |
| 2279 |
const char *formname;/* [charset(UTF16)] */ |
| 2280 |
#endif |
| 2281 |
TEST_DEVMODE_INT(q, s, needed, blob, 8, logpixels, 8, logpixels, __LINE__); |
| 2282 |
TEST_DEVMODE_INT(q, s, needed, blob, 8, bitsperpel, 8, bitsperpel, __LINE__); |
| 2283 |
TEST_DEVMODE_INT(q, s, needed, blob, 8, pelswidth, 8, pelswidth, __LINE__); |
| 2284 |
TEST_DEVMODE_INT(q, s, needed, blob, 8, pelsheight, 8, pelsheight, __LINE__); |
| 2285 |
TEST_DEVMODE_INT(q, s, needed, blob, 8, displayflags, 8, displayflags, __LINE__); |
| 2286 |
TEST_DEVMODE_INT(q, s, needed, blob, 8, displayfrequency, 8, displayfrequency, __LINE__); |
| 2287 |
TEST_DEVMODE_INT(q, s, needed, blob, 8, icmmethod, 8, icmmethod, __LINE__); |
| 2288 |
TEST_DEVMODE_INT(q, s, needed, blob, 8, icmintent, 8, icmintent, __LINE__); |
| 2289 |
TEST_DEVMODE_INT(q, s, needed, blob, 8, mediatype, 8, mediatype, __LINE__); |
| 2290 |
TEST_DEVMODE_INT(q, s, needed, blob, 8, dithertype, 8, dithertype, __LINE__); |
| 2291 |
TEST_DEVMODE_INT(q, s, needed, blob, 8, reserved1, 8, reserved1, __LINE__); |
| 2292 |
TEST_DEVMODE_INT(q, s, needed, blob, 8, reserved2, 8, reserved2, __LINE__); |
| 2293 |
TEST_DEVMODE_INT(q, s, needed, blob, 8, panningwidth, 8, panningwidth, __LINE__); |
| 2294 |
TEST_DEVMODE_INT(q, s, needed, blob, 8, panningheight, 8, panningheight, __LINE__); |
| 2295 |
|
| 2296 |
return ret; |
| 2297 |
} |
| 2298 |
|
| 2299 |
static bool call_OpenPrinterEx(struct torture_context *tctx, |
| 2300 |
struct dcerpc_pipe *p, |
| 2301 |
const char *name, |
| 2302 |
struct spoolss_DeviceMode *devmode, |
| 2303 |
struct policy_handle *handle); |
| 2304 |
|
| 2305 |
static bool test_PrinterInfo_DevModes(struct torture_context *tctx, |
| 2306 |
struct dcerpc_pipe *p, |
| 2307 |
struct policy_handle *handle, |
| 2308 |
const char *name) |
| 2309 |
{ |
| 2310 |
union spoolss_PrinterInfo info; |
| 2311 |
struct spoolss_DeviceMode *devmode; |
| 2312 |
struct spoolss_DeviceMode *devmode2; |
| 2313 |
struct policy_handle handle_devmode; |
| 2314 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 2315 |
|
| 2316 |
/* simply compare level8 and level2 devmode */ |
| 2317 |
|
| 2318 |
torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, 8, &info), ""); |
| 2319 |
|
| 2320 |
devmode = info.info8.devmode; |
| 2321 |
|
| 2322 |
if (devmode && devmode->size == 0) { |
| 2323 |
torture_fail(tctx, |
| 2324 |
"devmode of zero size!"); |
| 2325 |
} |
| 2326 |
|
| 2327 |
torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, 2, &info), ""); |
| 2328 |
|
| 2329 |
devmode2 = info.info2.devmode; |
| 2330 |
|
| 2331 |
if (devmode2 && devmode2->size == 0) { |
| 2332 |
torture_fail(tctx, |
| 2333 |
"devmode of zero size!"); |
| 2334 |
} |
| 2335 |
|
| 2336 |
torture_assert(tctx, test_devicemode_equal(tctx, devmode, devmode2), |
| 2337 |
"DM level 8 != DM level 2"); |
| 2338 |
|
| 2339 |
|
| 2340 |
/* set devicemode level 8 and see if it persists */ |
| 2341 |
|
| 2342 |
devmode->copies = 93; |
| 2343 |
devmode->formname = talloc_strdup(tctx, "Legal"); |
| 2344 |
|
| 2345 |
torture_assert(tctx, test_devmode_set_level(tctx, b, handle, 8, devmode), ""); |
| 2346 |
|
| 2347 |
torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, 8, &info), ""); |
| 2348 |
|
| 2349 |
devmode2 = info.info8.devmode; |
| 2350 |
|
| 2351 |
torture_assert(tctx, test_devicemode_equal(tctx, devmode, devmode2), |
| 2352 |
"modified DM level 8 != DM level 8 after DM has been set via level 8"); |
| 2353 |
|
| 2354 |
torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, 2, &info), ""); |
| 2355 |
|
| 2356 |
devmode2 = info.info2.devmode; |
| 2357 |
|
| 2358 |
torture_assert(tctx, test_devicemode_equal(tctx, devmode, devmode2), |
| 2359 |
"modified DM level 8 != DM level 2"); |
| 2360 |
|
| 2361 |
|
| 2362 |
/* set devicemode level 2 and see if it persists */ |
| 2363 |
|
| 2364 |
devmode->copies = 39; |
| 2365 |
devmode->formname = talloc_strdup(tctx, "Executive"); |
| 2366 |
|
| 2367 |
torture_assert(tctx, test_devmode_set_level(tctx, b, handle, 2, devmode), ""); |
| 2368 |
|
| 2369 |
torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, 8, &info), ""); |
| 2370 |
|
| 2371 |
devmode2 = info.info8.devmode; |
| 2372 |
|
| 2373 |
torture_assert(tctx, test_devicemode_equal(tctx, devmode, devmode2), |
| 2374 |
"modified DM level 8 != DM level 8 after DM has been set via level 2"); |
| 2375 |
|
| 2376 |
torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, 2, &info), ""); |
| 2377 |
|
| 2378 |
devmode2 = info.info2.devmode; |
| 2379 |
|
| 2380 |
torture_assert(tctx, test_devicemode_equal(tctx, devmode, devmode2), |
| 2381 |
"modified DM level 8 != DM level 2"); |
| 2382 |
|
| 2383 |
|
| 2384 |
/* check every single bit in public part of devicemode */ |
| 2385 |
|
| 2386 |
torture_assert(tctx, test_devicemode_full(tctx, b, handle), |
| 2387 |
"failed to set every single devicemode component"); |
| 2388 |
|
| 2389 |
|
| 2390 |
/* change formname upon open and see if it persists in getprinter calls */ |
| 2391 |
|
| 2392 |
devmode->formname = talloc_strdup(tctx, "A4"); |
| 2393 |
devmode->copies = 42; |
| 2394 |
|
| 2395 |
torture_assert(tctx, call_OpenPrinterEx(tctx, p, name, devmode, &handle_devmode), |
| 2396 |
"failed to open printer handle"); |
| 2397 |
|
| 2398 |
torture_assert(tctx, test_GetPrinter_level(tctx, b, &handle_devmode, 8, &info), ""); |
| 2399 |
|
| 2400 |
devmode2 = info.info8.devmode; |
| 2401 |
|
| 2402 |
if (strequal(devmode->devicename, devmode2->devicename)) { |
| 2403 |
torture_warning(tctx, "devicenames are the same\n"); |
| 2404 |
} else { |
| 2405 |
torture_comment(tctx, "devicename passed in for open: %s\n", devmode->devicename); |
| 2406 |
torture_comment(tctx, "devicename after level 8 get: %s\n", devmode2->devicename); |
| 2407 |
} |
| 2408 |
|
| 2409 |
if (strequal(devmode->formname, devmode2->formname)) { |
| 2410 |
torture_warning(tctx, "formname are the same\n"); |
| 2411 |
} else { |
| 2412 |
torture_comment(tctx, "formname passed in for open: %s\n", devmode->formname); |
| 2413 |
torture_comment(tctx, "formname after level 8 get: %s\n", devmode2->formname); |
| 2414 |
} |
| 2415 |
|
| 2416 |
if (devmode->copies == devmode2->copies) { |
| 2417 |
torture_warning(tctx, "copies are the same\n"); |
| 2418 |
} else { |
| 2419 |
torture_comment(tctx, "copies passed in for open: %d\n", devmode->copies); |
| 2420 |
torture_comment(tctx, "copies after level 8 get: %d\n", devmode2->copies); |
| 2421 |
} |
| 2422 |
|
| 2423 |
torture_assert(tctx, test_GetPrinter_level(tctx, b, &handle_devmode, 2, &info), ""); |
| 2424 |
|
| 2425 |
devmode2 = info.info2.devmode; |
| 2426 |
|
| 2427 |
if (strequal(devmode->devicename, devmode2->devicename)) { |
| 2428 |
torture_warning(tctx, "devicenames are the same\n"); |
| 2429 |
} else { |
| 2430 |
torture_comment(tctx, "devicename passed in for open: %s\n", devmode->devicename); |
| 2431 |
torture_comment(tctx, "devicename after level 2 get: %s\n", devmode2->devicename); |
| 2432 |
} |
| 2433 |
|
| 2434 |
if (strequal(devmode->formname, devmode2->formname)) { |
| 2435 |
torture_warning(tctx, "formname is the same\n"); |
| 2436 |
} else { |
| 2437 |
torture_comment(tctx, "formname passed in for open: %s\n", devmode->formname); |
| 2438 |
torture_comment(tctx, "formname after level 2 get: %s\n", devmode2->formname); |
| 2439 |
} |
| 2440 |
|
| 2441 |
if (devmode->copies == devmode2->copies) { |
| 2442 |
torture_warning(tctx, "copies are the same\n"); |
| 2443 |
} else { |
| 2444 |
torture_comment(tctx, "copies passed in for open: %d\n", devmode->copies); |
| 2445 |
torture_comment(tctx, "copies after level 2 get: %d\n", devmode2->copies); |
| 2446 |
} |
| 2447 |
|
| 2448 |
test_ClosePrinter(tctx, b, &handle_devmode); |
| 2449 |
|
| 2450 |
return true; |
| 2451 |
} |
| 2452 |
|
| 2453 |
/* |
| 2454 |
* wrapper call that saves original devmode, runs tests, and restores devmode |
| 2455 |
*/ |
| 2456 |
|
| 2457 |
static bool test_PrinterInfo_DevMode(struct torture_context *tctx, |
| 2458 |
struct dcerpc_pipe *p, |
| 2459 |
struct policy_handle *handle, |
| 2460 |
const char *name, |
| 2461 |
struct spoolss_DeviceMode *addprinter_devmode) |
| 2462 |
{ |
| 2463 |
union spoolss_PrinterInfo info; |
| 2464 |
struct spoolss_DeviceMode *devmode; |
| 2465 |
bool ret = true; |
| 2466 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 2467 |
|
| 2468 |
torture_comment(tctx, "Testing Printer Devicemodes\n"); |
| 2469 |
|
| 2470 |
/* save original devmode */ |
| 2471 |
|
| 2472 |
torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, 8, &info), |
| 2473 |
"failed to get initial global devicemode"); |
| 2474 |
|
| 2475 |
devmode = info.info8.devmode; |
| 2476 |
|
| 2477 |
if (devmode && devmode->size == 0) { |
| 2478 |
torture_fail(tctx, |
| 2479 |
"devmode of zero size!"); |
| 2480 |
} |
| 2481 |
|
| 2482 |
if (addprinter_devmode) { |
| 2483 |
if (!test_devicemode_equal(tctx, devmode, addprinter_devmode)) { |
| 2484 |
torture_warning(tctx, "current global DM is != DM provided in addprinter"); |
| 2485 |
} |
| 2486 |
} |
| 2487 |
|
| 2488 |
/* run tests */ |
| 2489 |
|
| 2490 |
ret = test_PrinterInfo_DevModes(tctx, p, handle, name); |
| 2491 |
|
| 2492 |
/* restore original devmode */ |
| 2493 |
|
| 2494 |
torture_assert(tctx, test_devmode_set_level(tctx, b, handle, 8, devmode), |
| 2495 |
"failed to restore initial global device mode"); |
| 2496 |
|
| 2497 |
torture_comment(tctx, "Printer Devicemodes test %s\n\n", |
| 2498 |
ret ? "succeeded" : "failed"); |
| 2499 |
|
| 2500 |
|
| 2501 |
return ret; |
| 2502 |
} |
| 2503 |
|
| 2504 |
bool test_ClosePrinter(struct torture_context *tctx, |
| 2505 |
struct dcerpc_binding_handle *b, |
| 2506 |
struct policy_handle *handle) |
| 2507 |
{ |
| 2508 |
NTSTATUS status; |
| 2509 |
struct spoolss_ClosePrinter r; |
| 2510 |
|
| 2511 |
r.in.handle = handle; |
| 2512 |
r.out.handle = handle; |
| 2513 |
|
| 2514 |
torture_comment(tctx, "Testing ClosePrinter\n"); |
| 2515 |
|
| 2516 |
status = dcerpc_spoolss_ClosePrinter_r(b, tctx, &r); |
| 2517 |
torture_assert_ntstatus_ok(tctx, status, "ClosePrinter failed"); |
| 2518 |
torture_assert_werr_ok(tctx, r.out.result, "ClosePrinter failed"); |
| 2519 |
|
| 2520 |
return true; |
| 2521 |
} |
| 2522 |
|
| 2523 |
static bool test_GetForm_args(struct torture_context *tctx, |
| 2524 |
struct dcerpc_binding_handle *b, |
| 2525 |
struct policy_handle *handle, |
| 2526 |
const char *form_name, |
| 2527 |
uint32_t level, |
| 2528 |
union spoolss_FormInfo *info_p) |
| 2529 |
{ |
| 2530 |
NTSTATUS status; |
| 2531 |
struct spoolss_GetForm r; |
| 2532 |
uint32_t needed; |
| 2533 |
|
| 2534 |
r.in.handle = handle; |
| 2535 |
r.in.form_name = form_name; |
| 2536 |
r.in.level = level; |
| 2537 |
r.in.buffer = NULL; |
| 2538 |
r.in.offered = 0; |
| 2539 |
r.out.needed = &needed; |
| 2540 |
|
| 2541 |
torture_comment(tctx, "Testing GetForm(%s) level %d\n", form_name, r.in.level); |
| 2542 |
|
| 2543 |
status = dcerpc_spoolss_GetForm_r(b, tctx, &r); |
| 2544 |
torture_assert_ntstatus_ok(tctx, status, "GetForm failed"); |
| 2545 |
|
| 2546 |
if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) { |
| 2547 |
DATA_BLOB blob = data_blob_talloc_zero(tctx, needed); |
| 2548 |
r.in.buffer = &blob; |
| 2549 |
r.in.offered = needed; |
| 2550 |
status = dcerpc_spoolss_GetForm_r(b, tctx, &r); |
| 2551 |
torture_assert_ntstatus_ok(tctx, status, "GetForm failed"); |
| 2552 |
|
| 2553 |
torture_assert_werr_ok(tctx, r.out.result, "GetForm failed"); |
| 2554 |
|
| 2555 |
torture_assert(tctx, r.out.info, "No form info returned"); |
| 2556 |
} |
| 2557 |
|
| 2558 |
torture_assert_werr_ok(tctx, r.out.result, "GetForm failed"); |
| 2559 |
|
| 2560 |
CHECK_NEEDED_SIZE_LEVEL(spoolss_FormInfo, r.out.info, r.in.level, needed, 4); |
| 2561 |
|
| 2562 |
if (info_p) { |
| 2563 |
*info_p = *r.out.info; |
| 2564 |
} |
| 2565 |
|
| 2566 |
return true; |
| 2567 |
} |
| 2568 |
|
| 2569 |
static bool test_GetForm(struct torture_context *tctx, |
| 2570 |
struct dcerpc_binding_handle *b, |
| 2571 |
struct policy_handle *handle, |
| 2572 |
const char *form_name, |
| 2573 |
uint32_t level) |
| 2574 |
{ |
| 2575 |
return test_GetForm_args(tctx, b, handle, form_name, level, NULL); |
| 2576 |
} |
| 2577 |
|
| 2578 |
static bool test_EnumForms(struct torture_context *tctx, |
| 2579 |
struct dcerpc_binding_handle *b, |
| 2580 |
struct policy_handle *handle, |
| 2581 |
bool print_server, |
| 2582 |
uint32_t level, |
| 2583 |
uint32_t *count_p, |
| 2584 |
union spoolss_FormInfo **info_p) |
| 2585 |
{ |
| 2586 |
struct spoolss_EnumForms r; |
| 2587 |
uint32_t needed; |
| 2588 |
uint32_t count; |
| 2589 |
union spoolss_FormInfo *info; |
| 2590 |
|
| 2591 |
r.in.handle = handle; |
| 2592 |
r.in.level = level; |
| 2593 |
r.in.buffer = NULL; |
| 2594 |
r.in.offered = 0; |
| 2595 |
r.out.needed = &needed; |
| 2596 |
r.out.count = &count; |
| 2597 |
r.out.info = &info; |
| 2598 |
|
| 2599 |
torture_comment(tctx, "Testing EnumForms level %d\n", r.in.level); |
| 2600 |
|
| 2601 |
torture_assert_ntstatus_ok(tctx, |
| 2602 |
dcerpc_spoolss_EnumForms_r(b, tctx, &r), |
| 2603 |
"EnumForms failed"); |
| 2604 |
|
| 2605 |
if ((r.in.level == 2) && (W_ERROR_EQUAL(r.out.result, WERR_INVALID_LEVEL))) { |
| 2606 |
torture_skip(tctx, "EnumForms level 2 not supported"); |
| 2607 |
} |
| 2608 |
|
| 2609 |
if (print_server && W_ERROR_EQUAL(r.out.result, WERR_INVALID_HANDLE)) { |
| 2610 |
torture_fail(tctx, "EnumForms on the PrintServer isn't supported by test server (NT4)"); |
| 2611 |
} |
| 2612 |
|
| 2613 |
if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) { |
| 2614 |
DATA_BLOB blob = data_blob_talloc_zero(tctx, needed); |
| 2615 |
r.in.buffer = &blob; |
| 2616 |
r.in.offered = needed; |
| 2617 |
|
| 2618 |
torture_assert_ntstatus_ok(tctx, |
| 2619 |
dcerpc_spoolss_EnumForms_r(b, tctx, &r), |
| 2620 |
"EnumForms failed"); |
| 2621 |
|
| 2622 |
torture_assert(tctx, info, "No forms returned"); |
| 2623 |
} |
| 2624 |
|
| 2625 |
torture_assert_werr_ok(tctx, r.out.result, "EnumForms failed"); |
| 2626 |
|
| 2627 |
CHECK_NEEDED_SIZE_ENUM_LEVEL(spoolss_EnumForms, info, r.in.level, count, needed, 4); |
| 2628 |
|
| 2629 |
if (info_p) { |
| 2630 |
*info_p = info; |
| 2631 |
} |
| 2632 |
if (count_p) { |
| 2633 |
*count_p = count; |
| 2634 |
} |
| 2635 |
|
| 2636 |
return true; |
| 2637 |
} |
| 2638 |
|
| 2639 |
static bool test_EnumForms_all(struct torture_context *tctx, |
| 2640 |
struct dcerpc_binding_handle *b, |
| 2641 |
struct policy_handle *handle, |
| 2642 |
bool print_server) |
| 2643 |
{ |
| 2644 |
uint32_t levels[] = { 1, 2 }; |
| 2645 |
int i, j; |
| 2646 |
|
| 2647 |
for (i=0; i<ARRAY_SIZE(levels); i++) { |
| 2648 |
|
| 2649 |
uint32_t count = 0; |
| 2650 |
union spoolss_FormInfo *info = NULL; |
| 2651 |
|
| 2652 |
torture_assert(tctx, |
| 2653 |
test_EnumForms(tctx, b, handle, print_server, levels[i], &count, &info), |
| 2654 |
"failed to enum forms"); |
| 2655 |
|
| 2656 |
for (j = 0; j < count; j++) { |
| 2657 |
if (!print_server) { |
| 2658 |
torture_assert(tctx, |
| 2659 |
test_GetForm(tctx, b, handle, info[j].info1.form_name, levels[i]), |
| 2660 |
"failed to get form"); |
| 2661 |
} |
| 2662 |
} |
| 2663 |
} |
| 2664 |
|
| 2665 |
return true; |
| 2666 |
} |
| 2667 |
|
| 2668 |
static bool test_EnumForms_find_one(struct torture_context *tctx, |
| 2669 |
struct dcerpc_binding_handle *b, |
| 2670 |
struct policy_handle *handle, |
| 2671 |
bool print_server, |
| 2672 |
const char *form_name) |
| 2673 |
{ |
| 2674 |
union spoolss_FormInfo *info = NULL; |
| 2675 |
uint32_t count = 0; |
| 2676 |
bool found = false; |
| 2677 |
int i; |
| 2678 |
|
| 2679 |
torture_assert(tctx, |
| 2680 |
test_EnumForms(tctx, b, handle, print_server, 1, &count, &info), |
| 2681 |
"failed to enumerate forms"); |
| 2682 |
|
| 2683 |
for (i=0; i<count; i++) { |
| 2684 |
if (strequal(form_name, info[i].info1.form_name)) { |
| 2685 |
found = true; |
| 2686 |
break; |
| 2687 |
} |
| 2688 |
} |
| 2689 |
|
| 2690 |
return found; |
| 2691 |
} |
| 2692 |
|
| 2693 |
static bool test_DeleteForm(struct torture_context *tctx, |
| 2694 |
struct dcerpc_binding_handle *b, |
| 2695 |
struct policy_handle *handle, |
| 2696 |
const char *form_name, |
| 2697 |
WERROR expected_result) |
| 2698 |
{ |
| 2699 |
struct spoolss_DeleteForm r; |
| 2700 |
|
| 2701 |
r.in.handle = handle; |
| 2702 |
r.in.form_name = form_name; |
| 2703 |
|
| 2704 |
torture_comment(tctx, "Testing DeleteForm(%s)\n", form_name); |
| 2705 |
|
| 2706 |
torture_assert_ntstatus_ok(tctx, |
| 2707 |
dcerpc_spoolss_DeleteForm_r(b, tctx, &r), |
| 2708 |
"DeleteForm failed"); |
| 2709 |
torture_assert_werr_equal(tctx, r.out.result, expected_result, |
| 2710 |
"DeleteForm gave unexpected result"); |
| 2711 |
if (W_ERROR_IS_OK(r.out.result)) { |
| 2712 |
torture_assert_ntstatus_ok(tctx, |
| 2713 |
dcerpc_spoolss_DeleteForm_r(b, tctx, &r), |
| 2714 |
"2nd DeleteForm failed"); |
| 2715 |
torture_assert_werr_equal(tctx, r.out.result, WERR_INVALID_FORM_NAME, |
| 2716 |
"2nd DeleteForm failed"); |
| 2717 |
} |
| 2718 |
|
| 2719 |
return true; |
| 2720 |
} |
| 2721 |
|
| 2722 |
static bool test_AddForm(struct torture_context *tctx, |
| 2723 |
struct dcerpc_binding_handle *b, |
| 2724 |
struct policy_handle *handle, |
| 2725 |
uint32_t level, |
| 2726 |
union spoolss_AddFormInfo *info, |
| 2727 |
WERROR expected_result) |
| 2728 |
{ |
| 2729 |
struct spoolss_AddForm r; |
| 2730 |
struct spoolss_AddFormInfoCtr info_ctr; |
| 2731 |
|
| 2732 |
info_ctr.level = level; |
| 2733 |
info_ctr.info = *info; |
| 2734 |
|
| 2735 |
if (level != 1) { |
| 2736 |
torture_skip(tctx, "only level 1 supported"); |
| 2737 |
} |
| 2738 |
|
| 2739 |
r.in.handle = handle; |
| 2740 |
r.in.info_ctr = &info_ctr; |
| 2741 |
|
| 2742 |
torture_comment(tctx, "Testing AddForm(%s) level %d, type %d\n", |
| 2743 |
r.in.info_ctr->info.info1->form_name, level, |
| 2744 |
r.in.info_ctr->info.info1->flags); |
| 2745 |
|
| 2746 |
torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_AddForm_r(b, tctx, &r), |
| 2747 |
"AddForm failed"); |
| 2748 |
torture_assert_werr_equal(tctx, r.out.result, expected_result, |
| 2749 |
"AddForm gave unexpected result"); |
| 2750 |
|
| 2751 |
torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_AddForm_r(b, tctx, &r), |
| 2752 |
"2nd AddForm failed"); |
| 2753 |
if (W_ERROR_EQUAL(expected_result, WERR_INVALID_PARAMETER)) { |
| 2754 |
torture_assert_werr_equal(tctx, r.out.result, WERR_INVALID_PARAMETER, |
| 2755 |
"2nd AddForm gave unexpected result"); |
| 2756 |
} else { |
| 2757 |
torture_assert_werr_equal(tctx, r.out.result, WERR_FILE_EXISTS, |
| 2758 |
"2nd AddForm gave unexpected result"); |
| 2759 |
} |
| 2760 |
|
| 2761 |
return true; |
| 2762 |
} |
| 2763 |
|
| 2764 |
static bool test_SetForm(struct torture_context *tctx, |
| 2765 |
struct dcerpc_binding_handle *b, |
| 2766 |
struct policy_handle *handle, |
| 2767 |
const char *form_name, |
| 2768 |
uint32_t level, |
| 2769 |
union spoolss_AddFormInfo *info) |
| 2770 |
{ |
| 2771 |
struct spoolss_SetForm r; |
| 2772 |
struct spoolss_AddFormInfoCtr info_ctr; |
| 2773 |
|
| 2774 |
info_ctr.level = level; |
| 2775 |
info_ctr.info = *info; |
| 2776 |
|
| 2777 |
r.in.handle = handle; |
| 2778 |
r.in.form_name = form_name; |
| 2779 |
r.in.info_ctr = &info_ctr; |
| 2780 |
|
| 2781 |
torture_comment(tctx, "Testing SetForm(%s) level %d\n", |
| 2782 |
form_name, level); |
| 2783 |
|
| 2784 |
torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_SetForm_r(b, tctx, &r), |
| 2785 |
"SetForm failed"); |
| 2786 |
|
| 2787 |
torture_assert_werr_ok(tctx, r.out.result, |
| 2788 |
"SetForm failed"); |
| 2789 |
|
| 2790 |
return true; |
| 2791 |
} |
| 2792 |
|
| 2793 |
static bool test_GetForm_winreg(struct torture_context *tctx, |
| 2794 |
struct dcerpc_binding_handle *b, |
| 2795 |
struct policy_handle *handle, |
| 2796 |
const char *key_name, |
| 2797 |
const char *form_name, |
| 2798 |
enum winreg_Type *w_type, |
| 2799 |
uint32_t *w_size, |
| 2800 |
uint32_t *w_length, |
| 2801 |
uint8_t **w_data); |
| 2802 |
|
| 2803 |
static bool test_Forms_args(struct torture_context *tctx, |
| 2804 |
struct dcerpc_binding_handle *b, |
| 2805 |
struct policy_handle *handle, |
| 2806 |
bool print_server, |
| 2807 |
const char *printer_name, |
| 2808 |
struct dcerpc_binding_handle *winreg_handle, |
| 2809 |
struct policy_handle *hive_handle, |
| 2810 |
const char *form_name, |
| 2811 |
struct spoolss_AddFormInfo1 *info1, |
| 2812 |
WERROR expected_add_result, |
| 2813 |
WERROR expected_delete_result) |
| 2814 |
{ |
| 2815 |
union spoolss_FormInfo info; |
| 2816 |
union spoolss_AddFormInfo add_info; |
| 2817 |
|
| 2818 |
enum winreg_Type w_type; |
| 2819 |
uint32_t w_size; |
| 2820 |
uint32_t w_length; |
| 2821 |
uint8_t *w_data; |
| 2822 |
|
| 2823 |
add_info.info1 = info1; |
| 2824 |
|
| 2825 |
torture_assert(tctx, |
| 2826 |
test_AddForm(tctx, b, handle, 1, &add_info, expected_add_result), |
| 2827 |
"failed to add form"); |
| 2828 |
|
| 2829 |
if (winreg_handle && hive_handle && W_ERROR_IS_OK(expected_add_result)) { |
| 2830 |
|
| 2831 |
struct spoolss_FormInfo1 i1; |
| 2832 |
|
| 2833 |
torture_assert(tctx, |
| 2834 |
test_GetForm_winreg(tctx, winreg_handle, hive_handle, TOP_LEVEL_CONTROL_FORMS_KEY, form_name, &w_type, &w_size, &w_length, &w_data), |
| 2835 |
"failed to get form via winreg"); |
| 2836 |
|
| 2837 |
i1.size.width = IVAL(w_data, 0); |
| 2838 |
i1.size.height = IVAL(w_data, 4); |
| 2839 |
i1.area.left = IVAL(w_data, 8); |
| 2840 |
i1.area.top = IVAL(w_data, 12); |
| 2841 |
i1.area.right = IVAL(w_data, 16); |
| 2842 |
i1.area.bottom = IVAL(w_data, 20); |
| 2843 |
/* skip index here */ |
| 2844 |
i1.flags = IVAL(w_data, 28); |
| 2845 |
|
| 2846 |
torture_assert_int_equal(tctx, w_type, REG_BINARY, "unexpected type"); |
| 2847 |
torture_assert_int_equal(tctx, w_size, 0x20, "unexpected size"); |
| 2848 |
torture_assert_int_equal(tctx, w_length, 0x20, "unexpected length"); |
| 2849 |
torture_assert_int_equal(tctx, i1.size.width, add_info.info1->size.width, "width mismatch"); |
| 2850 |
torture_assert_int_equal(tctx, i1.size.height, add_info.info1->size.height, "height mismatch"); |
| 2851 |
torture_assert_int_equal(tctx, i1.area.left, add_info.info1->area.left, "left mismatch"); |
| 2852 |
torture_assert_int_equal(tctx, i1.area.top, add_info.info1->area.top, "top mismatch"); |
| 2853 |
torture_assert_int_equal(tctx, i1.area.right, add_info.info1->area.right, "right mismatch"); |
| 2854 |
torture_assert_int_equal(tctx, i1.area.bottom, add_info.info1->area.bottom, "bottom mismatch"); |
| 2855 |
torture_assert_int_equal(tctx, i1.flags, add_info.info1->flags, "flags mismatch"); |
| 2856 |
} |
| 2857 |
|
| 2858 |
if (!print_server && W_ERROR_IS_OK(expected_add_result)) { |
| 2859 |
torture_assert(tctx, |
| 2860 |
test_GetForm_args(tctx, b, handle, form_name, 1, &info), |
| 2861 |
"failed to get added form"); |
| 2862 |
|
| 2863 |
torture_assert_int_equal(tctx, info.info1.size.width, add_info.info1->size.width, "width mismatch"); |
| 2864 |
torture_assert_int_equal(tctx, info.info1.size.height, add_info.info1->size.height, "height mismatch"); |
| 2865 |
torture_assert_int_equal(tctx, info.info1.area.left, add_info.info1->area.left, "left mismatch"); |
| 2866 |
torture_assert_int_equal(tctx, info.info1.area.top, add_info.info1->area.top, "top mismatch"); |
| 2867 |
torture_assert_int_equal(tctx, info.info1.area.right, add_info.info1->area.right, "right mismatch"); |
| 2868 |
torture_assert_int_equal(tctx, info.info1.area.bottom, add_info.info1->area.bottom, "bottom mismatch"); |
| 2869 |
torture_assert_int_equal(tctx, info.info1.flags, add_info.info1->flags, "flags mismatch"); |
| 2870 |
|
| 2871 |
if (winreg_handle && hive_handle) { |
| 2872 |
|
| 2873 |
struct spoolss_FormInfo1 i1; |
| 2874 |
|
| 2875 |
i1.size.width = IVAL(w_data, 0); |
| 2876 |
i1.size.height = IVAL(w_data, 4); |
| 2877 |
i1.area.left = IVAL(w_data, 8); |
| 2878 |
i1.area.top = IVAL(w_data, 12); |
| 2879 |
i1.area.right = IVAL(w_data, 16); |
| 2880 |
i1.area.bottom = IVAL(w_data, 20); |
| 2881 |
/* skip index here */ |
| 2882 |
i1.flags = IVAL(w_data, 28); |
| 2883 |
|
| 2884 |
torture_assert_int_equal(tctx, i1.size.width, info.info1.size.width, "width mismatch"); |
| 2885 |
torture_assert_int_equal(tctx, i1.size.height, info.info1.size.height, "height mismatch"); |
| 2886 |
torture_assert_int_equal(tctx, i1.area.left, info.info1.area.left, "left mismatch"); |
| 2887 |
torture_assert_int_equal(tctx, i1.area.top, info.info1.area.top, "top mismatch"); |
| 2888 |
torture_assert_int_equal(tctx, i1.area.right, info.info1.area.right, "right mismatch"); |
| 2889 |
torture_assert_int_equal(tctx, i1.area.bottom, info.info1.area.bottom, "bottom mismatch"); |
| 2890 |
torture_assert_int_equal(tctx, i1.flags, info.info1.flags, "flags mismatch"); |
| 2891 |
} |
| 2892 |
|
| 2893 |
add_info.info1->size.width = 1234; |
| 2894 |
|
| 2895 |
torture_assert(tctx, |
| 2896 |
test_SetForm(tctx, b, handle, form_name, 1, &add_info), |
| 2897 |
"failed to set form"); |
| 2898 |
torture_assert(tctx, |
| 2899 |
test_GetForm_args(tctx, b, handle, form_name, 1, &info), |
| 2900 |
"failed to get set form"); |
| 2901 |
|
| 2902 |
torture_assert_int_equal(tctx, info.info1.size.width, add_info.info1->size.width, "width mismatch"); |
| 2903 |
} |
| 2904 |
|
| 2905 |
if (!W_ERROR_EQUAL(expected_add_result, WERR_INVALID_PARAMETER)) { |
| 2906 |
torture_assert(tctx, |
| 2907 |
test_EnumForms_find_one(tctx, b, handle, print_server, form_name), |
| 2908 |
"Newly added form not found in enum call"); |
| 2909 |
} |
| 2910 |
|
| 2911 |
torture_assert(tctx, |
| 2912 |
test_DeleteForm(tctx, b, handle, form_name, expected_delete_result), |
| 2913 |
"failed to delete form"); |
| 2914 |
|
| 2915 |
return true; |
| 2916 |
} |
| 2917 |
|
| 2918 |
static bool test_Forms(struct torture_context *tctx, |
| 2919 |
struct dcerpc_binding_handle *b, |
| 2920 |
struct policy_handle *handle, |
| 2921 |
bool print_server, |
| 2922 |
const char *printer_name, |
| 2923 |
struct dcerpc_binding_handle *winreg_handle, |
| 2924 |
struct policy_handle *hive_handle) |
| 2925 |
{ |
| 2926 |
const struct spoolss_FormSize size = { |
| 2927 |
.width = 50, |
| 2928 |
.height = 25 |
| 2929 |
}; |
| 2930 |
const struct spoolss_FormArea area = { |
| 2931 |
.left = 5, |
| 2932 |
.top = 10, |
| 2933 |
.right = 45, |
| 2934 |
.bottom = 15 |
| 2935 |
}; |
| 2936 |
int i; |
| 2937 |
|
| 2938 |
struct { |
| 2939 |
struct spoolss_AddFormInfo1 info1; |
| 2940 |
WERROR expected_add_result; |
| 2941 |
WERROR expected_delete_result; |
| 2942 |
} forms[] = { |
| 2943 |
{ |
| 2944 |
.info1 = { |
| 2945 |
.flags = SPOOLSS_FORM_USER, |
| 2946 |
.form_name = "testform_user", |
| 2947 |
.size = size, |
| 2948 |
.area = area, |
| 2949 |
}, |
| 2950 |
.expected_add_result = WERR_OK, |
| 2951 |
.expected_delete_result = WERR_OK |
| 2952 |
}, |
| 2953 |
/* |
| 2954 |
weird, we can add a builtin form but we can never remove it |
| 2955 |
again - gd |
| 2956 |
|
| 2957 |
{ |
| 2958 |
.info1 = { |
| 2959 |
.flags = SPOOLSS_FORM_BUILTIN, |
| 2960 |
.form_name = "testform_builtin", |
| 2961 |
.size = size, |
| 2962 |
.area = area, |
| 2963 |
}, |
| 2964 |
.expected_add_result = WERR_OK, |
| 2965 |
.expected_delete_result = WERR_INVALID_PARAMETER, |
| 2966 |
}, |
| 2967 |
*/ |
| 2968 |
{ |
| 2969 |
.info1 = { |
| 2970 |
.flags = SPOOLSS_FORM_PRINTER, |
| 2971 |
.form_name = "testform_printer", |
| 2972 |
.size = size, |
| 2973 |
.area = area, |
| 2974 |
}, |
| 2975 |
.expected_add_result = WERR_OK, |
| 2976 |
.expected_delete_result = WERR_OK |
| 2977 |
}, |
| 2978 |
{ |
| 2979 |
.info1 = { |
| 2980 |
.flags = SPOOLSS_FORM_USER, |
| 2981 |
.form_name = "Letter", |
| 2982 |
.size = size, |
| 2983 |
.area = area, |
| 2984 |
}, |
| 2985 |
.expected_add_result = WERR_FILE_EXISTS, |
| 2986 |
.expected_delete_result = WERR_INVALID_PARAMETER |
| 2987 |
}, |
| 2988 |
{ |
| 2989 |
.info1 = { |
| 2990 |
.flags = SPOOLSS_FORM_BUILTIN, |
| 2991 |
.form_name = "Letter", |
| 2992 |
.size = size, |
| 2993 |
.area = area, |
| 2994 |
}, |
| 2995 |
.expected_add_result = WERR_FILE_EXISTS, |
| 2996 |
.expected_delete_result = WERR_INVALID_PARAMETER |
| 2997 |
}, |
| 2998 |
{ |
| 2999 |
.info1 = { |
| 3000 |
.flags = SPOOLSS_FORM_PRINTER, |
| 3001 |
.form_name = "Letter", |
| 3002 |
.size = size, |
| 3003 |
.area = area, |
| 3004 |
}, |
| 3005 |
.expected_add_result = WERR_FILE_EXISTS, |
| 3006 |
.expected_delete_result = WERR_INVALID_PARAMETER |
| 3007 |
}, |
| 3008 |
{ |
| 3009 |
.info1 = { |
| 3010 |
.flags = 12345, |
| 3011 |
.form_name = "invalid_flags", |
| 3012 |
.size = size, |
| 3013 |
.area = area, |
| 3014 |
}, |
| 3015 |
.expected_add_result = WERR_INVALID_PARAMETER, |
| 3016 |
.expected_delete_result = WERR_INVALID_FORM_NAME |
| 3017 |
} |
| 3018 |
|
| 3019 |
}; |
| 3020 |
|
| 3021 |
for (i=0; i < ARRAY_SIZE(forms); i++) { |
| 3022 |
torture_assert(tctx, |
| 3023 |
test_Forms_args(tctx, b, handle, print_server, printer_name, |
| 3024 |
winreg_handle, hive_handle, |
| 3025 |
forms[i].info1.form_name, |
| 3026 |
&forms[i].info1, |
| 3027 |
forms[i].expected_add_result, |
| 3028 |
forms[i].expected_delete_result), |
| 3029 |
talloc_asprintf(tctx, "failed to test form '%s'", forms[i].info1.form_name)); |
| 3030 |
} |
| 3031 |
|
| 3032 |
return true; |
| 3033 |
} |
| 3034 |
|
| 3035 |
static bool test_EnumPorts_old(struct torture_context *tctx, |
| 3036 |
void *private_data) |
| 3037 |
{ |
| 3038 |
struct test_spoolss_context *ctx = |
| 3039 |
talloc_get_type_abort(private_data, struct test_spoolss_context); |
| 3040 |
|
| 3041 |
NTSTATUS status; |
| 3042 |
struct spoolss_EnumPorts r; |
| 3043 |
uint32_t needed; |
| 3044 |
uint32_t count; |
| 3045 |
union spoolss_PortInfo *info; |
| 3046 |
struct dcerpc_pipe *p = ctx->spoolss_pipe; |
| 3047 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 3048 |
|
| 3049 |
r.in.servername = talloc_asprintf(tctx, "\\\\%s", |
| 3050 |
dcerpc_server_name(p)); |
| 3051 |
r.in.level = 2; |
| 3052 |
r.in.buffer = NULL; |
| 3053 |
r.in.offered = 0; |
| 3054 |
r.out.needed = &needed; |
| 3055 |
r.out.count = &count; |
| 3056 |
r.out.info = &info; |
| 3057 |
|
| 3058 |
torture_comment(tctx, "Testing EnumPorts\n"); |
| 3059 |
|
| 3060 |
status = dcerpc_spoolss_EnumPorts_r(b, tctx, &r); |
| 3061 |
|
| 3062 |
torture_assert_ntstatus_ok(tctx, status, "EnumPorts failed"); |
| 3063 |
|
| 3064 |
if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) { |
| 3065 |
DATA_BLOB blob = data_blob_talloc_zero(tctx, needed); |
| 3066 |
r.in.buffer = &blob; |
| 3067 |
r.in.offered = needed; |
| 3068 |
|
| 3069 |
status = dcerpc_spoolss_EnumPorts_r(b, tctx, &r); |
| 3070 |
torture_assert_ntstatus_ok(tctx, status, "EnumPorts failed"); |
| 3071 |
torture_assert_werr_ok(tctx, r.out.result, "EnumPorts failed"); |
| 3072 |
|
| 3073 |
torture_assert(tctx, info, "No ports returned"); |
| 3074 |
} |
| 3075 |
|
| 3076 |
torture_assert_werr_ok(tctx, r.out.result, "EnumPorts failed"); |
| 3077 |
|
| 3078 |
CHECK_NEEDED_SIZE_ENUM_LEVEL(spoolss_EnumPorts, info, 2, count, needed, 4); |
| 3079 |
|
| 3080 |
return true; |
| 3081 |
} |
| 3082 |
|
| 3083 |
static bool test_AddPort(struct torture_context *tctx, |
| 3084 |
void *private_data) |
| 3085 |
{ |
| 3086 |
struct test_spoolss_context *ctx = |
| 3087 |
talloc_get_type_abort(private_data, struct test_spoolss_context); |
| 3088 |
|
| 3089 |
NTSTATUS status; |
| 3090 |
struct spoolss_AddPort r; |
| 3091 |
struct dcerpc_pipe *p = ctx->spoolss_pipe; |
| 3092 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 3093 |
|
| 3094 |
r.in.server_name = talloc_asprintf(tctx, "\\\\%s", |
| 3095 |
dcerpc_server_name(p)); |
| 3096 |
r.in.unknown = 0; |
| 3097 |
r.in.monitor_name = "foo"; |
| 3098 |
|
| 3099 |
torture_comment(tctx, "Testing AddPort\n"); |
| 3100 |
|
| 3101 |
status = dcerpc_spoolss_AddPort_r(b, tctx, &r); |
| 3102 |
|
| 3103 |
torture_assert_ntstatus_ok(tctx, status, "AddPort failed"); |
| 3104 |
|
| 3105 |
/* win2k3 returns WERR_NOT_SUPPORTED */ |
| 3106 |
|
| 3107 |
#if 0 |
| 3108 |
|
| 3109 |
if (!W_ERROR_IS_OK(r.out.result)) { |
| 3110 |
printf("AddPort failed - %s\n", win_errstr(r.out.result)); |
| 3111 |
return false; |
| 3112 |
} |
| 3113 |
|
| 3114 |
#endif |
| 3115 |
|
| 3116 |
return true; |
| 3117 |
} |
| 3118 |
|
| 3119 |
static bool test_GetJob_args(struct torture_context *tctx, |
| 3120 |
struct dcerpc_binding_handle *b, |
| 3121 |
struct policy_handle *handle, |
| 3122 |
uint32_t job_id, |
| 3123 |
uint32_t level, |
| 3124 |
union spoolss_JobInfo *info_p) |
| 3125 |
{ |
| 3126 |
NTSTATUS status; |
| 3127 |
struct spoolss_GetJob r; |
| 3128 |
union spoolss_JobInfo info; |
| 3129 |
uint32_t needed; |
| 3130 |
|
| 3131 |
r.in.handle = handle; |
| 3132 |
r.in.job_id = job_id; |
| 3133 |
r.in.level = level; |
| 3134 |
r.in.buffer = NULL; |
| 3135 |
r.in.offered = 0; |
| 3136 |
r.out.needed = &needed; |
| 3137 |
r.out.info = &info; |
| 3138 |
|
| 3139 |
torture_comment(tctx, "Testing GetJob(%d), level %d\n", job_id, r.in.level); |
| 3140 |
|
| 3141 |
status = dcerpc_spoolss_GetJob_r(b, tctx, &r); |
| 3142 |
torture_assert_ntstatus_ok(tctx, status, "GetJob failed"); |
| 3143 |
if (level == 0) { |
| 3144 |
torture_assert_werr_equal(tctx, r.out.result, WERR_INVALID_LEVEL, "Unexpected return code"); |
| 3145 |
} |
| 3146 |
|
| 3147 |
if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) { |
| 3148 |
DATA_BLOB blob = data_blob_talloc_zero(tctx, needed); |
| 3149 |
r.in.buffer = &blob; |
| 3150 |
r.in.offered = needed; |
| 3151 |
|
| 3152 |
status = dcerpc_spoolss_GetJob_r(b, tctx, &r); |
| 3153 |
torture_assert_ntstatus_ok(tctx, status, "GetJob failed"); |
| 3154 |
} |
| 3155 |
|
| 3156 |
torture_assert_werr_ok(tctx, r.out.result, "GetJob failed"); |
| 3157 |
torture_assert(tctx, r.out.info, "No job info returned"); |
| 3158 |
|
| 3159 |
CHECK_NEEDED_SIZE_LEVEL(spoolss_JobInfo, r.out.info, r.in.level, needed, 4); |
| 3160 |
|
| 3161 |
if (info_p) { |
| 3162 |
*info_p = *r.out.info; |
| 3163 |
} |
| 3164 |
|
| 3165 |
return true; |
| 3166 |
} |
| 3167 |
|
| 3168 |
#if 0 |
| 3169 |
static bool test_GetJob(struct torture_context *tctx, |
| 3170 |
struct dcerpc_binding_handle *b, |
| 3171 |
struct policy_handle *handle, |
| 3172 |
uint32_t job_id) |
| 3173 |
{ |
| 3174 |
uint32_t levels[] = {0, 1, 2 /* 3, 4 */}; |
| 3175 |
uint32_t i; |
| 3176 |
|
| 3177 |
for (i=0; i < ARRAY_SIZE(levels); i++) { |
| 3178 |
torture_assert(tctx, |
| 3179 |
test_GetJob_args(tctx, b, handle, job_id, levels[i], NULL), |
| 3180 |
"GetJob failed"); |
| 3181 |
} |
| 3182 |
|
| 3183 |
return true; |
| 3184 |
} |
| 3185 |
#endif |
| 3186 |
|
| 3187 |
static bool test_SetJob(struct torture_context *tctx, |
| 3188 |
struct dcerpc_binding_handle *b, |
| 3189 |
struct policy_handle *handle, |
| 3190 |
uint32_t job_id, |
| 3191 |
struct spoolss_JobInfoContainer *ctr, |
| 3192 |
enum spoolss_JobControl command) |
| 3193 |
{ |
| 3194 |
NTSTATUS status; |
| 3195 |
struct spoolss_SetJob r; |
| 3196 |
|
| 3197 |
r.in.handle = handle; |
| 3198 |
r.in.job_id = job_id; |
| 3199 |
r.in.ctr = ctr; |
| 3200 |
r.in.command = command; |
| 3201 |
|
| 3202 |
switch (command) { |
| 3203 |
case SPOOLSS_JOB_CONTROL_PAUSE: |
| 3204 |
torture_comment(tctx, "Testing SetJob(%d), SPOOLSS_JOB_CONTROL_PAUSE\n", job_id); |
| 3205 |
break; |
| 3206 |
case SPOOLSS_JOB_CONTROL_RESUME: |
| 3207 |
torture_comment(tctx, "Testing SetJob(%d), SPOOLSS_JOB_CONTROL_RESUME\n", job_id); |
| 3208 |
break; |
| 3209 |
case SPOOLSS_JOB_CONTROL_CANCEL: |
| 3210 |
torture_comment(tctx, "Testing SetJob(%d), SPOOLSS_JOB_CONTROL_CANCEL\n", job_id); |
| 3211 |
break; |
| 3212 |
case SPOOLSS_JOB_CONTROL_RESTART: |
| 3213 |
torture_comment(tctx, "Testing SetJob(%d), SPOOLSS_JOB_CONTROL_RESTART\n", job_id); |
| 3214 |
break; |
| 3215 |
case SPOOLSS_JOB_CONTROL_DELETE: |
| 3216 |
torture_comment(tctx, "Testing SetJob(%d), SPOOLSS_JOB_CONTROL_DELETE\n", job_id); |
| 3217 |
break; |
| 3218 |
case SPOOLSS_JOB_CONTROL_SEND_TO_PRINTER: |
| 3219 |
torture_comment(tctx, "Testing SetJob(%d), SPOOLSS_JOB_CONTROL_SEND_TO_PRINTER\n", job_id); |
| 3220 |
break; |
| 3221 |
case SPOOLSS_JOB_CONTROL_LAST_PAGE_EJECTED: |
| 3222 |
torture_comment(tctx, "Testing SetJob(%d), SPOOLSS_JOB_CONTROL_LAST_PAGE_EJECTED\n", job_id); |
| 3223 |
break; |
| 3224 |
case SPOOLSS_JOB_CONTROL_RETAIN: |
| 3225 |
torture_comment(tctx, "Testing SetJob(%d), SPOOLSS_JOB_CONTROL_RETAIN\n", job_id); |
| 3226 |
break; |
| 3227 |
case SPOOLSS_JOB_CONTROL_RELEASE: |
| 3228 |
torture_comment(tctx, "Testing SetJob(%d), SPOOLSS_JOB_CONTROL_RELEASE\n", job_id); |
| 3229 |
break; |
| 3230 |
default: |
| 3231 |
torture_comment(tctx, "Testing SetJob(%d)\n", job_id); |
| 3232 |
break; |
| 3233 |
} |
| 3234 |
|
| 3235 |
status = dcerpc_spoolss_SetJob_r(b, tctx, &r); |
| 3236 |
torture_assert_ntstatus_ok(tctx, status, "SetJob failed"); |
| 3237 |
torture_assert_werr_ok(tctx, r.out.result, "SetJob failed"); |
| 3238 |
|
| 3239 |
return true; |
| 3240 |
} |
| 3241 |
|
| 3242 |
static bool test_AddJob(struct torture_context *tctx, |
| 3243 |
struct dcerpc_binding_handle *b, |
| 3244 |
struct policy_handle *handle) |
| 3245 |
{ |
| 3246 |
NTSTATUS status; |
| 3247 |
struct spoolss_AddJob r; |
| 3248 |
uint32_t needed; |
| 3249 |
|
| 3250 |
r.in.level = 0; |
| 3251 |
r.in.handle = handle; |
| 3252 |
r.in.offered = 0; |
| 3253 |
r.out.needed = &needed; |
| 3254 |
r.in.buffer = r.out.buffer = NULL; |
| 3255 |
|
| 3256 |
torture_comment(tctx, "Testing AddJob\n"); |
| 3257 |
|
| 3258 |
status = dcerpc_spoolss_AddJob_r(b, tctx, &r); |
| 3259 |
torture_assert_ntstatus_ok(tctx, status, "AddJob failed"); |
| 3260 |
torture_assert_werr_equal(tctx, r.out.result, WERR_INVALID_LEVEL, "AddJob failed"); |
| 3261 |
|
| 3262 |
r.in.level = 1; |
| 3263 |
|
| 3264 |
status = dcerpc_spoolss_AddJob_r(b, tctx, &r); |
| 3265 |
torture_assert_ntstatus_ok(tctx, status, "AddJob failed"); |
| 3266 |
torture_assert_werr_equal(tctx, r.out.result, WERR_INVALID_PARAMETER, "AddJob failed"); |
| 3267 |
|
| 3268 |
return true; |
| 3269 |
} |
| 3270 |
|
| 3271 |
|
| 3272 |
static bool test_EnumJobs_args(struct torture_context *tctx, |
| 3273 |
struct dcerpc_binding_handle *b, |
| 3274 |
struct policy_handle *handle, |
| 3275 |
uint32_t level, |
| 3276 |
WERROR werr_expected, |
| 3277 |
uint32_t *count_p, |
| 3278 |
union spoolss_JobInfo **info_p) |
| 3279 |
{ |
| 3280 |
NTSTATUS status; |
| 3281 |
struct spoolss_EnumJobs r; |
| 3282 |
uint32_t needed; |
| 3283 |
uint32_t count; |
| 3284 |
union spoolss_JobInfo *info; |
| 3285 |
|
| 3286 |
r.in.handle = handle; |
| 3287 |
r.in.firstjob = 0; |
| 3288 |
r.in.numjobs = 0xffffffff; |
| 3289 |
r.in.level = level; |
| 3290 |
r.in.buffer = NULL; |
| 3291 |
r.in.offered = 0; |
| 3292 |
r.out.needed = &needed; |
| 3293 |
r.out.count = &count; |
| 3294 |
r.out.info = &info; |
| 3295 |
|
| 3296 |
torture_comment(tctx, "Testing EnumJobs level %d\n", level); |
| 3297 |
|
| 3298 |
status = dcerpc_spoolss_EnumJobs_r(b, tctx, &r); |
| 3299 |
|
| 3300 |
torture_assert_ntstatus_ok(tctx, status, "EnumJobs failed"); |
| 3301 |
|
| 3302 |
if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) { |
| 3303 |
DATA_BLOB blob = data_blob_talloc_zero(tctx, needed); |
| 3304 |
r.in.buffer = &blob; |
| 3305 |
r.in.offered = needed; |
| 3306 |
|
| 3307 |
status = dcerpc_spoolss_EnumJobs_r(b, tctx, &r); |
| 3308 |
|
| 3309 |
torture_assert_ntstatus_ok(tctx, status, "EnumJobs failed"); |
| 3310 |
torture_assert_werr_equal(tctx, r.out.result, werr_expected, |
| 3311 |
"EnumJobs failed"); |
| 3312 |
torture_assert(tctx, info, "No jobs returned"); |
| 3313 |
|
| 3314 |
CHECK_NEEDED_SIZE_ENUM_LEVEL(spoolss_EnumJobs, *r.out.info, r.in.level, count, needed, 4); |
| 3315 |
|
| 3316 |
} else { |
| 3317 |
torture_assert_werr_equal(tctx, r.out.result, werr_expected, |
| 3318 |
"EnumJobs failed"); |
| 3319 |
} |
| 3320 |
|
| 3321 |
if (count_p) { |
| 3322 |
*count_p = count; |
| 3323 |
} |
| 3324 |
if (info_p) { |
| 3325 |
*info_p = info; |
| 3326 |
} |
| 3327 |
|
| 3328 |
return true; |
| 3329 |
} |
| 3330 |
|
| 3331 |
static bool test_JobPropertiesEnum(struct torture_context *tctx, |
| 3332 |
struct dcerpc_binding_handle *b, |
| 3333 |
struct policy_handle *handle, |
| 3334 |
uint32_t job_id) |
| 3335 |
{ |
| 3336 |
struct spoolss_EnumJobNamedProperties r; |
| 3337 |
uint32_t pcProperties = 0; |
| 3338 |
struct spoolss_PrintNamedProperty *ppProperties = NULL; |
| 3339 |
|
| 3340 |
r.in.hPrinter = handle; |
| 3341 |
r.in.JobId = job_id; |
| 3342 |
r.out.pcProperties = &pcProperties; |
| 3343 |
r.out.ppProperties = &ppProperties; |
| 3344 |
|
| 3345 |
torture_comment(tctx, "Testing EnumJobNamedProperties(%d)\n", job_id); |
| 3346 |
|
| 3347 |
torture_assert_ntstatus_ok(tctx, |
| 3348 |
dcerpc_spoolss_EnumJobNamedProperties_r(b, tctx, &r), |
| 3349 |
"spoolss_EnumJobNamedProperties failed"); |
| 3350 |
torture_assert_werr_ok(tctx, r.out.result, |
| 3351 |
"spoolss_EnumJobNamedProperties failed"); |
| 3352 |
|
| 3353 |
return true; |
| 3354 |
} |
| 3355 |
|
| 3356 |
static bool test_JobPropertySet(struct torture_context *tctx, |
| 3357 |
struct dcerpc_binding_handle *b, |
| 3358 |
struct policy_handle *handle, |
| 3359 |
uint32_t job_id, |
| 3360 |
struct spoolss_PrintNamedProperty *property) |
| 3361 |
{ |
| 3362 |
struct spoolss_SetJobNamedProperty r; |
| 3363 |
|
| 3364 |
r.in.hPrinter = handle; |
| 3365 |
r.in.JobId = job_id; |
| 3366 |
r.in.pProperty = property; |
| 3367 |
|
| 3368 |
torture_comment(tctx, "Testing SetJobNamedProperty(%d) %s - %d\n", |
| 3369 |
job_id, property->propertyName, |
| 3370 |
property->propertyValue.ePropertyType); |
| 3371 |
|
| 3372 |
torture_assert_ntstatus_ok(tctx, |
| 3373 |
dcerpc_spoolss_SetJobNamedProperty_r(b, tctx, &r), |
| 3374 |
"spoolss_SetJobNamedProperty failed"); |
| 3375 |
torture_assert_werr_ok(tctx, r.out.result, |
| 3376 |
"spoolss_SetJobNamedProperty failed"); |
| 3377 |
|
| 3378 |
return true; |
| 3379 |
} |
| 3380 |
|
| 3381 |
static bool test_JobPropertyGetValue(struct torture_context *tctx, |
| 3382 |
struct dcerpc_binding_handle *b, |
| 3383 |
struct policy_handle *handle, |
| 3384 |
uint32_t job_id, |
| 3385 |
const char *property_name, |
| 3386 |
struct spoolss_PrintPropertyValue *value) |
| 3387 |
{ |
| 3388 |
struct spoolss_GetJobNamedPropertyValue r; |
| 3389 |
|
| 3390 |
r.in.hPrinter = handle; |
| 3391 |
r.in.JobId = job_id; |
| 3392 |
r.in.pszName = property_name; |
| 3393 |
r.out.pValue = value; |
| 3394 |
|
| 3395 |
torture_comment(tctx, "Testing GetJobNamedPropertyValue(%d) %s\n", |
| 3396 |
job_id, property_name); |
| 3397 |
|
| 3398 |
torture_assert_ntstatus_ok(tctx, |
| 3399 |
dcerpc_spoolss_GetJobNamedPropertyValue_r(b, tctx, &r), |
| 3400 |
"spoolss_GetJobNamedPropertyValue failed"); |
| 3401 |
torture_assert_werr_ok(tctx, r.out.result, |
| 3402 |
"spoolss_GetJobNamedPropertyValue failed"); |
| 3403 |
|
| 3404 |
return true; |
| 3405 |
} |
| 3406 |
|
| 3407 |
static bool test_JobPropertyDelete(struct torture_context *tctx, |
| 3408 |
struct dcerpc_binding_handle *b, |
| 3409 |
struct policy_handle *handle, |
| 3410 |
uint32_t job_id, |
| 3411 |
const char *property_name) |
| 3412 |
{ |
| 3413 |
struct spoolss_DeleteJobNamedProperty r; |
| 3414 |
|
| 3415 |
r.in.hPrinter = handle; |
| 3416 |
r.in.JobId = job_id; |
| 3417 |
r.in.pszName = property_name; |
| 3418 |
|
| 3419 |
torture_comment(tctx, "Testing DeleteJobNamedProperty(%d) %s\n", |
| 3420 |
job_id, property_name); |
| 3421 |
|
| 3422 |
torture_assert_ntstatus_ok(tctx, |
| 3423 |
dcerpc_spoolss_DeleteJobNamedProperty_r(b, tctx, &r), |
| 3424 |
"spoolss_DeleteJobNamedProperty failed"); |
| 3425 |
torture_assert_werr_ok(tctx, r.out.result, |
| 3426 |
"spoolss_DeleteJobNamedProperty failed"); |
| 3427 |
|
| 3428 |
return true; |
| 3429 |
} |
| 3430 |
|
| 3431 |
static bool test_DoPrintTest_add_one_job_common(struct torture_context *tctx, |
| 3432 |
struct dcerpc_binding_handle *b, |
| 3433 |
struct policy_handle *handle, |
| 3434 |
const char *document_name, |
| 3435 |
const char *datatype, |
| 3436 |
uint32_t *job_id) |
| 3437 |
{ |
| 3438 |
NTSTATUS status; |
| 3439 |
struct spoolss_StartDocPrinter s; |
| 3440 |
struct spoolss_DocumentInfoCtr info_ctr; |
| 3441 |
struct spoolss_DocumentInfo1 info1; |
| 3442 |
struct spoolss_StartPagePrinter sp; |
| 3443 |
struct spoolss_WritePrinter w; |
| 3444 |
struct spoolss_EndPagePrinter ep; |
| 3445 |
struct spoolss_EndDocPrinter e; |
| 3446 |
int i; |
| 3447 |
uint32_t num_written; |
| 3448 |
|
| 3449 |
torture_comment(tctx, "Testing StartDocPrinter\n"); |
| 3450 |
|
| 3451 |
s.in.handle = handle; |
| 3452 |
s.in.info_ctr = &info_ctr; |
| 3453 |
s.out.job_id = job_id; |
| 3454 |
|
| 3455 |
info1.document_name = document_name; |
| 3456 |
info1.output_file = NULL; |
| 3457 |
info1.datatype = datatype; |
| 3458 |
|
| 3459 |
info_ctr.level = 1; |
| 3460 |
info_ctr.info.info1 = &info1; |
| 3461 |
|
| 3462 |
status = dcerpc_spoolss_StartDocPrinter_r(b, tctx, &s); |
| 3463 |
torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_StartDocPrinter failed"); |
| 3464 |
torture_assert_werr_ok(tctx, s.out.result, "StartDocPrinter failed"); |
| 3465 |
|
| 3466 |
for (i=1; i < 4; i++) { |
| 3467 |
union spoolss_JobInfo ginfo; |
| 3468 |
bool ok; |
| 3469 |
|
| 3470 |
torture_comment(tctx, "Testing StartPagePrinter: Page[%d], JobId[%d]\n", i, *job_id); |
| 3471 |
|
| 3472 |
sp.in.handle = handle; |
| 3473 |
|
| 3474 |
status = dcerpc_spoolss_StartPagePrinter_r(b, tctx, &sp); |
| 3475 |
torture_assert_ntstatus_ok(tctx, status, |
| 3476 |
"dcerpc_spoolss_StartPagePrinter failed"); |
| 3477 |
torture_assert_werr_ok(tctx, sp.out.result, "StartPagePrinter failed"); |
| 3478 |
|
| 3479 |
ok = test_GetJob_args(tctx, b, handle, *job_id, 1, &ginfo); |
| 3480 |
if (!ok) { |
| 3481 |
torture_comment(tctx, "test_GetJob failed for JobId[%d]\n", *job_id); |
| 3482 |
} |
| 3483 |
|
| 3484 |
torture_comment(tctx, "Testing WritePrinter: Page[%d], JobId[%d]\n", i, *job_id); |
| 3485 |
|
| 3486 |
w.in.handle = handle; |
| 3487 |
w.in.data = data_blob_string_const(talloc_asprintf(tctx,"TortureTestPage: %d\nData\n",i)); |
| 3488 |
w.out.num_written = &num_written; |
| 3489 |
|
| 3490 |
status = dcerpc_spoolss_WritePrinter_r(b, tctx, &w); |
| 3491 |
torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_WritePrinter failed"); |
| 3492 |
torture_assert_werr_ok(tctx, w.out.result, "WritePrinter failed"); |
| 3493 |
|
| 3494 |
torture_comment(tctx, "Testing EndPagePrinter: Page[%d], JobId[%d]\n", i, *job_id); |
| 3495 |
|
| 3496 |
ep.in.handle = handle; |
| 3497 |
|
| 3498 |
status = dcerpc_spoolss_EndPagePrinter_r(b, tctx, &ep); |
| 3499 |
torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EndPagePrinter failed"); |
| 3500 |
torture_assert_werr_ok(tctx, ep.out.result, "EndPagePrinter failed"); |
| 3501 |
} |
| 3502 |
|
| 3503 |
torture_comment(tctx, "Testing EndDocPrinter: JobId[%d]\n", *job_id); |
| 3504 |
|
| 3505 |
e.in.handle = handle; |
| 3506 |
|
| 3507 |
status = dcerpc_spoolss_EndDocPrinter_r(b, tctx, &e); |
| 3508 |
torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EndDocPrinter failed"); |
| 3509 |
torture_assert_werr_ok(tctx, e.out.result, "EndDocPrinter failed"); |
| 3510 |
|
| 3511 |
return true; |
| 3512 |
} |
| 3513 |
|
| 3514 |
static bool test_DoPrintTest_add_one_job(struct torture_context *tctx, |
| 3515 |
struct dcerpc_binding_handle *b, |
| 3516 |
struct policy_handle *handle, |
| 3517 |
const char *document_name, |
| 3518 |
uint32_t *job_id) |
| 3519 |
{ |
| 3520 |
test_DoPrintTest_add_one_job_common(tctx, b, handle, document_name, "RAW", job_id); |
| 3521 |
|
| 3522 |
return true; |
| 3523 |
} |
| 3524 |
|
| 3525 |
static bool test_DoPrintTest_add_one_job_v4(struct torture_context *tctx, |
| 3526 |
struct dcerpc_binding_handle *b, |
| 3527 |
struct policy_handle *handle, |
| 3528 |
const char *document_name, |
| 3529 |
uint32_t *job_id) |
| 3530 |
{ |
| 3531 |
test_DoPrintTest_add_one_job_common(tctx, b, handle, document_name, "XPS_PASS", job_id); |
| 3532 |
|
| 3533 |
return true; |
| 3534 |
} |
| 3535 |
|
| 3536 |
|
| 3537 |
static bool test_DoPrintTest_check_jobs(struct torture_context *tctx, |
| 3538 |
struct dcerpc_binding_handle *b, |
| 3539 |
struct policy_handle *handle, |
| 3540 |
uint32_t num_jobs, |
| 3541 |
uint32_t *job_ids) |
| 3542 |
{ |
| 3543 |
uint32_t count; |
| 3544 |
union spoolss_JobInfo *info = NULL; |
| 3545 |
int i; |
| 3546 |
|
| 3547 |
torture_assert(tctx, |
| 3548 |
test_AddJob(tctx, b, handle), |
| 3549 |
"AddJob failed"); |
| 3550 |
|
| 3551 |
torture_assert(tctx, |
| 3552 |
test_EnumJobs_args(tctx, b, handle, 1, WERR_OK, &count, &info), |
| 3553 |
"EnumJobs level 1 failed"); |
| 3554 |
|
| 3555 |
torture_assert_int_equal(tctx, count, num_jobs, "unexpected number of jobs in queue"); |
| 3556 |
|
| 3557 |
for (i=0; i < num_jobs; i++) { |
| 3558 |
union spoolss_JobInfo ginfo; |
| 3559 |
const char *document_name; |
| 3560 |
const char *new_document_name = "any_other_docname"; |
| 3561 |
struct spoolss_JobInfoContainer ctr; |
| 3562 |
struct spoolss_SetJobInfo1 info1; |
| 3563 |
|
| 3564 |
torture_assert_int_equal(tctx, info[i].info1.job_id, job_ids[i], "job id mismatch"); |
| 3565 |
|
| 3566 |
torture_assert(tctx, |
| 3567 |
test_GetJob_args(tctx, b, handle, info[i].info1.job_id, 1, &ginfo), |
| 3568 |
"failed to call test_GetJob"); |
| 3569 |
|
| 3570 |
torture_assert_int_equal(tctx, ginfo.info1.job_id, info[i].info1.job_id, "job id mismatch"); |
| 3571 |
|
| 3572 |
document_name = ginfo.info1.document_name; |
| 3573 |
|
| 3574 |
info1.job_id = ginfo.info1.job_id; |
| 3575 |
info1.printer_name = ginfo.info1.printer_name; |
| 3576 |
info1.server_name = ginfo.info1.server_name; |
| 3577 |
info1.user_name = ginfo.info1.user_name; |
| 3578 |
info1.document_name = new_document_name; |
| 3579 |
info1.data_type = ginfo.info1.data_type; |
| 3580 |
info1.text_status = ginfo.info1.text_status; |
| 3581 |
info1.status = ginfo.info1.status; |
| 3582 |
info1.priority = ginfo.info1.priority; |
| 3583 |
info1.position = ginfo.info1.position; |
| 3584 |
info1.total_pages = ginfo.info1.total_pages; |
| 3585 |
info1.pages_printed = ginfo.info1.pages_printed; |
| 3586 |
info1.submitted = ginfo.info1.submitted; |
| 3587 |
|
| 3588 |
ctr.level = 1; |
| 3589 |
ctr.info.info1 = &info1; |
| 3590 |
|
| 3591 |
torture_assert(tctx, |
| 3592 |
test_SetJob(tctx, b, handle, info[i].info1.job_id, &ctr, 0), |
| 3593 |
"failed to call test_SetJob level 1"); |
| 3594 |
|
| 3595 |
torture_assert(tctx, |
| 3596 |
test_GetJob_args(tctx, b, handle, info[i].info1.job_id, 1, &ginfo), |
| 3597 |
"failed to call test_GetJob"); |
| 3598 |
|
| 3599 |
if (strequal(ginfo.info1.document_name, document_name)) { |
| 3600 |
torture_warning(tctx, |
| 3601 |
"document_name did *NOT* change from '%s' to '%s'\n", |
| 3602 |
document_name, new_document_name); |
| 3603 |
} |
| 3604 |
} |
| 3605 |
|
| 3606 |
for (i=0; i < num_jobs; i++) { |
| 3607 |
if (!test_SetJob(tctx, b, handle, info[i].info1.job_id, NULL, SPOOLSS_JOB_CONTROL_PAUSE)) { |
| 3608 |
torture_warning(tctx, "failed to pause printjob\n"); |
| 3609 |
} |
| 3610 |
if (!test_SetJob(tctx, b, handle, info[i].info1.job_id, NULL, SPOOLSS_JOB_CONTROL_RESUME)) { |
| 3611 |
torture_warning(tctx, "failed to resume printjob\n"); |
| 3612 |
} |
| 3613 |
} |
| 3614 |
|
| 3615 |
return true; |
| 3616 |
} |
| 3617 |
|
| 3618 |
static bool test_DoPrintTest(struct torture_context *tctx, |
| 3619 |
struct dcerpc_binding_handle *b, |
| 3620 |
struct policy_handle *handle) |
| 3621 |
{ |
| 3622 |
bool ret = true; |
| 3623 |
uint32_t num_jobs = 8; |
| 3624 |
uint32_t *job_ids; |
| 3625 |
int i; |
| 3626 |
|
| 3627 |
torture_comment(tctx, "Testing real print operations\n"); |
| 3628 |
|
| 3629 |
job_ids = talloc_zero_array(tctx, uint32_t, num_jobs); |
| 3630 |
|
| 3631 |
for (i=0; i < num_jobs; i++) { |
| 3632 |
ret &= test_DoPrintTest_add_one_job(tctx, b, handle, "TorturePrintJob", &job_ids[i]); |
| 3633 |
} |
| 3634 |
|
| 3635 |
for (i=0; i < num_jobs; i++) { |
| 3636 |
ret &= test_SetJob(tctx, b, handle, job_ids[i], NULL, SPOOLSS_JOB_CONTROL_DELETE); |
| 3637 |
} |
| 3638 |
|
| 3639 |
for (i=0; i < num_jobs; i++) { |
| 3640 |
ret &= test_DoPrintTest_add_one_job_v4(tctx, b, handle, "TorturePrintJob v4", &job_ids[i]); |
| 3641 |
} |
| 3642 |
|
| 3643 |
for (i=0; i < num_jobs; i++) { |
| 3644 |
ret &= test_SetJob(tctx, b, handle, job_ids[i], NULL, SPOOLSS_JOB_CONTROL_DELETE); |
| 3645 |
} |
| 3646 |
|
| 3647 |
if (ret == true) { |
| 3648 |
torture_comment(tctx, "real print operations test succeeded\n\n"); |
| 3649 |
} |
| 3650 |
|
| 3651 |
return ret; |
| 3652 |
} |
| 3653 |
|
| 3654 |
static bool test_DoPrintTest_extended(struct torture_context *tctx, |
| 3655 |
struct dcerpc_binding_handle *b, |
| 3656 |
struct policy_handle *handle) |
| 3657 |
{ |
| 3658 |
bool ret = true; |
| 3659 |
uint32_t num_jobs = 8; |
| 3660 |
uint32_t *job_ids; |
| 3661 |
int i; |
| 3662 |
torture_comment(tctx, "Testing real print operations (extended)\n"); |
| 3663 |
|
| 3664 |
job_ids = talloc_zero_array(tctx, uint32_t, num_jobs); |
| 3665 |
|
| 3666 |
for (i=0; i < num_jobs; i++) { |
| 3667 |
ret &= test_DoPrintTest_add_one_job(tctx, b, handle, "TorturePrintJob", &job_ids[i]); |
| 3668 |
} |
| 3669 |
|
| 3670 |
ret &= test_DoPrintTest_check_jobs(tctx, b, handle, num_jobs, job_ids); |
| 3671 |
|
| 3672 |
for (i=0; i < num_jobs; i++) { |
| 3673 |
ret &= test_SetJob(tctx, b, handle, job_ids[i], NULL, SPOOLSS_JOB_CONTROL_DELETE); |
| 3674 |
} |
| 3675 |
|
| 3676 |
if (ret == true) { |
| 3677 |
torture_comment(tctx, "real print operations (extended) test succeeded\n\n"); |
| 3678 |
} |
| 3679 |
|
| 3680 |
return ret; |
| 3681 |
} |
| 3682 |
|
| 3683 |
static bool test_JobPrintProperties_equal(struct torture_context *tctx, |
| 3684 |
struct spoolss_PrintPropertyValue *got, |
| 3685 |
struct spoolss_PrintNamedProperty *exp) |
| 3686 |
{ |
| 3687 |
torture_assert_int_equal(tctx, |
| 3688 |
got->ePropertyType, |
| 3689 |
exp->propertyValue.ePropertyType, |
| 3690 |
"ePropertyType"); |
| 3691 |
|
| 3692 |
switch (exp->propertyValue.ePropertyType) { |
| 3693 |
case kRpcPropertyTypeString: |
| 3694 |
torture_assert_str_equal(tctx, |
| 3695 |
got->value.propertyString, |
| 3696 |
exp->propertyValue.value.propertyString, |
| 3697 |
"propertyString"); |
| 3698 |
break; |
| 3699 |
case kRpcPropertyTypeInt32: |
| 3700 |
torture_assert_int_equal(tctx, |
| 3701 |
got->value.propertyInt32, |
| 3702 |
exp->propertyValue.value.propertyInt32, |
| 3703 |
"propertyInt32"); |
| 3704 |
break; |
| 3705 |
case kRpcPropertyTypeInt64: |
| 3706 |
torture_assert_u64_equal(tctx, |
| 3707 |
got->value.propertyInt64, |
| 3708 |
exp->propertyValue.value.propertyInt64, |
| 3709 |
"propertyInt64"); |
| 3710 |
break; |
| 3711 |
case kRpcPropertyTypeByte: |
| 3712 |
torture_assert_int_equal(tctx, |
| 3713 |
got->value.propertyByte, |
| 3714 |
exp->propertyValue.value.propertyByte, |
| 3715 |
"propertyByte"); |
| 3716 |
break; |
| 3717 |
case kRpcPropertyTypeBuffer: |
| 3718 |
torture_assert_int_equal(tctx, |
| 3719 |
got->value.propertyBlob.cbBuf, |
| 3720 |
exp->propertyValue.value.propertyBlob.cbBuf, |
| 3721 |
"propertyBlob.cbBuf"); |
| 3722 |
torture_assert_mem_equal(tctx, |
| 3723 |
got->value.propertyBlob.pBuf, |
| 3724 |
exp->propertyValue.value.propertyBlob.pBuf, |
| 3725 |
exp->propertyValue.value.propertyBlob.cbBuf, |
| 3726 |
"propertyBlob.pBuf"); |
| 3727 |
|
| 3728 |
break; |
| 3729 |
|
| 3730 |
} |
| 3731 |
|
| 3732 |
return true; |
| 3733 |
} |
| 3734 |
|
| 3735 |
static bool test_JobPrintProperties(struct torture_context *tctx, |
| 3736 |
struct dcerpc_binding_handle *b, |
| 3737 |
struct policy_handle *handle, |
| 3738 |
uint32_t job_id) |
| 3739 |
{ |
| 3740 |
struct spoolss_PrintNamedProperty in; |
| 3741 |
struct spoolss_PrintPropertyValue out; |
| 3742 |
int i; |
| 3743 |
DATA_BLOB blob = data_blob_string_const("blob"); |
| 3744 |
struct { |
| 3745 |
const char *property_name; |
| 3746 |
enum spoolss_EPrintPropertyType type; |
| 3747 |
union spoolss_PrintPropertyValueUnion value; |
| 3748 |
WERROR expected_result; |
| 3749 |
} tests[] = { |
| 3750 |
{ |
| 3751 |
.property_name = "torture_property_string", |
| 3752 |
.type = kRpcPropertyTypeString, |
| 3753 |
.value.propertyString = "torture_property_value_string", |
| 3754 |
},{ |
| 3755 |
.property_name = "torture_property_int32", |
| 3756 |
.type = kRpcPropertyTypeInt32, |
| 3757 |
.value.propertyInt32 = 42, |
| 3758 |
},{ |
| 3759 |
.property_name = "torture_property_int64", |
| 3760 |
.type = kRpcPropertyTypeInt64, |
| 3761 |
.value.propertyInt64 = 0xaffe, |
| 3762 |
},{ |
| 3763 |
.property_name = "torture_property_byte", |
| 3764 |
.type = kRpcPropertyTypeByte, |
| 3765 |
.value.propertyByte = 0xab, |
| 3766 |
},{ |
| 3767 |
.property_name = "torture_property_buffer", |
| 3768 |
.type = kRpcPropertyTypeBuffer, |
| 3769 |
.value.propertyBlob.cbBuf = blob.length, |
| 3770 |
.value.propertyBlob.pBuf = blob.data, |
| 3771 |
} |
| 3772 |
}; |
| 3773 |
|
| 3774 |
torture_assert(tctx, |
| 3775 |
test_JobPropertiesEnum(tctx, b, handle, job_id), |
| 3776 |
"failed to enum properties"); |
| 3777 |
|
| 3778 |
for (i=0; i <ARRAY_SIZE(tests); i++) { |
| 3779 |
|
| 3780 |
in.propertyName = tests[i].property_name; |
| 3781 |
in.propertyValue.ePropertyType = tests[i].type; |
| 3782 |
in.propertyValue.value = tests[i].value; |
| 3783 |
|
| 3784 |
torture_assert(tctx, |
| 3785 |
test_JobPropertySet(tctx, b, handle, job_id, &in), |
| 3786 |
"failed to set property"); |
| 3787 |
|
| 3788 |
torture_assert(tctx, |
| 3789 |
test_JobPropertyGetValue(tctx, b, handle, job_id, in.propertyName, &out), |
| 3790 |
"failed to get property"); |
| 3791 |
|
| 3792 |
torture_assert(tctx, |
| 3793 |
test_JobPrintProperties_equal(tctx, &out, &in), |
| 3794 |
"property unequal"); |
| 3795 |
|
| 3796 |
torture_assert(tctx, |
| 3797 |
test_JobPropertiesEnum(tctx, b, handle, job_id), |
| 3798 |
"failed to enum properties"); |
| 3799 |
|
| 3800 |
torture_assert(tctx, |
| 3801 |
test_JobPropertyDelete(tctx, b, handle, job_id, in.propertyName), |
| 3802 |
"failed to delete job property"); |
| 3803 |
} |
| 3804 |
|
| 3805 |
torture_assert(tctx, |
| 3806 |
test_JobPropertiesEnum(tctx, b, handle, job_id), |
| 3807 |
"failed to enum properties"); |
| 3808 |
|
| 3809 |
return true; |
| 3810 |
} |
| 3811 |
|
| 3812 |
static bool test_DoPrintTest_properties(struct torture_context *tctx, |
| 3813 |
struct dcerpc_binding_handle *b, |
| 3814 |
struct policy_handle *handle) |
| 3815 |
{ |
| 3816 |
uint32_t num_jobs = 8; |
| 3817 |
uint32_t *job_ids; |
| 3818 |
int i; |
| 3819 |
torture_comment(tctx, "Testing real print operations (properties)\n"); |
| 3820 |
|
| 3821 |
job_ids = talloc_zero_array(tctx, uint32_t, num_jobs); |
| 3822 |
|
| 3823 |
for (i=0; i < num_jobs; i++) { |
| 3824 |
torture_assert(tctx, |
| 3825 |
test_DoPrintTest_add_one_job(tctx, b, handle, "TorturePrintJob", &job_ids[i]), |
| 3826 |
"failed to create print job"); |
| 3827 |
} |
| 3828 |
|
| 3829 |
for (i=0; i < num_jobs; i++) { |
| 3830 |
torture_assert(tctx, |
| 3831 |
test_JobPrintProperties(tctx, b, handle, job_ids[i]), |
| 3832 |
"failed to test job properties"); |
| 3833 |
} |
| 3834 |
|
| 3835 |
|
| 3836 |
for (i=0; i < num_jobs; i++) { |
| 3837 |
torture_assert(tctx, |
| 3838 |
test_SetJob(tctx, b, handle, job_ids[i], NULL, SPOOLSS_JOB_CONTROL_DELETE), |
| 3839 |
"failed to delete printjob"); |
| 3840 |
} |
| 3841 |
|
| 3842 |
torture_comment(tctx, "real print operations (properties) test succeeded\n\n"); |
| 3843 |
|
| 3844 |
return true; |
| 3845 |
} |
| 3846 |
|
| 3847 |
static bool test_PausePrinter(struct torture_context *tctx, |
| 3848 |
struct dcerpc_binding_handle *b, |
| 3849 |
struct policy_handle *handle) |
| 3850 |
{ |
| 3851 |
NTSTATUS status; |
| 3852 |
struct spoolss_SetPrinter r; |
| 3853 |
struct spoolss_SetPrinterInfoCtr info_ctr; |
| 3854 |
struct spoolss_DevmodeContainer devmode_ctr; |
| 3855 |
struct sec_desc_buf secdesc_ctr; |
| 3856 |
|
| 3857 |
info_ctr.level = 0; |
| 3858 |
info_ctr.info.info0 = NULL; |
| 3859 |
|
| 3860 |
ZERO_STRUCT(devmode_ctr); |
| 3861 |
ZERO_STRUCT(secdesc_ctr); |
| 3862 |
|
| 3863 |
r.in.handle = handle; |
| 3864 |
r.in.info_ctr = &info_ctr; |
| 3865 |
r.in.devmode_ctr = &devmode_ctr; |
| 3866 |
r.in.secdesc_ctr = &secdesc_ctr; |
| 3867 |
r.in.command = SPOOLSS_PRINTER_CONTROL_PAUSE; |
| 3868 |
|
| 3869 |
torture_comment(tctx, "Testing SetPrinter: SPOOLSS_PRINTER_CONTROL_PAUSE\n"); |
| 3870 |
|
| 3871 |
status = dcerpc_spoolss_SetPrinter_r(b, tctx, &r); |
| 3872 |
|
| 3873 |
torture_assert_ntstatus_ok(tctx, status, "SetPrinter failed"); |
| 3874 |
|
| 3875 |
torture_assert_werr_ok(tctx, r.out.result, "SetPrinter failed"); |
| 3876 |
|
| 3877 |
return true; |
| 3878 |
} |
| 3879 |
|
| 3880 |
static bool test_ResumePrinter(struct torture_context *tctx, |
| 3881 |
struct dcerpc_binding_handle *b, |
| 3882 |
struct policy_handle *handle) |
| 3883 |
{ |
| 3884 |
NTSTATUS status; |
| 3885 |
struct spoolss_SetPrinter r; |
| 3886 |
struct spoolss_SetPrinterInfoCtr info_ctr; |
| 3887 |
struct spoolss_DevmodeContainer devmode_ctr; |
| 3888 |
struct sec_desc_buf secdesc_ctr; |
| 3889 |
|
| 3890 |
info_ctr.level = 0; |
| 3891 |
info_ctr.info.info0 = NULL; |
| 3892 |
|
| 3893 |
ZERO_STRUCT(devmode_ctr); |
| 3894 |
ZERO_STRUCT(secdesc_ctr); |
| 3895 |
|
| 3896 |
r.in.handle = handle; |
| 3897 |
r.in.info_ctr = &info_ctr; |
| 3898 |
r.in.devmode_ctr = &devmode_ctr; |
| 3899 |
r.in.secdesc_ctr = &secdesc_ctr; |
| 3900 |
r.in.command = SPOOLSS_PRINTER_CONTROL_RESUME; |
| 3901 |
|
| 3902 |
torture_comment(tctx, "Testing SetPrinter: SPOOLSS_PRINTER_CONTROL_RESUME\n"); |
| 3903 |
|
| 3904 |
status = dcerpc_spoolss_SetPrinter_r(b, tctx, &r); |
| 3905 |
|
| 3906 |
torture_assert_ntstatus_ok(tctx, status, "SetPrinter failed"); |
| 3907 |
|
| 3908 |
torture_assert_werr_ok(tctx, r.out.result, "SetPrinter failed"); |
| 3909 |
|
| 3910 |
return true; |
| 3911 |
} |
| 3912 |
|
| 3913 |
static bool test_printer_purge(struct torture_context *tctx, |
| 3914 |
struct dcerpc_binding_handle *b, |
| 3915 |
struct policy_handle *handle) |
| 3916 |
{ |
| 3917 |
NTSTATUS status; |
| 3918 |
struct spoolss_SetPrinter r; |
| 3919 |
struct spoolss_SetPrinterInfoCtr info_ctr; |
| 3920 |
struct spoolss_DevmodeContainer devmode_ctr; |
| 3921 |
struct sec_desc_buf secdesc_ctr; |
| 3922 |
|
| 3923 |
info_ctr.level = 0; |
| 3924 |
info_ctr.info.info0 = NULL; |
| 3925 |
|
| 3926 |
ZERO_STRUCT(devmode_ctr); |
| 3927 |
ZERO_STRUCT(secdesc_ctr); |
| 3928 |
|
| 3929 |
r.in.handle = handle; |
| 3930 |
r.in.info_ctr = &info_ctr; |
| 3931 |
r.in.devmode_ctr = &devmode_ctr; |
| 3932 |
r.in.secdesc_ctr = &secdesc_ctr; |
| 3933 |
r.in.command = SPOOLSS_PRINTER_CONTROL_PURGE; |
| 3934 |
|
| 3935 |
torture_comment(tctx, "Testing SetPrinter: SPOOLSS_PRINTER_CONTROL_PURGE\n"); |
| 3936 |
|
| 3937 |
status = dcerpc_spoolss_SetPrinter_r(b, tctx, &r); |
| 3938 |
torture_assert_ntstatus_ok(tctx, status, "SetPrinter failed"); |
| 3939 |
torture_assert_werr_ok(tctx, r.out.result, "SetPrinter failed"); |
| 3940 |
|
| 3941 |
return true; |
| 3942 |
} |
| 3943 |
|
| 3944 |
static bool test_GetPrinterData_checktype(struct torture_context *tctx, |
| 3945 |
struct dcerpc_binding_handle *b, |
| 3946 |
struct policy_handle *handle, |
| 3947 |
const char *value_name, |
| 3948 |
enum winreg_Type *expected_type, |
| 3949 |
enum winreg_Type *type_p, |
| 3950 |
uint8_t **data_p, |
| 3951 |
uint32_t *needed_p) |
| 3952 |
{ |
| 3953 |
NTSTATUS status; |
| 3954 |
struct spoolss_GetPrinterData r; |
| 3955 |
uint32_t needed; |
| 3956 |
enum winreg_Type type; |
| 3957 |
union spoolss_PrinterData data; |
| 3958 |
|
| 3959 |
r.in.handle = handle; |
| 3960 |
r.in.value_name = value_name; |
| 3961 |
r.in.offered = 0; |
| 3962 |
r.out.needed = &needed; |
| 3963 |
r.out.type = &type; |
| 3964 |
r.out.data = talloc_zero_array(tctx, uint8_t, r.in.offered); |
| 3965 |
|
| 3966 |
torture_comment(tctx, "Testing GetPrinterData(%s)\n", r.in.value_name); |
| 3967 |
|
| 3968 |
status = dcerpc_spoolss_GetPrinterData_r(b, tctx, &r); |
| 3969 |
torture_assert_ntstatus_ok(tctx, status, "GetPrinterData failed"); |
| 3970 |
|
| 3971 |
if (W_ERROR_EQUAL(r.out.result, WERR_MORE_DATA)) { |
| 3972 |
if (expected_type) { |
| 3973 |
torture_assert_int_equal(tctx, type, *expected_type, "unexpected type"); |
| 3974 |
} |
| 3975 |
r.in.offered = needed; |
| 3976 |
r.out.data = talloc_zero_array(tctx, uint8_t, r.in.offered); |
| 3977 |
status = dcerpc_spoolss_GetPrinterData_r(b, tctx, &r); |
| 3978 |
torture_assert_ntstatus_ok(tctx, status, "GetPrinterData failed"); |
| 3979 |
} |
| 3980 |
|
| 3981 |
torture_assert_werr_ok(tctx, r.out.result, |
| 3982 |
talloc_asprintf(tctx, "GetPrinterData(%s) failed", r.in.value_name)); |
| 3983 |
|
| 3984 |
CHECK_NEEDED_SIZE_LEVEL(spoolss_PrinterData, &data, type, needed, 1); |
| 3985 |
|
| 3986 |
if (type_p) { |
| 3987 |
*type_p = type; |
| 3988 |
} |
| 3989 |
|
| 3990 |
if (data_p) { |
| 3991 |
*data_p = r.out.data; |
| 3992 |
} |
| 3993 |
|
| 3994 |
if (needed_p) { |
| 3995 |
*needed_p = needed; |
| 3996 |
} |
| 3997 |
|
| 3998 |
return true; |
| 3999 |
} |
| 4000 |
|
| 4001 |
static bool test_GetPrinterData(struct torture_context *tctx, |
| 4002 |
struct dcerpc_binding_handle *b, |
| 4003 |
struct policy_handle *handle, |
| 4004 |
const char *value_name, |
| 4005 |
enum winreg_Type *type_p, |
| 4006 |
uint8_t **data_p, |
| 4007 |
uint32_t *needed_p) |
| 4008 |
{ |
| 4009 |
return test_GetPrinterData_checktype(tctx, b, handle, value_name, |
| 4010 |
NULL, type_p, data_p, needed_p); |
| 4011 |
} |
| 4012 |
|
| 4013 |
static bool test_GetPrinterDataEx_checktype(struct torture_context *tctx, |
| 4014 |
struct dcerpc_pipe *p, |
| 4015 |
struct policy_handle *handle, |
| 4016 |
const char *key_name, |
| 4017 |
const char *value_name, |
| 4018 |
enum winreg_Type *expected_type, |
| 4019 |
enum winreg_Type *type_p, |
| 4020 |
uint8_t **data_p, |
| 4021 |
uint32_t *needed_p) |
| 4022 |
{ |
| 4023 |
NTSTATUS status; |
| 4024 |
struct spoolss_GetPrinterDataEx r; |
| 4025 |
enum winreg_Type type; |
| 4026 |
uint32_t needed; |
| 4027 |
union spoolss_PrinterData data; |
| 4028 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 4029 |
|
| 4030 |
r.in.handle = handle; |
| 4031 |
r.in.key_name = key_name; |
| 4032 |
r.in.value_name = value_name; |
| 4033 |
r.in.offered = 0; |
| 4034 |
r.out.type = &type; |
| 4035 |
r.out.needed = &needed; |
| 4036 |
r.out.data = talloc_zero_array(tctx, uint8_t, r.in.offered); |
| 4037 |
|
| 4038 |
torture_comment(tctx, "Testing GetPrinterDataEx(%s - %s)\n", |
| 4039 |
r.in.key_name, r.in.value_name); |
| 4040 |
|
| 4041 |
status = dcerpc_spoolss_GetPrinterDataEx_r(b, tctx, &r); |
| 4042 |
if (!NT_STATUS_IS_OK(status)) { |
| 4043 |
if (NT_STATUS_EQUAL(status, NT_STATUS_RPC_PROCNUM_OUT_OF_RANGE)) { |
| 4044 |
torture_skip(tctx, "GetPrinterDataEx not supported by server\n"); |
| 4045 |
} |
| 4046 |
torture_assert_ntstatus_ok(tctx, status, "GetPrinterDataEx failed"); |
| 4047 |
} |
| 4048 |
|
| 4049 |
if (W_ERROR_EQUAL(r.out.result, WERR_MORE_DATA)) { |
| 4050 |
if (expected_type) { |
| 4051 |
torture_assert_int_equal(tctx, type, *expected_type, "unexpected type"); |
| 4052 |
} |
| 4053 |
r.in.offered = needed; |
| 4054 |
r.out.data = talloc_zero_array(tctx, uint8_t, r.in.offered); |
| 4055 |
status = dcerpc_spoolss_GetPrinterDataEx_r(b, tctx, &r); |
| 4056 |
torture_assert_ntstatus_ok(tctx, status, "GetPrinterDataEx failed"); |
| 4057 |
} |
| 4058 |
|
| 4059 |
torture_assert_werr_ok(tctx, r.out.result, |
| 4060 |
talloc_asprintf(tctx, "GetPrinterDataEx(%s - %s) failed", r.in.key_name, r.in.value_name)); |
| 4061 |
|
| 4062 |
CHECK_NEEDED_SIZE_LEVEL(spoolss_PrinterData, &data, type, needed, 1); |
| 4063 |
|
| 4064 |
if (type_p) { |
| 4065 |
*type_p = type; |
| 4066 |
} |
| 4067 |
|
| 4068 |
if (data_p) { |
| 4069 |
*data_p = r.out.data; |
| 4070 |
} |
| 4071 |
|
| 4072 |
if (needed_p) { |
| 4073 |
*needed_p = needed; |
| 4074 |
} |
| 4075 |
|
| 4076 |
return true; |
| 4077 |
} |
| 4078 |
|
| 4079 |
static bool test_GetPrinterDataEx(struct torture_context *tctx, |
| 4080 |
struct dcerpc_pipe *p, |
| 4081 |
struct policy_handle *handle, |
| 4082 |
const char *key_name, |
| 4083 |
const char *value_name, |
| 4084 |
enum winreg_Type *type_p, |
| 4085 |
uint8_t **data_p, |
| 4086 |
uint32_t *needed_p) |
| 4087 |
{ |
| 4088 |
return test_GetPrinterDataEx_checktype(tctx, p, handle, key_name, value_name, |
| 4089 |
NULL, type_p, data_p, needed_p); |
| 4090 |
} |
| 4091 |
|
| 4092 |
static bool test_get_environment(struct torture_context *tctx, |
| 4093 |
struct dcerpc_binding_handle *b, |
| 4094 |
struct policy_handle *handle, |
| 4095 |
const char **architecture) |
| 4096 |
{ |
| 4097 |
DATA_BLOB blob; |
| 4098 |
enum winreg_Type type; |
| 4099 |
uint8_t *data; |
| 4100 |
uint32_t needed; |
| 4101 |
|
| 4102 |
torture_assert(tctx, |
| 4103 |
test_GetPrinterData(tctx, b, handle, "Architecture", &type, &data, &needed), |
| 4104 |
"failed to get Architecture"); |
| 4105 |
|
| 4106 |
torture_assert_int_equal(tctx, type, REG_SZ, "unexpected type"); |
| 4107 |
|
| 4108 |
blob = data_blob_const(data, needed); |
| 4109 |
*architecture = reg_val_data_string(tctx, REG_SZ, blob); |
| 4110 |
|
| 4111 |
return true; |
| 4112 |
} |
| 4113 |
|
| 4114 |
static bool test_GetPrinterData_list(struct torture_context *tctx, |
| 4115 |
void *private_data) |
| 4116 |
{ |
| 4117 |
struct test_spoolss_context *ctx = |
| 4118 |
talloc_get_type_abort(private_data, struct test_spoolss_context); |
| 4119 |
struct dcerpc_pipe *p = ctx->spoolss_pipe; |
| 4120 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 4121 |
const char *list[] = { |
| 4122 |
"W3SvcInstalled", |
| 4123 |
"BeepEnabled", |
| 4124 |
"EventLog", |
| 4125 |
/* "NetPopup", not on w2k8 */ |
| 4126 |
/* "NetPopupToComputer", not on w2k8 */ |
| 4127 |
"MajorVersion", |
| 4128 |
"MinorVersion", |
| 4129 |
"DefaultSpoolDirectory", |
| 4130 |
"Architecture", |
| 4131 |
"DsPresent", |
| 4132 |
"OSVersion", |
| 4133 |
/* "OSVersionEx", not on s3 */ |
| 4134 |
"DNSMachineName" |
| 4135 |
}; |
| 4136 |
int i; |
| 4137 |
|
| 4138 |
for (i=0; i < ARRAY_SIZE(list); i++) { |
| 4139 |
enum winreg_Type type = REG_NONE; |
| 4140 |
enum winreg_Type type_ex1 = REG_NONE; |
| 4141 |
enum winreg_Type type_ex2 = REG_NONE; |
| 4142 |
uint8_t *data; |
| 4143 |
uint8_t *data_ex1 = NULL; |
| 4144 |
uint8_t *data_ex2 = NULL; |
| 4145 |
uint32_t needed; |
| 4146 |
uint32_t needed_ex1 = 0; |
| 4147 |
uint32_t needed_ex2 = 0; |
| 4148 |
|
| 4149 |
torture_assert(tctx, test_GetPrinterData(tctx, b, &ctx->server_handle, list[i], &type, &data, &needed), |
| 4150 |
talloc_asprintf(tctx, "GetPrinterData failed on %s\n", list[i])); |
| 4151 |
torture_assert(tctx, test_GetPrinterDataEx(tctx, p, &ctx->server_handle, "random_string", list[i], &type_ex1, &data_ex1, &needed_ex1), |
| 4152 |
talloc_asprintf(tctx, "GetPrinterDataEx failed on %s\n", list[i])); |
| 4153 |
torture_assert(tctx, test_GetPrinterDataEx(tctx, p, &ctx->server_handle, "", list[i], &type_ex2, &data_ex2, &needed_ex2), |
| 4154 |
talloc_asprintf(tctx, "GetPrinterDataEx failed on %s\n", list[i])); |
| 4155 |
torture_assert_int_equal(tctx, type, type_ex1, "type mismatch"); |
| 4156 |
torture_assert_int_equal(tctx, type, type_ex2, "type mismatch"); |
| 4157 |
torture_assert_int_equal(tctx, needed, needed_ex1, "needed mismatch"); |
| 4158 |
torture_assert_int_equal(tctx, needed, needed_ex2, "needed mismatch"); |
| 4159 |
torture_assert_mem_equal(tctx, data, data_ex1, needed, "data mismatch"); |
| 4160 |
torture_assert_mem_equal(tctx, data, data_ex2, needed, "data mismatch"); |
| 4161 |
} |
| 4162 |
|
| 4163 |
return true; |
| 4164 |
} |
| 4165 |
|
| 4166 |
static bool test_EnumPrinterData(struct torture_context *tctx, |
| 4167 |
struct dcerpc_pipe *p, |
| 4168 |
struct policy_handle *handle, |
| 4169 |
uint32_t enum_index, |
| 4170 |
uint32_t value_offered, |
| 4171 |
uint32_t data_offered, |
| 4172 |
enum winreg_Type *type_p, |
| 4173 |
uint32_t *value_needed_p, |
| 4174 |
uint32_t *data_needed_p, |
| 4175 |
const char **value_name_p, |
| 4176 |
uint8_t **data_p, |
| 4177 |
WERROR *result_p) |
| 4178 |
{ |
| 4179 |
struct spoolss_EnumPrinterData r; |
| 4180 |
uint32_t data_needed; |
| 4181 |
uint32_t value_needed; |
| 4182 |
enum winreg_Type type; |
| 4183 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 4184 |
|
| 4185 |
r.in.handle = handle; |
| 4186 |
r.in.enum_index = enum_index; |
| 4187 |
r.in.value_offered = value_offered; |
| 4188 |
r.in.data_offered = data_offered; |
| 4189 |
r.out.data_needed = &data_needed; |
| 4190 |
r.out.value_needed = &value_needed; |
| 4191 |
r.out.type = &type; |
| 4192 |
r.out.data = talloc_zero_array(tctx, uint8_t, r.in.data_offered); |
| 4193 |
r.out.value_name = talloc_zero_array(tctx, const char, r.in.value_offered); |
| 4194 |
|
| 4195 |
torture_comment(tctx, "Testing EnumPrinterData(%d)\n", enum_index); |
| 4196 |
|
| 4197 |
torture_assert_ntstatus_ok(tctx, |
| 4198 |
dcerpc_spoolss_EnumPrinterData_r(b, tctx, &r), |
| 4199 |
"EnumPrinterData failed"); |
| 4200 |
|
| 4201 |
if (type_p) { |
| 4202 |
*type_p = type; |
| 4203 |
} |
| 4204 |
if (value_needed_p) { |
| 4205 |
*value_needed_p = value_needed; |
| 4206 |
} |
| 4207 |
if (data_needed_p) { |
| 4208 |
*data_needed_p = data_needed; |
| 4209 |
} |
| 4210 |
if (value_name_p) { |
| 4211 |
*value_name_p = r.out.value_name; |
| 4212 |
} |
| 4213 |
if (data_p) { |
| 4214 |
*data_p = r.out.data; |
| 4215 |
} |
| 4216 |
if (result_p) { |
| 4217 |
*result_p = r.out.result; |
| 4218 |
} |
| 4219 |
|
| 4220 |
return true; |
| 4221 |
} |
| 4222 |
|
| 4223 |
|
| 4224 |
static bool test_EnumPrinterData_all(struct torture_context *tctx, |
| 4225 |
struct dcerpc_pipe *p, |
| 4226 |
struct policy_handle *handle) |
| 4227 |
{ |
| 4228 |
uint32_t enum_index = 0; |
| 4229 |
enum winreg_Type type; |
| 4230 |
uint32_t value_needed; |
| 4231 |
uint32_t data_needed; |
| 4232 |
uint8_t *data; |
| 4233 |
const char *value_name; |
| 4234 |
WERROR result; |
| 4235 |
|
| 4236 |
torture_comment(tctx, "Testing EnumPrinterData\n"); |
| 4237 |
|
| 4238 |
do { |
| 4239 |
torture_assert(tctx, |
| 4240 |
test_EnumPrinterData(tctx, p, handle, enum_index, 0, 0, |
| 4241 |
&type, &value_needed, &data_needed, |
| 4242 |
&value_name, &data, &result), |
| 4243 |
"EnumPrinterData failed"); |
| 4244 |
|
| 4245 |
if (W_ERROR_EQUAL(result, WERR_NO_MORE_ITEMS)) { |
| 4246 |
break; |
| 4247 |
} |
| 4248 |
|
| 4249 |
torture_assert(tctx, |
| 4250 |
test_EnumPrinterData(tctx, p, handle, enum_index, value_needed, data_needed, |
| 4251 |
&type, &value_needed, &data_needed, |
| 4252 |
&value_name, &data, &result), |
| 4253 |
"EnumPrinterData failed"); |
| 4254 |
|
| 4255 |
if (W_ERROR_EQUAL(result, WERR_NO_MORE_ITEMS)) { |
| 4256 |
break; |
| 4257 |
} |
| 4258 |
|
| 4259 |
enum_index++; |
| 4260 |
|
| 4261 |
} while (W_ERROR_IS_OK(result)); |
| 4262 |
|
| 4263 |
torture_comment(tctx, "EnumPrinterData test succeeded\n"); |
| 4264 |
|
| 4265 |
return true; |
| 4266 |
} |
| 4267 |
|
| 4268 |
static bool test_EnumPrinterDataEx(struct torture_context *tctx, |
| 4269 |
struct dcerpc_binding_handle *b, |
| 4270 |
struct policy_handle *handle, |
| 4271 |
const char *key_name, |
| 4272 |
uint32_t *count_p, |
| 4273 |
struct spoolss_PrinterEnumValues **info_p) |
| 4274 |
{ |
| 4275 |
struct spoolss_EnumPrinterDataEx r; |
| 4276 |
struct spoolss_PrinterEnumValues *info; |
| 4277 |
uint32_t needed; |
| 4278 |
uint32_t count; |
| 4279 |
|
| 4280 |
r.in.handle = handle; |
| 4281 |
r.in.key_name = key_name; |
| 4282 |
r.in.offered = 0; |
| 4283 |
r.out.needed = &needed; |
| 4284 |
r.out.count = &count; |
| 4285 |
r.out.info = &info; |
| 4286 |
|
| 4287 |
torture_comment(tctx, "Testing EnumPrinterDataEx(%s)\n", key_name); |
| 4288 |
|
| 4289 |
torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_EnumPrinterDataEx_r(b, tctx, &r), |
| 4290 |
"EnumPrinterDataEx failed"); |
| 4291 |
if (W_ERROR_EQUAL(r.out.result, WERR_MORE_DATA)) { |
| 4292 |
r.in.offered = needed; |
| 4293 |
torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_EnumPrinterDataEx_r(b, tctx, &r), |
| 4294 |
"EnumPrinterDataEx failed"); |
| 4295 |
} |
| 4296 |
|
| 4297 |
torture_assert_werr_ok(tctx, r.out.result, "EnumPrinterDataEx failed"); |
| 4298 |
|
| 4299 |
CHECK_NEEDED_SIZE_ENUM(spoolss_EnumPrinterDataEx, info, count, needed, 1); |
| 4300 |
|
| 4301 |
if (count_p) { |
| 4302 |
*count_p = count; |
| 4303 |
} |
| 4304 |
if (info_p) { |
| 4305 |
*info_p = info; |
| 4306 |
} |
| 4307 |
|
| 4308 |
return true; |
| 4309 |
} |
| 4310 |
|
| 4311 |
static bool test_SetPrinterData(struct torture_context *tctx, |
| 4312 |
struct dcerpc_binding_handle *b, |
| 4313 |
struct policy_handle *handle, |
| 4314 |
const char *value_name, |
| 4315 |
enum winreg_Type type, |
| 4316 |
uint8_t *data, |
| 4317 |
uint32_t offered); |
| 4318 |
static bool test_DeletePrinterData(struct torture_context *tctx, |
| 4319 |
struct dcerpc_binding_handle *b, |
| 4320 |
struct policy_handle *handle, |
| 4321 |
const char *value_name); |
| 4322 |
|
| 4323 |
static bool test_EnumPrinterData_consistency(struct torture_context *tctx, |
| 4324 |
struct dcerpc_pipe *p, |
| 4325 |
struct policy_handle *handle) |
| 4326 |
{ |
| 4327 |
uint32_t count; |
| 4328 |
struct spoolss_PrinterEnumValues *info; |
| 4329 |
int i; |
| 4330 |
uint32_t value_needed, data_needed; |
| 4331 |
uint32_t value_offered, data_offered; |
| 4332 |
WERROR result; |
| 4333 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 4334 |
|
| 4335 |
enum winreg_Type type; |
| 4336 |
DATA_BLOB blob; |
| 4337 |
|
| 4338 |
torture_comment(tctx, "Testing EnumPrinterData vs EnumPrinterDataEx consistency\n"); |
| 4339 |
|
| 4340 |
torture_assert(tctx, push_reg_sz(tctx, &blob, "torture_data1"), ""); |
| 4341 |
type = REG_SZ; |
| 4342 |
|
| 4343 |
torture_assert(tctx, |
| 4344 |
test_SetPrinterData(tctx, b, handle, "torture_value1", type, blob.data, blob.length), |
| 4345 |
"SetPrinterData failed"); |
| 4346 |
|
| 4347 |
blob = data_blob_string_const("torture_data2"); |
| 4348 |
|
| 4349 |
torture_assert(tctx, |
| 4350 |
test_SetPrinterData(tctx, b, handle, "torture_value2", REG_BINARY, blob.data, blob.length), |
| 4351 |
"SetPrinterData failed"); |
| 4352 |
|
| 4353 |
blob = data_blob_talloc(tctx, NULL, 4); |
| 4354 |
SIVAL(blob.data, 0, 0x11223344); |
| 4355 |
|
| 4356 |
torture_assert(tctx, |
| 4357 |
test_SetPrinterData(tctx, b, handle, "torture_value3", type, blob.data, blob.length), |
| 4358 |
"SetPrinterData failed"); |
| 4359 |
|
| 4360 |
torture_assert(tctx, |
| 4361 |
test_EnumPrinterDataEx(tctx, b, handle, "PrinterDriverData", &count, &info), |
| 4362 |
"failed to call EnumPrinterDataEx"); |
| 4363 |
|
| 4364 |
/* get the max sizes for value and data */ |
| 4365 |
|
| 4366 |
torture_assert(tctx, |
| 4367 |
test_EnumPrinterData(tctx, p, handle, 0, 0, 0, |
| 4368 |
NULL, &value_needed, &data_needed, |
| 4369 |
NULL, NULL, &result), |
| 4370 |
"EnumPrinterData failed"); |
| 4371 |
torture_assert_werr_ok(tctx, result, "unexpected result"); |
| 4372 |
|
| 4373 |
/* check if the reply from the EnumPrinterData really matches max values */ |
| 4374 |
|
| 4375 |
for (i=0; i < count; i++) { |
| 4376 |
if (info[i].value_name_len > value_needed) { |
| 4377 |
torture_fail(tctx, |
| 4378 |
talloc_asprintf(tctx, |
| 4379 |
"EnumPrinterDataEx gave a reply with value length %d which is larger then expected max value length %d from EnumPrinterData", |
| 4380 |
info[i].value_name_len, value_needed)); |
| 4381 |
} |
| 4382 |
if (info[i].data_length > data_needed) { |
| 4383 |
torture_fail(tctx, |
| 4384 |
talloc_asprintf(tctx, |
| 4385 |
"EnumPrinterDataEx gave a reply with data length %d which is larger then expected max data length %d from EnumPrinterData", |
| 4386 |
info[i].data_length, data_needed)); |
| 4387 |
} |
| 4388 |
} |
| 4389 |
|
| 4390 |
/* assuming that both EnumPrinterData and EnumPrinterDataEx do either |
| 4391 |
* sort or not sort the replies by value name, we should be able to do |
| 4392 |
* the following entry comparison */ |
| 4393 |
|
| 4394 |
data_offered = data_needed; |
| 4395 |
value_offered = value_needed; |
| 4396 |
|
| 4397 |
for (i=0; i < count; i++) { |
| 4398 |
|
| 4399 |
const char *value_name; |
| 4400 |
uint8_t *data; |
| 4401 |
|
| 4402 |
torture_assert(tctx, |
| 4403 |
test_EnumPrinterData(tctx, p, handle, i, value_offered, data_offered, |
| 4404 |
&type, &value_needed, &data_needed, |
| 4405 |
&value_name, &data, &result), |
| 4406 |
"EnumPrinterData failed"); |
| 4407 |
|
| 4408 |
if (i -1 == count) { |
| 4409 |
torture_assert_werr_equal(tctx, result, WERR_NO_MORE_ITEMS, |
| 4410 |
"unexpected result"); |
| 4411 |
break; |
| 4412 |
} else { |
| 4413 |
torture_assert_werr_ok(tctx, result, "unexpected result"); |
| 4414 |
} |
| 4415 |
|
| 4416 |
torture_assert_int_equal(tctx, type, info[i].type, "type mismatch"); |
| 4417 |
torture_assert_int_equal(tctx, value_needed, info[i].value_name_len, "value name length mismatch"); |
| 4418 |
torture_assert_str_equal(tctx, value_name, info[i].value_name, "value name mismatch"); |
| 4419 |
torture_assert_int_equal(tctx, data_needed, info[i].data_length, "data length mismatch"); |
| 4420 |
torture_assert_mem_equal(tctx, data, info[i].data->data, info[i].data_length, "data mismatch"); |
| 4421 |
} |
| 4422 |
|
| 4423 |
torture_assert(tctx, |
| 4424 |
test_DeletePrinterData(tctx, b, handle, "torture_value1"), |
| 4425 |
"DeletePrinterData failed"); |
| 4426 |
torture_assert(tctx, |
| 4427 |
test_DeletePrinterData(tctx, b, handle, "torture_value2"), |
| 4428 |
"DeletePrinterData failed"); |
| 4429 |
torture_assert(tctx, |
| 4430 |
test_DeletePrinterData(tctx, b, handle, "torture_value3"), |
| 4431 |
"DeletePrinterData failed"); |
| 4432 |
|
| 4433 |
torture_comment(tctx, "EnumPrinterData vs EnumPrinterDataEx consistency test succeeded\n\n"); |
| 4434 |
|
| 4435 |
return true; |
| 4436 |
} |
| 4437 |
|
| 4438 |
static bool test_DeletePrinterData(struct torture_context *tctx, |
| 4439 |
struct dcerpc_binding_handle *b, |
| 4440 |
struct policy_handle *handle, |
| 4441 |
const char *value_name) |
| 4442 |
{ |
| 4443 |
NTSTATUS status; |
| 4444 |
struct spoolss_DeletePrinterData r; |
| 4445 |
|
| 4446 |
r.in.handle = handle; |
| 4447 |
r.in.value_name = value_name; |
| 4448 |
|
| 4449 |
torture_comment(tctx, "Testing DeletePrinterData(%s)\n", |
| 4450 |
r.in.value_name); |
| 4451 |
|
| 4452 |
status = dcerpc_spoolss_DeletePrinterData_r(b, tctx, &r); |
| 4453 |
|
| 4454 |
torture_assert_ntstatus_ok(tctx, status, "DeletePrinterData failed"); |
| 4455 |
torture_assert_werr_ok(tctx, r.out.result, "DeletePrinterData failed"); |
| 4456 |
|
| 4457 |
return true; |
| 4458 |
} |
| 4459 |
|
| 4460 |
static bool test_DeletePrinterDataEx(struct torture_context *tctx, |
| 4461 |
struct dcerpc_binding_handle *b, |
| 4462 |
struct policy_handle *handle, |
| 4463 |
const char *key_name, |
| 4464 |
const char *value_name) |
| 4465 |
{ |
| 4466 |
struct spoolss_DeletePrinterDataEx r; |
| 4467 |
|
| 4468 |
r.in.handle = handle; |
| 4469 |
r.in.key_name = key_name; |
| 4470 |
r.in.value_name = value_name; |
| 4471 |
|
| 4472 |
torture_comment(tctx, "Testing DeletePrinterDataEx(%s - %s)\n", |
| 4473 |
r.in.key_name, r.in.value_name); |
| 4474 |
|
| 4475 |
torture_assert_ntstatus_ok(tctx, |
| 4476 |
dcerpc_spoolss_DeletePrinterDataEx_r(b, tctx, &r), |
| 4477 |
"DeletePrinterDataEx failed"); |
| 4478 |
torture_assert_werr_ok(tctx, r.out.result, |
| 4479 |
"DeletePrinterDataEx failed"); |
| 4480 |
|
| 4481 |
return true; |
| 4482 |
} |
| 4483 |
|
| 4484 |
static bool test_DeletePrinterKey(struct torture_context *tctx, |
| 4485 |
struct dcerpc_binding_handle *b, |
| 4486 |
struct policy_handle *handle, |
| 4487 |
const char *key_name) |
| 4488 |
{ |
| 4489 |
struct spoolss_DeletePrinterKey r; |
| 4490 |
|
| 4491 |
r.in.handle = handle; |
| 4492 |
r.in.key_name = key_name; |
| 4493 |
|
| 4494 |
torture_comment(tctx, "Testing DeletePrinterKey(%s)\n", r.in.key_name); |
| 4495 |
|
| 4496 |
if (strequal(key_name, "") && !torture_setting_bool(tctx, "dangerous", false)) { |
| 4497 |
torture_skip(tctx, "not wiping out printer registry - enable dangerous tests to use\n"); |
| 4498 |
return true; |
| 4499 |
} |
| 4500 |
|
| 4501 |
torture_assert_ntstatus_ok(tctx, |
| 4502 |
dcerpc_spoolss_DeletePrinterKey_r(b, tctx, &r), |
| 4503 |
"DeletePrinterKey failed"); |
| 4504 |
torture_assert_werr_ok(tctx, r.out.result, |
| 4505 |
"DeletePrinterKey failed"); |
| 4506 |
|
| 4507 |
return true; |
| 4508 |
} |
| 4509 |
|
| 4510 |
static bool test_winreg_OpenHKLM(struct torture_context *tctx, |
| 4511 |
struct dcerpc_binding_handle *b, |
| 4512 |
struct policy_handle *handle) |
| 4513 |
{ |
| 4514 |
struct winreg_OpenHKLM r; |
| 4515 |
|
| 4516 |
r.in.system_name = NULL; |
| 4517 |
r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED; |
| 4518 |
r.out.handle = handle; |
| 4519 |
|
| 4520 |
torture_comment(tctx, "Testing winreg_OpenHKLM\n"); |
| 4521 |
|
| 4522 |
torture_assert_ntstatus_ok(tctx, dcerpc_winreg_OpenHKLM_r(b, tctx, &r), "OpenHKLM failed"); |
| 4523 |
torture_assert_werr_ok(tctx, r.out.result, "OpenHKLM failed"); |
| 4524 |
|
| 4525 |
return true; |
| 4526 |
} |
| 4527 |
|
| 4528 |
static void init_winreg_String(struct winreg_String *name, const char *s) |
| 4529 |
{ |
| 4530 |
name->name = s; |
| 4531 |
if (s) { |
| 4532 |
name->name_len = 2 * (strlen_m(s) + 1); |
| 4533 |
name->name_size = name->name_len; |
| 4534 |
} else { |
| 4535 |
name->name_len = 0; |
| 4536 |
name->name_size = 0; |
| 4537 |
} |
| 4538 |
} |
| 4539 |
|
| 4540 |
static bool test_winreg_OpenKey_opts(struct torture_context *tctx, |
| 4541 |
struct dcerpc_binding_handle *b, |
| 4542 |
struct policy_handle *hive_handle, |
| 4543 |
const char *keyname, |
| 4544 |
uint32_t options, |
| 4545 |
struct policy_handle *key_handle) |
| 4546 |
{ |
| 4547 |
struct winreg_OpenKey r; |
| 4548 |
|
| 4549 |
r.in.parent_handle = hive_handle; |
| 4550 |
init_winreg_String(&r.in.keyname, keyname); |
| 4551 |
r.in.options = options; |
| 4552 |
r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED; |
| 4553 |
r.out.handle = key_handle; |
| 4554 |
|
| 4555 |
torture_comment(tctx, "Testing winreg_OpenKey(%s)\n", keyname); |
| 4556 |
|
| 4557 |
torture_assert_ntstatus_ok(tctx, dcerpc_winreg_OpenKey_r(b, tctx, &r), "OpenKey failed"); |
| 4558 |
torture_assert_werr_ok(tctx, r.out.result, "OpenKey failed"); |
| 4559 |
|
| 4560 |
return true; |
| 4561 |
} |
| 4562 |
|
| 4563 |
static bool test_winreg_OpenKey(struct torture_context *tctx, |
| 4564 |
struct dcerpc_binding_handle *b, |
| 4565 |
struct policy_handle *hive_handle, |
| 4566 |
const char *keyname, |
| 4567 |
struct policy_handle *key_handle) |
| 4568 |
{ |
| 4569 |
return test_winreg_OpenKey_opts(tctx, b, hive_handle, keyname, |
| 4570 |
REG_OPTION_NON_VOLATILE, key_handle); |
| 4571 |
} |
| 4572 |
|
| 4573 |
static bool test_winreg_CloseKey(struct torture_context *tctx, |
| 4574 |
struct dcerpc_binding_handle *b, |
| 4575 |
struct policy_handle *handle) |
| 4576 |
{ |
| 4577 |
struct winreg_CloseKey r; |
| 4578 |
|
| 4579 |
r.in.handle = handle; |
| 4580 |
r.out.handle = handle; |
| 4581 |
|
| 4582 |
torture_comment(tctx, "Testing winreg_CloseKey\n"); |
| 4583 |
|
| 4584 |
torture_assert_ntstatus_ok(tctx, dcerpc_winreg_CloseKey_r(b, tctx, &r), "CloseKey failed"); |
| 4585 |
torture_assert_werr_ok(tctx, r.out.result, "CloseKey failed"); |
| 4586 |
|
| 4587 |
return true; |
| 4588 |
} |
| 4589 |
|
| 4590 |
bool test_winreg_QueryValue(struct torture_context *tctx, |
| 4591 |
struct dcerpc_binding_handle *b, |
| 4592 |
struct policy_handle *handle, |
| 4593 |
const char *value_name, |
| 4594 |
enum winreg_Type *type_p, |
| 4595 |
uint32_t *data_size_p, |
| 4596 |
uint32_t *data_length_p, |
| 4597 |
uint8_t **data_p) |
| 4598 |
{ |
| 4599 |
struct winreg_QueryValue r; |
| 4600 |
enum winreg_Type type = REG_NONE; |
| 4601 |
uint32_t data_size = 0; |
| 4602 |
uint32_t data_length = 0; |
| 4603 |
struct winreg_String valuename; |
| 4604 |
uint8_t *data = NULL; |
| 4605 |
|
| 4606 |
init_winreg_String(&valuename, value_name); |
| 4607 |
|
| 4608 |
data = talloc_zero_array(tctx, uint8_t, 0); |
| 4609 |
|
| 4610 |
r.in.handle = handle; |
| 4611 |
r.in.value_name = &valuename; |
| 4612 |
r.in.type = &type; |
| 4613 |
r.in.data_size = &data_size; |
| 4614 |
r.in.data_length = &data_length; |
| 4615 |
r.in.data = data; |
| 4616 |
r.out.type = &type; |
| 4617 |
r.out.data = data; |
| 4618 |
r.out.data_size = &data_size; |
| 4619 |
r.out.data_length = &data_length; |
| 4620 |
|
| 4621 |
torture_comment(tctx, "Testing winreg_QueryValue(%s)\n", value_name); |
| 4622 |
|
| 4623 |
torture_assert_ntstatus_ok(tctx, dcerpc_winreg_QueryValue_r(b, tctx, &r), "QueryValue failed"); |
| 4624 |
if (W_ERROR_EQUAL(r.out.result, WERR_MORE_DATA)) { |
| 4625 |
*r.in.data_size = *r.out.data_size; |
| 4626 |
data = talloc_zero_array(tctx, uint8_t, *r.in.data_size); |
| 4627 |
r.in.data = data; |
| 4628 |
r.out.data = data; |
| 4629 |
torture_assert_ntstatus_ok(tctx, dcerpc_winreg_QueryValue_r(b, tctx, &r), "QueryValue failed"); |
| 4630 |
} |
| 4631 |
torture_assert_werr_ok(tctx, r.out.result, "QueryValue failed"); |
| 4632 |
|
| 4633 |
if (type_p) { |
| 4634 |
*type_p = *r.out.type; |
| 4635 |
} |
| 4636 |
if (data_size_p) { |
| 4637 |
*data_size_p = *r.out.data_size; |
| 4638 |
} |
| 4639 |
if (data_length_p) { |
| 4640 |
*data_length_p = *r.out.data_length; |
| 4641 |
} |
| 4642 |
if (data_p) { |
| 4643 |
*data_p = r.out.data; |
| 4644 |
} |
| 4645 |
|
| 4646 |
return true; |
| 4647 |
} |
| 4648 |
|
| 4649 |
static bool test_winreg_query_printerdata(struct torture_context *tctx, |
| 4650 |
struct dcerpc_binding_handle *b, |
| 4651 |
struct policy_handle *handle, |
| 4652 |
const char *printer_name, |
| 4653 |
const char *key_name, |
| 4654 |
const char *value_name, |
| 4655 |
enum winreg_Type *w_type, |
| 4656 |
uint32_t *w_size, |
| 4657 |
uint32_t *w_length, |
| 4658 |
uint8_t **w_data) |
| 4659 |
{ |
| 4660 |
const char *printer_key; |
| 4661 |
struct policy_handle key_handle; |
| 4662 |
|
| 4663 |
printer_key = talloc_asprintf(tctx, "%s\\%s\\%s", |
| 4664 |
TOP_LEVEL_PRINT_PRINTERS_KEY, printer_name, key_name); |
| 4665 |
|
| 4666 |
torture_assert(tctx, |
| 4667 |
test_winreg_OpenKey(tctx, b, handle, printer_key, &key_handle), ""); |
| 4668 |
|
| 4669 |
torture_assert(tctx, |
| 4670 |
test_winreg_QueryValue(tctx, b, &key_handle, value_name, w_type, w_size, w_length, w_data), ""); |
| 4671 |
|
| 4672 |
torture_assert(tctx, |
| 4673 |
test_winreg_CloseKey(tctx, b, &key_handle), ""); |
| 4674 |
|
| 4675 |
return true; |
| 4676 |
} |
| 4677 |
|
| 4678 |
static bool test_GetForm_winreg(struct torture_context *tctx, |
| 4679 |
struct dcerpc_binding_handle *b, |
| 4680 |
struct policy_handle *handle, |
| 4681 |
const char *key_name, |
| 4682 |
const char *form_name, |
| 4683 |
enum winreg_Type *w_type, |
| 4684 |
uint32_t *w_size, |
| 4685 |
uint32_t *w_length, |
| 4686 |
uint8_t **w_data) |
| 4687 |
{ |
| 4688 |
struct policy_handle key_handle; |
| 4689 |
|
| 4690 |
torture_assert(tctx, |
| 4691 |
test_winreg_OpenKey(tctx, b, handle, key_name, &key_handle), ""); |
| 4692 |
|
| 4693 |
torture_assert(tctx, |
| 4694 |
test_winreg_QueryValue(tctx, b, &key_handle, form_name, w_type, w_size, w_length, w_data), ""); |
| 4695 |
|
| 4696 |
torture_assert(tctx, |
| 4697 |
test_winreg_CloseKey(tctx, b, &key_handle), ""); |
| 4698 |
|
| 4699 |
return true; |
| 4700 |
} |
| 4701 |
|
| 4702 |
static bool test_winreg_symbolic_link(struct torture_context *tctx, |
| 4703 |
struct dcerpc_binding_handle *b, |
| 4704 |
struct policy_handle *handle, |
| 4705 |
const char *symlink_keyname, |
| 4706 |
const char *symlink_destination) |
| 4707 |
{ |
| 4708 |
/* check if the first key is a symlink to the second key */ |
| 4709 |
|
| 4710 |
enum winreg_Type w_type; |
| 4711 |
uint32_t w_size; |
| 4712 |
uint32_t w_length; |
| 4713 |
uint8_t *w_data; |
| 4714 |
struct policy_handle key_handle; |
| 4715 |
DATA_BLOB blob; |
| 4716 |
const char *str; |
| 4717 |
|
| 4718 |
if (torture_setting_bool(tctx, "samba3", false) || |
| 4719 |
torture_setting_bool(tctx, "samba4", false)) { |
| 4720 |
torture_skip(tctx, "skip winreg symlink test against samba"); |
| 4721 |
} |
| 4722 |
|
| 4723 |
torture_assert(tctx, |
| 4724 |
test_winreg_OpenKey_opts(tctx, b, handle, symlink_keyname, REG_OPTION_OPEN_LINK, &key_handle), |
| 4725 |
"failed to open key link"); |
| 4726 |
|
| 4727 |
torture_assert(tctx, |
| 4728 |
test_winreg_QueryValue(tctx, b, &key_handle, |
| 4729 |
"SymbolicLinkValue", |
| 4730 |
&w_type, &w_size, &w_length, &w_data), |
| 4731 |
"failed to query for 'SymbolicLinkValue' attribute"); |
| 4732 |
|
| 4733 |
torture_assert_int_equal(tctx, w_type, REG_LINK, "unexpected type"); |
| 4734 |
|
| 4735 |
blob = data_blob(w_data, w_size); |
| 4736 |
str = reg_val_data_string(tctx, REG_SZ, blob); |
| 4737 |
|
| 4738 |
torture_assert_str_equal(tctx, str, symlink_destination, "unexpected symlink target string"); |
| 4739 |
|
| 4740 |
torture_assert(tctx, |
| 4741 |
test_winreg_CloseKey(tctx, b, &key_handle), |
| 4742 |
"failed to close key link"); |
| 4743 |
|
| 4744 |
return true; |
| 4745 |
} |
| 4746 |
|
| 4747 |
static const char *strip_unc(const char *unc) |
| 4748 |
{ |
| 4749 |
char *name; |
| 4750 |
|
| 4751 |
if (!unc) { |
| 4752 |
return NULL; |
| 4753 |
} |
| 4754 |
|
| 4755 |
if (unc[0] == '\\' && unc[1] == '\\') { |
| 4756 |
unc +=2; |
| 4757 |
} |
| 4758 |
|
| 4759 |
name = strchr(unc, '\\'); |
| 4760 |
if (name) { |
| 4761 |
return name+1; |
| 4762 |
} |
| 4763 |
|
| 4764 |
return unc; |
| 4765 |
} |
| 4766 |
|
| 4767 |
static bool test_GetPrinterInfo_winreg(struct torture_context *tctx, |
| 4768 |
struct dcerpc_binding_handle *b, |
| 4769 |
struct policy_handle *handle, |
| 4770 |
const char *printer_name, |
| 4771 |
struct dcerpc_binding_handle *winreg_handle, |
| 4772 |
struct policy_handle *hive_handle) |
| 4773 |
{ |
| 4774 |
union spoolss_PrinterInfo info; |
| 4775 |
const char *keys[] = { |
| 4776 |
TOP_LEVEL_CONTROL_PRINTERS_KEY, |
| 4777 |
TOP_LEVEL_PRINT_PRINTERS_KEY |
| 4778 |
}; |
| 4779 |
int i; |
| 4780 |
const char *printername, *sharename; |
| 4781 |
|
| 4782 |
torture_comment(tctx, "Testing Printer Info and winreg consistency\n"); |
| 4783 |
|
| 4784 |
torture_assert(tctx, |
| 4785 |
test_GetPrinter_level(tctx, b, handle, 2, &info), |
| 4786 |
"failed to get printer info level 2"); |
| 4787 |
|
| 4788 |
printername = strip_unc(info.info2.printername); |
| 4789 |
sharename = strip_unc(info.info2.sharename); |
| 4790 |
|
| 4791 |
#define test_sz(wname, iname) \ |
| 4792 |
do {\ |
| 4793 |
DATA_BLOB blob;\ |
| 4794 |
const char *str;\ |
| 4795 |
enum winreg_Type w_type;\ |
| 4796 |
uint32_t w_size;\ |
| 4797 |
uint32_t w_length;\ |
| 4798 |
uint8_t *w_data;\ |
| 4799 |
torture_assert(tctx,\ |
| 4800 |
test_winreg_QueryValue(tctx, winreg_handle, &key_handle, wname,\ |
| 4801 |
&w_type, &w_size, &w_length, &w_data),\ |
| 4802 |
"failed to query winreg");\ |
| 4803 |
torture_assert_int_equal(tctx, w_type, REG_SZ, "unexpected type");\ |
| 4804 |
blob = data_blob(w_data, w_size);\ |
| 4805 |
str = reg_val_data_string(tctx, REG_SZ, blob);\ |
| 4806 |
if (w_size == 2 && iname == NULL) {\ |
| 4807 |
/*torture_comment(tctx, "%s: \"\", %s: (null)\n", #wname, #iname);\ */\ |
| 4808 |
} else {\ |
| 4809 |
torture_assert_str_equal(tctx, str, iname,\ |
| 4810 |
talloc_asprintf(tctx, "%s - %s mismatch", #wname, #iname));\ |
| 4811 |
}\ |
| 4812 |
} while(0); |
| 4813 |
|
| 4814 |
#define test_dword(wname, iname) \ |
| 4815 |
do {\ |
| 4816 |
uint32_t value;\ |
| 4817 |
enum winreg_Type w_type;\ |
| 4818 |
uint32_t w_size;\ |
| 4819 |
uint32_t w_length;\ |
| 4820 |
uint8_t *w_data;\ |
| 4821 |
torture_assert(tctx,\ |
| 4822 |
test_winreg_QueryValue(tctx, winreg_handle, &key_handle, wname,\ |
| 4823 |
&w_type, &w_size, &w_length, &w_data),\ |
| 4824 |
"failed to query winreg");\ |
| 4825 |
torture_assert_int_equal(tctx, w_type, REG_DWORD, "unexpected type");\ |
| 4826 |
torture_assert_int_equal(tctx, w_size, 4, "unexpected size");\ |
| 4827 |
torture_assert_int_equal(tctx, w_length, 4, "unexpected length");\ |
| 4828 |
value = IVAL(w_data, 0);\ |
| 4829 |
torture_assert_int_equal(tctx, value, iname,\ |
| 4830 |
talloc_asprintf(tctx, "%s - %s mismatch", #wname, #iname));\ |
| 4831 |
} while(0); |
| 4832 |
|
| 4833 |
#define test_binary(wname, iname) \ |
| 4834 |
do {\ |
| 4835 |
enum winreg_Type w_type;\ |
| 4836 |
uint32_t w_size;\ |
| 4837 |
uint32_t w_length;\ |
| 4838 |
uint8_t *w_data;\ |
| 4839 |
torture_assert(tctx,\ |
| 4840 |
test_winreg_QueryValue(tctx, winreg_handle, &key_handle, wname,\ |
| 4841 |
&w_type, &w_size, &w_length, &w_data),\ |
| 4842 |
"failed to query winreg");\ |
| 4843 |
torture_assert_int_equal(tctx, w_type, REG_BINARY, "unexpected type");\ |
| 4844 |
torture_assert_int_equal(tctx, w_size, iname.length, "unexpected length");\ |
| 4845 |
torture_assert_mem_equal(tctx, w_data, iname.data, w_size, \ |
| 4846 |
"binary unequal");\ |
| 4847 |
} while(0); |
| 4848 |
|
| 4849 |
|
| 4850 |
#define test_dm(wname, iname) \ |
| 4851 |
do {\ |
| 4852 |
DATA_BLOB blob;\ |
| 4853 |
struct spoolss_DeviceMode dm;\ |
| 4854 |
enum ndr_err_code ndr_err;\ |
| 4855 |
enum winreg_Type w_type;\ |
| 4856 |
uint32_t w_size;\ |
| 4857 |
uint32_t w_length;\ |
| 4858 |
uint8_t *w_data;\ |
| 4859 |
torture_assert(tctx,\ |
| 4860 |
test_winreg_QueryValue(tctx, winreg_handle, &key_handle, wname,\ |
| 4861 |
&w_type, &w_size, &w_length, &w_data),\ |
| 4862 |
"failed to query winreg");\ |
| 4863 |
torture_assert_int_equal(tctx, w_type, REG_BINARY, "unexpected type");\ |
| 4864 |
blob = data_blob(w_data, w_size);\ |
| 4865 |
ndr_err = ndr_pull_struct_blob(&blob, tctx, &dm,\ |
| 4866 |
(ndr_pull_flags_fn_t)ndr_pull_spoolss_DeviceMode);\ |
| 4867 |
torture_assert_ndr_success(tctx, ndr_err, "failed to unmarshall dm");\ |
| 4868 |
torture_assert(tctx, test_devicemode_equal(tctx, &dm, iname),\ |
| 4869 |
"dm unequal");\ |
| 4870 |
} while(0); |
| 4871 |
|
| 4872 |
#define test_sd(wname, iname) \ |
| 4873 |
do {\ |
| 4874 |
DATA_BLOB blob;\ |
| 4875 |
struct security_descriptor sd;\ |
| 4876 |
enum ndr_err_code ndr_err;\ |
| 4877 |
enum winreg_Type w_type;\ |
| 4878 |
uint32_t w_size;\ |
| 4879 |
uint32_t w_length;\ |
| 4880 |
uint8_t *w_data;\ |
| 4881 |
torture_assert(tctx,\ |
| 4882 |
test_winreg_QueryValue(tctx, winreg_handle, &key_handle, wname,\ |
| 4883 |
&w_type, &w_size, &w_length, &w_data),\ |
| 4884 |
"failed to query winreg");\ |
| 4885 |
torture_assert_int_equal(tctx, w_type, REG_BINARY, "unexpected type");\ |
| 4886 |
blob = data_blob(w_data, w_size);\ |
| 4887 |
ndr_err = ndr_pull_struct_blob(&blob, tctx, &sd,\ |
| 4888 |
(ndr_pull_flags_fn_t)ndr_pull_security_descriptor);\ |
| 4889 |
torture_assert_ndr_success(tctx, ndr_err, "failed to unmarshall sd");\ |
| 4890 |
torture_assert(tctx, test_security_descriptor_equal(tctx, &sd, iname),\ |
| 4891 |
"sd unequal");\ |
| 4892 |
} while(0); |
| 4893 |
|
| 4894 |
#define test_multi_sz(wname, iname) \ |
| 4895 |
do {\ |
| 4896 |
DATA_BLOB blob;\ |
| 4897 |
const char **array;\ |
| 4898 |
enum winreg_Type w_type;\ |
| 4899 |
uint32_t w_size;\ |
| 4900 |
uint32_t w_length;\ |
| 4901 |
uint8_t *w_data;\ |
| 4902 |
int i;\ |
| 4903 |
torture_assert(tctx,\ |
| 4904 |
test_winreg_QueryValue(tctx, winreg_handle, &key_handle, wname,\ |
| 4905 |
&w_type, &w_size, &w_length, &w_data),\ |
| 4906 |
"failed to query winreg");\ |
| 4907 |
torture_assert_int_equal(tctx, w_type, REG_MULTI_SZ, "unexpected type");\ |
| 4908 |
blob = data_blob(w_data, w_size);\ |
| 4909 |
torture_assert(tctx, \ |
| 4910 |
pull_reg_multi_sz(tctx, &blob, &array),\ |
| 4911 |
"failed to pull multi sz");\ |
| 4912 |
for (i=0; array[i] != NULL; i++) {\ |
| 4913 |
torture_assert_str_equal(tctx, array[i], iname[i],\ |
| 4914 |
talloc_asprintf(tctx, "%s - %s mismatch", #wname, iname[i]));\ |
| 4915 |
}\ |
| 4916 |
} while(0); |
| 4917 |
|
| 4918 |
if (!test_winreg_symbolic_link(tctx, winreg_handle, hive_handle, |
| 4919 |
TOP_LEVEL_CONTROL_PRINTERS_KEY, |
| 4920 |
"\\Registry\\Machine\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Print\\Printers")) |
| 4921 |
{ |
| 4922 |
torture_warning(tctx, "failed to check for winreg symlink"); |
| 4923 |
} |
| 4924 |
|
| 4925 |
for (i=0; i < ARRAY_SIZE(keys); i++) { |
| 4926 |
|
| 4927 |
const char *printer_key; |
| 4928 |
struct policy_handle key_handle; |
| 4929 |
|
| 4930 |
printer_key = talloc_asprintf(tctx, "%s\\%s", |
| 4931 |
keys[i], printer_name); |
| 4932 |
|
| 4933 |
torture_assert(tctx, |
| 4934 |
test_winreg_OpenKey(tctx, winreg_handle, hive_handle, printer_key, &key_handle), ""); |
| 4935 |
|
| 4936 |
test_sz("Name", printername); |
| 4937 |
test_sz("Share Name", sharename); |
| 4938 |
test_sz("Port", info.info2.portname); |
| 4939 |
test_sz("Printer Driver", info.info2.drivername); |
| 4940 |
test_sz("Description", info.info2.comment); |
| 4941 |
test_sz("Location", info.info2.location); |
| 4942 |
test_sz("Separator File", info.info2.sepfile); |
| 4943 |
test_sz("Print Processor", info.info2.printprocessor); |
| 4944 |
test_sz("Datatype", info.info2.datatype); |
| 4945 |
test_sz("Parameters", info.info2.parameters); |
| 4946 |
/* winreg: 0, spoolss not */ |
| 4947 |
/* test_dword("Attributes", info.info2.attributes); */ |
| 4948 |
test_dword("Priority", info.info2.priority); |
| 4949 |
test_dword("Default Priority", info.info2.defaultpriority); |
| 4950 |
/* winreg: 60, spoolss: 0 */ |
| 4951 |
/* test_dword("StartTime", info.info2.starttime); */ |
| 4952 |
/* test_dword("UntilTime", info.info2.untiltime); */ |
| 4953 |
/* winreg != spoolss */ |
| 4954 |
/* test_dword("Status", info.info2.status); */ |
| 4955 |
test_dm("Default DevMode", info.info2.devmode); |
| 4956 |
test_sd("Security", info.info2.secdesc); |
| 4957 |
|
| 4958 |
torture_assert(tctx, |
| 4959 |
test_winreg_CloseKey(tctx, winreg_handle, &key_handle), ""); |
| 4960 |
} |
| 4961 |
|
| 4962 |
#undef test_dm |
| 4963 |
|
| 4964 |
torture_comment(tctx, "Printer Info and winreg consistency test succeeded\n\n"); |
| 4965 |
|
| 4966 |
return true; |
| 4967 |
} |
| 4968 |
|
| 4969 |
static bool test_GetPrintserverInfo_winreg(struct torture_context *tctx, |
| 4970 |
struct dcerpc_binding_handle *b, |
| 4971 |
struct policy_handle *handle, |
| 4972 |
struct dcerpc_binding_handle *winreg_handle, |
| 4973 |
struct policy_handle *hive_handle) |
| 4974 |
{ |
| 4975 |
union spoolss_PrinterInfo info; |
| 4976 |
struct policy_handle key_handle; |
| 4977 |
|
| 4978 |
torture_comment(tctx, |
| 4979 |
"Testing Printserver Info and winreg consistency\n"); |
| 4980 |
|
| 4981 |
torture_assert(tctx, |
| 4982 |
test_GetPrinter_level(tctx, b, handle, 3, &info), |
| 4983 |
"failed to get printer info level 2"); |
| 4984 |
|
| 4985 |
torture_assert(tctx, |
| 4986 |
test_winreg_OpenKey(tctx, winreg_handle, hive_handle, |
| 4987 |
TOP_LEVEL_CONTROL_KEY, &key_handle), ""); |
| 4988 |
|
| 4989 |
test_sd("ServerSecurityDescriptor", info.info3.secdesc); |
| 4990 |
|
| 4991 |
torture_assert(tctx, |
| 4992 |
test_winreg_CloseKey(tctx, winreg_handle, &key_handle), ""); |
| 4993 |
|
| 4994 |
#undef test_sd |
| 4995 |
|
| 4996 |
torture_comment(tctx, |
| 4997 |
"Printserver Info and winreg consistency test succeeded\n\n"); |
| 4998 |
|
| 4999 |
return true; |
| 5000 |
} |
| 5001 |
|
| 5002 |
|
| 5003 |
static bool test_PrintProcessors(struct torture_context *tctx, |
| 5004 |
struct dcerpc_binding_handle *b, |
| 5005 |
const char *environment, |
| 5006 |
struct dcerpc_binding_handle *winreg_handle, |
| 5007 |
struct policy_handle *hive_handle) |
| 5008 |
{ |
| 5009 |
union spoolss_PrintProcessorInfo *info; |
| 5010 |
uint32_t count; |
| 5011 |
int i; |
| 5012 |
|
| 5013 |
torture_comment(tctx, "Testing Print Processor Info and winreg consistency\n"); |
| 5014 |
|
| 5015 |
torture_assert(tctx, |
| 5016 |
test_EnumPrintProcessors_level(tctx, b, environment, 1, &count, &info, WERR_OK), |
| 5017 |
"failed to enum print processors level 1"); |
| 5018 |
|
| 5019 |
for (i=0; i < count; i++) { |
| 5020 |
|
| 5021 |
const char *processor_key; |
| 5022 |
struct policy_handle key_handle; |
| 5023 |
|
| 5024 |
processor_key = talloc_asprintf(tctx, "%s\\%s\\Print Processors\\%s", |
| 5025 |
TOP_LEVEL_CONTROL_ENVIRONMENTS_KEY, |
| 5026 |
environment, |
| 5027 |
info[i].info1.print_processor_name); |
| 5028 |
|
| 5029 |
torture_assert(tctx, |
| 5030 |
test_winreg_OpenKey(tctx, winreg_handle, hive_handle, processor_key, &key_handle), ""); |
| 5031 |
|
| 5032 |
/* nothing to check in there so far */ |
| 5033 |
|
| 5034 |
torture_assert(tctx, |
| 5035 |
test_winreg_CloseKey(tctx, winreg_handle, &key_handle), ""); |
| 5036 |
} |
| 5037 |
|
| 5038 |
torture_comment(tctx, "Print Processor Info and winreg consistency test succeeded\n\n"); |
| 5039 |
|
| 5040 |
return true; |
| 5041 |
} |
| 5042 |
|
| 5043 |
static bool test_GetPrinterDriver2_level(struct torture_context *tctx, |
| 5044 |
struct dcerpc_binding_handle *b, |
| 5045 |
struct policy_handle *handle, |
| 5046 |
const char *driver_name, |
| 5047 |
const char *architecture, |
| 5048 |
uint32_t level, |
| 5049 |
uint32_t client_major_version, |
| 5050 |
uint32_t client_minor_version, |
| 5051 |
union spoolss_DriverInfo *info_p, |
| 5052 |
WERROR *result); |
| 5053 |
|
| 5054 |
static const char *strip_path(const char *path) |
| 5055 |
{ |
| 5056 |
char *p; |
| 5057 |
|
| 5058 |
if (path == NULL) { |
| 5059 |
return NULL; |
| 5060 |
} |
| 5061 |
|
| 5062 |
p = strrchr(path, '\\'); |
| 5063 |
if (p) { |
| 5064 |
return p+1; |
| 5065 |
} |
| 5066 |
|
| 5067 |
return path; |
| 5068 |
} |
| 5069 |
|
| 5070 |
static const char **strip_paths(const char **path_array) |
| 5071 |
{ |
| 5072 |
int i; |
| 5073 |
|
| 5074 |
if (path_array == NULL) { |
| 5075 |
return NULL; |
| 5076 |
} |
| 5077 |
|
| 5078 |
for (i=0; path_array[i] != NULL; i++) { |
| 5079 |
path_array[i] = strip_path(path_array[i]); |
| 5080 |
} |
| 5081 |
|
| 5082 |
return path_array; |
| 5083 |
} |
| 5084 |
|
| 5085 |
static const char *driver_winreg_date(TALLOC_CTX *mem_ctx, NTTIME nt) |
| 5086 |
{ |
| 5087 |
time_t t; |
| 5088 |
struct tm *tm; |
| 5089 |
|
| 5090 |
if (nt == 0) { |
| 5091 |
return talloc_strdup(mem_ctx, "01/01/1601"); |
| 5092 |
} |
| 5093 |
|
| 5094 |
t = nt_time_to_unix(nt); |
| 5095 |
tm = localtime(&t); |
| 5096 |
|
| 5097 |
return talloc_asprintf(mem_ctx, "%02d/%02d/%04d", |
| 5098 |
tm->tm_mon + 1, tm->tm_mday, tm->tm_year + 1900); |
| 5099 |
} |
| 5100 |
|
| 5101 |
static const char *driver_winreg_version(TALLOC_CTX *mem_ctx, uint64_t v) |
| 5102 |
{ |
| 5103 |
return talloc_asprintf(mem_ctx, "%u.%u.%u.%u", |
| 5104 |
(unsigned)((v >> 48) & 0xFFFF), |
| 5105 |
(unsigned)((v >> 32) & 0xFFFF), |
| 5106 |
(unsigned)((v >> 16) & 0xFFFF), |
| 5107 |
(unsigned)(v & 0xFFFF)); |
| 5108 |
} |
| 5109 |
|
| 5110 |
static bool test_GetDriverInfo_winreg(struct torture_context *tctx, |
| 5111 |
struct dcerpc_binding_handle *b, |
| 5112 |
struct policy_handle *handle, |
| 5113 |
const char *printer_name, |
| 5114 |
const char *driver_name, |
| 5115 |
const char *environment, |
| 5116 |
enum spoolss_DriverOSVersion version, |
| 5117 |
struct dcerpc_binding_handle *winreg_handle, |
| 5118 |
struct policy_handle *hive_handle, |
| 5119 |
const char *server_name_slash) |
| 5120 |
{ |
| 5121 |
WERROR result = WERR_OK; |
| 5122 |
union spoolss_DriverInfo info; |
| 5123 |
const char *driver_key; |
| 5124 |
struct policy_handle key_handle; |
| 5125 |
|
| 5126 |
const char *driver_path; |
| 5127 |
const char *data_file; |
| 5128 |
const char *config_file; |
| 5129 |
const char *help_file; |
| 5130 |
const char **dependent_files; |
| 5131 |
|
| 5132 |
const char *driver_date; |
| 5133 |
const char *inbox_driver_date; |
| 5134 |
|
| 5135 |
const char *driver_version; |
| 5136 |
const char *inbox_driver_version; |
| 5137 |
|
| 5138 |
ZERO_STRUCT(key_handle); |
| 5139 |
|
| 5140 |
torture_comment(tctx, "Testing Driver Info and winreg consistency\n"); |
| 5141 |
|
| 5142 |
driver_key = talloc_asprintf(tctx, "%s\\%s\\Drivers\\Version-%d\\%s", |
| 5143 |
TOP_LEVEL_CONTROL_ENVIRONMENTS_KEY, |
| 5144 |
environment, |
| 5145 |
version, |
| 5146 |
driver_name); |
| 5147 |
|
| 5148 |
torture_assert(tctx, |
| 5149 |
test_winreg_OpenKey(tctx, winreg_handle, hive_handle, driver_key, &key_handle), |
| 5150 |
"failed to open driver key"); |
| 5151 |
|
| 5152 |
if (torture_setting_bool(tctx, "samba3", false) || |
| 5153 |
torture_setting_bool(tctx, "w2k3", false)) { |
| 5154 |
goto try_level6; |
| 5155 |
} |
| 5156 |
|
| 5157 |
if (handle) { |
| 5158 |
torture_assert(tctx, |
| 5159 |
test_GetPrinterDriver2_level(tctx, b, handle, driver_name, environment, 8, version, 0, &info, &result), |
| 5160 |
"failed to get driver info level 8"); |
| 5161 |
} else { |
| 5162 |
torture_assert(tctx, |
| 5163 |
test_EnumPrinterDrivers_findone(tctx, b, server_name_slash, environment, 8, driver_name, &info), |
| 5164 |
"failed to get driver info level 8"); |
| 5165 |
} |
| 5166 |
|
| 5167 |
if (W_ERROR_EQUAL(result, WERR_INVALID_LEVEL)) { |
| 5168 |
goto try_level6; |
| 5169 |
} |
| 5170 |
|
| 5171 |
driver_path = strip_path(info.info8.driver_path); |
| 5172 |
data_file = strip_path(info.info8.data_file); |
| 5173 |
config_file = strip_path(info.info8.config_file); |
| 5174 |
help_file = strip_path(info.info8.help_file); |
| 5175 |
dependent_files = strip_paths(info.info8.dependent_files); |
| 5176 |
|
| 5177 |
driver_date = driver_winreg_date(tctx, info.info8.driver_date); |
| 5178 |
inbox_driver_date = driver_winreg_date(tctx, info.info8.min_inbox_driver_ver_date); |
| 5179 |
|
| 5180 |
driver_version = driver_winreg_version(tctx, info.info8.driver_version); |
| 5181 |
inbox_driver_version = driver_winreg_version(tctx, info.info8.min_inbox_driver_ver_version); |
| 5182 |
|
| 5183 |
test_sz("Configuration File", config_file); |
| 5184 |
test_sz("Data File", data_file); |
| 5185 |
test_sz("Datatype", info.info8.default_datatype); |
| 5186 |
test_sz("Driver", driver_path); |
| 5187 |
test_sz("DriverDate", driver_date); |
| 5188 |
test_sz("DriverVersion", driver_version); |
| 5189 |
test_sz("HardwareID", info.info8.hardware_id); |
| 5190 |
test_sz("Help File", help_file); |
| 5191 |
test_sz("InfPath", info.info8.inf_path); |
| 5192 |
test_sz("Manufacturer", info.info8.manufacturer_name); |
| 5193 |
test_sz("MinInboxDriverVerDate", inbox_driver_date); |
| 5194 |
test_sz("MinInboxDriverVerVersion", inbox_driver_version); |
| 5195 |
test_sz("Monitor", info.info8.monitor_name); |
| 5196 |
test_sz("OEM URL", info.info8.manufacturer_url); |
| 5197 |
test_sz("Print Processor", info.info8.print_processor); |
| 5198 |
test_sz("Provider", info.info8.provider); |
| 5199 |
test_sz("VendorSetup", info.info8.vendor_setup); |
| 5200 |
test_multi_sz("ColorProfiles", info.info8.color_profiles); |
| 5201 |
test_multi_sz("Dependent Files", dependent_files); |
| 5202 |
test_multi_sz("CoreDependencies", info.info8.core_driver_dependencies); |
| 5203 |
test_multi_sz("Previous Names", info.info8.previous_names); |
| 5204 |
/* test_dword("Attributes", ?); */ |
| 5205 |
test_dword("PrinterDriverAttributes", info.info8.printer_driver_attributes); |
| 5206 |
test_dword("Version", info.info8.version); |
| 5207 |
/* test_dword("TempDir", ?); */ |
| 5208 |
|
| 5209 |
try_level6: |
| 5210 |
|
| 5211 |
if (handle) { |
| 5212 |
torture_assert(tctx, |
| 5213 |
test_GetPrinterDriver2_level(tctx, b, handle, driver_name, environment, 6, version, 0, &info, &result), |
| 5214 |
"failed to get driver info level 6"); |
| 5215 |
} else { |
| 5216 |
torture_assert(tctx, |
| 5217 |
test_EnumPrinterDrivers_findone(tctx, b, server_name_slash, environment, 6, driver_name, &info), |
| 5218 |
"failed to get driver info level 6"); |
| 5219 |
} |
| 5220 |
|
| 5221 |
driver_path = strip_path(info.info6.driver_path); |
| 5222 |
data_file = strip_path(info.info6.data_file); |
| 5223 |
config_file = strip_path(info.info6.config_file); |
| 5224 |
help_file = strip_path(info.info6.help_file); |
| 5225 |
dependent_files = strip_paths(info.info6.dependent_files); |
| 5226 |
|
| 5227 |
driver_date = driver_winreg_date(tctx, info.info6.driver_date); |
| 5228 |
|
| 5229 |
driver_version = driver_winreg_version(tctx, info.info6.driver_version); |
| 5230 |
|
| 5231 |
test_sz("Configuration File", config_file); |
| 5232 |
test_sz("Data File", data_file); |
| 5233 |
test_sz("Datatype", info.info6.default_datatype); |
| 5234 |
test_sz("Driver", driver_path); |
| 5235 |
if (torture_setting_bool(tctx, "w2k3", false)) { |
| 5236 |
DATA_BLOB blob = data_blob_talloc_zero(tctx, 8); |
| 5237 |
push_nttime(blob.data, 0, info.info6.driver_date); |
| 5238 |
test_binary("DriverDate", blob); |
| 5239 |
SBVAL(blob.data, 0, info.info6.driver_version); |
| 5240 |
test_binary("DriverVersion", blob); |
| 5241 |
} else { |
| 5242 |
test_sz("DriverDate", driver_date); |
| 5243 |
test_sz("DriverVersion", driver_version); |
| 5244 |
} |
| 5245 |
test_sz("HardwareID", info.info6.hardware_id); |
| 5246 |
test_sz("Help File", help_file); |
| 5247 |
test_sz("Manufacturer", info.info6.manufacturer_name); |
| 5248 |
test_sz("Monitor", info.info6.monitor_name); |
| 5249 |
test_sz("OEM URL", info.info6.manufacturer_url); |
| 5250 |
test_sz("Provider", info.info6.provider); |
| 5251 |
test_multi_sz("Dependent Files", dependent_files); |
| 5252 |
test_multi_sz("Previous Names", info.info6.previous_names); |
| 5253 |
/* test_dword("Attributes", ?); */ |
| 5254 |
test_dword("Version", info.info6.version); |
| 5255 |
/* test_dword("TempDir", ?); */ |
| 5256 |
|
| 5257 |
if (handle) { |
| 5258 |
torture_assert(tctx, |
| 5259 |
test_GetPrinterDriver2_level(tctx, b, handle, driver_name, environment, 3, version, 0, &info, &result), |
| 5260 |
"failed to get driver info level 3"); |
| 5261 |
} else { |
| 5262 |
torture_assert(tctx, |
| 5263 |
test_EnumPrinterDrivers_findone(tctx, b, server_name_slash, environment, 3, driver_name, &info), |
| 5264 |
"failed to get driver info level 3"); |
| 5265 |
} |
| 5266 |
|
| 5267 |
driver_path = strip_path(info.info3.driver_path); |
| 5268 |
data_file = strip_path(info.info3.data_file); |
| 5269 |
config_file = strip_path(info.info3.config_file); |
| 5270 |
help_file = strip_path(info.info3.help_file); |
| 5271 |
dependent_files = strip_paths(info.info3.dependent_files); |
| 5272 |
|
| 5273 |
test_sz("Configuration File", config_file); |
| 5274 |
test_sz("Data File", data_file); |
| 5275 |
test_sz("Datatype", info.info3.default_datatype); |
| 5276 |
test_sz("Driver", driver_path); |
| 5277 |
test_sz("Help File", help_file); |
| 5278 |
test_sz("Monitor", info.info3.monitor_name); |
| 5279 |
test_multi_sz("Dependent Files", dependent_files); |
| 5280 |
/* test_dword("Attributes", ?); */ |
| 5281 |
test_dword("Version", info.info3.version); |
| 5282 |
/* test_dword("TempDir", ?); */ |
| 5283 |
|
| 5284 |
|
| 5285 |
torture_assert(tctx, |
| 5286 |
test_winreg_CloseKey(tctx, winreg_handle, &key_handle), ""); |
| 5287 |
|
| 5288 |
torture_comment(tctx, "Driver Info and winreg consistency test succeeded\n\n"); |
| 5289 |
|
| 5290 |
return true; |
| 5291 |
} |
| 5292 |
|
| 5293 |
#undef test_sz |
| 5294 |
#undef test_dword |
| 5295 |
|
| 5296 |
static bool test_SetPrinterData(struct torture_context *tctx, |
| 5297 |
struct dcerpc_binding_handle *b, |
| 5298 |
struct policy_handle *handle, |
| 5299 |
const char *value_name, |
| 5300 |
enum winreg_Type type, |
| 5301 |
uint8_t *data, |
| 5302 |
uint32_t offered) |
| 5303 |
{ |
| 5304 |
struct spoolss_SetPrinterData r; |
| 5305 |
|
| 5306 |
r.in.handle = handle; |
| 5307 |
r.in.value_name = value_name; |
| 5308 |
r.in.type = type; |
| 5309 |
r.in.data = data; |
| 5310 |
r.in.offered = offered; |
| 5311 |
|
| 5312 |
torture_comment(tctx, "Testing SetPrinterData(%s)\n", |
| 5313 |
r.in.value_name); |
| 5314 |
|
| 5315 |
torture_assert_ntstatus_ok(tctx, |
| 5316 |
dcerpc_spoolss_SetPrinterData_r(b, tctx, &r), |
| 5317 |
"SetPrinterData failed"); |
| 5318 |
torture_assert_werr_ok(tctx, r.out.result, |
| 5319 |
"SetPrinterData failed"); |
| 5320 |
|
| 5321 |
return true; |
| 5322 |
} |
| 5323 |
|
| 5324 |
static bool test_SetPrinterData_matrix(struct torture_context *tctx, |
| 5325 |
struct dcerpc_binding_handle *b, |
| 5326 |
struct policy_handle *handle, |
| 5327 |
const char *printer_name, |
| 5328 |
struct dcerpc_binding_handle *winreg_handle, |
| 5329 |
struct policy_handle *hive_handle) |
| 5330 |
{ |
| 5331 |
const char *values[] = { |
| 5332 |
"spootyfoot", |
| 5333 |
"spooty\\foot", |
| 5334 |
#if 0 |
| 5335 |
/* FIXME: not working with s3 atm. */ |
| 5336 |
"spooty,foot", |
| 5337 |
"spooty,fo,ot", |
| 5338 |
#endif |
| 5339 |
"spooty foot", |
| 5340 |
#if 0 |
| 5341 |
/* FIXME: not working with s3 atm. */ |
| 5342 |
"spooty\\fo,ot", |
| 5343 |
"spooty,fo\\ot" |
| 5344 |
#endif |
| 5345 |
}; |
| 5346 |
int i; |
| 5347 |
|
| 5348 |
for (i=0; i < ARRAY_SIZE(values); i++) { |
| 5349 |
|
| 5350 |
enum winreg_Type type, expected_type = REG_SZ; |
| 5351 |
DATA_BLOB blob; |
| 5352 |
uint8_t *data; |
| 5353 |
uint32_t needed; |
| 5354 |
|
| 5355 |
torture_assert(tctx, push_reg_sz(tctx, &blob, "dog"), ""); |
| 5356 |
type = REG_SZ; |
| 5357 |
|
| 5358 |
torture_assert(tctx, |
| 5359 |
test_SetPrinterData(tctx, b, handle, values[i], REG_SZ, blob.data, blob.length), |
| 5360 |
"SetPrinterData failed"); |
| 5361 |
|
| 5362 |
torture_assert(tctx, |
| 5363 |
test_GetPrinterData_checktype(tctx, b, handle, values[i], &expected_type, &type, &data, &needed), |
| 5364 |
"GetPrinterData failed"); |
| 5365 |
|
| 5366 |
torture_assert_int_equal(tctx, type, REG_SZ, "type mismatch"); |
| 5367 |
torture_assert_int_equal(tctx, needed, blob.length, "size mismatch"); |
| 5368 |
torture_assert_mem_equal(tctx, data, blob.data, blob.length, "buffer mismatch"); |
| 5369 |
|
| 5370 |
if (winreg_handle && hive_handle) { |
| 5371 |
|
| 5372 |
enum winreg_Type w_type; |
| 5373 |
uint32_t w_size; |
| 5374 |
uint32_t w_length; |
| 5375 |
uint8_t *w_data; |
| 5376 |
|
| 5377 |
torture_assert(tctx, |
| 5378 |
test_winreg_query_printerdata(tctx, winreg_handle, hive_handle, |
| 5379 |
printer_name, "PrinterDriverData", values[i], |
| 5380 |
&w_type, &w_size, &w_length, &w_data), ""); |
| 5381 |
|
| 5382 |
torture_assert_int_equal(tctx, w_type, REG_SZ, "winreg type mismatch"); |
| 5383 |
torture_assert_int_equal(tctx, w_size, blob.length, "winreg size mismatch"); |
| 5384 |
torture_assert_int_equal(tctx, w_length, blob.length, "winreg length mismatch"); |
| 5385 |
torture_assert_mem_equal(tctx, w_data, blob.data, blob.length, "winreg buffer mismatch"); |
| 5386 |
} |
| 5387 |
|
| 5388 |
torture_assert(tctx, |
| 5389 |
test_DeletePrinterData(tctx, b, handle, values[i]), |
| 5390 |
"DeletePrinterData failed"); |
| 5391 |
} |
| 5392 |
|
| 5393 |
return true; |
| 5394 |
} |
| 5395 |
|
| 5396 |
|
| 5397 |
static bool test_EnumPrinterKey(struct torture_context *tctx, |
| 5398 |
struct dcerpc_binding_handle *b, |
| 5399 |
struct policy_handle *handle, |
| 5400 |
const char *key_name, |
| 5401 |
const char ***array); |
| 5402 |
|
| 5403 |
static bool test_SetPrinterDataEx(struct torture_context *tctx, |
| 5404 |
struct dcerpc_binding_handle *b, |
| 5405 |
struct policy_handle *handle, |
| 5406 |
const char *key_name, |
| 5407 |
const char *value_name, |
| 5408 |
enum winreg_Type type, |
| 5409 |
uint8_t *data, |
| 5410 |
uint32_t offered) |
| 5411 |
{ |
| 5412 |
NTSTATUS status; |
| 5413 |
struct spoolss_SetPrinterDataEx r; |
| 5414 |
|
| 5415 |
r.in.handle = handle; |
| 5416 |
r.in.key_name = key_name; |
| 5417 |
r.in.value_name = value_name; |
| 5418 |
r.in.type = type; |
| 5419 |
r.in.data = data; |
| 5420 |
r.in.offered = offered; |
| 5421 |
|
| 5422 |
torture_comment(tctx, "Testing SetPrinterDataEx(%s - %s) type: %s, offered: 0x%08x\n", |
| 5423 |
r.in.key_name, r.in.value_name, str_regtype(r.in.type), r.in.offered); |
| 5424 |
|
| 5425 |
status = dcerpc_spoolss_SetPrinterDataEx_r(b, tctx, &r); |
| 5426 |
|
| 5427 |
torture_assert_ntstatus_ok(tctx, status, "SetPrinterDataEx failed"); |
| 5428 |
torture_assert_werr_ok(tctx, r.out.result, "SetPrinterDataEx failed"); |
| 5429 |
|
| 5430 |
return true; |
| 5431 |
} |
| 5432 |
|
| 5433 |
static bool test_SetPrinterDataEx_keys(struct torture_context *tctx, |
| 5434 |
struct dcerpc_pipe *p, |
| 5435 |
struct policy_handle *handle) |
| 5436 |
{ |
| 5437 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 5438 |
const char *value_name = "dog"; |
| 5439 |
const char *keys[] = { |
| 5440 |
"torturedataex", |
| 5441 |
"torture data ex", |
| 5442 |
"torturedataex_with_subkey\\subkey", |
| 5443 |
"torturedataex_with_subkey\\subkey:0", |
| 5444 |
"torturedataex_with_subkey\\subkey:1", |
| 5445 |
"torturedataex_with_subkey\\subkey\\subsubkey", |
| 5446 |
"torturedataex_with_subkey\\subkey\\subsubkey:0", |
| 5447 |
"torturedataex_with_subkey\\subkey\\subsubkey:1", |
| 5448 |
"torture,data", |
| 5449 |
"torture,data,ex", |
| 5450 |
"torture,data\\ex", |
| 5451 |
"torture\\data,ex", |
| 5452 |
"torture/data", |
| 5453 |
"torture/data ex", |
| 5454 |
"torture/data ex/sub", |
| 5455 |
"torture//data", |
| 5456 |
"torture//data ex", |
| 5457 |
"torture//data ex/sub", |
| 5458 |
"torture//data ex//sub", |
| 5459 |
}; |
| 5460 |
int i; |
| 5461 |
|
| 5462 |
for (i=0; i < ARRAY_SIZE(keys); i++) { |
| 5463 |
|
| 5464 |
char *c; |
| 5465 |
const char *key; |
| 5466 |
enum winreg_Type type; |
| 5467 |
DATA_BLOB blob_in, blob_out; |
| 5468 |
const char **subkeys; |
| 5469 |
uint32_t ecount; |
| 5470 |
struct spoolss_PrinterEnumValues *einfo; |
| 5471 |
uint32_t needed; |
| 5472 |
|
| 5473 |
blob_in = data_blob_talloc(tctx, NULL, 42); |
| 5474 |
|
| 5475 |
generate_random_buffer(blob_in.data, blob_in.length); |
| 5476 |
|
| 5477 |
torture_assert(tctx, |
| 5478 |
test_SetPrinterDataEx(tctx, b, handle, keys[i], value_name, REG_BINARY, blob_in.data, blob_in.length), |
| 5479 |
"failed to call SetPrinterDataEx"); |
| 5480 |
|
| 5481 |
torture_assert(tctx, |
| 5482 |
test_GetPrinterDataEx(tctx, p, handle, keys[i], value_name, &type, &blob_out.data, &needed), |
| 5483 |
"failed to call GetPrinterDataEx"); |
| 5484 |
|
| 5485 |
blob_out.length = needed; |
| 5486 |
torture_assert(tctx, |
| 5487 |
test_EnumPrinterDataEx(tctx, b, handle, keys[i], &ecount, &einfo), |
| 5488 |
"failed to call EnumPrinterDataEx"); |
| 5489 |
|
| 5490 |
torture_assert_int_equal(tctx, type, REG_BINARY, "type mismatch"); |
| 5491 |
torture_assert_int_equal(tctx, blob_out.length, blob_in.length, "size mismatch"); |
| 5492 |
torture_assert_mem_equal(tctx, blob_out.data, blob_in.data, blob_in.length, "buffer mismatch"); |
| 5493 |
|
| 5494 |
torture_assert_int_equal(tctx, ecount, 1, "unexpected enum count"); |
| 5495 |
torture_assert_str_equal(tctx, einfo[0].value_name, value_name, "value_name mismatch"); |
| 5496 |
torture_assert_int_equal(tctx, einfo[0].value_name_len, strlen_m_term(value_name)*2, "unexpected value_name_len"); |
| 5497 |
torture_assert_int_equal(tctx, einfo[0].type, REG_BINARY, "type mismatch"); |
| 5498 |
torture_assert_int_equal(tctx, einfo[0].data_length, blob_in.length, "size mismatch"); |
| 5499 |
if (einfo[0].data_length > 0) { |
| 5500 |
torture_assert_mem_equal(tctx, einfo[0].data->data, blob_in.data, blob_in.length, "buffer mismatch"); |
| 5501 |
} |
| 5502 |
|
| 5503 |
key = talloc_strdup(tctx, keys[i]); |
| 5504 |
|
| 5505 |
if (!test_DeletePrinterDataEx(tctx, b, handle, keys[i], value_name)) { |
| 5506 |
return false; |
| 5507 |
} |
| 5508 |
|
| 5509 |
c = strchr(key, '\\'); |
| 5510 |
if (c) { |
| 5511 |
int k; |
| 5512 |
|
| 5513 |
/* we have subkeys */ |
| 5514 |
|
| 5515 |
*c = 0; |
| 5516 |
|
| 5517 |
if (!test_EnumPrinterKey(tctx, b, handle, key, &subkeys)) { |
| 5518 |
return false; |
| 5519 |
} |
| 5520 |
|
| 5521 |
for (k=0; subkeys && subkeys[k]; k++) { |
| 5522 |
|
| 5523 |
const char *current_key = talloc_asprintf(tctx, "%s\\%s", key, subkeys[k]); |
| 5524 |
|
| 5525 |
if (!test_DeletePrinterKey(tctx, b, handle, current_key)) { |
| 5526 |
return false; |
| 5527 |
} |
| 5528 |
} |
| 5529 |
|
| 5530 |
if (!test_DeletePrinterKey(tctx, b, handle, key)) { |
| 5531 |
return false; |
| 5532 |
} |
| 5533 |
|
| 5534 |
} else { |
| 5535 |
if (!test_DeletePrinterKey(tctx, b, handle, key)) { |
| 5536 |
return false; |
| 5537 |
} |
| 5538 |
} |
| 5539 |
} |
| 5540 |
|
| 5541 |
return true; |
| 5542 |
} |
| 5543 |
|
| 5544 |
static bool test_SetPrinterDataEx_values(struct torture_context *tctx, |
| 5545 |
struct dcerpc_pipe *p, |
| 5546 |
struct policy_handle *handle) |
| 5547 |
{ |
| 5548 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 5549 |
const char *key = "torturedataex"; |
| 5550 |
const char *values[] = { |
| 5551 |
"torture_value", |
| 5552 |
"torture value", |
| 5553 |
"torture,value", |
| 5554 |
"torture/value", |
| 5555 |
"torture\\value", |
| 5556 |
"torture\\\\value" |
| 5557 |
}; |
| 5558 |
int i; |
| 5559 |
|
| 5560 |
for (i=0; i < ARRAY_SIZE(values); i++) { |
| 5561 |
|
| 5562 |
enum winreg_Type type = REG_NONE; |
| 5563 |
DATA_BLOB blob_in = data_blob_null; |
| 5564 |
DATA_BLOB blob_out = data_blob_null; |
| 5565 |
uint32_t ecount; |
| 5566 |
struct spoolss_PrinterEnumValues *einfo; |
| 5567 |
uint32_t needed = 0; |
| 5568 |
|
| 5569 |
if (torture_setting_bool(tctx, "samba3", false) || |
| 5570 |
torture_setting_bool(tctx, "samba4", false)) { |
| 5571 |
char *q; |
| 5572 |
q = strrchr(values[i], ','); |
| 5573 |
if (q) { |
| 5574 |
torture_comment( |
| 5575 |
tctx, |
| 5576 |
"skipping valuename '%s' including ',' " |
| 5577 |
"character against Samba\n", |
| 5578 |
values[i]); |
| 5579 |
continue; |
| 5580 |
} |
| 5581 |
} |
| 5582 |
|
| 5583 |
blob_in = data_blob_talloc(tctx, NULL, 42); |
| 5584 |
|
| 5585 |
generate_random_buffer(blob_in.data, blob_in.length); |
| 5586 |
|
| 5587 |
torture_assert(tctx, |
| 5588 |
test_SetPrinterDataEx(tctx, b, handle, key, values[i], REG_BINARY, blob_in.data, blob_in.length), |
| 5589 |
"failed to call SetPrinterDataEx"); |
| 5590 |
|
| 5591 |
torture_assert(tctx, |
| 5592 |
test_GetPrinterDataEx(tctx, p, handle, key, values[i], &type, &blob_out.data, &needed), |
| 5593 |
"failed to call GetPrinterDataEx"); |
| 5594 |
|
| 5595 |
blob_out.length = needed; |
| 5596 |
torture_assert(tctx, |
| 5597 |
test_EnumPrinterDataEx(tctx, b, handle, key, &ecount, &einfo), |
| 5598 |
"failed to call EnumPrinterDataEx"); |
| 5599 |
|
| 5600 |
torture_assert_int_equal(tctx, type, REG_BINARY, "type mismatch"); |
| 5601 |
torture_assert_int_equal(tctx, blob_out.length, blob_in.length, "size mismatch"); |
| 5602 |
torture_assert_mem_equal(tctx, blob_out.data, blob_in.data, blob_in.length, "buffer mismatch"); |
| 5603 |
|
| 5604 |
torture_assert_int_equal(tctx, ecount, 1, "unexpected enum count"); |
| 5605 |
torture_assert_str_equal(tctx, einfo[0].value_name, values[i], "value_name mismatch"); |
| 5606 |
torture_assert_int_equal(tctx, einfo[0].value_name_len, strlen_m_term(values[i])*2, "unexpected value_name_len"); |
| 5607 |
torture_assert_int_equal(tctx, einfo[0].type, REG_BINARY, "type mismatch"); |
| 5608 |
torture_assert_int_equal(tctx, einfo[0].data_length, blob_in.length, "size mismatch"); |
| 5609 |
if (einfo[0].data_length > 0) { |
| 5610 |
torture_assert_mem_equal(tctx, einfo[0].data->data, blob_in.data, blob_in.length, "buffer mismatch"); |
| 5611 |
} |
| 5612 |
|
| 5613 |
torture_assert(tctx, |
| 5614 |
test_DeletePrinterDataEx(tctx, b, handle, key, values[i]), |
| 5615 |
"failed to call DeletePrinterDataEx"); |
| 5616 |
} |
| 5617 |
|
| 5618 |
return true; |
| 5619 |
} |
| 5620 |
|
| 5621 |
|
| 5622 |
static bool test_SetPrinterDataEx_matrix(struct torture_context *tctx, |
| 5623 |
struct dcerpc_pipe *p, |
| 5624 |
struct policy_handle *handle, |
| 5625 |
const char *printername, |
| 5626 |
struct dcerpc_binding_handle *winreg_handle, |
| 5627 |
struct policy_handle *hive_handle) |
| 5628 |
{ |
| 5629 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 5630 |
const char *value_name = "dog"; |
| 5631 |
const char *key_name = "torturedataex"; |
| 5632 |
enum winreg_Type types[] = { |
| 5633 |
REG_SZ, |
| 5634 |
REG_MULTI_SZ, |
| 5635 |
REG_DWORD, |
| 5636 |
REG_BINARY |
| 5637 |
}; |
| 5638 |
const char *str = "abcdefghi"; |
| 5639 |
size_t t, s; |
| 5640 |
|
| 5641 |
for (t=0; t < ARRAY_SIZE(types); t++) { |
| 5642 |
for (s=0; s < strlen(str); s++) { |
| 5643 |
|
| 5644 |
enum winreg_Type type; |
| 5645 |
const char *string = talloc_strndup(tctx, str, s); |
| 5646 |
const char *array[2]; |
| 5647 |
DATA_BLOB blob = data_blob_string_const(string); |
| 5648 |
DATA_BLOB data; |
| 5649 |
uint8_t *data_out; |
| 5650 |
uint32_t needed, offered = 0; |
| 5651 |
uint32_t ecount; |
| 5652 |
struct spoolss_PrinterEnumValues *einfo; |
| 5653 |
|
| 5654 |
array[0] = talloc_strdup(tctx, string); |
| 5655 |
array[1] = NULL; |
| 5656 |
|
| 5657 |
if (types[t] == REG_DWORD) { |
| 5658 |
s = 0xffff; |
| 5659 |
} |
| 5660 |
|
| 5661 |
switch (types[t]) { |
| 5662 |
case REG_BINARY: |
| 5663 |
data = blob; |
| 5664 |
offered = blob.length; |
| 5665 |
break; |
| 5666 |
case REG_DWORD: |
| 5667 |
data = data_blob_talloc(tctx, NULL, 4); |
| 5668 |
SIVAL(data.data, 0, 0x12345678); |
| 5669 |
offered = 4; |
| 5670 |
break; |
| 5671 |
case REG_SZ: |
| 5672 |
torture_assert(tctx, push_reg_sz(tctx, &data, string), ""); |
| 5673 |
type = REG_SZ; |
| 5674 |
offered = data.length; |
| 5675 |
/*strlen_m_term(data.string)*2;*/ |
| 5676 |
break; |
| 5677 |
case REG_MULTI_SZ: |
| 5678 |
torture_assert(tctx, push_reg_multi_sz(tctx, &data, array), ""); |
| 5679 |
type = REG_MULTI_SZ; |
| 5680 |
offered = data.length; |
| 5681 |
break; |
| 5682 |
default: |
| 5683 |
torture_fail(tctx, talloc_asprintf(tctx, "type %d untested\n", types[t])); |
| 5684 |
} |
| 5685 |
|
| 5686 |
torture_assert(tctx, |
| 5687 |
test_SetPrinterDataEx(tctx, b, handle, key_name, value_name, types[t], data.data, offered), |
| 5688 |
"failed to call SetPrinterDataEx"); |
| 5689 |
|
| 5690 |
torture_assert(tctx, |
| 5691 |
test_GetPrinterDataEx_checktype(tctx, p, handle, key_name, value_name, &types[t], &type, &data_out, &needed), |
| 5692 |
"failed to call GetPrinterDataEx"); |
| 5693 |
|
| 5694 |
torture_assert(tctx, |
| 5695 |
test_EnumPrinterDataEx(tctx, b, handle, key_name, &ecount, &einfo), |
| 5696 |
"failed to call EnumPrinterDataEx"); |
| 5697 |
|
| 5698 |
torture_assert_int_equal(tctx, types[t], type, "type mismatch"); |
| 5699 |
torture_assert_int_equal(tctx, needed, offered, "size mismatch"); |
| 5700 |
torture_assert_mem_equal(tctx, data_out, data.data, offered, "buffer mismatch"); |
| 5701 |
|
| 5702 |
torture_assert_int_equal(tctx, ecount, 1, "unexpected enum count"); |
| 5703 |
torture_assert_str_equal(tctx, einfo[0].value_name, value_name, "value_name mismatch"); |
| 5704 |
torture_assert_int_equal(tctx, einfo[0].value_name_len, strlen_m_term(value_name)*2, "unexpected value_name_len"); |
| 5705 |
torture_assert_int_equal(tctx, einfo[0].type, types[t], "type mismatch"); |
| 5706 |
torture_assert_int_equal(tctx, einfo[0].data_length, offered, "size mismatch"); |
| 5707 |
if (einfo[0].data_length > 0) { |
| 5708 |
torture_assert_mem_equal(tctx, einfo[0].data->data, data.data, offered, "buffer mismatch"); |
| 5709 |
} |
| 5710 |
|
| 5711 |
if (winreg_handle && hive_handle) { |
| 5712 |
enum winreg_Type w_type; |
| 5713 |
uint32_t w_size; |
| 5714 |
uint32_t w_length; |
| 5715 |
uint8_t *w_data; |
| 5716 |
|
| 5717 |
torture_assert(tctx, |
| 5718 |
test_winreg_query_printerdata(tctx, winreg_handle, hive_handle, |
| 5719 |
printername, key_name, value_name, |
| 5720 |
&w_type, &w_size, &w_length, &w_data), ""); |
| 5721 |
|
| 5722 |
torture_assert_int_equal(tctx, w_type, types[t], "winreg type mismatch"); |
| 5723 |
torture_assert_int_equal(tctx, w_size, offered, "winreg size mismatch"); |
| 5724 |
torture_assert_int_equal(tctx, w_length, offered, "winreg length mismatch"); |
| 5725 |
torture_assert_mem_equal(tctx, w_data, data.data, offered, "winreg buffer mismatch"); |
| 5726 |
} |
| 5727 |
|
| 5728 |
torture_assert(tctx, |
| 5729 |
test_DeletePrinterDataEx(tctx, b, handle, key_name, value_name), |
| 5730 |
"failed to call DeletePrinterDataEx"); |
| 5731 |
} |
| 5732 |
} |
| 5733 |
|
| 5734 |
return true; |
| 5735 |
} |
| 5736 |
|
| 5737 |
static bool test_PrinterData_winreg(struct torture_context *tctx, |
| 5738 |
struct dcerpc_pipe *p, |
| 5739 |
struct policy_handle *handle, |
| 5740 |
const char *printer_name) |
| 5741 |
{ |
| 5742 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 5743 |
struct dcerpc_pipe *p2; |
| 5744 |
bool ret = true; |
| 5745 |
struct policy_handle hive_handle; |
| 5746 |
struct dcerpc_binding_handle *b2; |
| 5747 |
|
| 5748 |
torture_assert_ntstatus_ok(tctx, |
| 5749 |
torture_rpc_connection(tctx, &p2, &ndr_table_winreg), |
| 5750 |
"could not open winreg pipe"); |
| 5751 |
b2 = p2->binding_handle; |
| 5752 |
|
| 5753 |
torture_assert(tctx, test_winreg_OpenHKLM(tctx, b2, &hive_handle), ""); |
| 5754 |
|
| 5755 |
ret &= test_SetPrinterData_matrix(tctx, b, handle, printer_name, b2, &hive_handle); |
| 5756 |
ret &= test_SetPrinterDataEx_matrix(tctx, p, handle, printer_name, b2, &hive_handle); |
| 5757 |
|
| 5758 |
test_winreg_CloseKey(tctx, b2, &hive_handle); |
| 5759 |
|
| 5760 |
talloc_free(p2); |
| 5761 |
|
| 5762 |
return ret; |
| 5763 |
} |
| 5764 |
|
| 5765 |
static bool test_Forms_winreg(struct torture_context *tctx, |
| 5766 |
struct dcerpc_binding_handle *b, |
| 5767 |
struct policy_handle *handle, |
| 5768 |
bool print_server, |
| 5769 |
const char *printer_name) |
| 5770 |
{ |
| 5771 |
struct dcerpc_pipe *p2; |
| 5772 |
bool ret = true; |
| 5773 |
struct policy_handle hive_handle; |
| 5774 |
struct dcerpc_binding_handle *b2; |
| 5775 |
|
| 5776 |
torture_assert_ntstatus_ok(tctx, |
| 5777 |
torture_rpc_connection(tctx, &p2, &ndr_table_winreg), |
| 5778 |
"could not open winreg pipe"); |
| 5779 |
b2 = p2->binding_handle; |
| 5780 |
|
| 5781 |
torture_assert(tctx, test_winreg_OpenHKLM(tctx, b2, &hive_handle), ""); |
| 5782 |
|
| 5783 |
ret = test_Forms(tctx, b, handle, print_server, printer_name, b2, &hive_handle); |
| 5784 |
|
| 5785 |
test_winreg_CloseKey(tctx, b2, &hive_handle); |
| 5786 |
|
| 5787 |
talloc_free(p2); |
| 5788 |
|
| 5789 |
return ret; |
| 5790 |
} |
| 5791 |
|
| 5792 |
static bool test_PrinterInfo_winreg(struct torture_context *tctx, |
| 5793 |
struct dcerpc_pipe *p, |
| 5794 |
struct policy_handle *handle, |
| 5795 |
const char *printer_name) |
| 5796 |
{ |
| 5797 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 5798 |
struct dcerpc_pipe *p2; |
| 5799 |
bool ret = true; |
| 5800 |
struct policy_handle hive_handle; |
| 5801 |
struct dcerpc_binding_handle *b2; |
| 5802 |
|
| 5803 |
torture_assert_ntstatus_ok(tctx, |
| 5804 |
torture_rpc_connection(tctx, &p2, &ndr_table_winreg), |
| 5805 |
"could not open winreg pipe"); |
| 5806 |
b2 = p2->binding_handle; |
| 5807 |
|
| 5808 |
torture_assert(tctx, test_winreg_OpenHKLM(tctx, b2, &hive_handle), ""); |
| 5809 |
|
| 5810 |
ret = test_GetPrinterInfo_winreg(tctx, b, handle, printer_name, b2, &hive_handle); |
| 5811 |
|
| 5812 |
test_winreg_CloseKey(tctx, b2, &hive_handle); |
| 5813 |
|
| 5814 |
talloc_free(p2); |
| 5815 |
|
| 5816 |
return ret; |
| 5817 |
} |
| 5818 |
|
| 5819 |
static bool test_PrintserverInfo_winreg(struct torture_context *tctx, |
| 5820 |
struct dcerpc_pipe *p, |
| 5821 |
struct policy_handle *handle) |
| 5822 |
{ |
| 5823 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 5824 |
struct dcerpc_pipe *p2; |
| 5825 |
bool ret = true; |
| 5826 |
struct policy_handle hive_handle; |
| 5827 |
struct dcerpc_binding_handle *b2; |
| 5828 |
|
| 5829 |
torture_assert_ntstatus_ok(tctx, |
| 5830 |
torture_rpc_connection(tctx, &p2, &ndr_table_winreg), |
| 5831 |
"could not open winreg pipe"); |
| 5832 |
b2 = p2->binding_handle; |
| 5833 |
|
| 5834 |
torture_assert(tctx, test_winreg_OpenHKLM(tctx, b2, &hive_handle), ""); |
| 5835 |
|
| 5836 |
ret = test_GetPrintserverInfo_winreg(tctx, b, handle, b2, &hive_handle); |
| 5837 |
|
| 5838 |
test_winreg_CloseKey(tctx, b2, &hive_handle); |
| 5839 |
|
| 5840 |
talloc_free(p2); |
| 5841 |
|
| 5842 |
return ret; |
| 5843 |
} |
| 5844 |
|
| 5845 |
|
| 5846 |
static bool test_DriverInfo_winreg(struct torture_context *tctx, |
| 5847 |
struct dcerpc_pipe *p, |
| 5848 |
struct policy_handle *handle, |
| 5849 |
const char *printer_name, |
| 5850 |
const char *driver_name, |
| 5851 |
const char *environment, |
| 5852 |
enum spoolss_DriverOSVersion version) |
| 5853 |
{ |
| 5854 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 5855 |
struct dcerpc_pipe *p2; |
| 5856 |
bool ret = true; |
| 5857 |
struct policy_handle hive_handle; |
| 5858 |
struct dcerpc_binding_handle *b2; |
| 5859 |
|
| 5860 |
torture_assert_ntstatus_ok(tctx, |
| 5861 |
torture_rpc_connection(tctx, &p2, &ndr_table_winreg), |
| 5862 |
"could not open winreg pipe"); |
| 5863 |
b2 = p2->binding_handle; |
| 5864 |
|
| 5865 |
torture_assert(tctx, test_winreg_OpenHKLM(tctx, b2, &hive_handle), ""); |
| 5866 |
|
| 5867 |
ret = test_GetDriverInfo_winreg(tctx, b, handle, printer_name, driver_name, environment, version, b2, &hive_handle, NULL); |
| 5868 |
|
| 5869 |
test_winreg_CloseKey(tctx, b2, &hive_handle); |
| 5870 |
|
| 5871 |
talloc_free(p2); |
| 5872 |
|
| 5873 |
return ret; |
| 5874 |
} |
| 5875 |
|
| 5876 |
static bool test_PrintProcessors_winreg(struct torture_context *tctx, |
| 5877 |
struct dcerpc_binding_handle *b, |
| 5878 |
const char *environment) |
| 5879 |
{ |
| 5880 |
struct dcerpc_pipe *p2; |
| 5881 |
bool ret = true; |
| 5882 |
struct policy_handle hive_handle; |
| 5883 |
struct dcerpc_binding_handle *b2; |
| 5884 |
|
| 5885 |
torture_assert_ntstatus_ok(tctx, |
| 5886 |
torture_rpc_connection(tctx, &p2, &ndr_table_winreg), |
| 5887 |
"could not open winreg pipe"); |
| 5888 |
b2 = p2->binding_handle; |
| 5889 |
|
| 5890 |
torture_assert(tctx, test_winreg_OpenHKLM(tctx, b2, &hive_handle), ""); |
| 5891 |
|
| 5892 |
ret = test_PrintProcessors(tctx, b, environment, b2, &hive_handle); |
| 5893 |
|
| 5894 |
test_winreg_CloseKey(tctx, b2, &hive_handle); |
| 5895 |
|
| 5896 |
talloc_free(p2); |
| 5897 |
|
| 5898 |
return ret; |
| 5899 |
} |
| 5900 |
|
| 5901 |
static bool test_PrinterData_DsSpooler(struct torture_context *tctx, |
| 5902 |
struct dcerpc_pipe *p, |
| 5903 |
struct policy_handle *handle, |
| 5904 |
const char *printer_name) |
| 5905 |
{ |
| 5906 |
struct spoolss_SetPrinterInfoCtr info_ctr; |
| 5907 |
struct spoolss_DevmodeContainer devmode_ctr; |
| 5908 |
struct sec_desc_buf secdesc_ctr; |
| 5909 |
union spoolss_SetPrinterInfo sinfo; |
| 5910 |
union spoolss_PrinterInfo info; |
| 5911 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 5912 |
const char *pname; |
| 5913 |
|
| 5914 |
ZERO_STRUCT(info_ctr); |
| 5915 |
ZERO_STRUCT(devmode_ctr); |
| 5916 |
ZERO_STRUCT(secdesc_ctr); |
| 5917 |
|
| 5918 |
torture_comment(tctx, "Testing DsSpooler <-> SetPrinter relations\n"); |
| 5919 |
|
| 5920 |
torture_assert(tctx, |
| 5921 |
test_GetPrinter_level(tctx, b, handle, 2, &info), |
| 5922 |
"failed to query Printer level 2"); |
| 5923 |
|
| 5924 |
torture_assert(tctx, |
| 5925 |
PrinterInfo_to_SetPrinterInfo(tctx, &info, 2, &sinfo), |
| 5926 |
"failed to convert"); |
| 5927 |
|
| 5928 |
info_ctr.level = 2; |
| 5929 |
info_ctr.info = sinfo; |
| 5930 |
|
| 5931 |
#define TEST_SZ(wname, iname) \ |
| 5932 |
do {\ |
| 5933 |
enum winreg_Type type;\ |
| 5934 |
uint8_t *data;\ |
| 5935 |
uint32_t needed;\ |
| 5936 |
DATA_BLOB blob;\ |
| 5937 |
const char *str;\ |
| 5938 |
torture_assert(tctx,\ |
| 5939 |
test_GetPrinterDataEx(tctx, p, handle, "DsSpooler", wname, &type, &data, &needed),\ |
| 5940 |
"failed to query");\ |
| 5941 |
torture_assert_int_equal(tctx, type, REG_SZ, "unexpected type");\ |
| 5942 |
blob = data_blob_const(data, needed);\ |
| 5943 |
torture_assert(tctx,\ |
| 5944 |
pull_reg_sz(tctx, &blob, &str),\ |
| 5945 |
"failed to pull REG_SZ");\ |
| 5946 |
torture_assert_str_equal(tctx, str, iname, "unexpected result");\ |
| 5947 |
} while(0); |
| 5948 |
|
| 5949 |
|
| 5950 |
#define TEST_SET_SZ(wname, iname, val) \ |
| 5951 |
do {\ |
| 5952 |
enum winreg_Type type;\ |
| 5953 |
uint8_t *data;\ |
| 5954 |
uint32_t needed;\ |
| 5955 |
DATA_BLOB blob;\ |
| 5956 |
const char *str;\ |
| 5957 |
sinfo.info2->iname = val;\ |
| 5958 |
torture_assert(tctx,\ |
| 5959 |
test_SetPrinter(tctx, b, handle, &info_ctr, &devmode_ctr, &secdesc_ctr, 0),\ |
| 5960 |
"failed to call SetPrinter");\ |
| 5961 |
torture_assert(tctx,\ |
| 5962 |
test_GetPrinterDataEx(tctx, p, handle, "DsSpooler", wname, &type, &data, &needed),\ |
| 5963 |
"failed to query");\ |
| 5964 |
torture_assert_int_equal(tctx, type, REG_SZ, "unexpected type");\ |
| 5965 |
blob = data_blob_const(data, needed);\ |
| 5966 |
torture_assert(tctx,\ |
| 5967 |
pull_reg_sz(tctx, &blob, &str),\ |
| 5968 |
"failed to pull REG_SZ");\ |
| 5969 |
torture_assert_str_equal(tctx, str, val, "unexpected result");\ |
| 5970 |
} while(0); |
| 5971 |
|
| 5972 |
#define TEST_SET_DWORD(wname, iname, val) \ |
| 5973 |
do {\ |
| 5974 |
enum winreg_Type type;\ |
| 5975 |
uint8_t *data;\ |
| 5976 |
uint32_t needed;\ |
| 5977 |
uint32_t value;\ |
| 5978 |
sinfo.info2->iname = val;\ |
| 5979 |
torture_assert(tctx,\ |
| 5980 |
test_SetPrinter(tctx, b, handle, &info_ctr, &devmode_ctr, &secdesc_ctr, 0),\ |
| 5981 |
"failed to call SetPrinter");\ |
| 5982 |
torture_assert(tctx,\ |
| 5983 |
test_GetPrinterDataEx(tctx, p, handle, "DsSpooler", wname, &type, &data, &needed),\ |
| 5984 |
"failed to query");\ |
| 5985 |
torture_assert_int_equal(tctx, type, REG_DWORD, "unexpected type");\ |
| 5986 |
torture_assert_int_equal(tctx, needed, 4, "unexpected length");\ |
| 5987 |
value = IVAL(data, 0); \ |
| 5988 |
torture_assert_int_equal(tctx, value, val, "unexpected result");\ |
| 5989 |
} while(0); |
| 5990 |
|
| 5991 |
TEST_SET_SZ("description", comment, "newval"); |
| 5992 |
TEST_SET_SZ("location", location, "newval"); |
| 5993 |
TEST_SET_SZ("driverName", drivername, "newval"); |
| 5994 |
/* TEST_SET_DWORD("priority", priority, 25); */ |
| 5995 |
|
| 5996 |
torture_assert(tctx, |
| 5997 |
test_GetPrinter_level(tctx, b, handle, 2, &info), |
| 5998 |
"failed to query Printer level 2"); |
| 5999 |
|
| 6000 |
TEST_SZ("description", info.info2.comment); |
| 6001 |
TEST_SZ("driverName", info.info2.drivername); |
| 6002 |
TEST_SZ("location", info.info2.location); |
| 6003 |
|
| 6004 |
pname = strrchr(info.info2.printername, '\\'); |
| 6005 |
if (pname == NULL) { |
| 6006 |
pname = info.info2.printername; |
| 6007 |
} else { |
| 6008 |
pname++; |
| 6009 |
} |
| 6010 |
TEST_SZ("printerName", pname); |
| 6011 |
/* TEST_SZ("printSeparatorFile", info.info2.sepfile); */ |
| 6012 |
/* TEST_SZ("printShareName", info.info2.sharename); */ |
| 6013 |
|
| 6014 |
/* FIXME gd: complete the list */ |
| 6015 |
|
| 6016 |
#undef TEST_SZ |
| 6017 |
#undef TEST_SET_SZ |
| 6018 |
#undef TEST_DWORD |
| 6019 |
|
| 6020 |
torture_comment(tctx, "DsSpooler <-> SetPrinter relations test succeeded\n\n"); |
| 6021 |
|
| 6022 |
return true; |
| 6023 |
} |
| 6024 |
|
| 6025 |
static bool test_print_processors_winreg(struct torture_context *tctx, |
| 6026 |
void *private_data) |
| 6027 |
{ |
| 6028 |
struct test_spoolss_context *ctx = |
| 6029 |
talloc_get_type_abort(private_data, struct test_spoolss_context); |
| 6030 |
struct dcerpc_pipe *p = ctx->spoolss_pipe; |
| 6031 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 6032 |
|
| 6033 |
return test_PrintProcessors_winreg(tctx, b, ctx->environment); |
| 6034 |
} |
| 6035 |
|
| 6036 |
static bool test_AddPrintProcessor(struct torture_context *tctx, |
| 6037 |
struct dcerpc_binding_handle *b, |
| 6038 |
const char *environment, |
| 6039 |
const char *path_name, |
| 6040 |
const char *print_processor_name, |
| 6041 |
WERROR expected_error) |
| 6042 |
{ |
| 6043 |
struct spoolss_AddPrintProcessor r; |
| 6044 |
|
| 6045 |
r.in.server = NULL; |
| 6046 |
r.in.architecture = environment; |
| 6047 |
r.in.path_name = path_name; |
| 6048 |
r.in.print_processor_name = print_processor_name; |
| 6049 |
|
| 6050 |
torture_comment(tctx, "Testing AddPrintProcessor(%s)\n", |
| 6051 |
print_processor_name); |
| 6052 |
|
| 6053 |
torture_assert_ntstatus_ok(tctx, |
| 6054 |
dcerpc_spoolss_AddPrintProcessor_r(b, tctx, &r), |
| 6055 |
"spoolss_AddPrintProcessor failed"); |
| 6056 |
torture_assert_werr_equal(tctx, r.out.result, expected_error, |
| 6057 |
"spoolss_AddPrintProcessor failed"); |
| 6058 |
|
| 6059 |
return true; |
| 6060 |
} |
| 6061 |
|
| 6062 |
static bool test_DeletePrintProcessor(struct torture_context *tctx, |
| 6063 |
struct dcerpc_binding_handle *b, |
| 6064 |
const char *environment, |
| 6065 |
const char *print_processor_name, |
| 6066 |
WERROR expected_error) |
| 6067 |
{ |
| 6068 |
struct spoolss_DeletePrintProcessor r; |
| 6069 |
|
| 6070 |
r.in.server = NULL; |
| 6071 |
r.in.architecture = environment; |
| 6072 |
r.in.print_processor_name = print_processor_name; |
| 6073 |
|
| 6074 |
torture_comment(tctx, "Testing DeletePrintProcessor(%s)\n", |
| 6075 |
print_processor_name); |
| 6076 |
|
| 6077 |
torture_assert_ntstatus_ok(tctx, |
| 6078 |
dcerpc_spoolss_DeletePrintProcessor_r(b, tctx, &r), |
| 6079 |
"spoolss_DeletePrintProcessor failed"); |
| 6080 |
torture_assert_werr_equal(tctx, r.out.result, expected_error, |
| 6081 |
"spoolss_DeletePrintProcessor failed"); |
| 6082 |
|
| 6083 |
return true; |
| 6084 |
} |
| 6085 |
|
| 6086 |
static bool test_add_print_processor(struct torture_context *tctx, |
| 6087 |
void *private_data) |
| 6088 |
{ |
| 6089 |
struct test_spoolss_context *ctx = |
| 6090 |
talloc_get_type_abort(private_data, struct test_spoolss_context); |
| 6091 |
struct dcerpc_pipe *p = ctx->spoolss_pipe; |
| 6092 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 6093 |
int i; |
| 6094 |
|
| 6095 |
struct { |
| 6096 |
const char *environment; |
| 6097 |
const char *path_name; |
| 6098 |
const char *print_processor_name; |
| 6099 |
WERROR expected_add_result; |
| 6100 |
WERROR expected_del_result; |
| 6101 |
} tests[] = { |
| 6102 |
{ |
| 6103 |
.environment = ctx->environment, |
| 6104 |
.path_name = "", |
| 6105 |
.print_processor_name = "winprint", |
| 6106 |
.expected_add_result = WERR_PRINT_PROCESSOR_ALREADY_INSTALLED, |
| 6107 |
.expected_del_result = WERR_CAN_NOT_COMPLETE |
| 6108 |
},{ |
| 6109 |
.environment = ctx->environment, |
| 6110 |
.path_name = "", |
| 6111 |
.print_processor_name = "unknown", |
| 6112 |
.expected_add_result = WERR_MOD_NOT_FOUND, |
| 6113 |
.expected_del_result = WERR_UNKNOWN_PRINTPROCESSOR |
| 6114 |
} |
| 6115 |
}; |
| 6116 |
|
| 6117 |
for (i=0; i < ARRAY_SIZE(tests); i++) { |
| 6118 |
torture_assert(tctx, |
| 6119 |
test_AddPrintProcessor(tctx, b, |
| 6120 |
tests[i].environment, |
| 6121 |
tests[i].path_name, |
| 6122 |
tests[i].print_processor_name, |
| 6123 |
tests[i].expected_add_result), |
| 6124 |
"add print processor failed"); |
| 6125 |
torture_assert(tctx, |
| 6126 |
test_DeletePrintProcessor(tctx, b, |
| 6127 |
tests[i].environment, |
| 6128 |
tests[i].print_processor_name, |
| 6129 |
tests[i].expected_del_result), |
| 6130 |
"delete print processor failed"); |
| 6131 |
} |
| 6132 |
|
| 6133 |
return true; |
| 6134 |
} |
| 6135 |
|
| 6136 |
static bool test_AddPerMachineConnection(struct torture_context *tctx, |
| 6137 |
struct dcerpc_binding_handle *b, |
| 6138 |
const char *servername, |
| 6139 |
const char *printername, |
| 6140 |
const char *printserver, |
| 6141 |
const char *provider, |
| 6142 |
WERROR expected_error) |
| 6143 |
{ |
| 6144 |
struct spoolss_AddPerMachineConnection r; |
| 6145 |
const char *composed_printername = printername; |
| 6146 |
|
| 6147 |
if (servername != NULL) { |
| 6148 |
composed_printername = talloc_asprintf(tctx, "%s\\%s", |
| 6149 |
servername, |
| 6150 |
printername); |
| 6151 |
} |
| 6152 |
r.in.server = servername; |
| 6153 |
r.in.printername = composed_printername; |
| 6154 |
r.in.printserver = printserver; |
| 6155 |
r.in.provider = provider; |
| 6156 |
|
| 6157 |
torture_comment(tctx, "Testing AddPerMachineConnection(%s|%s|%s)\n", |
| 6158 |
printername, printserver, provider); |
| 6159 |
|
| 6160 |
torture_assert_ntstatus_ok(tctx, |
| 6161 |
dcerpc_spoolss_AddPerMachineConnection_r(b, tctx, &r), |
| 6162 |
"spoolss_AddPerMachineConnection failed"); |
| 6163 |
torture_assert_werr_equal(tctx, r.out.result, expected_error, |
| 6164 |
"spoolss_AddPerMachineConnection failed"); |
| 6165 |
|
| 6166 |
return true; |
| 6167 |
} |
| 6168 |
|
| 6169 |
static bool test_DeletePerMachineConnection(struct torture_context *tctx, |
| 6170 |
struct dcerpc_binding_handle *b, |
| 6171 |
const char *servername, |
| 6172 |
const char *printername, |
| 6173 |
WERROR expected_error) |
| 6174 |
{ |
| 6175 |
struct spoolss_DeletePerMachineConnection r; |
| 6176 |
const char *composed_printername = printername; |
| 6177 |
|
| 6178 |
if (servername != NULL) { |
| 6179 |
composed_printername = talloc_asprintf(tctx, "%s\\%s", |
| 6180 |
servername, |
| 6181 |
printername); |
| 6182 |
} |
| 6183 |
|
| 6184 |
r.in.server = servername; |
| 6185 |
r.in.printername = composed_printername; |
| 6186 |
|
| 6187 |
torture_comment(tctx, "Testing DeletePerMachineConnection(%s)\n", |
| 6188 |
printername); |
| 6189 |
|
| 6190 |
torture_assert_ntstatus_ok(tctx, |
| 6191 |
dcerpc_spoolss_DeletePerMachineConnection_r(b, tctx, &r), |
| 6192 |
"spoolss_DeletePerMachineConnection failed"); |
| 6193 |
torture_assert_werr_equal(tctx, r.out.result, expected_error, |
| 6194 |
"spoolss_DeletePerMachineConnection failed"); |
| 6195 |
|
| 6196 |
return true; |
| 6197 |
} |
| 6198 |
|
| 6199 |
static bool test_EnumPerMachineConnections(struct torture_context *tctx, |
| 6200 |
struct dcerpc_binding_handle *b, |
| 6201 |
const char *servername) |
| 6202 |
{ |
| 6203 |
struct spoolss_EnumPerMachineConnections r; |
| 6204 |
DATA_BLOB blob = data_blob_null; |
| 6205 |
struct spoolss_PrinterInfo4 *info; |
| 6206 |
uint32_t needed; |
| 6207 |
uint32_t count; |
| 6208 |
|
| 6209 |
r.in.server = servername; |
| 6210 |
r.in.buffer = &blob; |
| 6211 |
r.in.offered = 0; |
| 6212 |
|
| 6213 |
r.out.info = &info; |
| 6214 |
r.out.needed = &needed; |
| 6215 |
r.out.count = &count; |
| 6216 |
|
| 6217 |
torture_comment(tctx, "Testing EnumPerMachineConnections(%s)\n", |
| 6218 |
servername); |
| 6219 |
|
| 6220 |
torture_assert_ntstatus_ok(tctx, |
| 6221 |
dcerpc_spoolss_EnumPerMachineConnections_r(b, tctx, &r), |
| 6222 |
"spoolss_EnumPerMachineConnections failed"); |
| 6223 |
if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) { |
| 6224 |
blob = data_blob_talloc_zero(tctx, needed); |
| 6225 |
r.in.buffer = &blob; |
| 6226 |
r.in.offered = needed; |
| 6227 |
|
| 6228 |
torture_assert_ntstatus_ok(tctx, |
| 6229 |
dcerpc_spoolss_EnumPerMachineConnections_r(b, tctx, &r), |
| 6230 |
"spoolss_EnumPerMachineConnections failed"); |
| 6231 |
} |
| 6232 |
torture_assert_werr_ok(tctx, r.out.result, |
| 6233 |
"spoolss_EnumPerMachineConnections failed"); |
| 6234 |
|
| 6235 |
return true; |
| 6236 |
} |
| 6237 |
|
| 6238 |
static bool test_addpermachineconnection(struct torture_context *tctx, |
| 6239 |
void *private_data) |
| 6240 |
{ |
| 6241 |
struct test_spoolss_context *ctx = |
| 6242 |
talloc_get_type_abort(private_data, struct test_spoolss_context); |
| 6243 |
struct dcerpc_pipe *p = ctx->spoolss_pipe; |
| 6244 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 6245 |
const char *server_name_slash = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p)); |
| 6246 |
int i; |
| 6247 |
|
| 6248 |
struct { |
| 6249 |
const char *servername; |
| 6250 |
const char *printername; |
| 6251 |
const char *printserver; |
| 6252 |
const char *provider; |
| 6253 |
WERROR expected_add_result; |
| 6254 |
WERROR expected_del_result; |
| 6255 |
} tests[] = { |
| 6256 |
{ |
| 6257 |
.servername = NULL, |
| 6258 |
.printername = "foo", |
| 6259 |
.printserver = "", |
| 6260 |
.provider = "unknown", |
| 6261 |
.expected_add_result = WERR_INVALID_PRINTER_NAME, |
| 6262 |
.expected_del_result = WERR_INVALID_PRINTER_NAME |
| 6263 |
},{ |
| 6264 |
.servername = NULL, |
| 6265 |
.printername = "Microsoft Print to PDF", |
| 6266 |
.printserver = "samba.org", |
| 6267 |
.provider = "unknown", |
| 6268 |
.expected_add_result = WERR_INVALID_PRINTER_NAME, |
| 6269 |
.expected_del_result = WERR_INVALID_PRINTER_NAME |
| 6270 |
},{ |
| 6271 |
.servername = NULL, |
| 6272 |
.printername = "Microsoft Print to PDF", |
| 6273 |
.printserver = "samba.org", |
| 6274 |
.provider = "", |
| 6275 |
.expected_add_result = WERR_INVALID_PRINTER_NAME, |
| 6276 |
.expected_del_result = WERR_INVALID_PRINTER_NAME |
| 6277 |
},{ |
| 6278 |
.servername = server_name_slash, |
| 6279 |
.printername = "foo", |
| 6280 |
.printserver = "", |
| 6281 |
.provider = "unknown", |
| 6282 |
.expected_add_result = WERR_FILE_NOT_FOUND, |
| 6283 |
.expected_del_result = WERR_INVALID_PRINTER_NAME |
| 6284 |
},{ |
| 6285 |
.servername = server_name_slash, |
| 6286 |
.printername = "foo", |
| 6287 |
.printserver = "", |
| 6288 |
.provider = "", |
| 6289 |
.expected_add_result = WERR_OK, |
| 6290 |
.expected_del_result = WERR_OK |
| 6291 |
},{ |
| 6292 |
.servername = server_name_slash, |
| 6293 |
.printername = "Microsoft Print to PDF", |
| 6294 |
.printserver = "samba.org", |
| 6295 |
.provider = "unknown", |
| 6296 |
.expected_add_result = WERR_FILE_NOT_FOUND, |
| 6297 |
.expected_del_result = WERR_INVALID_PRINTER_NAME |
| 6298 |
},{ |
| 6299 |
.servername = server_name_slash, |
| 6300 |
.printername = "Microsoft Print to PDF", |
| 6301 |
.printserver = "samba.org", |
| 6302 |
.provider = "", |
| 6303 |
.expected_add_result = WERR_OK, |
| 6304 |
.expected_del_result = WERR_OK |
| 6305 |
} |
| 6306 |
}; |
| 6307 |
|
| 6308 |
for (i=0; i < ARRAY_SIZE(tests); i++) { |
| 6309 |
torture_assert(tctx, |
| 6310 |
test_AddPerMachineConnection(tctx, b, |
| 6311 |
tests[i].servername, |
| 6312 |
tests[i].printername, |
| 6313 |
tests[i].printserver, |
| 6314 |
tests[i].provider, |
| 6315 |
tests[i].expected_add_result), |
| 6316 |
"add per machine connection failed"); |
| 6317 |
torture_assert(tctx, |
| 6318 |
test_EnumPerMachineConnections(tctx, b, |
| 6319 |
tests[i].servername), |
| 6320 |
"enum per machine connections failed"); |
| 6321 |
torture_assert(tctx, |
| 6322 |
test_DeletePerMachineConnection(tctx, b, |
| 6323 |
tests[i].servername, |
| 6324 |
tests[i].printername, |
| 6325 |
tests[i].expected_del_result), |
| 6326 |
"delete per machine connection failed"); |
| 6327 |
torture_assert(tctx, |
| 6328 |
test_EnumPerMachineConnections(tctx, b, |
| 6329 |
tests[i].servername), |
| 6330 |
"enum per machine connections failed"); |
| 6331 |
} |
| 6332 |
|
| 6333 |
return true; |
| 6334 |
} |
| 6335 |
|
| 6336 |
static bool test_GetChangeID_PrinterData(struct torture_context *tctx, |
| 6337 |
struct dcerpc_binding_handle *b, |
| 6338 |
struct policy_handle *handle, |
| 6339 |
uint32_t *change_id) |
| 6340 |
{ |
| 6341 |
enum winreg_Type type; |
| 6342 |
uint8_t *data; |
| 6343 |
uint32_t needed; |
| 6344 |
|
| 6345 |
torture_assert(tctx, |
| 6346 |
test_GetPrinterData(tctx, b, handle, "ChangeID", &type, &data, &needed), |
| 6347 |
"failed to call GetPrinterData"); |
| 6348 |
|
| 6349 |
torture_assert(tctx, type == REG_DWORD, "unexpected type"); |
| 6350 |
torture_assert_int_equal(tctx, needed, 4, "unexpected size"); |
| 6351 |
|
| 6352 |
*change_id = IVAL(data, 0); |
| 6353 |
|
| 6354 |
return true; |
| 6355 |
} |
| 6356 |
|
| 6357 |
static bool test_GetChangeID_PrinterDataEx(struct torture_context *tctx, |
| 6358 |
struct dcerpc_pipe *p, |
| 6359 |
struct policy_handle *handle, |
| 6360 |
uint32_t *change_id) |
| 6361 |
{ |
| 6362 |
enum winreg_Type type = REG_NONE; |
| 6363 |
uint8_t *data = NULL; |
| 6364 |
uint32_t needed = 0; |
| 6365 |
|
| 6366 |
torture_assert(tctx, |
| 6367 |
test_GetPrinterDataEx(tctx, p, handle, "PrinterDriverData", "ChangeID", &type, &data, &needed), |
| 6368 |
"failed to call GetPrinterData"); |
| 6369 |
|
| 6370 |
torture_assert(tctx, type == REG_DWORD, "unexpected type"); |
| 6371 |
torture_assert_int_equal(tctx, needed, 4, "unexpected size"); |
| 6372 |
|
| 6373 |
*change_id = IVAL(data, 0); |
| 6374 |
|
| 6375 |
return true; |
| 6376 |
} |
| 6377 |
|
| 6378 |
static bool test_GetChangeID_PrinterInfo(struct torture_context *tctx, |
| 6379 |
struct dcerpc_binding_handle *b, |
| 6380 |
struct policy_handle *handle, |
| 6381 |
uint32_t *change_id) |
| 6382 |
{ |
| 6383 |
union spoolss_PrinterInfo info; |
| 6384 |
|
| 6385 |
torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, 0, &info), |
| 6386 |
"failed to query Printer level 0"); |
| 6387 |
|
| 6388 |
*change_id = info.info0.change_id; |
| 6389 |
|
| 6390 |
return true; |
| 6391 |
} |
| 6392 |
|
| 6393 |
static bool test_ChangeID(struct torture_context *tctx, |
| 6394 |
struct dcerpc_pipe *p, |
| 6395 |
struct policy_handle *handle) |
| 6396 |
{ |
| 6397 |
uint32_t change_id, change_id_ex, change_id_info; |
| 6398 |
uint32_t change_id2, change_id_ex2, change_id_info2; |
| 6399 |
union spoolss_PrinterInfo info; |
| 6400 |
const char *comment; |
| 6401 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 6402 |
|
| 6403 |
torture_comment(tctx, "Testing ChangeID: id change test #1\n"); |
| 6404 |
|
| 6405 |
torture_assert(tctx, test_GetChangeID_PrinterData(tctx, b, handle, &change_id), |
| 6406 |
"failed to query for ChangeID"); |
| 6407 |
torture_assert(tctx, test_GetChangeID_PrinterDataEx(tctx, p, handle, &change_id_ex), |
| 6408 |
"failed to query for ChangeID"); |
| 6409 |
torture_assert(tctx, test_GetChangeID_PrinterInfo(tctx, b, handle, &change_id_info), |
| 6410 |
"failed to query for ChangeID"); |
| 6411 |
|
| 6412 |
torture_assert_int_equal(tctx, change_id, change_id_ex, |
| 6413 |
"change_ids should all be equal"); |
| 6414 |
torture_assert_int_equal(tctx, change_id_ex, change_id_info, |
| 6415 |
"change_ids should all be equal"); |
| 6416 |
|
| 6417 |
|
| 6418 |
torture_comment(tctx, "Testing ChangeID: id change test #2\n"); |
| 6419 |
|
| 6420 |
torture_assert(tctx, test_GetChangeID_PrinterData(tctx, b, handle, &change_id), |
| 6421 |
"failed to query for ChangeID"); |
| 6422 |
torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, 2, &info), |
| 6423 |
"failed to query Printer level 2"); |
| 6424 |
torture_assert(tctx, test_GetChangeID_PrinterDataEx(tctx, p, handle, &change_id_ex), |
| 6425 |
"failed to query for ChangeID"); |
| 6426 |
torture_assert(tctx, test_GetChangeID_PrinterInfo(tctx, b, handle, &change_id_info), |
| 6427 |
"failed to query for ChangeID"); |
| 6428 |
torture_assert_int_equal(tctx, change_id, change_id_ex, |
| 6429 |
"change_id should not have changed"); |
| 6430 |
torture_assert_int_equal(tctx, change_id_ex, change_id_info, |
| 6431 |
"change_id should not have changed"); |
| 6432 |
|
| 6433 |
|
| 6434 |
torture_comment(tctx, "Testing ChangeID: id change test #3\n"); |
| 6435 |
|
| 6436 |
torture_assert(tctx, test_GetChangeID_PrinterData(tctx, b, handle, &change_id), |
| 6437 |
"failed to query for ChangeID"); |
| 6438 |
torture_assert(tctx, test_GetChangeID_PrinterDataEx(tctx, p, handle, &change_id_ex), |
| 6439 |
"failed to query for ChangeID"); |
| 6440 |
torture_assert(tctx, test_GetChangeID_PrinterInfo(tctx, b, handle, &change_id_info), |
| 6441 |
"failed to query for ChangeID"); |
| 6442 |
torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, 2, &info), |
| 6443 |
"failed to query Printer level 2"); |
| 6444 |
comment = talloc_strdup(tctx, info.info2.comment); |
| 6445 |
|
| 6446 |
{ |
| 6447 |
struct spoolss_SetPrinterInfoCtr info_ctr; |
| 6448 |
struct spoolss_DevmodeContainer devmode_ctr; |
| 6449 |
struct sec_desc_buf secdesc_ctr; |
| 6450 |
union spoolss_SetPrinterInfo sinfo; |
| 6451 |
|
| 6452 |
ZERO_STRUCT(info_ctr); |
| 6453 |
ZERO_STRUCT(devmode_ctr); |
| 6454 |
ZERO_STRUCT(secdesc_ctr); |
| 6455 |
|
| 6456 |
|
| 6457 |
torture_assert(tctx, PrinterInfo_to_SetPrinterInfo(tctx, &info, 2, &sinfo), ""); |
| 6458 |
sinfo.info2->comment = "torture_comment"; |
| 6459 |
|
| 6460 |
info_ctr.level = 2; |
| 6461 |
info_ctr.info = sinfo; |
| 6462 |
|
| 6463 |
torture_assert(tctx, test_SetPrinter(tctx, b, handle, &info_ctr, &devmode_ctr, &secdesc_ctr, 0), |
| 6464 |
"failed to call SetPrinter"); |
| 6465 |
|
| 6466 |
sinfo.info2->comment = comment; |
| 6467 |
|
| 6468 |
torture_assert(tctx, test_SetPrinter(tctx, b, handle, &info_ctr, &devmode_ctr, &secdesc_ctr, 0), |
| 6469 |
"failed to call SetPrinter"); |
| 6470 |
|
| 6471 |
} |
| 6472 |
|
| 6473 |
torture_assert(tctx, test_GetChangeID_PrinterData(tctx, b, handle, &change_id2), |
| 6474 |
"failed to query for ChangeID"); |
| 6475 |
torture_assert(tctx, test_GetChangeID_PrinterDataEx(tctx, p, handle, &change_id_ex2), |
| 6476 |
"failed to query for ChangeID"); |
| 6477 |
torture_assert(tctx, test_GetChangeID_PrinterInfo(tctx, b, handle, &change_id_info2), |
| 6478 |
"failed to query for ChangeID"); |
| 6479 |
|
| 6480 |
torture_assert_int_equal(tctx, change_id2, change_id_ex2, |
| 6481 |
"change_ids should all be equal"); |
| 6482 |
torture_assert_int_equal(tctx, change_id_ex2, change_id_info2, |
| 6483 |
"change_ids should all be equal"); |
| 6484 |
|
| 6485 |
torture_assert(tctx, (change_id < change_id2), |
| 6486 |
talloc_asprintf(tctx, "change_id %d needs to be larger than change_id %d", |
| 6487 |
change_id2, change_id)); |
| 6488 |
torture_assert(tctx, (change_id_ex < change_id_ex2), |
| 6489 |
talloc_asprintf(tctx, "change_id %d needs to be larger than change_id %d", |
| 6490 |
change_id_ex2, change_id_ex)); |
| 6491 |
torture_assert(tctx, (change_id_info < change_id_info2), |
| 6492 |
talloc_asprintf(tctx, "change_id %d needs to be larger than change_id %d", |
| 6493 |
change_id_info2, change_id_info)); |
| 6494 |
|
| 6495 |
torture_comment(tctx, "ChangeID tests succeeded\n\n"); |
| 6496 |
|
| 6497 |
return true; |
| 6498 |
} |
| 6499 |
|
| 6500 |
static bool test_SecondaryClosePrinter(struct torture_context *tctx, |
| 6501 |
struct dcerpc_pipe *p, |
| 6502 |
struct policy_handle *handle) |
| 6503 |
{ |
| 6504 |
NTSTATUS status; |
| 6505 |
struct cli_credentials *anon_creds; |
| 6506 |
const struct dcerpc_binding *binding2; |
| 6507 |
struct dcerpc_pipe *p2; |
| 6508 |
struct spoolss_ClosePrinter cp; |
| 6509 |
|
| 6510 |
/* only makes sense on SMB */ |
| 6511 |
if (dcerpc_binding_handle_get_transport(p->binding_handle) != NCACN_NP) { |
| 6512 |
return true; |
| 6513 |
} |
| 6514 |
|
| 6515 |
torture_comment(tctx, "Testing close on secondary pipe\n"); |
| 6516 |
|
| 6517 |
anon_creds = cli_credentials_init_anon(tctx); |
| 6518 |
torture_assert(tctx, anon_creds != NULL, "cli_credentials_init_anon failed"); |
| 6519 |
|
| 6520 |
binding2 = dcerpc_binding_handle_get_binding(p->binding_handle); |
| 6521 |
status = dcerpc_secondary_auth_connection(p, binding2, &ndr_table_spoolss, |
| 6522 |
anon_creds, tctx->lp_ctx, |
| 6523 |
tctx, &p2); |
| 6524 |
torture_assert_ntstatus_ok(tctx, status, "Failed to create secondary connection"); |
| 6525 |
|
| 6526 |
cp.in.handle = handle; |
| 6527 |
cp.out.handle = handle; |
| 6528 |
|
| 6529 |
status = dcerpc_spoolss_ClosePrinter_r(p2->binding_handle, tctx, &cp); |
| 6530 |
torture_assert_ntstatus_equal(tctx, status, NT_STATUS_RPC_SS_CONTEXT_MISMATCH, |
| 6531 |
"ERROR: Allowed close on secondary connection"); |
| 6532 |
|
| 6533 |
talloc_free(p2); |
| 6534 |
|
| 6535 |
return true; |
| 6536 |
} |
| 6537 |
|
| 6538 |
static bool test_OpenPrinter_badname(struct torture_context *tctx, |
| 6539 |
struct dcerpc_binding_handle *b, const char *name) |
| 6540 |
{ |
| 6541 |
NTSTATUS status; |
| 6542 |
struct spoolss_OpenPrinter op; |
| 6543 |
struct spoolss_OpenPrinterEx opEx; |
| 6544 |
struct policy_handle handle; |
| 6545 |
bool ret = true; |
| 6546 |
|
| 6547 |
op.in.printername = name; |
| 6548 |
op.in.datatype = NULL; |
| 6549 |
op.in.devmode_ctr.devmode= NULL; |
| 6550 |
op.in.access_mask = 0; |
| 6551 |
op.out.handle = &handle; |
| 6552 |
|
| 6553 |
torture_comment(tctx, "Testing OpenPrinter(%s) with bad name\n", op.in.printername); |
| 6554 |
|
| 6555 |
status = dcerpc_spoolss_OpenPrinter_r(b, tctx, &op); |
| 6556 |
torture_assert_ntstatus_ok(tctx, status, "OpenPrinter failed"); |
| 6557 |
torture_assert_werr_equal(tctx, op.out.result, WERR_INVALID_PRINTER_NAME, |
| 6558 |
"unexpected result"); |
| 6559 |
|
| 6560 |
if (W_ERROR_IS_OK(op.out.result)) { |
| 6561 |
ret &=test_ClosePrinter(tctx, b, &handle); |
| 6562 |
} |
| 6563 |
|
| 6564 |
opEx.in.printername = name; |
| 6565 |
opEx.in.datatype = NULL; |
| 6566 |
opEx.in.devmode_ctr.devmode = NULL; |
| 6567 |
opEx.in.access_mask = 0; |
| 6568 |
opEx.in.userlevel_ctr.level = 1; |
| 6569 |
opEx.in.userlevel_ctr.user_info.level1 = NULL; |
| 6570 |
opEx.out.handle = &handle; |
| 6571 |
|
| 6572 |
torture_comment(tctx, "Testing OpenPrinterEx(%s) with bad name\n", opEx.in.printername); |
| 6573 |
|
| 6574 |
status = dcerpc_spoolss_OpenPrinterEx_r(b, tctx, &opEx); |
| 6575 |
torture_assert_ntstatus_ok(tctx, status, "OpenPrinterEx failed"); |
| 6576 |
torture_assert_werr_equal(tctx, opEx.out.result, WERR_INVALID_PARAMETER, |
| 6577 |
"unexpected result"); |
| 6578 |
|
| 6579 |
if (W_ERROR_IS_OK(opEx.out.result)) { |
| 6580 |
ret &=test_ClosePrinter(tctx, b, &handle); |
| 6581 |
} |
| 6582 |
|
| 6583 |
return ret; |
| 6584 |
} |
| 6585 |
|
| 6586 |
static bool test_OpenPrinter_badname_list(struct torture_context *tctx, |
| 6587 |
void *private_data) |
| 6588 |
{ |
| 6589 |
struct test_spoolss_context *ctx = |
| 6590 |
talloc_get_type_abort(private_data, struct test_spoolss_context); |
| 6591 |
|
| 6592 |
const char *badnames[] = { |
| 6593 |
"__INVALID_PRINTER__", |
| 6594 |
"\\\\__INVALID_HOST__", |
| 6595 |
"", |
| 6596 |
"\\\\\\", |
| 6597 |
"\\\\\\__INVALID_PRINTER__" |
| 6598 |
}; |
| 6599 |
const char *badname; |
| 6600 |
struct dcerpc_pipe *p = ctx->spoolss_pipe; |
| 6601 |
const char *server_name = dcerpc_server_name(p); |
| 6602 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 6603 |
int i; |
| 6604 |
|
| 6605 |
for (i=0; i < ARRAY_SIZE(badnames); i++) { |
| 6606 |
torture_assert(tctx, |
| 6607 |
test_OpenPrinter_badname(tctx, b, badnames[i]), |
| 6608 |
""); |
| 6609 |
} |
| 6610 |
|
| 6611 |
badname = talloc_asprintf(tctx, "\\\\%s\\", server_name); |
| 6612 |
torture_assert(tctx, |
| 6613 |
test_OpenPrinter_badname(tctx, b, badname), |
| 6614 |
""); |
| 6615 |
|
| 6616 |
badname = talloc_asprintf(tctx, "\\\\%s\\__INVALID_PRINTER__", server_name); |
| 6617 |
torture_assert(tctx, |
| 6618 |
test_OpenPrinter_badname(tctx, b, badname), |
| 6619 |
""); |
| 6620 |
|
| 6621 |
return true; |
| 6622 |
} |
| 6623 |
|
| 6624 |
static bool test_OpenPrinter(struct torture_context *tctx, |
| 6625 |
struct dcerpc_pipe *p, |
| 6626 |
const char *name, |
| 6627 |
const char *environment, |
| 6628 |
bool open_only) |
| 6629 |
{ |
| 6630 |
NTSTATUS status; |
| 6631 |
struct spoolss_OpenPrinter r; |
| 6632 |
struct policy_handle handle; |
| 6633 |
bool ret = true; |
| 6634 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 6635 |
|
| 6636 |
r.in.printername = name; |
| 6637 |
r.in.datatype = NULL; |
| 6638 |
r.in.devmode_ctr.devmode= NULL; |
| 6639 |
r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED; |
| 6640 |
r.out.handle = &handle; |
| 6641 |
|
| 6642 |
torture_comment(tctx, "Testing OpenPrinter(%s)\n", r.in.printername); |
| 6643 |
|
| 6644 |
status = dcerpc_spoolss_OpenPrinter_r(b, tctx, &r); |
| 6645 |
|
| 6646 |
torture_assert_ntstatus_ok(tctx, status, "OpenPrinter failed"); |
| 6647 |
|
| 6648 |
torture_assert_werr_ok(tctx, r.out.result, "OpenPrinter failed"); |
| 6649 |
|
| 6650 |
if (open_only) { |
| 6651 |
goto close_printer; |
| 6652 |
} |
| 6653 |
|
| 6654 |
if (!test_GetPrinter(tctx, b, &handle, environment)) { |
| 6655 |
ret = false; |
| 6656 |
} |
| 6657 |
|
| 6658 |
if (!torture_setting_bool(tctx, "samba3", false)) { |
| 6659 |
if (!test_SecondaryClosePrinter(tctx, p, &handle)) { |
| 6660 |
ret = false; |
| 6661 |
} |
| 6662 |
} |
| 6663 |
|
| 6664 |
close_printer: |
| 6665 |
if (!test_ClosePrinter(tctx, b, &handle)) { |
| 6666 |
ret = false; |
| 6667 |
} |
| 6668 |
|
| 6669 |
return ret; |
| 6670 |
} |
| 6671 |
|
| 6672 |
static bool test_OpenPrinterEx(struct torture_context *tctx, |
| 6673 |
struct dcerpc_binding_handle *b, |
| 6674 |
const char *printername, |
| 6675 |
const char *datatype, |
| 6676 |
struct spoolss_DeviceMode *devmode, |
| 6677 |
uint32_t access_mask, |
| 6678 |
struct spoolss_UserLevelCtr *userlevel_ctr, |
| 6679 |
struct policy_handle *handle, |
| 6680 |
WERROR expected_result) |
| 6681 |
{ |
| 6682 |
struct spoolss_OpenPrinterEx r; |
| 6683 |
|
| 6684 |
r.in.printername = printername; |
| 6685 |
r.in.datatype = datatype; |
| 6686 |
r.in.devmode_ctr.devmode= devmode; |
| 6687 |
r.in.access_mask = access_mask; |
| 6688 |
r.in.userlevel_ctr = *userlevel_ctr; |
| 6689 |
r.out.handle = handle; |
| 6690 |
|
| 6691 |
torture_comment(tctx, "Testing OpenPrinterEx(%s)\n", r.in.printername); |
| 6692 |
|
| 6693 |
torture_assert_ntstatus_ok(tctx, |
| 6694 |
dcerpc_spoolss_OpenPrinterEx_r(b, tctx, &r), |
| 6695 |
"OpenPrinterEx failed"); |
| 6696 |
|
| 6697 |
torture_assert_werr_equal(tctx, r.out.result, expected_result, |
| 6698 |
"OpenPrinterEx failed"); |
| 6699 |
|
| 6700 |
return true; |
| 6701 |
} |
| 6702 |
|
| 6703 |
static bool call_OpenPrinterEx(struct torture_context *tctx, |
| 6704 |
struct dcerpc_pipe *p, |
| 6705 |
const char *name, |
| 6706 |
struct spoolss_DeviceMode *devmode, |
| 6707 |
struct policy_handle *handle) |
| 6708 |
{ |
| 6709 |
struct spoolss_UserLevelCtr userlevel_ctr; |
| 6710 |
struct spoolss_UserLevel1 userlevel1; |
| 6711 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 6712 |
|
| 6713 |
userlevel1.size = 1234; |
| 6714 |
userlevel1.client = "hello"; |
| 6715 |
userlevel1.user = "spottyfoot!"; |
| 6716 |
userlevel1.build = 1; |
| 6717 |
userlevel1.major = 2; |
| 6718 |
userlevel1.minor = 3; |
| 6719 |
userlevel1.processor = 4; |
| 6720 |
|
| 6721 |
userlevel_ctr.level = 1; |
| 6722 |
userlevel_ctr.user_info.level1 = &userlevel1; |
| 6723 |
|
| 6724 |
return test_OpenPrinterEx(tctx, b, name, NULL, devmode, |
| 6725 |
SEC_FLAG_MAXIMUM_ALLOWED, |
| 6726 |
&userlevel_ctr, |
| 6727 |
handle, |
| 6728 |
WERR_OK); |
| 6729 |
} |
| 6730 |
|
| 6731 |
static bool test_printer_rename(struct torture_context *tctx, |
| 6732 |
void *private_data) |
| 6733 |
{ |
| 6734 |
struct torture_printer_context *t = |
| 6735 |
(struct torture_printer_context *)talloc_get_type_abort(private_data, struct torture_printer_context); |
| 6736 |
struct dcerpc_pipe *p = t->spoolss_pipe; |
| 6737 |
|
| 6738 |
bool ret = true; |
| 6739 |
union spoolss_PrinterInfo info; |
| 6740 |
union spoolss_SetPrinterInfo sinfo; |
| 6741 |
struct spoolss_SetPrinterInfoCtr info_ctr; |
| 6742 |
struct spoolss_DevmodeContainer devmode_ctr; |
| 6743 |
struct sec_desc_buf secdesc_ctr; |
| 6744 |
const char *printer_name; |
| 6745 |
const char *printer_name_orig; |
| 6746 |
const char *printer_name_new = "SAMBA smbtorture Test Printer (Copy 2)"; |
| 6747 |
struct policy_handle new_handle; |
| 6748 |
const char *q; |
| 6749 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 6750 |
|
| 6751 |
ZERO_STRUCT(devmode_ctr); |
| 6752 |
ZERO_STRUCT(secdesc_ctr); |
| 6753 |
|
| 6754 |
torture_comment(tctx, "Testing Printer rename operations\n"); |
| 6755 |
|
| 6756 |
torture_assert(tctx, |
| 6757 |
test_GetPrinter_level(tctx, b, &t->handle, 2, &info), |
| 6758 |
"failed to call GetPrinter level 2"); |
| 6759 |
|
| 6760 |
printer_name_orig = talloc_strdup(tctx, info.info2.printername); |
| 6761 |
|
| 6762 |
q = strrchr(info.info2.printername, '\\'); |
| 6763 |
if (q) { |
| 6764 |
torture_warning(tctx, |
| 6765 |
"server returns printername %s incl. servername although we did not set servername", info.info2.printername); |
| 6766 |
} |
| 6767 |
|
| 6768 |
torture_assert(tctx, |
| 6769 |
PrinterInfo_to_SetPrinterInfo(tctx, &info, 2, &sinfo), ""); |
| 6770 |
|
| 6771 |
sinfo.info2->printername = printer_name_new; |
| 6772 |
|
| 6773 |
info_ctr.level = 2; |
| 6774 |
info_ctr.info = sinfo; |
| 6775 |
|
| 6776 |
torture_assert(tctx, |
| 6777 |
test_SetPrinter(tctx, b, &t->handle, &info_ctr, &devmode_ctr, &secdesc_ctr, 0), |
| 6778 |
"failed to call SetPrinter level 2"); |
| 6779 |
|
| 6780 |
torture_assert(tctx, |
| 6781 |
test_GetPrinter_level(tctx, b, &t->handle, 2, &info), |
| 6782 |
"failed to call GetPrinter level 2"); |
| 6783 |
|
| 6784 |
printer_name = talloc_strdup(tctx, info.info2.printername); |
| 6785 |
|
| 6786 |
q = strrchr(info.info2.printername, '\\'); |
| 6787 |
if (q) { |
| 6788 |
torture_warning(tctx, |
| 6789 |
"server returns printername %s incl. servername although we did not set servername", info.info2.printername); |
| 6790 |
q++; |
| 6791 |
printer_name = q; |
| 6792 |
} |
| 6793 |
|
| 6794 |
torture_assert_str_equal(tctx, printer_name, printer_name_new, |
| 6795 |
"new printer name was not set"); |
| 6796 |
|
| 6797 |
/* samba currently cannot fully rename printers */ |
| 6798 |
if (!(torture_setting_bool(tctx, "samba3", false) || |
| 6799 |
torture_setting_bool(tctx, "samba4", false))) { |
| 6800 |
torture_assert(tctx, |
| 6801 |
test_OpenPrinter_badname(tctx, b, printer_name_orig), |
| 6802 |
"still can open printer with oldname after rename"); |
| 6803 |
} else { |
| 6804 |
torture_warning(tctx, "*not* checking for open with oldname after rename for samba3"); |
| 6805 |
} |
| 6806 |
|
| 6807 |
torture_assert(tctx, |
| 6808 |
call_OpenPrinterEx(tctx, p, printer_name_new, NULL, &new_handle), |
| 6809 |
"failed to open printer with new name"); |
| 6810 |
|
| 6811 |
torture_assert(tctx, |
| 6812 |
test_GetPrinter_level(tctx, b, &new_handle, 2, &info), |
| 6813 |
"failed to call GetPrinter level 2"); |
| 6814 |
|
| 6815 |
torture_assert_str_equal(tctx, info.info2.printername, printer_name_new, |
| 6816 |
"new printer name was not set"); |
| 6817 |
|
| 6818 |
torture_assert(tctx, |
| 6819 |
test_ClosePrinter(tctx, b, &new_handle), |
| 6820 |
"failed to close printer"); |
| 6821 |
|
| 6822 |
torture_comment(tctx, "Printer rename operations test succeeded\n\n"); |
| 6823 |
|
| 6824 |
return ret; |
| 6825 |
} |
| 6826 |
|
| 6827 |
static bool test_openprinter(struct torture_context *tctx, |
| 6828 |
struct dcerpc_binding_handle *b, |
| 6829 |
const char *real_printername) |
| 6830 |
{ |
| 6831 |
struct spoolss_UserLevelCtr userlevel_ctr; |
| 6832 |
struct policy_handle handle; |
| 6833 |
struct spoolss_UserLevel1 userlevel1; |
| 6834 |
const char *printername = NULL; |
| 6835 |
int i; |
| 6836 |
|
| 6837 |
struct { |
| 6838 |
const char *suffix; |
| 6839 |
WERROR expected_result; |
| 6840 |
} tests[] = { |
| 6841 |
{ |
| 6842 |
.suffix = "rubbish", |
| 6843 |
.expected_result = WERR_INVALID_PRINTER_NAME |
| 6844 |
},{ |
| 6845 |
.suffix = ", LocalOnl", |
| 6846 |
.expected_result = WERR_INVALID_PRINTER_NAME |
| 6847 |
},{ |
| 6848 |
.suffix = ", localOnly", |
| 6849 |
.expected_result = WERR_INVALID_PRINTER_NAME |
| 6850 |
},{ |
| 6851 |
.suffix = ", localonl", |
| 6852 |
.expected_result = WERR_INVALID_PRINTER_NAME |
| 6853 |
},{ |
| 6854 |
.suffix = ",LocalOnl", |
| 6855 |
.expected_result = WERR_INVALID_PRINTER_NAME |
| 6856 |
},{ |
| 6857 |
.suffix = ",localOnl2", |
| 6858 |
.expected_result = WERR_INVALID_PRINTER_NAME |
| 6859 |
},{ |
| 6860 |
.suffix = ", DrvConver2t", |
| 6861 |
.expected_result = WERR_INVALID_PRINTER_NAME |
| 6862 |
},{ |
| 6863 |
.suffix = ", drvconvert", |
| 6864 |
.expected_result = WERR_INVALID_PRINTER_NAME |
| 6865 |
},{ |
| 6866 |
.suffix = ",drvconvert", |
| 6867 |
.expected_result = WERR_INVALID_PRINTER_NAME |
| 6868 |
},{ |
| 6869 |
.suffix = ", DrvConvert", |
| 6870 |
.expected_result = WERR_OK |
| 6871 |
},{ |
| 6872 |
.suffix = " , DrvConvert", |
| 6873 |
.expected_result = WERR_INVALID_PRINTER_NAME |
| 6874 |
},{ |
| 6875 |
.suffix = ",DrvConvert", |
| 6876 |
.expected_result = WERR_OK |
| 6877 |
},{ |
| 6878 |
.suffix = ", DrvConvertsadfasdf", |
| 6879 |
.expected_result = WERR_OK |
| 6880 |
},{ |
| 6881 |
.suffix = ",DrvConvertasdfasd", |
| 6882 |
.expected_result = WERR_OK |
| 6883 |
},{ |
| 6884 |
.suffix = ", LocalOnly", |
| 6885 |
.expected_result = WERR_OK |
| 6886 |
},{ |
| 6887 |
.suffix = " , LocalOnly", |
| 6888 |
.expected_result = WERR_INVALID_PRINTER_NAME |
| 6889 |
},{ |
| 6890 |
.suffix = ",LocalOnly", |
| 6891 |
.expected_result = WERR_OK |
| 6892 |
},{ |
| 6893 |
.suffix = ", LocalOnlysagi4gjfkd", |
| 6894 |
.expected_result = WERR_OK |
| 6895 |
},{ |
| 6896 |
.suffix = ",LocalOnlysagi4gjfkd", |
| 6897 |
.expected_result = WERR_OK |
| 6898 |
} |
| 6899 |
}; |
| 6900 |
|
| 6901 |
userlevel1.size = 1234; |
| 6902 |
userlevel1.client = "hello"; |
| 6903 |
userlevel1.user = "spottyfoot!"; |
| 6904 |
userlevel1.build = 1; |
| 6905 |
userlevel1.major = 2; |
| 6906 |
userlevel1.minor = 3; |
| 6907 |
userlevel1.processor = 4; |
| 6908 |
|
| 6909 |
userlevel_ctr.level = 1; |
| 6910 |
userlevel_ctr.user_info.level1 = &userlevel1; |
| 6911 |
|
| 6912 |
torture_comment(tctx, "Testing openprinterex printername pattern\n"); |
| 6913 |
|
| 6914 |
torture_assert(tctx, |
| 6915 |
test_OpenPrinterEx(tctx, b, real_printername, NULL, NULL, 0, |
| 6916 |
&userlevel_ctr, &handle, |
| 6917 |
WERR_OK), |
| 6918 |
"OpenPrinterEx failed"); |
| 6919 |
test_ClosePrinter(tctx, b, &handle); |
| 6920 |
|
| 6921 |
for (i=0; i < ARRAY_SIZE(tests); i++) { |
| 6922 |
|
| 6923 |
printername = talloc_asprintf(tctx, "%s%s", |
| 6924 |
real_printername, |
| 6925 |
tests[i].suffix); |
| 6926 |
|
| 6927 |
torture_assert(tctx, |
| 6928 |
test_OpenPrinterEx(tctx, b, printername, NULL, NULL, 0, |
| 6929 |
&userlevel_ctr, &handle, |
| 6930 |
tests[i].expected_result), |
| 6931 |
"OpenPrinterEx failed"); |
| 6932 |
if (W_ERROR_IS_OK(tests[i].expected_result)) { |
| 6933 |
test_ClosePrinter(tctx, b, &handle); |
| 6934 |
} |
| 6935 |
} |
| 6936 |
|
| 6937 |
return true; |
| 6938 |
} |
| 6939 |
|
| 6940 |
|
| 6941 |
static bool test_existing_printer_openprinterex(struct torture_context *tctx, |
| 6942 |
struct dcerpc_pipe *p, |
| 6943 |
const char *name, |
| 6944 |
const char *environment) |
| 6945 |
{ |
| 6946 |
struct policy_handle handle; |
| 6947 |
bool ret = true; |
| 6948 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 6949 |
|
| 6950 |
if (!test_openprinter(tctx, b, name)) { |
| 6951 |
return false; |
| 6952 |
} |
| 6953 |
|
| 6954 |
if (!call_OpenPrinterEx(tctx, p, name, NULL, &handle)) { |
| 6955 |
return false; |
| 6956 |
} |
| 6957 |
|
| 6958 |
if (!test_PrinterInfo_SD(tctx, b, &handle)) { |
| 6959 |
ret = false; |
| 6960 |
} |
| 6961 |
|
| 6962 |
if (!test_GetPrinter(tctx, b, &handle, environment)) { |
| 6963 |
ret = false; |
| 6964 |
} |
| 6965 |
|
| 6966 |
if (!test_EnumForms_all(tctx, b, &handle, false)) { |
| 6967 |
ret = false; |
| 6968 |
} |
| 6969 |
|
| 6970 |
if (!test_Forms(tctx, b, &handle, false, name, NULL, NULL)) { |
| 6971 |
ret = false; |
| 6972 |
} |
| 6973 |
|
| 6974 |
if (!test_Forms_winreg(tctx, b, &handle, false, name)) { |
| 6975 |
ret = false; |
| 6976 |
} |
| 6977 |
|
| 6978 |
if (!test_EnumPrinterData_all(tctx, p, &handle)) { |
| 6979 |
ret = false; |
| 6980 |
} |
| 6981 |
|
| 6982 |
if (!test_EnumPrinterDataEx(tctx, b, &handle, "PrinterDriverData", NULL, NULL)) { |
| 6983 |
ret = false; |
| 6984 |
} |
| 6985 |
|
| 6986 |
if (!test_EnumPrinterData_consistency(tctx, p, &handle)) { |
| 6987 |
ret = false; |
| 6988 |
} |
| 6989 |
|
| 6990 |
if (!test_printer_all_keys(tctx, b, &handle)) { |
| 6991 |
ret = false; |
| 6992 |
} |
| 6993 |
|
| 6994 |
if (!test_PausePrinter(tctx, b, &handle)) { |
| 6995 |
ret = false; |
| 6996 |
} |
| 6997 |
|
| 6998 |
if (!test_DoPrintTest(tctx, b, &handle)) { |
| 6999 |
ret = false; |
| 7000 |
} |
| 7001 |
|
| 7002 |
if (!test_ResumePrinter(tctx, b, &handle)) { |
| 7003 |
ret = false; |
| 7004 |
} |
| 7005 |
|
| 7006 |
if (!test_SetPrinterData_matrix(tctx, b, &handle, name, NULL, NULL)) { |
| 7007 |
ret = false; |
| 7008 |
} |
| 7009 |
|
| 7010 |
if (!test_SetPrinterDataEx_matrix(tctx, p, &handle, name, NULL, NULL)) { |
| 7011 |
ret = false; |
| 7012 |
} |
| 7013 |
|
| 7014 |
if (!torture_setting_bool(tctx, "samba3", false)) { |
| 7015 |
if (!test_SecondaryClosePrinter(tctx, p, &handle)) { |
| 7016 |
ret = false; |
| 7017 |
} |
| 7018 |
} |
| 7019 |
|
| 7020 |
if (!test_ClosePrinter(tctx, b, &handle)) { |
| 7021 |
ret = false; |
| 7022 |
} |
| 7023 |
|
| 7024 |
return ret; |
| 7025 |
} |
| 7026 |
|
| 7027 |
static bool test_EnumPrinters_old(struct torture_context *tctx, |
| 7028 |
void *private_data) |
| 7029 |
{ |
| 7030 |
struct test_spoolss_context *ctx = |
| 7031 |
talloc_get_type_abort(private_data, struct test_spoolss_context); |
| 7032 |
struct spoolss_EnumPrinters r; |
| 7033 |
NTSTATUS status; |
| 7034 |
uint16_t levels[] = {1, 2, 4, 5}; |
| 7035 |
int i; |
| 7036 |
bool ret = true; |
| 7037 |
struct dcerpc_pipe *p = ctx->spoolss_pipe; |
| 7038 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 7039 |
|
| 7040 |
for (i=0;i<ARRAY_SIZE(levels);i++) { |
| 7041 |
union spoolss_PrinterInfo *info; |
| 7042 |
int j; |
| 7043 |
uint32_t needed; |
| 7044 |
uint32_t count; |
| 7045 |
|
| 7046 |
r.in.flags = PRINTER_ENUM_LOCAL; |
| 7047 |
r.in.server = ""; |
| 7048 |
r.in.level = levels[i]; |
| 7049 |
r.in.buffer = NULL; |
| 7050 |
r.in.offered = 0; |
| 7051 |
r.out.needed = &needed; |
| 7052 |
r.out.count = &count; |
| 7053 |
r.out.info = &info; |
| 7054 |
|
| 7055 |
torture_comment(tctx, "Testing EnumPrinters level %u\n", r.in.level); |
| 7056 |
|
| 7057 |
status = dcerpc_spoolss_EnumPrinters_r(b, tctx, &r); |
| 7058 |
torture_assert_ntstatus_ok(tctx, status, "EnumPrinters failed"); |
| 7059 |
|
| 7060 |
if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) { |
| 7061 |
DATA_BLOB blob = data_blob_talloc_zero(tctx, needed); |
| 7062 |
r.in.buffer = &blob; |
| 7063 |
r.in.offered = needed; |
| 7064 |
status = dcerpc_spoolss_EnumPrinters_r(b, tctx, &r); |
| 7065 |
} |
| 7066 |
|
| 7067 |
torture_assert_ntstatus_ok(tctx, status, "EnumPrinters failed"); |
| 7068 |
|
| 7069 |
torture_assert_werr_ok(tctx, r.out.result, "EnumPrinters failed"); |
| 7070 |
|
| 7071 |
CHECK_NEEDED_SIZE_ENUM_LEVEL(spoolss_EnumPrinters, info, r.in.level, count, needed, 4); |
| 7072 |
|
| 7073 |
if (!info) { |
| 7074 |
torture_comment(tctx, "No printers returned\n"); |
| 7075 |
return true; |
| 7076 |
} |
| 7077 |
|
| 7078 |
for (j=0;j<count;j++) { |
| 7079 |
if (r.in.level == 1) { |
| 7080 |
char *unc = talloc_strdup(tctx, info[j].info1.name); |
| 7081 |
char *slash, *name, *full_name; |
| 7082 |
name = unc; |
| 7083 |
if (unc[0] == '\\' && unc[1] == '\\') { |
| 7084 |
unc +=2; |
| 7085 |
} |
| 7086 |
slash = strchr(unc, '\\'); |
| 7087 |
if (slash) { |
| 7088 |
slash++; |
| 7089 |
name = slash; |
| 7090 |
} |
| 7091 |
full_name = talloc_asprintf(tctx, "\\\\%s\\%s", |
| 7092 |
dcerpc_server_name(p), name); |
| 7093 |
if (!test_OpenPrinter(tctx, p, name, ctx->environment, true)) { |
| 7094 |
ret = false; |
| 7095 |
} |
| 7096 |
if (!test_OpenPrinter(tctx, p, full_name, ctx->environment, true)) { |
| 7097 |
ret = false; |
| 7098 |
} |
| 7099 |
if (!test_OpenPrinter(tctx, p, name, ctx->environment, false)) { |
| 7100 |
ret = false; |
| 7101 |
} |
| 7102 |
if (!test_existing_printer_openprinterex(tctx, p, name, ctx->environment)) { |
| 7103 |
ret = false; |
| 7104 |
} |
| 7105 |
} |
| 7106 |
} |
| 7107 |
} |
| 7108 |
|
| 7109 |
return ret; |
| 7110 |
} |
| 7111 |
|
| 7112 |
static bool test_EnumPrinters_level(struct torture_context *tctx, |
| 7113 |
struct dcerpc_binding_handle *b, |
| 7114 |
uint32_t flags, |
| 7115 |
const char *servername, |
| 7116 |
uint32_t level, |
| 7117 |
uint32_t *count_p, |
| 7118 |
union spoolss_PrinterInfo **info_p) |
| 7119 |
{ |
| 7120 |
struct spoolss_EnumPrinters r; |
| 7121 |
union spoolss_PrinterInfo *info; |
| 7122 |
uint32_t needed; |
| 7123 |
uint32_t count; |
| 7124 |
|
| 7125 |
r.in.flags = flags; |
| 7126 |
r.in.server = servername; |
| 7127 |
r.in.level = level; |
| 7128 |
r.in.buffer = NULL; |
| 7129 |
r.in.offered = 0; |
| 7130 |
r.out.needed = &needed; |
| 7131 |
r.out.count = &count; |
| 7132 |
r.out.info = &info; |
| 7133 |
|
| 7134 |
torture_comment(tctx, "Testing EnumPrinters(%s) level %u\n", |
| 7135 |
r.in.server, r.in.level); |
| 7136 |
|
| 7137 |
torture_assert_ntstatus_ok(tctx, |
| 7138 |
dcerpc_spoolss_EnumPrinters_r(b, tctx, &r), |
| 7139 |
"EnumPrinters failed"); |
| 7140 |
if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) { |
| 7141 |
DATA_BLOB blob = data_blob_talloc_zero(tctx, needed); |
| 7142 |
r.in.buffer = &blob; |
| 7143 |
r.in.offered = needed; |
| 7144 |
torture_assert_ntstatus_ok(tctx, |
| 7145 |
dcerpc_spoolss_EnumPrinters_r(b, tctx, &r), |
| 7146 |
"EnumPrinters failed"); |
| 7147 |
} |
| 7148 |
|
| 7149 |
torture_assert_werr_ok(tctx, r.out.result, "EnumPrinters failed"); |
| 7150 |
|
| 7151 |
CHECK_NEEDED_SIZE_ENUM_LEVEL(spoolss_EnumPrinters, info, r.in.level, count, needed, 4); |
| 7152 |
|
| 7153 |
if (count_p) { |
| 7154 |
*count_p = count; |
| 7155 |
} |
| 7156 |
if (info_p) { |
| 7157 |
*info_p = info; |
| 7158 |
} |
| 7159 |
|
| 7160 |
return true; |
| 7161 |
} |
| 7162 |
|
| 7163 |
static const char *get_short_printername(struct torture_context *tctx, |
| 7164 |
const char *name) |
| 7165 |
{ |
| 7166 |
const char *short_name; |
| 7167 |
|
| 7168 |
if (name[0] == '\\' && name[1] == '\\') { |
| 7169 |
name += 2; |
| 7170 |
short_name = strchr(name, '\\'); |
| 7171 |
if (short_name) { |
| 7172 |
return talloc_strdup(tctx, short_name+1); |
| 7173 |
} |
| 7174 |
} |
| 7175 |
|
| 7176 |
return name; |
| 7177 |
} |
| 7178 |
|
| 7179 |
static const char *get_full_printername(struct torture_context *tctx, |
| 7180 |
const char *name) |
| 7181 |
{ |
| 7182 |
const char *full_name = talloc_strdup(tctx, name); |
| 7183 |
char *p; |
| 7184 |
|
| 7185 |
if (name && name[0] == '\\' && name[1] == '\\') { |
| 7186 |
name += 2; |
| 7187 |
p = strchr(name, '\\'); |
| 7188 |
if (p) { |
| 7189 |
return full_name; |
| 7190 |
} |
| 7191 |
} |
| 7192 |
|
| 7193 |
return NULL; |
| 7194 |
} |
| 7195 |
|
| 7196 |
static bool test_OnePrinter_servername(struct torture_context *tctx, |
| 7197 |
struct dcerpc_pipe *p, |
| 7198 |
struct dcerpc_binding_handle *b, |
| 7199 |
const char *servername, |
| 7200 |
const char *printername) |
| 7201 |
{ |
| 7202 |
union spoolss_PrinterInfo info; |
| 7203 |
const char *short_name = get_short_printername(tctx, printername); |
| 7204 |
const char *full_name = get_full_printername(tctx, printername); |
| 7205 |
|
| 7206 |
if (short_name) { |
| 7207 |
struct policy_handle handle; |
| 7208 |
torture_assert(tctx, |
| 7209 |
call_OpenPrinterEx(tctx, p, short_name, NULL, &handle), |
| 7210 |
"failed to open printer"); |
| 7211 |
|
| 7212 |
torture_assert(tctx, |
| 7213 |
test_GetPrinter_level(tctx, b, &handle, 2, &info), |
| 7214 |
"failed to get printer info"); |
| 7215 |
|
| 7216 |
torture_assert_casestr_equal(tctx, info.info2.servername, NULL, |
| 7217 |
"unexpected servername"); |
| 7218 |
torture_assert_casestr_equal(tctx, info.info2.printername, short_name, |
| 7219 |
"unexpected printername"); |
| 7220 |
|
| 7221 |
if (info.info2.devmode) { |
| 7222 |
const char *expected_devicename; |
| 7223 |
expected_devicename = talloc_strndup(tctx, short_name, MIN(strlen(short_name), 31)); |
| 7224 |
torture_assert_casestr_equal(tctx, info.info2.devmode->devicename, expected_devicename, |
| 7225 |
"unexpected devicemode devicename"); |
| 7226 |
} |
| 7227 |
|
| 7228 |
torture_assert(tctx, |
| 7229 |
test_ClosePrinter(tctx, b, &handle), |
| 7230 |
"failed to close printer"); |
| 7231 |
} |
| 7232 |
|
| 7233 |
if (full_name) { |
| 7234 |
struct policy_handle handle; |
| 7235 |
|
| 7236 |
torture_assert(tctx, |
| 7237 |
call_OpenPrinterEx(tctx, p, full_name, NULL, &handle), |
| 7238 |
"failed to open printer"); |
| 7239 |
|
| 7240 |
torture_assert(tctx, |
| 7241 |
test_GetPrinter_level(tctx, b, &handle, 2, &info), |
| 7242 |
"failed to get printer info"); |
| 7243 |
|
| 7244 |
torture_assert_casestr_equal(tctx, info.info2.servername, servername, |
| 7245 |
"unexpected servername"); |
| 7246 |
torture_assert_casestr_equal(tctx, info.info2.printername, full_name, |
| 7247 |
"unexpected printername"); |
| 7248 |
|
| 7249 |
if (info.info2.devmode) { |
| 7250 |
const char *expected_devicename; |
| 7251 |
expected_devicename = talloc_strndup(tctx, full_name, MIN(strlen(full_name), 31)); |
| 7252 |
torture_assert_casestr_equal(tctx, info.info2.devmode->devicename, expected_devicename, |
| 7253 |
"unexpected devicemode devicename"); |
| 7254 |
} |
| 7255 |
|
| 7256 |
torture_assert(tctx, |
| 7257 |
test_ClosePrinter(tctx, b, &handle), |
| 7258 |
"failed to close printer"); |
| 7259 |
} |
| 7260 |
|
| 7261 |
return true; |
| 7262 |
} |
| 7263 |
|
| 7264 |
static bool test_EnumPrinters_servername(struct torture_context *tctx, |
| 7265 |
void *private_data) |
| 7266 |
{ |
| 7267 |
struct test_spoolss_context *ctx = |
| 7268 |
talloc_get_type_abort(private_data, struct test_spoolss_context); |
| 7269 |
int i; |
| 7270 |
struct dcerpc_pipe *p = ctx->spoolss_pipe; |
| 7271 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 7272 |
uint32_t count; |
| 7273 |
union spoolss_PrinterInfo *info; |
| 7274 |
const char *servername; |
| 7275 |
uint32_t flags = PRINTER_ENUM_NAME|PRINTER_ENUM_LOCAL; |
| 7276 |
|
| 7277 |
torture_comment(tctx, "Testing servername behaviour in EnumPrinters and GetPrinters\n"); |
| 7278 |
|
| 7279 |
servername = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p)); |
| 7280 |
|
| 7281 |
torture_assert(tctx, |
| 7282 |
test_EnumPrinters_level(tctx, b, flags, servername, 2, &count, &info), |
| 7283 |
"failed to enumerate printers"); |
| 7284 |
|
| 7285 |
for (i=0; i < count; i++) { |
| 7286 |
|
| 7287 |
torture_assert_casestr_equal(tctx, info[i].info2.servername, servername, |
| 7288 |
"unexpected servername"); |
| 7289 |
|
| 7290 |
torture_assert(tctx, |
| 7291 |
test_OnePrinter_servername(tctx, p, b, servername, info[i].info2.printername), |
| 7292 |
"failed to check printer"); |
| 7293 |
} |
| 7294 |
|
| 7295 |
servername = ""; |
| 7296 |
|
| 7297 |
torture_assert(tctx, |
| 7298 |
test_EnumPrinters_level(tctx, b, flags, servername, 2, &count, &info), |
| 7299 |
"failed to enumerate printers"); |
| 7300 |
|
| 7301 |
for (i=0; i < count; i++) { |
| 7302 |
|
| 7303 |
torture_assert_casestr_equal(tctx, info[i].info2.servername, NULL, |
| 7304 |
"unexpected servername"); |
| 7305 |
|
| 7306 |
torture_assert(tctx, |
| 7307 |
test_OnePrinter_servername(tctx, p, b, servername, info[i].info2.printername), |
| 7308 |
"failed to check printer"); |
| 7309 |
} |
| 7310 |
|
| 7311 |
|
| 7312 |
return true; |
| 7313 |
} |
| 7314 |
|
| 7315 |
#if 0 |
| 7316 |
static bool test_GetPrinterDriver(struct torture_context *tctx, |
| 7317 |
struct dcerpc_binding_handle *b, |
| 7318 |
struct policy_handle *handle, |
| 7319 |
const char *driver_name) |
| 7320 |
{ |
| 7321 |
struct spoolss_GetPrinterDriver r; |
| 7322 |
uint32_t needed; |
| 7323 |
|
| 7324 |
r.in.handle = handle; |
| 7325 |
r.in.architecture = "W32X86"; |
| 7326 |
r.in.level = 1; |
| 7327 |
r.in.buffer = NULL; |
| 7328 |
r.in.offered = 0; |
| 7329 |
r.out.needed = &needed; |
| 7330 |
|
| 7331 |
torture_comment(tctx, "Testing GetPrinterDriver level %d\n", r.in.level); |
| 7332 |
|
| 7333 |
torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_GetPrinterDriver_r(b, tctx, &r), |
| 7334 |
"failed to call GetPrinterDriver"); |
| 7335 |
if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) { |
| 7336 |
DATA_BLOB blob = data_blob_talloc_zero(tctx, needed); |
| 7337 |
r.in.buffer = &blob; |
| 7338 |
r.in.offered = needed; |
| 7339 |
torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_GetPrinterDriver_r(b, tctx, &r), |
| 7340 |
"failed to call GetPrinterDriver"); |
| 7341 |
} |
| 7342 |
|
| 7343 |
torture_assert_werr_ok(tctx, r.out.result, |
| 7344 |
"failed to call GetPrinterDriver"); |
| 7345 |
|
| 7346 |
CHECK_NEEDED_SIZE_LEVEL(spoolss_DriverInfo, r.out.info, r.in.level, needed, 4); |
| 7347 |
|
| 7348 |
return true; |
| 7349 |
} |
| 7350 |
#endif |
| 7351 |
|
| 7352 |
static bool test_GetPrinterDriver2_level(struct torture_context *tctx, |
| 7353 |
struct dcerpc_binding_handle *b, |
| 7354 |
struct policy_handle *handle, |
| 7355 |
const char *driver_name, |
| 7356 |
const char *architecture, |
| 7357 |
uint32_t level, |
| 7358 |
uint32_t client_major_version, |
| 7359 |
uint32_t client_minor_version, |
| 7360 |
union spoolss_DriverInfo *info_p, |
| 7361 |
WERROR *result_p) |
| 7362 |
|
| 7363 |
{ |
| 7364 |
struct spoolss_GetPrinterDriver2 r; |
| 7365 |
uint32_t needed; |
| 7366 |
uint32_t server_major_version; |
| 7367 |
uint32_t server_minor_version; |
| 7368 |
|
| 7369 |
r.in.handle = handle; |
| 7370 |
r.in.architecture = architecture; |
| 7371 |
r.in.client_major_version = client_major_version; |
| 7372 |
r.in.client_minor_version = client_minor_version; |
| 7373 |
r.in.buffer = NULL; |
| 7374 |
r.in.offered = 0; |
| 7375 |
r.in.level = level; |
| 7376 |
r.out.needed = &needed; |
| 7377 |
r.out.server_major_version = &server_major_version; |
| 7378 |
r.out.server_minor_version = &server_minor_version; |
| 7379 |
|
| 7380 |
torture_comment(tctx, "Testing GetPrinterDriver2(%s) level %d\n", |
| 7381 |
driver_name, r.in.level); |
| 7382 |
|
| 7383 |
torture_assert_ntstatus_ok(tctx, |
| 7384 |
dcerpc_spoolss_GetPrinterDriver2_r(b, tctx, &r), |
| 7385 |
"failed to call GetPrinterDriver2"); |
| 7386 |
if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) { |
| 7387 |
DATA_BLOB blob = data_blob_talloc_zero(tctx, needed); |
| 7388 |
r.in.buffer = &blob; |
| 7389 |
r.in.offered = needed; |
| 7390 |
torture_assert_ntstatus_ok(tctx, |
| 7391 |
dcerpc_spoolss_GetPrinterDriver2_r(b, tctx, &r), |
| 7392 |
"failed to call GetPrinterDriver2"); |
| 7393 |
} |
| 7394 |
|
| 7395 |
if (result_p) { |
| 7396 |
*result_p = r.out.result; |
| 7397 |
} |
| 7398 |
|
| 7399 |
if (W_ERROR_EQUAL(r.out.result, WERR_INVALID_LEVEL)) { |
| 7400 |
switch (r.in.level) { |
| 7401 |
case 101: |
| 7402 |
case 8: |
| 7403 |
torture_comment(tctx, |
| 7404 |
"level %d not implemented, not considering as an error\n", |
| 7405 |
r.in.level); |
| 7406 |
return true; |
| 7407 |
default: |
| 7408 |
break; |
| 7409 |
} |
| 7410 |
} |
| 7411 |
|
| 7412 |
torture_assert_werr_ok(tctx, r.out.result, |
| 7413 |
"failed to call GetPrinterDriver2"); |
| 7414 |
|
| 7415 |
CHECK_NEEDED_SIZE_LEVEL(spoolss_DriverInfo, r.out.info, r.in.level, needed, 4); |
| 7416 |
|
| 7417 |
if (info_p) { |
| 7418 |
*info_p = *r.out.info; |
| 7419 |
} |
| 7420 |
|
| 7421 |
return true; |
| 7422 |
} |
| 7423 |
|
| 7424 |
static bool test_GetPrinterDriver2(struct torture_context *tctx, |
| 7425 |
struct dcerpc_binding_handle *b, |
| 7426 |
struct policy_handle *handle, |
| 7427 |
const char *driver_name, |
| 7428 |
const char *architecture) |
| 7429 |
{ |
| 7430 |
uint16_t levels[] = {1, 2, 3, 4, 5, 6, 8, 101 }; |
| 7431 |
int i; |
| 7432 |
|
| 7433 |
|
| 7434 |
for (i=0;i<ARRAY_SIZE(levels);i++) { |
| 7435 |
|
| 7436 |
torture_assert(tctx, |
| 7437 |
test_GetPrinterDriver2_level(tctx, b, handle, driver_name, architecture, levels[i], 3, 0, NULL, NULL), |
| 7438 |
""); |
| 7439 |
} |
| 7440 |
|
| 7441 |
return true; |
| 7442 |
} |
| 7443 |
|
| 7444 |
static bool test_EnumPrinterDrivers_old(struct torture_context *tctx, |
| 7445 |
void *private_data) |
| 7446 |
{ |
| 7447 |
struct test_spoolss_context *ctx = |
| 7448 |
talloc_get_type_abort(private_data, struct test_spoolss_context); |
| 7449 |
uint16_t levels[] = {1, 2, 3, 4, 5, 6}; |
| 7450 |
int i; |
| 7451 |
struct dcerpc_pipe *p = ctx->spoolss_pipe; |
| 7452 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 7453 |
const char *server_name = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p)); |
| 7454 |
|
| 7455 |
for (i=0;i<ARRAY_SIZE(levels);i++) { |
| 7456 |
|
| 7457 |
uint32_t count; |
| 7458 |
union spoolss_DriverInfo *info; |
| 7459 |
|
| 7460 |
torture_assert(tctx, |
| 7461 |
test_EnumPrinterDrivers_args(tctx, b, server_name, ctx->environment, levels[i], &count, &info), |
| 7462 |
"failed to enumerate drivers"); |
| 7463 |
|
| 7464 |
if (!info) { |
| 7465 |
torture_comment(tctx, "No printer drivers returned\n"); |
| 7466 |
break; |
| 7467 |
} |
| 7468 |
} |
| 7469 |
|
| 7470 |
return true; |
| 7471 |
} |
| 7472 |
|
| 7473 |
static bool test_DeletePrinter(struct torture_context *tctx, |
| 7474 |
struct dcerpc_binding_handle *b, |
| 7475 |
struct policy_handle *handle) |
| 7476 |
{ |
| 7477 |
struct spoolss_DeletePrinter r; |
| 7478 |
|
| 7479 |
torture_comment(tctx, "Testing DeletePrinter\n"); |
| 7480 |
|
| 7481 |
r.in.handle = handle; |
| 7482 |
|
| 7483 |
torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_DeletePrinter_r(b, tctx, &r), |
| 7484 |
"failed to delete printer"); |
| 7485 |
torture_assert_werr_ok(tctx, r.out.result, |
| 7486 |
"failed to delete printer"); |
| 7487 |
|
| 7488 |
return true; |
| 7489 |
} |
| 7490 |
|
| 7491 |
static bool test_EnumPrinters_findname(struct torture_context *tctx, |
| 7492 |
struct dcerpc_binding_handle *b, |
| 7493 |
uint32_t flags, |
| 7494 |
uint32_t level, |
| 7495 |
const char *name, |
| 7496 |
bool *found) |
| 7497 |
{ |
| 7498 |
struct spoolss_EnumPrinters e; |
| 7499 |
uint32_t count; |
| 7500 |
union spoolss_PrinterInfo *info; |
| 7501 |
uint32_t needed; |
| 7502 |
int i; |
| 7503 |
|
| 7504 |
*found = false; |
| 7505 |
|
| 7506 |
e.in.flags = flags; |
| 7507 |
e.in.server = NULL; |
| 7508 |
e.in.level = level; |
| 7509 |
e.in.buffer = NULL; |
| 7510 |
e.in.offered = 0; |
| 7511 |
e.out.count = &count; |
| 7512 |
e.out.info = &info; |
| 7513 |
e.out.needed = &needed; |
| 7514 |
|
| 7515 |
torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_EnumPrinters_r(b, tctx, &e), |
| 7516 |
"failed to enum printers"); |
| 7517 |
|
| 7518 |
if (W_ERROR_EQUAL(e.out.result, WERR_INSUFFICIENT_BUFFER)) { |
| 7519 |
DATA_BLOB blob = data_blob_talloc_zero(tctx, needed); |
| 7520 |
e.in.buffer = &blob; |
| 7521 |
e.in.offered = needed; |
| 7522 |
|
| 7523 |
torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_EnumPrinters_r(b, tctx, &e), |
| 7524 |
"failed to enum printers"); |
| 7525 |
} |
| 7526 |
|
| 7527 |
torture_assert_werr_ok(tctx, e.out.result, |
| 7528 |
"failed to enum printers"); |
| 7529 |
|
| 7530 |
for (i=0; i < count; i++) { |
| 7531 |
|
| 7532 |
const char *current = NULL; |
| 7533 |
const char *q; |
| 7534 |
|
| 7535 |
switch (level) { |
| 7536 |
case 1: |
| 7537 |
current = info[i].info1.name; |
| 7538 |
break; |
| 7539 |
} |
| 7540 |
|
| 7541 |
if (strequal(current, name)) { |
| 7542 |
*found = true; |
| 7543 |
break; |
| 7544 |
} |
| 7545 |
|
| 7546 |
q = strrchr(current, '\\'); |
| 7547 |
if (q) { |
| 7548 |
if (!e.in.server) { |
| 7549 |
torture_warning(tctx, |
| 7550 |
"server returns printername %s incl. servername although we did not set servername", current); |
| 7551 |
} |
| 7552 |
q++; |
| 7553 |
if (strequal(q, name)) { |
| 7554 |
*found = true; |
| 7555 |
break; |
| 7556 |
} |
| 7557 |
} |
| 7558 |
} |
| 7559 |
|
| 7560 |
return true; |
| 7561 |
} |
| 7562 |
|
| 7563 |
static bool test_AddPrinter_wellknown(struct torture_context *tctx, |
| 7564 |
struct dcerpc_pipe *p, |
| 7565 |
const char *printername, |
| 7566 |
bool ex) |
| 7567 |
{ |
| 7568 |
WERROR result; |
| 7569 |
struct spoolss_AddPrinter r; |
| 7570 |
struct spoolss_AddPrinterEx rex; |
| 7571 |
struct spoolss_SetPrinterInfoCtr info_ctr; |
| 7572 |
struct spoolss_SetPrinterInfo1 info1; |
| 7573 |
struct spoolss_DevmodeContainer devmode_ctr; |
| 7574 |
struct sec_desc_buf secdesc_ctr; |
| 7575 |
struct spoolss_UserLevelCtr userlevel_ctr; |
| 7576 |
struct policy_handle handle; |
| 7577 |
bool found = false; |
| 7578 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 7579 |
|
| 7580 |
ZERO_STRUCT(devmode_ctr); |
| 7581 |
ZERO_STRUCT(secdesc_ctr); |
| 7582 |
ZERO_STRUCT(userlevel_ctr); |
| 7583 |
ZERO_STRUCT(info1); |
| 7584 |
|
| 7585 |
torture_comment(tctx, "Testing AddPrinter%s(%s) level 1\n", |
| 7586 |
ex ? "Ex":"", printername); |
| 7587 |
|
| 7588 |
/* try to add printer to wellknown printer list (level 1) */ |
| 7589 |
|
| 7590 |
userlevel_ctr.level = 1; |
| 7591 |
|
| 7592 |
info_ctr.info.info1 = &info1; |
| 7593 |
info_ctr.level = 1; |
| 7594 |
|
| 7595 |
rex.in.server = NULL; |
| 7596 |
rex.in.info_ctr = &info_ctr; |
| 7597 |
rex.in.devmode_ctr = &devmode_ctr; |
| 7598 |
rex.in.secdesc_ctr = &secdesc_ctr; |
| 7599 |
rex.in.userlevel_ctr = &userlevel_ctr; |
| 7600 |
rex.out.handle = &handle; |
| 7601 |
|
| 7602 |
r.in.server = NULL; |
| 7603 |
r.in.info_ctr = &info_ctr; |
| 7604 |
r.in.devmode_ctr = &devmode_ctr; |
| 7605 |
r.in.secdesc_ctr = &secdesc_ctr; |
| 7606 |
r.out.handle = &handle; |
| 7607 |
|
| 7608 |
torture_assert_ntstatus_ok(tctx, ex ? dcerpc_spoolss_AddPrinterEx_r(b, tctx, &rex) : |
| 7609 |
dcerpc_spoolss_AddPrinter_r(b, tctx, &r), |
| 7610 |
"failed to add printer"); |
| 7611 |
result = ex ? rex.out.result : r.out.result; |
| 7612 |
torture_assert_werr_equal(tctx, result, WERR_INVALID_PRINTER_NAME, |
| 7613 |
"unexpected result code"); |
| 7614 |
|
| 7615 |
info1.name = printername; |
| 7616 |
info1.flags = PRINTER_ATTRIBUTE_SHARED; |
| 7617 |
|
| 7618 |
torture_assert_ntstatus_ok(tctx, ex ? dcerpc_spoolss_AddPrinterEx_r(b, tctx, &rex) : |
| 7619 |
dcerpc_spoolss_AddPrinter_r(b, tctx, &r), |
| 7620 |
"failed to add printer"); |
| 7621 |
result = ex ? rex.out.result : r.out.result; |
| 7622 |
torture_assert_werr_equal(tctx, result, WERR_PRINTER_ALREADY_EXISTS, |
| 7623 |
"unexpected result code"); |
| 7624 |
|
| 7625 |
/* bizarre protocol, WERR_PRINTER_ALREADY_EXISTS means success here, |
| 7626 |
better do a real check to see the printer is really there */ |
| 7627 |
|
| 7628 |
torture_assert(tctx, test_EnumPrinters_findname(tctx, b, |
| 7629 |
PRINTER_ENUM_NETWORK, 1, |
| 7630 |
printername, |
| 7631 |
&found), |
| 7632 |
"failed to enum printers"); |
| 7633 |
|
| 7634 |
torture_assert(tctx, found, "failed to find newly added printer"); |
| 7635 |
|
| 7636 |
info1.flags = 0; |
| 7637 |
|
| 7638 |
torture_assert_ntstatus_ok(tctx, ex ? dcerpc_spoolss_AddPrinterEx_r(b, tctx, &rex) : |
| 7639 |
dcerpc_spoolss_AddPrinter_r(b, tctx, &r), |
| 7640 |
"failed to add printer"); |
| 7641 |
result = ex ? rex.out.result : r.out.result; |
| 7642 |
torture_assert_werr_equal(tctx, result, WERR_PRINTER_ALREADY_EXISTS, |
| 7643 |
"unexpected result code"); |
| 7644 |
|
| 7645 |
/* bizarre protocol, WERR_PRINTER_ALREADY_EXISTS means success here, |
| 7646 |
better do a real check to see the printer has really been removed |
| 7647 |
from the well known printer list */ |
| 7648 |
|
| 7649 |
found = false; |
| 7650 |
|
| 7651 |
torture_assert(tctx, test_EnumPrinters_findname(tctx, b, |
| 7652 |
PRINTER_ENUM_NETWORK, 1, |
| 7653 |
printername, |
| 7654 |
&found), |
| 7655 |
"failed to enum printers"); |
| 7656 |
#if 0 |
| 7657 |
torture_assert(tctx, !found, "printer still in well known printer list"); |
| 7658 |
#endif |
| 7659 |
return true; |
| 7660 |
} |
| 7661 |
|
| 7662 |
static bool test_AddPrinter_normal(struct torture_context *tctx, |
| 7663 |
struct dcerpc_pipe *p, |
| 7664 |
struct policy_handle *handle_p, |
| 7665 |
const char *printername, |
| 7666 |
const char *drivername, |
| 7667 |
const char *portname, |
| 7668 |
struct spoolss_DeviceMode *devmode, |
| 7669 |
bool ex) |
| 7670 |
{ |
| 7671 |
WERROR result; |
| 7672 |
struct spoolss_AddPrinter r; |
| 7673 |
struct spoolss_AddPrinterEx rex; |
| 7674 |
struct spoolss_SetPrinterInfoCtr info_ctr; |
| 7675 |
struct spoolss_SetPrinterInfo2 info2; |
| 7676 |
struct spoolss_DevmodeContainer devmode_ctr; |
| 7677 |
struct sec_desc_buf secdesc_ctr; |
| 7678 |
struct spoolss_UserLevelCtr userlevel_ctr; |
| 7679 |
struct policy_handle handle; |
| 7680 |
bool found = false; |
| 7681 |
bool existing_printer_deleted = false; |
| 7682 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 7683 |
|
| 7684 |
ZERO_STRUCT(devmode_ctr); |
| 7685 |
ZERO_STRUCT(secdesc_ctr); |
| 7686 |
ZERO_STRUCT(userlevel_ctr); |
| 7687 |
|
| 7688 |
torture_comment(tctx, "Testing AddPrinter%s(%s) level 2\n", |
| 7689 |
ex ? "Ex":"", printername); |
| 7690 |
|
| 7691 |
devmode_ctr.devmode = devmode; |
| 7692 |
|
| 7693 |
userlevel_ctr.level = 1; |
| 7694 |
|
| 7695 |
rex.in.server = NULL; |
| 7696 |
rex.in.info_ctr = &info_ctr; |
| 7697 |
rex.in.devmode_ctr = &devmode_ctr; |
| 7698 |
rex.in.secdesc_ctr = &secdesc_ctr; |
| 7699 |
rex.in.userlevel_ctr = &userlevel_ctr; |
| 7700 |
rex.out.handle = &handle; |
| 7701 |
|
| 7702 |
r.in.server = NULL; |
| 7703 |
r.in.info_ctr = &info_ctr; |
| 7704 |
r.in.devmode_ctr = &devmode_ctr; |
| 7705 |
r.in.secdesc_ctr = &secdesc_ctr; |
| 7706 |
r.out.handle = &handle; |
| 7707 |
|
| 7708 |
again: |
| 7709 |
|
| 7710 |
/* try to add printer to printer list (level 2) */ |
| 7711 |
|
| 7712 |
ZERO_STRUCT(info2); |
| 7713 |
|
| 7714 |
info_ctr.info.info2 = &info2; |
| 7715 |
info_ctr.level = 2; |
| 7716 |
|
| 7717 |
torture_assert_ntstatus_ok(tctx, ex ? dcerpc_spoolss_AddPrinterEx_r(b, tctx, &rex) : |
| 7718 |
dcerpc_spoolss_AddPrinter_r(b, tctx, &r), |
| 7719 |
"failed to add printer"); |
| 7720 |
result = ex ? rex.out.result : r.out.result; |
| 7721 |
torture_assert_werr_equal(tctx, result, WERR_INVALID_PRINTER_NAME, |
| 7722 |
"unexpected result code"); |
| 7723 |
|
| 7724 |
info2.printername = printername; |
| 7725 |
|
| 7726 |
torture_assert_ntstatus_ok(tctx, ex ? dcerpc_spoolss_AddPrinterEx_r(b, tctx, &rex) : |
| 7727 |
dcerpc_spoolss_AddPrinter_r(b, tctx, &r), |
| 7728 |
"failed to add printer"); |
| 7729 |
result = ex ? rex.out.result : r.out.result; |
| 7730 |
|
| 7731 |
if (W_ERROR_EQUAL(result, WERR_PRINTER_ALREADY_EXISTS)) { |
| 7732 |
struct policy_handle printer_handle; |
| 7733 |
|
| 7734 |
if (existing_printer_deleted) { |
| 7735 |
torture_fail(tctx, "already deleted printer still existing?"); |
| 7736 |
} |
| 7737 |
|
| 7738 |
torture_assert(tctx, call_OpenPrinterEx(tctx, p, printername, NULL, &printer_handle), |
| 7739 |
"failed to open printer handle"); |
| 7740 |
|
| 7741 |
torture_assert(tctx, test_DeletePrinter(tctx, b, &printer_handle), |
| 7742 |
"failed to delete printer"); |
| 7743 |
|
| 7744 |
torture_assert(tctx, test_ClosePrinter(tctx, b, &printer_handle), |
| 7745 |
"failed to close server handle"); |
| 7746 |
|
| 7747 |
existing_printer_deleted = true; |
| 7748 |
|
| 7749 |
goto again; |
| 7750 |
} |
| 7751 |
|
| 7752 |
torture_assert_werr_equal(tctx, result, WERR_UNKNOWN_PORT, |
| 7753 |
"unexpected result code"); |
| 7754 |
|
| 7755 |
info2.portname = portname; |
| 7756 |
|
| 7757 |
torture_assert_ntstatus_ok(tctx, ex ? dcerpc_spoolss_AddPrinterEx_r(b, tctx, &rex) : |
| 7758 |
dcerpc_spoolss_AddPrinter_r(b, tctx, &r), |
| 7759 |
"failed to add printer"); |
| 7760 |
result = ex ? rex.out.result : r.out.result; |
| 7761 |
torture_assert_werr_equal(tctx, result, WERR_UNKNOWN_PRINTER_DRIVER, |
| 7762 |
"unexpected result code"); |
| 7763 |
|
| 7764 |
info2.drivername = drivername; |
| 7765 |
|
| 7766 |
torture_assert_ntstatus_ok(tctx, ex ? dcerpc_spoolss_AddPrinterEx_r(b, tctx, &rex) : |
| 7767 |
dcerpc_spoolss_AddPrinter_r(b, tctx, &r), |
| 7768 |
"failed to add printer"); |
| 7769 |
result = ex ? rex.out.result : r.out.result; |
| 7770 |
|
| 7771 |
/* w2k8r2 allows one to add printer w/o defining printprocessor */ |
| 7772 |
|
| 7773 |
if (!W_ERROR_IS_OK(result)) { |
| 7774 |
torture_assert_werr_equal(tctx, result, WERR_UNKNOWN_PRINTPROCESSOR, |
| 7775 |
"unexpected result code"); |
| 7776 |
|
| 7777 |
info2.printprocessor = "winprint"; |
| 7778 |
|
| 7779 |
torture_assert_ntstatus_ok(tctx, ex ? dcerpc_spoolss_AddPrinterEx_r(b, tctx, &rex) : |
| 7780 |
dcerpc_spoolss_AddPrinter_r(b, tctx, &r), |
| 7781 |
"failed to add printer"); |
| 7782 |
result = ex ? rex.out.result : r.out.result; |
| 7783 |
torture_assert_werr_ok(tctx, result, |
| 7784 |
"failed to add printer"); |
| 7785 |
} |
| 7786 |
|
| 7787 |
*handle_p = handle; |
| 7788 |
|
| 7789 |
/* we are paranoid, really check if the printer is there now */ |
| 7790 |
|
| 7791 |
torture_assert(tctx, test_EnumPrinters_findname(tctx, b, |
| 7792 |
PRINTER_ENUM_LOCAL, 1, |
| 7793 |
printername, |
| 7794 |
&found), |
| 7795 |
"failed to enum printers"); |
| 7796 |
torture_assert(tctx, found, "failed to find newly added printer"); |
| 7797 |
|
| 7798 |
torture_assert_ntstatus_ok(tctx, ex ? dcerpc_spoolss_AddPrinterEx_r(b, tctx, &rex) : |
| 7799 |
dcerpc_spoolss_AddPrinter_r(b, tctx, &r), |
| 7800 |
"failed to add printer"); |
| 7801 |
result = ex ? rex.out.result : r.out.result; |
| 7802 |
torture_assert_werr_equal(tctx, result, WERR_PRINTER_ALREADY_EXISTS, |
| 7803 |
"unexpected result code"); |
| 7804 |
|
| 7805 |
return true; |
| 7806 |
} |
| 7807 |
|
| 7808 |
static bool test_printer_info(struct torture_context *tctx, |
| 7809 |
void *private_data) |
| 7810 |
{ |
| 7811 |
struct torture_printer_context *t = |
| 7812 |
(struct torture_printer_context *)talloc_get_type_abort(private_data, struct torture_printer_context); |
| 7813 |
struct dcerpc_pipe *p = t->spoolss_pipe; |
| 7814 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 7815 |
|
| 7816 |
bool ret = true; |
| 7817 |
|
| 7818 |
if (torture_setting_bool(tctx, "samba3", false) || |
| 7819 |
torture_setting_bool(tctx, "samba4", false)) { |
| 7820 |
torture_skip(tctx, |
| 7821 |
"skipping printer info cross tests against samba"); |
| 7822 |
} |
| 7823 |
|
| 7824 |
if (!test_PrinterInfo(tctx, b, &t->handle)) { |
| 7825 |
ret = false; |
| 7826 |
} |
| 7827 |
|
| 7828 |
if (!test_SetPrinter_errors(tctx, b, &t->handle)) { |
| 7829 |
ret = false; |
| 7830 |
} |
| 7831 |
|
| 7832 |
return ret; |
| 7833 |
} |
| 7834 |
|
| 7835 |
static bool test_EnumPrinterKey(struct torture_context *tctx, |
| 7836 |
struct dcerpc_binding_handle *b, |
| 7837 |
struct policy_handle *handle, |
| 7838 |
const char *key_name, |
| 7839 |
const char ***array) |
| 7840 |
{ |
| 7841 |
struct spoolss_EnumPrinterKey r; |
| 7842 |
uint32_t needed = 0; |
| 7843 |
union spoolss_KeyNames key_buffer = {}; |
| 7844 |
int32_t offered[] = { 0, 1, 2, 3, 4, 5, -1, -2, -3, -4, -5, 256, 512, 1024, 2048 }; |
| 7845 |
uint32_t _ndr_size; |
| 7846 |
int i; |
| 7847 |
|
| 7848 |
r.in.handle = handle; |
| 7849 |
r.in.key_name = key_name; |
| 7850 |
r.out.key_buffer = &key_buffer; |
| 7851 |
r.out.needed = &needed; |
| 7852 |
r.out._ndr_size = &_ndr_size; |
| 7853 |
|
| 7854 |
for (i=0; i < ARRAY_SIZE(offered); i++) { |
| 7855 |
|
| 7856 |
if (offered[i] < 0 && needed) { |
| 7857 |
if (needed <= 4) { |
| 7858 |
continue; |
| 7859 |
} |
| 7860 |
r.in.offered = needed + offered[i]; |
| 7861 |
} else { |
| 7862 |
r.in.offered = offered[i]; |
| 7863 |
} |
| 7864 |
|
| 7865 |
ZERO_STRUCT(key_buffer); |
| 7866 |
|
| 7867 |
torture_comment(tctx, "Testing EnumPrinterKey(%s) with %d offered\n", r.in.key_name, r.in.offered); |
| 7868 |
|
| 7869 |
torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_EnumPrinterKey_r(b, tctx, &r), |
| 7870 |
"failed to call EnumPrinterKey"); |
| 7871 |
if (W_ERROR_EQUAL(r.out.result, WERR_MORE_DATA)) { |
| 7872 |
|
| 7873 |
torture_assert(tctx, (_ndr_size == r.in.offered/2), |
| 7874 |
talloc_asprintf(tctx, "EnumPrinterKey size mismatch, _ndr_size %d (expected %d)", |
| 7875 |
_ndr_size, r.in.offered/2)); |
| 7876 |
|
| 7877 |
r.in.offered = needed; |
| 7878 |
torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_EnumPrinterKey_r(b, tctx, &r), |
| 7879 |
"failed to call EnumPrinterKey"); |
| 7880 |
} |
| 7881 |
|
| 7882 |
if (offered[i] > 0) { |
| 7883 |
torture_assert_werr_ok(tctx, r.out.result, |
| 7884 |
"failed to call EnumPrinterKey"); |
| 7885 |
} |
| 7886 |
|
| 7887 |
torture_assert(tctx, (_ndr_size == r.in.offered/2), |
| 7888 |
talloc_asprintf(tctx, "EnumPrinterKey size mismatch, _ndr_size %d (expected %d)", |
| 7889 |
_ndr_size, r.in.offered/2)); |
| 7890 |
|
| 7891 |
torture_assert(tctx, (*r.out.needed <= r.in.offered), |
| 7892 |
talloc_asprintf(tctx, "EnumPrinterKey size mismatch: needed %d is not <= offered %d", *r.out.needed, r.in.offered)); |
| 7893 |
|
| 7894 |
torture_assert(tctx, (*r.out.needed <= _ndr_size * 2), |
| 7895 |
talloc_asprintf(tctx, "EnumPrinterKey size mismatch: needed %d is not <= _ndr_size %d * 2", *r.out.needed, _ndr_size)); |
| 7896 |
|
| 7897 |
if (key_buffer.string_array) { |
| 7898 |
uint32_t calc_needed = 0; |
| 7899 |
int s; |
| 7900 |
for (s=0; key_buffer.string_array[s]; s++) { |
| 7901 |
calc_needed += strlen_m_term(key_buffer.string_array[s])*2; |
| 7902 |
} |
| 7903 |
if (!key_buffer.string_array[0]) { |
| 7904 |
calc_needed += 2; |
| 7905 |
} |
| 7906 |
calc_needed += 2; |
| 7907 |
|
| 7908 |
torture_assert_int_equal(tctx, *r.out.needed, calc_needed, |
| 7909 |
"EnumPrinterKey unexpected size"); |
| 7910 |
} |
| 7911 |
} |
| 7912 |
|
| 7913 |
if (array) { |
| 7914 |
*array = key_buffer.string_array; |
| 7915 |
} |
| 7916 |
|
| 7917 |
return true; |
| 7918 |
} |
| 7919 |
|
| 7920 |
bool test_printer_all_keys(struct torture_context *tctx, |
| 7921 |
struct dcerpc_binding_handle *b, |
| 7922 |
struct policy_handle *handle) |
| 7923 |
{ |
| 7924 |
const char **key_array = NULL; |
| 7925 |
int i; |
| 7926 |
|
| 7927 |
torture_comment(tctx, "Testing Printer Keys\n"); |
| 7928 |
|
| 7929 |
torture_assert(tctx, test_EnumPrinterKey(tctx, b, handle, "", &key_array), |
| 7930 |
"failed to call test_EnumPrinterKey"); |
| 7931 |
|
| 7932 |
for (i=0; key_array && key_array[i]; i++) { |
| 7933 |
torture_assert(tctx, test_EnumPrinterKey(tctx, b, handle, key_array[i], NULL), |
| 7934 |
"failed to call test_EnumPrinterKey"); |
| 7935 |
} |
| 7936 |
for (i=0; key_array && key_array[i]; i++) { |
| 7937 |
torture_assert(tctx, test_EnumPrinterDataEx(tctx, b, handle, key_array[i], NULL, NULL), |
| 7938 |
"failed to call test_EnumPrinterDataEx"); |
| 7939 |
} |
| 7940 |
|
| 7941 |
torture_comment(tctx, "Printer Keys test succeeded\n\n"); |
| 7942 |
|
| 7943 |
return true; |
| 7944 |
} |
| 7945 |
|
| 7946 |
static bool test_openprinter_wrap(struct torture_context *tctx, |
| 7947 |
void *private_data) |
| 7948 |
{ |
| 7949 |
struct torture_printer_context *t = |
| 7950 |
(struct torture_printer_context *)talloc_get_type_abort(private_data, struct torture_printer_context); |
| 7951 |
struct dcerpc_pipe *p = t->spoolss_pipe; |
| 7952 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 7953 |
const char *printername = t->info2.printername; |
| 7954 |
|
| 7955 |
return test_openprinter(tctx, b, printername); |
| 7956 |
} |
| 7957 |
|
| 7958 |
static bool test_csetprinter(struct torture_context *tctx, |
| 7959 |
void *private_data) |
| 7960 |
{ |
| 7961 |
struct torture_printer_context *t = |
| 7962 |
(struct torture_printer_context *)talloc_get_type_abort(private_data, struct torture_printer_context); |
| 7963 |
struct dcerpc_pipe *p = t->spoolss_pipe; |
| 7964 |
|
| 7965 |
const char *printername = talloc_asprintf(tctx, "%s2", t->info2.printername); |
| 7966 |
const char *drivername = t->added_driver ? t->driver.info8.driver_name : t->info2.drivername; |
| 7967 |
const char *portname = t->info2.portname; |
| 7968 |
|
| 7969 |
union spoolss_PrinterInfo info; |
| 7970 |
struct policy_handle new_handle, new_handle2; |
| 7971 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 7972 |
|
| 7973 |
torture_comment(tctx, "Testing c_setprinter\n"); |
| 7974 |
|
| 7975 |
torture_assert(tctx, |
| 7976 |
test_GetPrinter_level(tctx, b, &t->handle, 0, &info), |
| 7977 |
"failed to get level 0 printer info"); |
| 7978 |
torture_comment(tctx, "csetprinter on initial printer handle: %d\n", |
| 7979 |
info.info0.c_setprinter); |
| 7980 |
|
| 7981 |
/* check if c_setprinter on 1st handle increases after a printer has |
| 7982 |
* been added */ |
| 7983 |
|
| 7984 |
torture_assert(tctx, |
| 7985 |
test_AddPrinter_normal(tctx, p, &new_handle, printername, drivername, portname, NULL, false), |
| 7986 |
"failed to add new printer"); |
| 7987 |
torture_assert(tctx, |
| 7988 |
test_GetPrinter_level(tctx, b, &t->handle, 0, &info), |
| 7989 |
"failed to get level 0 printer info"); |
| 7990 |
torture_comment(tctx, "csetprinter on initial printer handle (after add): %d\n", |
| 7991 |
info.info0.c_setprinter); |
| 7992 |
|
| 7993 |
/* check if c_setprinter on new handle increases after a printer has |
| 7994 |
* been added */ |
| 7995 |
|
| 7996 |
torture_assert(tctx, |
| 7997 |
test_GetPrinter_level(tctx, b, &new_handle, 0, &info), |
| 7998 |
"failed to get level 0 printer info"); |
| 7999 |
torture_comment(tctx, "csetprinter on created handle: %d\n", |
| 8000 |
info.info0.c_setprinter); |
| 8001 |
|
| 8002 |
/* open the new printer and check if c_setprinter increases */ |
| 8003 |
|
| 8004 |
torture_assert(tctx, |
| 8005 |
call_OpenPrinterEx(tctx, p, printername, NULL, &new_handle2), |
| 8006 |
"failed to open created printer"); |
| 8007 |
torture_assert(tctx, |
| 8008 |
test_GetPrinter_level(tctx, b, &new_handle2, 0, &info), |
| 8009 |
"failed to get level 0 printer info"); |
| 8010 |
torture_comment(tctx, "csetprinter on new handle (after openprinter): %d\n", |
| 8011 |
info.info0.c_setprinter); |
| 8012 |
|
| 8013 |
/* cleanup */ |
| 8014 |
|
| 8015 |
torture_assert(tctx, |
| 8016 |
test_ClosePrinter(tctx, b, &new_handle2), |
| 8017 |
"failed to close printer"); |
| 8018 |
torture_assert(tctx, |
| 8019 |
test_DeletePrinter(tctx, b, &new_handle), |
| 8020 |
"failed to delete new printer"); |
| 8021 |
|
| 8022 |
return true; |
| 8023 |
} |
| 8024 |
|
| 8025 |
static bool compose_local_driver_directory(struct torture_context *tctx, |
| 8026 |
const char *environment, |
| 8027 |
const char *local_dir, |
| 8028 |
const char **path) |
| 8029 |
{ |
| 8030 |
char *p; |
| 8031 |
|
| 8032 |
p = strrchr(local_dir, '/'); |
| 8033 |
if (!p) { |
| 8034 |
return NULL; |
| 8035 |
} |
| 8036 |
p++; |
| 8037 |
|
| 8038 |
if (strequal(environment, SPOOLSS_ARCHITECTURE_x64)) { |
| 8039 |
if (!strequal(p, "x64")) { |
| 8040 |
*path = talloc_asprintf(tctx, "%s/x64", local_dir); |
| 8041 |
} |
| 8042 |
} else if (strequal(environment, SPOOLSS_ARCHITECTURE_NT_X86)) { |
| 8043 |
if (!strequal(p, "i386")) { |
| 8044 |
*path = talloc_asprintf(tctx, "%s/i386", local_dir); |
| 8045 |
} |
| 8046 |
} else { |
| 8047 |
torture_assert(tctx, "unknown environment: '%s'\n", environment); |
| 8048 |
} |
| 8049 |
|
| 8050 |
return true; |
| 8051 |
} |
| 8052 |
|
| 8053 |
#if 0 |
| 8054 |
static struct spoolss_DeviceMode *torture_devicemode(TALLOC_CTX *mem_ctx, |
| 8055 |
const char *devicename) |
| 8056 |
{ |
| 8057 |
struct spoolss_DeviceMode *r; |
| 8058 |
|
| 8059 |
r = talloc_zero(mem_ctx, struct spoolss_DeviceMode); |
| 8060 |
if (r == NULL) { |
| 8061 |
return NULL; |
| 8062 |
} |
| 8063 |
|
| 8064 |
r->devicename = talloc_strdup(r, devicename); |
| 8065 |
r->specversion = DMSPEC_NT4_AND_ABOVE; |
| 8066 |
r->driverversion = 0x0600; |
| 8067 |
r->size = 0x00dc; |
| 8068 |
r->__driverextra_length = 0; |
| 8069 |
r->fields = DEVMODE_FORMNAME | |
| 8070 |
DEVMODE_TTOPTION | |
| 8071 |
DEVMODE_PRINTQUALITY | |
| 8072 |
DEVMODE_DEFAULTSOURCE | |
| 8073 |
DEVMODE_COPIES | |
| 8074 |
DEVMODE_SCALE | |
| 8075 |
DEVMODE_PAPERSIZE | |
| 8076 |
DEVMODE_ORIENTATION; |
| 8077 |
r->orientation = DMORIENT_PORTRAIT; |
| 8078 |
r->papersize = DMPAPER_LETTER; |
| 8079 |
r->paperlength = 0; |
| 8080 |
r->paperwidth = 0; |
| 8081 |
r->scale = 100; |
| 8082 |
r->copies = 55; |
| 8083 |
r->defaultsource = DMBIN_FORMSOURCE; |
| 8084 |
r->printquality = DMRES_HIGH; |
| 8085 |
r->color = DMRES_MONOCHROME; |
| 8086 |
r->duplex = DMDUP_SIMPLEX; |
| 8087 |
r->yresolution = 0; |
| 8088 |
r->ttoption = DMTT_SUBDEV; |
| 8089 |
r->collate = DMCOLLATE_FALSE; |
| 8090 |
r->formname = talloc_strdup(r, "Letter"); |
| 8091 |
|
| 8092 |
return r; |
| 8093 |
} |
| 8094 |
#endif |
| 8095 |
|
| 8096 |
static bool test_architecture_buffer(struct torture_context *tctx, |
| 8097 |
void *private_data) |
| 8098 |
{ |
| 8099 |
struct test_spoolss_context *ctx = |
| 8100 |
talloc_get_type_abort(private_data, struct test_spoolss_context); |
| 8101 |
|
| 8102 |
struct spoolss_OpenPrinterEx r; |
| 8103 |
struct spoolss_UserLevel1 u1; |
| 8104 |
struct policy_handle handle; |
| 8105 |
uint32_t architectures[] = { |
| 8106 |
PROCESSOR_ARCHITECTURE_INTEL, |
| 8107 |
PROCESSOR_ARCHITECTURE_IA64, |
| 8108 |
PROCESSOR_ARCHITECTURE_AMD64 |
| 8109 |
}; |
| 8110 |
uint32_t needed[3]; |
| 8111 |
int i; |
| 8112 |
struct dcerpc_pipe *p = ctx->spoolss_pipe; |
| 8113 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 8114 |
|
| 8115 |
for (i=0; i < ARRAY_SIZE(architectures); i++) { |
| 8116 |
|
| 8117 |
torture_comment(tctx, "Testing OpenPrinterEx with architecture %d\n", architectures[i]); |
| 8118 |
|
| 8119 |
u1.size = 0; |
| 8120 |
u1.client = NULL; |
| 8121 |
u1.user = NULL; |
| 8122 |
u1.build = 0; |
| 8123 |
u1.major = 3; |
| 8124 |
u1.minor = 0; |
| 8125 |
u1.processor = architectures[i]; |
| 8126 |
|
| 8127 |
r.in.printername = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p)); |
| 8128 |
r.in.datatype = NULL; |
| 8129 |
r.in.devmode_ctr.devmode= NULL; |
| 8130 |
r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED; |
| 8131 |
r.in.userlevel_ctr.level = 1; |
| 8132 |
r.in.userlevel_ctr.user_info.level1 = &u1; |
| 8133 |
r.out.handle = &handle; |
| 8134 |
|
| 8135 |
torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_OpenPrinterEx_r(b, tctx, &r), ""); |
| 8136 |
torture_assert_werr_ok(tctx, r.out.result, ""); |
| 8137 |
|
| 8138 |
{ |
| 8139 |
struct spoolss_EnumPrinters e; |
| 8140 |
uint32_t count; |
| 8141 |
union spoolss_PrinterInfo *info; |
| 8142 |
|
| 8143 |
e.in.flags = PRINTER_ENUM_LOCAL; |
| 8144 |
e.in.server = NULL; |
| 8145 |
e.in.level = 2; |
| 8146 |
e.in.buffer = NULL; |
| 8147 |
e.in.offered = 0; |
| 8148 |
e.out.count = &count; |
| 8149 |
e.out.info = &info; |
| 8150 |
e.out.needed = &needed[i]; |
| 8151 |
|
| 8152 |
torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_EnumPrinters_r(b, tctx, &e), ""); |
| 8153 |
#if 0 |
| 8154 |
torture_comment(tctx, "needed was %d\n", needed[i]); |
| 8155 |
#endif |
| 8156 |
} |
| 8157 |
|
| 8158 |
torture_assert(tctx, test_ClosePrinter(tctx, b, &handle), ""); |
| 8159 |
} |
| 8160 |
|
| 8161 |
for (i=1; i < ARRAY_SIZE(architectures); i++) { |
| 8162 |
if (needed[i-1] != needed[i]) { |
| 8163 |
torture_fail(tctx, |
| 8164 |
talloc_asprintf(tctx, "needed size %d for architecture %d != needed size %d for architecture %d\n", |
| 8165 |
needed[i-1], architectures[i-1], needed[i], architectures[i])); |
| 8166 |
} |
| 8167 |
} |
| 8168 |
|
| 8169 |
return true; |
| 8170 |
} |
| 8171 |
|
| 8172 |
static bool test_get_core_printer_drivers_arch_guid(struct torture_context *tctx, |
| 8173 |
struct dcerpc_pipe *p, |
| 8174 |
const char *architecture, |
| 8175 |
const char *guid_str, |
| 8176 |
const char **package_id) |
| 8177 |
{ |
| 8178 |
struct spoolss_GetCorePrinterDrivers r; |
| 8179 |
struct spoolss_CorePrinterDriver core_printer_drivers; |
| 8180 |
DATA_BLOB blob = data_blob_talloc_zero(tctx, 2); |
| 8181 |
const char **s; |
| 8182 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 8183 |
struct GUID guid; |
| 8184 |
|
| 8185 |
s = talloc_zero_array(tctx, const char *, 2); |
| 8186 |
|
| 8187 |
r.in.servername = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p)); |
| 8188 |
r.in.architecture = "foobar"; |
| 8189 |
r.in.core_driver_size = 0; |
| 8190 |
r.in.core_driver_dependencies = (uint16_t *)blob.data; |
| 8191 |
r.in.core_printer_driver_count = 0; |
| 8192 |
r.out.core_printer_drivers = &core_printer_drivers; |
| 8193 |
|
| 8194 |
torture_assert_ntstatus_ok(tctx, |
| 8195 |
dcerpc_spoolss_GetCorePrinterDrivers_r(b, tctx, &r), |
| 8196 |
"spoolss_GetCorePrinterDrivers failed"); |
| 8197 |
torture_assert_hresult_equal(tctx, r.out.result, HRES_E_INVALIDARG, |
| 8198 |
"spoolss_GetCorePrinterDrivers failed"); |
| 8199 |
|
| 8200 |
guid = GUID_random(); |
| 8201 |
s[0] = GUID_string2(tctx, &guid); |
| 8202 |
|
| 8203 |
torture_assert(tctx, |
| 8204 |
push_reg_multi_sz(tctx, &blob, s), |
| 8205 |
"push_reg_multi_sz failed"); |
| 8206 |
|
| 8207 |
r.in.core_driver_size = blob.length/2; |
| 8208 |
r.in.core_driver_dependencies = (uint16_t *)blob.data; |
| 8209 |
r.in.core_printer_driver_count = 1; |
| 8210 |
r.out.core_printer_drivers = talloc_zero_array(tctx, struct spoolss_CorePrinterDriver, r.in.core_printer_driver_count); |
| 8211 |
|
| 8212 |
torture_assert_ntstatus_ok(tctx, |
| 8213 |
dcerpc_spoolss_GetCorePrinterDrivers_r(b, tctx, &r), |
| 8214 |
"spoolss_GetCorePrinterDrivers failed"); |
| 8215 |
torture_assert_werr_equal(tctx, |
| 8216 |
W_ERROR(WIN32_FROM_HRESULT(r.out.result)), WERR_INVALID_ENVIRONMENT, |
| 8217 |
"spoolss_GetCorePrinterDrivers failed"); |
| 8218 |
|
| 8219 |
r.in.architecture = architecture; |
| 8220 |
|
| 8221 |
torture_assert_ntstatus_ok(tctx, |
| 8222 |
dcerpc_spoolss_GetCorePrinterDrivers_r(b, tctx, &r), |
| 8223 |
"spoolss_GetCorePrinterDrivers failed"); |
| 8224 |
torture_assert_werr_equal(tctx, |
| 8225 |
W_ERROR(WIN32_FROM_HRESULT(r.out.result)), WERR_NOT_FOUND, |
| 8226 |
"spoolss_GetCorePrinterDrivers failed"); |
| 8227 |
|
| 8228 |
s[0] = talloc_strdup(s, guid_str); |
| 8229 |
|
| 8230 |
torture_assert(tctx, |
| 8231 |
push_reg_multi_sz(tctx, &blob, s), |
| 8232 |
"push_reg_multi_sz failed"); |
| 8233 |
|
| 8234 |
r.in.core_driver_size = blob.length/2; |
| 8235 |
r.in.core_driver_dependencies = (uint16_t *)blob.data; |
| 8236 |
r.in.core_printer_driver_count = 1; |
| 8237 |
r.out.core_printer_drivers = talloc_zero_array(tctx, struct spoolss_CorePrinterDriver, r.in.core_printer_driver_count); |
| 8238 |
|
| 8239 |
torture_assert_ntstatus_ok(tctx, |
| 8240 |
dcerpc_spoolss_GetCorePrinterDrivers_r(b, tctx, &r), |
| 8241 |
"spoolss_GetCorePrinterDrivers failed"); |
| 8242 |
torture_assert_hresult_ok(tctx, r.out.result, |
| 8243 |
"spoolss_GetCorePrinterDrivers failed"); |
| 8244 |
|
| 8245 |
if (package_id) { |
| 8246 |
*package_id = r.out.core_printer_drivers[0].szPackageID; |
| 8247 |
} |
| 8248 |
|
| 8249 |
return true; |
| 8250 |
} |
| 8251 |
|
| 8252 |
static bool test_get_core_printer_drivers(struct torture_context *tctx, |
| 8253 |
void *private_data) |
| 8254 |
{ |
| 8255 |
struct test_spoolss_context *ctx = |
| 8256 |
talloc_get_type_abort(private_data, struct test_spoolss_context); |
| 8257 |
|
| 8258 |
const char *architectures[] = { |
| 8259 |
SPOOLSS_ARCHITECTURE_NT_X86, |
| 8260 |
SPOOLSS_ARCHITECTURE_x64 |
| 8261 |
}; |
| 8262 |
int i; |
| 8263 |
struct dcerpc_pipe *p = ctx->spoolss_pipe; |
| 8264 |
|
| 8265 |
for (i=0; i < ARRAY_SIZE(architectures); i++) { |
| 8266 |
|
| 8267 |
torture_comment(tctx, "Testing GetCorePrinterDrivers(\"%s\",\"%s\")\n", |
| 8268 |
architectures[i], |
| 8269 |
SPOOLSS_CORE_PRINT_PACKAGE_FILES_XPSDRV); |
| 8270 |
|
| 8271 |
torture_assert(tctx, |
| 8272 |
test_get_core_printer_drivers_arch_guid(tctx, p, |
| 8273 |
architectures[i], |
| 8274 |
SPOOLSS_CORE_PRINT_PACKAGE_FILES_XPSDRV, |
| 8275 |
NULL), |
| 8276 |
""); |
| 8277 |
} |
| 8278 |
|
| 8279 |
return true; |
| 8280 |
} |
| 8281 |
|
| 8282 |
static bool test_get_printer_driver_package_path(struct torture_context *tctx, |
| 8283 |
void *private_data) |
| 8284 |
{ |
| 8285 |
struct test_spoolss_context *ctx = |
| 8286 |
talloc_get_type_abort(private_data, struct test_spoolss_context); |
| 8287 |
|
| 8288 |
const char *architectures[] = { |
| 8289 |
SPOOLSS_ARCHITECTURE_NT_X86, |
| 8290 |
SPOOLSS_ARCHITECTURE_x64 |
| 8291 |
}; |
| 8292 |
int i; |
| 8293 |
struct dcerpc_pipe *p = ctx->spoolss_pipe; |
| 8294 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 8295 |
|
| 8296 |
for (i=0; i < ARRAY_SIZE(architectures); i++) { |
| 8297 |
struct spoolss_GetPrinterDriverPackagePath r; |
| 8298 |
uint32_t required = 0; |
| 8299 |
const char *package_id = NULL; |
| 8300 |
|
| 8301 |
test_get_core_printer_drivers_arch_guid(tctx, p, |
| 8302 |
architectures[i], |
| 8303 |
SPOOLSS_CORE_PRINT_PACKAGE_FILES_XPSDRV, |
| 8304 |
&package_id), |
| 8305 |
|
| 8306 |
torture_comment(tctx, "Testing GetPrinterDriverPackagePath(\"%s\",\"%s\")\n", |
| 8307 |
architectures[i], package_id); |
| 8308 |
|
| 8309 |
r.in.servername = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p)); |
| 8310 |
r.in.architecture = "foobar"; |
| 8311 |
r.in.language = NULL; |
| 8312 |
r.in.package_id = ""; |
| 8313 |
r.in.driver_package_cab_size = 0; |
| 8314 |
r.in.driver_package_cab = NULL; |
| 8315 |
|
| 8316 |
r.out.required = &required; |
| 8317 |
r.out.driver_package_cab = NULL; |
| 8318 |
|
| 8319 |
torture_assert_ntstatus_ok(tctx, |
| 8320 |
dcerpc_spoolss_GetPrinterDriverPackagePath_r(b, tctx, &r), |
| 8321 |
"spoolss_GetPrinterDriverPackagePath failed"); |
| 8322 |
torture_assert_werr_equal(tctx, |
| 8323 |
W_ERROR(WIN32_FROM_HRESULT(r.out.result)), WERR_INVALID_ENVIRONMENT, |
| 8324 |
"spoolss_GetPrinterDriverPackagePath failed"); |
| 8325 |
|
| 8326 |
r.in.architecture = architectures[i]; |
| 8327 |
|
| 8328 |
torture_assert_ntstatus_ok(tctx, |
| 8329 |
dcerpc_spoolss_GetPrinterDriverPackagePath_r(b, tctx, &r), |
| 8330 |
"spoolss_GetPrinterDriverPackagePath failed"); |
| 8331 |
torture_assert_werr_equal(tctx, |
| 8332 |
W_ERROR(WIN32_FROM_HRESULT(r.out.result)), WERR_FILE_NOT_FOUND, |
| 8333 |
"spoolss_GetPrinterDriverPackagePath failed"); |
| 8334 |
|
| 8335 |
r.in.package_id = package_id; |
| 8336 |
|
| 8337 |
torture_assert_ntstatus_ok(tctx, |
| 8338 |
dcerpc_spoolss_GetPrinterDriverPackagePath_r(b, tctx, &r), |
| 8339 |
"spoolss_GetPrinterDriverPackagePath failed"); |
| 8340 |
torture_assert_hresult_ok(tctx, r.out.result, |
| 8341 |
"spoolss_GetPrinterDriverPackagePath failed"); |
| 8342 |
|
| 8343 |
r.in.driver_package_cab_size = required; |
| 8344 |
r.in.driver_package_cab = talloc_zero_array(tctx, char, required); |
| 8345 |
r.out.driver_package_cab = talloc_zero_array(tctx, char, required); |
| 8346 |
|
| 8347 |
torture_assert_ntstatus_ok(tctx, |
| 8348 |
dcerpc_spoolss_GetPrinterDriverPackagePath_r(b, tctx, &r), |
| 8349 |
"spoolss_GetPrinterDriverPackagePath failed"); |
| 8350 |
torture_assert_hresult_ok(tctx, r.out.result, |
| 8351 |
"spoolss_GetPrinterDriverPackagePath failed"); |
| 8352 |
|
| 8353 |
r.in.servername = NULL; |
| 8354 |
|
| 8355 |
torture_assert_ntstatus_ok(tctx, |
| 8356 |
dcerpc_spoolss_GetPrinterDriverPackagePath_r(b, tctx, &r), |
| 8357 |
"spoolss_GetPrinterDriverPackagePath failed"); |
| 8358 |
torture_assert_werr_equal(tctx, |
| 8359 |
W_ERROR(WIN32_FROM_HRESULT(r.out.result)), WERR_INSUFFICIENT_BUFFER, |
| 8360 |
"spoolss_GetPrinterDriverPackagePath failed"); |
| 8361 |
|
| 8362 |
r.in.driver_package_cab_size = required; |
| 8363 |
r.in.driver_package_cab = talloc_zero_array(tctx, char, required); |
| 8364 |
r.out.driver_package_cab = talloc_zero_array(tctx, char, required); |
| 8365 |
|
| 8366 |
torture_assert_ntstatus_ok(tctx, |
| 8367 |
dcerpc_spoolss_GetPrinterDriverPackagePath_r(b, tctx, &r), |
| 8368 |
"spoolss_GetPrinterDriverPackagePath failed"); |
| 8369 |
torture_assert_hresult_ok(tctx, r.out.result, |
| 8370 |
"spoolss_GetPrinterDriverPackagePath failed"); |
| 8371 |
|
| 8372 |
} |
| 8373 |
|
| 8374 |
return true; |
| 8375 |
} |
| 8376 |
|
| 8377 |
static bool test_get_printer_printserverhandle(struct torture_context *tctx, |
| 8378 |
void *private_data) |
| 8379 |
{ |
| 8380 |
struct test_spoolss_context *ctx = |
| 8381 |
talloc_get_type_abort(private_data, struct test_spoolss_context); |
| 8382 |
|
| 8383 |
struct dcerpc_pipe *p = ctx->spoolss_pipe; |
| 8384 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 8385 |
uint32_t levels[] = {0, 1, 2, /* 3,*/ 4, 5, 6, 7, 8}; |
| 8386 |
int i; |
| 8387 |
|
| 8388 |
for (i=0;i<ARRAY_SIZE(levels);i++) { |
| 8389 |
|
| 8390 |
torture_assert(tctx, |
| 8391 |
test_GetPrinter_level_exp(tctx, b, &ctx->server_handle, |
| 8392 |
levels[i], WERR_INVALID_LEVEL, |
| 8393 |
NULL), |
| 8394 |
"failed to call GetPrinter"); |
| 8395 |
} |
| 8396 |
|
| 8397 |
torture_assert(tctx, |
| 8398 |
test_GetPrinter_level(tctx, b, &ctx->server_handle, 3, NULL), |
| 8399 |
"failed to call GetPrinter"); |
| 8400 |
|
| 8401 |
return true; |
| 8402 |
} |
| 8403 |
|
| 8404 |
#define TEST_SID "S-1-5-21-1234567890-1234567890-1234567890-500" |
| 8405 |
|
| 8406 |
static bool test_set_printer_printserverhandle(struct torture_context *tctx, |
| 8407 |
void *private_data) |
| 8408 |
{ |
| 8409 |
struct test_spoolss_context *ctx = |
| 8410 |
talloc_get_type_abort(private_data, struct test_spoolss_context); |
| 8411 |
|
| 8412 |
struct dcerpc_pipe *p = ctx->spoolss_pipe; |
| 8413 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 8414 |
union spoolss_PrinterInfo info; |
| 8415 |
struct spoolss_SetPrinterInfoCtr info_ctr; |
| 8416 |
struct spoolss_SetPrinterInfo3 info3; |
| 8417 |
struct spoolss_DevmodeContainer devmode_ctr; |
| 8418 |
struct sec_desc_buf secdesc_ctr; |
| 8419 |
struct security_descriptor *sd; |
| 8420 |
struct security_ace *ace; |
| 8421 |
struct dom_sid sid; |
| 8422 |
int i; |
| 8423 |
|
| 8424 |
torture_assert(tctx, |
| 8425 |
test_GetPrinter_level(tctx, b, &ctx->server_handle, 3, &info), |
| 8426 |
"failed to call GetPrinter"); |
| 8427 |
|
| 8428 |
secdesc_ctr.sd = info.info3.secdesc; |
| 8429 |
secdesc_ctr.sd->owner_sid = NULL; |
| 8430 |
secdesc_ctr.sd->group_sid = NULL; |
| 8431 |
|
| 8432 |
sd = security_descriptor_copy(tctx, secdesc_ctr.sd); |
| 8433 |
if (sd == NULL) { |
| 8434 |
return false; |
| 8435 |
} |
| 8436 |
|
| 8437 |
ace = security_ace_create(tctx, |
| 8438 |
TEST_SID, |
| 8439 |
SEC_ACE_TYPE_ACCESS_ALLOWED, |
| 8440 |
SEC_STD_REQUIRED, |
| 8441 |
SEC_ACE_FLAG_CONTAINER_INHERIT); |
| 8442 |
torture_assert(tctx, ace, "failed to create ace"); |
| 8443 |
|
| 8444 |
torture_assert_ntstatus_ok(tctx, |
| 8445 |
security_descriptor_dacl_add(sd, ace), |
| 8446 |
"failed to add ace"); |
| 8447 |
|
| 8448 |
secdesc_ctr.sd = sd; |
| 8449 |
|
| 8450 |
info3.sec_desc_ptr = 0; |
| 8451 |
|
| 8452 |
info_ctr.level = 3; |
| 8453 |
info_ctr.info.info3 = &info3; |
| 8454 |
|
| 8455 |
ZERO_STRUCT(devmode_ctr); |
| 8456 |
|
| 8457 |
torture_assert(tctx, |
| 8458 |
test_SetPrinter(tctx, b, &ctx->server_handle, &info_ctr, |
| 8459 |
&devmode_ctr, &secdesc_ctr, 0), |
| 8460 |
"failed to call SetPrinter"); |
| 8461 |
|
| 8462 |
torture_assert(tctx, |
| 8463 |
test_GetPrinter_level(tctx, b, &ctx->server_handle, 3, &info), |
| 8464 |
"failed to call GetPrinter"); |
| 8465 |
|
| 8466 |
for (i = 0; i < info.info3.secdesc->dacl->num_aces; i++) { |
| 8467 |
if (security_ace_equal(&info.info3.secdesc->dacl->aces[i], ace)) { |
| 8468 |
break; |
| 8469 |
} |
| 8470 |
} |
| 8471 |
|
| 8472 |
if (i == info.info3.secdesc->dacl->num_aces) { |
| 8473 |
torture_fail(tctx, "ace not present"); |
| 8474 |
} |
| 8475 |
|
| 8476 |
torture_assert(tctx, |
| 8477 |
dom_sid_parse(TEST_SID, &sid), |
| 8478 |
"failed to parse sid"); |
| 8479 |
|
| 8480 |
torture_assert_ntstatus_ok(tctx, |
| 8481 |
security_descriptor_dacl_del(info.info3.secdesc, &sid), |
| 8482 |
"failed to remove ace from sd"); |
| 8483 |
|
| 8484 |
secdesc_ctr.sd = info.info3.secdesc; |
| 8485 |
|
| 8486 |
torture_assert(tctx, |
| 8487 |
test_SetPrinter(tctx, b, &ctx->server_handle, &info_ctr, |
| 8488 |
&devmode_ctr, &secdesc_ctr, 0), |
| 8489 |
"failed to call SetPrinter"); |
| 8490 |
|
| 8491 |
torture_assert(tctx, |
| 8492 |
test_GetPrinter_level(tctx, b, &ctx->server_handle, 3, &info), |
| 8493 |
"failed to call GetPrinter"); |
| 8494 |
|
| 8495 |
for (i = 0; i < info.info3.secdesc->dacl->num_aces; i++) { |
| 8496 |
if (security_ace_equal(&info.info3.secdesc->dacl->aces[i], ace)) { |
| 8497 |
torture_fail(tctx, "ace still present"); |
| 8498 |
} |
| 8499 |
} |
| 8500 |
|
| 8501 |
return true; |
| 8502 |
} |
| 8503 |
|
| 8504 |
|
| 8505 |
static bool test_PrintServer_Forms_Winreg(struct torture_context *tctx, |
| 8506 |
void *private_data) |
| 8507 |
{ |
| 8508 |
struct test_spoolss_context *ctx = |
| 8509 |
talloc_get_type_abort(private_data, struct test_spoolss_context); |
| 8510 |
struct dcerpc_pipe *p = ctx->spoolss_pipe; |
| 8511 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 8512 |
|
| 8513 |
return test_Forms_winreg(tctx, b, &ctx->server_handle, true, NULL); |
| 8514 |
} |
| 8515 |
|
| 8516 |
static bool test_PrintServer_Forms(struct torture_context *tctx, |
| 8517 |
void *private_data) |
| 8518 |
{ |
| 8519 |
struct test_spoolss_context *ctx = |
| 8520 |
talloc_get_type_abort(private_data, struct test_spoolss_context); |
| 8521 |
struct dcerpc_pipe *p = ctx->spoolss_pipe; |
| 8522 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 8523 |
|
| 8524 |
return test_Forms(tctx, b, &ctx->server_handle, true, NULL, NULL, NULL); |
| 8525 |
} |
| 8526 |
|
| 8527 |
static bool test_PrintServer_EnumForms(struct torture_context *tctx, |
| 8528 |
void *private_data) |
| 8529 |
{ |
| 8530 |
struct test_spoolss_context *ctx = |
| 8531 |
talloc_get_type_abort(private_data, struct test_spoolss_context); |
| 8532 |
struct dcerpc_pipe *p = ctx->spoolss_pipe; |
| 8533 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 8534 |
|
| 8535 |
return test_EnumForms_all(tctx, b, &ctx->server_handle, true); |
| 8536 |
} |
| 8537 |
|
| 8538 |
static bool torture_rpc_spoolss_setup_common(struct torture_context *tctx, struct test_spoolss_context *t) |
| 8539 |
{ |
| 8540 |
NTSTATUS status; |
| 8541 |
|
| 8542 |
status = torture_rpc_connection(tctx, &t->spoolss_pipe, &ndr_table_spoolss); |
| 8543 |
|
| 8544 |
torture_assert_ntstatus_ok(tctx, status, "Error connecting to server"); |
| 8545 |
|
| 8546 |
torture_assert(tctx, |
| 8547 |
test_OpenPrinter_server(tctx, t->spoolss_pipe, &t->server_handle), |
| 8548 |
"failed to open printserver"); |
| 8549 |
torture_assert(tctx, |
| 8550 |
test_get_environment(tctx, t->spoolss_pipe->binding_handle, &t->server_handle, &t->environment), |
| 8551 |
"failed to get environment"); |
| 8552 |
|
| 8553 |
return true; |
| 8554 |
} |
| 8555 |
|
| 8556 |
static bool torture_rpc_spoolss_setup(struct torture_context *tctx, void **data) |
| 8557 |
{ |
| 8558 |
struct test_spoolss_context *t; |
| 8559 |
|
| 8560 |
*data = t = talloc_zero(tctx, struct test_spoolss_context); |
| 8561 |
|
| 8562 |
return torture_rpc_spoolss_setup_common(tctx, t); |
| 8563 |
} |
| 8564 |
|
| 8565 |
static bool torture_rpc_spoolss_teardown_common(struct torture_context *tctx, struct test_spoolss_context *t) |
| 8566 |
{ |
| 8567 |
test_ClosePrinter(tctx, t->spoolss_pipe->binding_handle, &t->server_handle); |
| 8568 |
|
| 8569 |
return true; |
| 8570 |
} |
| 8571 |
|
| 8572 |
static bool torture_rpc_spoolss_teardown(struct torture_context *tctx, void *data) |
| 8573 |
{ |
| 8574 |
struct test_spoolss_context *t = talloc_get_type(data, struct test_spoolss_context); |
| 8575 |
bool ret; |
| 8576 |
|
| 8577 |
ret = torture_rpc_spoolss_teardown_common(tctx, t); |
| 8578 |
talloc_free(t); |
| 8579 |
|
| 8580 |
return ret; |
| 8581 |
} |
| 8582 |
|
| 8583 |
static bool torture_rpc_spoolss_printer_setup_common(struct torture_context *tctx, struct torture_printer_context *t) |
| 8584 |
{ |
| 8585 |
struct dcerpc_pipe *p; |
| 8586 |
struct dcerpc_binding_handle *b; |
| 8587 |
const char *server_name_slash; |
| 8588 |
const char *driver_name; |
| 8589 |
const char *printer_name; |
| 8590 |
const char *port_name; |
| 8591 |
|
| 8592 |
torture_assert_ntstatus_ok(tctx, |
| 8593 |
torture_rpc_connection(tctx, &t->spoolss_pipe, &ndr_table_spoolss), |
| 8594 |
"Error connecting to server"); |
| 8595 |
|
| 8596 |
p = t->spoolss_pipe; |
| 8597 |
b = p->binding_handle; |
| 8598 |
server_name_slash = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p)); |
| 8599 |
|
| 8600 |
t->driver.info8.version = SPOOLSS_DRIVER_VERSION_200X; |
| 8601 |
t->driver.info8.driver_name = TORTURE_DRIVER; |
| 8602 |
t->driver.info8.driver_path = "pscript5.dll"; |
| 8603 |
t->driver.info8.data_file = "cups6.ppd"; |
| 8604 |
t->driver.info8.config_file = "ps5ui.dll"; |
| 8605 |
t->driver.info8.help_file = "pscript.hlp"; |
| 8606 |
t->driver.info8.default_datatype = "RAW"; |
| 8607 |
t->driver.info8.dependent_files = talloc_zero(t, struct spoolss_StringArray); |
| 8608 |
t->driver.info8.dependent_files->string = talloc_zero_array(t, const char *, 8 + 1); |
| 8609 |
t->driver.info8.dependent_files->string[0] = "pscript5.dll"; |
| 8610 |
t->driver.info8.dependent_files->string[1] = "cups6.ppd"; |
| 8611 |
t->driver.info8.dependent_files->string[2] = "ps5ui.dll"; |
| 8612 |
t->driver.info8.dependent_files->string[3] = "pscript.hlp"; |
| 8613 |
t->driver.info8.dependent_files->string[4] = "pscript.ntf"; |
| 8614 |
t->driver.info8.dependent_files->string[5] = "cups6.ini"; |
| 8615 |
t->driver.info8.dependent_files->string[6] = "cupsps6.dll"; |
| 8616 |
t->driver.info8.dependent_files->string[7] = "cupsui6.dll"; |
| 8617 |
|
| 8618 |
t->driver.local.driver_directory= "/usr/share/cups/drivers"; |
| 8619 |
|
| 8620 |
t->info2.portname = "LPT1:"; |
| 8621 |
|
| 8622 |
printer_name = t->info2.printername; |
| 8623 |
port_name = t->info2.portname; |
| 8624 |
|
| 8625 |
torture_assert(tctx, |
| 8626 |
fillup_printserver_info(tctx, p, &t->driver), |
| 8627 |
"failed to fillup printserver info"); |
| 8628 |
|
| 8629 |
t->driver.info8.architecture = talloc_strdup(t, t->driver.remote.environment); |
| 8630 |
|
| 8631 |
torture_assert(tctx, |
| 8632 |
compose_local_driver_directory(tctx, t->driver.remote.environment, |
| 8633 |
t->driver.local.driver_directory, |
| 8634 |
&t->driver.local.driver_directory), |
| 8635 |
"failed to compose local driver directory"); |
| 8636 |
|
| 8637 |
t->info2.drivername = "Microsoft XPS Document Writer"; |
| 8638 |
|
| 8639 |
if (test_EnumPrinterDrivers_findone(tctx, b, server_name_slash, t->driver.remote.environment, 3, t->info2.drivername, NULL)) { |
| 8640 |
torture_comment(tctx, "driver '%s' (architecture: %s, version: 3) is present on server\n", |
| 8641 |
t->info2.drivername, t->driver.remote.environment); |
| 8642 |
t->have_driver = true; |
| 8643 |
goto try_add; |
| 8644 |
} |
| 8645 |
|
| 8646 |
torture_comment(tctx, "driver '%s' (architecture: %s, version: 3) does not exist on the server\n", |
| 8647 |
t->info2.drivername, t->driver.remote.environment); |
| 8648 |
|
| 8649 |
t->info2.drivername = "Microsoft XPS Document Writer v4"; |
| 8650 |
|
| 8651 |
if (test_EnumPrinterDrivers_findone(tctx, b, server_name_slash, t->driver.remote.environment, 3, t->info2.drivername, NULL)) { |
| 8652 |
torture_comment(tctx, "driver '%s' (architecture: %s, version: 4) is present on server\n", |
| 8653 |
t->info2.drivername, t->driver.remote.environment); |
| 8654 |
t->have_driver = true; |
| 8655 |
goto try_add; |
| 8656 |
} |
| 8657 |
|
| 8658 |
torture_comment(tctx, "trying to upload own driver\n"); |
| 8659 |
|
| 8660 |
if (!directory_exist(t->driver.local.driver_directory)) { |
| 8661 |
torture_warning(tctx, "no local driver is available!"); |
| 8662 |
t->have_driver = false; |
| 8663 |
goto try_add; |
| 8664 |
} |
| 8665 |
|
| 8666 |
torture_assert(tctx, |
| 8667 |
upload_printer_driver(tctx, dcerpc_server_name(p), &t->driver), |
| 8668 |
"failed to upload printer driver"); |
| 8669 |
|
| 8670 |
torture_assert(tctx, |
| 8671 |
test_AddPrinterDriver_args_level_3(tctx, b, server_name_slash, &t->driver.info8, 0, false, NULL), |
| 8672 |
"failed to add driver"); |
| 8673 |
|
| 8674 |
t->added_driver = true; |
| 8675 |
t->have_driver = true; |
| 8676 |
|
| 8677 |
try_add: |
| 8678 |
driver_name = t->added_driver ? t->driver.info8.driver_name : t->info2.drivername; |
| 8679 |
|
| 8680 |
if (t->wellknown) { |
| 8681 |
torture_assert(tctx, |
| 8682 |
test_AddPrinter_wellknown(tctx, p, printer_name, t->ex), |
| 8683 |
"failed to add wellknown printer"); |
| 8684 |
} else { |
| 8685 |
torture_assert(tctx, |
| 8686 |
test_AddPrinter_normal(tctx, p, &t->handle, printer_name, driver_name, port_name, t->devmode, t->ex), |
| 8687 |
"failed to add printer"); |
| 8688 |
} |
| 8689 |
|
| 8690 |
return true; |
| 8691 |
} |
| 8692 |
|
| 8693 |
static bool torture_rpc_spoolss_printer_setup(struct torture_context *tctx, void **data) |
| 8694 |
{ |
| 8695 |
struct torture_printer_context *t; |
| 8696 |
|
| 8697 |
*data = t = talloc_zero(tctx, struct torture_printer_context); |
| 8698 |
|
| 8699 |
t->ex = false; |
| 8700 |
t->wellknown = false; |
| 8701 |
t->info2.printername = TORTURE_PRINTER; |
| 8702 |
t->devmode = NULL; |
| 8703 |
|
| 8704 |
return torture_rpc_spoolss_printer_setup_common(tctx, t); |
| 8705 |
} |
| 8706 |
|
| 8707 |
static bool torture_rpc_spoolss_printerex_setup(struct torture_context *tctx, void **data) |
| 8708 |
{ |
| 8709 |
struct torture_printer_context *t; |
| 8710 |
|
| 8711 |
*data = t = talloc_zero(tctx, struct torture_printer_context); |
| 8712 |
|
| 8713 |
t->ex = true; |
| 8714 |
t->wellknown = false; |
| 8715 |
t->info2.printername = TORTURE_PRINTER_EX; |
| 8716 |
t->devmode = NULL; |
| 8717 |
|
| 8718 |
return torture_rpc_spoolss_printer_setup_common(tctx, t); |
| 8719 |
} |
| 8720 |
|
| 8721 |
static bool torture_rpc_spoolss_printerwkn_setup(struct torture_context *tctx, void **data) |
| 8722 |
{ |
| 8723 |
struct torture_printer_context *t; |
| 8724 |
|
| 8725 |
*data = t = talloc_zero(tctx, struct torture_printer_context); |
| 8726 |
|
| 8727 |
t->ex = false; |
| 8728 |
t->wellknown = true; |
| 8729 |
t->info2.printername = TORTURE_WELLKNOWN_PRINTER; |
| 8730 |
t->devmode = NULL; |
| 8731 |
|
| 8732 |
/* FIXME */ |
| 8733 |
if (t->wellknown) { |
| 8734 |
torture_skip(tctx, "skipping AddPrinter level 1"); |
| 8735 |
} |
| 8736 |
|
| 8737 |
return torture_rpc_spoolss_printer_setup_common(tctx, t); |
| 8738 |
} |
| 8739 |
|
| 8740 |
static bool torture_rpc_spoolss_printerexwkn_setup(struct torture_context *tctx, void **data) |
| 8741 |
{ |
| 8742 |
struct torture_printer_context *t; |
| 8743 |
|
| 8744 |
*data = t = talloc_zero(tctx, struct torture_printer_context); |
| 8745 |
|
| 8746 |
t->ex = true; |
| 8747 |
t->wellknown = true; |
| 8748 |
t->info2.printername = TORTURE_WELLKNOWN_PRINTER_EX; |
| 8749 |
t->devmode = NULL; |
| 8750 |
|
| 8751 |
/* FIXME */ |
| 8752 |
if (t->wellknown) { |
| 8753 |
torture_skip(tctx, "skipping AddPrinterEx level 1"); |
| 8754 |
} |
| 8755 |
|
| 8756 |
return torture_rpc_spoolss_printer_setup_common(tctx, t); |
| 8757 |
} |
| 8758 |
|
| 8759 |
#if 0 |
| 8760 |
static bool torture_rpc_spoolss_printerdm_setup(struct torture_context *tctx, void **data) |
| 8761 |
{ |
| 8762 |
struct torture_printer_context *t; |
| 8763 |
|
| 8764 |
*data = t = talloc_zero(tctx, struct torture_printer_context); |
| 8765 |
|
| 8766 |
t->ex = true; |
| 8767 |
t->wellknown = false; |
| 8768 |
t->info2.printername = TORTURE_PRINTER_EX; |
| 8769 |
t->devmode = torture_devicemode(t, TORTURE_PRINTER_EX); |
| 8770 |
|
| 8771 |
return torture_rpc_spoolss_printer_setup_common(tctx, t); |
| 8772 |
} |
| 8773 |
#endif |
| 8774 |
|
| 8775 |
static bool test_DeletePrinterDriverEx_exp(struct torture_context *tctx, |
| 8776 |
struct dcerpc_binding_handle *b, |
| 8777 |
const char *server, |
| 8778 |
const char *driver, |
| 8779 |
const char *environment, |
| 8780 |
uint32_t delete_flags, |
| 8781 |
uint32_t version, |
| 8782 |
WERROR expected_result); |
| 8783 |
|
| 8784 |
static bool torture_rpc_spoolss_printer_teardown_common(struct torture_context *tctx, struct torture_printer_context *t) |
| 8785 |
{ |
| 8786 |
bool found = false; |
| 8787 |
struct dcerpc_pipe *p = t->spoolss_pipe; |
| 8788 |
struct dcerpc_binding_handle *b = NULL; |
| 8789 |
const char *server_name_slash; |
| 8790 |
bool ok = true; |
| 8791 |
|
| 8792 |
if (p == NULL) { |
| 8793 |
return true; |
| 8794 |
} |
| 8795 |
b = p->binding_handle; |
| 8796 |
|
| 8797 |
server_name_slash = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p)); |
| 8798 |
|
| 8799 |
if (!t->wellknown) { |
| 8800 |
const char *printer_name = t->info2.printername; |
| 8801 |
|
| 8802 |
torture_assert_goto(tctx, |
| 8803 |
test_DeletePrinter(tctx, b, &t->handle), |
| 8804 |
ok, |
| 8805 |
remove_driver, |
| 8806 |
"failed to delete printer"); |
| 8807 |
|
| 8808 |
torture_assert_goto(tctx, |
| 8809 |
test_EnumPrinters_findname(tctx, b, PRINTER_ENUM_LOCAL, 1, |
| 8810 |
printer_name, &found), |
| 8811 |
ok, |
| 8812 |
remove_driver, |
| 8813 |
"failed to enumerate printers"); |
| 8814 |
|
| 8815 |
torture_assert_goto(tctx, |
| 8816 |
!found, |
| 8817 |
ok, |
| 8818 |
remove_driver, |
| 8819 |
"deleted printer still there"); |
| 8820 |
} |
| 8821 |
|
| 8822 |
|
| 8823 |
remove_driver: |
| 8824 |
if (t->added_driver) { |
| 8825 |
ok = remove_printer_driver(tctx, |
| 8826 |
dcerpc_server_name(p), |
| 8827 |
&t->driver); |
| 8828 |
if (!ok) { |
| 8829 |
torture_warning(tctx, |
| 8830 |
"failed to remove printer driver\n"); |
| 8831 |
} |
| 8832 |
|
| 8833 |
ok = test_DeletePrinterDriverEx_exp(tctx, b, |
| 8834 |
server_name_slash, |
| 8835 |
t->driver.info8.driver_name, |
| 8836 |
t->driver.info8.architecture, |
| 8837 |
DPD_DELETE_ALL_FILES, |
| 8838 |
t->driver.info8.version, |
| 8839 |
WERR_OK); |
| 8840 |
if (!ok) { |
| 8841 |
torture_warning(tctx, |
| 8842 |
"failed to delete printer driver via " |
| 8843 |
"spoolss\n"); |
| 8844 |
} |
| 8845 |
} |
| 8846 |
|
| 8847 |
return ok; |
| 8848 |
} |
| 8849 |
|
| 8850 |
static bool torture_rpc_spoolss_printer_teardown(struct torture_context *tctx, void *data) |
| 8851 |
{ |
| 8852 |
struct torture_printer_context *t = talloc_get_type(data, struct torture_printer_context); |
| 8853 |
bool ret; |
| 8854 |
|
| 8855 |
ret = torture_rpc_spoolss_printer_teardown_common(tctx, t); |
| 8856 |
talloc_free(t); |
| 8857 |
|
| 8858 |
return ret; |
| 8859 |
} |
| 8860 |
|
| 8861 |
static bool test_print_test(struct torture_context *tctx, |
| 8862 |
void *private_data) |
| 8863 |
{ |
| 8864 |
struct torture_printer_context *t = |
| 8865 |
(struct torture_printer_context *)talloc_get_type_abort(private_data, struct torture_printer_context); |
| 8866 |
struct dcerpc_pipe *p = t->spoolss_pipe; |
| 8867 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 8868 |
|
| 8869 |
torture_assert(tctx, |
| 8870 |
test_PausePrinter(tctx, b, &t->handle), |
| 8871 |
"failed to pause printer"); |
| 8872 |
|
| 8873 |
torture_assert(tctx, |
| 8874 |
test_DoPrintTest(tctx, b, &t->handle), |
| 8875 |
"failed to do print test"); |
| 8876 |
|
| 8877 |
torture_assert(tctx, |
| 8878 |
test_ResumePrinter(tctx, b, &t->handle), |
| 8879 |
"failed to resume printer"); |
| 8880 |
|
| 8881 |
return true; |
| 8882 |
} |
| 8883 |
|
| 8884 |
static bool test_print_test_extended(struct torture_context *tctx, |
| 8885 |
void *private_data) |
| 8886 |
{ |
| 8887 |
struct torture_printer_context *t = |
| 8888 |
(struct torture_printer_context *)talloc_get_type_abort(private_data, struct torture_printer_context); |
| 8889 |
struct dcerpc_pipe *p = t->spoolss_pipe; |
| 8890 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 8891 |
bool ret = true; |
| 8892 |
|
| 8893 |
torture_assert(tctx, |
| 8894 |
test_PausePrinter(tctx, b, &t->handle), |
| 8895 |
"failed to pause printer"); |
| 8896 |
|
| 8897 |
ret = test_DoPrintTest_extended(tctx, b, &t->handle); |
| 8898 |
if (ret == false) { |
| 8899 |
torture_comment(tctx, "WARNING! failed to do extended print test\n"); |
| 8900 |
if (torture_setting_bool(tctx, "samba3", false)) { |
| 8901 |
torture_comment(tctx, "non-critical for samba3\n"); |
| 8902 |
ret = true; |
| 8903 |
tctx->last_result = TORTURE_SKIP; |
| 8904 |
} |
| 8905 |
} |
| 8906 |
|
| 8907 |
torture_assert(tctx, |
| 8908 |
test_ResumePrinter(tctx, b, &t->handle), |
| 8909 |
"failed to resume printer"); |
| 8910 |
|
| 8911 |
return ret; |
| 8912 |
} |
| 8913 |
|
| 8914 |
static bool test_print_test_properties(struct torture_context *tctx, |
| 8915 |
void *private_data) |
| 8916 |
{ |
| 8917 |
struct torture_printer_context *t = |
| 8918 |
(struct torture_printer_context *)talloc_get_type_abort(private_data, struct torture_printer_context); |
| 8919 |
struct dcerpc_pipe *p = t->spoolss_pipe; |
| 8920 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 8921 |
|
| 8922 |
if (torture_setting_bool(tctx, "samba3", false) || |
| 8923 |
torture_setting_bool(tctx, "samba4", false)) { |
| 8924 |
torture_skip(tctx, "skip printer job property tests against samba"); |
| 8925 |
} |
| 8926 |
|
| 8927 |
torture_assert(tctx, |
| 8928 |
test_PausePrinter(tctx, b, &t->handle), |
| 8929 |
"failed to pause printer"); |
| 8930 |
|
| 8931 |
torture_assert(tctx, |
| 8932 |
test_DoPrintTest_properties(tctx, b, &t->handle), |
| 8933 |
"failed to test print job properties"); |
| 8934 |
|
| 8935 |
torture_assert(tctx, |
| 8936 |
test_ResumePrinter(tctx, b, &t->handle), |
| 8937 |
"failed to resume printer"); |
| 8938 |
|
| 8939 |
return true; |
| 8940 |
} |
| 8941 |
|
| 8942 |
/* use smbd file IO to spool a print job */ |
| 8943 |
static bool test_print_test_smbd(struct torture_context *tctx, |
| 8944 |
void *private_data) |
| 8945 |
{ |
| 8946 |
struct torture_printer_context *t = |
| 8947 |
(struct torture_printer_context *)talloc_get_type_abort(private_data, struct torture_printer_context); |
| 8948 |
struct dcerpc_pipe *p = t->spoolss_pipe; |
| 8949 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 8950 |
NTSTATUS status; |
| 8951 |
uint32_t count; |
| 8952 |
union spoolss_JobInfo *info = NULL; |
| 8953 |
int i; |
| 8954 |
|
| 8955 |
struct smb2_tree *tree; |
| 8956 |
struct smb2_handle job_h; |
| 8957 |
struct smbcli_options options; |
| 8958 |
TALLOC_CTX *mem_ctx = talloc_new(tctx); |
| 8959 |
/* |
| 8960 |
* Do not test against the dynamically added printers, printing via |
| 8961 |
* smbd means that a different spoolss process may handle the |
| 8962 |
* OpenPrinter request to the one that handled the AddPrinter request. |
| 8963 |
* This currently leads to an ugly race condition where one process |
| 8964 |
* sees the new printer and one doesn't. |
| 8965 |
*/ |
| 8966 |
const char *share = TORTURE_PRINTER_STATIC1; |
| 8967 |
|
| 8968 |
torture_comment(tctx, "Testing smbd job spooling\n"); |
| 8969 |
lpcfg_smbcli_options(tctx->lp_ctx, &options); |
| 8970 |
|
| 8971 |
status = smb2_connect(mem_ctx, |
| 8972 |
torture_setting_string(tctx, "host", NULL), |
| 8973 |
share, |
| 8974 |
tctx->lp_ctx, |
| 8975 |
lpcfg_resolve_context(tctx->lp_ctx), |
| 8976 |
samba_cmdline_get_creds(), |
| 8977 |
&tree, |
| 8978 |
tctx->ev, |
| 8979 |
&options, |
| 8980 |
lpcfg_socket_options(tctx->lp_ctx), |
| 8981 |
lpcfg_gensec_settings(tctx, tctx->lp_ctx)); |
| 8982 |
if (!NT_STATUS_IS_OK(status)) { |
| 8983 |
printf("Failed to connect to SMB2 printer %s - %s\n", |
| 8984 |
share, nt_errstr(status)); |
| 8985 |
return false; |
| 8986 |
} |
| 8987 |
|
| 8988 |
status = torture_smb2_testfile(tree, "smbd_spooler_job", &job_h); |
| 8989 |
torture_assert_ntstatus_ok(tctx, status, "smbd spool job create"); |
| 8990 |
|
| 8991 |
status = smb2_util_write(tree, job_h, "exciting print job data", 0, |
| 8992 |
sizeof("exciting print job data")); |
| 8993 |
torture_assert_ntstatus_ok(tctx, status, "smbd spool job write"); |
| 8994 |
|
| 8995 |
/* check back end spoolss job was created */ |
| 8996 |
torture_assert(tctx, |
| 8997 |
test_EnumJobs_args(tctx, b, &t->handle, 1, WERR_OK, |
| 8998 |
&count, &info), |
| 8999 |
"EnumJobs level 1 failed"); |
| 9000 |
|
| 9001 |
for (i = 0; i < count; i++) { |
| 9002 |
if (!strcmp(info[i].info1.document_name, "smbd_spooler_job")) { |
| 9003 |
break; |
| 9004 |
} |
| 9005 |
} |
| 9006 |
torture_assert(tctx, (i != count), "smbd_spooler_job not found"); |
| 9007 |
|
| 9008 |
status = smb2_util_close(tree, job_h); |
| 9009 |
torture_assert_ntstatus_ok(tctx, status, "smbd spool job close"); |
| 9010 |
|
| 9011 |
/* disconnect from printer share */ |
| 9012 |
talloc_free(mem_ctx); |
| 9013 |
|
| 9014 |
return true; |
| 9015 |
} |
| 9016 |
|
| 9017 |
static bool test_print_test_purge(struct torture_context *tctx, |
| 9018 |
void *private_data) |
| 9019 |
{ |
| 9020 |
struct torture_printer_context *t = |
| 9021 |
(struct torture_printer_context *)talloc_get_type_abort(private_data, |
| 9022 |
struct torture_printer_context); |
| 9023 |
struct dcerpc_pipe *p = t->spoolss_pipe; |
| 9024 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 9025 |
uint32_t num_jobs = 8; |
| 9026 |
uint32_t *job_ids; |
| 9027 |
int i; |
| 9028 |
bool ret = true; |
| 9029 |
uint32_t count; |
| 9030 |
union spoolss_JobInfo *info; |
| 9031 |
|
| 9032 |
torture_assert(tctx, |
| 9033 |
test_PausePrinter(tctx, b, &t->handle), |
| 9034 |
"failed to pause printer"); |
| 9035 |
|
| 9036 |
job_ids = talloc_zero_array(tctx, uint32_t, num_jobs); |
| 9037 |
for (i=0; i < num_jobs; i++) { |
| 9038 |
ret = test_DoPrintTest_add_one_job(tctx, b, &t->handle, |
| 9039 |
"TorturePrintJob", |
| 9040 |
&job_ids[i]); |
| 9041 |
torture_assert(tctx, ret, "failed to add print job"); |
| 9042 |
} |
| 9043 |
|
| 9044 |
torture_assert(tctx, |
| 9045 |
test_EnumJobs_args(tctx, b, &t->handle, 1, WERR_OK, |
| 9046 |
&count, &info), |
| 9047 |
"EnumJobs level 1 failed"); |
| 9048 |
|
| 9049 |
torture_assert_int_equal(tctx, count, num_jobs, |
| 9050 |
"unexpected number of jobs in queue"); |
| 9051 |
|
| 9052 |
torture_assert(tctx, |
| 9053 |
test_printer_purge(tctx, b, &t->handle), |
| 9054 |
"failed to purge printer"); |
| 9055 |
|
| 9056 |
torture_assert(tctx, |
| 9057 |
test_EnumJobs_args(tctx, b, &t->handle, 1, WERR_OK, |
| 9058 |
&count, &info), |
| 9059 |
"EnumJobs level 1 failed"); |
| 9060 |
|
| 9061 |
torture_assert_int_equal(tctx, count, 0, |
| 9062 |
"unexpected number of jobs in queue"); |
| 9063 |
|
| 9064 |
torture_assert(tctx, |
| 9065 |
test_ResumePrinter(tctx, b, &t->handle), |
| 9066 |
"failed to resume printer"); |
| 9067 |
|
| 9068 |
return true; |
| 9069 |
} |
| 9070 |
|
| 9071 |
static bool test_printer_sd(struct torture_context *tctx, |
| 9072 |
void *private_data) |
| 9073 |
{ |
| 9074 |
struct torture_printer_context *t = |
| 9075 |
(struct torture_printer_context *)talloc_get_type_abort(private_data, struct torture_printer_context); |
| 9076 |
struct dcerpc_pipe *p = t->spoolss_pipe; |
| 9077 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 9078 |
|
| 9079 |
torture_assert(tctx, |
| 9080 |
test_PrinterInfo_SD(tctx, b, &t->handle), |
| 9081 |
"failed to test security descriptors"); |
| 9082 |
|
| 9083 |
return true; |
| 9084 |
} |
| 9085 |
|
| 9086 |
static bool test_printer_dm(struct torture_context *tctx, |
| 9087 |
void *private_data) |
| 9088 |
{ |
| 9089 |
struct torture_printer_context *t = |
| 9090 |
(struct torture_printer_context *)talloc_get_type_abort(private_data, struct torture_printer_context); |
| 9091 |
struct dcerpc_pipe *p = t->spoolss_pipe; |
| 9092 |
|
| 9093 |
torture_assert(tctx, |
| 9094 |
test_PrinterInfo_DevMode(tctx, p, &t->handle, t->info2.printername, t->devmode), |
| 9095 |
"failed to test devicemodes"); |
| 9096 |
|
| 9097 |
return true; |
| 9098 |
} |
| 9099 |
|
| 9100 |
static bool test_printer_info_winreg(struct torture_context *tctx, |
| 9101 |
void *private_data) |
| 9102 |
{ |
| 9103 |
struct torture_printer_context *t = |
| 9104 |
(struct torture_printer_context *)talloc_get_type_abort(private_data, struct torture_printer_context); |
| 9105 |
struct dcerpc_pipe *p = t->spoolss_pipe; |
| 9106 |
|
| 9107 |
torture_assert(tctx, |
| 9108 |
test_PrinterInfo_winreg(tctx, p, &t->handle, t->info2.printername), |
| 9109 |
"failed to test printer info winreg"); |
| 9110 |
|
| 9111 |
return true; |
| 9112 |
} |
| 9113 |
|
| 9114 |
static bool test_printserver_info_winreg(struct torture_context *tctx, |
| 9115 |
void *private_data) |
| 9116 |
{ |
| 9117 |
struct test_spoolss_context *t = |
| 9118 |
(struct test_spoolss_context *)talloc_get_type_abort(private_data, struct test_spoolss_context); |
| 9119 |
struct dcerpc_pipe *p = t->spoolss_pipe; |
| 9120 |
|
| 9121 |
torture_assert(tctx, |
| 9122 |
test_PrintserverInfo_winreg(tctx, p, &t->server_handle), |
| 9123 |
"failed to test printserver info winreg"); |
| 9124 |
|
| 9125 |
return true; |
| 9126 |
} |
| 9127 |
|
| 9128 |
|
| 9129 |
static bool test_printer_change_id(struct torture_context *tctx, |
| 9130 |
void *private_data) |
| 9131 |
{ |
| 9132 |
struct torture_printer_context *t = |
| 9133 |
(struct torture_printer_context *)talloc_get_type_abort(private_data, struct torture_printer_context); |
| 9134 |
struct dcerpc_pipe *p = t->spoolss_pipe; |
| 9135 |
|
| 9136 |
torture_assert(tctx, |
| 9137 |
test_ChangeID(tctx, p, &t->handle), |
| 9138 |
"failed to test change id"); |
| 9139 |
|
| 9140 |
return true; |
| 9141 |
} |
| 9142 |
|
| 9143 |
static bool test_printer_keys(struct torture_context *tctx, |
| 9144 |
void *private_data) |
| 9145 |
{ |
| 9146 |
struct torture_printer_context *t = |
| 9147 |
(struct torture_printer_context *)talloc_get_type_abort(private_data, struct torture_printer_context); |
| 9148 |
struct dcerpc_pipe *p = t->spoolss_pipe; |
| 9149 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 9150 |
|
| 9151 |
torture_assert(tctx, |
| 9152 |
test_printer_all_keys(tctx, b, &t->handle), |
| 9153 |
"failed to test printer keys"); |
| 9154 |
|
| 9155 |
return true; |
| 9156 |
} |
| 9157 |
|
| 9158 |
static bool test_printer_data_consistency(struct torture_context *tctx, |
| 9159 |
void *private_data) |
| 9160 |
{ |
| 9161 |
struct torture_printer_context *t = |
| 9162 |
(struct torture_printer_context *)talloc_get_type_abort(private_data, struct torture_printer_context); |
| 9163 |
struct dcerpc_pipe *p = t->spoolss_pipe; |
| 9164 |
|
| 9165 |
torture_assert(tctx, |
| 9166 |
test_EnumPrinterData_consistency(tctx, p, &t->handle), |
| 9167 |
"failed to test printer data consistency"); |
| 9168 |
|
| 9169 |
return true; |
| 9170 |
} |
| 9171 |
|
| 9172 |
static bool test_printer_data_keys(struct torture_context *tctx, |
| 9173 |
void *private_data) |
| 9174 |
{ |
| 9175 |
struct torture_printer_context *t = |
| 9176 |
(struct torture_printer_context *)talloc_get_type_abort(private_data, struct torture_printer_context); |
| 9177 |
struct dcerpc_pipe *p = t->spoolss_pipe; |
| 9178 |
|
| 9179 |
torture_assert(tctx, |
| 9180 |
test_SetPrinterDataEx_keys(tctx, p, &t->handle), |
| 9181 |
"failed to test printer data keys"); |
| 9182 |
|
| 9183 |
return true; |
| 9184 |
} |
| 9185 |
|
| 9186 |
static bool test_printer_data_values(struct torture_context *tctx, |
| 9187 |
void *private_data) |
| 9188 |
{ |
| 9189 |
struct torture_printer_context *t = |
| 9190 |
(struct torture_printer_context *)talloc_get_type_abort(private_data, struct torture_printer_context); |
| 9191 |
struct dcerpc_pipe *p = t->spoolss_pipe; |
| 9192 |
|
| 9193 |
torture_assert(tctx, |
| 9194 |
test_SetPrinterDataEx_values(tctx, p, &t->handle), |
| 9195 |
"failed to test printer data values"); |
| 9196 |
|
| 9197 |
return true; |
| 9198 |
} |
| 9199 |
|
| 9200 |
static bool test_printer_data_set(struct torture_context *tctx, |
| 9201 |
void *private_data) |
| 9202 |
{ |
| 9203 |
struct torture_printer_context *t = |
| 9204 |
(struct torture_printer_context *)talloc_get_type_abort(private_data, struct torture_printer_context); |
| 9205 |
struct dcerpc_pipe *p = t->spoolss_pipe; |
| 9206 |
|
| 9207 |
torture_assert(tctx, |
| 9208 |
test_SetPrinterDataEx_matrix(tctx, p, &t->handle, t->info2.printername, NULL, NULL), |
| 9209 |
"failed to test printer data set"); |
| 9210 |
|
| 9211 |
return true; |
| 9212 |
} |
| 9213 |
|
| 9214 |
static bool test_printer_data_winreg(struct torture_context *tctx, |
| 9215 |
void *private_data) |
| 9216 |
{ |
| 9217 |
struct torture_printer_context *t = |
| 9218 |
(struct torture_printer_context *)talloc_get_type_abort(private_data, struct torture_printer_context); |
| 9219 |
struct dcerpc_pipe *p = t->spoolss_pipe; |
| 9220 |
|
| 9221 |
torture_assert(tctx, |
| 9222 |
test_PrinterData_winreg(tctx, p, &t->handle, t->info2.printername), |
| 9223 |
"failed to test printer data winreg"); |
| 9224 |
|
| 9225 |
return true; |
| 9226 |
} |
| 9227 |
|
| 9228 |
static bool test_printer_data_dsspooler(struct torture_context *tctx, |
| 9229 |
void *private_data) |
| 9230 |
{ |
| 9231 |
struct torture_printer_context *t = |
| 9232 |
(struct torture_printer_context *)talloc_get_type_abort(private_data, struct torture_printer_context); |
| 9233 |
struct dcerpc_pipe *p = t->spoolss_pipe; |
| 9234 |
|
| 9235 |
torture_assert(tctx, |
| 9236 |
test_PrinterData_DsSpooler(tctx, p, &t->handle, t->info2.printername), |
| 9237 |
"failed to test printer data winreg dsspooler"); |
| 9238 |
|
| 9239 |
return true; |
| 9240 |
} |
| 9241 |
|
| 9242 |
static bool test_printer_ic(struct torture_context *tctx, |
| 9243 |
void *private_data) |
| 9244 |
{ |
| 9245 |
struct torture_printer_context *t = |
| 9246 |
talloc_get_type_abort(private_data, |
| 9247 |
struct torture_printer_context); |
| 9248 |
struct dcerpc_pipe *p = t->spoolss_pipe; |
| 9249 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 9250 |
struct policy_handle gdi_handle; |
| 9251 |
|
| 9252 |
if (torture_setting_bool(tctx, "samba3", false) || |
| 9253 |
torture_setting_bool(tctx, "samba4", false)) { |
| 9254 |
torture_skip(tctx, "skip printer information context tests against samba"); |
| 9255 |
} |
| 9256 |
|
| 9257 |
{ |
| 9258 |
struct spoolss_CreatePrinterIC r; |
| 9259 |
struct spoolss_DevmodeContainer devmode_ctr; |
| 9260 |
|
| 9261 |
ZERO_STRUCT(devmode_ctr); |
| 9262 |
|
| 9263 |
r.in.handle = &t->handle; |
| 9264 |
r.in.devmode_ctr = &devmode_ctr; |
| 9265 |
r.out.gdi_handle = &gdi_handle; |
| 9266 |
|
| 9267 |
torture_assert_ntstatus_ok(tctx, |
| 9268 |
dcerpc_spoolss_CreatePrinterIC_r(b, tctx, &r), |
| 9269 |
"CreatePrinterIC failed"); |
| 9270 |
torture_assert_werr_ok(tctx, r.out.result, |
| 9271 |
"CreatePrinterIC failed"); |
| 9272 |
} |
| 9273 |
|
| 9274 |
{ |
| 9275 |
struct spoolss_PlayGDIScriptOnPrinterIC r; |
| 9276 |
DATA_BLOB in,out; |
| 9277 |
int i; |
| 9278 |
uint32_t num_fonts = 0; |
| 9279 |
|
| 9280 |
in = data_blob_string_const(""); |
| 9281 |
|
| 9282 |
r.in.gdi_handle = &gdi_handle; |
| 9283 |
r.in.pIn = in.data; |
| 9284 |
r.in.cIn = in.length; |
| 9285 |
r.in.ul = 0; |
| 9286 |
|
| 9287 |
for (i = 0; i < 4; i++) { |
| 9288 |
|
| 9289 |
out = data_blob_talloc_zero(tctx, i); |
| 9290 |
|
| 9291 |
r.in.cOut = out.length; |
| 9292 |
r.out.pOut = out.data; |
| 9293 |
|
| 9294 |
torture_assert_ntstatus_ok(tctx, |
| 9295 |
dcerpc_spoolss_PlayGDIScriptOnPrinterIC_r(b, tctx, &r), |
| 9296 |
"PlayGDIScriptOnPrinterIC failed"); |
| 9297 |
torture_assert_werr_equal(tctx, r.out.result, WERR_NOT_ENOUGH_MEMORY, |
| 9298 |
"PlayGDIScriptOnPrinterIC failed"); |
| 9299 |
} |
| 9300 |
|
| 9301 |
out = data_blob_talloc_zero(tctx, 4); |
| 9302 |
|
| 9303 |
r.in.cOut = out.length; |
| 9304 |
r.out.pOut = out.data; |
| 9305 |
|
| 9306 |
torture_assert_ntstatus_ok(tctx, |
| 9307 |
dcerpc_spoolss_PlayGDIScriptOnPrinterIC_r(b, tctx, &r), |
| 9308 |
"PlayGDIScriptOnPrinterIC failed"); |
| 9309 |
torture_assert_werr_equal(tctx, r.out.result, WERR_OK, |
| 9310 |
"PlayGDIScriptOnPrinterIC failed"); |
| 9311 |
|
| 9312 |
/* now we should have the required length, so retry with a |
| 9313 |
* buffer which is large enough to carry all font ids */ |
| 9314 |
|
| 9315 |
num_fonts = IVAL(r.out.pOut, 0); |
| 9316 |
|
| 9317 |
torture_comment(tctx, "PlayGDIScriptOnPrinterIC gave font count of %d\n", num_fonts); |
| 9318 |
|
| 9319 |
out = data_blob_talloc_zero(tctx, |
| 9320 |
num_fonts * sizeof(struct UNIVERSAL_FONT_ID) + 4); |
| 9321 |
|
| 9322 |
r.in.cOut = out.length; |
| 9323 |
r.out.pOut = out.data; |
| 9324 |
|
| 9325 |
torture_assert_ntstatus_ok(tctx, |
| 9326 |
dcerpc_spoolss_PlayGDIScriptOnPrinterIC_r(b, tctx, &r), |
| 9327 |
"PlayGDIScriptOnPrinterIC failed"); |
| 9328 |
torture_assert_werr_equal(tctx, r.out.result, WERR_OK, |
| 9329 |
"PlayGDIScriptOnPrinterIC failed"); |
| 9330 |
|
| 9331 |
} |
| 9332 |
|
| 9333 |
{ |
| 9334 |
struct spoolss_DeletePrinterIC r; |
| 9335 |
|
| 9336 |
r.in.gdi_handle = &gdi_handle; |
| 9337 |
r.out.gdi_handle = &gdi_handle; |
| 9338 |
|
| 9339 |
torture_assert_ntstatus_ok(tctx, |
| 9340 |
dcerpc_spoolss_DeletePrinterIC_r(b, tctx, &r), |
| 9341 |
"DeletePrinterIC failed"); |
| 9342 |
torture_assert_werr_ok(tctx, r.out.result, |
| 9343 |
"DeletePrinterIC failed"); |
| 9344 |
|
| 9345 |
} |
| 9346 |
|
| 9347 |
return true; |
| 9348 |
} |
| 9349 |
|
| 9350 |
static bool test_printer_bidi(struct torture_context *tctx, |
| 9351 |
void *private_data) |
| 9352 |
{ |
| 9353 |
struct torture_printer_context *t = |
| 9354 |
talloc_get_type_abort(private_data, |
| 9355 |
struct torture_printer_context); |
| 9356 |
struct dcerpc_pipe *p = t->spoolss_pipe; |
| 9357 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 9358 |
struct spoolss_SendRecvBidiData r; |
| 9359 |
struct RPC_BIDI_REQUEST_CONTAINER bidi_req; |
| 9360 |
struct RPC_BIDI_RESPONSE_CONTAINER *bidi_rep = NULL; |
| 9361 |
|
| 9362 |
if (torture_setting_bool(tctx, "samba3", false) || |
| 9363 |
torture_setting_bool(tctx, "samba4", false)) { |
| 9364 |
torture_skip(tctx, "skip printer bidirectional tests against samba"); |
| 9365 |
} |
| 9366 |
|
| 9367 |
ZERO_STRUCT(bidi_req); |
| 9368 |
|
| 9369 |
r.in.hPrinter = t->handle; |
| 9370 |
r.in.pAction = "foobar"; |
| 9371 |
r.in.pReqData = &bidi_req; |
| 9372 |
r.out.ppRespData = &bidi_rep; |
| 9373 |
|
| 9374 |
torture_assert_ntstatus_ok(tctx, |
| 9375 |
dcerpc_spoolss_SendRecvBidiData_r(b, tctx, &r), |
| 9376 |
"SendRecvBidiData failed"); |
| 9377 |
torture_assert_werr_equal(tctx, r.out.result, WERR_NOT_SUPPORTED, |
| 9378 |
"SendRecvBidiData failed"); |
| 9379 |
|
| 9380 |
if (!(t->info2.attributes & PRINTER_ATTRIBUTE_ENABLE_BIDI)) { |
| 9381 |
torture_skip(tctx, "skipping further tests as printer is not BIDI enabled"); |
| 9382 |
} |
| 9383 |
|
| 9384 |
r.in.pAction = BIDI_ACTION_ENUM_SCHEMA; |
| 9385 |
|
| 9386 |
torture_assert_ntstatus_ok(tctx, |
| 9387 |
dcerpc_spoolss_SendRecvBidiData_r(b, tctx, &r), |
| 9388 |
"SendRecvBidiData failed"); |
| 9389 |
torture_assert_werr_ok(tctx, r.out.result, |
| 9390 |
"SendRecvBidiData failed"); |
| 9391 |
|
| 9392 |
return true; |
| 9393 |
} |
| 9394 |
|
| 9395 |
static bool test_printer_set_publish(struct torture_context *tctx, |
| 9396 |
struct dcerpc_binding_handle *b, |
| 9397 |
struct policy_handle *handle) |
| 9398 |
{ |
| 9399 |
union spoolss_PrinterInfo info; |
| 9400 |
struct spoolss_SetPrinterInfo7 info7; |
| 9401 |
struct spoolss_SetPrinterInfoCtr info_ctr; |
| 9402 |
struct spoolss_DevmodeContainer devmode_ctr; |
| 9403 |
struct sec_desc_buf secdesc_ctr; |
| 9404 |
|
| 9405 |
info7.guid = ""; |
| 9406 |
info7.action = DSPRINT_PUBLISH; |
| 9407 |
|
| 9408 |
ZERO_STRUCT(info_ctr); |
| 9409 |
ZERO_STRUCT(devmode_ctr); |
| 9410 |
ZERO_STRUCT(secdesc_ctr); |
| 9411 |
info_ctr.level = 7; |
| 9412 |
info_ctr.info.info7 = &info7; |
| 9413 |
|
| 9414 |
torture_assert(tctx, |
| 9415 |
test_SetPrinter(tctx, b, handle, &info_ctr, |
| 9416 |
&devmode_ctr, &secdesc_ctr, 0), ""); |
| 9417 |
|
| 9418 |
torture_assert(tctx, |
| 9419 |
test_GetPrinter_level(tctx, b, handle, 2, &info), |
| 9420 |
""); |
| 9421 |
torture_assert(tctx, |
| 9422 |
(info.info2.attributes & PRINTER_ATTRIBUTE_PUBLISHED), |
| 9423 |
"info2 publish flag not set"); |
| 9424 |
torture_assert(tctx, |
| 9425 |
test_GetPrinter_level(tctx, b, handle, 7, &info), |
| 9426 |
""); |
| 9427 |
if (info.info7.action & DSPRINT_PENDING) { |
| 9428 |
torture_comment(tctx, "publish is pending\n"); |
| 9429 |
torture_assert_int_equal(tctx, |
| 9430 |
info.info7.action, |
| 9431 |
(DSPRINT_PENDING | DSPRINT_PUBLISH), |
| 9432 |
"info7 publish flag not set"); |
| 9433 |
} else { |
| 9434 |
struct GUID guid; |
| 9435 |
char *ref_guid; |
| 9436 |
torture_assert_int_equal(tctx, |
| 9437 |
info.info7.action, |
| 9438 |
DSPRINT_PUBLISH, |
| 9439 |
"info7 publish flag not set"); |
| 9440 |
|
| 9441 |
/* GUID_from_string is able to parse both plain and |
| 9442 |
* curly-braced guids */ |
| 9443 |
torture_assert_ntstatus_ok(tctx, |
| 9444 |
GUID_from_string(info.info7.guid, |
| 9445 |
&guid), |
| 9446 |
"invalid published printer GUID"); |
| 9447 |
|
| 9448 |
/* Build reference GUID string */ |
| 9449 |
ref_guid = GUID_string2(tctx, &guid); |
| 9450 |
torture_assert_not_null(tctx, ref_guid, "ENOMEM"); |
| 9451 |
ref_guid = talloc_strdup_upper(tctx, ref_guid); |
| 9452 |
torture_assert_not_null(tctx, ref_guid, "ENOMEM"); |
| 9453 |
torture_assert_str_equal(tctx, info.info7.guid, ref_guid, |
| 9454 |
"invalid GUID format"); |
| 9455 |
} |
| 9456 |
|
| 9457 |
return true; |
| 9458 |
} |
| 9459 |
|
| 9460 |
static bool test_printer_set_unpublish(struct torture_context *tctx, |
| 9461 |
struct dcerpc_binding_handle *b, |
| 9462 |
struct policy_handle *handle) |
| 9463 |
{ |
| 9464 |
union spoolss_PrinterInfo info; |
| 9465 |
struct spoolss_SetPrinterInfo7 info7; |
| 9466 |
struct spoolss_SetPrinterInfoCtr info_ctr; |
| 9467 |
struct spoolss_DevmodeContainer devmode_ctr; |
| 9468 |
struct sec_desc_buf secdesc_ctr; |
| 9469 |
|
| 9470 |
info7.action = DSPRINT_UNPUBLISH; |
| 9471 |
info7.guid = ""; |
| 9472 |
|
| 9473 |
ZERO_STRUCT(info_ctr); |
| 9474 |
ZERO_STRUCT(devmode_ctr); |
| 9475 |
ZERO_STRUCT(secdesc_ctr); |
| 9476 |
info_ctr.level = 7; |
| 9477 |
info_ctr.info.info7 = &info7; |
| 9478 |
|
| 9479 |
torture_assert(tctx, |
| 9480 |
test_SetPrinter(tctx, b, handle, &info_ctr, |
| 9481 |
&devmode_ctr, &secdesc_ctr, 0), ""); |
| 9482 |
|
| 9483 |
torture_assert(tctx, |
| 9484 |
test_GetPrinter_level(tctx, b, handle, 2, &info), |
| 9485 |
""); |
| 9486 |
torture_assert(tctx, |
| 9487 |
!(info.info2.attributes & PRINTER_ATTRIBUTE_PUBLISHED), |
| 9488 |
"info2 publish flag still set"); |
| 9489 |
torture_assert(tctx, |
| 9490 |
test_GetPrinter_level(tctx, b, handle, 7, &info), |
| 9491 |
""); |
| 9492 |
|
| 9493 |
if (info.info7.action & DSPRINT_PENDING) { |
| 9494 |
struct GUID guid; |
| 9495 |
torture_comment(tctx, "unpublish is pending\n"); |
| 9496 |
torture_assert_int_equal(tctx, |
| 9497 |
info.info7.action, |
| 9498 |
(DSPRINT_PENDING | DSPRINT_UNPUBLISH), |
| 9499 |
"info7 unpublish flag not set"); |
| 9500 |
torture_assert_ntstatus_ok(tctx, |
| 9501 |
GUID_from_string(info.info7.guid, |
| 9502 |
&guid), |
| 9503 |
"invalid printer GUID"); |
| 9504 |
} else { |
| 9505 |
torture_assert_int_equal(tctx, |
| 9506 |
info.info7.action, DSPRINT_UNPUBLISH, |
| 9507 |
"info7 unpublish flag not set"); |
| 9508 |
} |
| 9509 |
|
| 9510 |
return true; |
| 9511 |
} |
| 9512 |
|
| 9513 |
static bool test_printer_publish_toggle(struct torture_context *tctx, |
| 9514 |
void *private_data) |
| 9515 |
{ |
| 9516 |
struct torture_printer_context *t = |
| 9517 |
talloc_get_type_abort(private_data, |
| 9518 |
struct torture_printer_context); |
| 9519 |
struct dcerpc_pipe *p = t->spoolss_pipe; |
| 9520 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 9521 |
struct policy_handle *handle = &t->handle; |
| 9522 |
union spoolss_PrinterInfo info7; |
| 9523 |
union spoolss_PrinterInfo info2; |
| 9524 |
|
| 9525 |
/* check publish status via level 7 and level 2 */ |
| 9526 |
torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, 7, &info7), |
| 9527 |
""); |
| 9528 |
torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, 2, &info2), |
| 9529 |
""); |
| 9530 |
|
| 9531 |
if (info2.info2.attributes & PRINTER_ATTRIBUTE_PUBLISHED) { |
| 9532 |
torture_assert_int_equal(tctx, |
| 9533 |
info7.info7.action, DSPRINT_PUBLISH, |
| 9534 |
"info7 publish flag not set"); |
| 9535 |
torture_assert(tctx, test_printer_set_unpublish(tctx, b, handle), ""); |
| 9536 |
torture_assert(tctx, test_printer_set_publish(tctx, b, handle), ""); |
| 9537 |
} else { |
| 9538 |
torture_assert_int_equal(tctx, |
| 9539 |
info7.info7.action, DSPRINT_UNPUBLISH, |
| 9540 |
"info7 unpublish flag not set"); |
| 9541 |
torture_assert(tctx, test_printer_set_publish(tctx, b, handle), ""); |
| 9542 |
torture_assert(tctx, test_printer_set_unpublish(tctx, b, handle), ""); |
| 9543 |
} |
| 9544 |
|
| 9545 |
return true; |
| 9546 |
} |
| 9547 |
|
| 9548 |
static bool test_driver_info_winreg(struct torture_context *tctx, |
| 9549 |
void *private_data) |
| 9550 |
{ |
| 9551 |
struct torture_printer_context *t = |
| 9552 |
(struct torture_printer_context *)talloc_get_type_abort(private_data, struct torture_printer_context); |
| 9553 |
struct dcerpc_pipe *p = t->spoolss_pipe; |
| 9554 |
const char *driver_name = t->added_driver ? t->driver.info8.driver_name : t->info2.drivername; |
| 9555 |
|
| 9556 |
if (!t->have_driver) { |
| 9557 |
torture_skip(tctx, "skipping driver info winreg test as we don't have a driver"); |
| 9558 |
} |
| 9559 |
|
| 9560 |
torture_assert(tctx, |
| 9561 |
test_DriverInfo_winreg(tctx, p, &t->handle, t->info2.printername, driver_name, t->driver.remote.environment, 3), |
| 9562 |
"failed to test driver info winreg"); |
| 9563 |
|
| 9564 |
return true; |
| 9565 |
} |
| 9566 |
|
| 9567 |
static bool test_print_job_enum(struct torture_context *tctx, |
| 9568 |
void *private_data) |
| 9569 |
{ |
| 9570 |
struct torture_printer_context *t = |
| 9571 |
(struct torture_printer_context *)talloc_get_type_abort(private_data, struct torture_printer_context); |
| 9572 |
struct dcerpc_pipe *p = t->spoolss_pipe; |
| 9573 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 9574 |
bool ret = true; |
| 9575 |
uint32_t num_jobs = 8; |
| 9576 |
uint32_t *job_ids; |
| 9577 |
int i; |
| 9578 |
union spoolss_JobInfo *info = NULL; |
| 9579 |
uint32_t count; |
| 9580 |
|
| 9581 |
torture_assert(tctx, |
| 9582 |
test_PausePrinter(tctx, b, &t->handle), |
| 9583 |
"failed to pause printer"); |
| 9584 |
|
| 9585 |
/* purge in case of any jobs from previous tests */ |
| 9586 |
torture_assert(tctx, |
| 9587 |
test_printer_purge(tctx, b, &t->handle), |
| 9588 |
"failed to purge printer"); |
| 9589 |
|
| 9590 |
/* enum before jobs, valid level */ |
| 9591 |
torture_assert(tctx, |
| 9592 |
test_EnumJobs_args(tctx, b, &t->handle, 1, WERR_OK, |
| 9593 |
&count, &info), |
| 9594 |
"EnumJobs with valid level"); |
| 9595 |
torture_assert_int_equal(tctx, count, 0, "EnumJobs count"); |
| 9596 |
torture_assert(tctx, |
| 9597 |
test_EnumJobs_args(tctx, b, &t->handle, 2, WERR_OK, |
| 9598 |
&count, &info), |
| 9599 |
"EnumJobs with valid level"); |
| 9600 |
torture_assert_int_equal(tctx, count, 0, "EnumJobs count"); |
| 9601 |
/* enum before jobs, invalid level - expect failure */ |
| 9602 |
torture_assert(tctx, |
| 9603 |
test_EnumJobs_args(tctx, b, &t->handle, 100, |
| 9604 |
WERR_INVALID_LEVEL, |
| 9605 |
&count, &info), |
| 9606 |
"EnumJobs with invalid level"); |
| 9607 |
|
| 9608 |
job_ids = talloc_zero_array(tctx, uint32_t, num_jobs); |
| 9609 |
|
| 9610 |
for (i = 0; i < num_jobs; i++) { |
| 9611 |
ret = test_DoPrintTest_add_one_job(tctx, b, &t->handle, |
| 9612 |
"TorturePrintJob", |
| 9613 |
&job_ids[i]); |
| 9614 |
torture_assert(tctx, ret, "failed to add print job"); |
| 9615 |
} |
| 9616 |
|
| 9617 |
/* enum after jobs, valid level */ |
| 9618 |
torture_assert(tctx, |
| 9619 |
test_EnumJobs_args(tctx, b, &t->handle, 1, WERR_OK, |
| 9620 |
&count, &info), |
| 9621 |
"EnumJobs with valid level"); |
| 9622 |
torture_assert_int_equal(tctx, count, num_jobs, "EnumJobs count"); |
| 9623 |
torture_assert(tctx, |
| 9624 |
test_EnumJobs_args(tctx, b, &t->handle, 2, WERR_OK, |
| 9625 |
&count, &info), |
| 9626 |
"EnumJobs with valid level"); |
| 9627 |
torture_assert_int_equal(tctx, count, num_jobs, "EnumJobs count"); |
| 9628 |
/* enum after jobs, invalid level - expect failure */ |
| 9629 |
torture_assert(tctx, |
| 9630 |
test_EnumJobs_args(tctx, b, &t->handle, 100, |
| 9631 |
WERR_INVALID_LEVEL, |
| 9632 |
&count, &info), |
| 9633 |
"EnumJobs with invalid level"); |
| 9634 |
|
| 9635 |
for (i = 0; i < num_jobs; i++) { |
| 9636 |
test_SetJob(tctx, b, &t->handle, job_ids[i], NULL, |
| 9637 |
SPOOLSS_JOB_CONTROL_DELETE); |
| 9638 |
} |
| 9639 |
|
| 9640 |
torture_assert(tctx, |
| 9641 |
test_ResumePrinter(tctx, b, &t->handle), |
| 9642 |
"failed to resume printer"); |
| 9643 |
|
| 9644 |
return true; |
| 9645 |
} |
| 9646 |
|
| 9647 |
static bool test_printer_log_jobinfo(struct torture_context *tctx, |
| 9648 |
void *private_data) |
| 9649 |
{ |
| 9650 |
struct torture_printer_context *t = |
| 9651 |
(struct torture_printer_context *)talloc_get_type_abort(private_data, struct torture_printer_context); |
| 9652 |
struct dcerpc_pipe *p = t->spoolss_pipe; |
| 9653 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 9654 |
struct spoolss_BranchOfficeJobDataContainer info; |
| 9655 |
int i; |
| 9656 |
|
| 9657 |
struct spoolss_LogJobInfoForBranchOffice r; |
| 9658 |
|
| 9659 |
torture_comment(tctx, "Testing LogJobInfoForBranchOffice\n"); |
| 9660 |
|
| 9661 |
info.cJobDataEntries = 0; |
| 9662 |
info.JobData = NULL; |
| 9663 |
|
| 9664 |
r.in.hPrinter = &t->handle; |
| 9665 |
r.in.pBranchOfficeJobDataContainer = &info; |
| 9666 |
|
| 9667 |
torture_assert_ntstatus_ok(tctx, |
| 9668 |
dcerpc_spoolss_LogJobInfoForBranchOffice_r(b, tctx, &r), |
| 9669 |
"LogJobInfoForBranchOffice failed"); |
| 9670 |
torture_assert_werr_equal(tctx, r.out.result, WERR_INVALID_PARAMETER, |
| 9671 |
"LogJobInfoForBranchOffice failed"); |
| 9672 |
|
| 9673 |
info.cJobDataEntries = 1; |
| 9674 |
info.JobData = talloc_zero_array(tctx, struct spoolss_BranchOfficeJobData, info.cJobDataEntries); |
| 9675 |
|
| 9676 |
info.JobData[0].eEventType = kLogOfflineFileFull; |
| 9677 |
info.JobData[0].JobId = 42; |
| 9678 |
info.JobData[0].JobInfo.LogOfflineFileFull.pMachineName = talloc_strdup(tctx, "mthelena"); |
| 9679 |
|
| 9680 |
torture_assert_ntstatus_ok(tctx, |
| 9681 |
dcerpc_spoolss_LogJobInfoForBranchOffice_r(b, tctx, &r), |
| 9682 |
"LogJobInfoForBranchOffice failed"); |
| 9683 |
torture_assert_werr_equal(tctx, r.out.result, WERR_OK, |
| 9684 |
"LogJobInfoForBranchOffice failed"); |
| 9685 |
|
| 9686 |
info.cJobDataEntries = 42; |
| 9687 |
info.JobData = talloc_zero_array(tctx, struct spoolss_BranchOfficeJobData, info.cJobDataEntries); |
| 9688 |
|
| 9689 |
for (i=0; i < info.cJobDataEntries; i++) { |
| 9690 |
info.JobData[i].eEventType = kLogOfflineFileFull; |
| 9691 |
info.JobData[i].JobId = i; |
| 9692 |
info.JobData[i].JobInfo.LogOfflineFileFull.pMachineName = talloc_asprintf(tctx, "torture_%d", i); |
| 9693 |
} |
| 9694 |
|
| 9695 |
torture_assert_ntstatus_ok(tctx, |
| 9696 |
dcerpc_spoolss_LogJobInfoForBranchOffice_r(b, tctx, &r), |
| 9697 |
"LogJobInfoForBranchOffice failed"); |
| 9698 |
torture_assert_werr_equal(tctx, r.out.result, WERR_OK, |
| 9699 |
"LogJobInfoForBranchOffice failed"); |
| 9700 |
|
| 9701 |
return true; |
| 9702 |
} |
| 9703 |
|
| 9704 |
static bool test_printer_os_versions(struct torture_context *tctx, |
| 9705 |
void *private_data) |
| 9706 |
{ |
| 9707 |
struct torture_printer_context *t = |
| 9708 |
(struct torture_printer_context *)talloc_get_type_abort(private_data, struct torture_printer_context); |
| 9709 |
struct dcerpc_pipe *p = t->spoolss_pipe; |
| 9710 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 9711 |
union spoolss_PrinterInfo info; |
| 9712 |
DATA_BLOB blob; |
| 9713 |
uint8_t *data; |
| 9714 |
uint32_t length; |
| 9715 |
struct spoolss_OSVersion osversion; |
| 9716 |
uint8_t os_major, os_minor; |
| 9717 |
uint16_t os_build; |
| 9718 |
struct policy_handle server_handle; |
| 9719 |
|
| 9720 |
torture_comment(tctx, "Testing OSVersion vs. PRINTER_INFO_STRESS\n"); |
| 9721 |
|
| 9722 |
torture_assert(tctx, |
| 9723 |
test_GetPrinter_level(tctx, b, &t->handle, 0, &info), |
| 9724 |
"failed to get level 0 printer info"); |
| 9725 |
|
| 9726 |
torture_assert(tctx, |
| 9727 |
test_OpenPrinter_server(tctx, p, &server_handle), |
| 9728 |
"failed to open printserver"); |
| 9729 |
|
| 9730 |
torture_assert(tctx, |
| 9731 |
test_GetPrinterData_checktype(tctx, b, &server_handle, "OSVersion", |
| 9732 |
NULL, NULL, &data, &length), |
| 9733 |
"failed to fetch OSVersion printer data"); |
| 9734 |
|
| 9735 |
test_ClosePrinter(tctx, b, &server_handle); |
| 9736 |
|
| 9737 |
blob = data_blob_const(data, length); |
| 9738 |
|
| 9739 |
torture_assert_ndr_success(tctx, |
| 9740 |
ndr_pull_struct_blob(&blob, tctx, &osversion, |
| 9741 |
(ndr_pull_flags_fn_t)ndr_pull_spoolss_OSVersion), |
| 9742 |
"failed to pull OSVersion"); |
| 9743 |
|
| 9744 |
os_major = CVAL(&info.info0.version, 0); |
| 9745 |
os_minor = CVAL(&info.info0.version, 1); |
| 9746 |
os_build = SVAL(&info.info0.version, 2); |
| 9747 |
|
| 9748 |
torture_assert_int_equal(tctx, os_major, osversion.major, "major"); |
| 9749 |
torture_assert_int_equal(tctx, os_minor, osversion.minor, "minor"); |
| 9750 |
torture_assert_int_equal(tctx, os_build, osversion.build, "build"); |
| 9751 |
|
| 9752 |
return true; |
| 9753 |
} |
| 9754 |
|
| 9755 |
|
| 9756 |
void torture_tcase_printer(struct torture_tcase *tcase) |
| 9757 |
{ |
| 9758 |
torture_tcase_add_simple_test(tcase, "openprinter", test_openprinter_wrap); |
| 9759 |
torture_tcase_add_simple_test(tcase, "csetprinter", test_csetprinter); |
| 9760 |
torture_tcase_add_simple_test(tcase, "print_test", test_print_test); |
| 9761 |
torture_tcase_add_simple_test(tcase, "print_test_extended", test_print_test_extended); |
| 9762 |
torture_tcase_add_simple_test(tcase, "print_test_smbd", test_print_test_smbd); |
| 9763 |
torture_tcase_add_simple_test(tcase, "print_test_properties", test_print_test_properties); |
| 9764 |
torture_tcase_add_simple_test(tcase, "print_test_purge", test_print_test_purge); |
| 9765 |
torture_tcase_add_simple_test(tcase, "printer_info", test_printer_info); |
| 9766 |
torture_tcase_add_simple_test(tcase, "sd", test_printer_sd); |
| 9767 |
torture_tcase_add_simple_test(tcase, "dm", test_printer_dm); |
| 9768 |
torture_tcase_add_simple_test(tcase, "printer_info_winreg", test_printer_info_winreg); |
| 9769 |
torture_tcase_add_simple_test(tcase, "change_id", test_printer_change_id); |
| 9770 |
torture_tcase_add_simple_test(tcase, "keys", test_printer_keys); |
| 9771 |
torture_tcase_add_simple_test(tcase, "printerdata_consistency", test_printer_data_consistency); |
| 9772 |
torture_tcase_add_simple_test(tcase, "printerdata_keys", test_printer_data_keys); |
| 9773 |
torture_tcase_add_simple_test(tcase, "printerdata_values", test_printer_data_values); |
| 9774 |
torture_tcase_add_simple_test(tcase, "printerdata_set", test_printer_data_set); |
| 9775 |
torture_tcase_add_simple_test(tcase, "printerdata_winreg", test_printer_data_winreg); |
| 9776 |
torture_tcase_add_simple_test(tcase, "printerdata_dsspooler", test_printer_data_dsspooler); |
| 9777 |
torture_tcase_add_simple_test(tcase, "driver_info_winreg", test_driver_info_winreg); |
| 9778 |
torture_tcase_add_simple_test(tcase, "printer_rename", test_printer_rename); |
| 9779 |
torture_tcase_add_simple_test(tcase, "printer_ic", test_printer_ic); |
| 9780 |
torture_tcase_add_simple_test(tcase, "bidi", test_printer_bidi); |
| 9781 |
torture_tcase_add_simple_test(tcase, "publish_toggle", |
| 9782 |
test_printer_publish_toggle); |
| 9783 |
torture_tcase_add_simple_test(tcase, "print_job_enum", test_print_job_enum); |
| 9784 |
torture_tcase_add_simple_test(tcase, "log_jobinfo", test_printer_log_jobinfo); |
| 9785 |
torture_tcase_add_simple_test(tcase, "os_versions", test_printer_os_versions); |
| 9786 |
} |
| 9787 |
|
| 9788 |
struct torture_suite *torture_rpc_spoolss_printer(TALLOC_CTX *mem_ctx) |
| 9789 |
{ |
| 9790 |
struct torture_suite *suite = torture_suite_create(mem_ctx, "printer"); |
| 9791 |
struct torture_tcase *tcase; |
| 9792 |
|
| 9793 |
tcase = torture_suite_add_tcase(suite, "addprinter"); |
| 9794 |
|
| 9795 |
torture_tcase_set_fixture(tcase, |
| 9796 |
torture_rpc_spoolss_printer_setup, |
| 9797 |
torture_rpc_spoolss_printer_teardown); |
| 9798 |
|
| 9799 |
torture_tcase_printer(tcase); |
| 9800 |
|
| 9801 |
tcase = torture_suite_add_tcase(suite, "addprinterex"); |
| 9802 |
|
| 9803 |
torture_tcase_set_fixture(tcase, |
| 9804 |
torture_rpc_spoolss_printerex_setup, |
| 9805 |
torture_rpc_spoolss_printer_teardown); |
| 9806 |
|
| 9807 |
torture_tcase_printer(tcase); |
| 9808 |
|
| 9809 |
tcase = torture_suite_add_tcase(suite, "addprinterwkn"); |
| 9810 |
|
| 9811 |
torture_tcase_set_fixture(tcase, |
| 9812 |
torture_rpc_spoolss_printerwkn_setup, |
| 9813 |
torture_rpc_spoolss_printer_teardown); |
| 9814 |
|
| 9815 |
tcase = torture_suite_add_tcase(suite, "addprinterexwkn"); |
| 9816 |
|
| 9817 |
torture_tcase_set_fixture(tcase, |
| 9818 |
torture_rpc_spoolss_printerexwkn_setup, |
| 9819 |
torture_rpc_spoolss_printer_teardown); |
| 9820 |
|
| 9821 |
#if 0 |
| 9822 |
/* test is not correct */ |
| 9823 |
tcase = torture_suite_add_tcase(suite, "addprinterdm"); |
| 9824 |
|
| 9825 |
torture_tcase_set_fixture(tcase, |
| 9826 |
torture_rpc_spoolss_printerdm_setup, |
| 9827 |
torture_rpc_spoolss_printer_teardown); |
| 9828 |
|
| 9829 |
torture_tcase_printer(tcase); |
| 9830 |
#endif |
| 9831 |
return suite; |
| 9832 |
} |
| 9833 |
|
| 9834 |
struct torture_suite *torture_rpc_spoolss(TALLOC_CTX *mem_ctx) |
| 9835 |
{ |
| 9836 |
struct torture_suite *suite = torture_suite_create(mem_ctx, "spoolss"); |
| 9837 |
struct torture_tcase *tcase = torture_suite_add_tcase(suite, "printserver"); |
| 9838 |
|
| 9839 |
torture_tcase_set_fixture(tcase, |
| 9840 |
torture_rpc_spoolss_setup, |
| 9841 |
torture_rpc_spoolss_teardown); |
| 9842 |
|
| 9843 |
torture_tcase_add_simple_test(tcase, "openprinter_badnamelist", test_OpenPrinter_badname_list); |
| 9844 |
torture_tcase_add_simple_test(tcase, "printer_data_list", test_GetPrinterData_list); |
| 9845 |
torture_tcase_add_simple_test(tcase, "enum_forms", test_PrintServer_EnumForms); |
| 9846 |
torture_tcase_add_simple_test(tcase, "forms", test_PrintServer_Forms); |
| 9847 |
torture_tcase_add_simple_test(tcase, "forms_winreg", test_PrintServer_Forms_Winreg); |
| 9848 |
torture_tcase_add_simple_test(tcase, "enum_ports", test_EnumPorts); |
| 9849 |
torture_tcase_add_simple_test(tcase, "add_port", test_AddPort); |
| 9850 |
torture_tcase_add_simple_test(tcase, "get_printer_driver_directory", test_GetPrinterDriverDirectory); |
| 9851 |
torture_tcase_add_simple_test(tcase, "get_print_processor_directory", test_GetPrintProcessorDirectory); |
| 9852 |
torture_tcase_add_simple_test(tcase, "enum_printer_drivers", test_EnumPrinterDrivers); |
| 9853 |
torture_tcase_add_simple_test(tcase, "enum_monitors", test_EnumMonitors); |
| 9854 |
torture_tcase_add_simple_test(tcase, "enum_print_processors", test_EnumPrintProcessors); |
| 9855 |
torture_tcase_add_simple_test(tcase, "print_processors_winreg", test_print_processors_winreg); |
| 9856 |
torture_tcase_add_simple_test(tcase, "add_processor", test_add_print_processor); |
| 9857 |
torture_tcase_add_simple_test(tcase, "enum_printprocdata", test_EnumPrintProcessorDataTypes); |
| 9858 |
torture_tcase_add_simple_test(tcase, "enum_printers", test_EnumPrinters); |
| 9859 |
torture_tcase_add_simple_test(tcase, "enum_ports_old", test_EnumPorts_old); |
| 9860 |
torture_tcase_add_simple_test(tcase, "enum_printers_old", test_EnumPrinters_old); |
| 9861 |
torture_tcase_add_simple_test(tcase, "enum_printers_servername", test_EnumPrinters_servername); |
| 9862 |
torture_tcase_add_simple_test(tcase, "enum_printer_drivers_old", test_EnumPrinterDrivers_old); |
| 9863 |
torture_tcase_add_simple_test(tcase, "architecture_buffer", test_architecture_buffer); |
| 9864 |
torture_tcase_add_simple_test(tcase, "get_core_printer_drivers", test_get_core_printer_drivers); |
| 9865 |
torture_tcase_add_simple_test(tcase, "get_printer_driver_package_path", test_get_printer_driver_package_path); |
| 9866 |
torture_tcase_add_simple_test(tcase, "get_printer", test_get_printer_printserverhandle); |
| 9867 |
torture_tcase_add_simple_test(tcase, "set_printer", test_set_printer_printserverhandle); |
| 9868 |
torture_tcase_add_simple_test(tcase, "printserver_info_winreg", test_printserver_info_winreg); |
| 9869 |
torture_tcase_add_simple_test(tcase, "addpermachineconnection", test_addpermachineconnection); |
| 9870 |
|
| 9871 |
torture_suite_add_suite(suite, torture_rpc_spoolss_printer(suite)); |
| 9872 |
|
| 9873 |
return suite; |
| 9874 |
} |
| 9875 |
|
| 9876 |
static bool test_GetPrinterDriverDirectory_getdir(struct torture_context *tctx, |
| 9877 |
struct dcerpc_binding_handle *b, |
| 9878 |
const char *server, |
| 9879 |
const char *environment, |
| 9880 |
const char **dir_p) |
| 9881 |
{ |
| 9882 |
struct spoolss_GetPrinterDriverDirectory r; |
| 9883 |
uint32_t needed; |
| 9884 |
|
| 9885 |
r.in.server = server; |
| 9886 |
r.in.environment = environment; |
| 9887 |
r.in.level = 1; |
| 9888 |
r.in.buffer = NULL; |
| 9889 |
r.in.offered = 0; |
| 9890 |
r.out.needed = &needed; |
| 9891 |
|
| 9892 |
torture_assert_ntstatus_ok(tctx, |
| 9893 |
dcerpc_spoolss_GetPrinterDriverDirectory_r(b, tctx, &r), |
| 9894 |
"failed to query driver directory"); |
| 9895 |
|
| 9896 |
if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) { |
| 9897 |
DATA_BLOB blob = data_blob_talloc_zero(tctx, needed); |
| 9898 |
r.in.buffer = &blob; |
| 9899 |
r.in.offered = needed; |
| 9900 |
|
| 9901 |
torture_assert_ntstatus_ok(tctx, |
| 9902 |
dcerpc_spoolss_GetPrinterDriverDirectory_r(b, tctx, &r), |
| 9903 |
"failed to query driver directory"); |
| 9904 |
} |
| 9905 |
|
| 9906 |
torture_assert_werr_ok(tctx, r.out.result, |
| 9907 |
"failed to query driver directory"); |
| 9908 |
|
| 9909 |
if (dir_p) { |
| 9910 |
*dir_p = r.out.info->info1.directory_name; |
| 9911 |
} |
| 9912 |
|
| 9913 |
return true; |
| 9914 |
} |
| 9915 |
|
| 9916 |
static const char *get_driver_from_info(struct spoolss_AddDriverInfoCtr *info_ctr) |
| 9917 |
{ |
| 9918 |
if (info_ctr == NULL) { |
| 9919 |
return NULL; |
| 9920 |
} |
| 9921 |
|
| 9922 |
switch (info_ctr->level) { |
| 9923 |
case 1: |
| 9924 |
return info_ctr->info.info1->driver_name; |
| 9925 |
case 2: |
| 9926 |
return info_ctr->info.info2->driver_name; |
| 9927 |
case 3: |
| 9928 |
return info_ctr->info.info3->driver_name; |
| 9929 |
case 4: |
| 9930 |
return info_ctr->info.info4->driver_name; |
| 9931 |
case 6: |
| 9932 |
return info_ctr->info.info6->driver_name; |
| 9933 |
case 8: |
| 9934 |
return info_ctr->info.info8->driver_name; |
| 9935 |
default: |
| 9936 |
return NULL; |
| 9937 |
} |
| 9938 |
} |
| 9939 |
|
| 9940 |
static const char *get_environment_from_info(struct spoolss_AddDriverInfoCtr *info_ctr) |
| 9941 |
{ |
| 9942 |
if (info_ctr == NULL) { |
| 9943 |
return NULL; |
| 9944 |
} |
| 9945 |
|
| 9946 |
switch (info_ctr->level) { |
| 9947 |
case 2: |
| 9948 |
return info_ctr->info.info2->architecture; |
| 9949 |
case 3: |
| 9950 |
return info_ctr->info.info3->architecture; |
| 9951 |
case 4: |
| 9952 |
return info_ctr->info.info4->architecture; |
| 9953 |
case 6: |
| 9954 |
return info_ctr->info.info6->architecture; |
| 9955 |
case 8: |
| 9956 |
return info_ctr->info.info8->architecture; |
| 9957 |
default: |
| 9958 |
return NULL; |
| 9959 |
} |
| 9960 |
} |
| 9961 |
|
| 9962 |
|
| 9963 |
static bool test_AddPrinterDriver_exp(struct torture_context *tctx, |
| 9964 |
struct dcerpc_binding_handle *b, |
| 9965 |
const char *servername, |
| 9966 |
struct spoolss_AddDriverInfoCtr *info_ctr, |
| 9967 |
WERROR expected_result) |
| 9968 |
{ |
| 9969 |
struct spoolss_AddPrinterDriver r; |
| 9970 |
const char *drivername = get_driver_from_info(info_ctr); |
| 9971 |
const char *environment = get_environment_from_info(info_ctr); |
| 9972 |
|
| 9973 |
r.in.servername = servername; |
| 9974 |
r.in.info_ctr = info_ctr; |
| 9975 |
|
| 9976 |
torture_comment(tctx, "Testing AddPrinterDriver(%s) level: %d, environment: '%s'\n", |
| 9977 |
drivername, info_ctr->level, environment); |
| 9978 |
|
| 9979 |
torture_assert_ntstatus_ok(tctx, |
| 9980 |
dcerpc_spoolss_AddPrinterDriver_r(b, tctx, &r), |
| 9981 |
"spoolss_AddPrinterDriver failed"); |
| 9982 |
torture_assert_werr_equal(tctx, r.out.result, expected_result, |
| 9983 |
"spoolss_AddPrinterDriver failed with unexpected result"); |
| 9984 |
|
| 9985 |
return true; |
| 9986 |
|
| 9987 |
} |
| 9988 |
|
| 9989 |
static bool test_AddPrinterDriverEx_exp(struct torture_context *tctx, |
| 9990 |
struct dcerpc_binding_handle *b, |
| 9991 |
const char *servername, |
| 9992 |
struct spoolss_AddDriverInfoCtr *info_ctr, |
| 9993 |
uint32_t flags, |
| 9994 |
WERROR expected_result) |
| 9995 |
{ |
| 9996 |
struct spoolss_AddPrinterDriverEx r; |
| 9997 |
const char *drivername = get_driver_from_info(info_ctr); |
| 9998 |
const char *environment = get_environment_from_info(info_ctr); |
| 9999 |
|
| 10000 |
r.in.servername = servername; |
| 10001 |
r.in.info_ctr = info_ctr; |
| 10002 |
r.in.flags = flags; |
| 10003 |
|
| 10004 |
torture_comment(tctx, "Testing AddPrinterDriverEx(%s) level: %d, environment: '%s'\n", |
| 10005 |
drivername, info_ctr->level, environment); |
| 10006 |
|
| 10007 |
torture_assert_ntstatus_ok(tctx, |
| 10008 |
dcerpc_spoolss_AddPrinterDriverEx_r(b, tctx, &r), |
| 10009 |
"AddPrinterDriverEx failed"); |
| 10010 |
torture_assert_werr_equal(tctx, r.out.result, expected_result, |
| 10011 |
"AddPrinterDriverEx failed with unexpected result"); |
| 10012 |
|
| 10013 |
return true; |
| 10014 |
} |
| 10015 |
|
| 10016 |
#define ASSERT_DRIVER_PATH(tctx, path, driver_dir, cmt) \ |
| 10017 |
if (path && strlen(path)) {\ |
| 10018 |
torture_assert_strn_equal(tctx, path, driver_dir, strlen(driver_dir), cmt); \ |
| 10019 |
} |
| 10020 |
|
| 10021 |
static bool test_AddPrinterDriver_args_level_1(struct torture_context *tctx, |
| 10022 |
struct dcerpc_binding_handle *b, |
| 10023 |
const char *server_name, |
| 10024 |
struct spoolss_AddDriverInfo8 *r, |
| 10025 |
uint32_t flags, |
| 10026 |
bool ex, |
| 10027 |
const char *remote_driver_dir) |
| 10028 |
{ |
| 10029 |
struct spoolss_AddDriverInfoCtr info_ctr; |
| 10030 |
struct spoolss_AddDriverInfo1 info1; |
| 10031 |
|
| 10032 |
ZERO_STRUCT(info1); |
| 10033 |
|
| 10034 |
info_ctr.level = 1; |
| 10035 |
info_ctr.info.info1 = &info1; |
| 10036 |
|
| 10037 |
if (ex) { |
| 10038 |
torture_assert(tctx, |
| 10039 |
test_AddPrinterDriverEx_exp(tctx, b, server_name, &info_ctr, flags, WERR_INVALID_LEVEL), |
| 10040 |
"failed to test AddPrinterDriverEx level 1"); |
| 10041 |
} else { |
| 10042 |
torture_assert(tctx, |
| 10043 |
test_AddPrinterDriver_exp(tctx, b, server_name, &info_ctr, WERR_INVALID_LEVEL), |
| 10044 |
"failed to test AddPrinterDriver level 1"); |
| 10045 |
} |
| 10046 |
|
| 10047 |
info1.driver_name = r->driver_name; |
| 10048 |
|
| 10049 |
if (ex) { |
| 10050 |
torture_assert(tctx, |
| 10051 |
test_AddPrinterDriverEx_exp(tctx, b, server_name, &info_ctr, flags, WERR_INVALID_LEVEL), |
| 10052 |
"failed to test AddPrinterDriverEx level 1"); |
| 10053 |
} else { |
| 10054 |
torture_assert(tctx, |
| 10055 |
test_AddPrinterDriver_exp(tctx, b, server_name, &info_ctr, WERR_INVALID_LEVEL), |
| 10056 |
"failed to test AddPrinterDriver level 1"); |
| 10057 |
} |
| 10058 |
|
| 10059 |
return true; |
| 10060 |
} |
| 10061 |
|
| 10062 |
static bool test_AddPrinterDriver_args_level_2(struct torture_context *tctx, |
| 10063 |
struct dcerpc_binding_handle *b, |
| 10064 |
const char *server_name, |
| 10065 |
struct spoolss_AddDriverInfo8 *r, |
| 10066 |
uint32_t flags, |
| 10067 |
bool ex, |
| 10068 |
const char *remote_driver_dir) |
| 10069 |
{ |
| 10070 |
struct spoolss_AddDriverInfoCtr info_ctr; |
| 10071 |
struct spoolss_AddDriverInfo2 info2; |
| 10072 |
union spoolss_DriverInfo info; |
| 10073 |
|
| 10074 |
ZERO_STRUCT(info2); |
| 10075 |
|
| 10076 |
info_ctr.level = 2; |
| 10077 |
info_ctr.info.info2 = &info2; |
| 10078 |
|
| 10079 |
if (ex) { |
| 10080 |
torture_assert(tctx, |
| 10081 |
test_AddPrinterDriverEx_exp(tctx, b, server_name, &info_ctr, flags, WERR_INVALID_PARAMETER), |
| 10082 |
"failed to test AddPrinterDriverEx level 2"); |
| 10083 |
} else { |
| 10084 |
torture_assert(tctx, |
| 10085 |
test_AddPrinterDriver_exp(tctx, b, server_name, &info_ctr, WERR_INVALID_PARAMETER), |
| 10086 |
"failed to test AddPrinterDriver level 2"); |
| 10087 |
} |
| 10088 |
|
| 10089 |
info2.driver_name = r->driver_name; |
| 10090 |
|
| 10091 |
if (ex) { |
| 10092 |
torture_assert(tctx, |
| 10093 |
test_AddPrinterDriverEx_exp(tctx, b, server_name, &info_ctr, flags, WERR_INVALID_PARAMETER), |
| 10094 |
"failed to test AddPrinterDriverEx level 2"); |
| 10095 |
} else { |
| 10096 |
torture_assert(tctx, |
| 10097 |
test_AddPrinterDriver_exp(tctx, b, server_name, &info_ctr, WERR_INVALID_PARAMETER), |
| 10098 |
"failed to test AddPrinterDriver level 2"); |
| 10099 |
} |
| 10100 |
|
| 10101 |
info2.version = r->version; |
| 10102 |
|
| 10103 |
if (ex) { |
| 10104 |
torture_assert(tctx, |
| 10105 |
test_AddPrinterDriverEx_exp(tctx, b, server_name, &info_ctr, flags, WERR_INVALID_PARAMETER), |
| 10106 |
"failed to test AddPrinterDriverEx level 2"); |
| 10107 |
} else { |
| 10108 |
torture_assert(tctx, |
| 10109 |
test_AddPrinterDriver_exp(tctx, b, server_name, &info_ctr, WERR_INVALID_PARAMETER), |
| 10110 |
"failed to test AddPrinterDriver level 2"); |
| 10111 |
} |
| 10112 |
|
| 10113 |
info2.architecture = r->architecture; |
| 10114 |
|
| 10115 |
if (ex) { |
| 10116 |
torture_assert(tctx, |
| 10117 |
test_AddPrinterDriverEx_exp(tctx, b, server_name, &info_ctr, flags, WERR_INVALID_PARAMETER), |
| 10118 |
"failed to test AddPrinterDriverEx level 2"); |
| 10119 |
} else { |
| 10120 |
torture_assert(tctx, |
| 10121 |
test_AddPrinterDriver_exp(tctx, b, server_name, &info_ctr, WERR_INVALID_PARAMETER), |
| 10122 |
"failed to test AddPrinterDriver level 2"); |
| 10123 |
} |
| 10124 |
|
| 10125 |
info2.driver_path = r->driver_path; |
| 10126 |
|
| 10127 |
if (ex) { |
| 10128 |
torture_assert(tctx, |
| 10129 |
test_AddPrinterDriverEx_exp(tctx, b, server_name, &info_ctr, flags, WERR_INVALID_PARAMETER), |
| 10130 |
"failed to test AddPrinterDriverEx level 2"); |
| 10131 |
} else { |
| 10132 |
torture_assert(tctx, |
| 10133 |
test_AddPrinterDriver_exp(tctx, b, server_name, &info_ctr, WERR_INVALID_PARAMETER), |
| 10134 |
"failed to test AddPrinterDriver level 2"); |
| 10135 |
} |
| 10136 |
|
| 10137 |
info2.data_file = r->data_file; |
| 10138 |
|
| 10139 |
if (ex) { |
| 10140 |
torture_assert(tctx, |
| 10141 |
test_AddPrinterDriverEx_exp(tctx, b, server_name, &info_ctr, flags, WERR_INVALID_PARAMETER), |
| 10142 |
"failed to test AddPrinterDriverEx level 2"); |
| 10143 |
} else { |
| 10144 |
torture_assert(tctx, |
| 10145 |
test_AddPrinterDriver_exp(tctx, b, server_name, &info_ctr, WERR_INVALID_PARAMETER), |
| 10146 |
"failed to test AddPrinterDriver level 2"); |
| 10147 |
} |
| 10148 |
|
| 10149 |
info2.config_file = r->config_file; |
| 10150 |
|
| 10151 |
if (ex) { |
| 10152 |
torture_assert(tctx, |
| 10153 |
test_AddPrinterDriverEx_exp(tctx, b, server_name, &info_ctr, 0, WERR_INVALID_PARAMETER), |
| 10154 |
"failed to test AddPrinterDriverEx"); |
| 10155 |
} |
| 10156 |
|
| 10157 |
if (ex) { |
| 10158 |
torture_assert(tctx, |
| 10159 |
test_AddPrinterDriverEx_exp(tctx, b, server_name, &info_ctr, flags, WERR_OK), |
| 10160 |
"failed to test AddPrinterDriverEx level 2"); |
| 10161 |
} else { |
| 10162 |
torture_assert(tctx, |
| 10163 |
test_AddPrinterDriver_exp(tctx, b, server_name, &info_ctr, WERR_OK), |
| 10164 |
"failed to test AddPrinterDriver level 2"); |
| 10165 |
} |
| 10166 |
|
| 10167 |
torture_assert(tctx, |
| 10168 |
test_EnumPrinterDrivers_findone(tctx, b, server_name, r->architecture, 2, r->driver_name, &info), |
| 10169 |
"failed to find added printer driver"); |
| 10170 |
|
| 10171 |
if (remote_driver_dir) { |
| 10172 |
ASSERT_DRIVER_PATH(tctx, info.info2.driver_path, remote_driver_dir, "unexpected path"); |
| 10173 |
ASSERT_DRIVER_PATH(tctx, info.info2.data_file, remote_driver_dir, "unexpected path"); |
| 10174 |
ASSERT_DRIVER_PATH(tctx, info.info2.config_file, remote_driver_dir, "unexpected path"); |
| 10175 |
} |
| 10176 |
|
| 10177 |
return true; |
| 10178 |
} |
| 10179 |
|
| 10180 |
static bool test_AddPrinterDriver_args_level_3(struct torture_context *tctx, |
| 10181 |
struct dcerpc_binding_handle *b, |
| 10182 |
const char *server_name, |
| 10183 |
struct spoolss_AddDriverInfo8 *r, |
| 10184 |
uint32_t flags, |
| 10185 |
bool ex, |
| 10186 |
const char *remote_driver_dir) |
| 10187 |
{ |
| 10188 |
struct spoolss_AddDriverInfoCtr info_ctr; |
| 10189 |
struct spoolss_AddDriverInfo3 info3; |
| 10190 |
union spoolss_DriverInfo info; |
| 10191 |
|
| 10192 |
info3.driver_name = r->driver_name; |
| 10193 |
info3.version = r->version; |
| 10194 |
info3.architecture = r->architecture; |
| 10195 |
info3.driver_path = r->driver_path; |
| 10196 |
info3.data_file = r->data_file; |
| 10197 |
info3.config_file = r->config_file; |
| 10198 |
info3.help_file = r->help_file; |
| 10199 |
info3.monitor_name = r->monitor_name; |
| 10200 |
info3.default_datatype = r->default_datatype; |
| 10201 |
info3._ndr_size_dependent_files = r->_ndr_size_dependent_files; |
| 10202 |
info3.dependent_files = r->dependent_files; |
| 10203 |
|
| 10204 |
info_ctr.level = 3; |
| 10205 |
info_ctr.info.info3 = &info3; |
| 10206 |
|
| 10207 |
if (ex) { |
| 10208 |
torture_assert(tctx, |
| 10209 |
test_AddPrinterDriverEx_exp(tctx, b, server_name, &info_ctr, flags, WERR_OK), |
| 10210 |
"failed to test AddPrinterDriverEx level 3"); |
| 10211 |
} else { |
| 10212 |
torture_assert(tctx, |
| 10213 |
test_AddPrinterDriver_exp(tctx, b, server_name, &info_ctr, WERR_OK), |
| 10214 |
"failed to test AddPrinterDriver level 3"); |
| 10215 |
} |
| 10216 |
|
| 10217 |
torture_assert(tctx, |
| 10218 |
test_EnumPrinterDrivers_findone(tctx, b, server_name, r->architecture, 3, r->driver_name, &info), |
| 10219 |
"failed to find added printer driver"); |
| 10220 |
|
| 10221 |
if (remote_driver_dir) { |
| 10222 |
int i; |
| 10223 |
ASSERT_DRIVER_PATH(tctx, info.info3.driver_path, remote_driver_dir, "unexpected path"); |
| 10224 |
ASSERT_DRIVER_PATH(tctx, info.info3.data_file, remote_driver_dir, "unexpected path"); |
| 10225 |
ASSERT_DRIVER_PATH(tctx, info.info3.config_file, remote_driver_dir, "unexpected path"); |
| 10226 |
ASSERT_DRIVER_PATH(tctx, info.info3.help_file, remote_driver_dir, "unexpected path"); |
| 10227 |
for (i=0; info.info3.dependent_files && info.info3.dependent_files[i] != NULL; i++) { |
| 10228 |
ASSERT_DRIVER_PATH(tctx, info.info3.dependent_files[i], remote_driver_dir, "unexpected path"); |
| 10229 |
} |
| 10230 |
} |
| 10231 |
|
| 10232 |
return true; |
| 10233 |
} |
| 10234 |
|
| 10235 |
static bool test_AddPrinterDriver_args_level_4(struct torture_context *tctx, |
| 10236 |
struct dcerpc_binding_handle *b, |
| 10237 |
const char *server_name, |
| 10238 |
struct spoolss_AddDriverInfo8 *r, |
| 10239 |
uint32_t flags, |
| 10240 |
bool ex, |
| 10241 |
const char *remote_driver_dir) |
| 10242 |
{ |
| 10243 |
struct spoolss_AddDriverInfoCtr info_ctr; |
| 10244 |
struct spoolss_AddDriverInfo4 info4; |
| 10245 |
union spoolss_DriverInfo info; |
| 10246 |
|
| 10247 |
info4.version = r->version; |
| 10248 |
info4.driver_name = r->driver_name; |
| 10249 |
info4.architecture = r->architecture; |
| 10250 |
info4.driver_path = r->driver_path; |
| 10251 |
info4.data_file = r->data_file; |
| 10252 |
info4.config_file = r->config_file; |
| 10253 |
info4.help_file = r->help_file; |
| 10254 |
info4.monitor_name = r->monitor_name; |
| 10255 |
info4.default_datatype = r->default_datatype; |
| 10256 |
info4._ndr_size_dependent_files = r->_ndr_size_dependent_files; |
| 10257 |
info4.dependent_files = r->dependent_files; |
| 10258 |
info4._ndr_size_previous_names = r->_ndr_size_previous_names; |
| 10259 |
info4.previous_names = r->previous_names; |
| 10260 |
|
| 10261 |
info_ctr.level = 4; |
| 10262 |
info_ctr.info.info4 = &info4; |
| 10263 |
|
| 10264 |
if (ex) { |
| 10265 |
torture_assert(tctx, |
| 10266 |
test_AddPrinterDriverEx_exp(tctx, b, server_name, &info_ctr, flags, WERR_OK), |
| 10267 |
"failed to test AddPrinterDriverEx level 4"); |
| 10268 |
} else { |
| 10269 |
torture_assert(tctx, |
| 10270 |
test_AddPrinterDriver_exp(tctx, b, server_name, &info_ctr, WERR_OK), |
| 10271 |
"failed to test AddPrinterDriver level 4"); |
| 10272 |
} |
| 10273 |
|
| 10274 |
torture_assert(tctx, |
| 10275 |
test_EnumPrinterDrivers_findone(tctx, b, server_name, r->architecture, 4, r->driver_name, &info), |
| 10276 |
"failed to find added printer driver"); |
| 10277 |
|
| 10278 |
if (remote_driver_dir) { |
| 10279 |
int i; |
| 10280 |
ASSERT_DRIVER_PATH(tctx, info.info4.driver_path, remote_driver_dir, "unexpected path"); |
| 10281 |
ASSERT_DRIVER_PATH(tctx, info.info4.data_file, remote_driver_dir, "unexpected path"); |
| 10282 |
ASSERT_DRIVER_PATH(tctx, info.info4.config_file, remote_driver_dir, "unexpected path"); |
| 10283 |
ASSERT_DRIVER_PATH(tctx, info.info4.help_file, remote_driver_dir, "unexpected path"); |
| 10284 |
for (i=0; info.info4.dependent_files && info.info4.dependent_files[i] != NULL; i++) { |
| 10285 |
ASSERT_DRIVER_PATH(tctx, info.info4.dependent_files[i], remote_driver_dir, "unexpected path"); |
| 10286 |
} |
| 10287 |
} |
| 10288 |
|
| 10289 |
return true; |
| 10290 |
} |
| 10291 |
|
| 10292 |
static bool test_AddPrinterDriver_args_level_6(struct torture_context *tctx, |
| 10293 |
struct dcerpc_binding_handle *b, |
| 10294 |
const char *server_name, |
| 10295 |
struct spoolss_AddDriverInfo8 *r, |
| 10296 |
uint32_t flags, |
| 10297 |
bool ex, |
| 10298 |
const char *remote_driver_dir) |
| 10299 |
{ |
| 10300 |
struct spoolss_AddDriverInfoCtr info_ctr; |
| 10301 |
struct spoolss_AddDriverInfo6 info6; |
| 10302 |
union spoolss_DriverInfo info; |
| 10303 |
|
| 10304 |
info6.version = r->version; |
| 10305 |
info6.driver_name = r->driver_name; |
| 10306 |
info6.architecture = r->architecture; |
| 10307 |
info6.driver_path = r->driver_path; |
| 10308 |
info6.data_file = r->data_file; |
| 10309 |
info6.config_file = r->config_file; |
| 10310 |
info6.help_file = r->help_file; |
| 10311 |
info6.monitor_name = r->monitor_name; |
| 10312 |
info6.default_datatype = r->default_datatype; |
| 10313 |
info6._ndr_size_dependent_files = r->_ndr_size_dependent_files; |
| 10314 |
info6.dependent_files = r->dependent_files; |
| 10315 |
info6._ndr_size_previous_names = r->_ndr_size_previous_names; |
| 10316 |
info6.previous_names = r->previous_names; |
| 10317 |
info6.driver_date = r->driver_date; |
| 10318 |
info6.driver_version = r->driver_version; |
| 10319 |
info6.manufacturer_name = r->manufacturer_name; |
| 10320 |
info6.manufacturer_url = r->manufacturer_url; |
| 10321 |
info6.hardware_id = r->hardware_id; |
| 10322 |
info6.provider = r->provider; |
| 10323 |
|
| 10324 |
info_ctr.level = 6; |
| 10325 |
info_ctr.info.info6 = &info6; |
| 10326 |
|
| 10327 |
if (ex) { |
| 10328 |
torture_assert(tctx, |
| 10329 |
test_AddPrinterDriverEx_exp(tctx, b, server_name, &info_ctr, flags, WERR_OK), |
| 10330 |
"failed to test AddPrinterDriverEx level 6"); |
| 10331 |
} else { |
| 10332 |
torture_assert(tctx, |
| 10333 |
test_AddPrinterDriver_exp(tctx, b, server_name, &info_ctr, WERR_INVALID_LEVEL), |
| 10334 |
"failed to test AddPrinterDriver level 6"); |
| 10335 |
} |
| 10336 |
|
| 10337 |
/* spoolss_AddPrinterDriver does not deal with level 6 or 8 - gd */ |
| 10338 |
|
| 10339 |
if (!ex) { |
| 10340 |
return true; |
| 10341 |
} |
| 10342 |
|
| 10343 |
torture_assert(tctx, |
| 10344 |
test_EnumPrinterDrivers_findone(tctx, b, server_name, r->architecture, 6, r->driver_name, &info), |
| 10345 |
"failed to find added printer driver"); |
| 10346 |
|
| 10347 |
if (remote_driver_dir) { |
| 10348 |
int i; |
| 10349 |
ASSERT_DRIVER_PATH(tctx, info.info6.driver_path, remote_driver_dir, "unexpected path"); |
| 10350 |
ASSERT_DRIVER_PATH(tctx, info.info6.data_file, remote_driver_dir, "unexpected path"); |
| 10351 |
ASSERT_DRIVER_PATH(tctx, info.info6.config_file, remote_driver_dir, "unexpected path"); |
| 10352 |
ASSERT_DRIVER_PATH(tctx, info.info6.help_file, remote_driver_dir, "unexpected path"); |
| 10353 |
for (i=0; info.info6.dependent_files && info.info6.dependent_files[i] != NULL; i++) { |
| 10354 |
ASSERT_DRIVER_PATH(tctx, info.info6.dependent_files[i], remote_driver_dir, "unexpected path"); |
| 10355 |
} |
| 10356 |
} |
| 10357 |
|
| 10358 |
torture_assert_nttime_equal(tctx, info.info6.driver_date, info6.driver_date, "driverdate mismatch"); |
| 10359 |
torture_assert_u64_equal(tctx, info.info6.driver_version, info6.driver_version, "driverversion mismatch"); |
| 10360 |
|
| 10361 |
return true; |
| 10362 |
} |
| 10363 |
|
| 10364 |
static bool test_AddPrinterDriver_args_level_8(struct torture_context *tctx, |
| 10365 |
struct dcerpc_binding_handle *b, |
| 10366 |
const char *server_name, |
| 10367 |
struct spoolss_AddDriverInfo8 *r, |
| 10368 |
uint32_t flags, |
| 10369 |
bool ex, |
| 10370 |
const char *remote_driver_dir) |
| 10371 |
{ |
| 10372 |
struct spoolss_AddDriverInfoCtr info_ctr; |
| 10373 |
union spoolss_DriverInfo info; |
| 10374 |
|
| 10375 |
info_ctr.level = 8; |
| 10376 |
info_ctr.info.info8 = r; |
| 10377 |
|
| 10378 |
if (ex) { |
| 10379 |
torture_assert(tctx, |
| 10380 |
test_AddPrinterDriverEx_exp(tctx, b, server_name, &info_ctr, flags, WERR_OK), |
| 10381 |
"failed to test AddPrinterDriverEx level 8"); |
| 10382 |
} else { |
| 10383 |
torture_assert(tctx, |
| 10384 |
test_AddPrinterDriver_exp(tctx, b, server_name, &info_ctr, WERR_INVALID_LEVEL), |
| 10385 |
"failed to test AddPrinterDriver level 8"); |
| 10386 |
} |
| 10387 |
|
| 10388 |
/* spoolss_AddPrinterDriver does not deal with level 6 or 8 - gd */ |
| 10389 |
|
| 10390 |
if (!ex) { |
| 10391 |
return true; |
| 10392 |
} |
| 10393 |
|
| 10394 |
torture_assert(tctx, |
| 10395 |
test_EnumPrinterDrivers_findone(tctx, b, server_name, r->architecture, 8, r->driver_name, &info), |
| 10396 |
"failed to find added printer driver"); |
| 10397 |
|
| 10398 |
if (remote_driver_dir) { |
| 10399 |
int i; |
| 10400 |
ASSERT_DRIVER_PATH(tctx, info.info8.driver_path, remote_driver_dir, "unexpected path"); |
| 10401 |
ASSERT_DRIVER_PATH(tctx, info.info8.data_file, remote_driver_dir, "unexpected path"); |
| 10402 |
ASSERT_DRIVER_PATH(tctx, info.info8.config_file, remote_driver_dir, "unexpected path"); |
| 10403 |
ASSERT_DRIVER_PATH(tctx, info.info8.help_file, remote_driver_dir, "unexpected path"); |
| 10404 |
for (i=0; info.info8.dependent_files && info.info8.dependent_files[i] != NULL; i++) { |
| 10405 |
ASSERT_DRIVER_PATH(tctx, info.info8.dependent_files[i], remote_driver_dir, "unexpected path"); |
| 10406 |
} |
| 10407 |
} |
| 10408 |
|
| 10409 |
torture_assert_nttime_equal(tctx, info.info8.driver_date, r->driver_date, "driverdate mismatch"); |
| 10410 |
torture_assert_u64_equal(tctx, info.info8.driver_version, r->driver_version, "driverversion mismatch"); |
| 10411 |
|
| 10412 |
return true; |
| 10413 |
} |
| 10414 |
|
| 10415 |
#undef ASSERT_DRIVER_PATH |
| 10416 |
|
| 10417 |
static bool test_DeletePrinterDriver_exp(struct torture_context *tctx, |
| 10418 |
struct dcerpc_binding_handle *b, |
| 10419 |
const char *server, |
| 10420 |
const char *driver, |
| 10421 |
const char *environment, |
| 10422 |
WERROR expected_result) |
| 10423 |
{ |
| 10424 |
struct spoolss_DeletePrinterDriver r; |
| 10425 |
|
| 10426 |
r.in.server = server; |
| 10427 |
r.in.architecture = environment; |
| 10428 |
r.in.driver = driver; |
| 10429 |
|
| 10430 |
torture_comment(tctx, "Testing DeletePrinterDriver(%s)\n", driver); |
| 10431 |
|
| 10432 |
torture_assert_ntstatus_ok(tctx, |
| 10433 |
dcerpc_spoolss_DeletePrinterDriver_r(b, tctx, &r), |
| 10434 |
"DeletePrinterDriver failed"); |
| 10435 |
torture_assert_werr_equal(tctx, r.out.result, expected_result, |
| 10436 |
"DeletePrinterDriver failed with unexpected result"); |
| 10437 |
|
| 10438 |
return true; |
| 10439 |
} |
| 10440 |
|
| 10441 |
static bool test_DeletePrinterDriverEx_exp(struct torture_context *tctx, |
| 10442 |
struct dcerpc_binding_handle *b, |
| 10443 |
const char *server, |
| 10444 |
const char *driver, |
| 10445 |
const char *environment, |
| 10446 |
uint32_t delete_flags, |
| 10447 |
uint32_t version, |
| 10448 |
WERROR expected_result) |
| 10449 |
{ |
| 10450 |
struct spoolss_DeletePrinterDriverEx r; |
| 10451 |
|
| 10452 |
r.in.server = server; |
| 10453 |
r.in.architecture = environment; |
| 10454 |
r.in.driver = driver; |
| 10455 |
r.in.delete_flags = delete_flags; |
| 10456 |
r.in.version = version; |
| 10457 |
|
| 10458 |
torture_comment(tctx, "Testing DeletePrinterDriverEx(%s)\n", driver); |
| 10459 |
|
| 10460 |
torture_assert_ntstatus_ok(tctx, |
| 10461 |
dcerpc_spoolss_DeletePrinterDriverEx_r(b, tctx, &r), |
| 10462 |
"DeletePrinterDriverEx failed"); |
| 10463 |
torture_assert_werr_equal(tctx, r.out.result, expected_result, |
| 10464 |
"DeletePrinterDriverEx failed with unexpected result"); |
| 10465 |
|
| 10466 |
return true; |
| 10467 |
} |
| 10468 |
|
| 10469 |
static bool test_DeletePrinterDriver(struct torture_context *tctx, |
| 10470 |
struct dcerpc_binding_handle *b, |
| 10471 |
const char *server_name, |
| 10472 |
const char *driver, |
| 10473 |
const char *environment) |
| 10474 |
{ |
| 10475 |
torture_assert(tctx, |
| 10476 |
test_DeletePrinterDriver_exp(tctx, b, server_name, driver, "FOOBAR", WERR_INVALID_ENVIRONMENT), |
| 10477 |
"failed to delete driver"); |
| 10478 |
|
| 10479 |
torture_assert(tctx, |
| 10480 |
test_DeletePrinterDriver_exp(tctx, b, server_name, driver, environment, WERR_OK), |
| 10481 |
"failed to delete driver"); |
| 10482 |
|
| 10483 |
if (test_EnumPrinterDrivers_findone(tctx, b, server_name, environment, 1, driver, NULL)) { |
| 10484 |
torture_fail(tctx, "deleted driver still enumerated"); |
| 10485 |
} |
| 10486 |
|
| 10487 |
torture_assert(tctx, |
| 10488 |
test_DeletePrinterDriver_exp(tctx, b, server_name, driver, environment, WERR_UNKNOWN_PRINTER_DRIVER), |
| 10489 |
"2nd delete failed"); |
| 10490 |
|
| 10491 |
return true; |
| 10492 |
} |
| 10493 |
|
| 10494 |
static bool test_DeletePrinterDriverEx(struct torture_context *tctx, |
| 10495 |
struct dcerpc_binding_handle *b, |
| 10496 |
const char *server_name, |
| 10497 |
const char *driver, |
| 10498 |
const char *environment, |
| 10499 |
uint32_t delete_flags, |
| 10500 |
uint32_t version) |
| 10501 |
{ |
| 10502 |
torture_assert(tctx, |
| 10503 |
test_DeletePrinterDriverEx_exp(tctx, b, server_name, driver, "FOOBAR", delete_flags, version, WERR_INVALID_ENVIRONMENT), |
| 10504 |
"failed to delete driver"); |
| 10505 |
|
| 10506 |
torture_assert(tctx, |
| 10507 |
test_DeletePrinterDriverEx_exp(tctx, b, server_name, driver, environment, delete_flags, version, WERR_OK), |
| 10508 |
"failed to delete driver"); |
| 10509 |
|
| 10510 |
if (test_EnumPrinterDrivers_findone(tctx, b, server_name, environment, 1, driver, NULL)) { |
| 10511 |
torture_fail(tctx, "deleted driver still enumerated"); |
| 10512 |
} |
| 10513 |
|
| 10514 |
torture_assert(tctx, |
| 10515 |
test_DeletePrinterDriverEx_exp(tctx, b, server_name, driver, environment, delete_flags, version, WERR_UNKNOWN_PRINTER_DRIVER), |
| 10516 |
"2nd delete failed"); |
| 10517 |
|
| 10518 |
return true; |
| 10519 |
} |
| 10520 |
|
| 10521 |
static bool test_PrinterDriver_args(struct torture_context *tctx, |
| 10522 |
struct dcerpc_binding_handle *b, |
| 10523 |
const char *server_name, |
| 10524 |
uint32_t level, |
| 10525 |
struct spoolss_AddDriverInfo8 *r, |
| 10526 |
uint32_t add_flags, |
| 10527 |
uint32_t delete_flags, |
| 10528 |
uint32_t delete_version, |
| 10529 |
bool ex, |
| 10530 |
const char *remote_driver_dir) |
| 10531 |
{ |
| 10532 |
bool ret = true; |
| 10533 |
|
| 10534 |
switch (level) { |
| 10535 |
case 1: |
| 10536 |
ret = test_AddPrinterDriver_args_level_1(tctx, b, server_name, r, add_flags, ex, remote_driver_dir); |
| 10537 |
break; |
| 10538 |
case 2: |
| 10539 |
ret = test_AddPrinterDriver_args_level_2(tctx, b, server_name, r, add_flags, ex, remote_driver_dir); |
| 10540 |
break; |
| 10541 |
case 3: |
| 10542 |
ret = test_AddPrinterDriver_args_level_3(tctx, b, server_name, r, add_flags, ex, remote_driver_dir); |
| 10543 |
break; |
| 10544 |
case 4: |
| 10545 |
ret = test_AddPrinterDriver_args_level_4(tctx, b, server_name, r, add_flags, ex, remote_driver_dir); |
| 10546 |
break; |
| 10547 |
case 6: |
| 10548 |
ret = test_AddPrinterDriver_args_level_6(tctx, b, server_name, r, add_flags, ex, remote_driver_dir); |
| 10549 |
break; |
| 10550 |
case 8: |
| 10551 |
ret = test_AddPrinterDriver_args_level_8(tctx, b, server_name, r, add_flags, ex, remote_driver_dir); |
| 10552 |
break; |
| 10553 |
default: |
| 10554 |
return false; |
| 10555 |
} |
| 10556 |
|
| 10557 |
if (ret == false) { |
| 10558 |
return ret; |
| 10559 |
} |
| 10560 |
|
| 10561 |
if (level == 1) { |
| 10562 |
return ret; |
| 10563 |
} |
| 10564 |
|
| 10565 |
/* spoolss_AddPrinterDriver does not deal with level 6 or 8 - gd */ |
| 10566 |
|
| 10567 |
if (!ex && (level == 6 || level == 8)) { |
| 10568 |
return ret; |
| 10569 |
} |
| 10570 |
|
| 10571 |
{ |
| 10572 |
struct dcerpc_pipe *p2; |
| 10573 |
struct policy_handle hive_handle; |
| 10574 |
struct dcerpc_binding_handle *b2; |
| 10575 |
|
| 10576 |
torture_assert_ntstatus_ok(tctx, |
| 10577 |
torture_rpc_connection(tctx, &p2, &ndr_table_winreg), |
| 10578 |
"could not open winreg pipe"); |
| 10579 |
b2 = p2->binding_handle; |
| 10580 |
|
| 10581 |
torture_assert(tctx, test_winreg_OpenHKLM(tctx, b2, &hive_handle), ""); |
| 10582 |
|
| 10583 |
ret = test_GetDriverInfo_winreg(tctx, b, NULL, NULL, r->driver_name, r->architecture, r->version, b2, &hive_handle, server_name); |
| 10584 |
|
| 10585 |
test_winreg_CloseKey(tctx, b2, &hive_handle); |
| 10586 |
|
| 10587 |
talloc_free(p2); |
| 10588 |
} |
| 10589 |
|
| 10590 |
if (ex) { |
| 10591 |
return test_DeletePrinterDriverEx(tctx, b, server_name, r->driver_name, r->architecture, delete_flags, r->version); |
| 10592 |
} else { |
| 10593 |
return test_DeletePrinterDriver(tctx, b, server_name, r->driver_name, r->architecture); |
| 10594 |
} |
| 10595 |
} |
| 10596 |
|
| 10597 |
static bool fillup_printserver_info(struct torture_context *tctx, |
| 10598 |
struct dcerpc_pipe *p, |
| 10599 |
struct torture_driver_context *d) |
| 10600 |
{ |
| 10601 |
struct policy_handle server_handle; |
| 10602 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 10603 |
const char *server_name_slash = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p)); |
| 10604 |
|
| 10605 |
torture_assert(tctx, |
| 10606 |
test_OpenPrinter_server(tctx, p, &server_handle), |
| 10607 |
"failed to open printserver"); |
| 10608 |
torture_assert(tctx, |
| 10609 |
test_get_environment(tctx, b, &server_handle, &d->remote.environment), |
| 10610 |
"failed to get environment"); |
| 10611 |
torture_assert(tctx, |
| 10612 |
test_ClosePrinter(tctx, b, &server_handle), |
| 10613 |
"failed to close printserver"); |
| 10614 |
|
| 10615 |
torture_assert(tctx, |
| 10616 |
test_GetPrinterDriverDirectory_getdir(tctx, b, server_name_slash, |
| 10617 |
d->local.environment ? d->local.environment : d->remote.environment, |
| 10618 |
&d->remote.driver_directory), |
| 10619 |
"failed to get driver directory"); |
| 10620 |
|
| 10621 |
return true; |
| 10622 |
} |
| 10623 |
|
| 10624 |
static const char *driver_directory_dir(const char *driver_directory) |
| 10625 |
{ |
| 10626 |
char *p; |
| 10627 |
|
| 10628 |
p = strrchr(driver_directory, '\\'); |
| 10629 |
if (p) { |
| 10630 |
return p+1; |
| 10631 |
} |
| 10632 |
|
| 10633 |
return NULL; |
| 10634 |
} |
| 10635 |
|
| 10636 |
static const char *driver_directory_share(struct torture_context *tctx, |
| 10637 |
const char *driver_directory) |
| 10638 |
{ |
| 10639 |
const char *p; |
| 10640 |
char *tok; |
| 10641 |
|
| 10642 |
if (driver_directory[0] == '\\' && driver_directory[1] == '\\') { |
| 10643 |
driver_directory += 2; |
| 10644 |
} |
| 10645 |
|
| 10646 |
p = talloc_strdup(tctx, driver_directory); |
| 10647 |
|
| 10648 |
torture_assert(tctx, |
| 10649 |
next_token_talloc(tctx, &p, &tok, "\\"), |
| 10650 |
"cannot explode uri"); |
| 10651 |
torture_assert(tctx, |
| 10652 |
next_token_talloc(tctx, &p, &tok, "\\"), |
| 10653 |
"cannot explode uri"); |
| 10654 |
|
| 10655 |
return tok; |
| 10656 |
} |
| 10657 |
|
| 10658 |
#define CREATE_PRINTER_DRIVER_PATH(_d, _file) \ |
| 10659 |
talloc_asprintf((_d), "%s\\%s\\%s", (_d)->remote.driver_directory, (_d)->remote.driver_upload_directory, (_file)) |
| 10660 |
|
| 10661 |
|
| 10662 |
static bool create_printer_driver_directory(struct torture_context *tctx, |
| 10663 |
struct smbcli_state *cli, |
| 10664 |
struct torture_driver_context *d) |
| 10665 |
{ |
| 10666 |
char *driver_dir; |
| 10667 |
|
| 10668 |
if (d->remote.driver_upload_directory == NULL) { |
| 10669 |
return true; |
| 10670 |
} |
| 10671 |
|
| 10672 |
driver_dir = talloc_asprintf(tctx, |
| 10673 |
"%s\\%s", |
| 10674 |
driver_directory_dir(d->remote.driver_directory), |
| 10675 |
d->remote.driver_upload_directory); |
| 10676 |
torture_assert_not_null(tctx, driver_dir, "ENOMEM"); |
| 10677 |
|
| 10678 |
torture_comment(tctx, |
| 10679 |
"Create remote driver directory: %s\n", |
| 10680 |
driver_dir); |
| 10681 |
|
| 10682 |
torture_assert_ntstatus_ok(tctx, |
| 10683 |
smbcli_mkdir(cli->tree, |
| 10684 |
driver_dir), |
| 10685 |
"Failed to create driver directory"); |
| 10686 |
|
| 10687 |
return true; |
| 10688 |
} |
| 10689 |
|
| 10690 |
static bool upload_printer_driver_file(struct torture_context *tctx, |
| 10691 |
struct smbcli_state *cli, |
| 10692 |
struct torture_driver_context *d, |
| 10693 |
const char *file_name) |
| 10694 |
{ |
| 10695 |
FILE *f; |
| 10696 |
int fnum; |
| 10697 |
uint8_t *buf; |
| 10698 |
int maxwrite = 64512; |
| 10699 |
off_t nread = 0; |
| 10700 |
size_t start = 0; |
| 10701 |
const char *remote_dir = driver_directory_dir(d->remote.driver_directory); |
| 10702 |
const char *remote_name; |
| 10703 |
const char *local_name; |
| 10704 |
const char *p; |
| 10705 |
|
| 10706 |
if (!file_name || strlen(file_name) == 0) { |
| 10707 |
return true; |
| 10708 |
} |
| 10709 |
|
| 10710 |
p = strrchr(file_name, '\\'); |
| 10711 |
if (p == NULL) { |
| 10712 |
p = file_name; |
| 10713 |
} else { |
| 10714 |
p++; |
| 10715 |
} |
| 10716 |
|
| 10717 |
local_name = talloc_asprintf(tctx, "%s/%s", d->local.driver_directory, p); |
| 10718 |
torture_assert_not_null(tctx, local_name, "ENOMEM"); |
| 10719 |
if (d->remote.driver_upload_directory != NULL) { |
| 10720 |
remote_name = talloc_asprintf(tctx, |
| 10721 |
"%s\\%s\\%s", |
| 10722 |
remote_dir, |
| 10723 |
d->remote.driver_upload_directory, |
| 10724 |
p); |
| 10725 |
} else { |
| 10726 |
remote_name = talloc_asprintf(tctx, "%s\\%s", remote_dir, p); |
| 10727 |
} |
| 10728 |
torture_assert_not_null(tctx, remote_name, "ENOMEM"); |
| 10729 |
|
| 10730 |
torture_comment(tctx, "Uploading %s to %s\n", local_name, remote_name); |
| 10731 |
|
| 10732 |
fnum = smbcli_open(cli->tree, remote_name, O_RDWR|O_CREAT|O_TRUNC, DENY_NONE); |
| 10733 |
if (fnum == -1) { |
| 10734 |
torture_fail(tctx, talloc_asprintf(tctx, "failed to open remote file: %s\n", remote_name)); |
| 10735 |
} |
| 10736 |
|
| 10737 |
f = fopen(local_name, "r"); |
| 10738 |
if (f == NULL) { |
| 10739 |
torture_fail(tctx, talloc_asprintf(tctx, "failed to open local file: %s\n", local_name)); |
| 10740 |
} |
| 10741 |
|
| 10742 |
buf = talloc_array(tctx, uint8_t, maxwrite); |
| 10743 |
if (!buf) { |
| 10744 |
fclose(f); |
| 10745 |
return false; |
| 10746 |
} |
| 10747 |
|
| 10748 |
while (!feof(f)) { |
| 10749 |
int n = maxwrite; |
| 10750 |
int ret; |
| 10751 |
|
| 10752 |
if ((n = fread(buf, 1, n, f)) < 1) { |
| 10753 |
if((n == 0) && feof(f)) |
| 10754 |
break; /* Empty local file. */ |
| 10755 |
|
| 10756 |
torture_warning(tctx, |
| 10757 |
"failed to read file: %s\n", strerror(errno)); |
| 10758 |
break; |
| 10759 |
} |
| 10760 |
|
| 10761 |
ret = smbcli_write(cli->tree, fnum, 0, buf, nread + start, n); |
| 10762 |
|
| 10763 |
if (n != ret) { |
| 10764 |
torture_warning(tctx, |
| 10765 |
"failed to write file: %s\n", smbcli_errstr(cli->tree)); |
| 10766 |
break; |
| 10767 |
} |
| 10768 |
|
| 10769 |
nread += n; |
| 10770 |
} |
| 10771 |
|
| 10772 |
fclose(f); |
| 10773 |
|
| 10774 |
torture_assert_ntstatus_ok(tctx, |
| 10775 |
smbcli_close(cli->tree, fnum), |
| 10776 |
"failed to close file"); |
| 10777 |
|
| 10778 |
return true; |
| 10779 |
} |
| 10780 |
|
| 10781 |
static bool connect_printer_driver_share(struct torture_context *tctx, |
| 10782 |
const char *server_name, |
| 10783 |
const char *share_name, |
| 10784 |
struct smbcli_state **cli) |
| 10785 |
{ |
| 10786 |
struct smbcli_options smb_options; |
| 10787 |
struct smbcli_session_options smb_session_options; |
| 10788 |
|
| 10789 |
torture_comment(tctx, "Connecting printer driver share '%s' on '%s'\n", |
| 10790 |
share_name, server_name); |
| 10791 |
|
| 10792 |
lpcfg_smbcli_options(tctx->lp_ctx, &smb_options); |
| 10793 |
lpcfg_smbcli_session_options(tctx->lp_ctx, &smb_session_options); |
| 10794 |
|
| 10795 |
torture_assert_ntstatus_ok(tctx, |
| 10796 |
smbcli_full_connection(tctx, cli, server_name, |
| 10797 |
share_name, NULL, |
| 10798 |
lpcfg_socket_options(tctx->lp_ctx), |
| 10799 |
samba_cmdline_get_creds(), |
| 10800 |
tctx->lp_ctx, |
| 10801 |
lpcfg_resolve_context(tctx->lp_ctx), |
| 10802 |
tctx->ev, |
| 10803 |
&smb_options, |
| 10804 |
&smb_session_options, |
| 10805 |
lpcfg_gensec_settings(tctx, tctx->lp_ctx)), |
| 10806 |
"failed to open driver share"); |
| 10807 |
|
| 10808 |
return true; |
| 10809 |
} |
| 10810 |
|
| 10811 |
static bool upload_printer_driver(struct torture_context *tctx, |
| 10812 |
const char *server_name, |
| 10813 |
struct torture_driver_context *d) |
| 10814 |
{ |
| 10815 |
struct smbcli_state *cli; |
| 10816 |
const char *share_name = driver_directory_share(tctx, d->remote.driver_directory); |
| 10817 |
int i; |
| 10818 |
|
| 10819 |
torture_assert(tctx, |
| 10820 |
connect_printer_driver_share(tctx, server_name, share_name, &cli), |
| 10821 |
"failed to connect to driver share"); |
| 10822 |
|
| 10823 |
torture_comment(tctx, "Uploading printer driver files to \\\\%s\\%s\n", |
| 10824 |
server_name, share_name); |
| 10825 |
|
| 10826 |
torture_assert(tctx, |
| 10827 |
create_printer_driver_directory(tctx, cli, d), |
| 10828 |
"failed to create driver directory"); |
| 10829 |
|
| 10830 |
torture_assert(tctx, |
| 10831 |
upload_printer_driver_file(tctx, cli, d, d->info8.driver_path), |
| 10832 |
"failed to upload driver_path"); |
| 10833 |
torture_assert(tctx, |
| 10834 |
upload_printer_driver_file(tctx, cli, d, d->info8.data_file), |
| 10835 |
"failed to upload data_file"); |
| 10836 |
torture_assert(tctx, |
| 10837 |
upload_printer_driver_file(tctx, cli, d, d->info8.config_file), |
| 10838 |
"failed to upload config_file"); |
| 10839 |
torture_assert(tctx, |
| 10840 |
upload_printer_driver_file(tctx, cli, d, d->info8.help_file), |
| 10841 |
"failed to upload help_file"); |
| 10842 |
if (d->info8.dependent_files) { |
| 10843 |
for (i=0; d->info8.dependent_files->string && d->info8.dependent_files->string[i] != NULL; i++) { |
| 10844 |
torture_assert(tctx, |
| 10845 |
upload_printer_driver_file(tctx, cli, d, d->info8.dependent_files->string[i]), |
| 10846 |
"failed to upload dependent_files"); |
| 10847 |
} |
| 10848 |
} |
| 10849 |
|
| 10850 |
talloc_free(cli); |
| 10851 |
|
| 10852 |
return true; |
| 10853 |
} |
| 10854 |
|
| 10855 |
static bool check_printer_driver_file(struct torture_context *tctx, |
| 10856 |
struct smbcli_state *cli, |
| 10857 |
struct torture_driver_context *d, |
| 10858 |
const char *file_name) |
| 10859 |
{ |
| 10860 |
const char *remote_arch_dir = NULL; |
| 10861 |
const char *remote_name = NULL; |
| 10862 |
int fnum; |
| 10863 |
|
| 10864 |
torture_assert(tctx, (file_name && strlen(file_name) != 0), "invalid filename"); |
| 10865 |
|
| 10866 |
remote_arch_dir = driver_directory_dir(d->remote.driver_directory); |
| 10867 |
torture_assert_not_null(tctx, remote_arch_dir, "remote_arch_dir is null"); |
| 10868 |
|
| 10869 |
remote_name = talloc_asprintf(tctx, |
| 10870 |
"%s\\%d\\%s", |
| 10871 |
remote_arch_dir, |
| 10872 |
d->info8.version, |
| 10873 |
file_name); |
| 10874 |
torture_assert_not_null(tctx, remote_name, "renote_name is null"); |
| 10875 |
|
| 10876 |
torture_comment(tctx, "checking for driver file at %s\n", remote_name); |
| 10877 |
|
| 10878 |
fnum = smbcli_open(cli->tree, remote_name, O_RDONLY, DENY_NONE); |
| 10879 |
if (fnum == -1) { |
| 10880 |
return false; |
| 10881 |
} |
| 10882 |
|
| 10883 |
torture_assert_ntstatus_ok(tctx, |
| 10884 |
smbcli_close(cli->tree, fnum), |
| 10885 |
"failed to close driver file"); |
| 10886 |
|
| 10887 |
return true; |
| 10888 |
} |
| 10889 |
|
| 10890 |
static bool check_printer_driver_files(struct torture_context *tctx, |
| 10891 |
const char *server_name, |
| 10892 |
struct torture_driver_context *d, |
| 10893 |
bool expect_exist) |
| 10894 |
{ |
| 10895 |
struct smbcli_state *cli; |
| 10896 |
const char *share_name = driver_directory_share(tctx, d->remote.driver_directory); |
| 10897 |
int i; |
| 10898 |
|
| 10899 |
torture_assert(tctx, |
| 10900 |
connect_printer_driver_share(tctx, server_name, share_name, &cli), |
| 10901 |
"failed to connect to driver share"); |
| 10902 |
|
| 10903 |
torture_comment(tctx, "checking %sexistent driver files at \\\\%s\\%s\n", |
| 10904 |
(expect_exist ? "": "non-"), |
| 10905 |
server_name, share_name); |
| 10906 |
|
| 10907 |
if (d->info8.driver_path && d->info8.driver_path[0]) { |
| 10908 |
torture_assert(tctx, |
| 10909 |
check_printer_driver_file(tctx, cli, d, d->info8.driver_path) == expect_exist, |
| 10910 |
"failed driver_path check"); |
| 10911 |
} |
| 10912 |
if (d->info8.data_file && d->info8.data_file[0]) { |
| 10913 |
torture_assert(tctx, |
| 10914 |
check_printer_driver_file(tctx, cli, d, d->info8.data_file) == expect_exist, |
| 10915 |
"failed data_file check"); |
| 10916 |
} |
| 10917 |
if (d->info8.config_file && d->info8.config_file[0]) { |
| 10918 |
torture_assert(tctx, |
| 10919 |
check_printer_driver_file(tctx, cli, d, d->info8.config_file) == expect_exist, |
| 10920 |
"failed config_file check"); |
| 10921 |
} |
| 10922 |
if (d->info8.help_file && d->info8.help_file[0]) { |
| 10923 |
torture_assert(tctx, |
| 10924 |
check_printer_driver_file(tctx, cli, d, d->info8.help_file) == expect_exist, |
| 10925 |
"failed help_file check"); |
| 10926 |
} |
| 10927 |
if (d->info8.dependent_files) { |
| 10928 |
for (i=0; d->info8.dependent_files->string && d->info8.dependent_files->string[i] != NULL; i++) { |
| 10929 |
torture_assert(tctx, |
| 10930 |
check_printer_driver_file(tctx, cli, d, d->info8.dependent_files->string[i]) == expect_exist, |
| 10931 |
"failed dependent_files check"); |
| 10932 |
} |
| 10933 |
} |
| 10934 |
|
| 10935 |
talloc_free(cli); |
| 10936 |
|
| 10937 |
return true; |
| 10938 |
} |
| 10939 |
|
| 10940 |
static bool remove_printer_driver_file(struct torture_context *tctx, |
| 10941 |
struct smbcli_state *cli, |
| 10942 |
struct torture_driver_context *d, |
| 10943 |
const char *file_name) |
| 10944 |
{ |
| 10945 |
const char *remote_name; |
| 10946 |
const char *remote_dir = driver_directory_dir(d->remote.driver_directory); |
| 10947 |
|
| 10948 |
if (!file_name || strlen(file_name) == 0) { |
| 10949 |
return true; |
| 10950 |
} |
| 10951 |
|
| 10952 |
remote_name = talloc_asprintf(tctx, "%s\\%s", remote_dir, file_name); |
| 10953 |
|
| 10954 |
torture_comment(tctx, "Removing %s\n", remote_name); |
| 10955 |
|
| 10956 |
torture_assert_ntstatus_ok(tctx, |
| 10957 |
smbcli_unlink(cli->tree, remote_name), |
| 10958 |
"failed to unlink"); |
| 10959 |
|
| 10960 |
return true; |
| 10961 |
} |
| 10962 |
|
| 10963 |
static bool remove_printer_driver(struct torture_context *tctx, |
| 10964 |
const char *server_name, |
| 10965 |
struct torture_driver_context *d) |
| 10966 |
{ |
| 10967 |
struct smbcli_state *cli; |
| 10968 |
const char *share_name = driver_directory_share(tctx, d->remote.driver_directory); |
| 10969 |
int i; |
| 10970 |
|
| 10971 |
torture_assert(tctx, |
| 10972 |
connect_printer_driver_share(tctx, server_name, share_name, &cli), |
| 10973 |
"failed to connect to driver share"); |
| 10974 |
|
| 10975 |
torture_comment(tctx, "Removing printer driver files from \\\\%s\\%s\n", |
| 10976 |
server_name, share_name); |
| 10977 |
|
| 10978 |
torture_assert(tctx, |
| 10979 |
remove_printer_driver_file(tctx, cli, d, d->info8.driver_path), |
| 10980 |
"failed to remove driver_path"); |
| 10981 |
torture_assert(tctx, |
| 10982 |
remove_printer_driver_file(tctx, cli, d, d->info8.data_file), |
| 10983 |
"failed to remove data_file"); |
| 10984 |
if (!strequal(d->info8.config_file, d->info8.driver_path)) { |
| 10985 |
torture_assert(tctx, |
| 10986 |
remove_printer_driver_file(tctx, cli, d, d->info8.config_file), |
| 10987 |
"failed to remove config_file"); |
| 10988 |
} |
| 10989 |
torture_assert(tctx, |
| 10990 |
remove_printer_driver_file(tctx, cli, d, d->info8.help_file), |
| 10991 |
"failed to remove help_file"); |
| 10992 |
if (d->info8.dependent_files) { |
| 10993 |
for (i=0; d->info8.dependent_files->string && d->info8.dependent_files->string[i] != NULL; i++) { |
| 10994 |
if (strequal(d->info8.dependent_files->string[i], d->info8.driver_path) || |
| 10995 |
strequal(d->info8.dependent_files->string[i], d->info8.data_file) || |
| 10996 |
strequal(d->info8.dependent_files->string[i], d->info8.config_file) || |
| 10997 |
strequal(d->info8.dependent_files->string[i], d->info8.help_file)) { |
| 10998 |
continue; |
| 10999 |
} |
| 11000 |
torture_assert(tctx, |
| 11001 |
remove_printer_driver_file(tctx, cli, d, d->info8.dependent_files->string[i]), |
| 11002 |
"failed to remove dependent_files"); |
| 11003 |
} |
| 11004 |
} |
| 11005 |
|
| 11006 |
talloc_free(cli); |
| 11007 |
|
| 11008 |
return true; |
| 11009 |
|
| 11010 |
} |
| 11011 |
|
| 11012 |
static bool test_add_driver_arg(struct torture_context *tctx, |
| 11013 |
struct dcerpc_pipe *p, |
| 11014 |
struct torture_driver_context *d) |
| 11015 |
{ |
| 11016 |
bool ret = true; |
| 11017 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 11018 |
const char *server_name_slash = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p)); |
| 11019 |
uint32_t levels[] = { 1, 2, 3, 4, 6, 8 }; |
| 11020 |
int i; |
| 11021 |
struct spoolss_AddDriverInfo8 info8; |
| 11022 |
uint32_t add_flags = APD_COPY_NEW_FILES; |
| 11023 |
uint32_t delete_flags = 0; |
| 11024 |
|
| 11025 |
ZERO_STRUCT(info8); |
| 11026 |
|
| 11027 |
torture_comment(tctx, "Testing PrinterDriver%s '%s' for environment '%s'\n", |
| 11028 |
d->ex ? "Ex" : "", d->info8.driver_name, d->local.environment); |
| 11029 |
|
| 11030 |
torture_assert(tctx, |
| 11031 |
fillup_printserver_info(tctx, p, d), |
| 11032 |
"failed to fillup printserver info"); |
| 11033 |
|
| 11034 |
if (!directory_exist(d->local.driver_directory)) { |
| 11035 |
torture_skip(tctx, "Skipping Printer Driver test as no local driver is available"); |
| 11036 |
} |
| 11037 |
|
| 11038 |
torture_assert(tctx, |
| 11039 |
upload_printer_driver(tctx, dcerpc_server_name(p), d), |
| 11040 |
"failed to upload printer driver"); |
| 11041 |
|
| 11042 |
info8 = d->info8; |
| 11043 |
if (d->info8.dependent_files) { |
| 11044 |
info8.dependent_files = talloc_zero(tctx, struct spoolss_StringArray); |
| 11045 |
if (d->info8.dependent_files->string) { |
| 11046 |
for (i=0; d->info8.dependent_files->string[i] != NULL; i++) { |
| 11047 |
} |
| 11048 |
info8.dependent_files->string = talloc_zero_array(info8.dependent_files, const char *, i+1); |
| 11049 |
for (i=0; d->info8.dependent_files->string[i] != NULL; i++) { |
| 11050 |
info8.dependent_files->string[i] = talloc_strdup(info8.dependent_files->string, d->info8.dependent_files->string[i]); |
| 11051 |
} |
| 11052 |
} |
| 11053 |
} |
| 11054 |
|
| 11055 |
for (i=0; i < ARRAY_SIZE(levels); i++) { |
| 11056 |
|
| 11057 |
if (torture_setting_bool(tctx, "samba3", false) || |
| 11058 |
torture_setting_bool(tctx, "samba4", false)) { |
| 11059 |
switch (levels[i]) { |
| 11060 |
case 2: |
| 11061 |
case 4: |
| 11062 |
torture_comment(tctx, "skipping level %d against samba\n", levels[i]); |
| 11063 |
continue; |
| 11064 |
default: |
| 11065 |
break; |
| 11066 |
} |
| 11067 |
} |
| 11068 |
if (torture_setting_bool(tctx, "w2k3", false)) { |
| 11069 |
switch (levels[i]) { |
| 11070 |
case 8: |
| 11071 |
torture_comment(tctx, "skipping level %d against w2k3\n", levels[i]); |
| 11072 |
continue; |
| 11073 |
default: |
| 11074 |
break; |
| 11075 |
} |
| 11076 |
} |
| 11077 |
|
| 11078 |
torture_comment(tctx, |
| 11079 |
"Testing PrinterDriver%s '%s' add & delete level %d\n", |
| 11080 |
d->ex ? "Ex" : "", info8.driver_name, levels[i]); |
| 11081 |
|
| 11082 |
ret &= test_PrinterDriver_args(tctx, b, server_name_slash, levels[i], &info8, add_flags, delete_flags, d->info8.version, d->ex, d->remote.driver_directory); |
| 11083 |
} |
| 11084 |
|
| 11085 |
info8.driver_path = talloc_asprintf(tctx, "%s\\%s", d->remote.driver_directory, d->info8.driver_path); |
| 11086 |
info8.data_file = talloc_asprintf(tctx, "%s\\%s", d->remote.driver_directory, d->info8.data_file); |
| 11087 |
if (d->info8.config_file) { |
| 11088 |
info8.config_file = talloc_asprintf(tctx, "%s\\%s", d->remote.driver_directory, d->info8.config_file); |
| 11089 |
} |
| 11090 |
if (d->info8.help_file) { |
| 11091 |
info8.help_file = talloc_asprintf(tctx, "%s\\%s", d->remote.driver_directory, d->info8.help_file); |
| 11092 |
} |
| 11093 |
if (d->info8.dependent_files && d->info8.dependent_files->string) { |
| 11094 |
for (i=0; d->info8.dependent_files->string[i] != NULL; i++) { |
| 11095 |
info8.dependent_files->string[i] = talloc_asprintf(tctx, "%s\\%s", d->remote.driver_directory, d->info8.dependent_files->string[i]); |
| 11096 |
} |
| 11097 |
} |
| 11098 |
|
| 11099 |
for (i=0; i < ARRAY_SIZE(levels); i++) { |
| 11100 |
|
| 11101 |
if (torture_setting_bool(tctx, "samba3", false) || |
| 11102 |
torture_setting_bool(tctx, "samba4", false)) { |
| 11103 |
switch (levels[i]) { |
| 11104 |
case 2: |
| 11105 |
case 4: |
| 11106 |
continue; |
| 11107 |
default: |
| 11108 |
break; |
| 11109 |
} |
| 11110 |
} |
| 11111 |
if (torture_setting_bool(tctx, "w2k3", false)) { |
| 11112 |
switch (levels[i]) { |
| 11113 |
case 8: |
| 11114 |
torture_comment(tctx, "skipping level %d against w2k3\n", levels[i]); |
| 11115 |
continue; |
| 11116 |
default: |
| 11117 |
break; |
| 11118 |
} |
| 11119 |
} |
| 11120 |
|
| 11121 |
torture_comment(tctx, |
| 11122 |
"Testing PrinterDriver%s '%s' add & delete level %d (full unc paths)\n", |
| 11123 |
d->ex ? "Ex" : "", info8.driver_name, levels[i]); |
| 11124 |
|
| 11125 |
ret &= test_PrinterDriver_args(tctx, b, server_name_slash, levels[i], &info8, add_flags, delete_flags, d->info8.version, d->ex, d->remote.driver_directory); |
| 11126 |
} |
| 11127 |
|
| 11128 |
torture_assert(tctx, |
| 11129 |
remove_printer_driver(tctx, dcerpc_server_name(p), d), |
| 11130 |
"failed to remove printer driver"); |
| 11131 |
|
| 11132 |
torture_comment(tctx, "\n"); |
| 11133 |
|
| 11134 |
return ret; |
| 11135 |
} |
| 11136 |
|
| 11137 |
static bool test_add_driver_ex_64(struct torture_context *tctx, |
| 11138 |
struct dcerpc_pipe *p) |
| 11139 |
{ |
| 11140 |
struct torture_driver_context *d; |
| 11141 |
|
| 11142 |
d = talloc_zero(tctx, struct torture_driver_context); |
| 11143 |
|
| 11144 |
d->local.environment = talloc_strdup(d, SPOOLSS_ARCHITECTURE_x64); |
| 11145 |
d->local.driver_directory = talloc_strdup(d, "/usr/share/cups/drivers/x64"); |
| 11146 |
|
| 11147 |
d->info8.version = SPOOLSS_DRIVER_VERSION_200X; |
| 11148 |
d->info8.driver_name = TORTURE_DRIVER_EX; |
| 11149 |
d->info8.architecture = d->local.environment; |
| 11150 |
d->info8.driver_path = talloc_strdup(d, "pscript5.dll"); |
| 11151 |
d->info8.data_file = talloc_strdup(d, "cups6.ppd"); |
| 11152 |
d->info8.config_file = talloc_strdup(d, "cupsui6.dll"); |
| 11153 |
d->ex = true; |
| 11154 |
|
| 11155 |
return test_add_driver_arg(tctx, p, d); |
| 11156 |
} |
| 11157 |
|
| 11158 |
static bool test_add_driver_ex_32(struct torture_context *tctx, |
| 11159 |
struct dcerpc_pipe *p) |
| 11160 |
{ |
| 11161 |
struct torture_driver_context *d; |
| 11162 |
|
| 11163 |
d = talloc_zero(tctx, struct torture_driver_context); |
| 11164 |
|
| 11165 |
d->local.environment = talloc_strdup(d, SPOOLSS_ARCHITECTURE_NT_X86); |
| 11166 |
d->local.driver_directory = talloc_strdup(d, "/usr/share/cups/drivers/i386"); |
| 11167 |
|
| 11168 |
d->info8.version = SPOOLSS_DRIVER_VERSION_200X; |
| 11169 |
d->info8.driver_name = TORTURE_DRIVER_EX; |
| 11170 |
d->info8.architecture = d->local.environment; |
| 11171 |
d->info8.driver_path = talloc_strdup(d, "pscript5.dll"); |
| 11172 |
d->info8.data_file = talloc_strdup(d, "cups6.ppd"); |
| 11173 |
d->info8.config_file = talloc_strdup(d, "cupsui6.dll"); |
| 11174 |
d->ex = true; |
| 11175 |
|
| 11176 |
return test_add_driver_arg(tctx, p, d); |
| 11177 |
} |
| 11178 |
|
| 11179 |
static bool test_add_driver_64(struct torture_context *tctx, |
| 11180 |
struct dcerpc_pipe *p) |
| 11181 |
{ |
| 11182 |
struct torture_driver_context *d; |
| 11183 |
|
| 11184 |
d = talloc_zero(tctx, struct torture_driver_context); |
| 11185 |
|
| 11186 |
d->local.environment = talloc_strdup(d, SPOOLSS_ARCHITECTURE_x64); |
| 11187 |
d->local.driver_directory = talloc_strdup(d, "/usr/share/cups/drivers/x64"); |
| 11188 |
|
| 11189 |
d->info8.version = SPOOLSS_DRIVER_VERSION_200X; |
| 11190 |
d->info8.driver_name = TORTURE_DRIVER_ADD; |
| 11191 |
d->info8.architecture = d->local.environment; |
| 11192 |
d->info8.driver_path = talloc_strdup(d, "pscript5.dll"); |
| 11193 |
d->info8.data_file = talloc_strdup(d, "cups6.ppd"); |
| 11194 |
d->info8.config_file = talloc_strdup(d, "cupsui6.dll"); |
| 11195 |
d->ex = false; |
| 11196 |
|
| 11197 |
return test_add_driver_arg(tctx, p, d); |
| 11198 |
} |
| 11199 |
|
| 11200 |
static bool test_add_driver_32(struct torture_context *tctx, |
| 11201 |
struct dcerpc_pipe *p) |
| 11202 |
{ |
| 11203 |
struct torture_driver_context *d; |
| 11204 |
|
| 11205 |
d = talloc_zero(tctx, struct torture_driver_context); |
| 11206 |
|
| 11207 |
d->local.environment = talloc_strdup(d, SPOOLSS_ARCHITECTURE_NT_X86); |
| 11208 |
d->local.driver_directory = talloc_strdup(d, "/usr/share/cups/drivers/i386"); |
| 11209 |
|
| 11210 |
d->info8.version = SPOOLSS_DRIVER_VERSION_200X; |
| 11211 |
d->info8.driver_name = TORTURE_DRIVER_ADD; |
| 11212 |
d->info8.architecture = d->local.environment; |
| 11213 |
d->info8.driver_path = talloc_strdup(d, "pscript5.dll"); |
| 11214 |
d->info8.data_file = talloc_strdup(d, "cups6.ppd"); |
| 11215 |
d->info8.config_file = talloc_strdup(d, "cupsui6.dll"); |
| 11216 |
d->ex = false; |
| 11217 |
|
| 11218 |
return test_add_driver_arg(tctx, p, d); |
| 11219 |
} |
| 11220 |
|
| 11221 |
static bool test_add_driver_adobe(struct torture_context *tctx, |
| 11222 |
struct dcerpc_pipe *p) |
| 11223 |
{ |
| 11224 |
struct torture_driver_context *d; |
| 11225 |
|
| 11226 |
if (!torture_setting_bool(tctx, "samba3", false)) { |
| 11227 |
torture_skip(tctx, "skipping adobe test which only works against samba3"); |
| 11228 |
} |
| 11229 |
|
| 11230 |
d = talloc_zero(tctx, struct torture_driver_context); |
| 11231 |
|
| 11232 |
d->local.environment = talloc_strdup(d, "Windows 4.0"); |
| 11233 |
d->local.driver_directory = talloc_strdup(d, "/usr/share/cups/drivers/adobe/"); |
| 11234 |
|
| 11235 |
d->info8.version = SPOOLSS_DRIVER_VERSION_9X; |
| 11236 |
d->info8.driver_name = TORTURE_DRIVER_ADOBE; |
| 11237 |
d->info8.architecture = d->local.environment; |
| 11238 |
d->info8.driver_path = talloc_strdup(d, "ADOBEPS4.DRV"); |
| 11239 |
d->info8.data_file = talloc_strdup(d, "DEFPRTR2.PPD"); |
| 11240 |
d->info8.config_file = talloc_strdup(d, "ADOBEPS4.DRV"); |
| 11241 |
#if 0 |
| 11242 |
d->info8.help_file = talloc_strdup(d, "ADOBEPS4.HLP"); |
| 11243 |
d->info8.monitor_name = talloc_strdup(d, "PSMON.DLL"); |
| 11244 |
#endif |
| 11245 |
d->ex = false; |
| 11246 |
|
| 11247 |
return test_add_driver_arg(tctx, p, d); |
| 11248 |
} |
| 11249 |
|
| 11250 |
static bool test_add_driver_adobe_cupsaddsmb(struct torture_context *tctx, |
| 11251 |
struct dcerpc_pipe *p) |
| 11252 |
{ |
| 11253 |
struct torture_driver_context *d; |
| 11254 |
struct spoolss_StringArray *a; |
| 11255 |
|
| 11256 |
if (!torture_setting_bool(tctx, "samba3", false)) { |
| 11257 |
torture_skip(tctx, "skipping cupsaddsmb test which only works against samba3"); |
| 11258 |
} |
| 11259 |
|
| 11260 |
d = talloc_zero(tctx, struct torture_driver_context); |
| 11261 |
|
| 11262 |
d->local.environment = talloc_strdup(d, "Windows 4.0"); |
| 11263 |
d->local.driver_directory = talloc_strdup(d, "/usr/share/cups/drivers/adobe/"); |
| 11264 |
|
| 11265 |
d->info8.version = SPOOLSS_DRIVER_VERSION_9X; |
| 11266 |
d->info8.driver_name = TORTURE_DRIVER_ADOBE_CUPSADDSMB; |
| 11267 |
d->info8.architecture = d->local.environment; |
| 11268 |
d->info8.driver_path = talloc_strdup(d, "ADOBEPS4.DRV"); |
| 11269 |
d->info8.data_file = talloc_strdup(d, "DEFPRTR2.PPD"); |
| 11270 |
d->info8.config_file = NULL; |
| 11271 |
d->info8.help_file = talloc_strdup(d, "ADOBEPS4.HLP"); |
| 11272 |
d->info8.monitor_name = talloc_strdup(d, "PSMON.DLL"); |
| 11273 |
d->info8.default_datatype = talloc_strdup(d, "RAW"); |
| 11274 |
|
| 11275 |
a = talloc_zero(d, struct spoolss_StringArray); |
| 11276 |
a->string = talloc_zero_array(a, const char *, 7); |
| 11277 |
a->string[0] = talloc_strdup(a->string, "ADOBEPS4.DRV"); |
| 11278 |
a->string[1] = talloc_strdup(a->string, "DEFPRTR2.PPD"); |
| 11279 |
a->string[2] = talloc_strdup(a->string, "ADOBEPS4.HLP"); |
| 11280 |
a->string[3] = talloc_strdup(a->string, "PSMON.DLL"); |
| 11281 |
a->string[4] = talloc_strdup(a->string, "ADFONTS.MFM"); |
| 11282 |
a->string[5] = talloc_strdup(a->string, "ICONLIB.DLL"); |
| 11283 |
|
| 11284 |
d->info8.dependent_files = a; |
| 11285 |
d->ex = false; |
| 11286 |
|
| 11287 |
return test_add_driver_arg(tctx, p, d); |
| 11288 |
} |
| 11289 |
|
| 11290 |
static bool test_add_driver_timestamps(struct torture_context *tctx, |
| 11291 |
struct dcerpc_pipe *p) |
| 11292 |
{ |
| 11293 |
struct torture_driver_context *d; |
| 11294 |
struct timeval t = timeval_current(); |
| 11295 |
|
| 11296 |
d = talloc_zero(tctx, struct torture_driver_context); |
| 11297 |
|
| 11298 |
d->local.environment = talloc_strdup(d, SPOOLSS_ARCHITECTURE_NT_X86); |
| 11299 |
d->local.driver_directory = talloc_strdup(d, "/usr/share/cups/drivers/i386"); |
| 11300 |
|
| 11301 |
d->info8.version = SPOOLSS_DRIVER_VERSION_200X; |
| 11302 |
d->info8.driver_name = TORTURE_DRIVER_TIMESTAMPS; |
| 11303 |
d->info8.architecture = d->local.environment; |
| 11304 |
d->info8.driver_path = talloc_strdup(d, "pscript5.dll"); |
| 11305 |
d->info8.data_file = talloc_strdup(d, "cups6.ppd"); |
| 11306 |
d->info8.config_file = talloc_strdup(d, "cupsui6.dll"); |
| 11307 |
d->info8.driver_date = timeval_to_nttime(&t); |
| 11308 |
d->ex = true; |
| 11309 |
|
| 11310 |
torture_assert(tctx, |
| 11311 |
test_add_driver_arg(tctx, p, d), |
| 11312 |
""); |
| 11313 |
|
| 11314 |
unix_to_nt_time(&d->info8.driver_date, 1); |
| 11315 |
|
| 11316 |
torture_assert(tctx, |
| 11317 |
test_add_driver_arg(tctx, p, d), |
| 11318 |
""); |
| 11319 |
|
| 11320 |
return true; |
| 11321 |
} |
| 11322 |
|
| 11323 |
static bool test_multiple_drivers(struct torture_context *tctx, |
| 11324 |
struct dcerpc_pipe *p) |
| 11325 |
{ |
| 11326 |
struct torture_driver_context *d; |
| 11327 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 11328 |
const char *server_name_slash = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p)); |
| 11329 |
int i; |
| 11330 |
struct spoolss_AddDriverInfo8 info8; |
| 11331 |
uint32_t add_flags = APD_COPY_NEW_FILES; |
| 11332 |
uint32_t delete_flags = 0; |
| 11333 |
|
| 11334 |
d = talloc_zero(tctx, struct torture_driver_context); |
| 11335 |
|
| 11336 |
d->local.environment = talloc_strdup(d, SPOOLSS_ARCHITECTURE_NT_X86); |
| 11337 |
d->local.driver_directory = talloc_strdup(d, "/usr/share/cups/drivers/i386"); |
| 11338 |
|
| 11339 |
d->info8.version = SPOOLSS_DRIVER_VERSION_200X; |
| 11340 |
d->info8.driver_path = talloc_strdup(d, "pscript5.dll"); |
| 11341 |
d->info8.data_file = talloc_strdup(d, "cups6.ppd"); |
| 11342 |
d->info8.config_file = talloc_strdup(d, "cupsui6.dll"); |
| 11343 |
d->info8.architecture = d->local.environment; |
| 11344 |
d->ex = true; |
| 11345 |
|
| 11346 |
torture_assert(tctx, |
| 11347 |
fillup_printserver_info(tctx, p, d), |
| 11348 |
"failed to fillup printserver info"); |
| 11349 |
|
| 11350 |
if (!directory_exist(d->local.driver_directory)) { |
| 11351 |
torture_skip(tctx, "Skipping Printer Driver test as no local driver is available"); |
| 11352 |
} |
| 11353 |
|
| 11354 |
torture_assert(tctx, |
| 11355 |
upload_printer_driver(tctx, dcerpc_server_name(p), d), |
| 11356 |
"failed to upload printer driver"); |
| 11357 |
|
| 11358 |
info8 = d->info8; |
| 11359 |
|
| 11360 |
for (i=0; i < 3; i++) { |
| 11361 |
info8.driver_name = talloc_asprintf(d, "torture_test_driver_%d", i); |
| 11362 |
|
| 11363 |
torture_assert(tctx, |
| 11364 |
test_AddPrinterDriver_args_level_3(tctx, b, server_name_slash, &info8, add_flags, true, NULL), |
| 11365 |
"failed to add driver"); |
| 11366 |
} |
| 11367 |
|
| 11368 |
torture_assert(tctx, |
| 11369 |
test_DeletePrinterDriverEx(tctx, b, server_name_slash, "torture_test_driver_0", info8.architecture, delete_flags, info8.version), |
| 11370 |
"failed to delete driver"); |
| 11371 |
|
| 11372 |
torture_assert(tctx, |
| 11373 |
test_EnumPrinterDrivers_findone(tctx, b, server_name_slash, info8.architecture, 3, "torture_test_driver_1", NULL), |
| 11374 |
"torture_test_driver_1 no longer on the server"); |
| 11375 |
|
| 11376 |
torture_assert(tctx, |
| 11377 |
test_EnumPrinterDrivers_findone(tctx, b, server_name_slash, info8.architecture, 3, "torture_test_driver_2", NULL), |
| 11378 |
"torture_test_driver_2 no longer on the server"); |
| 11379 |
|
| 11380 |
torture_assert(tctx, |
| 11381 |
test_DeletePrinterDriverEx(tctx, b, server_name_slash, "torture_test_driver_1", info8.architecture, delete_flags, info8.version), |
| 11382 |
"failed to delete driver"); |
| 11383 |
|
| 11384 |
torture_assert(tctx, |
| 11385 |
test_EnumPrinterDrivers_findone(tctx, b, server_name_slash, info8.architecture, 3, "torture_test_driver_2", NULL), |
| 11386 |
"torture_test_driver_2 no longer on the server"); |
| 11387 |
|
| 11388 |
torture_assert(tctx, |
| 11389 |
test_DeletePrinterDriverEx(tctx, b, server_name_slash, "torture_test_driver_2", info8.architecture, delete_flags, info8.version), |
| 11390 |
"failed to delete driver"); |
| 11391 |
|
| 11392 |
torture_assert(tctx, |
| 11393 |
remove_printer_driver(tctx, dcerpc_server_name(p), d), |
| 11394 |
"failed to remove printer driver"); |
| 11395 |
|
| 11396 |
return true; |
| 11397 |
} |
| 11398 |
|
| 11399 |
static bool test_driver_copy_from_directory(struct torture_context *tctx, |
| 11400 |
struct dcerpc_pipe *p, |
| 11401 |
const char *architecture) |
| 11402 |
{ |
| 11403 |
struct torture_driver_context *d; |
| 11404 |
struct spoolss_StringArray *a; |
| 11405 |
uint32_t add_flags = APD_COPY_NEW_FILES|APD_COPY_FROM_DIRECTORY|APD_RETURN_BLOCKING_STATUS_CODE; |
| 11406 |
uint32_t delete_flags = DPD_DELETE_ALL_FILES; |
| 11407 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 11408 |
const char *server_name_slash = talloc_asprintf(tctx, |
| 11409 |
"\\\\%s", |
| 11410 |
dcerpc_server_name(p)); |
| 11411 |
struct GUID guid = GUID_random(); |
| 11412 |
bool ok = false; |
| 11413 |
|
| 11414 |
d = talloc_zero(tctx, struct torture_driver_context); |
| 11415 |
torture_assert_not_null(tctx, d, "ENOMEM"); |
| 11416 |
|
| 11417 |
d->local.environment = talloc_strdup(d, architecture); |
| 11418 |
torture_assert_not_null_goto(tctx, d->local.environment, ok, done, "ENOMEM"); |
| 11419 |
|
| 11420 |
if (strequal(architecture, SPOOLSS_ARCHITECTURE_x64)) { |
| 11421 |
d->local.driver_directory = |
| 11422 |
talloc_strdup(d, "/usr/share/cups/drivers/x64"); |
| 11423 |
} else { |
| 11424 |
d->local.driver_directory = |
| 11425 |
talloc_strdup(d, "/usr/share/cups/drivers/i386"); |
| 11426 |
} |
| 11427 |
torture_assert_not_null_goto(tctx, d->local.driver_directory, ok, done, "ENOMEM"); |
| 11428 |
|
| 11429 |
d->remote.driver_upload_directory = GUID_string2(d, &guid); |
| 11430 |
torture_assert_not_null_goto(tctx, d->remote.driver_upload_directory, ok, done, "ENOMEM"); |
| 11431 |
|
| 11432 |
torture_assert(tctx, |
| 11433 |
fillup_printserver_info(tctx, p, d), |
| 11434 |
"failed to fillup printserver info"); |
| 11435 |
|
| 11436 |
d->ex = true; |
| 11437 |
d->info8.version = SPOOLSS_DRIVER_VERSION_200X; |
| 11438 |
d->info8.driver_name = TORTURE_DRIVER_COPY_DIR; |
| 11439 |
d->info8.architecture = d->local.environment; |
| 11440 |
|
| 11441 |
d->info8.driver_path = CREATE_PRINTER_DRIVER_PATH(d, "pscript5.dll"); |
| 11442 |
torture_assert_not_null_goto(tctx, d->info8.driver_path, ok, done, "ENOMEM"); |
| 11443 |
d->info8.data_file = CREATE_PRINTER_DRIVER_PATH(d, "cups6.ppd"); |
| 11444 |
torture_assert_not_null_goto(tctx, d->info8.data_file, ok, done, "ENOMEM"); |
| 11445 |
d->info8.config_file = CREATE_PRINTER_DRIVER_PATH(d, "cupsui6.dll"); |
| 11446 |
torture_assert_not_null_goto(tctx, d->info8.config_file, ok, done, "ENOMEM"); |
| 11447 |
d->info8.help_file = CREATE_PRINTER_DRIVER_PATH(d, "pscript.hlp"); |
| 11448 |
torture_assert_not_null_goto(tctx, d->info8.help_file, ok, done, "ENOMEM"); |
| 11449 |
|
| 11450 |
a = talloc_zero(d, struct spoolss_StringArray); |
| 11451 |
torture_assert_not_null_goto(tctx, a, ok, done, "ENOMEM"); |
| 11452 |
a->string = talloc_zero_array(a, const char *, 3); |
| 11453 |
torture_assert_not_null_goto(tctx, a->string, ok, done, "ENOMEM"); |
| 11454 |
a->string[0] = CREATE_PRINTER_DRIVER_PATH(d, "cups6.inf"); |
| 11455 |
torture_assert_not_null_goto(tctx, a->string[0], ok, done, "ENOMEM"); |
| 11456 |
a->string[1] = CREATE_PRINTER_DRIVER_PATH(d, "cups6.ini"); |
| 11457 |
torture_assert_not_null_goto(tctx, a->string[1], ok, done, "ENOMEM"); |
| 11458 |
|
| 11459 |
d->info8.dependent_files = a; |
| 11460 |
|
| 11461 |
if (!directory_exist(d->local.driver_directory)) { |
| 11462 |
torture_skip(tctx, |
| 11463 |
"Skipping Printer Driver test as no local drivers " |
| 11464 |
"are available"); |
| 11465 |
} |
| 11466 |
|
| 11467 |
torture_assert(tctx, |
| 11468 |
upload_printer_driver(tctx, dcerpc_server_name(p), d), |
| 11469 |
"failed to upload printer driver"); |
| 11470 |
|
| 11471 |
torture_assert(tctx, |
| 11472 |
test_AddPrinterDriver_args_level_3(tctx, |
| 11473 |
b, |
| 11474 |
server_name_slash, |
| 11475 |
&d->info8, |
| 11476 |
add_flags, |
| 11477 |
true, |
| 11478 |
NULL), |
| 11479 |
"failed to add driver"); |
| 11480 |
|
| 11481 |
torture_assert(tctx, |
| 11482 |
test_DeletePrinterDriverEx(tctx, |
| 11483 |
b, |
| 11484 |
server_name_slash, |
| 11485 |
d->info8.driver_name, |
| 11486 |
d->local.environment, |
| 11487 |
delete_flags, |
| 11488 |
d->info8.version), |
| 11489 |
"failed to delete driver"); |
| 11490 |
|
| 11491 |
torture_assert(tctx, |
| 11492 |
check_printer_driver_files(tctx, |
| 11493 |
dcerpc_server_name(p), |
| 11494 |
d, |
| 11495 |
false), |
| 11496 |
"printer driver file check failed"); |
| 11497 |
|
| 11498 |
ok = true; |
| 11499 |
done: |
| 11500 |
talloc_free(d); |
| 11501 |
return ok; |
| 11502 |
} |
| 11503 |
|
| 11504 |
static bool test_driver_copy_from_directory_64(struct torture_context *tctx, |
| 11505 |
struct dcerpc_pipe *p) |
| 11506 |
{ |
| 11507 |
return test_driver_copy_from_directory(tctx, p, SPOOLSS_ARCHITECTURE_x64); |
| 11508 |
} |
| 11509 |
|
| 11510 |
static bool test_driver_copy_from_directory_32(struct torture_context *tctx, |
| 11511 |
struct dcerpc_pipe *p) |
| 11512 |
{ |
| 11513 |
return test_driver_copy_from_directory(tctx, p, SPOOLSS_ARCHITECTURE_NT_X86); |
| 11514 |
} |
| 11515 |
|
| 11516 |
static bool test_del_driver_all_files(struct torture_context *tctx, |
| 11517 |
struct dcerpc_pipe *p) |
| 11518 |
{ |
| 11519 |
struct torture_driver_context *d; |
| 11520 |
struct spoolss_StringArray *a; |
| 11521 |
uint32_t add_flags = APD_COPY_NEW_FILES; |
| 11522 |
uint32_t delete_flags = DPD_DELETE_ALL_FILES; |
| 11523 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 11524 |
const char *server_name_slash = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p)); |
| 11525 |
|
| 11526 |
d = talloc_zero(tctx, struct torture_driver_context); |
| 11527 |
|
| 11528 |
d->local.environment = talloc_strdup(d, SPOOLSS_ARCHITECTURE_x64); |
| 11529 |
d->local.driver_directory = talloc_strdup(d, "/usr/share/cups/drivers/x64"); |
| 11530 |
|
| 11531 |
d->ex = true; |
| 11532 |
d->info8.version = SPOOLSS_DRIVER_VERSION_200X; |
| 11533 |
d->info8.driver_name = TORTURE_DRIVER_DELETER; |
| 11534 |
d->info8.architecture = d->local.environment; |
| 11535 |
d->info8.driver_path = talloc_strdup(d, "pscript5.dll"); |
| 11536 |
d->info8.data_file = talloc_strdup(d, "cups6.ppd"); |
| 11537 |
d->info8.config_file = talloc_strdup(d, "cupsui6.dll"); |
| 11538 |
d->info8.help_file = talloc_strdup(d, "pscript.hlp"); |
| 11539 |
|
| 11540 |
a = talloc_zero(d, struct spoolss_StringArray); |
| 11541 |
a->string = talloc_zero_array(a, const char *, 3); |
| 11542 |
a->string[0] = talloc_strdup(a->string, "cups6.inf"); |
| 11543 |
a->string[1] = talloc_strdup(a->string, "cups6.ini"); |
| 11544 |
|
| 11545 |
d->info8.dependent_files = a; |
| 11546 |
|
| 11547 |
torture_assert(tctx, |
| 11548 |
fillup_printserver_info(tctx, p, d), |
| 11549 |
"failed to fillup printserver info"); |
| 11550 |
|
| 11551 |
if (!directory_exist(d->local.driver_directory)) { |
| 11552 |
torture_skip(tctx, "Skipping Printer Driver test as no local driver is available"); |
| 11553 |
} |
| 11554 |
|
| 11555 |
torture_assert(tctx, |
| 11556 |
upload_printer_driver(tctx, dcerpc_server_name(p), d), |
| 11557 |
"failed to upload printer driver"); |
| 11558 |
|
| 11559 |
torture_assert(tctx, |
| 11560 |
test_AddPrinterDriver_args_level_3(tctx, b, server_name_slash, &d->info8, add_flags, true, NULL), |
| 11561 |
"failed to add driver"); |
| 11562 |
|
| 11563 |
torture_assert(tctx, |
| 11564 |
test_DeletePrinterDriverEx(tctx, b, server_name_slash, |
| 11565 |
d->info8.driver_name, |
| 11566 |
d->info8.architecture, |
| 11567 |
delete_flags, |
| 11568 |
d->info8.version), |
| 11569 |
"failed to delete driver"); |
| 11570 |
|
| 11571 |
torture_assert(tctx, |
| 11572 |
check_printer_driver_files(tctx, dcerpc_server_name(p), d, false), |
| 11573 |
"printer driver file check failed"); |
| 11574 |
|
| 11575 |
talloc_free(d); |
| 11576 |
return true; |
| 11577 |
} |
| 11578 |
|
| 11579 |
static bool test_del_driver_unused_files(struct torture_context *tctx, |
| 11580 |
struct dcerpc_pipe *p) |
| 11581 |
{ |
| 11582 |
struct torture_driver_context *d1; |
| 11583 |
struct torture_driver_context *d2; |
| 11584 |
uint32_t add_flags = APD_COPY_NEW_FILES; |
| 11585 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 11586 |
const char *server_name_slash = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p)); |
| 11587 |
|
| 11588 |
d1 = talloc_zero(tctx, struct torture_driver_context); |
| 11589 |
d1->ex = true; |
| 11590 |
|
| 11591 |
d1->local.environment = talloc_strdup(d1, SPOOLSS_ARCHITECTURE_x64); |
| 11592 |
d1->local.driver_directory = talloc_strdup(d1, "/usr/share/cups/drivers/x64"); |
| 11593 |
|
| 11594 |
d1->info8.version = SPOOLSS_DRIVER_VERSION_200X; |
| 11595 |
d1->info8.driver_name = TORTURE_DRIVER_DELETER; |
| 11596 |
d1->info8.architecture = NULL; |
| 11597 |
d1->info8.driver_path = talloc_strdup(d1, "pscript5.dll"); |
| 11598 |
d1->info8.data_file = talloc_strdup(d1, "cups6.ppd"); |
| 11599 |
d1->info8.config_file = talloc_strdup(d1, "cupsui6.dll"); |
| 11600 |
d1->info8.help_file = talloc_strdup(d1, "pscript.hlp"); |
| 11601 |
d1->info8.architecture = d1->local.environment; |
| 11602 |
|
| 11603 |
d2 = talloc_zero(tctx, struct torture_driver_context); |
| 11604 |
d2->ex = true; |
| 11605 |
|
| 11606 |
d2->local.environment = talloc_strdup(d2, SPOOLSS_ARCHITECTURE_x64); |
| 11607 |
d2->local.driver_directory = talloc_strdup(d2, "/usr/share/cups/drivers/x64"); |
| 11608 |
|
| 11609 |
d2->info8.version = SPOOLSS_DRIVER_VERSION_200X; |
| 11610 |
d2->info8.driver_name = TORTURE_DRIVER_DELETERIN; |
| 11611 |
d2->info8.architecture = NULL; |
| 11612 |
d2->info8.driver_path = talloc_strdup(d2, "pscript5.dll"); /* overlapping */ |
| 11613 |
d2->info8.data_file = talloc_strdup(d2, "cupsps6.dll"); |
| 11614 |
d2->info8.config_file = talloc_strdup(d2, "cups6.ini"); |
| 11615 |
d2->info8.help_file = talloc_strdup(d2, "pscript.hlp"); /* overlapping */ |
| 11616 |
d2->info8.architecture = d2->local.environment; |
| 11617 |
|
| 11618 |
torture_assert(tctx, |
| 11619 |
fillup_printserver_info(tctx, p, d1), |
| 11620 |
"failed to fillup printserver info"); |
| 11621 |
torture_assert(tctx, |
| 11622 |
fillup_printserver_info(tctx, p, d2), |
| 11623 |
"failed to fillup printserver info"); |
| 11624 |
|
| 11625 |
if (!directory_exist(d1->local.driver_directory)) { |
| 11626 |
torture_skip(tctx, "Skipping Printer Driver test as no local driver is available"); |
| 11627 |
} |
| 11628 |
|
| 11629 |
torture_assert(tctx, |
| 11630 |
upload_printer_driver(tctx, dcerpc_server_name(p), d1), |
| 11631 |
"failed to upload printer driver"); |
| 11632 |
torture_assert(tctx, |
| 11633 |
test_AddPrinterDriver_args_level_3(tctx, b, server_name_slash, &d1->info8, add_flags, true, NULL), |
| 11634 |
"failed to add driver"); |
| 11635 |
|
| 11636 |
torture_assert(tctx, |
| 11637 |
upload_printer_driver(tctx, dcerpc_server_name(p), d2), |
| 11638 |
"failed to upload printer driver"); |
| 11639 |
torture_assert(tctx, |
| 11640 |
test_AddPrinterDriver_args_level_3(tctx, b, server_name_slash, &d2->info8, add_flags, true, NULL), |
| 11641 |
"failed to add driver"); |
| 11642 |
|
| 11643 |
/* some files are in use by a separate driver, should fail */ |
| 11644 |
torture_assert(tctx, |
| 11645 |
test_DeletePrinterDriverEx_exp(tctx, b, server_name_slash, |
| 11646 |
d1->info8.driver_name, |
| 11647 |
d1->info8.architecture, |
| 11648 |
DPD_DELETE_ALL_FILES, |
| 11649 |
d1->info8.version, |
| 11650 |
WERR_PRINTER_DRIVER_IN_USE), |
| 11651 |
"invalid delete driver response"); |
| 11652 |
|
| 11653 |
/* should only delete files not in use by other driver */ |
| 11654 |
torture_assert(tctx, |
| 11655 |
test_DeletePrinterDriverEx_exp(tctx, b, server_name_slash, |
| 11656 |
d1->info8.driver_name, |
| 11657 |
d1->info8.architecture, |
| 11658 |
DPD_DELETE_UNUSED_FILES, |
| 11659 |
d1->info8.version, |
| 11660 |
WERR_OK), |
| 11661 |
"failed to delete driver (unused files)"); |
| 11662 |
|
| 11663 |
/* check non-overlapping were deleted */ |
| 11664 |
d1->info8.driver_path = NULL; |
| 11665 |
d1->info8.help_file = NULL; |
| 11666 |
torture_assert(tctx, |
| 11667 |
check_printer_driver_files(tctx, dcerpc_server_name(p), d1, false), |
| 11668 |
"printer driver file check failed"); |
| 11669 |
/* d2 files should be uneffected */ |
| 11670 |
torture_assert(tctx, |
| 11671 |
check_printer_driver_files(tctx, dcerpc_server_name(p), d2, true), |
| 11672 |
"printer driver file check failed"); |
| 11673 |
|
| 11674 |
torture_assert(tctx, |
| 11675 |
test_DeletePrinterDriverEx_exp(tctx, b, server_name_slash, |
| 11676 |
d2->info8.driver_name, |
| 11677 |
d2->info8.architecture, |
| 11678 |
DPD_DELETE_ALL_FILES, |
| 11679 |
d2->info8.version, |
| 11680 |
WERR_OK), |
| 11681 |
"failed to delete driver"); |
| 11682 |
|
| 11683 |
torture_assert(tctx, |
| 11684 |
check_printer_driver_files(tctx, dcerpc_server_name(p), d2, false), |
| 11685 |
"printer driver file check failed"); |
| 11686 |
|
| 11687 |
talloc_free(d1); |
| 11688 |
talloc_free(d2); |
| 11689 |
return true; |
| 11690 |
} |
| 11691 |
|
| 11692 |
struct torture_suite *torture_rpc_spoolss_driver(TALLOC_CTX *mem_ctx) |
| 11693 |
{ |
| 11694 |
struct torture_suite *suite = torture_suite_create(mem_ctx, "spoolss.driver"); |
| 11695 |
|
| 11696 |
struct torture_rpc_tcase *tcase = torture_suite_add_rpc_iface_tcase(suite, |
| 11697 |
"driver", &ndr_table_spoolss); |
| 11698 |
torture_rpc_tcase_add_test(tcase, "add_driver_64", test_add_driver_64); |
| 11699 |
torture_rpc_tcase_add_test(tcase, "add_driver_ex_64", test_add_driver_ex_64); |
| 11700 |
|
| 11701 |
torture_rpc_tcase_add_test(tcase, "add_driver_32", test_add_driver_32); |
| 11702 |
torture_rpc_tcase_add_test(tcase, "add_driver_ex_32", test_add_driver_ex_32); |
| 11703 |
|
| 11704 |
torture_rpc_tcase_add_test(tcase, "add_driver_adobe", test_add_driver_adobe); |
| 11705 |
|
| 11706 |
torture_rpc_tcase_add_test(tcase, "add_driver_adobe_cupsaddsmb", test_add_driver_adobe_cupsaddsmb); |
| 11707 |
|
| 11708 |
torture_rpc_tcase_add_test(tcase, "add_driver_timestamps", test_add_driver_timestamps); |
| 11709 |
|
| 11710 |
torture_rpc_tcase_add_test(tcase, "multiple_drivers", test_multiple_drivers); |
| 11711 |
|
| 11712 |
torture_rpc_tcase_add_test(tcase, |
| 11713 |
"test_driver_copy_from_directory_64", |
| 11714 |
test_driver_copy_from_directory_64); |
| 11715 |
|
| 11716 |
torture_rpc_tcase_add_test(tcase, |
| 11717 |
"test_driver_copy_from_directory_32", |
| 11718 |
test_driver_copy_from_directory_32); |
| 11719 |
|
| 11720 |
torture_rpc_tcase_add_test(tcase, "del_driver_all_files", test_del_driver_all_files); |
| 11721 |
|
| 11722 |
torture_rpc_tcase_add_test(tcase, "del_driver_unused_files", test_del_driver_unused_files); |
| 11723 |
|
| 11724 |
return suite; |
| 11725 |
} |