summaryrefslogtreecommitdiffstats
path: root/storage/maria/libmarias3/src
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-13 13:39:13 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-13 13:39:13 +0000
commit86fbb58c3ac0865482819c10a3e81f2eea001c36 (patch)
tree28c9e526ea739c6f9b89e36115e1e2698bddf981 /storage/maria/libmarias3/src
parentReleasing progress-linux version 1:10.11.6-2~progress7.99u1. (diff)
downloadmariadb-86fbb58c3ac0865482819c10a3e81f2eea001c36.tar.xz
mariadb-86fbb58c3ac0865482819c10a3e81f2eea001c36.zip
Merging upstream version 1:10.11.7.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'storage/maria/libmarias3/src')
-rw-r--r--storage/maria/libmarias3/src/assume_role.c4
-rw-r--r--storage/maria/libmarias3/src/error.c4
-rw-r--r--storage/maria/libmarias3/src/include.am2
-rw-r--r--storage/maria/libmarias3/src/marias3.c50
-rw-r--r--storage/maria/libmarias3/src/request.c30
-rw-r--r--storage/maria/libmarias3/src/request.h2
-rw-r--r--storage/maria/libmarias3/src/response.c2
-rw-r--r--storage/maria/libmarias3/src/structs.h2
-rw-r--r--storage/maria/libmarias3/src/xml.c2
9 files changed, 78 insertions, 20 deletions
diff --git a/storage/maria/libmarias3/src/assume_role.c b/storage/maria/libmarias3/src/assume_role.c
index 255b1eca..4135504c 100644
--- a/storage/maria/libmarias3/src/assume_role.c
+++ b/storage/maria/libmarias3/src/assume_role.c
@@ -373,7 +373,7 @@ build_assume_role_request_headers(CURL *curl, struct curl_slist **head,
time_t now;
struct tm tmp_tm;
char headerbuf[3072];
- char secrethead[45];
+ char secrethead[MAX_S3_SECRET_LENGTH + S3_SECRET_EXTRA_LENGTH];
char date[9];
char sha256hash[65];
char post_hash[65];
@@ -445,7 +445,7 @@ build_assume_role_request_headers(CURL *curl, struct curl_slist **head,
// User signing key hash
// Date hashed using AWS4:secret_key
- snprintf(secrethead, sizeof(secrethead), "AWS4%.*s", 40, secret);
+ snprintf(secrethead, sizeof(secrethead), "AWS4%.*s", MAX_S3_SECRET_LENGTH, secret);
strftime(headerbuf, sizeof(headerbuf), "%Y%m%d", &tmp_tm);
hmac_sha256((uint8_t *)secrethead, strlen(secrethead), (uint8_t *)headerbuf,
strlen(headerbuf), hmac_hash);
diff --git a/storage/maria/libmarias3/src/error.c b/storage/maria/libmarias3/src/error.c
index edf95d05..2723c846 100644
--- a/storage/maria/libmarias3/src/error.c
+++ b/storage/maria/libmarias3/src/error.c
@@ -35,5 +35,7 @@ const char *errmsgs[] =
"Authentication error",
"File not found",
"S3 server error",
- "Data too big. Maximum data size is 4GB"
+ "Data too big. Maximum data size is 4GB",
+ "Error in role",
+ "Endpoint permanently moved"
};
diff --git a/storage/maria/libmarias3/src/include.am b/storage/maria/libmarias3/src/include.am
index b8c07a6f..f786df3b 100644
--- a/storage/maria/libmarias3/src/include.am
+++ b/storage/maria/libmarias3/src/include.am
@@ -18,7 +18,7 @@ lib_LTLIBRARIES+= src/libmarias3.la
src_libmarias3_la_SOURCES=
src_libmarias3_la_LIBADD=
src_libmarias3_la_LDFLAGS=
-src_libmarias3_la_CFLAGS= -DBUILDING_MS3
+src_libmarias3_la_CFLAGS= -DBUILDING_MS3 -fPIC
src_libmarias3_la_SOURCES+= src/marias3.c
src_libmarias3_la_SOURCES+= src/request.c
diff --git a/storage/maria/libmarias3/src/marias3.c b/storage/maria/libmarias3/src/marias3.c
index 74d7233a..b146da55 100644
--- a/storage/maria/libmarias3/src/marias3.c
+++ b/storage/maria/libmarias3/src/marias3.c
@@ -52,7 +52,7 @@ static void locking_function(int mode, int n, const char *file, int line)
pthread_mutex_unlock(&(mutex_buf[n]));
}
-static int curl_needs_openssl_locking()
+static int curl_needs_openssl_locking(void)
{
curl_version_info_data *data = curl_version_info(CURLVERSION_NOW);
@@ -214,6 +214,8 @@ ms3_st *ms3_init(const char *s3key, const char *s3secret,
ms3->list_container.start = NULL;
ms3->list_container.pool_list = NULL;
ms3->list_container.pool_free = 0;
+ ms3->read_cb= 0;
+ ms3->user_data= 0;
ms3->iam_role = NULL;
ms3->role_key = NULL;
@@ -354,14 +356,16 @@ const char *ms3_server_error(ms3_st *ms3)
return ms3->last_error;
}
-void ms3_debug(void)
+void ms3_debug(int debug_state)
{
bool state = ms3debug_get();
- ms3debug_set(!state);
-
- if (state)
+ if (state != (bool) debug_state)
{
- ms3debug("enabling debug");
+ ms3debug_set((bool) debug_state);
+ if (debug_state)
+ {
+ ms3debug("enabling debug");
+ }
}
}
@@ -449,15 +453,23 @@ uint8_t ms3_get(ms3_st *ms3, const char *bucket, const char *key,
buf.data = NULL;
buf.length = 0;
- if (!ms3 || !bucket || !key || key[0] == '\0' || !data || !length)
+ if (!ms3 || !bucket || !key || key[0] == '\0')
+ {
+ return MS3_ERR_PARAMETER;
+ }
+ else if (!ms3->read_cb && (!data || !length))
{
return MS3_ERR_PARAMETER;
}
res = execute_request(ms3, MS3_CMD_GET, bucket, key, NULL, NULL, NULL, NULL, 0,
NULL, &buf);
- *data = buf.data;
- *length = buf.length;
+ if (!ms3->read_cb)
+ {
+ *data = buf.data;
+ *length = buf.length;
+ }
+
return res;
}
@@ -617,7 +629,7 @@ uint8_t ms3_set_option(ms3_st *ms3, ms3_set_option_t option, void *value)
return MS3_ERR_PARAMETER;
}
- ms3->list_version = protocol_version;
+ ms3->protocol_version = protocol_version;
break;
}
@@ -634,6 +646,24 @@ uint8_t ms3_set_option(ms3_st *ms3, ms3_set_option_t option, void *value)
ms3->port = port_number;
break;
}
+
+ case MS3_OPT_READ_CB:
+ {
+ if (!value)
+ {
+ return MS3_ERR_PARAMETER;
+ }
+
+ ms3->read_cb = value;
+ break;
+ }
+
+ case MS3_OPT_USER_DATA:
+ {
+ ms3->user_data = value;
+ break;
+ }
+
default:
return MS3_ERR_PARAMETER;
}
diff --git a/storage/maria/libmarias3/src/request.c b/storage/maria/libmarias3/src/request.c
index 26165474..b2924f9d 100644
--- a/storage/maria/libmarias3/src/request.c
+++ b/storage/maria/libmarias3/src/request.c
@@ -413,7 +413,7 @@ static uint8_t build_request_headers(CURL *curl, struct curl_slist **head,
time_t now;
struct tm tmp_tm;
char headerbuf[3072];
- char secrethead[45];
+ char secrethead[MAX_S3_SECRET_LENGTH + S3_SECRET_EXTRA_LENGTH];
char date[9];
char sha256hash[65];
char post_hash[65];
@@ -520,7 +520,7 @@ static uint8_t build_request_headers(CURL *curl, struct curl_slist **head,
// User signing key hash
// Date hashed using AWS4:secret_key
- snprintf(secrethead, sizeof(secrethead), "AWS4%.*s", 40, secret);
+ snprintf(secrethead, sizeof(secrethead), "AWS4%.*s", MAX_S3_SECRET_LENGTH, secret);
strftime(headerbuf, sizeof(headerbuf), "%Y%m%d", &tmp_tm);
hmac_sha256((uint8_t *)secrethead, strlen(secrethead), (uint8_t *)headerbuf,
strlen(headerbuf), hmac_hash);
@@ -829,9 +829,19 @@ uint8_t execute_request(ms3_st *ms3, command_t cmd, const char *bucket,
if (ms3->port)
curl_easy_setopt(curl, CURLOPT_PORT, (long)ms3->port);
+ if (ms3->read_cb && cmd == MS3_CMD_GET)
+ {
+ curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, ms3->read_cb);
+ curl_easy_setopt(curl, CURLOPT_WRITEDATA, ms3->user_data);
+ }
+ else
+ {
+ curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, body_callback);
+ curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&mem);
+ }
+
+ curl_easy_setopt(curl, CURLOPT_BUFFERSIZE, ms3->buffer_chunk_size);
curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, header_callback);
- curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, body_callback);
- curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&mem);
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
curl_res = curl_easy_perform(curl);
@@ -848,6 +858,18 @@ uint8_t execute_request(ms3_st *ms3, command_t cmd, const char *bucket,
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response_code);
ms3debug("Response code: %ld", response_code);
+ if (response_code == 301)
+ {
+ char *message = parse_error_message((char *)mem.data, mem.length);
+
+ if (message)
+ {
+ ms3debug("Response message: %s", message);
+ }
+
+ set_error_nocopy(ms3, message);
+ res = MS3_ERR_ENDPOINT;
+ }
if (response_code == 404)
{
char *message = parse_error_message((char *)mem.data, mem.length);
diff --git a/storage/maria/libmarias3/src/request.h b/storage/maria/libmarias3/src/request.h
index 9ce8bb5c..29ea79b3 100644
--- a/storage/maria/libmarias3/src/request.h
+++ b/storage/maria/libmarias3/src/request.h
@@ -26,6 +26,8 @@
// Maxmum S3 file size is 1024 bytes so for protection we make the maximum
// URI length this
#define MAX_URI_LENGTH 1024
+#define MAX_S3_SECRET_LENGTH 128
+#define S3_SECRET_EXTRA_LENGTH 5
#define READ_BUFFER_DEFAULT_SIZE 1024*1024
diff --git a/storage/maria/libmarias3/src/response.c b/storage/maria/libmarias3/src/response.c
index 4e976aba..da5d6b3c 100644
--- a/storage/maria/libmarias3/src/response.c
+++ b/storage/maria/libmarias3/src/response.c
@@ -395,7 +395,7 @@ uint8_t parse_role_list_response(const char *data, size_t length, char *role_nam
}
}
while ((member = xml_node_child(roles, ++roles_it)));
- if (!strcmp(response_role_name, role_name))
+ if (response_role_name && !strcmp(response_role_name, role_name))
{
ms3debug("Role Found ARN = %s",response_role_arn);
sprintf(arn, "%s", response_role_arn);
diff --git a/storage/maria/libmarias3/src/structs.h b/storage/maria/libmarias3/src/structs.h
index 34cbd817..30a7fff0 100644
--- a/storage/maria/libmarias3/src/structs.h
+++ b/storage/maria/libmarias3/src/structs.h
@@ -64,6 +64,8 @@ struct ms3_st
bool first_run;
char *path_buffer;
char *query_buffer;
+ void *read_cb;
+ void *user_data;
struct ms3_list_container_st list_container;
};
diff --git a/storage/maria/libmarias3/src/xml.c b/storage/maria/libmarias3/src/xml.c
index 2c48a4ea..25bd125f 100644
--- a/storage/maria/libmarias3/src/xml.c
+++ b/storage/maria/libmarias3/src/xml.c
@@ -800,7 +800,7 @@ node_creation:;
return node;
- /* A failure occured, so free all allocalted resources
+ /* A failure occurred, so free all allocalted resources
*/
exit_failure:
if (tag_open) {