#include "main.h"
#include "roll_history.h"
+static const gchar rspamd_history_magic[] = {'r', 's', 'h', '1'};
/**
* Returns new roll history
}
/* Add information from task to roll history */
- memcpy (&row->from_addr, &task->from_addr, sizeof (row->from_addr));
+ rspamd_strlcpy (row->from_addr,
+ rspamd_inet_address_to_string (task->from_addr),
+ sizeof (row->from_addr));
memcpy (&row->tv, &task->tv, sizeof (row->tv));
/* Strings */
{
gint fd;
struct stat st;
+ gchar magic[sizeof(rspamd_history_magic)];
if (stat (filename, &st) == -1) {
msg_info ("cannot load history from %s: %s", filename,
return FALSE;
}
- if (st.st_size != sizeof (history->rows)) {
+ if (st.st_size != sizeof (history->rows) + sizeof (rspamd_history_magic)) {
msg_info ("cannot load history from %s: size mismatch", filename);
return FALSE;
}
return FALSE;
}
+ if (read (fd, magic, sizeof (magic)) == -1) {
+ close (fd);
+ msg_info ("cannot read history from %s: %s", filename,
+ strerror (errno));
+ return FALSE;
+ }
+
+ if (memcmp (magic, rspamd_history_magic, sizeof (magic)) != 0) {
+ close (fd);
+ msg_info ("cannot read history from %s: bad magic", filename);
+ return FALSE;
+ }
+
if (read (fd, history->rows, sizeof (history->rows)) == -1) {
close (fd);
msg_info ("cannot read history from %s: %s", filename,
return FALSE;
}
+ if (write (fd, rspamd_history_magic, sizeof (rspamd_history_magic)) == -1) {
+ close (fd);
+ msg_info ("cannot write history to %s: %s", filename, strerror (errno));
+ return FALSE;
+ }
+
if (write (fd, history->rows, sizeof (history->rows)) == -1) {
close (fd);
msg_info ("cannot write history to %s: %s", filename, strerror (errno));
#define HISTORY_MAX_ID 100
#define HISTORY_MAX_SYMBOLS 200
#define HISTORY_MAX_USER 20
+#define HISTORY_MAX_ADDR 32
#define HISTORY_MAX_ROWS 200
struct rspamd_task;
gchar message_id[HISTORY_MAX_ID];
gchar symbols[HISTORY_MAX_SYMBOLS];
gchar user[HISTORY_MAX_USER];
- rspamd_inet_addr_t from_addr;
+ gchar from_addr[HISTORY_MAX_ADDR];
gsize len;
guint scan_time;
gint action;