2 Unix SMB/Netbios implementation.
5 Copyright (C) Tim Potter 2000
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 2 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, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include "se_access_check_utils.h"
30 struct ace_entry acl_printer[] = {
32 /* Everyone is allowed to print */
34 { SEC_ACE_TYPE_ACCESS_ALLOWED, SEC_ACE_FLAG_CONTAINER_INHERIT,
35 PRINTER_ACE_PRINT, "S-1-1-0" },
37 /* Except for user0 who uses too much paper */
39 { SEC_ACE_TYPE_ACCESS_DENIED, SEC_ACE_FLAG_CONTAINER_INHERIT,
40 PRINTER_ACE_FULL_CONTROL, "user0" },
42 /* Users 1 and 2 can manage documents */
44 { SEC_ACE_TYPE_ACCESS_ALLOWED, SEC_ACE_FLAG_CONTAINER_INHERIT,
45 PRINTER_ACE_MANAGE_DOCUMENTS, "user1" },
47 { SEC_ACE_TYPE_ACCESS_ALLOWED, SEC_ACE_FLAG_CONTAINER_INHERIT,
48 PRINTER_ACE_MANAGE_DOCUMENTS, "user2" },
50 /* Domain Admins can also manage documents */
52 { SEC_ACE_TYPE_ACCESS_ALLOWED, SEC_ACE_FLAG_CONTAINER_INHERIT,
53 PRINTER_ACE_MANAGE_DOCUMENTS, "Domain Admins" },
55 /* User 3 is da man */
57 { SEC_ACE_TYPE_ACCESS_ALLOWED, SEC_ACE_FLAG_CONTAINER_INHERIT,
58 PRINTER_ACE_FULL_CONTROL, "user3" },
63 BOOL test_user(char *username, uint32 acc_desired, uint32 *acc_granted)
68 if (!(pw = getpwnam(username))) {
69 printf("FAIL: could not lookup user info for %s\n",
74 return se_access_check(sd, pw->pw_uid, pw->pw_gid, 0, NULL,
75 acc_desired, acc_granted, &status);
78 static char *pace_str(uint32 ace_flags)
80 if ((ace_flags & PRINTER_ACE_FULL_CONTROL) ==
81 PRINTER_ACE_FULL_CONTROL) return "full control";
83 if ((ace_flags & PRINTER_ACE_MANAGE_DOCUMENTS) ==
84 PRINTER_ACE_MANAGE_DOCUMENTS) return "manage documents";
86 if ((ace_flags & PRINTER_ACE_PRINT) == PRINTER_ACE_PRINT)
94 PRINTER_ACE_FULL_CONTROL,
95 PRINTER_ACE_MANAGE_DOCUMENTS,
105 for (i = 0; perms[i]; i++) {
109 for (j = 0; j < 10; j++) {
112 /* Test user against ACL */
114 snprintf(name, sizeof(fstring), "%s/user%d",
115 getenv("TEST_WORKGROUP"), j);
117 result = test_user(name, perms[i], &acc_granted);
119 printf("%s: %s %s 0x%08x\n", name,
121 result ? "TRUE " : "FALSE", acc_granted);
127 case PRINTER_ACE_PRINT: {
128 if (!result || acc_granted !=
130 printf("FAIL: user %s can't print\n",
137 case PRINTER_ACE_FULL_CONTROL: {
139 if (!result || acc_granted !=
140 PRINTER_ACE_FULL_CONTROL) {
141 printf("FAIL: user %s doesn't "
142 "have full control\n",
147 if (result || acc_granted != 0) {
148 printf("FAIL: user %s has full "
155 case PRINTER_ACE_MANAGE_DOCUMENTS: {
156 if (j == 1 || j == 2) {
157 if (!result || acc_granted !=
158 PRINTER_ACE_MANAGE_DOCUMENTS) {
159 printf("FAIL: user %s can't "
160 "manage documents\n",
165 if (result || acc_granted != 0) {
166 printf("FAIL: user %s can "
167 "manage documents\n",
176 printf("FAIL: internal error\n");
185 int main(int argc, char **argv)
189 generate_wellknown_sids();
191 /* Create security descriptor */
193 sd = build_sec_desc(acl_printer, NULL, NULL_SID, NULL_SID);
196 printf("FAIL: could not build security descriptor\n");