]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
Add VolumeEncrypted field to the catalog
authorAlain Spineux <alain@baculasystems.com>
Mon, 7 Nov 2022 11:07:18 +0000 (12:07 +0100)
committerEric Bollengier <eric@baculasystems.com>
Thu, 14 Sep 2023 11:57:00 +0000 (13:57 +0200)
- the goal is to not append encrypted data to volumes that that are not
  encryption ready ( that are BB02 or have not been label with an
  "encrypted" capable label )

24 files changed:
bacula/src/baconfig.h
bacula/src/cats/cats.h
bacula/src/cats/make_mysql_tables.in
bacula/src/cats/make_postgresql_tables.in
bacula/src/cats/make_sqlite3_tables.in
bacula/src/cats/sql_create.c
bacula/src/cats/sql_find.c
bacula/src/cats/sql_get.c
bacula/src/cats/sql_list.c
bacula/src/cats/sql_update.c
bacula/src/cats/update_mysql_tables.in
bacula/src/cats/update_postgresql_tables.in
bacula/src/dird/catreq.c
bacula/src/dird/next_vol.c
bacula/src/dird/protos.h
bacula/src/dird/ua_label.c
bacula/src/dird/ua_output.c
bacula/src/dird/ua_status.c
bacula/src/stored/askdir.c
bacula/src/stored/dev.c
bacula/src/stored/dev.h
bacula/src/stored/dircmd.c
bacula/src/stored/label.c
bacula/src/stored/record.h

index 0431d7b425d392bccc0e434f64c2720358369365..00da234d6e98c8d39768f75a66ac265c32e695ec 100644 (file)
@@ -489,6 +489,7 @@ void b_memset(const char *file, int line, void *mem, int val, size_t num);
 #define Pmsg12(lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12) p_msg(__FILE__,__LINE__,lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12)
 #define Pmsg13(lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13) p_msg(__FILE__,__LINE__,lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13)
 #define Pmsg14(lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14) p_msg(__FILE__,__LINE__,lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14)
+#define Pmsg15(lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15) p_msg(__FILE__,__LINE__,lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15)
 
 
 /** Daemon Error Messages that are delivered according to the message resource */
index 2bdbfcff4045b4fca45a22d0eb0c83bede538bf4..241fa8ddd6ef6bbda7e985cc1e9222a92bfd5fab 100644 (file)
@@ -458,8 +458,9 @@ public:
    uint32_t MaxVolJobs;               /* Max Jobs on Volume */
    uint32_t MaxVolFiles;              /* Max files on Volume */
    int32_t  Recycle;                  /* recycle yes/no */
-   int32_t  Protected;                  /* Protected yes/no */
+   int32_t  Protected;                /* Protected yes/no */
    int32_t  UseProtect;               /* Use Protected feature yes/no */
+   int32_t  VolEncrypted;             /* Volume is encrypted */
    int32_t  Slot;                     /* slot in changer */
    int32_t  Enabled;                  /* 0=disabled, 1=enabled, 2=archived */
    int32_t  InChanger;                /* Volume currently in changer */
index d54c04ad99697c536e70bc1c43d9c380378d70a1..5b29d08c5fa5d66e833cf5db60d4bdd56a11b6f2 100644 (file)
@@ -481,6 +481,7 @@ CREATE TABLE Media (
    Comment BLOB,
    Protected TINYINT DEFAULT 0,
    UseProtect TINYINT DEFAULT 0,
+   VolEncrypted TINYINT DEFAULT 0,
    PRIMARY KEY(MediaId),
    UNIQUE (VolumeName(128)),
    INDEX (PoolId),
index ac26f447993a20faa7fbdaa40a8ab425c4016f4e..21d18550201b27d90657ae6cdf3c920ed5021842 100644 (file)
@@ -420,6 +420,7 @@ CREATE TABLE media
     comment          text,
     protected         smallint    default 0,
     useprotect        smallint    default 0,
+    volencrypted      smallint    default 0,
     primary key (mediaid)
 );
 
index 8962799f7890f536cc474340e4ea2d7a86b954a8..5987d18d49ff8e5e525e643aaba698270412e49d 100644 (file)
@@ -427,6 +427,7 @@ CREATE TABLE Media (
    Comment TEXT,
    Protected TINYINT DEFAULT 0,
    UseProtect TINYINT DEFAULT 0,
+   VolEncrypted TINYINT DEFAULT 0,
    PRIMARY KEY(MediaId)
    );
 
index f0d32219f258672eecb44e62bbb5ad4d073b80b8..4b7b8e0eac40cdaaa0c04f9729377d54313b3141 100644 (file)
@@ -442,9 +442,10 @@ int BDB::bdb_create_media_record(JCR *jcr, MEDIA_DBR *mr)
 "VolStatus,Slot,VolBytes,InChanger,VolReadTime,VolWriteTime,VolType,"
 "VolParts,VolCloudParts,LastPartBytes,"
 "EndFile,EndBlock,LabelType,StorageId,DeviceId,LocationId,"
-"ScratchPoolId,RecyclePoolId,Enabled,ActionOnPurge,CacheRetention,UseProtect,Protected)"
+"ScratchPoolId,RecyclePoolId,Enabled,ActionOnPurge,CacheRetention,UseProtect,"
+"Protected,VolEncrypted)"
 "VALUES ('%s','%s',0,%lu,%s,%s,%ld,%s,%s,%lu,%lu,'%s',%ld,%s,%ld,%s,%s,%ld,"
-        "%ld,%ld,'%s',%ld,%ld,%ld,%s,%s,%s,%s,%s,%ld,%ld,%s,%ld,%ld)",
+        "%ld,%ld,'%s',%ld,%ld,%ld,%s,%s,%s,%s,%s,%ld,%ld,%s,%ld,%ld,%ld)",
           esc_name,
           esc_mtype, mr->PoolId,
           edit_uint64(mr->MaxVolBytes,ed1),
@@ -472,11 +473,12 @@ int BDB::bdb_create_media_record(JCR *jcr, MEDIA_DBR *mr)
           edit_int64(mr->LocationId, ed11),
           edit_int64(mr->ScratchPoolId, ed12),
           edit_int64(mr->RecyclePoolId, ed13),
-          mr->Enabled, 
+          mr->Enabled,
           mr->ActionOnPurge,
           edit_uint64(mr->CacheRetention, ed14),
           mr->UseProtect,
-          mr->Protected
+          mr->Protected,
+          mr->VolEncrypted
           );
 
 
index ebe5e98354c325f4824598cc1975cf3d15740d77..5173d88ec44cb9cfc425636b8e98f91176e5b909 100644 (file)
@@ -426,11 +426,13 @@ int BDB::bdb_find_next_volume(JCR *jcr, int item, bool InChanger, MEDIA_DBR *mr)
          "LabelType,LabelDate,StorageId,"
          "Enabled,LocationId,RecycleCount,InitialWrite,"
          "ScratchPoolId,RecyclePoolId,VolReadTime,VolWriteTime,ActionOnPurge,CacheRetention "
+         "VolEncrypted "
          "FROM Media WHERE PoolId=%s AND MediaType='%s' "
          " AND (VolStatus IN ('Full', 'Append', 'Used') OR (VolStatus IN ('Recycle', 'Purged', 'Used') AND Recycle=1)) "
          " AND Enabled=1 "
+         " AND VolEncrypted=%d "
          "ORDER BY LastWritten LIMIT 1",
-         edit_int64(mr->PoolId, ed1), esc_type);
+         edit_int64(mr->PoolId, ed1), esc_type, mr->VolEncrypted);
      item = 1;
    } else {
       POOL_MEM changer(PM_FNAME);
@@ -483,15 +485,17 @@ int BDB::bdb_find_next_volume(JCR *jcr, int item, bool InChanger, MEDIA_DBR *mr)
          "EndFile,EndBlock,VolType,VolParts,VolCloudParts,LastPartBytes,"
          "LabelType,LabelDate,StorageId,"
          "Enabled,LocationId,RecycleCount,InitialWrite,"
-         "ScratchPoolId,RecyclePoolId,VolReadTime,VolWriteTime,ActionOnPurge,CacheRetention "
+         "ScratchPoolId,RecyclePoolId,VolReadTime,VolWriteTime,ActionOnPurge,CacheRetention,"
+         "VolEncrypted "
          "FROM Media WHERE PoolId=%s AND MediaType='%s' AND Enabled=1 "
          "AND VolStatus='%s' "
+         "AND VolEncrypted=%d "
          "%s "
          "%s "
          "%s "
          "%s LIMIT %d",
          edit_int64(mr->PoolId, ed1), esc_type,
-         esc_status,
+         esc_status, mr->VolEncrypted,
          voltype.c_str(),
          changer.c_str(), exclude.c_str(), order, item);
    }
@@ -573,6 +577,7 @@ int BDB::bdb_find_next_volume(JCR *jcr, int item, bool InChanger, MEDIA_DBR *mr)
    mr->VolWriteTime = str_to_int64(row[39]);
    mr->ActionOnPurge = str_to_int64(row[40]);
    mr->CacheRetention = str_to_int64(row[41]);
+   mr->VolEncrypted = str_to_int64(row[42]);
 
    sql_free_result();
 
index 2380ae6ab80c5977c189e855f9cf0632f83de5f8..767a929f83dad85522bbe9fa4c44f80e16d1a515 100644 (file)
@@ -1370,8 +1370,9 @@ bool BDB::bdb_get_media_record(JCR *jcr, MEDIA_DBR *mr)
          "EndFile,EndBlock,VolType,VolParts,VolCloudParts,LastPartBytes,"
          "LabelType,LabelDate,StorageId,"
          "Enabled,LocationId,RecycleCount,InitialWrite,"
-         "ScratchPoolId,RecyclePoolId,VolReadTime,VolWriteTime,ActionOnPurge,CacheRetention,Pool.Name,Protected,UseProtect "
-         "FROM Media JOIN Pool USING (PoolId) WHERE MediaId=%s",
+         "ScratchPoolId,RecyclePoolId,VolReadTime,VolWriteTime,ActionOnPurge,"
+         "CacheRetention,Pool.Name,Protected,UseProtect,VolEncrypted "
+         "FROM Media WHERE MediaId=%s",
          edit_int64(mr->MediaId, ed1));
    } else {                           /* find by name */
       bdb_escape_string(jcr, esc, mr->VolumeName, strlen(mr->VolumeName));
@@ -1383,8 +1384,9 @@ bool BDB::bdb_get_media_record(JCR *jcr, MEDIA_DBR *mr)
          "EndFile,EndBlock,VolType,VolParts,VolCloudParts,LastPartBytes,"
          "LabelType,LabelDate,StorageId,"
          "Enabled,LocationId,RecycleCount,InitialWrite,"
-         "ScratchPoolId,RecyclePoolId,VolReadTime,VolWriteTime,ActionOnPurge,CacheRetention,Pool.Name,Protected,UseProtect "
-         "FROM Media JOIN Pool USING (PoolId) WHERE VolumeName='%s'", esc);
+         "ScratchPoolId,RecyclePoolId,VolReadTime,VolWriteTime,ActionOnPurge,"
+         "CacheRetention,Pool.Name,Protected,UseProtect,VolEncrypted "
+         "FROM Media WHERE VolumeName='%s'", esc);
    }
 
    if (QueryDB(jcr, cmd)) {
@@ -1449,8 +1451,9 @@ bool BDB::bdb_get_media_record(JCR *jcr, MEDIA_DBR *mr)
             mr->ActionOnPurge = str_to_int32(row[43]);
             mr->CacheRetention = str_to_int64(row[44]);
             bstrncpy(mr->Pool, row[45], sizeof(mr->Pool));
-            mr->Protected = str_to_int64(row[45]);
-            mr->UseProtect = str_to_int64(row[46]);
+            mr->Protected = str_to_int64(row[46]);
+            mr->UseProtect = str_to_int64(row[47]);
+            mr->VolEncrypted = str_to_int64(row[48]);
 
             ok = true;
          }
index 552d046ef9111eeac7cf4eb7788795a4076bb75d..b834fa6372dc396ad2819c8729d28a44bc7e7ed7 100644 (file)
@@ -490,7 +490,7 @@ void BDB::bdb_list_media_records(JCR *jcr, MEDIA_DBR *mdbr,
             "EndFile,EndBlock,VolType,Media.LabelType,StorageId,DeviceId,"
             "MediaAddressing,VolReadTime,VolWriteTime,"
             "LocationId,RecycleCount,InitialWrite,Media.ScratchPoolId,Media.RecyclePoolId, "
-            "Media.ActionOnPurge,%s AS ExpiresIn, Comment, Protected, UseProtect"
+            "Media.ActionOnPurge,%s AS ExpiresIn, Comment, Protected, UseProtect, VolEncrypted"
            " FROM Media %s WHERE Media.VolumeName='%s' %s",
               expiresin,
               join,
@@ -508,7 +508,7 @@ void BDB::bdb_list_media_records(JCR *jcr, MEDIA_DBR *mdbr,
             "EndFile,EndBlock,VolType,Media.LabelType,StorageId,DeviceId,"
             "MediaAddressing,VolReadTime,VolWriteTime,"
             "LocationId,RecycleCount,InitialWrite,Media.ScratchPoolId,Media.RecyclePoolId, "
-            "Media.ActionOnPurge,%s AS ExpiresIn, Comment, Protected, UseProtect"
+            "Media.ActionOnPurge,%s AS ExpiresIn, Comment, Protected, UseProtect, VolEncrypted"
             " FROM Media %s WHERE Media.PoolId=%s %s ORDER BY MediaId",
               expiresin,
               join,
index 2ec63537cfc473d5d11cc0890aca5cbfb4fcb307..2b7f1d5ac3d28bb492a83895761cc661e4743d79 100644 (file)
@@ -408,7 +408,8 @@ int BDB::bdb_update_media_record(JCR *jcr, MEDIA_DBR *mr)
         "LabelType=%d,StorageId=%s,PoolId=%s,VolRetention=%s,VolUseDuration=%s,"
         "MaxVolJobs=%d,MaxVolFiles=%d,Enabled=%d,LocationId=%s,"
         "ScratchPoolId=%s,RecyclePoolId=%s,RecycleCount=%d,Recycle=%d,"
-        "ActionOnPurge=%d,CacheRetention=%s,EndBlock=%u,Protected=%d,UseProtect=%d"
+        "ActionOnPurge=%d,CacheRetention=%s,EndBlock=%u,Protected=%d,"
+        "UseProtect=%d,VolEncrypted=%d"
         " WHERE VolumeName='%s'",
         mr->VolJobs, mr->VolFiles, mr->VolBlocks,
         edit_uint64(mr->VolBytes, ed1),
@@ -435,7 +436,7 @@ int BDB::bdb_update_media_record(JCR *jcr, MEDIA_DBR *mr)
         edit_uint64(mr->RecyclePoolId, ed15),
         mr->RecycleCount,mr->Recycle, mr->ActionOnPurge,
         edit_uint64(mr->CacheRetention, ed16),
-        mr->EndBlock,mr->Protected,mr->UseProtect,
+        mr->EndBlock, mr->Protected, mr->UseProtect, mr->VolEncrypted,
         esc_name);
 
    Dmsg1(dbglevel1, "%s\n", cmd);
index c166d5a14191ab9289b481216cb7ac0219fe4e88..32ac4d3afb42e450b60fdfbf03a60ebcf28aec38 100644 (file)
@@ -707,7 +707,8 @@ CREATE INDEX meta_attachmentemailid ON MetaAttachment (AttachmentEmailId(255));
 
 ALTER TABLE Media
     MODIFY COLUMN Protected TINYINT DEFAULT 0,
-    MODIFY COLUMN UseProtect TINYINT DEFAULT 0;
+    MODIFY COLUMN UseProtect TINYINT DEFAULT 0,
+    MODIFY COLUMN VolEncrypted TINYINT DEFAULT 0;
 
 ALTER TABLE Object
     ADD COLUMN FileIndex integer not null default 0,
index 4e71cd1f8373ca2b3b2f5ff22a99040cf92cdec5..320fbf5ecee6b5317404037de66e8c7c7ab8e69d 100644 (file)
@@ -758,8 +758,9 @@ ALTER TABLE Job ADD COLUMN WriteDevice       text        default ''
 ALTER TABLE Job ADD COLUMN StatusInfo        text        default '';
 ATLER TABLE Job ADD COLUMN Encrypted         int         default 0;
 
-ALTER TABLE Media ADD COLUMN Protected              smallint    default 0;
-ALTER TABLE Media ADD COLUMN IsProtect            smallint    default 0;
+ALTER TABLE Media ADD COLUMN Protected       smallint    default 0;
+ALTER TABLE Media ADD COLUMN UseProtect      smallint    default 0;
+ALTER TABLE Media ADD COLUMN VolEncrypted    smallint    default 0;
 
 INSERT INTO Events (EventsCode, EventsType, EventsTime, EventsDaemon, EventsSource, EventsRef, EventsText) VALUES
   ('DU0001', 'catalog_update', NOW(), '*SHELL*', 'update_bacula_tables', 'pid$$', 'Catalog schema was updated to 1026');
index 8d54068a70bd9386112abb8e7444fc430d62da1e..7c9710378ea21713beae7ecf6ffeabc0cf571e1d 100644 (file)
@@ -38,7 +38,7 @@
  */
 
 /* Requests from the Storage daemon */
-static char Find_media[] = "CatReq JobId=%ld FindMedia=%d pool_name=%127s media_type=%127s vol_type=%d create=%d use_protect=%d\n";
+static char Find_media[] = "CatReq JobId=%ld FindMedia=%d pool_name=%127s media_type=%127s vol_type=%d create=%d use_protect=%d vol_encrypted=%d\n";
 static char Get_Vol_Info[] = "CatReq JobId=%ld GetVolInfo VolName=%127s write=%d\n";
 
 static char Update_media[] = "CatReq JobId=%ld UpdateMedia VolName=%s"
@@ -47,7 +47,7 @@ static char Update_media[] = "CatReq JobId=%ld UpdateMedia VolName=%s"
    " VolErrors=%u VolWrites=%lld MaxVolBytes=%lld EndTime=%lld VolStatus=%10s"
    " Slot=%d relabel=%d InChanger=%d VolReadTime=%llu VolWriteTime=%llu"
    " VolFirstWritten=%lld VolType=%u VolParts=%d VolCloudParts=%d"
-   " LastPartBytes=%lld Enabled=%d Recycle=%d Protected=%d UseProtect=%d\n";
+   " LastPartBytes=%lld Enabled=%d Recycle=%d Protected=%d UseProtect=%d VolEncrypted=%d\n";
 
 static char FileEvent_add[] = "%c %d %127s %127s 0";
 /* Full format when coming from the Verify Job */
@@ -67,7 +67,8 @@ static char OK_media[] = "1000 OK VolName=%s VolJobs=%u VolFiles=%u"
    " MaxVolJobs=%u MaxVolFiles=%u InChanger=%d VolReadTime=%s"
    " VolWriteTime=%s EndFile=%u EndBlock=%u VolType=%u LabelType=%d"
    " MediaId=%s ScratchPoolId=%s VolParts=%d VolCloudParts=%d"
-   " LastPartBytes=%lld Enabled=%d MaxPoolBytes=%s PoolBytes=%s Recycle=%d Protected=%d UseProtect=%d\n";
+   " LastPartBytes=%lld Enabled=%d MaxPoolBytes=%s PoolBytes=%s Recycle=%d"
+   " Protected=%d UseProtect=%d VolEncrypted=%d\n";
 
 static char OK_create[] = "1000 OK CreateJobMedia\n";
 
@@ -120,7 +121,7 @@ static int send_volume_info_to_storage_daemon(JCR *jcr, BSOCK *sd, MEDIA_DBR *mr
       mr->Enabled,
       edit_uint64(pr.MaxPoolBytes, ed11),
       edit_uint64(pr.PoolBytes, ed12),
-      mr->Recycle, mr->Protected, mr->UseProtect);
+      mr->Recycle, mr->Protected, mr->UseProtect, mr->VolEncrypted);
    unbash_spaces(mr->VolumeName);
    Dmsg2(100, "Vol Info for %s: %s", jcr->Job, sd->msg);
    return stat;
@@ -187,8 +188,8 @@ void catalog_request(JCR *jcr, BSOCK *bs)
    utime_t VolFirstWritten;
    utime_t VolLastWritten;
    int n;
-   int can_create=0, use_protect=0;
-   int Enabled, Recycle, Protected, UseProtect;
+   int can_create=0, use_protect=0, vol_encrypted;
+   int Enabled, Recycle, Protected, UseProtect, VolEncrypted;
    JobId_t JobId = 0;
    STORE *wstore = jcr->store_mngr->get_wstore();
 
@@ -212,8 +213,9 @@ void catalog_request(JCR *jcr, BSOCK *bs)
    /*
     * Find next appendable medium for SD
     */
-   n = sscanf(bs->msg, Find_media, &JobId, &index, &pool_name, &mr.MediaType, &mr.VolType, &can_create, &use_protect);
-   if (n == 7) {
+   n = sscanf(bs->msg, Find_media, &JobId, &index, &pool_name, &mr.MediaType,
+         &mr.VolType, &can_create, &use_protect, &vol_encrypted);
+   if (n == 8) {
       POOL_MEM errmsg;
       POOL_DBR pr;
       bstrncpy(pr.Name, pool_name, sizeof(pr.Name));
@@ -225,7 +227,7 @@ void catalog_request(JCR *jcr, BSOCK *bs)
          mr.ScratchPoolId = pr.ScratchPoolId;
          ok = find_next_volume_for_append(jcr, &mr, index,
                                           can_create?fnv_create_vol : fnv_no_create_vol,
-                                          fnv_prune, use_protect, errmsg);
+                                          fnv_prune, use_protect, vol_encrypted, errmsg);
          Dmsg3(050, "find_media ok=%d idx=%d vol=%s\n", ok, index, mr.VolumeName);
       } else {
          /* Report problem finding pool */
@@ -316,8 +318,8 @@ void catalog_request(JCR *jcr, BSOCK *bs)
       &VolLastWritten, &sdmr.VolStatus, &sdmr.Slot, &label, &sdmr.InChanger,
       &sdmr.VolReadTime, &sdmr.VolWriteTime, &VolFirstWritten,
       &sdmr.VolType, &sdmr.VolParts, &sdmr.VolCloudParts,
-      &sdmr.LastPartBytes, &Enabled, &Recycle, &Protected, &UseProtect);
-    if (n == 29) {
+      &sdmr.LastPartBytes, &Enabled, &Recycle, &Protected, &UseProtect, &VolEncrypted);
+    if (n == 30) {
       db_lock(jcr->db);
       Dmsg3(400, "Update media %s oldStat=%s newStat=%s\n", sdmr.VolumeName,
          mr.VolStatus, sdmr.VolStatus);
@@ -401,10 +403,11 @@ void catalog_request(JCR *jcr, BSOCK *bs)
       mr.VolParts      = sdmr.VolParts;
       mr.VolCloudParts = sdmr.VolCloudParts;
       mr.LastPartBytes = sdmr.LastPartBytes;
-      mr.Enabled       = Enabled;  /* byte assignment */
-      mr.Recycle       = Recycle;  /* byte assignment */
-      mr.Protected          = Protected;    /* byte assignment */
-      mr.UseProtect       = UseProtect;  /* byte assignment */
+      mr.Enabled       = Enabled;     /* byte assignment */
+      mr.Recycle       = Recycle;     /* byte assignment */
+      mr.Protected     = Protected;   /* byte assignment */
+      mr.UseProtect    = UseProtect;  /* byte assignment */
+      mr.VolEncrypted  = VolEncrypted;   /* byte assignment */
       bstrncpy(mr.VolStatus, sdmr.VolStatus, sizeof(mr.VolStatus));
       mr.VolReadTime  = sdmr.VolReadTime;
       mr.VolWriteTime = sdmr.VolWriteTime;
index 2762a2945c32db92f1aea5da0ebccaa30f090aff..3d8e06bc5c3ee2a0e1c96b02d23cbeef6558d079 100644 (file)
@@ -100,7 +100,8 @@ static void set_volume_to_exclude_list(JCR *jcr, int index, MEDIA_DBR *mr)
  *   use_protect -- whether or not the device will mark the volume as protected (0 no, -1 don't know, 1 yes)
  */
 int find_next_volume_for_append(JCR *jcr, MEDIA_DBR *mr, int index,
-                                bool create, bool prune, int use_protect, POOL_MEM &errmsg)
+                                bool create, bool prune, int use_protect,
+                                int vol_encrypted, POOL_MEM &errmsg)
 {
    int retry = 0;
    bool ok;
@@ -108,9 +109,9 @@ int find_next_volume_for_append(JCR *jcr, MEDIA_DBR *mr, int index,
    STORE *store = jcr->store_mngr->get_wstore();
 
    bstrncpy(mr->MediaType, store->media_type, sizeof(mr->MediaType));
-   Dmsg7(dbglvl, "find_next_vol_for_append: JobId=%u PoolId=%d, MediaType=%s index=%d create=%d prune=%d protect=%d\n",
+   Dmsg8(dbglvl, "find_next_vol_for_append: JobId=%u PoolId=%d, MediaType=%s index=%d create=%d prune=%d protect=%d vol_encrypted=%d\n",
          (uint32_t)jcr->JobId, (int)mr->PoolId, mr->MediaType, index,
-         create, prune, use_protect);
+         create, prune, use_protect, vol_encrypted);
    /*
     * If we are using an Autochanger, restrict Volume
     *   search to the Autochanger on the first pass
@@ -120,6 +121,12 @@ int find_next_volume_for_append(JCR *jcr, MEDIA_DBR *mr, int index,
    /* Make sure we don't send two times the same volume in the same session */
    set_volume_to_exclude_list(jcr, index, mr);
 
+   if (vol_encrypted == 1) {
+      mr->VolEncrypted = 1;
+   } else {
+      mr->VolEncrypted = 0;
+   }
+
    /*
     * Find the Next Volume for Append
     */
index 5714651b64fb5150d21d0212146df78f63f6c773..046686fec61c7e4563004aef8a34ff4ed479c506 100644 (file)
@@ -186,7 +186,8 @@ bool has_quota_reached(JCR *jcr, MEDIA_DBR *mr);
 bool has_quota_reached(JCR *jcr);
 void set_storageid_in_mr(STORE *store, MEDIA_DBR *mr);
 int find_next_volume_for_append(JCR *jcr, MEDIA_DBR *mr, int index,
-                                bool create, bool purge, int use_worm, POOL_MEM &errmsg);
+                                bool create, bool purge, int use_protect,
+                                int vol_encrypted, POOL_MEM &errmsg);
 bool has_volume_expired(JCR *jcr, MEDIA_DBR *mr);
 void check_if_volume_valid_or_recyclable(JCR *jcr, MEDIA_DBR *mr, const char **reason);
 bool get_scratch_volume(JCR *jcr, bool InChanger, MEDIA_DBR *mr,
index d121918142c6c510bf9385d9fcf8df236f195190..a572444486f9a5e6d0e49c354e98f3575a6c1a01 100644 (file)
@@ -682,6 +682,7 @@ static bool send_label_request(UAContext *ua, MEDIA_DBR *mr, MEDIA_DBR *omr,
    uint64_t VolABytes = 0;
    uint32_t VolType = 0;
    int UseProtect = 0;
+   int VolEncrypted = 0;
    STORE *wstore = ua->jcr->store_mngr->get_wstore();
 
    if (!(sd=open_sd_bsock(ua))) {
@@ -713,8 +714,8 @@ static bool send_label_request(UAContext *ua, MEDIA_DBR *mr, MEDIA_DBR *omr,
 
    while (bget_dirmsg(ua->jcr, sd, BSOCK_TYPE_SD) >= 0) {
       ua->send_msg("%s", sd->msg);
-      if (sscanf(sd->msg, "3000 OK label. VolBytes=%llu VolABytes=%lld VolType=%ld UseProtect=%d",
-                 &VolBytes, &VolABytes, &VolType, &UseProtect) == 4) {
+      if (sscanf(sd->msg, "3000 OK label. VolBytes=%llu VolABytes=%lld VolType=%ld UseProtect=%d VolEncrypted=%d",
+                 &VolBytes, &VolABytes, &VolType, &UseProtect, &VolEncrypted) == 5) {
          ok = true;
          if (media_record_exists) {      /* we update it */
             mr->VolBytes = VolBytes;
@@ -722,6 +723,7 @@ static bool send_label_request(UAContext *ua, MEDIA_DBR *mr, MEDIA_DBR *omr,
             mr->VolType = VolType;
             mr->InChanger = mr->Slot > 0;  /* if slot give assume in changer */
             mr->UseProtect = UseProtect;
+            mr->VolEncrypted = VolEncrypted;
             set_storageid_in_mr(wstore, mr);
             if (!db_update_media_record(ua->jcr, ua->db, mr)) {
                ua->error_msg("%s", db_strerror(ua->db));
@@ -735,6 +737,7 @@ static bool send_label_request(UAContext *ua, MEDIA_DBR *mr, MEDIA_DBR *omr,
             mr->InChanger = mr->Slot > 0;  /* if slot give assume in changer */
             mr->Enabled = 1;
             mr->UseProtect = UseProtect;
+            mr->VolEncrypted = VolEncrypted;
             set_storageid_in_mr(wstore, mr);
             if (db_create_media_record(ua->jcr, ua->db, mr)) {
                ua->info_msg(_("Catalog record for Volume \"%s\", Slot %d  successfully created.\n"),
index 5a1c5137600e6fcb8e67b4dfad43d37592987b7d..d5d61cf7f893d887ef12ce50c6cf802af92be44e 100644 (file)
@@ -1198,7 +1198,8 @@ static bool list_nextvol(UAContext *ua, int ndays)
       get_job_storage(&store, job, run);
       set_storageid_in_mr(store.store, &mr);
       /* no need to set ScratchPoolId, since we use fnv_no_create_vol */
-      if (!find_next_volume_for_append(jcr, &mr, 1, fnv_no_create_vol, fnv_prune, -1 /* no worm */, errmsg)) {
+      if (!find_next_volume_for_append(jcr, &mr, 1, fnv_no_create_vol, fnv_prune,
+            -1 /* no protect */, -1 /* vol_encrypted*/, errmsg)) {
          ua->error_msg(_("Could not find next Volume for Job %s (Pool=%s, Level=%s).%s\n"),
                        job->name(), pr.Name, level_to_str(edl, sizeof(edl), run->level), errmsg.c_str());
       } else {
index 41cb4012b9502a71d2e8aeea2ddeafb69c050983..924e402aff37a972ef59a402484db98cfc6f2334 100644 (file)
@@ -778,7 +778,7 @@ static void prt_runtime(UAContext *ua, sched_pkt *sp, int novolume, OutputWriter
          } else {
             Dmsg0(250, "call find_next_volume_for_append\n");
             /* no need to set ScratchPoolId, since we use fnv_no_create_vol */
-            ok = find_next_volume_for_append(jcr, &mr, 1, fnv_no_create_vol, fnv_no_prune, -1, tmp);
+            ok = find_next_volume_for_append(jcr, &mr, 1, fnv_no_create_vol, fnv_no_prune, -1, -1, tmp);
          }
       }
       if (!ok) {
index 6312e69035d1553a712d6beaf3febf4e84983587..31c8f2ebe58bad4c44afd1834c8280c95b211e81 100644 (file)
@@ -29,7 +29,7 @@
 static const int dbglvl = 200;
 
 /* Requests sent to the Director */
-static char Find_media[]   = "CatReq JobId=%ld FindMedia=%d pool_name=%s media_type=%s vol_type=%d create=%d use_protect=%d\n";
+static char Find_media[]   = "CatReq JobId=%ld FindMedia=%d pool_name=%s media_type=%s vol_type=%d create=%d use_protect=%d vol_encrypted=%d\n";
 static char Get_Vol_Info[] = "CatReq JobId=%ld GetVolInfo VolName=%s write=%d\n";
 static char Update_media[] = "CatReq JobId=%ld UpdateMedia VolName=%s"
    " VolJobs=%u VolFiles=%u VolBlocks=%u VolBytes=%s VolABytes=%s"
@@ -37,7 +37,7 @@ static char Update_media[] = "CatReq JobId=%ld UpdateMedia VolName=%s"
    " VolErrors=%u VolWrites=%u MaxVolBytes=%s EndTime=%s VolStatus=%s"
    " Slot=%d relabel=%d InChanger=%d VolReadTime=%s VolWriteTime=%s"
    " VolFirstWritten=%s VolType=%u VolParts=%d VolCloudParts=%d"
-   " LastPartBytes=%lld Enabled=%d Recycle=%d Protected=%d UseProtect=%d\n";
+   " LastPartBytes=%lld Enabled=%d Recycle=%d Protected=%d UseProtect=%d VolEncrypted=%d\n";
 static char Create_jobmedia[] = "CatReq JobId=%ld CreateJobMedia\n";
 static char FileAttributes[] = "UpdCat JobId=%ld FileAttributes ";
 
@@ -51,7 +51,7 @@ static char OK_media[] = "1000 OK VolName=%127s VolJobs=%u VolFiles=%lu"
    " VolReadTime=%lld VolWriteTime=%lld EndFile=%lu EndBlock=%lu"
    " VolType=%lu LabelType=%ld MediaId=%lld ScratchPoolId=%lld"
    " VolParts=%d VolCloudParts=%d LastPartBytes=%lld Enabled=%d MaxPoolBytes=%lld PoolBytes=%lld Recycle=%d"
-   " Protected=%d UseProtect=%d\n";
+   " Protected=%d UseProtect=%d VolEncrypted=%d\n";
 
 
 static char OK_create[] = "1000 OK CreateJobMedia\n";
@@ -200,7 +200,7 @@ static bool do_get_volume_info(DCR *dcr)
     BSOCK *dir = jcr->dir_bsock;
     VOLUME_CAT_INFO vol;
     int n;
-    int32_t Enabled, Recycle, Protected, UseProtect;
+    int32_t Enabled, Recycle, Protected, UseProtect, VolEncrypted;
     int32_t InChanger;
 
     dcr->setVolCatInfo(false);
@@ -222,9 +222,10 @@ static bool do_get_volume_info(DCR *dcr)
                &vol.EndFile, &vol.EndBlock, &vol.VolCatType,
                &vol.LabelType, &vol.VolMediaId, &vol.VolScratchPoolId,
                &vol.VolCatParts, &vol.VolCatCloudParts,
-               &vol.VolLastPartBytes, &Enabled, &vol.MaxPoolBytes, &vol.PoolBytes, &Recycle, &Protected, &UseProtect);
+               &vol.VolLastPartBytes, &Enabled, &vol.MaxPoolBytes,
+               &vol.PoolBytes, &Recycle, &Protected, &UseProtect, &VolEncrypted);
     Dmsg2(dbglvl, "<dird n=%d %s", n, dir->msg);
-    if (n != 35) {
+    if (n != 36) {
        Dmsg1(dbglvl, "get_volume_info failed: ERR=%s", dir->msg);
        /*
         * Note, we can get an error here either because there is
@@ -240,6 +241,7 @@ static bool do_get_volume_info(DCR *dcr)
     vol.VolRecycle = Recycle;         /* bool in structure */
     vol.Protected = Protected;        /* bool in structure */
     vol.UseProtect = UseProtect;      /* bool in structure */
+    vol.VolEncrypted = VolEncrypted;  /* bool in structure */
     vol.is_valid = true;
     vol.VolCatBytes = vol.VolCatAmetaBytes + vol.VolCatAdataBytes;
     unbash_spaces(vol.VolCatName);
@@ -340,7 +342,8 @@ bool dir_find_next_appendable_volume(DCR *dcr)
        bash_spaces(dcr->media_type);
        bash_spaces(dcr->pool_name);
        dir->fsend(Find_media, jcr->JobId, vol_index, dcr->pool_name, dcr->media_type,
-                  dcr->dev->dev_type, can_create, dcr->dev->use_protect());
+                  dcr->dev->dev_type, can_create, dcr->dev->use_protect(),
+                  dcr->dev->use_volume_encryption());
        unbash_spaces(dcr->media_type);
        unbash_spaces(dcr->pool_name);
        Dmsg1(dbglvl, ">dird %s", dir->msg);
@@ -526,7 +529,8 @@ bool dir_update_volume_info(DCR *dcr, bool label, bool update_LastWritten,
          Enabled,
          Recycle,
          vol.Protected,
-         dev->use_protect()
+         dev->use_protect(),
+         vol.VolEncrypted
          );
        Dmsg1(100, ">dird %s", dir->msg);
       /*
index 148a8a66068c1f0d4a528d560f37cd015221d432..43306cfedccf5d1d6304f2b1281d90f9c09758ef 100644 (file)
@@ -1173,6 +1173,11 @@ bool DEVICE::get_tape_worm(DCR *dcr)
    return false;
 }
 
+int DEVICE::use_volume_encryption()
+{
+   return device->volume_encryption != ET_NONE;
+};
+
 bool DEVICE::load_encryption_key(DCR *dcr, const char *operation,
       const char *volume_name,
       uint32_t *enc_cipher_key_size, unsigned char *enc_cipher_key,
@@ -1180,23 +1185,24 @@ bool DEVICE::load_encryption_key(DCR *dcr, const char *operation,
 {
    enum { op_none, op_label, op_read };
    bool ok = true; // No error
-   if (!device->volume_encryption) {
+   Dmsg4(0, "load_encryption_key %s %s enc=%ld ver=%d\n", operation, volume_name, device->volume_encryption, VolHdr.BlockVer);
+   int op = op_none;
+   if (0 == strcmp(operation, "LABEL")) {
+      op = op_label;
+   } else if (0 == strcmp(operation, "READ")) {
+      op = op_read;
+   }
+   /* don't use encryption if volume encryption is not enable or we are reading
+    * (aka not recycling) a BB02 volume */
+   if (device->volume_encryption == ET_NONE || (op != op_label && VolHdr.BlockVer <= 2)) {
       return ok;
    }
    JCR *jcr = dcr->jcr;
-//      char *edit_device_codes(DCR *dcr, char *omsg, const char *imsg, const char *cmd)
    POOLMEM *encrypt_program = get_pool_memory(PM_FNAME);
    POOL_MEM results(PM_MESSAGE);
    POOL_MEM err_msg(PM_MESSAGE);
    POOL_MEM envv;
 
-   int op = op_none;
-   if (0 == strcmp(operation, "LABEL")) {
-      op = op_label;
-   } else if (0 == strcmp(operation, "READ")) {
-      op = op_read;
-   }
-
    edit_device_codes(dcr, &encrypt_program, me->encryption_command, "load");
    char *envp[5];
    Mmsg(envv, "OPERATION=%s", operation);
index c85eb63477374ed52fac27f303b839de67bb980e..6acf154d0149c926919870670a2dbd591f4c26ca 100644 (file)
@@ -235,6 +235,7 @@ struct VOLUME_CAT_INFO {
    bool     InChanger;                /* Set if vol in current magazine */
    bool     Protected;                /* Set if the vol is Readonly, worm or immutable */
    bool     UseProtect;               /* Set if the device can set the volume Readonly, worm or immutable */
+   bool     VolEncrypted;             /* Set if the volume is encrypted */
    bool     is_valid;                 /* set if this data is valid */
    bool     VolEnabled;               /* set if volume enabled */
    bool     VolRecycle;               /* set if volume can be recycled */
@@ -617,6 +618,7 @@ public:
    virtual int set_readonly(int fd, const char *vol_name) { errno=ENOSYS; return -1;};
    virtual int set_atime(int fd, const char *vol_name, btime_t val) { errno=ENOSYS; return -1;};
    virtual int use_protect() { return 0; };
+   virtual int use_volume_encryption();
    virtual const char *print_type() = 0;        /* in dev.c */
    virtual const char *print_driver_type() { return "";};
    virtual const char *print_full_type() { return print_type();};
index 5e8680360bae966b7dcc56cf2da32c8bd77f3ae1..cca993583c0016f81fa9819d7e5100dfde836383 100644 (file)
@@ -1105,9 +1105,10 @@ static void label_volume_if_ok(DCR *dcr, char *oldname,
       } else {
          type = 0;
       }
-      dir->fsend("3000 OK label. VolBytes=%lld VolABytes=%lld VolType=%d UseProtect=%d Volume=\"%s\" Device=%s\n",
+      dir->fsend("3000 OK label. VolBytes=%lld VolABytes=%lld VolType=%d UseProtect=%d VolEncrypted=%d Volume=\"%s\" Device=%s\n",
                  volCatBytes, dev->VolCatInfo.VolCatAdataBytes,
-                 type, dev->use_protect(), newname, dev->print_name());
+                 type, dev->use_protect(), dev->use_volume_encryption(),
+                 newname, dev->print_name());
       break;
    case VOL_TYPE_ERROR:
       dir->fsend(_("3917 Failed to label Volume: ERR=%s\n"), dcr->jcr->errmsg);
index 6b49caedf0d2dc752da8ecd61375abd844fd2e04..06c843320da1787f11e0bad08e917f9c6e0da9aa 100644 (file)
@@ -659,6 +659,7 @@ bool DEVICE::rewrite_volume_label(DCR *dcr, bool recycle)
    VolCatInfo.VolLastPartBytes = 0;
    VolCatInfo.VolCatType = 0; /* Will be set by dir_update_volume_info() */
    VolCatInfo.UseProtect = use_protect();
+   VolCatInfo.VolEncrypted = use_volume_encryption();
    if (recycle) {
       VolCatInfo.VolCatMounts++;
       VolCatInfo.VolCatRecycles++;
@@ -809,7 +810,7 @@ void create_volume_header(DEVICE *dev, const char *VolName,
    Enter(130);
 
    ASSERT2(dev != NULL, "dev ptr is NULL");
-
+   dev->VolHdr.BlockVer = BLOCK_VER;
    if (dev->is_aligned()) {
       bstrncpy(dev->VolHdr.Id, BaculaMetaDataId, sizeof(dev->VolHdr.Id));
       dev->VolHdr.VerNum = BaculaMetaDataVersion;
@@ -1035,7 +1036,7 @@ bool unser_volume_label(DEVICE *dev, DEV_RECORD *rec)
 
    dev->VolHdr.LabelType = rec->FileIndex;
    dev->VolHdr.LabelSize = rec->data_len;
-
+   dev->VolHdr.BlockVer = rec->BlockVer;
 
    /* Unserialize the record into the Volume Header */
    Dmsg2(100, "reclen=%d recdata=%s", rec->data_len, rec->data);
@@ -1180,7 +1181,7 @@ void DEVICE::dump_volume_label()
       break;
    }
 
-   Pmsg14(-1, _("\nVolume Label:\n"
+   Pmsg15(-1, _("\nVolume Label:\n"
 "Adata             : %d\n"
 "Id                : %s"
 "VerNo             : %d\n"
@@ -1193,6 +1194,7 @@ void DEVICE::dump_volume_label()
 "MediaType         : %s\n"
 "PoolType          : %s\n"
 "HostName          : %s\n"
+"BlockVer          : BB%02%d\n"
 "EncCypherKeySize  : %ld\n"
 "MasterKeyIdSize   : %ld\n"
 ""),
@@ -1202,7 +1204,7 @@ void DEVICE::dump_volume_label()
              File, LabelType, VolHdr.LabelSize,
              VolHdr.PoolName, VolHdr.MediaType,
              VolHdr.PoolType, VolHdr.HostName,
-             VolHdr.EncCypherKeySize, VolHdr.MasterKeyIdSize);
+             VolHdr.BlockVer, VolHdr.EncCypherKeySize, VolHdr.MasterKeyIdSize);
 
    if (VolHdr.VerNum >= 11) {
       char dt[50];
index 50d82174ca99b6d63ecc5e1784010d3cd7ce8e59..dfb74ec3ec07bb614eb06b98c0091fe0b9cf2376 100644 (file)
@@ -172,7 +172,7 @@ struct Volume_Label {
   char Id[32];                        /* Bacula Immortal ... */
 
   uint32_t VerNum;                    /* Label version number */
-
+  int      BlockVer;                  /* 1, 2 or .. from BB01, BB02 from the FIRST block */
   /* VerNum <= 10 */
   float64_t label_date;               /* Date tape labeled */
   float64_t label_time;               /* Time tape labeled */