feat: add transactional evidence importer
This commit is contained in:
parent
d3a2124f8b
commit
2b9d560da7
29 changed files with 4324 additions and 2 deletions
24
Makefile
24
Makefile
|
|
@ -53,6 +53,7 @@ TEST_TOOL_CATALOG := tests/test_tool_catalog
|
||||||
TEST_TOOL_INITIALIZER := tests/test_tool_initializer
|
TEST_TOOL_INITIALIZER := tests/test_tool_initializer
|
||||||
TEST_FILE_HASH := tests/test_file_hash
|
TEST_FILE_HASH := tests/test_file_hash
|
||||||
TEST_EVIDENCE_COPY := tests/test_evidence_copy
|
TEST_EVIDENCE_COPY := tests/test_evidence_copy
|
||||||
|
TEST_EVIDENCE_IMPORTER := tests/test_evidence_importer
|
||||||
|
|
||||||
all: $(TARGET)
|
all: $(TARGET)
|
||||||
|
|
||||||
|
|
@ -228,6 +229,22 @@ $(TEST_EVIDENCE_COPY): \
|
||||||
-DEVIDENCE_COPY_ENABLE_TEST_HOOKS \
|
-DEVIDENCE_COPY_ENABLE_TEST_HOOKS \
|
||||||
$^ -o $@ $(TEST_LDFLAGS)
|
$^ -o $@ $(TEST_LDFLAGS)
|
||||||
|
|
||||||
|
$(TEST_EVIDENCE_IMPORTER): \
|
||||||
|
tests/test_evidence_importer.c \
|
||||||
|
src/core/evidence_importer.c \
|
||||||
|
src/core/evidence_copy.c \
|
||||||
|
src/core/file_hash.c \
|
||||||
|
src/dao/evidence_dao.c \
|
||||||
|
src/models/evidence_record.c \
|
||||||
|
src/database/database.c \
|
||||||
|
src/database/schema.c \
|
||||||
|
src/database/statement.c \
|
||||||
|
src/database/transaction.c \
|
||||||
|
src/database/error.c
|
||||||
|
$(CC) $(TEST_CFLAGS) \
|
||||||
|
-DEVIDENCE_IMPORTER_ENABLE_TEST_HOOKS \
|
||||||
|
$^ -o $@ $(TEST_LDFLAGS) -lsqlite3
|
||||||
|
|
||||||
test: \
|
test: \
|
||||||
$(TEST_NODE) \
|
$(TEST_NODE) \
|
||||||
$(TEST_TREE_MODEL) \
|
$(TEST_TREE_MODEL) \
|
||||||
|
|
@ -250,7 +267,8 @@ test: \
|
||||||
$(TEST_TOOL_CATALOG) \
|
$(TEST_TOOL_CATALOG) \
|
||||||
$(TEST_TOOL_INITIALIZER) \
|
$(TEST_TOOL_INITIALIZER) \
|
||||||
$(TEST_FILE_HASH) \
|
$(TEST_FILE_HASH) \
|
||||||
$(TEST_EVIDENCE_COPY)
|
$(TEST_EVIDENCE_COPY) \
|
||||||
|
$(TEST_EVIDENCE_IMPORTER)
|
||||||
@echo "Exécution des tests..."
|
@echo "Exécution des tests..."
|
||||||
@./$(TEST_NODE)
|
@./$(TEST_NODE)
|
||||||
@./$(TEST_TREE_MODEL)
|
@./$(TEST_TREE_MODEL)
|
||||||
|
|
@ -274,6 +292,7 @@ test: \
|
||||||
@$(TEST_TOOL_INITIALIZER)
|
@$(TEST_TOOL_INITIALIZER)
|
||||||
@$(TEST_FILE_HASH)
|
@$(TEST_FILE_HASH)
|
||||||
@$(TEST_EVIDENCE_COPY)
|
@$(TEST_EVIDENCE_COPY)
|
||||||
|
@$(TEST_EVIDENCE_IMPORTER)
|
||||||
@echo "Tous les tests sont valides."
|
@echo "Tous les tests sont valides."
|
||||||
|
|
||||||
%.o: %.c
|
%.o: %.c
|
||||||
|
|
@ -305,7 +324,8 @@ clean:
|
||||||
$(TEST_TOOL_CATALOG) \
|
$(TEST_TOOL_CATALOG) \
|
||||||
$(TEST_TOOL_INITIALIZER) \
|
$(TEST_TOOL_INITIALIZER) \
|
||||||
$(TEST_FILE_HASH) \
|
$(TEST_FILE_HASH) \
|
||||||
$(TEST_EVIDENCE_COPY)
|
$(TEST_EVIDENCE_COPY) \
|
||||||
|
$(TEST_EVIDENCE_IMPORTER)
|
||||||
|
|
||||||
|
|
||||||
.PHONY: clean run test
|
.PHONY: clean run test
|
||||||
|
|
|
||||||
132
include/core/evidence_importer.h
Normal file
132
include/core/evidence_importer.h
Normal file
|
|
@ -0,0 +1,132 @@
|
||||||
|
/******************************************************************************
|
||||||
|
* @file evidence_importer.h
|
||||||
|
* @brief Orchestration de l’import transactionnel des preuves.
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
#ifndef LABFY_INVESTIGATION_EVIDENCE_IMPORTER_H
|
||||||
|
#define LABFY_INVESTIGATION_EVIDENCE_IMPORTER_H
|
||||||
|
|
||||||
|
#include "database/database.h"
|
||||||
|
#include "models/evidence_record.h"
|
||||||
|
|
||||||
|
#include <gio/gio.h>
|
||||||
|
#include <glib.h>
|
||||||
|
|
||||||
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Catégories d’erreurs du module EvidenceImporter.
|
||||||
|
*/
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
EVIDENCE_IMPORTER_ERROR_INVALID_ARGUMENT,
|
||||||
|
EVIDENCE_IMPORTER_ERROR_MEMORY,
|
||||||
|
EVIDENCE_IMPORTER_ERROR_CANCELLED,
|
||||||
|
EVIDENCE_IMPORTER_ERROR_DESTINATION,
|
||||||
|
EVIDENCE_IMPORTER_ERROR_COPY,
|
||||||
|
EVIDENCE_IMPORTER_ERROR_MODEL,
|
||||||
|
EVIDENCE_IMPORTER_ERROR_DATABASE,
|
||||||
|
EVIDENCE_IMPORTER_ERROR_ROLLBACK
|
||||||
|
} EvidenceImporterError;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Domaine d’erreurs du module EvidenceImporter.
|
||||||
|
*/
|
||||||
|
#define EVIDENCE_IMPORTER_ERROR \
|
||||||
|
evidence_importer_error_quark()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Retourne le domaine d’erreurs du module.
|
||||||
|
*/
|
||||||
|
GQuark evidence_importer_error_quark(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Service opaque orchestrant l’import des preuves.
|
||||||
|
*
|
||||||
|
* L’objet emprunte la connexion Database reçue à sa création.
|
||||||
|
*/
|
||||||
|
typedef struct EvidenceImporter EvidenceImporter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Paramètres empruntés d’un import de preuve.
|
||||||
|
*
|
||||||
|
* Les chaînes restent la propriété de l’appelant.
|
||||||
|
*
|
||||||
|
* source_path, destination_directory, relative_directory et
|
||||||
|
* type_identifier sont obligatoires.
|
||||||
|
*
|
||||||
|
* collected_at, source et description sont facultatifs.
|
||||||
|
*/
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
const char *source_path;
|
||||||
|
const char *destination_directory;
|
||||||
|
const char *relative_directory;
|
||||||
|
const char *type_identifier;
|
||||||
|
|
||||||
|
const char *collected_at;
|
||||||
|
const char *source;
|
||||||
|
const char *description;
|
||||||
|
} EvidenceImportRequest;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Crée un service d’import utilisant une connexion existante.
|
||||||
|
*
|
||||||
|
* La connexion est empruntée et doit rester valide pendant toute la durée
|
||||||
|
* de vie de l’importeur.
|
||||||
|
*
|
||||||
|
* @param database Connexion ouverte et migrée.
|
||||||
|
* @param error Adresse recevant une éventuelle erreur.
|
||||||
|
*
|
||||||
|
* @return Nouvel importeur, ou NULL.
|
||||||
|
*/
|
||||||
|
EvidenceImporter *evidence_importer_new(
|
||||||
|
Database *database,
|
||||||
|
GError **error
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Libère un importeur.
|
||||||
|
*
|
||||||
|
* La connexion Database empruntée n’est pas fermée.
|
||||||
|
* Cette fonction accepte NULL.
|
||||||
|
*
|
||||||
|
* @param evidence_importer Importeur à libérer.
|
||||||
|
*/
|
||||||
|
void evidence_importer_free(
|
||||||
|
EvidenceImporter *evidence_importer
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Importe une preuve de manière transactionnelle.
|
||||||
|
*
|
||||||
|
* Après succès :
|
||||||
|
*
|
||||||
|
* - le fichier est présent dans l’enquête ;
|
||||||
|
* - le modèle est enregistré dans SQLite ;
|
||||||
|
* - le EvidenceRecord retourné appartient à l’appelant.
|
||||||
|
*
|
||||||
|
* Après échec :
|
||||||
|
*
|
||||||
|
* - aucun EvidenceRecord n’est retourné ;
|
||||||
|
* - aucune transaction démarrée par l’importeur ne reste active ;
|
||||||
|
* - toute copie créée par l’opération est supprimée lorsque cela est
|
||||||
|
* encore possible.
|
||||||
|
*
|
||||||
|
* @param evidence_importer Service d’import.
|
||||||
|
* @param request Paramètres empruntés de l’import.
|
||||||
|
* @param cancellable Objet d’annulation facultatif.
|
||||||
|
* @param error Adresse recevant une éventuelle erreur.
|
||||||
|
*
|
||||||
|
* @return Nouveau EvidenceRecord, ou NULL.
|
||||||
|
*/
|
||||||
|
EvidenceRecord *evidence_importer_import(
|
||||||
|
EvidenceImporter *evidence_importer,
|
||||||
|
const EvidenceImportRequest *request,
|
||||||
|
GCancellable *cancellable,
|
||||||
|
GError **error
|
||||||
|
);
|
||||||
|
|
||||||
|
G_END_DECLS
|
||||||
|
|
||||||
|
#endif
|
||||||
29
include/core/evidence_importer_test.h
Normal file
29
include/core/evidence_importer_test.h
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
/******************************************************************************
|
||||||
|
* @file evidence_importer_test.h
|
||||||
|
* @brief Crochets réservés aux tests de EvidenceImporter.
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
#ifndef LABFY_INVESTIGATION_EVIDENCE_IMPORTER_TEST_H
|
||||||
|
#define LABFY_INVESTIGATION_EVIDENCE_IMPORTER_TEST_H
|
||||||
|
|
||||||
|
#include <glib.h>
|
||||||
|
|
||||||
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
|
void evidence_importer_test_reset_hooks(void);
|
||||||
|
|
||||||
|
void evidence_importer_test_set_cancel_after_copy(
|
||||||
|
gboolean enabled
|
||||||
|
);
|
||||||
|
|
||||||
|
void evidence_importer_test_set_commit_failure(
|
||||||
|
gboolean enabled
|
||||||
|
);
|
||||||
|
|
||||||
|
void evidence_importer_test_set_cleanup_failure(
|
||||||
|
gboolean enabled
|
||||||
|
);
|
||||||
|
|
||||||
|
G_END_DECLS
|
||||||
|
|
||||||
|
#endif
|
||||||
BIN
labfy-investigation
Executable file
BIN
labfy-investigation
Executable file
Binary file not shown.
1476
src/core/evidence_importer.c
Normal file
1476
src/core/evidence_importer.c
Normal file
File diff suppressed because it is too large
Load diff
BIN
tests/test_background_task
Executable file
BIN
tests/test_background_task
Executable file
Binary file not shown.
BIN
tests/test_database
Executable file
BIN
tests/test_database
Executable file
Binary file not shown.
BIN
tests/test_error
Executable file
BIN
tests/test_error
Executable file
Binary file not shown.
BIN
tests/test_evidence_copy
Executable file
BIN
tests/test_evidence_copy
Executable file
Binary file not shown.
BIN
tests/test_evidence_dao
Executable file
BIN
tests/test_evidence_dao
Executable file
Binary file not shown.
BIN
tests/test_evidence_importer
Executable file
BIN
tests/test_evidence_importer
Executable file
Binary file not shown.
2665
tests/test_evidence_importer.c
Normal file
2665
tests/test_evidence_importer.c
Normal file
File diff suppressed because it is too large
Load diff
BIN
tests/test_evidence_record
Executable file
BIN
tests/test_evidence_record
Executable file
Binary file not shown.
BIN
tests/test_file_hash
Executable file
BIN
tests/test_file_hash
Executable file
Binary file not shown.
BIN
tests/test_investigation_dao
Executable file
BIN
tests/test_investigation_dao
Executable file
Binary file not shown.
BIN
tests/test_investigation_node
Executable file
BIN
tests/test_investigation_node
Executable file
Binary file not shown.
BIN
tests/test_investigation_project
Executable file
BIN
tests/test_investigation_project
Executable file
Binary file not shown.
BIN
tests/test_investigation_record
Executable file
BIN
tests/test_investigation_record
Executable file
Binary file not shown.
BIN
tests/test_investigation_session
Executable file
BIN
tests/test_investigation_session
Executable file
Binary file not shown.
BIN
tests/test_investigation_tree_builder
Executable file
BIN
tests/test_investigation_tree_builder
Executable file
Binary file not shown.
BIN
tests/test_investigation_tree_model
Executable file
BIN
tests/test_investigation_tree_model
Executable file
Binary file not shown.
BIN
tests/test_statement
Executable file
BIN
tests/test_statement
Executable file
Binary file not shown.
BIN
tests/test_task_manager
Executable file
BIN
tests/test_task_manager
Executable file
Binary file not shown.
BIN
tests/test_tool_catalog
Executable file
BIN
tests/test_tool_catalog
Executable file
Binary file not shown.
BIN
tests/test_tool_initializer
Executable file
BIN
tests/test_tool_initializer
Executable file
Binary file not shown.
BIN
tests/test_tool_process
Executable file
BIN
tests/test_tool_process
Executable file
Binary file not shown.
BIN
tests/test_tool_registry
Executable file
BIN
tests/test_tool_registry
Executable file
Binary file not shown.
BIN
tests/test_tool_task
Executable file
BIN
tests/test_tool_task
Executable file
Binary file not shown.
BIN
tests/test_transaction
Executable file
BIN
tests/test_transaction
Executable file
Binary file not shown.
Loading…
Reference in a new issue