Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/techsneeze/dmarcts-report-parser.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWolfgang Karall-Ahlborn <wolfgangkarall@users.noreply.github.com>2021-03-17 11:50:15 +0300
committerWolfgang Karall-Ahlborn <wolfgangkarall@users.noreply.github.com>2021-03-17 11:50:15 +0300
commit7181f97a0063ad5a022be30b9a3aee1aaf053235 (patch)
tree265ce473c628dbffd40d4c3865ca3ce17cb402c9
parent73bbb0ff546a332e7d1953d6d76d392d2840857f (diff)
Make sure the data inserted into the DB match the enum()
Extend column dkimresult to include 'unknown', as was done for spfresult etc. in 29a9a0a8dde1f2360d36551aca5df13dc3d251d4, as it's in reports in the wild, too. Do the same for column disposition, just in case. Neither of DispositionType, SPFResultType nor DKIMResultType in https://tools.ietf.org/html/rfc7489#appendix-C mention 'unknown', but it's only a 'proposed ... schema' after all. So, no more errors like DBD::mysql::db do failed: Data truncated for column 'dkimresult' The columns disposition, dkimresult and spfresult should probably be 'NOT NULL' as well, but this cannot be changed by the simple ALTER TABLE $table MODIFY COLUMN $col_name $col_def used in checkDatabase(), as on finding existing NULL values this leads to ERROR 1265 (01000): Data truncated for column 'spfresult' at row 1912
-rwxr-xr-xdmarcts-report-parser.pl65
1 files changed, 58 insertions, 7 deletions
diff --git a/dmarcts-report-parser.pl b/dmarcts-report-parser.pl
index dffd41f..ace1597 100755
--- a/dmarcts-report-parser.pl
+++ b/dmarcts-report-parser.pl
@@ -128,6 +128,45 @@ $db_tx_support = 1;
# used in messages
my $scriptname = 'dmarcts-report-parser.pl';
+# allowed values for the DB columns, also used to build the enum() in the
+# CREATE TABLE statements in checkDatabase(), in order defined here
+use constant ALLOWED_DISPOSITION => qw(
+ none
+ quarantine
+ reject
+ unknown
+);
+use constant ALLOWED_DKIM_ALIGN => qw(
+ fail
+ pass
+ unknown
+);
+use constant ALLOWED_SPF_ALIGN => qw(
+ fail
+ pass
+ unknown
+);
+use constant ALLOWED_DKIMRESULT => qw(
+ none
+ pass
+ fail
+ neutral
+ policy
+ temperror
+ permerror
+ unknown
+);
+use constant ALLOWED_SPFRESULT => qw(
+ none
+ neutral
+ pass
+ fail
+ softfail
+ temperror
+ permerror
+ unknown
+);
+
# Load script configuration options from local config file. The file is expected
# to be in the current working directory.
my $conf_file = 'dmarcts-report-parser.conf';
@@ -829,8 +868,14 @@ sub storeXMLInDatabase {
my $count = $r{'row'}->{'count'};
my $disp = $r{'row'}->{'policy_evaluated'}->{'disposition'};
# some reports don't have dkim/spf, "unknown" is default for these
- my $dkim_align = $r{'row'}->{'policy_evaluated'}->{'dkim'} || "unknown";
- my $spf_align = $r{'row'}->{'policy_evaluated'}->{'spf'} || "unknown";
+ my $dkim_align = $r{'row'}->{'policy_evaluated'}->{'dkim'};
+ if ( ! grep { $_ eq $dkim_align } ALLOWED_DKIM_ALIGN ) {
+ $dkim_align = 'unknown';
+ };
+ my $spf_align = $r{'row'}->{'policy_evaluated'}->{'spf'};
+ if ( ! grep { $_ eq $spf_align } ALLOWED_SPF_ALIGN ) {
+ $spf_align = 'unknown';
+ };
my $identifier_hfrom = $r{'identifiers'}->{'header_from'};
@@ -875,6 +920,9 @@ sub storeXMLInDatabase {
}
}
}
+ if ( ! grep { $_ eq $dkimresult } ALLOWED_DKIMRESULT ) {
+ $dkimresult = 'unknown';
+ };
$rp = $r{'auth_results'}->{'spf'};
if(ref $rp eq "HASH") {
@@ -905,6 +953,9 @@ sub storeXMLInDatabase {
}
}
}
+ if ( ! grep { $_ eq $spfresult } ALLOWED_SPFRESULT ) {
+ $spfresult = 'unknown';
+ };
$rp = $r{'row'}->{'policy_evaluated'}->{'reason'};
if(ref $rp eq "HASH") {
@@ -1020,14 +1071,14 @@ sub checkDatabase {
"ip" , "int(10) unsigned",
"ip6" , "binary(16)",
"rcount" , "int(10) unsigned NOT NULL",
- "disposition" , "enum('none','quarantine','reject')",
+ "disposition" , "enum('" . join("','", ALLOWED_DISPOSITION) . "')",
"reason" , "varchar(255)",
"dkimdomain" , "varchar(255)",
- "dkimresult" , "enum('none','pass','fail','neutral','policy','temperror','permerror')",
+ "dkimresult" , "enum('" . join("','", ALLOWED_DKIMRESULT) . "')",
"spfdomain" , "varchar(255)",
- "spfresult" , "enum('none','neutral','pass','fail','softfail','temperror','permerror','unknown')",
- "spf_align" , "enum('fail','pass','unknown') NOT NULL",
- "dkim_align" , "enum('fail','pass','unknown') NOT NULL",
+ "spfresult" , "enum('" . join("','", ALLOWED_SPFRESULT) . "')",
+ "spf_align" , "enum('" . join("','", ALLOWED_SPF_ALIGN) . "') NOT NULL",
+ "dkim_align" , "enum('" . join("','", ALLOWED_DKIM_ALIGN) . "') NOT NULL",
"identifier_hfrom" , "varchar(255)",
],
additional_definitions => "KEY serial (serial,ip), KEY serial6 (serial,ip6)",