3 * Bacula Director -- User Agent Access Control List (ACL) handling
5 * Kern Sibbald, January MMIV
11 Copyright (C) 2004-2006 Kern Sibbald
13 This program is free software; you can redistribute it and/or
14 modify it under the terms of the GNU General Public License
15 version 2 as amended with additional clauses defined in the
16 file LICENSE in the main source directory.
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 the file LICENSE for additional details.
29 * Check if access is permitted to item in acl
31 bool acl_access_ok(UAContext *ua, int acl, char *item)
33 return acl_access_ok(ua, acl, item, strlen(item));
37 /* This version expects the length of the item which we must check. */
38 bool acl_access_ok(UAContext *ua, int acl, char *item, int len)
41 /* If no console resource => default console and all is permitted */
43 Dmsg0(1400, "Root cons access OK.\n");
44 return true; /* No cons resource -> root console OK for everything */
47 alist *list = ua->cons->ACL_lists[acl];
48 if (!list) { /* empty list */
49 if (len == 0 && acl == Where_ACL) {
50 return true; /* Empty list for Where => empty where */
52 return false; /* List empty, reject everything */
55 /* Special case *all* gives full access */
56 if (list->size() == 1 && strcasecmp("*all*", (char *)list->get(0)) == 0) {
60 /* Search list for item */
61 for (int i=0; i<list->size(); i++) {
62 if (strcasecmp(item, (char *)list->get(i)) == 0) {
63 Dmsg3(1400, "ACL found %s in %d %s\n", item, acl, (char *)list->get(i));