2 Unix SMB/CIFS implementation.
3 test suite for spoolss rpc operations
5 Copyright (C) Guenther Deschner 2010
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "torture/torture.h"
23 #include "librpc/gen_ndr/ndr_misc.h"
24 #include "librpc/gen_ndr/ndr_spoolss.h"
25 #include "librpc/gen_ndr/ndr_spoolss_c.h"
26 #include "librpc/gen_ndr/ndr_samr_c.h"
27 #include "librpc/gen_ndr/ndr_lsa_c.h"
28 #include "librpc/gen_ndr/ndr_security.h"
29 #include "libcli/security/security.h"
30 #include "torture/rpc/torture_rpc.h"
31 #include "param/param.h"
32 #include "lib/cmdline/popt_common.h"
34 #define TORTURE_USER "torture_user"
35 #define TORTURE_USER_ADMINGROUP "torture_user_544"
36 #define TORTURE_USER_PRINTOPGROUP "torture_user_550"
37 #define TORTURE_USER_PRINTOPPRIV "torture_user_priv"
38 #define TORTURE_USER_SD "torture_user_sd"
39 #define TORTURE_WORKSTATION "torture_workstation"
44 uint32_t *builtin_memberships
;
45 uint32_t num_builtin_memberships
;
54 struct torture_access_context
{
55 struct dcerpc_pipe
*spoolss_pipe
;
56 const char *printername
;
57 struct security_descriptor
*sd_orig
;
58 struct torture_user user
;
61 static bool test_openprinter_handle(struct torture_context
*tctx
,
62 struct dcerpc_pipe
*p
,
64 const char *printername
,
67 WERROR expected_result
,
68 struct policy_handle
*handle
)
70 struct spoolss_OpenPrinterEx r
;
71 struct spoolss_UserLevel1 level1
;
72 struct dcerpc_binding_handle
*b
= p
->binding_handle
;
75 level1
.client
= talloc_asprintf(tctx
, "\\\\%s", "smbtorture");
76 level1
.user
= username
;
82 r
.in
.printername
= printername
;
84 r
.in
.devmode_ctr
.devmode
= NULL
;
85 r
.in
.access_mask
= access_mask
;
86 r
.in
.userlevel_ctr
.level
= 1;
87 r
.in
.userlevel_ctr
.user_info
.level1
= &level1
;
88 r
.out
.handle
= handle
;
90 torture_comment(tctx
, "Testing OpenPrinterEx(%s) with access_mask 0x%08x (%s)\n",
91 r
.in
.printername
, r
.in
.access_mask
, name
);
93 torture_assert_ntstatus_ok(tctx
,
94 dcerpc_spoolss_OpenPrinterEx_r(b
, tctx
, &r
),
95 "OpenPrinterEx failed");
96 torture_assert_werr_equal(tctx
, r
.out
.result
, expected_result
,
97 talloc_asprintf(tctx
, "OpenPrinterEx(%s) as '%s' with access_mask: 0x%08x (%s) failed",
98 r
.in
.printername
, username
, r
.in
.access_mask
, name
));
103 static bool test_openprinter_access(struct torture_context
*tctx
,
104 struct dcerpc_pipe
*p
,
106 const char *printername
,
107 const char *username
,
108 uint32_t access_mask
,
109 WERROR expected_result
)
111 struct policy_handle handle
;
112 struct dcerpc_binding_handle
*b
= p
->binding_handle
;
117 if (printername
== NULL
) {
118 torture_comment(tctx
, "skipping test %s as there is no printer\n", name
);
122 ret
= test_openprinter_handle(tctx
, p
, name
, printername
, username
, access_mask
, expected_result
, &handle
);
123 if (is_valid_policy_hnd(&handle
)) {
124 test_ClosePrinter(tctx
, b
, &handle
);
130 static bool spoolss_access_setup_membership(struct torture_context
*tctx
,
131 struct dcerpc_pipe
*p
,
132 uint32_t num_members
,
134 struct dom_sid
*user_sid
)
136 struct dcerpc_binding_handle
*b
= p
->binding_handle
;
137 struct policy_handle connect_handle
, domain_handle
;
140 torture_comment(tctx
,
141 "Setting up BUILTIN membership for %s\n",
142 dom_sid_string(tctx
, user_sid
));
143 for (i
=0; i
< num_members
; i
++) {
144 torture_comment(tctx
, "adding user to S-1-5-32-%d\n", members
[i
]);
148 struct samr_Connect2 r
;
149 r
.in
.system_name
= "";
150 r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
151 r
.out
.connect_handle
= &connect_handle
;
153 torture_assert_ntstatus_ok(tctx
,
154 dcerpc_samr_Connect2_r(b
, tctx
, &r
),
155 "samr_Connect2 failed");
156 torture_assert_ntstatus_ok(tctx
, r
.out
.result
,
157 "samr_Connect2 failed");
161 struct samr_OpenDomain r
;
162 r
.in
.connect_handle
= &connect_handle
;
163 r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
164 r
.in
.sid
= dom_sid_parse_talloc(tctx
, "S-1-5-32");
165 r
.out
.domain_handle
= &domain_handle
;
167 torture_assert_ntstatus_ok(tctx
,
168 dcerpc_samr_OpenDomain_r(b
, tctx
, &r
),
169 "samr_OpenDomain failed");
170 torture_assert_ntstatus_ok(tctx
, r
.out
.result
,
171 "samr_OpenDomain failed");
174 for (i
=0; i
< num_members
; i
++) {
176 struct policy_handle alias_handle
;
179 struct samr_OpenAlias r
;
180 r
.in
.domain_handle
= &domain_handle
;
181 r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
182 r
.in
.rid
= members
[i
];
183 r
.out
.alias_handle
= &alias_handle
;
185 torture_assert_ntstatus_ok(tctx
,
186 dcerpc_samr_OpenAlias_r(b
, tctx
, &r
),
187 "samr_OpenAlias failed");
188 torture_assert_ntstatus_ok(tctx
, r
.out
.result
,
189 "samr_OpenAlias failed");
193 struct samr_AddAliasMember r
;
194 r
.in
.alias_handle
= &alias_handle
;
197 torture_assert_ntstatus_ok(tctx
,
198 dcerpc_samr_AddAliasMember_r(b
, tctx
, &r
),
199 "samr_AddAliasMember failed");
200 torture_assert_ntstatus_ok(tctx
, r
.out
.result
,
201 "samr_AddAliasMember failed");
204 test_samr_handle_Close(b
, tctx
, &alias_handle
);
207 test_samr_handle_Close(b
, tctx
, &domain_handle
);
208 test_samr_handle_Close(b
, tctx
, &connect_handle
);
213 static void init_lsa_StringLarge(struct lsa_StringLarge
*name
, const char *s
)
217 static void init_lsa_String(struct lsa_String
*name
, const char *s
)
222 static bool spoolss_access_setup_privs(struct torture_context
*tctx
,
223 struct dcerpc_pipe
*p
,
226 struct dom_sid
*user_sid
,
229 struct dcerpc_binding_handle
*b
= p
->binding_handle
;
230 struct policy_handle
*handle
;
234 test_lsa_OpenPolicy2(b
, tctx
, &handle
),
235 "failed to open policy");
237 for (i
=0; i
< num_privs
; i
++) {
238 struct lsa_LookupPrivValue r
;
239 struct lsa_LUID luid
;
240 struct lsa_String name
;
242 init_lsa_String(&name
, privs
[i
]);
244 r
.in
.handle
= handle
;
248 torture_assert_ntstatus_ok(tctx
,
249 dcerpc_lsa_LookupPrivValue_r(b
, tctx
, &r
),
250 "lsa_LookupPrivValue failed");
251 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
252 torture_comment(tctx
, "lsa_LookupPrivValue failed for '%s' with %s\n",
253 privs
[i
], nt_errstr(r
.out
.result
));
254 *privs_present
= false;
259 *privs_present
= true;
262 struct lsa_AddAccountRights r
;
263 struct lsa_RightSet rights
;
265 rights
.count
= num_privs
;
266 rights
.names
= talloc_zero_array(tctx
, struct lsa_StringLarge
, rights
.count
);
268 for (i
=0; i
< rights
.count
; i
++) {
269 init_lsa_StringLarge(&rights
.names
[i
], privs
[i
]);
272 r
.in
.handle
= handle
;
274 r
.in
.rights
= &rights
;
276 torture_assert_ntstatus_ok(tctx
,
277 dcerpc_lsa_AddAccountRights_r(b
, tctx
, &r
),
278 "lsa_AddAccountRights failed");
279 torture_assert_ntstatus_ok(tctx
, r
.out
.result
,
280 "lsa_AddAccountRights failed");
283 test_lsa_Close(b
, tctx
, handle
);
288 static bool test_SetPrinter(struct torture_context
*tctx
,
289 struct dcerpc_binding_handle
*b
,
290 struct policy_handle
*handle
,
291 struct spoolss_SetPrinterInfoCtr
*info_ctr
,
292 struct spoolss_DevmodeContainer
*devmode_ctr
,
293 struct sec_desc_buf
*secdesc_ctr
,
294 enum spoolss_PrinterControl command
)
296 struct spoolss_SetPrinter r
;
298 r
.in
.handle
= handle
;
299 r
.in
.info_ctr
= info_ctr
;
300 r
.in
.devmode_ctr
= devmode_ctr
;
301 r
.in
.secdesc_ctr
= secdesc_ctr
;
302 r
.in
.command
= command
;
304 torture_comment(tctx
, "Testing SetPrinter level %d\n", r
.in
.info_ctr
->level
);
306 torture_assert_ntstatus_ok(tctx
, dcerpc_spoolss_SetPrinter_r(b
, tctx
, &r
),
307 "failed to call SetPrinter");
308 torture_assert_werr_ok(tctx
, r
.out
.result
,
309 "failed to call SetPrinter");
314 static bool spoolss_access_setup_sd(struct torture_context
*tctx
,
315 struct dcerpc_pipe
*p
,
316 const char *printername
,
317 const struct dom_sid
*user_sid
,
318 struct security_descriptor
**sd_orig
)
320 struct dcerpc_binding_handle
*b
= p
->binding_handle
;
321 struct policy_handle handle
;
322 union spoolss_PrinterInfo info
;
323 struct spoolss_SetPrinterInfoCtr info_ctr
;
324 struct spoolss_SetPrinterInfo3 info3
;
325 struct spoolss_DevmodeContainer devmode_ctr
;
326 struct sec_desc_buf secdesc_ctr
;
327 struct security_ace
*ace
;
328 struct security_descriptor
*sd
;
331 test_openprinter_handle(tctx
, p
, "", printername
, "", SEC_FLAG_MAXIMUM_ALLOWED
, WERR_OK
, &handle
),
332 "failed to open printer");
335 test_GetPrinter_level(tctx
, b
, &handle
, 3, &info
),
338 sd
= security_descriptor_copy(tctx
, info
.info3
.secdesc
);
339 *sd_orig
= security_descriptor_copy(tctx
, info
.info3
.secdesc
);
341 ace
= talloc_zero(tctx
, struct security_ace
);
343 ace
->type
= SEC_ACE_TYPE_ACCESS_ALLOWED
;
345 ace
->access_mask
= PRINTER_ALL_ACCESS
;
346 ace
->trustee
= *user_sid
;
348 torture_assert_ntstatus_ok(tctx
,
349 security_descriptor_dacl_add(sd
, ace
),
350 "failed to add new ace");
352 ace
= talloc_zero(tctx
, struct security_ace
);
354 ace
->type
= SEC_ACE_TYPE_ACCESS_ALLOWED
;
355 ace
->flags
= SEC_ACE_FLAG_OBJECT_INHERIT
|
356 SEC_ACE_FLAG_CONTAINER_INHERIT
|
357 SEC_ACE_FLAG_INHERIT_ONLY
;
358 ace
->access_mask
= SEC_GENERIC_ALL
;
359 ace
->trustee
= *user_sid
;
361 torture_assert_ntstatus_ok(tctx
,
362 security_descriptor_dacl_add(sd
, ace
),
363 "failed to add new ace");
366 ZERO_STRUCT(info_ctr
);
367 ZERO_STRUCT(devmode_ctr
);
368 ZERO_STRUCT(secdesc_ctr
);
371 info_ctr
.info
.info3
= &info3
;
375 test_SetPrinter(tctx
, b
, &handle
, &info_ctr
, &devmode_ctr
, &secdesc_ctr
, 0),
381 static bool test_EnumPrinters_findone(struct torture_context
*tctx
,
382 struct dcerpc_pipe
*p
,
383 const char **printername
)
385 struct spoolss_EnumPrinters r
;
387 union spoolss_PrinterInfo
*info
;
390 struct dcerpc_binding_handle
*b
= p
->binding_handle
;
394 r
.in
.flags
= PRINTER_ENUM_LOCAL
;
399 r
.out
.count
= &count
;
401 r
.out
.needed
= &needed
;
403 torture_assert_ntstatus_ok(tctx
,
404 dcerpc_spoolss_EnumPrinters_r(b
, tctx
, &r
),
405 "failed to enum printers");
407 if (W_ERROR_EQUAL(r
.out
.result
, WERR_INSUFFICIENT_BUFFER
)) {
408 DATA_BLOB blob
= data_blob_talloc_zero(tctx
, needed
);
410 r
.in
.offered
= needed
;
412 torture_assert_ntstatus_ok(tctx
,
413 dcerpc_spoolss_EnumPrinters_r(b
, tctx
, &r
),
414 "failed to enum printers");
417 torture_assert_werr_ok(tctx
, r
.out
.result
,
418 "failed to enum printers");
420 for (i
=0; i
< count
; i
++) {
422 if (count
> 1 && strequal(info
[i
].info1
.name
, "Microsoft XPS Document Writer")) {
426 torture_comment(tctx
, "testing printer: %s\n",
429 *printername
= talloc_strdup(tctx
, info
[i
].info1
.name
);
437 static bool torture_rpc_spoolss_access_setup_common(struct torture_context
*tctx
, struct torture_access_context
*t
)
440 const char *testuser_passwd
;
441 struct cli_credentials
*test_credentials
;
442 struct dom_sid
*test_sid
;
443 struct dcerpc_pipe
*p
;
444 const char *printername
;
445 const char *binding
= torture_setting_string(tctx
, "binding", NULL
);
446 struct dcerpc_pipe
*spoolss_pipe
;
448 testuser
= torture_create_testuser_max_pwlen(tctx
, t
->user
.username
,
449 torture_setting_string(tctx
, "workgroup", NULL
),
454 torture_fail(tctx
, "Failed to create test user");
457 test_credentials
= cli_credentials_init(tctx
);
458 cli_credentials_set_workstation(test_credentials
, "localhost", CRED_SPECIFIED
);
459 cli_credentials_set_domain(test_credentials
, lpcfg_workgroup(tctx
->lp_ctx
),
461 cli_credentials_set_username(test_credentials
, t
->user
.username
, CRED_SPECIFIED
);
462 cli_credentials_set_password(test_credentials
, testuser_passwd
, CRED_SPECIFIED
);
463 test_sid
= discard_const_p(struct dom_sid
,
464 torture_join_user_sid(testuser
));
466 if (t
->user
.num_builtin_memberships
) {
467 struct dcerpc_pipe
*samr_pipe
= torture_join_samr_pipe(testuser
);
470 spoolss_access_setup_membership(tctx
, samr_pipe
,
471 t
->user
.num_builtin_memberships
,
472 t
->user
.builtin_memberships
,
474 "failed to setup membership");
477 if (t
->user
.num_privs
) {
478 struct dcerpc_pipe
*lsa_pipe
;
480 torture_assert_ntstatus_ok(tctx
,
481 torture_rpc_connection(tctx
, &lsa_pipe
, &ndr_table_lsarpc
),
482 "Error connecting to server");
485 spoolss_access_setup_privs(tctx
, lsa_pipe
,
489 &t
->user
.privs_present
),
490 "failed to setup privs");
491 talloc_free(lsa_pipe
);
494 torture_assert_ntstatus_ok(tctx
,
495 torture_rpc_connection(tctx
, &spoolss_pipe
, &ndr_table_spoolss
),
496 "Error connecting to server");
499 test_EnumPrinters_findone(tctx
, spoolss_pipe
, &printername
),
500 "failed to enumerate printers");
502 if (t
->user
.sd
&& printername
) {
504 spoolss_access_setup_sd(tctx
, spoolss_pipe
,
508 "failed to setup sd");
511 talloc_free(spoolss_pipe
);
513 torture_assert_ntstatus_ok(tctx
,
514 dcerpc_pipe_connect(tctx
, &p
, binding
, &ndr_table_spoolss
,
515 test_credentials
, tctx
->ev
, tctx
->lp_ctx
),
516 "Error connecting to server");
519 t
->printername
= printername
;
520 t
->user
.testuser
= testuser
;
525 static bool torture_rpc_spoolss_access_setup(struct torture_context
*tctx
, void **data
)
527 struct torture_access_context
*t
;
529 *data
= t
= talloc_zero(tctx
, struct torture_access_context
);
531 t
->user
.username
= talloc_strdup(t
, TORTURE_USER
);
533 return torture_rpc_spoolss_access_setup_common(tctx
, t
);
536 static bool torture_rpc_spoolss_access_admin_setup(struct torture_context
*tctx
, void **data
)
538 struct torture_access_context
*t
;
540 *data
= t
= talloc_zero(tctx
, struct torture_access_context
);
542 t
->user
.num_builtin_memberships
= 1;
543 t
->user
.builtin_memberships
= talloc_zero_array(t
, uint32_t, t
->user
.num_builtin_memberships
);
544 t
->user
.builtin_memberships
[0] = BUILTIN_RID_ADMINISTRATORS
;
545 t
->user
.username
= talloc_strdup(t
, TORTURE_USER_ADMINGROUP
);
546 t
->user
.admin_rights
= true;
547 t
->user
.system_security
= true;
549 return torture_rpc_spoolss_access_setup_common(tctx
, t
);
552 static bool torture_rpc_spoolss_access_printop_setup(struct torture_context
*tctx
, void **data
)
554 struct torture_access_context
*t
;
556 *data
= t
= talloc_zero(tctx
, struct torture_access_context
);
558 t
->user
.num_builtin_memberships
= 1;
559 t
->user
.builtin_memberships
= talloc_zero_array(t
, uint32_t, t
->user
.num_builtin_memberships
);
560 t
->user
.builtin_memberships
[0] = BUILTIN_RID_PRINT_OPERATORS
;
561 t
->user
.username
= talloc_strdup(t
, TORTURE_USER_PRINTOPGROUP
);
562 t
->user
.admin_rights
= true;
564 return torture_rpc_spoolss_access_setup_common(tctx
, t
);
567 static bool torture_rpc_spoolss_access_priv_setup(struct torture_context
*tctx
, void **data
)
569 struct torture_access_context
*t
;
571 *data
= t
= talloc_zero(tctx
, struct torture_access_context
);
573 t
->user
.username
= talloc_strdup(t
, TORTURE_USER_PRINTOPPRIV
);
574 t
->user
.num_privs
= 1;
575 t
->user
.privs
= talloc_zero_array(t
, const char *, t
->user
.num_privs
);
576 t
->user
.privs
[0] = talloc_strdup(t
, "SePrintOperatorPrivilege");
577 t
->user
.admin_rights
= true;
579 return torture_rpc_spoolss_access_setup_common(tctx
, t
);
582 static bool torture_rpc_spoolss_access_sd_setup(struct torture_context
*tctx
, void **data
)
584 struct torture_access_context
*t
;
586 *data
= t
= talloc_zero(tctx
, struct torture_access_context
);
588 t
->user
.username
= talloc_strdup(t
, TORTURE_USER_SD
);
590 t
->user
.admin_rights
= true;
592 return torture_rpc_spoolss_access_setup_common(tctx
, t
);
595 static bool torture_rpc_spoolss_access_teardown_common(struct torture_context
*tctx
, struct torture_access_context
*t
)
597 if (t
->user
.testuser
) {
598 torture_leave_domain(tctx
, t
->user
.testuser
);
601 /* remove membership ? */
602 if (t
->user
.num_builtin_memberships
) {
606 if (t
->user
.num_privs
) {
610 if (t
->user
.sd
&& t
->printername
) {
611 struct policy_handle handle
;
612 struct spoolss_SetPrinterInfoCtr info_ctr
;
613 struct spoolss_SetPrinterInfo3 info3
;
614 struct spoolss_DevmodeContainer devmode_ctr
;
615 struct sec_desc_buf secdesc_ctr
;
616 struct dcerpc_pipe
*spoolss_pipe
;
617 struct dcerpc_binding_handle
*b
;
619 torture_assert_ntstatus_ok(tctx
,
620 torture_rpc_connection(tctx
, &spoolss_pipe
, &ndr_table_spoolss
),
621 "Error connecting to server");
623 b
= spoolss_pipe
->binding_handle
;
625 ZERO_STRUCT(info_ctr
);
627 ZERO_STRUCT(devmode_ctr
);
628 ZERO_STRUCT(secdesc_ctr
);
631 info_ctr
.info
.info3
= &info3
;
632 secdesc_ctr
.sd
= t
->sd_orig
;
635 test_openprinter_handle(tctx
, spoolss_pipe
, "", t
->printername
, "", SEC_FLAG_MAXIMUM_ALLOWED
, WERR_OK
, &handle
),
636 "failed to open printer");
639 test_SetPrinter(tctx
, b
, &handle
, &info_ctr
, &devmode_ctr
, &secdesc_ctr
, 0),
642 talloc_free(spoolss_pipe
);
648 static bool torture_rpc_spoolss_access_teardown(struct torture_context
*tctx
, void *data
)
650 struct torture_access_context
*t
= talloc_get_type(data
, struct torture_access_context
);
653 ret
= torture_rpc_spoolss_access_teardown_common(tctx
, t
);
659 static bool test_openprinter(struct torture_context
*tctx
,
662 struct torture_access_context
*t
=
663 (struct torture_access_context
*)talloc_get_type_abort(private_data
, struct torture_access_context
);
664 struct dcerpc_pipe
*p
= t
->spoolss_pipe
;
666 const char *username
= t
->user
.username
;
667 const char *servername_slash
= talloc_asprintf(tctx
, "\\\\%s", dcerpc_server_name(p
));
672 uint32_t access_mask
;
673 const char *printername
;
674 WERROR expected_result
;
677 /* printserver handle tests */
682 .printername
= servername_slash
,
683 .expected_result
= WERR_OK
686 .name
= "SEC_FLAG_MAXIMUM_ALLOWED",
687 .access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
,
688 .printername
= servername_slash
,
689 .expected_result
= WERR_OK
692 .name
= "SERVER_ACCESS_ENUMERATE",
693 .access_mask
= SERVER_ACCESS_ENUMERATE
,
694 .printername
= servername_slash
,
695 .expected_result
= WERR_OK
698 .name
= "SERVER_ACCESS_ADMINISTER",
699 .access_mask
= SERVER_ACCESS_ADMINISTER
,
700 .printername
= servername_slash
,
701 .expected_result
= t
->user
.admin_rights
? WERR_OK
: WERR_ACCESS_DENIED
704 .name
= "SERVER_READ",
705 .access_mask
= SERVER_READ
,
706 .printername
= servername_slash
,
707 .expected_result
= WERR_OK
710 .name
= "SERVER_WRITE",
711 .access_mask
= SERVER_WRITE
,
712 .printername
= servername_slash
,
713 .expected_result
= t
->user
.admin_rights
? WERR_OK
: WERR_ACCESS_DENIED
716 .name
= "SERVER_EXECUTE",
717 .access_mask
= SERVER_EXECUTE
,
718 .printername
= servername_slash
,
719 .expected_result
= WERR_OK
722 .name
= "SERVER_ALL_ACCESS",
723 .access_mask
= SERVER_ALL_ACCESS
,
724 .printername
= servername_slash
,
725 .expected_result
= t
->user
.admin_rights
? WERR_OK
: WERR_ACCESS_DENIED
728 /* printer handle tests */
733 .printername
= t
->printername
,
734 .expected_result
= WERR_OK
737 .name
= "SEC_FLAG_MAXIMUM_ALLOWED",
738 .access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
,
739 .printername
= t
->printername
,
740 .expected_result
= WERR_OK
743 .name
= "SEC_FLAG_SYSTEM_SECURITY",
744 .access_mask
= SEC_FLAG_SYSTEM_SECURITY
,
745 .printername
= t
->printername
,
746 .expected_result
= t
->user
.system_security
? WERR_OK
: WERR_ACCESS_DENIED
749 .name
= "0x010e0000",
750 .access_mask
= 0x010e0000,
751 .printername
= t
->printername
,
752 .expected_result
= t
->user
.system_security
? WERR_OK
: WERR_ACCESS_DENIED
755 .name
= "PRINTER_ACCESS_USE",
756 .access_mask
= PRINTER_ACCESS_USE
,
757 .printername
= t
->printername
,
758 .expected_result
= WERR_OK
761 .name
= "SEC_STD_READ_CONTROL",
762 .access_mask
= SEC_STD_READ_CONTROL
,
763 .printername
= t
->printername
,
764 .expected_result
= WERR_OK
767 .name
= "PRINTER_ACCESS_ADMINISTER",
768 .access_mask
= PRINTER_ACCESS_ADMINISTER
,
769 .printername
= t
->printername
,
770 .expected_result
= t
->user
.admin_rights
? WERR_OK
: WERR_ACCESS_DENIED
773 .name
= "SEC_STD_WRITE_DAC",
774 .access_mask
= SEC_STD_WRITE_DAC
,
775 .printername
= t
->printername
,
776 .expected_result
= t
->user
.admin_rights
? WERR_OK
: WERR_ACCESS_DENIED
779 .name
= "SEC_STD_WRITE_OWNER",
780 .access_mask
= SEC_STD_WRITE_OWNER
,
781 .printername
= t
->printername
,
782 .expected_result
= t
->user
.admin_rights
? WERR_OK
: WERR_ACCESS_DENIED
785 .name
= "PRINTER_READ",
786 .access_mask
= PRINTER_READ
,
787 .printername
= t
->printername
,
788 .expected_result
= WERR_OK
791 .name
= "PRINTER_WRITE",
792 .access_mask
= PRINTER_WRITE
,
793 .printername
= t
->printername
,
794 .expected_result
= t
->user
.admin_rights
? WERR_OK
: WERR_ACCESS_DENIED
797 .name
= "PRINTER_EXECUTE",
798 .access_mask
= PRINTER_EXECUTE
,
799 .printername
= t
->printername
,
800 .expected_result
= WERR_OK
803 .name
= "PRINTER_ALL_ACCESS",
804 .access_mask
= PRINTER_ALL_ACCESS
,
805 .printername
= t
->printername
,
806 .expected_result
= t
->user
.admin_rights
? WERR_OK
: WERR_ACCESS_DENIED
810 if (t
->user
.num_privs
&& !t
->user
.privs_present
) {
811 torture_skip(tctx
, "skipping test as not all required privileges are present on the server\n");
814 for (i
=0; i
< ARRAY_SIZE(checks
); i
++) {
815 ret
&= test_openprinter_access(tctx
, p
,
817 checks
[i
].printername
,
819 checks
[i
].access_mask
,
820 checks
[i
].expected_result
);
826 static bool test_openprinter_wrap(struct torture_context
*tctx
,
827 struct dcerpc_pipe
*p
)
829 struct torture_access_context
*t
;
830 const char *printername
;
833 t
= talloc_zero(tctx
, struct torture_access_context
);
835 t
->user
.username
= talloc_strdup(tctx
, "dummy");
839 test_EnumPrinters_findone(tctx
, p
, &printername
),
840 "failed to enumerate printers");
842 t
->printername
= printername
;
844 ret
= test_openprinter(tctx
, (void *)t
);
851 struct torture_suite
*torture_rpc_spoolss_access(TALLOC_CTX
*mem_ctx
)
853 struct torture_suite
*suite
= torture_suite_create(mem_ctx
, "spoolss.access");
854 struct torture_tcase
*tcase
;
855 struct torture_rpc_tcase
*rpc_tcase
;
857 tcase
= torture_suite_add_tcase(suite
, "normaluser");
859 torture_tcase_set_fixture(tcase
,
860 torture_rpc_spoolss_access_setup
,
861 torture_rpc_spoolss_access_teardown
);
863 torture_tcase_add_simple_test(tcase
, "openprinter", test_openprinter
);
865 tcase
= torture_suite_add_tcase(suite
, "adminuser");
867 torture_tcase_set_fixture(tcase
,
868 torture_rpc_spoolss_access_admin_setup
,
869 torture_rpc_spoolss_access_teardown
);
871 torture_tcase_add_simple_test(tcase
, "openprinter", test_openprinter
);
873 tcase
= torture_suite_add_tcase(suite
, "printopuser");
875 torture_tcase_set_fixture(tcase
,
876 torture_rpc_spoolss_access_printop_setup
,
877 torture_rpc_spoolss_access_teardown
);
879 torture_tcase_add_simple_test(tcase
, "openprinter", test_openprinter
);
881 tcase
= torture_suite_add_tcase(suite
, "printopuserpriv");
883 torture_tcase_set_fixture(tcase
,
884 torture_rpc_spoolss_access_priv_setup
,
885 torture_rpc_spoolss_access_teardown
);
887 torture_tcase_add_simple_test(tcase
, "openprinter", test_openprinter
);
889 tcase
= torture_suite_add_tcase(suite
, "normaluser_sd");
891 torture_tcase_set_fixture(tcase
,
892 torture_rpc_spoolss_access_sd_setup
,
893 torture_rpc_spoolss_access_teardown
);
895 torture_tcase_add_simple_test(tcase
, "openprinter", test_openprinter
);
897 rpc_tcase
= torture_suite_add_machine_workstation_rpc_iface_tcase(suite
, "workstation",
899 TORTURE_WORKSTATION
);
901 torture_rpc_tcase_add_test(rpc_tcase
, "openprinter", test_openprinter_wrap
);