]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/dird/ua_acl.c
1b271bb2b0efcf00a57496fbcf7c671e017bc9d6
[bacula/bacula] / bacula / src / dird / ua_acl.c
1 /*
2    Bacula(R) - The Network Backup Solution
3
4    Copyright (C) 2000-2015 Kern Sibbald
5
6    The original author of Bacula is Kern Sibbald, with contributions
7    from many others, a complete list can be found in the file AUTHORS.
8
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.
13
14    This notice must be preserved when any source code is 
15    conveyed and/or propagated.
16
17    Bacula(R) is a registered trademark of Kern Sibbald.
18 */
19 /*
20  *
21  *   Bacula Director -- User Agent Access Control List (ACL) handling
22  *
23  *     Kern Sibbald, January MMIV
24  *
25  */
26
27 #include "bacula.h"
28 #include "dird.h"
29
30 /*
31  * Check if access is permitted to item in acl
32  */
33 bool acl_access_ok(UAContext *ua, int acl, const char *item)
34 {
35    return acl_access_ok(ua, acl, item, strlen(item));
36 }
37
38
39 /* This version expects the length of the item which we must check. */
40 bool acl_access_ok(UAContext *ua, int acl, const char *item, int len)
41 {
42    /* The resource name contains nasty characters */
43    if (acl != Where_ACL && !is_name_valid(item, NULL)) {
44       Dmsg1(1400, "Access denied for item=%s\n", item);
45       return false;
46    }
47
48    /* If no console resource => default console and all is permitted */
49    if (!ua || !ua->cons) {
50       Dmsg0(1400, "Root cons access OK.\n");
51       return true;                    /* No cons resource -> root console OK for everything */
52    }
53
54    alist *list = ua->cons->ACL_lists[acl];
55    if (!list) {                       /* empty list */
56       if (len == 0 && acl == Where_ACL) {
57          return true;                 /* Empty list for Where => empty where */
58       }
59       return false;                   /* List empty, reject everything */
60    }
61
62    /* Special case *all* gives full access */
63    if (list->size() == 1 && strcasecmp("*all*", (char *)list->get(0)) == 0) {
64       return true;
65    }
66
67    /* Search list for item */
68    for (int i=0; i<list->size(); i++) {
69       if (strcasecmp(item, (char *)list->get(i)) == 0) {
70          Dmsg3(1400, "ACL found %s in %d %s\n", item, acl, (char *)list->get(i));
71          return true;
72       }
73    }
74    return false;
75 }
76
77 /*
78  * Return  true if we have a restriction on the ACL
79  *        false if there is no ACL restriction
80  */
81 bool have_restricted_acl(UAContext *ua, int acl)
82 {
83    alist *list;
84
85    /* If no console resource => default console and all is permitted */
86    if (!ua || !ua->cons) {
87       return false;       /* no restrictions */
88    }
89
90    list = ua->cons->ACL_lists[acl];
91    if (!list) {
92       return false;
93    }
94    /* Special case *all* gives full access */
95    if (list->size() == 1 && strcasecmp("*all*", (char *)list->get(0)) == 0) {
96       return false;
97    }
98    return list->size() > 0;
99 }