summaryrefslogtreecommitdiff
path: root/src/analysis/db/analyst.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/analysis/db/analyst.c')
-rw-r--r--src/analysis/db/analyst.c115
1 files changed, 107 insertions, 8 deletions
diff --git a/src/analysis/db/analyst.c b/src/analysis/db/analyst.c
index dff073a..49585c2 100644
--- a/src/analysis/db/analyst.c
+++ b/src/analysis/db/analyst.c
@@ -26,9 +26,11 @@
#include <assert.h>
#include <poll.h>
+#include <string.h>
#include "client-int.h"
+#include "../storage/storage.h"
#include "../../core/logs.h"
@@ -38,7 +40,7 @@ struct _GAnalystClient
{
GHubClient parent; /* A laisser en premier */
- rle_string hash; /* Empreinte du binaire lié */
+ char *hash; /* Empreinte du binaire lié */
GList *collections; /* Collections d'un binaire */
bool can_get_updates; /* Réception de maj possibles ?*/
@@ -157,7 +159,7 @@ static void g_analyst_client_class_init(GAnalystClientClass *klass)
static void g_analyst_client_init(GAnalystClient *client)
{
- setup_empty_rle_string(&client->hash);
+ client->hash = NULL;
client->collections = NULL;
client->can_get_updates = false;
@@ -214,7 +216,8 @@ static void g_analyst_client_finalize(GAnalystClient *client)
{
size_t i; /* Boucle de parcours */
- unset_rle_string(&client->hash);
+ if (client->hash != NULL)
+ free(client->hash);
if (client->snapshots != NULL)
{
@@ -249,7 +252,7 @@ GAnalystClient *g_analyst_client_new(const char *hash, GList *collections)
result = g_object_new(G_TYPE_ANALYST_CLIENT, NULL);
- init_static_rle_string(&result->hash, hash);
+ result->hash = strdup(hash);
result->collections = collections;
return result;
@@ -273,8 +276,13 @@ GAnalystClient *g_analyst_client_new(const char *hash, GList *collections)
static bool g_analyst_client_complete_hello(GAnalystClient *client, packed_buffer_t *pbuf)
{
bool result; /* Bilan à retourner */
+ rle_string str; /* Chaîne à communiquer */
- result = pack_rle_string(&client->hash, pbuf);
+ init_static_rle_string(&str, client->hash);
+
+ result = pack_rle_string(&str, pbuf);
+
+ exit_rle_string(&str);
return result;
@@ -406,11 +414,10 @@ static void *g_analyst_client_update(GAnalystClient *client)
error = tmp32;
if (error == DBE_NONE)
- log_variadic_message(LMT_INFO, _("Archive saved for binary '%s'"),
- get_rle_string(&client->hash));
+ log_variadic_message(LMT_INFO, _("Archive saved for binary '%s'"), client->hash);
else
log_variadic_message(LMT_ERROR, _("Failed to save the archive for binary '%s'"),
- get_rle_string(&client->hash));
+ client->hash);
break;
@@ -635,6 +642,98 @@ static bool g_analyst_client_update_current_snapshot(GAnalystClient *client, pac
/******************************************************************************
* *
+* Paramètres : client = client pour les accès distants à manipuler. *
+* content = contenu binaire à envoyer. *
+* *
+* Description : Envoie un contenu binaire pour conservation côté serveur. *
+* *
+* Retour : true si la commande a bien été envoyée, false sinon. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool g_analyst_client_send_content(GAnalystClient *client, GBinContent *content)
+{
+ bool result; /* Bilan partiel à remonter */
+ const gchar *hash; /* Empreinte du contenu fourni */
+ packed_buffer_t cnt_pbuf; /* Tampon de stockage */
+ GObjectStorage *storage; /* Gestionnaire de stockage */
+ off64_t pos; /* Emplacement du binaire */
+ SSL *tls_fd; /* Canal de communication SSL */
+ packed_buffer_t out_pbuf; /* Tampon d'émission */
+
+ result = false;
+
+ /* Validation de la conformité du contenu */
+
+ hash = g_binary_content_get_checksum(content);
+
+ if (strcmp(hash, client->hash) != 0)
+ {
+ log_variadic_message(LMT_ERROR, _("Provided ontent does not match client content (hash: '%s')"),
+ client->hash);
+ goto exit;
+ }
+
+ /* Conversion en format de stockage */
+
+ init_packed_buffer(&cnt_pbuf);
+
+ storage = g_object_storage_new(client->hash);
+
+ result = g_object_storage_store_object(storage, "contents", G_SERIALIZABLE_OBJECT(content), &pos);
+ if (!result) goto exit_with_failure;
+
+ result = pack_uleb128((uleb128_t []){ pos }, &cnt_pbuf);
+ if (!result) goto exit_with_failure;
+
+ result = g_object_storage_store(storage, &cnt_pbuf);
+ if (!result) goto exit_with_failure;
+
+ /* Transmission */
+
+ tls_fd = g_hub_client_get_ssl_fd(G_HUB_CLIENT(client));
+
+ if (tls_fd == NULL)
+ result = false;
+
+ else
+ {
+ init_packed_buffer(&out_pbuf);
+
+ result = extend_packed_buffer(&out_pbuf, (uint32_t []) { DBC_SET_CONTENT }, sizeof(uint32_t), true);
+
+ if (result)
+ result = pack_uleb128((uleb128_t []){ get_packed_buffer_payload_length(&cnt_pbuf) }, &out_pbuf);
+
+ if (result)
+ result = include_packed_buffer(&out_pbuf, &cnt_pbuf);
+
+ if (result)
+ result = ssl_send_packed_buffer(&out_pbuf, tls_fd);
+
+ g_hub_client_put_ssl_fd(G_HUB_CLIENT(client), tls_fd);
+
+ exit_packed_buffer(&out_pbuf);
+
+ }
+
+ exit_with_failure:
+
+ g_object_unref(G_OBJECT(storage));
+
+ exit_packed_buffer(&cnt_pbuf);
+
+ exit:
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
* Paramètres : client = client pour les accès distants à manipuler. *
* *
* Description : Effectue une demande de sauvegarde de l'état courant. *