]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
Add RBCLIENT ACL type to query both RCLIENT and BCLIENT
authorEric Bollengier <eric@baculasystems.com>
Mon, 20 Mar 2023 16:50:40 +0000 (17:50 +0100)
committerEric Bollengier <eric@baculasystems.com>
Tue, 2 May 2023 07:07:18 +0000 (09:07 +0200)
bacula/src/cats/bdb.h
bacula/src/cats/sql.c
bacula/src/dird/ua_cmds.c

index 03f0cfd136efe4f2be002aa08a6bae2e5f1daacc..cfd2a76ed1fbe25b2226465e6bd6c07732f7917f 100644 (file)
@@ -39,6 +39,7 @@ typedef enum
    DB_ACL_FILESET,
    DB_ACL_RCLIENT,
    DB_ACL_BCLIENT,
+   DB_ACL_RBCLIENT,
    DB_ACL_PATH,
    DB_ACL_LOG,
    DB_ACL_LAST                  /* Keep last */
@@ -157,7 +158,7 @@ public:
    /* Used during the initialization, the UA code can call this function
     * foreach kind of ACL
     */
-   void  set_acl(JCR *jcr, DB_ACL_t type, alist *l, alist *l2=NULL); 
+   void  set_acl(JCR *jcr, DB_ACL_t type, alist *l, alist *l2=NULL, alist *l3=NULL); 
 
    /* Get the SQL string that corresponds to the Console ACL for Pool, Job,
     * Client, ... 
index 558e35d6ddaade4ed3578bc8b265b17110a1ca0c..7a1c49e394dfefd0b4c0e851525569de3d9b9519 100644 (file)
@@ -252,6 +252,9 @@ char *BDB::get_acls(int tables, bool where /* use WHERE or AND */)
    return acl_where;
 }
 
+/* Get the list of the JobId that are accessible for this console
+ * Usually, this function is called in a restore context
+ */
 char *BDB::bdb_get_jobids(const char *jobids, POOLMEM **ret, bool append)
 {
    if (!ret || !*ret) {
@@ -269,10 +272,10 @@ char *BDB::bdb_get_jobids(const char *jobids, POOLMEM **ret, bool append)
    bdb_lock();
    /* Get optional filters for the SQL query */
    const char *where = get_acls(DB_ACL_BIT(DB_ACL_JOB) |
-                                DB_ACL_BIT(DB_ACL_CLIENT) |
+                                DB_ACL_BIT(DB_ACL_RCLIENT) | // Clients where we can restore
                                 DB_ACL_BIT(DB_ACL_FILESET), false);
 
-   const char *join = *where ? get_acl_join_filter(DB_ACL_BIT(DB_ACL_CLIENT)  |
+   const char *join = *where ? get_acl_join_filter(DB_ACL_BIT(DB_ACL_RCLIENT)  |
                                                    DB_ACL_BIT(DB_ACL_FILESET)) : "";
    /* No filters, no need to run the query */
    if (!*where && !*join) {
@@ -314,7 +317,11 @@ char *BDB::get_acl_join_filter(int tables)
       Mmsg(tmp, " JOIN Job USING (JobId) ");
       pm_strcat(acl_join, tmp);
    }
-   if (tables & (DB_ACL_BIT(DB_ACL_CLIENT) | DB_ACL_BIT(DB_ACL_RCLIENT) | DB_ACL_BIT(DB_ACL_BCLIENT))) {
+   if (tables & (DB_ACL_BIT(DB_ACL_CLIENT)  |
+                 DB_ACL_BIT(DB_ACL_RCLIENT) |
+                 DB_ACL_BIT(DB_ACL_BCLIENT) |
+                 DB_ACL_BIT(DB_ACL_RBCLIENT)))
+   {
       Mmsg(tmp, " JOIN Client USING (ClientId) ");
       pm_strcat(acl_join, tmp);
    }
@@ -365,7 +372,7 @@ const char *BDB::get_acl(DB_ACL_t type, bool where /* display WHERE or AND */)
 }
 
 /* Keep UAContext ACLs in our structure for further SQL queries */
-void BDB::set_acl(JCR *jcr, DB_ACL_t type, alist *list, alist *list2)
+void BDB::set_acl(JCR *jcr, DB_ACL_t type, alist *list, alist *list2, alist *list3)
 {
    const char *key=NULL;
    const char *keyid=NULL;
@@ -380,6 +387,11 @@ void BDB::set_acl(JCR *jcr, DB_ACL_t type, alist *list, alist *list2)
       return;
    }
 
+   /* If the list is present, but we authorize everything */
+   if (list3 && list3->size() == 1 && strcasecmp((char*)list3->get(0), "*all*") == 0) {
+      return;
+   }
+
    POOLMEM *tmp = get_pool_memory(PM_FNAME);
    POOLMEM *where = get_pool_memory(PM_FNAME);
 
@@ -394,6 +406,7 @@ void BDB::set_acl(JCR *jcr, DB_ACL_t type, alist *list, alist *list2)
    case DB_ACL_BCLIENT:
    case DB_ACL_CLIENT:
    case DB_ACL_RCLIENT:
+   case DB_ACL_RBCLIENT:
       key = "Client.Name";
       break;
 
@@ -424,6 +437,11 @@ void BDB::set_acl(JCR *jcr, DB_ACL_t type, alist *list, alist *list2)
          merged_list->append(elt);
       }
    }
+   if (list3) {
+      foreach_alist(elt, list3) {
+         merged_list->append(elt);
+      }
+   }
    escape_acl_list(jcr, key, &tmp, merged_list);
    delete merged_list;
 
index 6feffd20ee345093da5a08717208ce84c36b842a..8d5c9d638efd738314eb07c5fad818d513c4e325 100644 (file)
@@ -3304,6 +3304,11 @@ bool open_db(UAContext *ua)
       ua->db->set_acl(ua->jcr, DB_ACL_BCLIENT,
                       ua->cons->ACL_lists[Client_ACL],
                       ua->cons->ACL_lists[BackupClient_ACL]);
+
+      ua->db->set_acl(ua->jcr, DB_ACL_RBCLIENT,
+                      ua->cons->ACL_lists[Client_ACL],
+                      ua->cons->ACL_lists[BackupClient_ACL],
+                      ua->cons->ACL_lists[RestoreClient_ACL]);
    }
    if (!ua->api) {
       ua->send_msg(_("Using Catalog \"%s\"\n"), ua->catalog->name());