]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/dird/ua_acl.c
kes Print the Volume purged message only for real jobs to keep
[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-2006 Kern Sibbald
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
15    version 2 as amended with additional clauses defined in the
16    file LICENSE in the main source directory.
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 
21    the file LICENSE for additional details.
22
23  */
24
25 #include "bacula.h"
26 #include "dird.h"
27
28 /*
29  * Check if access is permitted to item in acl
30  */
31 bool acl_access_ok(UAContext *ua, int acl, char *item)
32 {
33    return acl_access_ok(ua, acl, item, strlen(item));
34 }
35
36
37 /* This version expects the length of the item which we must check. */
38 bool acl_access_ok(UAContext *ua, int acl, char *item, int len)
39 {
40
41    /* If no console resource => default console and all is permitted */
42    if (!ua->cons) {
43       Dmsg0(1400, "Root cons access OK.\n");
44       return true;                    /* No cons resource -> root console OK for everything */
45    }
46
47    alist *list = ua->cons->ACL_lists[acl];
48    if (!list) {                       /* empty list */
49       if (len == 0 && acl == Where_ACL) {
50          return true;                 /* Empty list for Where => empty where */
51       }
52       return false;                   /* List empty, reject everything */
53    }
54
55    /* Special case *all* gives full access */
56    if (list->size() == 1 && strcasecmp("*all*", (char *)list->get(0)) == 0) {
57       return true;
58    }
59
60    /* Search list for item */
61    for (int i=0; i<list->size(); i++) {
62       if (strcasecmp(item, (char *)list->get(i)) == 0) {
63          Dmsg3(1400, "ACL found %s in %d %s\n", item, acl, (char *)list->get(i));
64          return true;
65       }
66    }
67    return false;
68 }