From 6dd0c2538589765f35c3bed5444194f576c12a9c Mon Sep 17 00:00:00 2001 From: SciLor Date: Thu, 3 Oct 2024 10:18:27 +0000 Subject: [PATCH] fix abort if base certs exist + wrong deletion. --- src/handler_api.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/handler_api.c b/src/handler_api.c index 5989003d..ab21b388 100644 --- a/src/handler_api.c +++ b/src/handler_api.c @@ -1216,7 +1216,6 @@ bool_t move_cert_file(const char *type, char *from, char *to, char message[1024] else if (error == NO_ERROR) { TRACE_INFO("Skipped identical %s", type); - fsDeleteFile(from); } return true; } @@ -1239,6 +1238,7 @@ error_t handleApiESP32ExtractCerts(HttpConnection *connection, const char_t *uri } bool overwrite = false; + bool overwriteBase = false; if (queryGet(queryString, "overwrite", overwrite_s, sizeof(overwrite_s))) { if (overwrite_s[0] == 't') @@ -1302,17 +1302,14 @@ error_t handleApiESP32ExtractCerts(HttpConnection *connection, const char_t *uri break; } - if (!move_cert_file("CA", ca_target_file, ca_global_file, message, &statusCode, overwrite)) + if (!move_cert_file("CA", ca_target_file, ca_global_file, message, &statusCode, overwriteBase)) { - break; } - if (!move_cert_file("CLIENT", client_target_file, client_global_file, message, &statusCode, overwrite)) + if (!move_cert_file("CLIENT", client_target_file, client_global_file, message, &statusCode, overwriteBase)) { - break; } - if (!move_cert_file("PRIVATE", private_target_file, private_global_file, message, &statusCode, overwrite)) + if (!move_cert_file("PRIVATE", private_target_file, private_global_file, message, &statusCode, overwriteBase)) { - break; } osSnprintf(message, sizeof(message), "OK"); @@ -1324,6 +1321,10 @@ error_t handleApiESP32ExtractCerts(HttpConnection *connection, const char_t *uri TRACE_ERROR("%s\r\n", message); } + fsDeleteFile(ca_file); + fsDeleteFile(client_file); + fsDeleteFile(private_file); + osFreeMem(file_path); osFreeMem(target_dir);