]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/dird/ua_acl.c
1a386fd75b2570e426efe214c05426b6c3a1ce8e
[bacula/bacula] / bacula / src / dird / ua_acl.c
1 /*
2    Bacula® - The Network Backup Solution
3
4    Copyright (C) 2004-2008 Free Software Foundation Europe e.V.
5
6    The main author of Bacula is Kern Sibbald, with contributions from
7    many others, a complete list can be found in the file AUTHORS.
8    This program is Free Software; you can redistribute it and/or
9    modify it under the terms of version three of the GNU Affero General Public
10    License as published by the Free Software Foundation and included
11    in the file LICENSE.
12
13    This program is distributed in the hope that it will be useful, but
14    WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16    General Public License for more details.
17
18    You should have received a copy of the GNU Affero General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21    02110-1301, USA.
22
23    Bacula® is a registered trademark of Kern Sibbald.
24    The licensor of Bacula is the Free Software Foundation Europe
25    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
26    Switzerland, email:ftf@fsfeurope.org.
27 */
28 /*
29  *
30  *   Bacula Director -- User Agent Access Control List (ACL) handling
31  *
32  *     Kern Sibbald, January MMIV
33  *
34  *   Version  $Id$
35  */
36
37 #include "bacula.h"
38 #include "dird.h"
39
40 /*
41  * Check if access is permitted to item in acl
42  */
43 bool acl_access_ok(UAContext *ua, int acl, const char *item)
44 {
45    return acl_access_ok(ua, acl, item, strlen(item));
46 }
47
48
49 /* This version expects the length of the item which we must check. */
50 bool acl_access_ok(UAContext *ua, int acl, const char *item, int len)
51 {
52    /* The resource name contains nasty characters */
53    if (acl != Where_ACL && !is_name_valid(item, NULL)) {
54       Dmsg1(1400, "Access denied for item=%s\n", item);
55       return false;
56    }
57
58    /* If no console resource => default console and all is permitted */
59    if (!ua->cons) {
60       Dmsg0(1400, "Root cons access OK.\n");
61       return true;                    /* No cons resource -> root console OK for everything */
62    }
63
64    alist *list = ua->cons->ACL_lists[acl];
65    if (!list) {                       /* empty list */
66       if (len == 0 && acl == Where_ACL) {
67          return true;                 /* Empty list for Where => empty where */
68       }
69       return false;                   /* List empty, reject everything */
70    }
71
72    /* Special case *all* gives full access */
73    if (list->size() == 1 && strcasecmp("*all*", (char *)list->get(0)) == 0) {
74       return true;
75    }
76
77    /* Search list for item */
78    for (int i=0; i<list->size(); i++) {
79       if (strcasecmp(item, (char *)list->get(i)) == 0) {
80          Dmsg3(1400, "ACL found %s in %d %s\n", item, acl, (char *)list->get(i));
81          return true;
82       }
83    }
84    return false;
85 }