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