]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
cloud: Fix #6457 About segfault in glacier restore due to s3ctx initialization in...
authorNorbert Bizet <norbert.bizet@baculasystems.com>
Fri, 3 Jul 2020 14:26:22 +0000 (10:26 -0400)
committerEric Bollengier <eric@baculasystems.com>
Tue, 1 Mar 2022 14:36:16 +0000 (15:36 +0100)
bacula/src/stored/cloud_glacier.h
bacula/src/stored/s3_driver.c

index 93ba9808a54e3933e9fccbf0f74348d09ec2d719..93003682722da7d730467acccdcb45b2601f258c 100644 (file)
 #ifndef _CLOUD_GLACIER_H_
 #define _CLOUD_GLACIER_H_
 
+typedef struct cloud_glacier_cgc
+{
+   const char *host_name;
+   const char *bucket_name;
+}  cloud_glacier_ctx;
+
 /* Abstract class cannot be instantiated */
 class cloud_glacier: public SMARTALLOC {
 public:
    cloud_glacier() {};
    virtual ~cloud_glacier() {};
-
+   
+   virtual bool init(cloud_glacier_ctx *ctx, POOLMEM *&err) = 0;
    virtual bool restore_cloud_object(transfer *xfer, const char *cloud_fname) = 0;
    virtual bool is_waiting_on_server(transfer *xfer, const char *cloud_fname) = 0;
 };
@@ -44,6 +51,11 @@ public:
 class dummy_glacier: public cloud_glacier {
 public:
    dummy_glacier() {};
+   bool init (cloud_glacier_ctx *ctx, POOLMEM *&err)
+   {
+      Mmsg(err, "Cloud glacier not properly loaded");
+      return false;
+   }
    bool restore_cloud_object(transfer *xfer, const char *cloud_fname)
    {
       Mmsg(xfer->m_message, "Cloud glacier not properly loaded");
index 5c419140c4011ee33a018c94ec2a6119d58f7ce0..5aa4535302115513ab14bb1c222f0dc662943c35 100644 (file)
@@ -839,26 +839,6 @@ bool s3_driver::init(CLOUD *cloud, POOLMEM *&err)
    s3ctx.accessKeyId = cloud->access_key;
    s3ctx.secretAccessKey = cloud->secret_key;
    s3ctx.authRegion = cloud->region;
-   switch( cloud->transfer_priority) {
-      case CLOUD_RESTORE_PRIO_HIGH:
-         transfer_priority = S3RestoreTierExpedited;
-         break;
-      case CLOUD_RESTORE_PRIO_MEDIUM:
-         transfer_priority = S3RestoreTierStandard;
-         break;
-      case CLOUD_RESTORE_PRIO_LOW:
-         transfer_priority = S3RestoreTierBulk;
-         break;
-      default:
-         transfer_priority = S3RestoreTierExpedited;
-         break;
-   };
-
-   transfer_retention_days = cloud->transfer_retention / (3600 * 24);
-   /* at least 1 day retention period */
-   if (transfer_retention_days <= 0) {
-      transfer_retention_days = 1;
-   }
 
    if ((status = S3_initialize("s3", S3_INIT_ALL, s3ctx.hostName)) != S3StatusOK) {
       Mmsg1(err, "Failed to initialize S3 lib. ERR=%s\n", S3_get_status_name(status));
@@ -868,6 +848,22 @@ bool s3_driver::init(CLOUD *cloud, POOLMEM *&err)
    /*load glacier */
    if (me) {
       load_glacier_driver(me->plugin_directory);
+      if (glacier_item.ptr) {
+         s3_cloud_glacier_ctx glacier_ctx;
+         glacier_ctx.host_name = cloud->host_name;
+         glacier_ctx.bucket_name = cloud->bucket_name;
+         glacier_ctx.protocol = (S3Protocol)cloud->protocol;
+         glacier_ctx.uri_style = (S3UriStyle)cloud->uri_style;
+         glacier_ctx.access_key = cloud->access_key;
+         glacier_ctx.secret_key = cloud->secret_key;
+         glacier_ctx.region = cloud->region;
+         glacier_ctx.transfer_priority = cloud->transfer_priority;
+         glacier_ctx.transfer_retention = cloud->transfer_retention;
+
+         if (!glacier_item.ptr->init(&glacier_ctx, err)) {
+            return false;
+         }
+      }
    }
 
    return true;