]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/dird/ua_acl.c
cb184a0a88253506bc44f4be814e0bf602230afc
[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 /*
11    Copyright (C) 2004 Kern Sibbald and John Walker
12
13    This program is free software; you can redistribute it and/or
14    modify it under the terms of the GNU General Public License as
15    published by the Free Software Foundation; either version 2 of
16    the License, or (at your option) any later version.
17
18    This program is distributed in the hope that it will be useful,
19    but WITHOUT ANY WARRANTY; without even the implied warranty of
20    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21    General Public License for more details.
22
23    You should have received a copy of the GNU General Public
24    License along with this program; if not, write to the Free
25    Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
26    MA 02111-1307, USA.
27
28  */
29
30 #include "bacula.h"
31 #include "dird.h"
32
33 /*  
34  * Check if access is permitted to item in acl    
35  */
36 bool acl_access_ok(UAContext *ua, int acl, char *item)
37 {
38    return acl_access_ok(ua, acl, item, strlen(item));
39 }
40
41
42 bool acl_access_ok(UAContext *ua, int acl, char *item, int len)
43 {
44
45    /* If no console resource => default console and all is permitted */
46    if (!ua->cons) {
47       Dmsg0(400, "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) {
53       return false;                   /* List empty, reject everything */
54    }
55
56    /* Special case *all* gives full access */
57    if (list->size() == 1 && strcasecmp("*all*", (char *)list->get(0)) == 0) {
58       return true;
59    }
60
61    /* Search list for item */
62    for (int i=0; i<list->size(); i++) {
63       if (strncasecmp(item, (char *)list->get(i), len) == 0) {
64          Dmsg3(400, "Found %s in %d %s\n", item, acl, (char *)list->get(i));
65          return true;
66       }
67    }
68    return false;
69 }