2 Bacula® - The Network Backup Solution
4 Copyright (C) 2004-2014 Free Software Foundation Europe e.V.
6 The main author of Bacula is Kern Sibbald, with contributions from many
7 others, a complete list can be found in the file AUTHORS.
9 You may use this file and others of this release according to the
10 license defined in the LICENSE file, which includes the Affero General
11 Public License, v3.0 ("AGPLv3") and some additional permissions and
12 terms pursuant to its AGPLv3 Section 7.
14 Bacula® is a registered trademark of Kern Sibbald.
18 * Bacula Director -- User Agent Access Control List (ACL) handling
20 * Kern Sibbald, January MMIV
28 * Check if access is permitted to item in acl
30 bool acl_access_ok(UAContext *ua, int acl, const char *item)
32 return acl_access_ok(ua, acl, item, strlen(item));
36 /* This version expects the length of the item which we must check. */
37 bool acl_access_ok(UAContext *ua, int acl, const char *item, int len)
39 /* The resource name contains nasty characters */
40 if (acl != Where_ACL && !is_name_valid(item, NULL)) {
41 Dmsg1(1400, "Access denied for item=%s\n", item);
45 /* If no console resource => default console and all is permitted */
46 if (!ua || !ua->cons) {
47 Dmsg0(1400, "Root cons access OK.\n");
48 return true; /* No cons resource -> root console OK for everything */
51 alist *list = ua->cons->ACL_lists[acl];
52 if (!list) { /* empty list */
53 if (len == 0 && acl == Where_ACL) {
54 return true; /* Empty list for Where => empty where */
56 return false; /* List empty, reject everything */
59 /* Special case *all* gives full access */
60 if (list->size() == 1 && strcasecmp("*all*", (char *)list->get(0)) == 0) {
64 /* Search list for item */
65 for (int i=0; i<list->size(); i++) {
66 if (strcasecmp(item, (char *)list->get(i)) == 0) {
67 Dmsg3(1400, "ACL found %s in %d %s\n", item, acl, (char *)list->get(i));
75 * Return true if we have a restriction on the ACL
76 * false if there is no ACL restriction
78 bool have_restricted_acl(UAContext *ua, int acl)
82 /* If no console resource => default console and all is permitted */
83 if (!ua || !ua->cons) {
84 return false; /* no restrictions */
87 list = ua->cons->ACL_lists[acl];
91 /* Special case *all* gives full access */
92 if (list->size() == 1 && strcasecmp("*all*", (char *)list->get(0)) == 0) {
95 return list->size() > 0;