From: Norbert Bizet Date: Fri, 3 Jul 2020 14:26:22 +0000 (-0400) Subject: cloud: Fix #6457 About segfault in glacier restore due to s3ctx initialization in... X-Git-Tag: Release-11.3.2~1406 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bf0701daa7f2e16ed61866b948ada6288ef615ec;p=thirdparty%2Fbacula.git cloud: Fix #6457 About segfault in glacier restore due to s3ctx initialization in s3_cloud_glacier --- diff --git a/bacula/src/stored/cloud_glacier.h b/bacula/src/stored/cloud_glacier.h index 93ba9808a5..9300368272 100644 --- a/bacula/src/stored/cloud_glacier.h +++ b/bacula/src/stored/cloud_glacier.h @@ -31,12 +31,19 @@ #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"); diff --git a/bacula/src/stored/s3_driver.c b/bacula/src/stored/s3_driver.c index 5c419140c4..5aa4535302 100644 --- a/bacula/src/stored/s3_driver.c +++ b/bacula/src/stored/s3_driver.c @@ -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;