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 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 "se_access_check_utils.h"
29 struct ace_entry acl_printer[] = {
31 /* Everyone is allowed to print */
33 { SEC_ACE_TYPE_ACCESS_ALLOWED, SEC_ACE_FLAG_CONTAINER_INHERIT,
34 PRINTER_ACE_PRINT, "S-1-1-0" },
36 /* Except for user0 who uses too much paper */
38 { SEC_ACE_TYPE_ACCESS_DENIED, SEC_ACE_FLAG_CONTAINER_INHERIT,
39 PRINTER_ACE_FULL_CONTROL, "user0" },
41 /* Users 1 and 2 can manage documents */
43 { SEC_ACE_TYPE_ACCESS_ALLOWED, SEC_ACE_FLAG_CONTAINER_INHERIT,
44 PRINTER_ACE_MANAGE_DOCUMENTS, "user1" },
46 { SEC_ACE_TYPE_ACCESS_ALLOWED, SEC_ACE_FLAG_CONTAINER_INHERIT,
47 PRINTER_ACE_MANAGE_DOCUMENTS, "user2" },
49 /* Domain Admins can also manage documents */
51 { SEC_ACE_TYPE_ACCESS_ALLOWED, SEC_ACE_FLAG_CONTAINER_INHERIT,
52 PRINTER_ACE_MANAGE_DOCUMENTS, "Domain Admins" },
54 /* User 3 is da man */
56 { SEC_ACE_TYPE_ACCESS_ALLOWED, SEC_ACE_FLAG_CONTAINER_INHERIT,
57 PRINTER_ACE_FULL_CONTROL, "user3" },
62 BOOL test_user(char *username, uint32 acc_desired, uint32 *acc_granted)
67 if (!(pw = getpwnam(username))) {
68 printf("FAIL: could not lookup user info for %s\n",
73 return se_access_check(sd, pw->pw_uid, pw->pw_gid, 0, NULL,
74 acc_desired, acc_granted, &status);
77 static char *pace_str(uint32 ace_flags)
79 if ((ace_flags & PRINTER_ACE_FULL_CONTROL) ==
80 PRINTER_ACE_FULL_CONTROL) return "full control";
82 if ((ace_flags & PRINTER_ACE_MANAGE_DOCUMENTS) ==
83 PRINTER_ACE_MANAGE_DOCUMENTS) return "manage documents";
85 if ((ace_flags & PRINTER_ACE_PRINT) == PRINTER_ACE_PRINT)
93 PRINTER_ACE_FULL_CONTROL,
94 PRINTER_ACE_MANAGE_DOCUMENTS,
104 for (i = 0; perms[i]; i++) {
108 for (j = 0; j < 10; j++) {
111 /* Test user against ACL */
113 snprintf(name, sizeof(fstring), "%s/user%d",
114 getenv("TEST_WORKGROUP"), j);
116 result = test_user(name, perms[i], &acc_granted);
118 printf("%s: %s %s 0x%08x\n", name,
120 result ? "TRUE " : "FALSE", acc_granted);
126 case PRINTER_ACE_PRINT: {
127 if (!result || acc_granted !=
129 printf("FAIL: user %s can't print\n",
136 case PRINTER_ACE_FULL_CONTROL: {
138 if (!result || acc_granted !=
139 PRINTER_ACE_FULL_CONTROL) {
140 printf("FAIL: user %s doesn't "
141 "have full control\n",
146 if (result || acc_granted != 0) {
147 printf("FAIL: user %s has full "
154 case PRINTER_ACE_MANAGE_DOCUMENTS: {
155 if (j == 1 || j == 2) {
156 if (!result || acc_granted !=
157 PRINTER_ACE_MANAGE_DOCUMENTS) {
158 printf("FAIL: user %s can't "
159 "manage documents\n",
164 if (result || acc_granted != 0) {
165 printf("FAIL: user %s can "
166 "manage documents\n",
175 printf("FAIL: internal error\n");
184 int main(int argc, char **argv)
188 generate_wellknown_sids();
190 /* Create security descriptor */
192 sd = build_sec_desc(acl_printer, NULL, NULL_SID, NULL_SID);
195 printf("FAIL: could not build security descriptor\n");