summaryrefslogtreecommitdiff
path: root/src/analysis/db/server.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/analysis/db/server.c')
-rw-r--r--src/analysis/db/server.c50
1 files changed, 39 insertions, 11 deletions
diff --git a/src/analysis/db/server.c b/src/analysis/db/server.c
index 1621ed7..748af4e 100644
--- a/src/analysis/db/server.c
+++ b/src/analysis/db/server.c
@@ -478,12 +478,15 @@ static void *g_db_server_listener(GDbServer *server)
char *peer_name; /* Désignation du correspondant*/
DBError error; /* Validation de la connexion */
GCdbArchive *archive; /* Destinataire final du client*/
+ packed_buffer in_pbuf; /* Tampon de réception */
+ bool status; /* Bilan d'une opération */
uint32_t cmd; /* Commande initiale lue */
uint32_t version; /* Version du client lue */
rle_string hash; /* Empreinte du binaire visé */
rle_string user; /* Nom d'utilisateur du client */
unsigned char sig[RSA_USED_SIZE]; /* Signature effectuée */
GList *iter; /* Boucle de parcours */
+ packed_buffer out_pbuf; /* Tampon d'émission */
fds.fd = server->fd;
fds.events = POLLIN | POLLPRI;
@@ -540,7 +543,17 @@ static void *g_db_server_listener(GDbServer *server)
* Tout ceci est à synchroniser avec la fonction g_db_client_start().
*/
- if (!safe_recv(fd, &cmd, sizeof(uint32_t), 0))
+ status = recv_packed_buffer(&in_pbuf, fd);
+ if (!status)
+ {
+ log_variadic_message(LMT_ERROR, _("Error while getting the initial packet from '%s'..."),
+ peer_name);
+ error = DBE_BAD_EXCHANGE;
+ goto gdsl_error_sending;
+ }
+
+ status = extract_packed_buffer(&in_pbuf, &cmd, sizeof(uint32_t), true);
+ if (!status)
{
log_variadic_message(LMT_ERROR, _("Error while getting the initial command from '%s'..."),
peer_name);
@@ -548,7 +561,8 @@ static void *g_db_server_listener(GDbServer *server)
goto gdsl_error_sending;
}
- if (!safe_recv(fd, &version, sizeof(uint32_t), 0))
+ status = extract_packed_buffer(&in_pbuf, &version, sizeof(uint32_t), true);
+ if (!status)
{
log_variadic_message(LMT_ERROR, _("Error while getting the protocol version from '%s'..."),
peer_name);
@@ -556,7 +570,8 @@ static void *g_db_server_listener(GDbServer *server)
goto gdsl_error_sending;
}
- if (!recv_rle_string(&hash, fd, 0))
+ status = unpack_rle_string(&hash, &in_pbuf);
+ if (!status)
{
log_variadic_message(LMT_ERROR, _("Error while getting the binary hash from '%s'..."),
peer_name);
@@ -564,7 +579,8 @@ static void *g_db_server_listener(GDbServer *server)
goto gdsl_error_sending;
}
- if (!recv_rle_string(&user, fd, 0))
+ status = unpack_rle_string(&user, &in_pbuf);
+ if (!status)
{
log_variadic_message(LMT_ERROR, _("Error while getting the user name from '%s'..."),
peer_name);
@@ -572,7 +588,8 @@ static void *g_db_server_listener(GDbServer *server)
goto gdsl_error_sending;
}
- if (!safe_recv(fd, sig, RSA_USED_SIZE, 0))
+ status = extract_packed_buffer(&in_pbuf, sig, RSA_USED_SIZE, false);
+ if (!status)
{
log_variadic_message(LMT_ERROR, _("Error while getting the signature from '%s'..."),
peer_name);
@@ -580,7 +597,7 @@ static void *g_db_server_listener(GDbServer *server)
goto gdsl_error_sending;
}
- if (be32toh(cmd) != DBC_HELO)
+ if (cmd != DBC_HELO)
{
log_variadic_message(LMT_ERROR, _("The client from '%s' did not introduce itself!"),
peer_name);
@@ -588,7 +605,7 @@ static void *g_db_server_listener(GDbServer *server)
goto gdsl_error_sending;
}
- if (be32toh(version) != CDB_PROTOCOL_VERSION)
+ if (version != CDB_PROTOCOL_VERSION)
{
log_variadic_message(LMT_ERROR, _("The client from '%s' does not use the same protocol: 0x%08x vs 0x%08x..."),
peer_name, be32toh(version), CDB_PROTOCOL_VERSION);
@@ -647,11 +664,20 @@ static void *g_db_server_listener(GDbServer *server)
gdsl_error_sending:
- if (!safe_send(fd, (uint32_t []) { htobe32(DBC_WELCOME) }, sizeof(uint32_t), MSG_MORE))
- goto gdsl_error;
+ exit_packed_buffer(&in_pbuf);
- if (!safe_send(fd, (uint32_t []) { htobe32(error) }, sizeof(uint32_t), 0))
- goto gdsl_error;
+ init_packed_buffer(&out_pbuf);
+
+ status = extend_packed_buffer(&out_pbuf, (uint32_t []) { DBC_WELCOME }, sizeof(uint32_t), true);
+ if (!status) goto gdsl_error;
+
+ status = extend_packed_buffer(&out_pbuf, (uint32_t []) { error }, sizeof(uint32_t), true);
+ if (!status) goto gdsl_error;
+
+ status = send_packed_buffer(&out_pbuf, fd);
+ if (!status) goto gdsl_error;
+
+ exit_packed_buffer(&out_pbuf);
/**
* L'ajout dans la liste des clients connectés provoque un envoie de mises à jour.
@@ -679,6 +705,8 @@ static void *g_db_server_listener(GDbServer *server)
gdsl_error:
+ exit_packed_buffer(&out_pbuf);
+
free(peer_name);
exit_rle_string(&hash);