]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/dird/ua_acl.c
Backport from BEE
[bacula/bacula] / bacula / src / dird / ua_acl.c
1 /*
2    Bacula® - The Network Backup Solution
3
4    Copyright (C) 2004-2014 Free Software Foundation Europe e.V.
5
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.
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    Bacula® is a registered trademark of Kern Sibbald.
15 */
16 /*
17  *
18  *   Bacula Director -- User Agent Access Control List (ACL) handling
19  *
20  *     Kern Sibbald, January MMIV
21  *
22  */
23
24 #include "bacula.h"
25 #include "dird.h"
26
27 /*
28  * Check if access is permitted to item in acl
29  */
30 bool acl_access_ok(UAContext *ua, int acl, const char *item)
31 {
32    return acl_access_ok(ua, acl, item, strlen(item));
33 }
34
35
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)
38 {
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);
42       return false;
43    }
44
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 */
49    }
50
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 */
55       }
56       return false;                   /* List empty, reject everything */
57    }
58
59    /* Special case *all* gives full access */
60    if (list->size() == 1 && strcasecmp("*all*", (char *)list->get(0)) == 0) {
61       return true;
62    }
63
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));
68          return true;
69       }
70    }
71    return false;
72 }
73
74 /*
75  * Return  true if we have a restriction on the ACL
76  *        false if there is no ACL restriction
77  */
78 bool have_restricted_acl(UAContext *ua, int acl)
79 {
80    alist *list;
81
82    /* If no console resource => default console and all is permitted */
83    if (!ua || !ua->cons) {
84       return false;       /* no restrictions */
85    }
86
87    list = ua->cons->ACL_lists[acl];
88    if (!list) {
89       return false;
90    }
91    /* Special case *all* gives full access */
92    if (list->size() == 1 && strcasecmp("*all*", (char *)list->get(0)) == 0) {
93       return false;
94    }
95    return list->size() > 0;
96 }