]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
BEE Backport bacula/src/dird/ua_acl.c
authorEric Bollengier <eric@baculasystems.com>
Fri, 24 Apr 2020 16:00:48 +0000 (18:00 +0200)
committerEric Bollengier <eric@baculasystems.com>
Thu, 29 Apr 2021 08:44:17 +0000 (10:44 +0200)
This commit is the result of the squash of the following main commits:

Author: Alain Spineux <alain@baculasystems.com>
Date:   Tue May 21 18:32:30 2019 +0200

    re-activate command "show console" and display ACLs

    - "root" console can display any console resource
    - restricted console can only display its own ressource
    - Display all ACLs
      - use the name of the ACL define in the RES_ITEM

Author: Eric Bollengier <eric@baculasystems.com>
Date:   Mon Jun 18 15:40:30 2018 +0200

    Allow glob type expression in Console ACL lists

Author: Eric Bollengier <eric@baculasystems.com>
Date:   Thu Jun 30 20:53:53 2016 +0200

    Add new RestoreClientAcl/BackupClientAcl console directives

Author: Kern Sibbald <kern@sibbald.com>
Date:   Sun Sep 23 14:31:40 2012 +0200

    Add first cut bconsjson and bdirjson

bacula/src/dird/ua_acl.c

index c69d495bc17fd8d8b208270015d0cd54ece74ea7..f6a80b89c5e5b46fed3afddf1078b2e30e131ad8 100644 (file)
    Bacula(R) is a registered trademark of Kern Sibbald.
 */
 /*
+ *
  *   Bacula Director -- User Agent Access Control List (ACL) handling
  *
  *     Kern Sibbald, January MMIV
+ *
  */
 
 #include "bacula.h"
@@ -54,13 +56,25 @@ bool acl_access_client_ok(UAContext *ua, const char *name, int32_t jobtype)
    return false;
 }
 
-
+bool acl_access_console_ok(UAContext *ua, const char *name)
+{
+   /* If no console resource => default console and all is permitted */
+   if (!ua || !ua->cons) {
+      Dmsg0(1400, "Root cons access OK.\n");
+      return true;                    /* No cons resource -> root console OK for everything */
+   }
+   /* allow access to its own console resource only */
+   if (strcmp(ua->cons->name(), name)==0) {
+      return true;
+   }
+   return false;
+}
 
 /* This version expects the length of the item which we must check. */
 bool acl_access_ok(UAContext *ua, int acl, const char *item, int len)
 {
    /* The resource name contains nasty characters */
-   if (acl != Where_ACL && !is_name_valid(item, NULL)) {
+   if (acl != Where_ACL && !is_name_valid(item, NULL, EXTRA_VALID_RESOURCE_CHAR_GLOB)) {
       Dmsg1(1400, "Access denied for item=%s\n", item);
       return false;
    }
@@ -86,7 +100,7 @@ bool acl_access_ok(UAContext *ua, int acl, const char *item, int len)
 
    /* Search list for item */
    for (int i=0; i<list->size(); i++) {
-      if (strcasecmp(item, (char *)list->get(i)) == 0) {
+      if (fnmatch((char *)list->get(i), item, 0) == 0) {
          Dmsg3(1400, "ACL found %s in %d %s\n", item, acl, (char *)list->get(i));
          return true;
       }